all repos — mgba @ 50cbf732b51ada4e6ce2a8f425540e701f7721dd

mGBA Game Boy Advance Emulator

GUI: Make autosave configurable
Vicki Pfau vi@endrift.com
Sat, 20 Jan 2018 15:48:57 -0800
commit

50cbf732b51ada4e6ce2a8f425540e701f7721dd

parent

45c2fdf7ed224b11b4175d816451e645e4a45245

2 files changed, 44 insertions(+), 12 deletions(-)

jump to
M src/feature/gui/gui-config.csrc/feature/gui/gui-config.c

@@ -48,6 +48,26 @@ },

.nStates = 2 }; *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { + .title = "Autosave state", + .data = "autosave", + .submenu = 0, + .state = true, + .validStates = (const char*[]) { + "Off", "On" + }, + .nStates = 2 + }; + *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { + .title = "Autoload state", + .data = "autoload", + .submenu = 0, + .state = true, + .validStates = (const char*[]) { + "Off", "On" + }, + .nStates = 2 + }; + *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { .title = "Use BIOS if found", .data = "useBios", .submenu = 0,
M src/feature/gui/gui-runner.csrc/feature/gui/gui-runner.c

@@ -135,6 +135,12 @@ return 0xFF - value;

} static void _tryAutosave(struct mGUIRunner* runner) { + int autosave = false; + mCoreConfigGetIntValue(&runner->config, "autosave", &autosave); + if (!autosave) { + return; + } + #ifdef DISABLE_THREADING mCoreSaveState(runner->core, 0, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA); #else

@@ -168,6 +174,12 @@ mCoreConfigInit(&runner->config, runner->port);

// TODO: Do we need to load more defaults? mCoreConfigSetDefaultIntValue(&runner->config, "volume", 0x100); mCoreConfigSetDefaultValue(&runner->config, "idleOptimization", "detect"); + mCoreConfigSetDefaultIntValue(&runner->config, "autoload", true); +#ifdef DISABLE_THREADING + mCoreConfigSetDefaultIntValue(&runner->config, "autosave", false); +#else + mCoreConfigSetDefaultIntValue(&runner->config, "autosave", true); +#endif mCoreConfigLoad(&runner->config); mCoreConfigGetIntValue(&runner->config, "logLevel", &logger.logLevel);

@@ -352,10 +364,11 @@ mLOG(GUI_RUNNER, DEBUG, "Reseting...");

runner->core->reset(runner->core); mLOG(GUI_RUNNER, DEBUG, "Reset!"); - if (mCoreLoadState(runner->core, 0, SAVESTATE_SCREENSHOT | SAVESTATE_RTC)) { - struct VFile* autosave = mCoreGetState(runner->core, 0, true); - autosave->truncate(autosave, 0); - autosave->close(autosave); + + int autoload = false; + mCoreConfigGetIntValue(&runner->config, "autoload", &autoload); + if (autoload) { + mCoreLoadState(runner->core, 0, SAVESTATE_SCREENSHOT | SAVESTATE_RTC); } bool running = true;

@@ -516,6 +529,13 @@ MutexLock(&runner->autosave.mutex);

runner->autosave.core = NULL; MutexUnlock(&runner->autosave.mutex); #endif + + int autosave = false; + mCoreConfigGetIntValue(&runner->config, "autosave", &autosave); + if (autosave) { + mCoreSaveState(runner->core, 0, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA); + } + mLOG(GUI_RUNNER, DEBUG, "Unloading game..."); runner->core->unloadROM(runner->core); drawState.screenshotId = 0;

@@ -523,14 +543,6 @@ if (drawState.screenshot) {

unsigned w, h; runner->core->desiredVideoDimensions(runner->core, &w, &h); mappedMemoryFree(drawState.screenshot, w * h * 4); - } - - struct VFile* autosave = mCoreGetState(runner->core, 0, false); - if (autosave) { - autosave->close(autosave); - autosave = mCoreGetState(runner->core, 0, true); - autosave->truncate(autosave, 0); - autosave->close(autosave); } if (runner->config.port) {