BYTE save_slot_load(BYTE slot) { uTCHAR *file; FILE *fp; if (tas.type) { text_add_line_info(1, "[yellow]movie playback interrupted[normal]"); tas_quit(); } /* game genie */ if (info.mapper.id == GAMEGENIE_MAPPER) { gamegenie_reset(); gamegenie.phase = GG_LOAD_ROM; emu_reset(CHANGE_ROM); gamegenie.phase = GG_FINISH; } if (slot < SAVE_SLOT_FILE) { if ((file = name_slot_file(slot)) == NULL) { return (EXIT_ERROR); } } else { file = cfg->save_file; } if ((fp = ufopen(file, uL("rb"))) == NULL) { text_add_line_info(1, "[red]error[normal] loading state"); fprintf(stderr, "error loading state\n"); return (EXIT_ERROR); } /* * mi salvo lo stato attuale da ripristinare in caso * di un file di salvataggio corrotto. */ timeline_snap(TL_SAVE_SLOT); if (slot == SAVE_SLOT_FILE) { slot_operation(SAVE_SLOT_COUNT, slot, fp); if (memcmp(info.sha1sum.prg.value, save_slot.sha1sum.prg.value, sizeof(info.sha1sum.prg.value)) != 0) { text_add_line_info(1, "[red]state file is not for this rom[normal]"); fprintf(stderr, "state file is not for this rom.\n"); timeline_back(TL_SAVE_SLOT, 0); fclose(fp); return (EXIT_ERROR); } } if (slot_operation(SAVE_SLOT_READ, slot, fp)) { fprintf(stderr, "error loading state, corrupted file.\n"); timeline_back(TL_SAVE_SLOT, 0); fclose(fp); return (EXIT_ERROR); } fclose(fp); if (slot < SAVE_SLOT_FILE) { text_save_slot(SAVE_SLOT_READ); } /* riavvio il timeline */ timeline_init(); return (EXIT_OK); }
BYTE emu_frame(void) { #if defined (DEBUG) WORD PCBREAK = 0xA930; #endif #if defined (SDL) && defined (__WIN32__) gfx_sdlwe_tick(); #endif gui_control_visible_cursor(); tas.lag_frame = TRUE; /* gestione uscita */ if (info.stop == TRUE) { emu_quit(EXIT_SUCCESS); } /* eseguo un frame dell'emulatore */ if (!(info.no_rom | info.pause)) { /* controllo se ci sono eventi di input */ if (tas.type) { tas_frame(); } else { BYTE i; for (i = PORT1; i < PORT_MAX; i++) { if (input_add_event[i]) { input_add_event[i](i); } } } /* riprendo a far correre la CPU */ info.execute_cpu = TRUE; while (info.execute_cpu == TRUE) { #if defined (DEBUG) if (cpu.PC == PCBREAK) { BYTE pippo = 5; pippo = pippo + 1; } #endif /* eseguo CPU, PPU e APU */ cpu_exe_op(); } if ((cfg->cheat_mode == GAMEGENIE_MODE) && (gamegenie.phase == GG_LOAD_ROM)) { emu_reset(CHANGE_ROM); gamegenie.phase = GG_FINISH; } if (tas.lag_frame) { tas.total_lag_frames++; } if (snd_end_frame) { snd_end_frame(); } //#if defined (DEBUG) // gfx_draw_screen(TRUE); //#else gfx_draw_screen(FALSE); //#endif if (!tas.type && (++tl.frames == tl.frames_snap)) { timeline_snap(TL_NORMAL); } r4011.frames++; } else { gfx_draw_screen(FALSE); } /* gestione frameskip e calcolo fps */ fps_frameskip(); return (EXIT_OK); }