static void prepare_save(void) { if (paquete) return; char *str="UAE4ALL"; vmu_pkg_t pkg; memset(&pkg, 0, sizeof(pkg)); strcpy(pkg.desc_short, str); strcpy(pkg.desc_long, str); strcpy(pkg.app_id, str); pkg.icon_cnt = 1; pkg.icon_anim_speed = 0; pkg.eyecatch_type = VMUPKG_EC_NONE; pkg.eyecatch_data = NULL; pkg.data_len = 4; pkg.data = (const uint8*)&pkg; memcpy((void *)&pkg.icon_pal[0],(void *)&vmu_savestate_icon_pal,32); pkg.icon_data = (const uint8*)&vmu_savestate_icon_data; vmu_pkg_build(&pkg, &paquete, &paquete_size); paquete_size-=4; }
void netcfg_vmuify(const char *filename_in, const char *filename_out) { int fd, pkg_size; uint8 *buf; uint8 *pkg_out; vmu_pkg_t pkg; dbgp("Opening source file\n"); fd = fs_open(filename_in, O_RDONLY); buf = (uint8 *) malloc(fs_total(fd)); fs_read(fd, buf, fs_total(fd)); dbgp("Read %i bytes\n", fs_total(fd)); strcpy(pkg.desc_short, "KallistiOS 1.3"); strcpy(pkg.desc_long, "KOS Network Settings"); strcpy(pkg.app_id, "KOS"); pkg.icon_cnt = 1; pkg.icon_anim_speed = 1; memcpy(&pkg.icon_pal[0], netcfg_icon, 32); pkg.icon_data = netcfg_icon + 32; pkg.eyecatch_type = VMUPKG_EC_NONE; pkg.data_len = fs_total(fd); pkg.data = buf; dbgp("Building package\n"); vmu_pkg_build(&pkg, &pkg_out, &pkg_size); fs_close(fd); dbgp("Closing source file\n"); dbgp("Opening output file\n"); fd = fs_open(filename_out, O_WRONLY); dbgp("Writing..\n"); fs_write(fd, pkg_out, pkg_size); dbgp("Closing output file\n"); fs_close(fd); free(buf); dbgp("VMUification complete\n"); }
int coleco_save_state(const char *filename) { char tmpfn[4096]; int rv; uint32 crc, adler; uint8 *buf, *buf2; FILE *fp; long len; uLong clen; vmu_pkg_t pkg; uint8 *pkg_out; int pkg_size; maple_device_t *vmu; file_t f; int blocks_freed = 0; /* Make sure there's a VMU in port A1. */ if(!(vmu = maple_enum_dev(0, 1))) { return -100; } if(!vmu->valid || !(vmu->info.functions & MAPLE_FUNC_MEMCARD)) { return -100; } sprintf(tmpfn, "/ram/%s", filename); rv = coleco_save_state_int(tmpfn); if(rv) return rv; /* Read in the uncompressed save state */ fp = fopen(tmpfn, "rb"); if(!fp) { fs_unlink(tmpfn); return -1; } fseek(fp, 0, SEEK_END); len = ftell(fp); fseek(fp, 0, SEEK_SET); if(!(buf = (uint8 *)malloc(len))) { fclose(fp); fs_unlink(tmpfn); return -1; } fread(buf, 1, len, fp); fclose(fp); fs_unlink(tmpfn); /* Create a compressed version */ clen = len * 2; if(!(buf2 = (uint8 *)malloc(clen + 8))) { free(buf); return -1; } if(compress2(buf2 + 8, &clen, buf, len, 9) != Z_OK) { free(buf2); free(buf); return -1; } /* Clean up the old buffer and save the length of the uncompressed data into the new buffer */ free(buf); *((uint32 *)buf2) = (uint32)len; *(((uint32 *)buf2) + 1) = (uint32)clen; /* Make the VMU save */ coleco_get_checksums(&crc, &adler); sprintf(tmpfn, "/vmu/a1/ss-%08" PRIX32, (uint32_t)crc); if(filename != NULL) { strncpy(pkg.desc_long, filename, 32); pkg.desc_long[31] = 0; } else { sprintf(pkg.desc_long, "CRC: %08" PRIX32 " Adler: %08" PRIX32, (uint32_t)crc, (uint32_t)adler); } strcpy(pkg.desc_short, "CrabEmu State"); strcpy(pkg.app_id, "CrabEmu"); pkg.icon_cnt = 1; pkg.icon_anim_speed = 0; memcpy(pkg.icon_pal, icon_pal, 32); pkg.icon_data = icon_img; pkg.eyecatch_type = VMUPKG_EC_NONE; pkg.data_len = clen + 4; pkg.data = buf2; vmu_pkg_build(&pkg, &pkg_out, &pkg_size); /* See if a file exists with that name, since we'll overwrite it. */ f = fs_open(tmpfn, O_RDONLY); if(f != FILEHND_INVALID) { blocks_freed = fs_total(f) >> 9; fs_close(f); }