diff --git a/Core/debugger.c b/Core/debugger.c index 71f0861e..8e7151b4 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -1420,15 +1420,20 @@ static bool mbc(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg } if (cartridge->mbc_type) { - static const char * const mapper_names[] = { - [GB_MBC1] = "MBC1", - [GB_MBC2] = "MBC2", - [GB_MBC3] = "MBC3", - [GB_MBC5] = "MBC5", - [GB_HUC1] = "HUC1", - [GB_HUC3] = "HUC3", - }; - GB_log(gb, "%s\n", mapper_names[cartridge->mbc_type]); + if (gb->is_mbc30) { + GB_log(gb, "MBC30\n"); + } + else { + static const char *const mapper_names[] = { + [GB_MBC1] = "MBC1", + [GB_MBC2] = "MBC2", + [GB_MBC3] = "MBC3", + [GB_MBC5] = "MBC5", + [GB_HUC1] = "HUC1", + [GB_HUC3] = "HUC3", + }; + GB_log(gb, "%s\n", mapper_names[cartridge->mbc_type]); + } GB_log(gb, "Current mapped ROM bank: %x\n", gb->mbc_rom_bank); if (cartridge->has_ram) { GB_log(gb, "Current mapped RAM bank: %x\n", gb->mbc_ram_bank); diff --git a/Core/gb.h b/Core/gb.h index b4ef6580..0b188d62 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -403,9 +403,8 @@ struct GB_gameboy_internal_s { } mbc2; struct { - uint8_t rom_bank:7; - uint8_t padding:1; - uint8_t ram_bank:4; + uint8_t rom_bank:8; + uint8_t ram_bank:3; } mbc3; struct { @@ -538,6 +537,7 @@ struct GB_gameboy_internal_s { GB_STANDARD_MBC1_WIRING, GB_MBC1M_WIRING, } mbc1_wiring; + bool is_mbc30; unsigned pending_cycles; diff --git a/Core/mbc.c b/Core/mbc.c index d3791a18..2a96219d 100644 --- a/Core/mbc.c +++ b/Core/mbc.c @@ -86,6 +86,10 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) case GB_MBC3: gb->mbc_rom_bank = gb->mbc3.rom_bank; gb->mbc_ram_bank = gb->mbc3.ram_bank; + if (!gb->is_mbc30) { + gb->mbc_rom_bank &= 0x7F; + gb->mbc_ram_bank &= 0x3; + } if (gb->mbc_rom_bank == 0) { gb->mbc_rom_bank = 1; } @@ -147,6 +151,13 @@ void GB_configure_cart(GB_gameboy_t *gb) } } + /* Detect MBC30 */ + if (gb->cartridge_type->mbc_type == GB_MBC3) { + if (gb->rom_size > 0x200000 || gb->mbc_ram_size > 0x8000) { + gb->is_mbc30 = true; + } + } + /* Set MBC5's bank to 1 correctly */ if (gb->cartridge_type->mbc_type == GB_MBC5) { gb->mbc5.rom_bank_low = 1;