]> localhost Git - WindEmu.git/commitdiff
Fix up RTC
authorGeorge Wright <gw@gwright.org.uk>
Tue, 10 Dec 2024 07:25:25 +0000 (23:25 -0800)
committerGeorge Wright <gw@gwright.org.uk>
Tue, 10 Dec 2024 07:25:25 +0000 (23:25 -0800)
WindCore/sa1100.cpp
WindCore/sa1100/rtc.cpp
WindCore/sa1100/rtc.h

index 287db682ddca3597279e34a29046c5800f6c0e53..4e30dc7bad0c0246ab0b2d943746f00f2f9fdf22 100644 (file)
@@ -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();
index 12cb22621beef23148af58de4790e4a24dd7fee5..5146a328abe9e3228641c6fcdc501827105f6c81 100644 (file)
@@ -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:
     //
index a30ae5cf95a4a2b34d762f7fcb1db22f16879e01..26da45cd8c5efc73de1955c60357df35053a9750 100644 (file)
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <stdint.h>
+#include <time.h>
 
 namespace SA1100 {
 
@@ -42,6 +43,8 @@ class RTC {
       m_RTSR = 0;
     }
 
+    time_t mLatestTime;
+
   public:
     RTC();
     inline uint32_t