diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 54fdbbeec..80835e4ba 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -26,6 +26,7 @@ #include "FSNode.hxx" #include "Settings.hxx" #include "DebuggerDialog.hxx" +#include "PromptWidget.hxx" #include "DebuggerParser.hxx" #include "StateManager.hxx" #include "RewindManager.hxx" @@ -151,11 +152,16 @@ bool Debugger::startWithFatalError(const string& message) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Debugger::quit(bool exitrom) +void Debugger::quit() { - if(myOSystem.settings().getBool("dbg.autosave")) + if(myOSystem.settings().getBool("dbg.autosave") + && myDialog->prompt().isLoaded()) myParser->run("save"); +} +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Debugger::exit(bool exitrom) +{ if(exitrom) myOSystem.eventHandler().handleEvent(Event::ExitGame); else diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 14c657de2..25feebeab 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -102,7 +102,12 @@ class Debugger : public DialogContainer Wrapper method for EventHandler::leaveDebugMode() for those classes that don't have access to EventHandler. */ - void quit(bool exitrom); + void exit(bool exitrom); + + /** + Executed when debugger is quit. + */ + void quit(); bool addFunction(const string& name, const string& def, Expression* exp, bool builtin = false); diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index d6df6bde6..4ffce742a 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -153,7 +153,7 @@ string DebuggerParser::exec(const FilesystemNode& file, StringList* history) history->push_back(command); count++; } - buf << "\nExecuted " << count << " commands from \"" + buf << "\nExecuted " << count << " command" << (count != 1 ? "s" : "") << " from \"" << file.getShortPath() << "\""; return buf.str(); @@ -1332,7 +1332,7 @@ void DebuggerParser::executeExec() // "exitRom" void DebuggerParser::executeExitRom() { - debugger.quit(true); + debugger.exit(true); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1690,7 +1690,7 @@ void DebuggerParser::executeLogBreaks() bool enable = !debugger.mySystem.m6502().getLogBreaks(); debugger.mySystem.m6502().setLogBreaks(enable); - settings.setValue("dbg.logBreaks", enable); + settings.setValue("dbg.logbreaks", enable); commandResult << "logBreaks " << (enable ? "enabled" : "disabled"); } @@ -1814,7 +1814,7 @@ void DebuggerParser::executeRow() void DebuggerParser::executeRun() { debugger.saveOldState(); - debugger.quit(false); + debugger.exit(false); commandResult << "_EXIT_DEBUGGER"; // See PromptWidget for more info } diff --git a/src/debugger/gui/PromptWidget.hxx b/src/debugger/gui/PromptWidget.hxx index bf96f935a..852c8fd85 100644 --- a/src/debugger/gui/PromptWidget.hxx +++ b/src/debugger/gui/PromptWidget.hxx @@ -46,13 +46,15 @@ class PromptWidget : public Widget, public CommandSender void printPrompt(); string saveBuffer(const FilesystemNode& file); - // Clear screen + // Clear screen void clearScreen(); // Erase all history void clearHistory(); void addToHistory(const char *str); + bool isLoaded() const { return !_firstTime; } + protected: ATTRIBUTE_FMT_PRINTF int printf(const char* format, ...); ATTRIBUTE_FMT_PRINTF int vprintf(const char* format, va_list argptr); diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 165510ffc..55ff715bd 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -54,6 +54,7 @@ #endif #ifdef DEBUGGER_SUPPORT #include "Debugger.hxx" + #include "DebuggerParser.hxx" #endif #ifdef GUI_SUPPORT #include "Menu.hxx" @@ -2996,12 +2997,15 @@ void EventHandler::exitEmulation(bool checkLauncher) const bool activeTM = myOSystem.settings().getBool( myOSystem.settings().getBool("dev.settings") ? "dev.timemachine" : "plr.timemachine"); - if (saveOnExit == "all" && activeTM) handleEvent(Event::SaveAllStates); else if (saveOnExit == "current") handleEvent(Event::SaveState); +#if DEBUGGER_SUPPORT + myOSystem.debugger().quit(); +#endif + if (checkLauncher) { // Go back to the launcher, or immediately quit