From 110cedeaac3918170263377792e63f5addf436df Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 23:26:17 +0300 Subject: [PATCH] Even better hueristics --- Core/gb.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Core/gb.c b/Core/gb.c index 966022b..a17a5a7 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -484,17 +484,37 @@ done:; // Fix a common wrong MBC error if (gb->rom[0x147] == 3) { // MBC1 + RAM + Battery - if (gb->rom_size >= 33 * 0x4000) { - for (unsigned i = 32 * 0x4000; i < 33 * 0x4000; i++) { + bool needs_fix = false; + if (gb->rom_size >= 0x21 * 0x4000) { + for (unsigned i = 0x20 * 0x4000; i < 0x21 * 0x4000; i++) { if (gb->rom[i]) { - gb->rom[0x147] = 0x10; // MBC3 + RTC + RAM + Battery - GB_configure_cart(gb); - gb->rom[0x147] = 0x3; - GB_log(gb, "ROM claims to use MBC1 but appears to require MBC3 or 5, assuming MBC3.\n"); + needs_fix = true; break; } } } + if (!needs_fix && gb->rom_size >= 0x41 * 0x4000) { + for (unsigned i = 0x40 * 0x4000; i < 0x41 * 0x4000; i++) { + if (gb->rom[i]) { + needs_fix = true; + break; + } + } + } + if (!needs_fix && gb->rom_size >= 0x61 * 0x4000) { + for (unsigned i = 0x60 * 0x4000; i < 0x61 * 0x4000; i++) { + if (gb->rom[i]) { + needs_fix = true; + break; + } + } + } + if (needs_fix) { + gb->rom[0x147] = 0x10; // MBC3 + RTC + RAM + Battery + GB_configure_cart(gb); + gb->rom[0x147] = 0x3; + GB_log(gb, "ROM claims to use MBC1 but appears to require MBC3 or 5, assuming MBC3.\n"); + } } if (old_rom) {