all repos — mgba @ 34647ffdca68da94f4fb5b51df4a8dc43758ad77

mGBA Game Boy Advance Emulator

GB: Trust ROM header for number of SRAM banks (fixes #726)
Vicki Pfau vi@endrift.com
Tue, 13 Jun 2017 21:14:20 -0700
commit

34647ffdca68da94f4fb5b51df4a8dc43758ad77

parent

655807441ac42be7ee5220bdab21cc7f4dbe701b

2 files changed, 6 insertions(+), 1 deletions(-)

jump to
M CHANGESCHANGES

@@ -133,6 +133,7 @@ - Core: List memory segments in the core

- Core: Move savestate creation time to extdata - Debugger: Add mDebuggerRunFrame convenience function - GBA Memory: Remove unused prefetch cruft + - GB: Trust ROM header for number of SRAM banks (fixes mgba.io/i/726) 0.5.2: (2016-12-31) Bugfixes:
M src/gb/mbc.csrc/gb/mbc.c

@@ -79,7 +79,11 @@ }

void GBMBCSwitchSramBank(struct GB* gb, int bank) { size_t bankStart = bank * GB_SIZE_EXTERNAL_RAM; - GBResizeSram(gb, (bank + 1) * GB_SIZE_EXTERNAL_RAM); + if (bankStart + GB_SIZE_EXTERNAL_RAM > gb->sramSize) { + mLOG(GB_MBC, GAME_ERROR, "Attempting to switch to an invalid RAM bank: %0X", bank); + bankStart &= (gb->sramSize - 1); + bank = bankStart / GB_SIZE_EXTERNAL_RAM; + } gb->memory.sramBank = &gb->memory.sram[bankStart]; gb->memory.sramCurrentBank = bank; }