GB MBC: Fix switching bank 0
Vicki Pfau vi@endrift.com
Wed, 01 Aug 2018 08:41:18 -0700
1 files changed,
9 insertions(+),
4 deletions(-)
jump to
M
src/gb/mbc.c
→
src/gb/mbc.c
@@ -61,7 +61,7 @@ }
} void GBMBCSwitchBank0(struct GB* gb, int bank) { - size_t bankStart = bank * GB_SIZE_CART_BANK0 << gb->memory.mbcState.mbc1.multicartStride; + size_t bankStart = bank * GB_SIZE_CART_BANK0; if (bankStart + GB_SIZE_CART_BANK0 > gb->memory.romSize) { mLOG(GB_MBC, GAME_ERROR, "Attempting to switch to an invalid ROM bank: %0X", bank); bankStart &= (gb->memory.romSize - 1);@@ -407,7 +407,7 @@ break;
case 0x2: bank &= 3; if (memory->mbcState.mbc1.mode) { - GBMBCSwitchBank0(gb, bank); + GBMBCSwitchBank0(gb, bank << gb->memory.mbcState.mbc1.multicartStride); GBMBCSwitchSramBank(gb, bank); } GBMBCSwitchBank(gb, (bank << memory->mbcState.mbc1.multicartStride) | (memory->currentBank & (stride - 1)));@@ -415,7 +415,7 @@ break;
case 0x3: memory->mbcState.mbc1.mode = value & 1; if (memory->mbcState.mbc1.mode) { - GBMBCSwitchBank0(gb, memory->currentBank >> memory->mbcState.mbc1.multicartStride); + GBMBCSwitchBank0(gb, memory->currentBank & ~((1 << memory->mbcState.mbc1.multicartStride) - 1)); } else { GBMBCSwitchBank0(gb, 0); GBMBCSwitchSramBank(gb, 0);@@ -844,7 +844,12 @@ memory->mbcState.mmm01.locked = true;
GBMBCSwitchBank0(gb, memory->mbcState.mmm01.currentBank0); break; case 0x1: - memory->mbcState.mmm01.currentBank0 = value & 0x3F; + memory->mbcState.mmm01.currentBank0 &= ~0x7F; + memory->mbcState.mmm01.currentBank0 |= value & 0x7F; + break; + case 0x2: + memory->mbcState.mmm01.currentBank0 &= ~0x180; + memory->mbcState.mmm01.currentBank0 |= (value & 0x30) << 3; break; default: // TODO