GB Memory: Fix bank switching overflow case
Jeffrey Pfau jeffrey@endrift.com
Sun, 07 Feb 2016 09:16:25 -0800
1 files changed,
2 insertions(+),
1 deletions(-)
jump to
M
src/gb/memory.c
→
src/gb/memory.c
@@ -314,7 +314,8 @@ static void _switchBank(struct GBMemory* memory, int bank) {
size_t bankStart = bank * GB_SIZE_CART_BANK0; if (bankStart + GB_SIZE_CART_BANK0 > memory->romSize) { mLOG(GB_MBC, GAME_ERROR, "Attempting to switch to an invalid ROM bank: %0X", bank); - return; + bankStart &= (GB_SIZE_CART_BANK0 - 1); + bank /= GB_SIZE_CART_BANK0; } memory->romBank = &memory->rom[bankStart]; memory->currentBank = bank;