From efbc385417327454f0eaf14221aa021666184d21 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 21 Jun 2017 01:07:11 +0300 Subject: [PATCH] Forgot to amend the last commit, it was broken. --- Core/gb.h | 3 ++- Core/mbc.c | 53 +++++++++++++++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Core/gb.h b/Core/gb.h index 5448e5d..18df88f 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -279,7 +279,8 @@ struct GB_gameboy_internal_s { union { struct { uint8_t bank_low:5; - uint8_t bank_high:3; + uint8_t bank_high:2; + uint8_t padding:1; // Save state compatibility with 0.9 uint8_t mode:1; } mbc1; diff --git a/Core/mbc.c b/Core/mbc.c index 474ead0..d3791a1 100644 --- a/Core/mbc.c +++ b/Core/mbc.c @@ -46,41 +46,49 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) switch (gb->cartridge_type->mbc_type) { case GB_NO_MBC: return; case GB_MBC1: - 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); + switch (gb->mbc1_wiring) { + case GB_STANDARD_MBC1_WIRING: + gb->mbc_rom_bank = gb->mbc1.bank_low | (gb->mbc1.bank_high << 5); + if (gb->mbc1.mode == 0) { gb->mbc_ram_bank = 0; gb->mbc_rom0_bank = 0; - break; - - case GB_MBC1M_WIRING: - gb->mbc_rom_bank = (gb->mbc1.bank_low & 0xF) | (gb->mbc1.bank_high << 4); - gb->mbc_ram_bank = 0; - gb->mbc_rom0_bank = 0; - } - } - else { - switch (gb->mbc1_wiring) { - case GB_STANDARD_MBC1_WIRING: - gb->mbc_rom_bank = gb->mbc1.bank_low | (gb->mbc1.bank_high << 5); + } + else { gb->mbc_ram_bank = gb->mbc1.bank_high; gb->mbc_rom0_bank = gb->mbc1.bank_high << 5; - break; - - case GB_MBC1M_WIRING: - gb->mbc_rom_bank = (gb->mbc1.bank_low & 0xF) | (gb->mbc1.bank_high << 4); + } + if ((gb->mbc_rom_bank & 0x1F) == 0) { + gb->mbc_rom_bank++; + } + break; + case GB_MBC1M_WIRING: + gb->mbc_rom_bank = (gb->mbc1.bank_low & 0xF) | (gb->mbc1.bank_high << 4); + if (gb->mbc1.mode == 0) { + gb->mbc_ram_bank = 0; + gb->mbc_rom0_bank = 0; + } + else { gb->mbc_rom0_bank = gb->mbc1.bank_high << 4; gb->mbc_ram_bank = 0; - } + } + if ((gb->mbc1.bank_low & 0x1F) == 0) { + gb->mbc_rom_bank++; + } + break; } break; case GB_MBC2: gb->mbc_rom_bank = gb->mbc2.rom_bank; + if ((gb->mbc_rom_bank & 0xF) == 0) { + gb->mbc_rom_bank = 1; + } break; case GB_MBC3: gb->mbc_rom_bank = gb->mbc3.rom_bank; gb->mbc_ram_bank = gb->mbc3.ram_bank; + if (gb->mbc_rom_bank == 0) { + gb->mbc_rom_bank = 1; + } break; case GB_MBC5: gb->mbc_rom_bank = gb->mbc5.rom_bank_low | (gb->mbc5.rom_bank_high << 8); @@ -101,9 +109,6 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) gb->mbc_ram_bank = gb->huc3.ram_bank; break; } - 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++; - } } void GB_configure_cart(GB_gameboy_t *gb)