void S9xQuickLoadSlot (int slot) { char def[PATH_MAX]; char filename[PATH_MAX]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char ext[_MAX_EXT]; if (!gui_config->rom_loaded) return; _splitpath (Memory.ROMFilename, drive, dir, def, ext); snprintf (filename, PATH_MAX, "%s%s%s.%03d", S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def, slot); if (file_exists (filename)) S9xFreezeGame (S9xGetFilename (".undo", SNAPSHOT_DIR)); if (S9xUnfreezeGame (filename)) { snprintf (buf, PATH_MAX, "%s.%03d loaded", def, slot); S9xSetInfoString (buf); return; } static const char *digits = "t123456789"; _splitpath (Memory.ROMFilename, drive, dir, def, ext); snprintf (filename, PATH_MAX, "%s%s%s.zs%c", S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def, digits[slot]); if (file_exists (filename)) S9xFreezeGame (S9xGetFilename (".undo", SNAPSHOT_DIR)); if (S9xUnfreezeGame (filename)) { snprintf (buf, PATH_MAX, "Loaded ZSNES freeze file %s.zs%c", def, digits [slot]); S9xSetInfoString (buf); return; } S9xMessage (S9X_ERROR, S9X_FREEZE_FILE_NOT_FOUND, "Freeze file not found"); }
void S9xLoadState(int num) { const char * file = S9xGetQuickSaveFilename(num); int result = S9xUnfreezeGame(file); S9xSetInfoString("Load slot %u: %s", num, (result ? "done" : "failed")); }
bool snes_unserialize(const uint8_t* data, unsigned size) { memstream_set_buffer((uint8_t*)data, size); if (S9xUnfreezeGame("foo") == FALSE) return false; return true; }
bool8 SNES9X_Defrost(void) { int which; const char *filename; if (cartOpen) { MacStopSound(); which = PromptFreezeDefrost(false); if (which >= 0) { filename = S9xGetFreezeFilename(which); S9xUnfreezeGame(filename); SNES9X_Go(); MacStartSound(); return true; } else { MacStartSound(); return false; } } else return false; }
void resumeGame() { if (!autosave) return; const char * file = S9xGetFilename(FILE_FREEZE); int result = S9xUnfreezeGame(file); printf("Unfreeze: %s", file); if (!result) { printf(" failed"); FILE* fp = fopen(file, "rb"); if (fp) { //if (Config.snapshotSave) { // puts(", but the file exists, so I'm not going to overwrite it"); // Config.snapshotSave = false; //} else { puts(" (bad file?)"); //} fclose(fp); } else { puts(" (file does not exist)"); } } else { puts(" ok"); } }
bool retro_unserialize(const void * data, size_t size) { memstream_set_buffer((uint8_t*)data, size); if (S9xUnfreezeGame("") == FALSE) return FALSE; return TRUE; }
static bool8 LoadStateFile(s8 *filename) { bool8 ret; if (!(ret = S9xUnfreezeGame(filename))) fprintf(stderr, "Failed to read saved state at %s: %s\n", filename, strerror(errno)); return ret; }
static void MusicBoxForceDefrost(void) { char filename[PATH_MAX + 1]; strcpy(filename, S9xGetFreezeFilename(999)); strcat(filename, ".tmp"); S9xUnfreezeGame(filename); remove(filename); }
static bool8 LoadStateTemp() { char name[SAL_MAX_PATH]; bool8 ret; sprintf(name, "%s%s%s", sal_DirectoryGetTemp(), SAL_DIR_SEP, ".svt"); if (!(ret = S9xUnfreezeGame(name))) fprintf(stderr, "Failed to read saved state at %s: %s\n", name, strerror(errno)); return ret; }
void S9xLoadState (const char *filename) { S9xFreezeGame (S9xGetFilename (".undo", SNAPSHOT_DIR)); if (S9xUnfreezeGame (filename)) { sprintf (buf, "%s loaded", filename); S9xSetInfoString (buf); } else { fprintf (stderr, "Failed to load state file: %s\n", filename); } }
void S9xLoadState (const char *filename) { if (S9xUnfreezeGame (filename)) { sprintf (buf, "%s loaded", filename); S9xSetInfoString (buf); } else { fprintf (stderr, "Failed to load state file: %s\n", filename); } return; }
int os9x_load(const char *ext) { FILE *savefile; const char *save_filename; os9x_externstate_mode=0; save_filename=S9xGetSaveFilename (ext); savefile=fopen(save_filename,"rb"); if (savefile) { fclose(savefile); S9xUnfreezeGame(save_filename); // S9xInitUpdate(); S9xReschedule (); return 1; } return 0; }
bool snes_unserialize(const uint8_t* data, unsigned size) { FILE *tmp = fopen(s9x_tmp_file(S9X_TMP_STATE_FILE), "wb"); if (!tmp) { return false; } fwrite(data, 1, size, tmp); fclose(tmp); if (S9xUnfreezeGame(s9x_tmp_file(S9X_TMP_STATE_FILE)) == FALSE) { return false; } return true; }
bool8 SNES9X_DefrostFrom(void) { char filename[PATH_MAX + 1]; if (cartOpen) { if (NavDefrostFrom(filename)) { S9xUnfreezeGame(filename); SNES9X_Go(); return true; } } return false; }
static void LoadStateMem() { SetSaveStateIoModeMemory(&mTempState); S9xUnfreezeGame("blah"); }
int main (int argc, char *argv[]) { struct sigaction sig_callback; gtk_init (&argc, &argv); bindtextdomain (GETTEXT_PACKAGE, SNES9XLOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); memset (&Settings, 0, sizeof (Settings)); /* Allow original config file for backend settings */ S9xLoadConfigFiles (argv, argc); /* Perform our config here */ gui_config = new Snes9xConfig (); S9xInitInputDevices (); gui_config->load_config_file (); char *rom_filename = S9xParseArgs (argv, argc); S9xReportControllers (); if (!Memory.Init () || !S9xInitAPU ()) exit (3); g_set_application_name ("Snes9x"); top_level = new Snes9xWindow (gui_config); /* If we're going to fullscreen, do it before showing window to avoid flicker. */ if ((gui_config->full_screen_on_open && rom_filename) || (gui_config->fullscreen)) gtk_window_fullscreen (top_level->get_window ()); top_level->show (); S9xInitDisplay (argc, argv); Memory.PostRomInitFunc = S9xPostRomInit; S9xPortSoundInit (); gui_config->reconfigure (); top_level->update_accels (); Settings.Paused = TRUE; syncing = 0; idle_func_id = g_idle_add_full (IDLE_FUNC_PRIORITY, S9xIdleFunc, NULL, NULL); g_timeout_add (10000, S9xScreenSaverCheckFunc, NULL); S9xNoROMLoaded (); if (rom_filename) { if (S9xOpenROM (rom_filename) && gui_config->full_screen_on_open) gtk_window_unfullscreen (top_level->get_window()); } memset (&sig_callback, 0, sizeof (struct sigaction)); sig_callback.sa_handler = S9xTerm; sigaction (15 /* SIGTERM */, &sig_callback, NULL); sigaction (3 /* SIGQUIT */, &sig_callback, NULL); sigaction (2 /* SIGINT */, &sig_callback, NULL); if (gui_config->fullscreen) { gui_config->fullscreen = 0; needs_fullscreening = 1; } #ifdef USE_JOYSTICK gui_config->flush_joysticks (); #endif gtk_window_present (top_level->get_window ()); if (rom_filename && *Settings.InitialSnapshotFilename) S9xUnfreezeGame(Settings.InitialSnapshotFilename); gtk_main (); return 0; }
/**************************************************************************** * NGCUnfreezeGame ***************************************************************************/ int NGCUnfreezeGame (int method, bool8 silent) { char filepath[1024]; int offset = 0; int result = 0; char msg[80]; bufoffset = 0; ShowAction ((char*) "Loading..."); if(method == METHOD_AUTO) method = autoSaveMethod(); // we use 'Save' because snapshot needs R/W if(!MakeFilePath(filepath, FILE_SNAPSHOT, method)) return 0; AllocSaveBuffer (); offset = LoadFile(filepath, method, silent); if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B { if (offset) { char * zipbuffer = (char *)malloc(SAVEBUFFERSIZE); memset (zipbuffer, 0, SAVEBUFFERSIZE); // skip the saveicon and comment offset = (sizeof(saveicon) + 64); uLongf zipsize = 0; uLongf decompressedsize = 0; memcpy (&zipsize, savebuffer+offset, 4); offset += 4; memcpy (&decompressedsize, savebuffer+offset, 4); offset += 4; uLongf DestBuffSize = SAVEBUFFERSIZE; int err= uncompress((Bytef*)zipbuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize); if ( err!=Z_OK ) { sprintf (msg, "Unzip error %s ",zError(err)); WaitPrompt (msg); } else if ( DestBuffSize != decompressedsize ) { WaitPrompt((char*) "Unzipped size doesn't match expected size!"); } else { offset = SAVEBUFFERSIZE; memcpy (savebuffer, zipbuffer, SAVEBUFFERSIZE); } free(zipbuffer); } } if(offset > 0) { if (S9xUnfreezeGame ("AGAME") == SUCCESS) result = 1; else WaitPrompt((char*) "Error thawing"); } else { if(!silent) WaitPrompt((char*) "Freeze file not found"); } FreeSaveBuffer (); return result; }