From: George Wright Date: Tue, 10 Dec 2024 07:25:25 +0000 (-0800) Subject: Fix up RTC X-Git-Url: http://git.gwright.org.uk/?a=commitdiff_plain;h=9049e34c9da2fb1a7eb6ac4f5ab33873104e8908;p=WindEmu.git Fix up RTC --- diff --git a/WindCore/sa1100.cpp b/WindCore/sa1100.cpp index 287db68..4e30dc7 100644 --- a/WindCore/sa1100.cpp +++ b/WindCore/sa1100.cpp @@ -981,11 +981,7 @@ bool Emulator::executeUntil(int64_t cycles) { osTimer->tick(); nextTimerTick += TICKS_3_6864_MHZ; } - if (passedCycles >= nextRTCTick) { - //printf("RTC tick\n"); - rtc->run(); - nextRTCTick += TICKS_1_HZ; - } + rtc->run(); gpioController->run(); serial3->run(); intController->run(); diff --git a/WindCore/sa1100/rtc.cpp b/WindCore/sa1100/rtc.cpp index 12cb226..5146a32 100644 --- a/WindCore/sa1100/rtc.cpp +++ b/WindCore/sa1100/rtc.cpp @@ -23,6 +23,7 @@ namespace SA1100 { RTC::RTC() { init_register(); + mLatestTime = time(nullptr); } void RTC::run() @@ -30,7 +31,11 @@ void RTC::run() // :SA-1110 Developer's Manual: Wei 2003-Dec-08: // // The counter is incremented on rising edges of the 1-Hz clock. - ++m_RCNR; + auto currentTime = time(nullptr); + if (currentTime > mLatestTime) { + ++m_RCNR; + mLatestTime = currentTime; + } // :SA-1110 Developer's Manual: Wei 2003-Dec-08: // diff --git a/WindCore/sa1100/rtc.h b/WindCore/sa1100/rtc.h index a30ae5c..26da45c 100644 --- a/WindCore/sa1100/rtc.h +++ b/WindCore/sa1100/rtc.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace SA1100 { @@ -42,6 +43,8 @@ class RTC { m_RTSR = 0; } + time_t mLatestTime; + public: RTC(); inline uint32_t