Proper MBC30 support, more accurate MBC3 emulation. Fixes #244

This commit is contained in:
Lior Halphon 2020-04-08 19:07:29 +03:00
parent d75b7c0023
commit 0ed5cf6b38
3 changed files with 28 additions and 12 deletions

View File

@ -1420,6 +1420,10 @@ static bool mbc(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg
} }
if (cartridge->mbc_type) { if (cartridge->mbc_type) {
if (gb->is_mbc30) {
GB_log(gb, "MBC30\n");
}
else {
static const char *const mapper_names[] = { static const char *const mapper_names[] = {
[GB_MBC1] = "MBC1", [GB_MBC1] = "MBC1",
[GB_MBC2] = "MBC2", [GB_MBC2] = "MBC2",
@ -1429,6 +1433,7 @@ static bool mbc(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg
[GB_HUC3] = "HUC3", [GB_HUC3] = "HUC3",
}; };
GB_log(gb, "%s\n", mapper_names[cartridge->mbc_type]); GB_log(gb, "%s\n", mapper_names[cartridge->mbc_type]);
}
GB_log(gb, "Current mapped ROM bank: %x\n", gb->mbc_rom_bank); GB_log(gb, "Current mapped ROM bank: %x\n", gb->mbc_rom_bank);
if (cartridge->has_ram) { if (cartridge->has_ram) {
GB_log(gb, "Current mapped RAM bank: %x\n", gb->mbc_ram_bank); GB_log(gb, "Current mapped RAM bank: %x\n", gb->mbc_ram_bank);

View File

@ -403,9 +403,8 @@ struct GB_gameboy_internal_s {
} mbc2; } mbc2;
struct { struct {
uint8_t rom_bank:7; uint8_t rom_bank:8;
uint8_t padding:1; uint8_t ram_bank:3;
uint8_t ram_bank:4;
} mbc3; } mbc3;
struct { struct {
@ -538,6 +537,7 @@ struct GB_gameboy_internal_s {
GB_STANDARD_MBC1_WIRING, GB_STANDARD_MBC1_WIRING,
GB_MBC1M_WIRING, GB_MBC1M_WIRING,
} mbc1_wiring; } mbc1_wiring;
bool is_mbc30;
unsigned pending_cycles; unsigned pending_cycles;

View File

@ -86,6 +86,10 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb)
case GB_MBC3: case GB_MBC3:
gb->mbc_rom_bank = gb->mbc3.rom_bank; gb->mbc_rom_bank = gb->mbc3.rom_bank;
gb->mbc_ram_bank = gb->mbc3.ram_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) { if (gb->mbc_rom_bank == 0) {
gb->mbc_rom_bank = 1; 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 */ /* Set MBC5's bank to 1 correctly */
if (gb->cartridge_type->mbc_type == GB_MBC5) { if (gb->cartridge_type->mbc_type == GB_MBC5) {
gb->mbc5.rom_bank_low = 1; gb->mbc5.rom_bank_low = 1;