all repos — mgba @ 1402593855729beaca177d43700eb462bd8c123d

mGBA Game Boy Advance Emulator

GB MBC: Fix MBC2 bit selection
Vicki Pfau vi@endrift.com
Tue, 16 Jun 2020 20:49:07 -0700
commit

1402593855729beaca177d43700eb462bd8c123d

parent

c487b0cf4336ac373b95e2cf5518e27de65dab5d

M CHANGESCHANGES

@@ -7,6 +7,7 @@ - ARM: Fix ALU reading PC after shifting

- ARM: Fix STR storing PC after address calculation - GB MBC: Fix MBC1 mode changing behavior - GB MBC: Fix MBC1 RAM enable bit selection + - GB MBC: Fix MBC2 bit selection - GB Video: Fix state after skipping BIOS (fixes mgba.io/i/1715 and mgba.io/i/1716) - GBA: Fix timing advancing too quickly in rare cases - GBA BIOS: Implement dummy sound driver calls
M src/gb/mbc.csrc/gb/mbc.c

@@ -480,9 +480,9 @@ void _GBMBC2(struct GB* gb, uint16_t address, uint8_t value) {

struct GBMemory* memory = &gb->memory; int shift = (address & 1) * 4; int bank = value & 0xF; - switch (address >> 13) { + switch ((address & 0xC100) >> 8) { case 0x0: - switch (value) { + switch (value & 0x0F) { case 0: memory->sramAccess = false; break;

@@ -491,7 +491,7 @@ memory->sramAccess = true;

break; default: // TODO - mLOG(GB_MBC, STUB, "MBC1 unknown value %02X", value); + mLOG(GB_MBC, STUB, "MBC2 unknown value %02X", value); break; } break;

@@ -501,7 +501,10 @@ ++bank;

} GBMBCSwitchBank(gb, bank); break; - case 0x5: + case 0x80: + case 0x81: + case 0x82: + case 0x83: if (!memory->sramAccess) { return; }

@@ -517,6 +520,9 @@ }

} static uint8_t _GBMBC2Read(struct GBMemory* memory, uint16_t address) { + if (!memory->sramAccess) { + return 0xFF; + } address &= 0x1FF; int shift = (address & 1) * 4; return (memory->sramBank[(address >> 1)] >> shift) | 0xF0;