diff --git a/docs/index.html b/docs/index.html
index dccd854a2..6a3542d33 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -2185,6 +2185,11 @@
saving a ROM state file.
+
+ -saveonexit <none|current|all> |
+ Automatically save no, current or all states when exiting emulation. |
+
+
-fastscbios <1|0> |
Disable Supercharger BIOS progress loading bars. |
@@ -3298,6 +3303,12 @@
'Buffer size'.
-plr.tm.horizon -dev.tm.horizon |
+
+ When exiting emulation: |
+
+ Automatically save no, current or all states when exiting emulation.
+ |
+ -saveonexit |
diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx
index 159fb91e6..d83bc827d 100644
--- a/src/emucore/EventHandler.cxx
+++ b/src/emucore/EventHandler.cxx
@@ -705,6 +705,7 @@ void EventHandler::handleEvent(Event::Type event, bool pressed, bool repeated)
case EventHandlerState::EMULATION:
if (pressed && !repeated)
{
+ exitEmulation();
// Go back to the launcher, or immediately quit
if (myOSystem.settings().getBool("exitlauncher") ||
myOSystem.launcherUsed())
@@ -723,6 +724,8 @@ void EventHandler::handleEvent(Event::Type event, bool pressed, bool repeated)
{
saveKeyMapping();
saveJoyMapping();
+ if (myState != EventHandlerState::LAUNCHER)
+ exitEmulation();
myOSystem.quit();
}
return;
@@ -1570,6 +1573,18 @@ void EventHandler::setState(EventHandlerState state)
myEvent.clear();
}
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+void EventHandler::exitEmulation()
+{
+ // TODO: confirm message
+ string saveOnExit = myOSystem.settings().getString("saveonexit");
+
+ if (saveOnExit == "all")
+ handleEvent(Event::SaveAllStates);
+ else if (saveOnExit == "current")
+ handleEvent(Event::SaveState);
+}
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] = {
{ Event::Quit, "Quit", "" },
diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx
index a825bb70d..59bd99b19 100644
--- a/src/emucore/EventHandler.hxx
+++ b/src/emucore/EventHandler.hxx
@@ -308,6 +308,8 @@ class EventHandler
void saveKeyMapping();
void saveJoyMapping();
+ void exitEmulation();
+
protected:
// Global OSystem object
OSystem& myOSystem;
diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx
index e847489df..7bce6a15e 100644
--- a/src/emucore/Settings.cxx
+++ b/src/emucore/Settings.cxx
@@ -104,10 +104,11 @@ Settings::Settings()
setPermanent("snapsavedir", "");
setPermanent("snaploaddir", "");
setPermanent("snapname", "int");
- setPermanent("autoslot", "false");
setPermanent("sssingle", "false");
setPermanent("ss1x", "false");
setPermanent("ssinterval", "2");
+ setPermanent("autoslot", "false");
+ setPermanent("saveonexit", "ALL");
// Config files and paths
setPermanent("romdir", "");
@@ -451,13 +452,15 @@ void Settings::usage() const
<< " -snaploaddir The directory to load snapshot files from\n"
<< " -snapname Name snapshots according to internal database or\n"
<< " ROM\n"
- << " -autoslot <1|0> Automatically switch to next save slot when\n"
- << " state saving\n"
<< " -sssingle <1|0> Generate single snapshot instead of many\n"
<< " -ss1x <1|0> Generate TIA snapshot in 1x mode (ignore\n"
<< " scaling/effects)\n"
- << " -ssinterval Number of seconds between snapshots in\n"
<< " continuous snapshot mode\n"
+ << " -autoslot <1|0> Automatically switch to next save slot when\n"
+ << " state saving\n"
+ << " -saveonexit \n"
<< endl
<< " -rominfo Display detailed information for the given ROM\n"
<< " -listrominfo Display contents of stella.pro, one line per ROM\n"
diff --git a/src/gui/DeveloperDialog.cxx b/src/gui/DeveloperDialog.cxx
index c538a08c0..4e5e84a19 100644
--- a/src/gui/DeveloperDialog.cxx
+++ b/src/gui/DeveloperDialog.cxx
@@ -472,6 +472,24 @@ void DeveloperDialog::addTimeMachineTab(const GUI::Font& font)
lineHeight, items, "Horizon ~ ", 0, kHorizonChanged);
wid.push_back(myStateHorizonWidget);
+ ypos += lineHeight + VGAP * 2;
+ new StaticTextWidget(myTab, font, HBORDER, ypos + 1,
+ "When exiting emulation:");
+ ypos += lineHeight + VGAP;
+ mySaveOnExitGroup = new RadioButtonGroup();
+ r = new RadioButtonWidget(myTab, font, HBORDER + INDENT, ypos + 1,
+ "Save nothing", mySaveOnExitGroup);
+ wid.push_back(r);
+ ypos += lineHeight + VGAP;
+ r = new RadioButtonWidget(myTab, font, HBORDER + INDENT, ypos + 1,
+ "Save current state in current slot", mySaveOnExitGroup);
+ wid.push_back(r);
+ ypos += lineHeight + VGAP;
+ r = new RadioButtonWidget(myTab, font, HBORDER + INDENT, ypos + 1,
+ "Save all states", mySaveOnExitGroup);
+ wid.push_back(r);
+ ypos += lineHeight + VGAP;
+
// Add message concerning usage
const GUI::Font& infofont = instance().frameBuffer().infoFont();
ypos = myTab->getHeight() - 5 - fontHeight - infofont.getFontHeight() - 10;
@@ -625,6 +643,8 @@ void DeveloperDialog::loadSettings(SettingsSet set)
myUncompressed[set] = instance().settings().getInt(prefix + "tm.uncompressed");
myStateInterval[set] = instance().settings().getString(prefix + "tm.interval");
myStateHorizon[set] = instance().settings().getString(prefix + "tm.horizon");
+
+
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -813,6 +833,10 @@ void DeveloperDialog::loadConfig()
// Debug colours
handleDebugColours(instance().settings().getString("tia.dbgcolors"));
+ // Save on exit
+ string saveOnExit = instance().settings().getString("saveonexit");
+ mySaveOnExitGroup->setSelected(saveOnExit == "all" ? 2 : saveOnExit == "current" ? 1 : 0);
+
#ifdef DEBUGGER_SUPPORT
uInt32 w, h;
@@ -889,6 +913,11 @@ void DeveloperDialog::saveConfig()
instance().state().setRewindMode(myTimeMachineWidget->getState() ?
StateManager::Mode::TimeMachine : StateManager::Mode::Off);
+ // Save on exit
+ int saveOnExit = mySaveOnExitGroup->getSelected();
+ instance().settings().setValue("saveonexit",
+ saveOnExit == 0 ? "none" : saveOnExit == 1 ? "current" : "all");
+
#ifdef DEBUGGER_SUPPORT
// Debugger font style
instance().settings().setValue("dbg.fontstyle",
@@ -975,6 +1004,7 @@ void DeveloperDialog::setDefaults()
myStateHorizon[set] = devSettings ? "30s" : "10m";
setWidgetStates(set);
+ mySaveOnExitGroup->setSelected(0);
break;
case 4: // Debugger options
diff --git a/src/gui/DeveloperDialog.hxx b/src/gui/DeveloperDialog.hxx
index b327a7697..3f054123d 100644
--- a/src/gui/DeveloperDialog.hxx
+++ b/src/gui/DeveloperDialog.hxx
@@ -134,6 +134,7 @@ class DeveloperDialog : public Dialog
SliderWidget* myUncompressedWidget;
PopUpWidget* myStateIntervalWidget;
PopUpWidget* myStateHorizonWidget;
+ RadioButtonGroup* mySaveOnExitGroup;
#ifdef DEBUGGER_SUPPORT
// Debugger UI widgets