GB Memory: Fix bank switching overflow case

This commit is contained in:
Jeffrey Pfau 2016-02-07 09:16:25 -08:00
parent 1425db6a7a
commit b782d902e6
1 changed files with 2 additions and 1 deletions

View File

@ -314,7 +314,8 @@ static void _switchBank(struct GBMemory* memory, int bank) {
size_t bankStart = bank * GB_SIZE_CART_BANK0; size_t bankStart = bank * GB_SIZE_CART_BANK0;
if (bankStart + GB_SIZE_CART_BANK0 > memory->romSize) { if (bankStart + GB_SIZE_CART_BANK0 > memory->romSize) {
mLOG(GB_MBC, GAME_ERROR, "Attempting to switch to an invalid ROM bank: %0X", bank); 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->romBank = &memory->rom[bankStart];
memory->currentBank = bank; memory->currentBank = bank;