GB, GBA Savedata: Fix savestate-related save overwriting (fixes #834)

This commit is contained in:
Vicki Pfau 2017-08-04 12:42:10 -07:00
parent 30db4ebee8
commit c030fb656f
3 changed files with 9 additions and 1 deletions

View File

@ -25,6 +25,7 @@ Bugfixes:
- GB MBC: Fix RTC loading when file size is off - GB MBC: Fix RTC loading when file size is off
- GB Serialize: Fix deserializing video STAT - GB Serialize: Fix deserializing video STAT
- Qt: Fix GL display when loading a game from CLI (fixes mgba.io/i/843) - Qt: Fix GL display when loading a game from CLI (fixes mgba.io/i/843)
- GB, GBA Savedata: Fix savestate-related save overwriting (fixes mgba.io/i/834)
Misc: Misc:
- GBA Timer: Use global cycles for timers - GBA Timer: Use global cycles for timers
- GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722) - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)

View File

@ -220,7 +220,7 @@ void GBResizeSram(struct GB* gb, size_t size) {
void GBSramClean(struct GB* gb, uint32_t frameCount) { void GBSramClean(struct GB* gb, uint32_t frameCount) {
// TODO: Share with GBASavedataClean // TODO: Share with GBASavedataClean
if (!gb->sramVf || gb->sramVf != gb->sramRealVf) { if (!gb->sramVf) {
return; return;
} }
if (gb->sramDirty & GB_SRAM_DIRT_NEW) { if (gb->sramDirty & GB_SRAM_DIRT_NEW) {
@ -230,6 +230,9 @@ void GBSramClean(struct GB* gb, uint32_t frameCount) {
gb->sramDirty |= GB_SRAM_DIRT_SEEN; gb->sramDirty |= GB_SRAM_DIRT_SEEN;
} }
} else if ((gb->sramDirty & GB_SRAM_DIRT_SEEN) && frameCount - gb->sramDirtAge > CLEANUP_THRESHOLD) { } else if ((gb->sramDirty & GB_SRAM_DIRT_SEEN) && frameCount - gb->sramDirtAge > CLEANUP_THRESHOLD) {
if (gb->sramMaskWriteback) {
GBSavedataUnmask(gb);
}
if (gb->memory.mbcType == GB_MBC3_RTC) { if (gb->memory.mbcType == GB_MBC3_RTC) {
GBMBCRTCWrite(gb); GBMBCRTCWrite(gb);
} }
@ -259,7 +262,9 @@ void GBSavedataUnmask(struct GB* gb) {
gb->sramVf = gb->sramRealVf; gb->sramVf = gb->sramRealVf;
gb->memory.sram = gb->sramVf->map(gb->sramVf, gb->sramSize, MAP_WRITE); gb->memory.sram = gb->sramVf->map(gb->sramVf, gb->sramSize, MAP_WRITE);
if (gb->sramMaskWriteback) { if (gb->sramMaskWriteback) {
vf->seek(vf, 0, SEEK_SET);
vf->read(vf, gb->memory.sram, gb->sramSize); vf->read(vf, gb->memory.sram, gb->sramSize);
gb->sramMaskWriteback = false;
} }
vf->close(vf); vf->close(vf);
} }
@ -287,6 +292,7 @@ void GBUnloadROM(struct GB* gb) {
gb->memory.mbcType = GB_MBC_AUTODETECT; gb->memory.mbcType = GB_MBC_AUTODETECT;
gb->isPristine = false; gb->isPristine = false;
gb->sramMaskWriteback = false;
GBSavedataUnmask(gb); GBSavedataUnmask(gb);
GBSramDeinit(gb); GBSramDeinit(gb);
if (gb->sramRealVf) { if (gb->sramRealVf) {

View File

@ -92,6 +92,7 @@ void GBAMemoryDeinit(struct GBA* gba) {
if (gba->memory.rom) { if (gba->memory.rom) {
mappedMemoryFree(gba->memory.rom, gba->memory.romSize); mappedMemoryFree(gba->memory.rom, gba->memory.romSize);
} }
gba->memory.savedata.maskWriteback = false;
GBASavedataUnmask(&gba->memory.savedata); GBASavedataUnmask(&gba->memory.savedata);
GBASavedataDeinit(&gba->memory.savedata); GBASavedataDeinit(&gba->memory.savedata);
if (gba->memory.savedata.realVf) { if (gba->memory.savedata.realVf) {