From d3664d5da0eaab1f6f564466351fe4c8a5d7fa8e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 5 Aug 2020 01:39:19 +0300 Subject: [PATCH] Fix more RTC regressions --- Core/mbc.c | 1 - Core/memory.c | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Core/mbc.c b/Core/mbc.c index ba5055f..2259681 100644 --- a/Core/mbc.c +++ b/Core/mbc.c @@ -88,7 +88,6 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) 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; diff --git a/Core/memory.c b/Core/memory.c index c44c4ec..a75c382 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -183,7 +183,7 @@ static uint8_t read_mbc_ram(GB_gameboy_t *gb, uint16_t addr) } } - if ((!gb->mbc_ram_enable || !gb->mbc_ram_size) && + if ((!gb->mbc_ram_enable) && gb->cartridge_type->mbc_subtype != GB_CAMERA && gb->cartridge_type->mbc_type != GB_HUC1 && gb->cartridge_type->mbc_type != GB_HUC3) { @@ -205,7 +205,7 @@ static uint8_t read_mbc_ram(GB_gameboy_t *gb, uint16_t addr) return GB_camera_read_register(gb, addr); } - if (!gb->mbc_ram) { + if (!gb->mbc_ram || gb->mbc_ram_size) { return 0xFF; } @@ -213,7 +213,11 @@ static uint8_t read_mbc_ram(GB_gameboy_t *gb, uint16_t addr) return GB_camera_read_image(gb, addr - 0xa100); } - uint8_t ret = gb->mbc_ram[((addr & 0x1FFF) + gb->mbc_ram_bank * 0x2000) & (gb->mbc_ram_size - 1)]; + uint8_t effective_bank = gb->mbc_ram_bank; + if (gb->is_mbc30) { + effective_bank &= 0x3; + } + uint8_t ret = gb->mbc_ram[((addr & 0x1FFF) + effective_bank * 0x2000) & (gb->mbc_ram_size - 1)]; if (gb->cartridge_type->mbc_type == GB_MBC2) { ret |= 0xF0; }