Skip to content

Commit acfb34f

Browse files
alsrgvclaude
authored andcommitted
sim: Persist calculator state on exit
The simulator already saves its state on EXIT_PGM (see src/dmcp/main.cc), but only when a state-file path has previously been configured by the user via the SETUP > State > Save menu. On a fresh install the path is empty, so closing the window silently discards all settings (Beep mode, display options, etc.) and stack contents. Default the persisted state-file path to "state/<PROGRAM_NAME>.48S" on first launch, so that exit reliably writes a state file and the next launch reliably restores it. Also honor STATE_IO_SILENT in state_load_callback. With the default path set, the first launch (when no state file exists yet) was popping up a "State load failed: No such file or directory" dialog; silent loads should be silent on missing files too. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Alex Sergeev <alexander.sergeev@live.com> Reviewed-by: Christophe de Dinechin <christophe@dinechin.org>
1 parent 7b4fd1b commit acfb34f

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This software was brought to you by the DB48X authors below
2121
- Mikael Djurfeldt <mikael@djurfeldt.com>
2222
- Pasquale Pigazzini <pasquale.pigazzini@gmail.com>
2323
- Wolf <wolfwings@wolfwings.us>
24+
- Alex Sergeev <alexander.sergeev@live.com>
2425

2526
Copyright (c) 2022-2025, the DB48X authors
2627

doc/0-Overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,8 @@ Additional contributors to the project include (in order of appearance):
843843
* Ralf Ahlbrink (raprism@users.noreply.github.com)
844844
* Mikael Djurfeldt (mikael@djurfeldt.com)
845845
* Pasquale Pigazzini (pasquale.pigazzini@gmail.com)
846-
* Wolf <wolfwings@wolfwings.us>
846+
* Wolf (wolfwings@wolfwings.us)
847+
- Alex Sergeev (alexander.sergeev@live.com)
847848

848849
The authors would like to acknowledge
849850

help/db48x.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,8 @@ Additional contributors to the project include (in order of appearance):
785785
* Ralf Ahlbrink (raprism@users.noreply.github.com)
786786
* Mikael Djurfeldt (mikael@djurfeldt.com)
787787
* Pasquale Pigazzini (pasquale.pigazzini@gmail.com)
788-
* Wolf <wolfwings@wolfwings.us>
788+
* Wolf (wolfwings@wolfwings.us)
789+
- Alex Sergeev (alexander.sergeev@live.com)
789790

790791
The authors would like to acknowledge
791792

help/db50x.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ Additional contributors to the project include (in order of appearance):
794794
* Ralf Ahlbrink (raprism@users.noreply.github.com)
795795
* Mikael Djurfeldt (mikael@djurfeldt.com)
796796
* Pasquale Pigazzini (pasquale.pigazzini@gmail.com)
797-
* Wolf <wolfwings@wolfwings.us>
797+
* Wolf (wolfwings@wolfwings.us)
798+
- Alex Sergeev (alexander.sergeev@live.com)
798799

799800
The authors would like to acknowledge
800801

sim/sim-window.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ MainWindow::MainWindow(QWidget *parent)
106106
QCoreApplication::setOrganizationName("DB48X");
107107
QCoreApplication::setApplicationName(PROGRAM_NAME);
108108

109+
// Default the persisted state file path on first run, so that the RPL
110+
// engine's EXIT_PGM handler in main.cc actually writes a state file
111+
// (it's a no-op when no path has been configured). The file lives
112+
// under the app data dir; QDir::setCurrent() is already pointed there.
113+
if (ui_read_setting("state", nullptr, 0) == 0)
114+
{
115+
QString defaultPath = QString("state/") + PROGRAM_NAME + ".48S";
116+
ui_save_setting("state", defaultPath.toUtf8().constData());
117+
}
118+
109119
ui.setupUi(this);
110120

111121
// Disable automatic layout management for manual control

src/dmcp/sysmenu.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,11 @@ static int state_load_callback(cstring path, cstring name, void *data)
395395
file prog(path, file::READING);
396396
if (!prog.valid())
397397
{
398-
ui.draw_message("State load failed", prog.error(), name);
399-
wait_for_key_press();
398+
if (!is_silent)
399+
{
400+
ui.draw_message("State load failed", prog.error(), name);
401+
wait_for_key_press();
402+
}
400403
return 1;
401404
}
402405

0 commit comments

Comments
 (0)