Skip to content

Commit

Permalink
SRAM: Do not save SRAM if unmodified.
Browse files Browse the repository at this point in the history
Previously SRAM always created a file in the `persistent` folder, even if its
initial contents were never modified. This change only creates the file if the
SRAM contents are actually modified.

A case where this was particularly bothersome are mappers backed by Flash ROM.
It would copy the passed ROM to SRAM and then persist it, and the next time you
ran openMSX with an updated ROM (e.g. during development) it would ignore its
contents entirely. The user has to manually delete the SRAM file.

With this change, the latter situation can still occur, but only if the Flash
ROM is being written to (e.g. for a savegame).

Also remove the ”SRAM file not found, assuming blank content” message, since it
is quite noisy in general and in this case would show up even more frequently.

In the future if we would want to reintroduce a message of some kind to indicate
the creation of a persistent file, we could consider setting a flag when
FileNotFoundException occurs, and then in `SRAM::write()` check for that flag
and print a message about creating the SRAM file.
  • Loading branch information
grauw committed May 20, 2024
1 parent 721fc7e commit f1bbc93
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/memory/SRAM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ SRAM::SRAM(const std::string& name, static_string_view description, size_t size,

SRAM::~SRAM()
{
if (schedulable) {
if (schedulable && schedulable->isPendingRT()) {
schedulable->cancelRT();
save();
}
}
Expand Down Expand Up @@ -102,9 +103,7 @@ void SRAM::load(bool* loaded)
"Warning no correct SRAM file: ", filename);
}
} catch (FileNotFoundException& /*e*/) {
config.getCliComm().printInfo(
"SRAM file ", filename, " not found, "
"assuming blank SRAM content.");
// SRAM file not found, assuming blank SRAM content.
} catch (FileException& e) {
config.getCliComm().printWarning(
"Couldn't load SRAM ", filename,
Expand Down

0 comments on commit f1bbc93

Please sign in to comment.