From c34e031d8c6da4ef3a9804c14817dbe3dbd1eec1 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 20 Jan 2022 22:27:15 -0800 Subject: [PATCH] GB, GBA: Save writeback-pending masked saves on unload (fixes #2396) --- CHANGES | 1 + src/gb/gb.c | 4 +++- src/gba/gba.c | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 0ead4fb8b..5399d1611 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ Emulation fixes: - GBA I/O: Disable open bus behavior on invalid register 06A Other fixes: - FFmpeg: Fix crash when encoding audio with some containers + - GB, GBA: Save writeback-pending masked saves on unload (fixes mgba.io/i/2396) 0.9.3: (2021-12-17) Emulation fixes: diff --git a/src/gb/gb.c b/src/gb/gb.c index ad3f3bbcb..a676ab99c 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -316,7 +316,9 @@ void GBUnloadROM(struct GB* gb) { gb->memory.mbcType = GB_MBC_AUTODETECT; gb->isPristine = false; - gb->sramMaskWriteback = false; + if (!gb->sramDirty) { + gb->sramMaskWriteback = false; + } GBSavedataUnmask(gb); GBSramDeinit(gb); if (gb->sramRealVf) { diff --git a/src/gba/gba.c b/src/gba/gba.c index 7ac7bbdf3..6ca0cfa3f 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -148,7 +148,9 @@ void GBAUnloadROM(struct GBA* gba) { gba->memory.rom = NULL; gba->isPristine = false; - gba->memory.savedata.maskWriteback = false; + if (!gba->memory.savedata.dirty) { + gba->memory.savedata.maskWriteback = false; + } GBASavedataUnmask(&gba->memory.savedata); GBASavedataDeinit(&gba->memory.savedata); if (gba->memory.savedata.realVf) {