diff --git a/CHANGES b/CHANGES index 0cb5eaafa..b4b1cccf3 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,7 @@ Emulation fixes: - 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 diff --git a/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_ramg/baseline_0000.png b/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_ramg/baseline_0000.png new file mode 100644 index 000000000..f9e5e47b5 Binary files /dev/null and b/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_ramg/baseline_0000.png differ diff --git a/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_ramg/config.ini b/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_ramg/config.ini index 7ddee425b..7f44b56a9 100644 --- a/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_ramg/config.ini +++ b/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_ramg/config.ini @@ -1,2 +1,2 @@ [testinfo] -fail=1 +skip=360 diff --git a/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_romb/baseline_0000.png b/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_romb/baseline_0000.png new file mode 100644 index 000000000..f9e5e47b5 Binary files /dev/null and b/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_romb/baseline_0000.png differ diff --git a/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_romb/config.ini b/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_romb/config.ini index 7ddee425b..7f44b56a9 100644 --- a/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_romb/config.ini +++ b/cinema/gb/mooneye-gb/emulator-only/mbc2/bits_romb/config.ini @@ -1,2 +1,2 @@ [testinfo] -fail=1 +skip=360 diff --git a/src/gb/mbc.c b/src/gb/mbc.c index 8417c2102..ca94cb534 100644 --- a/src/gb/mbc.c +++ b/src/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 @@ void _GBMBC2(struct GB* gb, uint16_t address, uint8_t value) { 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 @@ void _GBMBC2(struct GB* gb, uint16_t address, uint8_t value) { } GBMBCSwitchBank(gb, bank); break; - case 0x5: + case 0x80: + case 0x81: + case 0x82: + case 0x83: if (!memory->sramAccess) { return; } @@ -517,6 +520,9 @@ void _GBMBC2(struct GB* gb, uint16_t address, uint8_t value) { } 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;