diff options
author | Raphaël Zumer <rzumer@tebako.net> | 2019-12-22 15:49:23 -0500 |
---|---|---|
committer | Raphaël Zumer <rzumer@tebako.net> | 2019-12-22 16:01:13 -0500 |
commit | 22d11209b0466e3c852da543ddfc512b66735bc2 (patch) | |
tree | 3539a080f103cec24bee6880d679e8aaa37a9271 /src/libui_sdl | |
parent | f380767fab219df087488a4e4e8a5eab47efb94c (diff) |
Split GBA Reset and Eject logic into two sets
This allows solving some crashes and provides more
flexibility in how GBA cartridges change state between
soft and hard resets. Since save states including GBA
data do not carry over the original save file path,
and the GBA cartridge is being reset along with the other
parts of the system, this is needed to avoid losing
the GBA state on reset following a state load, while
preserving the behavior where cartridges are ejected
when calling Stop().
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/main.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 38804f6..af69f8e 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -1694,6 +1694,7 @@ void Stop(bool internal) RunningSomething = false; // eject any inserted GBA cartridge + GBACart::Eject(); ROMPath[1][0] = '\0'; uiWindowSetTitle(MainWindow, "melonDS " MELONDS_VERSION); @@ -1834,6 +1835,8 @@ void LoadState(int slot) return; } + u32 oldGBACartCRC = GBACart::CartCRC; + // backup Savestate* backup = new Savestate("timewarp.mln", true); NDS::DoSavestate(backup); @@ -1870,9 +1873,24 @@ void LoadState(int slot) NDS::RelocateSave(SRAMPath[0], false); } + bool loadedPartialGBAROM = false; + + // in case we have a GBA cart inserted, and the GBA ROM changes + // due to having loaded a save state, we do not want to reload + // the previous cartridge on reset, or commit writes to any + // loaded save file. therefore, their paths are "nulled". + if (GBACart::CartInserted && GBACart::CartCRC != oldGBACartCRC) + { + ROMPath[1][0] = '\0'; + SRAMPath[1][0] = '\0'; + loadedPartialGBAROM = true; + } + char msg[64]; - if (slot > 0) sprintf(msg, "State loaded from slot %d", slot); - else sprintf(msg, "State loaded from file"); + if (slot > 0) sprintf(msg, "State loaded from slot %d%s", + slot, loadedPartialGBAROM ? " (GBA ROM header only)" : ""); + else sprintf(msg, "State loaded from file%s", + loadedPartialGBAROM ? " (GBA ROM header only)" : ""); OSD::AddMessage(0, msg); SavestateLoaded = true; |