Skip to content

Commit

Permalink
Fixed MBC2 implementation (#36)
Browse files Browse the repository at this point in the history
MBC2 only uses bit 8 to check between RAM enable and ROM bank, when writing to address < 0x4000. Both pandocs and sameboy agree on this.
  • Loading branch information
daid authored Sep 14, 2020
1 parent 146ae67 commit cb34848
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,23 +1234,16 @@ static void mbc1m_write_rom(Emulator* e, MaskedAddress addr, u8 value) {
}

static void mbc2_write_rom(Emulator* e, MaskedAddress addr, u8 value) {
switch (addr >> 13) {
case 0: /* 0000-1fff */
if ((addr & MBC2_ADDR_SELECT_BIT_MASK) == 0) {
MMAP_STATE.ext_ram_enabled =
(value & MBC_RAM_ENABLED_MASK) == MBC_RAM_ENABLED_VALUE;
}
break;
case 1: { /* 2000-3fff */
u16 rom1_bank;
if ((addr & MBC2_ADDR_SELECT_BIT_MASK) != 0) {
rom1_bank = value & MBC2_ROM_BANK_SELECT_MASK & ROM_BANK_MASK(e);
if (rom1_bank == 0) {
rom1_bank++;
}
set_rom_bank(e, 1, rom1_bank);
if (addr < 0x4000) {
if ((addr & MBC2_ADDR_SELECT_BIT_MASK) != 0) {
u16 rom1_bank = value & MBC2_ROM_BANK_SELECT_MASK & ROM_BANK_MASK(e);
if (rom1_bank == 0) {
rom1_bank++;
}
break;
set_rom_bank(e, 1, rom1_bank);
} else {
MMAP_STATE.ext_ram_enabled =
(value & MBC_RAM_ENABLED_MASK) == MBC_RAM_ENABLED_VALUE;
}
}
}
Expand Down

0 comments on commit cb34848

Please sign in to comment.