From ac5b0aca2c51768548e4ae25d86d740680ab50be Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 23 Apr 2021 21:01:17 +0300 Subject: [PATCH] RTC accuracy fix --- Core/gb.h | 2 +- Core/memory.c | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Core/gb.h b/Core/gb.h index a2e8db19..4241a613 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -543,7 +543,7 @@ struct GB_gameboy_internal_s { GB_SECTION(rtc, GB_rtc_time_t rtc_real, rtc_latched; uint64_t last_rtc_second; - bool rtc_latch; + GB_PADDING(bool, rtc_latch); uint32_t rtc_cycles; uint8_t tpp1_mr4; ); diff --git a/Core/memory.c b/Core/memory.c index a25b860f..f499e744 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -541,10 +541,7 @@ static void write_mbc(GB_gameboy_t *gb, uint16_t addr, uint8_t 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)); - } - gb->rtc_latch = value & 1; + memcpy(&gb->rtc_latched, &gb->rtc_real, sizeof(gb->rtc_real)); break; } break; @@ -781,7 +778,7 @@ static void write_mbc_ram(GB_gameboy_t *gb, uint16_t addr, uint8_t value) if (gb->mbc_ram_bank == 0) { gb->rtc_cycles = 0; } - gb->rtc_latched.data[gb->mbc_ram_bank] = gb->rtc_real.data[gb->mbc_ram_bank] = value; + gb->rtc_real.data[gb->mbc_ram_bank] = value; } return; }