From ebcd5bec5c025e360dd15745cdc02c8c061edf2f Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sun, 7 Nov 2021 13:05:41 -0600 Subject: [PATCH] fix(cart): reset sub-cycle counting in RTC specifically when RTC S is written to --- src/cartridge.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cartridge.rs b/src/cartridge.rs index 673192a..562c94f 100644 --- a/src/cartridge.rs +++ b/src/cartridge.rs @@ -538,7 +538,11 @@ impl MBCIo for MBC3 { self.memory[0x2000 * self.ram_bank as usize + (addr as usize - 0xA000)] = byte } Some(MBC3Device::Clock(rtc_reg)) if self.devs_enabled => match rtc_reg { - Second => self.rtc.sec = byte & 0x3F, + Second => { + self.rtc.sec = byte & 0x3F; + // Writing to RTC S resets the internal sub-second counter + self.rtc.cycles = 0; + } Minute => self.rtc.min = byte & 0x3F, Hour => self.rtc.hr = byte & 0x1F, DayLow => self.rtc.day_low = byte & 0xFF,