--- nono/vm/goldfish_rtc.cpp 2026/04/29 17:05:29 1.1.1.2 +++ nono/vm/goldfish_rtc.cpp 2026/04/29 17:06:00 1.1.1.5 @@ -20,7 +20,9 @@ // 同じものを使うらしい。 #include "goldfish_rtc.h" -#include "mpu.h" +#include "event.h" +#include "mainbus.h" +#include "mytime.h" #include "textscreen.h" // @@ -38,22 +40,11 @@ GFRTCDevice::~GFRTCDevice() { } -// 初期化 -bool -GFRTCDevice::Init() -{ - if (inherited::Init() == false) { - return false; - } - - return true; -} - // リセット void GFRTCDevice::ResetHard(bool poweron) { - time_nsec = 0; + time_nsec.q = 0; } busdata @@ -63,19 +54,18 @@ GFRTCDevice::ReadPort(uint32 offset) switch (offset) { case GFRTC::TIME_LOW: - time_nsec = (uint64)MkTime() * 1000'000'000U; - data = (uint32)time_nsec; + time_nsec.q = sec_to_nsec(MkTime()); + data = time_nsec.l; if (__predict_false(loglevel >= 1)) { if (loglevel >= 3) { putlogn("TIME_LOW -> $%08x", data.Data()); } else { - putlogn("TIME -> $%08x'%08x", - (uint32)(time_nsec >> 32), data.Data()); + putlogn("TIME -> $%08x'%08x", time_nsec.h, data.Data()); } if (loglevel >= 2) { struct tm tm, tr; - time_t t = (time_t)(time_nsec / 1_sec); + time_t t = (time_t)nsec_to_sec(time_nsec.q); gmtime_r(&t, &tm); putlogn("TIME / 1e9: %4u/%02u/%02u %02u:%02u:%02u", tm.tm_year + 1900, @@ -85,10 +75,9 @@ GFRTCDevice::ReadPort(uint32 offset) tm.tm_min, tm.tm_sec); - struct timeval tv; - gettimeofday(&tv, NULL); - gmtime_r(&tv.tv_sec, &tr); - putlogn("gettimeofday: %4u/%02u/%02u %02u:%02u:%02u", + time_t u = (time_t)get_hosttime_sec(); + gmtime_r(&u, &tr); + putlogn("system_clock: %4u/%02u/%02u %02u:%02u:%02u", tr.tm_year + 1900, tr.tm_mon + 1, tr.tm_mday, @@ -100,7 +89,7 @@ GFRTCDevice::ReadPort(uint32 offset) break; case GFRTC::TIME_HIGH: - data = (uint32)(time_nsec >> 32); + data = time_nsec.h; putlog(3, "TIME_HIGH -> $%08x", data.Data()); break; @@ -115,7 +104,7 @@ GFRTCDevice::ReadPort(uint32 offset) break; default: - putlog(1, "Read unknown $%08x", mpu->GetPaddr()); + putlog(1, "Read unknown $%08x", GetMainbusDevice()->GetPaddr()); data.SetBusErr(); break; } @@ -132,18 +121,17 @@ GFRTCDevice::WritePort(uint32 offset, ui switch (offset) { case GFRTC::TIME_LOW: { - time_nsec |= data; + time_nsec.l = data; if (__predict_false(loglevel >= 1)) { if (loglevel >= 2) { - putlogn("TIME_LOW <- $%08x", (uint32)time_nsec); + putlogn("TIME_LOW <- $%08x", time_nsec.l); } else { - putlogn("TIME <- $%08x'%08x", - (uint32)(time_nsec >> 32), (uint32)time_nsec); + putlogn("TIME <- $%08x'%08x", time_nsec.h, time_nsec.l); } } - time_t t = time_nsec / 1000'000'000U; + time_t t = nsec_to_sec(time_nsec.q); struct tm tm; gmtime_r(&t, &tm); SetYear(tm.tm_year + 1900); @@ -157,7 +145,7 @@ GFRTCDevice::WritePort(uint32 offset, ui case GFRTC::TIME_HIGH: putlog(2, "TIME_HIGH <- $%08x", data); - time_nsec = (uint64)data << 32; + time_nsec.h = data; break; case GFRTC::ALARM_LOW: @@ -181,7 +169,8 @@ GFRTCDevice::WritePort(uint32 offset, ui break; default: - putlog(1, "Write unknown $%08x <- $%08x", mpu->GetPaddr(), data); + putlog(1, "Write unknown $%08x <- $%08x", + GetMainbusDevice()->GetPaddr(), data); r.SetBusErr(); break; } @@ -196,12 +185,12 @@ GFRTCDevice::PeekPort(uint32 offset) switch (offset) { case GFRTC::TIME_LOW: { - uint64 now = MkTime() * 1000'000'000U; + uint64 now = sec_to_nsec(MkTime()); return now & 0xffffffffU; } case GFRTC::TIME_HIGH: { - uint64 now = MkTime() * 1000'000'000U; + uint64 now = sec_to_nsec(MkTime()); return now >> 32; } case GFRTC::INTR_STATUS: @@ -214,7 +203,7 @@ GFRTCDevice::PeekPort(uint32 offset) // モニタの下請け。(GFTimer から呼ばれる) int -GFRTCDevice::MonitorUpdateRTC(TextScreen& screen, int y) const +GFRTCDevice::MonitorScreenRTC(TextScreen& screen, int y) const { screen.Puts(0, y++, ""); screen.Print(0, y++, "%04u/%02u/%02u(%s) %02u:%02u:%02u",