all repos — mgba @ b782d902e63e7046b2a0f6b32cb129ef328fe9c2

mGBA Game Boy Advance Emulator

GB Memory: Fix bank switching overflow case
Jeffrey Pfau jeffrey@endrift.com
Sun, 07 Feb 2016 09:16:25 -0800
commit

b782d902e63e7046b2a0f6b32cb129ef328fe9c2

parent

1425db6a7a4c8b1c31c15062ee6c7c1dc32627cf

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

jump to
M src/gb/memory.csrc/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;