From aefca34b3910177c66e398237f2cd3ca5efbd1a3 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 19 Jun 2017 19:46:09 +0300 Subject: [PATCH] Improved MBC1 emulation. Fixed incorrect error messages. --- Core/gb.c | 2 +- Core/mbc.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Core/gb.c b/Core/gb.c index f21319e2..73469dce 100755 --- a/Core/gb.c +++ b/Core/gb.c @@ -194,7 +194,7 @@ int GB_save_battery(GB_gameboy_t *gb, const char *path) if (gb->mbc_ram_size == 0 && !gb->cartridge_type->has_rtc) return 0; /* Claims to have battery, but has no RAM or RTC */ FILE *f = fopen(path, "wb"); if (!f) { - GB_log(gb, "Could not open save state: %s.\n", strerror(errno)); + GB_log(gb, "Could not open battery save: %s.\n", strerror(errno)); return errno; } diff --git a/Core/mbc.c b/Core/mbc.c index 9a17388e..474ead0a 100644 --- a/Core/mbc.c +++ b/Core/mbc.c @@ -46,12 +46,12 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) switch (gb->cartridge_type->mbc_type) { case GB_NO_MBC: return; case GB_MBC1: - /* Todo: some obscure behaviors of MBC1 are not supported. See http://forums.nesdev.com/viewtopic.php?f=20&t=14099 */ if (gb->mbc1.mode == 0) { switch (gb->mbc1_wiring) { case GB_STANDARD_MBC1_WIRING: gb->mbc_rom_bank = gb->mbc1.bank_low | (gb->mbc1.bank_high << 5); gb->mbc_ram_bank = 0; + gb->mbc_rom0_bank = 0; break; case GB_MBC1M_WIRING: @@ -63,8 +63,9 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) else { switch (gb->mbc1_wiring) { case GB_STANDARD_MBC1_WIRING: - gb->mbc_rom_bank = gb->mbc1.bank_low; + gb->mbc_rom_bank = gb->mbc1.bank_low | (gb->mbc1.bank_high << 5); gb->mbc_ram_bank = gb->mbc1.bank_high; + gb->mbc_rom0_bank = gb->mbc1.bank_high << 5; break; case GB_MBC1M_WIRING: @@ -100,8 +101,8 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) gb->mbc_ram_bank = gb->huc3.ram_bank; break; } - if (gb->mbc_rom_bank == 0 && gb->cartridge_type->mbc_type != GB_MBC5 && gb->cartridge_type->mbc_type != GB_HUC3) { - gb->mbc_rom_bank = 1; + if ((gb->mbc_rom_bank & 0x1F) == 0 && gb->cartridge_type->mbc_type != GB_MBC5 && gb->cartridge_type->mbc_type != GB_HUC3) { + gb->mbc_rom_bank++; } }