From 16a3a977dd208bf8b7a942b89eb6aaf23f6aa9d2 Mon Sep 17 00:00:00 2001
From: Thomas Jentzsch
Use "autoSave" to automatically execute the "save" command when + exiting the debugger.
Note: While "save" is ROM specific, you can also create a file called "autoexec.script" which will be loaded when the debugger starts, no matter what ROM you have loaded.
@@ -927,6 +930,7 @@ Type "help 'cmd'" to see extended information about the given command.
a - Set Accumulator to <value> aud - Mark 'AUD' range in disassembly + autoSave - Automatically execute "save" when exiting the debugger base - Set default number base to <base> (bin, dec, hex) bCol - Mark 'BCOL' range in disassembly break - Set/clear breakpoint at <address> and <bank> @@ -997,7 +1001,7 @@ clearSaveStateIfs - Clear all saveState points runTo - Run until string xx in disassembly runToPc - Run until PC is set to value xx s - Set Stack Pointer to value xx - save - Save breaks, watches, traps and functions to file+ save - Save breaks, watches, traps and functions to file [xx or ?] saveAccess - Save access counters to CSV file [?] saveConfig - Save DiStella config file (with default name) saveDis - Save DiStella disassembly to file [?] diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 811f11c59..54fdbbeec 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -153,6 +153,9 @@ bool Debugger::startWithFatalError(const string& message) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Debugger::quit(bool exitrom) { + if(myOSystem.settings().getBool("dbg.autosave")) + myParser->run("save"); + if(exitrom) myOSystem.eventHandler().handleEvent(Event::ExitGame); else @@ -173,7 +176,8 @@ string Debugger::autoExec(StringList* history) << myParser->exec(autoexec, history) << endl; // Also, "romname.script" if present - FilesystemNode romname(myOSystem.romFile().getPathWithExt(".script")); + const string path = myOSystem.userDir().getPath() + myOSystem.romFile().getNameWithExt(".script"); + FilesystemNode romname(path); buf << myParser->exec(romname, history) << endl; // Init builtins diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index 94f9139c6..d6df6bde6 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -758,6 +758,16 @@ void DebuggerParser::executeAud() executeDirective(Device::AUD); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// "autoSave" +void DebuggerParser::executeAutoSave() +{ + bool enable = !settings.getBool("dbg.autosave"); + + settings.setValue("dbg.autosave", enable); + commandResult << "autoSave " << (enable ? "enabled" : "disabled"); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // "base" void DebuggerParser::executeBase() @@ -1910,24 +1920,29 @@ void DebuggerParser::executeS() // "save" void DebuggerParser::executeSave() { - if(argCount && argStrings[0] == "?") - { - DebuggerDialog* dlg = debugger.myDialog; + DebuggerDialog* dlg = debugger.myDialog; + const string fileName = dlg->instance().userDir().getPath() + cartName() + ".script"; - BrowserDialog::show(dlg, "Save Workbench as", - dlg->instance().userDir().getPath() + cartName() + ".script", - BrowserDialog::Mode::FileSave, - [this, dlg](bool OK, const FilesystemNode& node) + if(argCount) + { + if(argStrings[0] == "?") { - if(OK) - dlg->prompt().print(saveScriptFile(node.getPath()) + '\n'); - dlg->prompt().printPrompt(); - }); - // avoid printing a new prompt - commandResult.str("_NO_PROMPT"); + BrowserDialog::show(dlg, "Save Workbench as", fileName, + BrowserDialog::Mode::FileSave, + [this, dlg](bool OK, const FilesystemNode& node) + { + if(OK) + dlg->prompt().print(saveScriptFile(node.getPath()) + '\n'); + dlg->prompt().printPrompt(); + }); + // avoid printing a new prompt + commandResult.str("_NO_PROMPT"); + } + else + commandResult << saveScriptFile(argStrings[0]); } else - commandResult << saveScriptFile(argStrings[0]); + commandResult << saveScriptFile(fileName); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2516,6 +2531,16 @@ DebuggerParser::CommandArray DebuggerParser::commands = { { std::mem_fn(&DebuggerParser::executeAud) }, + { + "autoSave", + "Toggle automatic saving of commands (see 'save')", + "Example: autoSave (no parameters)", + false, + true, + { Parameters::ARG_END_ARGS }, + std::mem_fn(&DebuggerParser::executeAutoSave) + }, + { "base", "Set default number base to ", @@ -3230,10 +3255,10 @@ DebuggerParser::CommandArray DebuggerParser::commands = { { { "save", - "Save breaks, watches, traps and functions to file ", - "Example: save commands.script, save ?\n" + "Save breaks, watches, traps and functions to file [xx or ?]", + "Example: save, save commands.script, save ?\n" "NOTE: saves to user dir by default", - true, + false, false, { Parameters::ARG_FILE, Parameters::ARG_END_ARGS }, std::mem_fn(&DebuggerParser::executeSave) diff --git a/src/debugger/DebuggerParser.hxx b/src/debugger/DebuggerParser.hxx index 89cea1abe..e69069f66 100644 --- a/src/debugger/DebuggerParser.hxx +++ b/src/debugger/DebuggerParser.hxx @@ -101,7 +101,7 @@ class DebuggerParser std::array parms; std::function executor; }; - using CommandArray = std::array ; + using CommandArray = std::array ; static CommandArray commands; struct Trap @@ -150,6 +150,7 @@ class DebuggerParser // List of available command methods void executeA(); void executeAud(); + void executeAutoSave(); void executeBase(); void executeBCol(); void executeBreak(); diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index 2b27a2c5b..ef055e817 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -386,8 +386,22 @@ void PromptWidget::loadConfig() print(instance().debugger().cartDebug().loadConfigFile() + "\n"); print(instance().debugger().cartDebug().loadListFile() + "\n"); print(instance().debugger().cartDebug().loadSymbolFile() + "\n"); + + bool extra = false; + if(instance().settings().getBool("dbg.autosave")) + { + print(DebuggerParser::inverse(" autoSave enabled ")); + print("\177 "); // must switch inverse here! + extra = true; + } if(instance().settings().getBool("dbg.logbreaks")) - print(DebuggerParser::inverse(" logBreaks enabled \n")); + { + print(DebuggerParser::inverse(" logBreaks enabled ")); + extra = true; + } + if(extra) + print("\n"); + print(PROMPT); _promptStartPos = _promptEndPos = _currentPos; diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 81880794a..9f0cc5055 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -189,6 +189,7 @@ Settings::Settings() setPermanent("dbg.uhex", "false"); setPermanent("dbg.ghostreadstrap", "true"); setPermanent("dbg.logbreaks", "false"); + setPermanent("dbg.autosave", "false"); setPermanent("dis.resolve", "true"); setPermanent("dis.gfxformat", "2"); setPermanent("dis.showaddr", "true"); @@ -614,8 +615,9 @@ void Settings::usage() const << " -dbg.fontstyle <0-3> Font style to use in debugger window (bold vs.\n" << " normal)\n" << " -dbg.ghostreadstrap <1|0> Debugger traps on 'ghost' reads\n" - << " -dbg.uhex <0|1> lower-/uppercase HEX display\n" - << " -dbg.logbreaks <0|1> log breaks and traps and continue emulation\n" + << " -dbg.uhex <0|1> Lower-/uppercase HEX display\n" + << " -dbg.logbreaks <0|1> Log breaks and traps and continue emulation\n" + << " -dbg.autosave <0|1> Automatically save breaks, traps etc.\n" << " -break Set a breakpoint at 'address'\n" << " -debug Start in debugger mode\n" << endl