int state_save(int slot) { FILE *fp = NULL; char path[MAX_PATH]; sprintf(path, "%sstate", launchDir); mkdir(path, 0755); sprintf(path, "%sstate/%s.sv%d", launchDir, game_name, slot); remove(path); if ((fp = fopen(path, "wb")) != NULL) { // Header (8 bytes) state_save_byte(current_version_str, 8); // State save state_save_memory(fp); state_save_m68000(fp); state_save_z80(fp); state_save_input(fp); state_save_timer(fp); state_save_driver(fp); state_save_video(fp); state_save_coin(fp); state_save_qsound(fp); state_save_eeprom(fp); fclose(fp); sync(); msg_printf("Save: \"%s.sv%d\"\n", game_name, slot); return 1; } msg_printf("Save: Couldn't open \"%s.sv%d\"\n", game_name, slot); return 0; }
int state_save(int slot) { SceUID fd = -1; pspTime nowtime; char path[MAX_PATH]; char error_mes[128]; char buf[128]; #if (EMU_SYSTEM == NCDZ) UINT8 *inbuf, *outbuf; unsigned long insize, outsize; #else #ifndef ADHOC UINT8 *state_buffer_base; #endif UINT32 size; #endif sprintf(path, "%sstate/%s.sv%d", launchDir, game_name, slot); sceIoRemove(path); sprintf(buf, TEXT(STATE_SAVING), game_name, slot); init_progress(6, buf); sceRtcGetCurrentClockLocalTime(&nowtime); if ((fd = sceIoOpen(path, PSP_O_WRONLY|PSP_O_CREAT, 0777)) >= 0) #if (EMU_SYSTEM == NCDZ) { if ((inbuf = memalign(MEM_ALIGN, STATE_BUFFER_SIZE)) == NULL) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); goto error; } memset(inbuf, 0, STATE_BUFFER_SIZE); state_buffer = inbuf; state_save_byte(current_version_str, 8); state_save_byte(&nowtime, 16); update_progress(); save_thumbnail(); update_progress(); sceIoWrite(fd, inbuf, (UINT32)state_buffer - (UINT32)inbuf); update_progress(); memset(inbuf, 0, STATE_BUFFER_SIZE); state_buffer = inbuf; state_save_memory(); state_save_m68000(); state_save_z80(); state_save_input(); state_save_timer(); state_save_driver(); state_save_video(); state_save_ym2610(); state_save_cdda(); state_save_cdrom(); update_progress(); insize = (UINT32)state_buffer - (UINT32)inbuf; outsize = insize * 1.1 + 12; if ((outbuf = memalign(MEM_ALIGN, outsize)) == NULL) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); free(inbuf); goto error; } memset(outbuf, 0, outsize); if (compress(outbuf, &outsize, inbuf, insize) != Z_OK) { strcpy(error_mes, TEXT(COULD_NOT_COMPRESS_STATE_DATA)); free(inbuf); free(outbuf); goto error; } free(inbuf); update_progress(); sceIoWrite(fd, &outsize, 4); sceIoWrite(fd, outbuf, outsize); sceIoClose(fd); free(outbuf); update_progress(); show_progress(buf); return 1; } #else { #ifdef ADHOC state_buffer = state_buffer_base; #else #if (EMU_SYSTEM == CPS1 || (EMU_SYSTEM == CPS2 && defined(PSP_SLIM))) state_buffer = state_buffer_base = memalign(MEM_ALIGN, STATE_BUFFER_SIZE); #else state_buffer = state_buffer_base = cache_alloc_state_buffer(STATE_BUFFER_SIZE); #endif if (!state_buffer) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); goto error; } #endif memset(state_buffer, 0, STATE_BUFFER_SIZE); update_progress(); state_save_byte(current_version_str, 8); state_save_byte(&nowtime, 16); update_progress(); save_thumbnail(); update_progress(); state_save_memory(); state_save_m68000(); state_save_z80(); state_save_input(); state_save_timer(); state_save_driver(); state_save_video(); #if (EMU_SYSTEM == CPS1) state_save_coin(); switch (machine_driver_type) { case MACHINE_qsound: state_save_qsound(); state_save_eeprom(); break; case MACHINE_pang3: state_save_eeprom(); default: state_save_ym2151(); break; } #elif (EMU_SYSTEM == CPS2) state_save_coin(); state_save_qsound(); state_save_eeprom(); #elif (EMU_SYSTEM == MVS) state_save_ym2610(); state_save_pd4990a(); #endif update_progress(); size = (UINT32)state_buffer - (UINT32)state_buffer_base; sceIoWrite(fd, state_buffer_base, size); sceIoClose(fd); update_progress(); #ifndef ADHOC #if (EMU_SYSTEM == CPS1 || (EMU_SYSTEM == CPS2 && defined(PSP_SLIM))) free(state_buffer_base); #else cache_free_state_buffer(STATE_BUFFER_SIZE); #endif #endif update_progress(); show_progress(buf); return 1; } #endif else {