Skip to content

Commit

Permalink
Save SRAM on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
NicknineTheEagle committed Apr 19, 2024
1 parent 9a96379 commit d473c20
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ const char* rs_name[ROM_SET_COUNT] = {
"JV880"
};

const char* rs_shortname[ROM_SET_COUNT] = {
"sc55mk2",
"sc55st",
"sc55mk1",
"cm300"
};

const char* roms[ROM_SET_COUNT][5] =
{
"rom1.bin",
Expand Down Expand Up @@ -1595,6 +1602,23 @@ int main(int argc, char *argv[])
fflush(stderr);
}

std::string sramPath = basePath + "/" + rs_shortname[romset] + "_sram.bin";
bool hasSram = (romset == ROM_SET_MK2 || romset == ROM_SET_MK1);

if (hasSram)
{
auto h = Files::utf8_fopen(sramPath.c_str(), "rb");
if (h)
{
if (fread(tempbuf, 1, SRAM_SIZE, h) == SRAM_SIZE)
{
printf("Loaded SRAM from %s\n", sramPath.c_str());
memcpy(sram, tempbuf, SRAM_SIZE);
}
fclose(h);
}
}

LCD_Init();
MCU_Init();
MCU_PatchROM();
Expand All @@ -1606,6 +1630,13 @@ int main(int argc, char *argv[])

MCU_Run();

if (hasSram)
{
auto h = Files::utf8_fopen(sramPath.c_str(), "wb");
fwrite(sram, 1, SRAM_SIZE, h);
fclose(h);
}

MCU_CloseAudio();
MIDI_Quit();
LCD_UnInit();
Expand Down

0 comments on commit d473c20

Please sign in to comment.