diff --git a/Core/gb.h b/Core/gb.h index 409e4cd1..f085eacb 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -438,7 +438,7 @@ struct GB_gameboy_internal_s { bool rumble_state; bool cart_ir; - // TODO: move to huc3 struct when breaking save compat + // TODO: move to huc3/mbc3 struct when breaking save compat uint8_t huc3_mode; uint8_t huc3_access_index; uint16_t huc3_minutes, huc3_days; @@ -446,6 +446,7 @@ struct GB_gameboy_internal_s { bool huc3_alarm_enabled; uint8_t huc3_read; uint8_t huc3_access_flags; + bool mbc3_rtc_mapped; ); diff --git a/Core/memory.c b/Core/memory.c index 3f924bc7..c44c4ec9 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -195,10 +195,10 @@ static uint8_t read_mbc_ram(GB_gameboy_t *gb, uint16_t addr) } if (gb->cartridge_type->has_rtc && gb->cartridge_type->mbc_type != GB_HUC3 && - gb->mbc_ram_bank >= 8 && gb->mbc_ram_bank <= 0xC) { + gb->mbc3_rtc_mapped && gb->mbc_ram_bank <= 4) { /* RTC read */ gb->rtc_latched.high |= ~0xC1; /* Not all bytes in RTC high are used. */ - return gb->rtc_latched.data[gb->mbc_ram_bank - 8]; + return gb->rtc_latched.data[gb->mbc_ram_bank]; } if (gb->camera_registers_mapped) { @@ -509,7 +509,10 @@ static void write_mbc(GB_gameboy_t *gb, uint16_t addr, uint8_t value) switch (addr & 0xF000) { case 0x0000: case 0x1000: gb->mbc_ram_enable = (value & 0xF) == 0xA; break; case 0x2000: case 0x3000: gb->mbc3.rom_bank = value; break; - case 0x4000: case 0x5000: gb->mbc3.ram_bank = value; break; + case 0x4000: case 0x5000: + gb->mbc3.ram_bank = value; + gb->mbc3_rtc_mapped = value & 8; + break; case 0x6000: case 0x7000: if (!gb->rtc_latch && (value & 1)) { /* Todo: verify condition is correct */ memcpy(&gb->rtc_latched, &gb->rtc_real, sizeof(gb->rtc_real)); @@ -693,8 +696,8 @@ static void write_mbc_ram(GB_gameboy_t *gb, uint16_t addr, uint8_t value) return; } - if (gb->cartridge_type->has_rtc && gb->mbc_ram_bank >= 8 && gb->mbc_ram_bank <= 0xC) { - gb->rtc_latched.data[gb->mbc_ram_bank - 8] = gb->rtc_real.data[gb->mbc_ram_bank - 8] = value; + if (gb->cartridge_type->has_rtc && gb->mbc3_rtc_mapped && gb->mbc_ram_bank <= 4) { + gb->rtc_latched.data[gb->mbc_ram_bank] = gb->rtc_real.data[gb->mbc_ram_bank] = value; return; }