--- nono/vm/goldfish_rtc.cpp 2026/04/29 17:05:25 1.1.1.1 +++ nono/vm/goldfish_rtc.cpp 2026/04/29 17:05:50 1.1.1.4 @@ -20,6 +20,8 @@ // 同じものを使うらしい。 #include "goldfish_rtc.h" +#include "event.h" +#include "mpu.h" #include "textscreen.h" // @@ -37,17 +39,6 @@ GFRTCDevice::~GFRTCDevice() { } -// 初期化 -bool -GFRTCDevice::Init() -{ - if (inherited::Init() == false) { - return false; - } - - return true; -} - // リセット void GFRTCDevice::ResetHard(bool poweron) @@ -56,9 +47,8 @@ GFRTCDevice::ResetHard(bool poweron) } busdata -GFRTCDevice::Read32(uint32 addr) +GFRTCDevice::ReadPort(uint32 offset) { - uint32 offset = addr & 0xfff; busdata data; switch (offset) { @@ -72,6 +62,30 @@ GFRTCDevice::Read32(uint32 addr) putlogn("TIME -> $%08x'%08x", (uint32)(time_nsec >> 32), data.Data()); } + + if (loglevel >= 2) { + struct tm tm, tr; + time_t t = (time_t)(time_nsec / 1_sec); + gmtime_r(&t, &tm); + putlogn("TIME / 1e9: %4u/%02u/%02u %02u:%02u:%02u", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + tm.tm_hour, + 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", + tr.tm_year + 1900, + tr.tm_mon + 1, + tr.tm_mday, + tr.tm_hour, + tr.tm_min, + tr.tm_sec); + } } break; @@ -91,17 +105,18 @@ GFRTCDevice::Read32(uint32 addr) break; default: - putlog(1, "Read unknown $%08x", addr); + putlog(1, "Read unknown $%08x", mpu->GetPaddr()); data.SetBusErr(); break; } + + data |= BusData::Size4; return data; } busdata -GFRTCDevice::Write32(uint32 addr, uint32 data) +GFRTCDevice::WritePort(uint32 offset, uint32 data) { - uint32 offset = addr & 0xfff; busdata r; switch (offset) { @@ -156,67 +171,34 @@ GFRTCDevice::Write32(uint32 addr, uint32 break; default: - putlog(1, "Write unknown $%08x <- $%08x", addr, data); + putlog(1, "Write unknown $%08x <- $%08x", mpu->GetPaddr(), data); r.SetBusErr(); break; } + + r |= BusData::Size4; return r; } busdata -GFRTCDevice::Peek8(uint32 addr) +GFRTCDevice::PeekPort(uint32 offset) { - uint32 offset = addr & 0xfff; - switch (offset) { - case GFRTC::TIME_LOW + 0: - case GFRTC::TIME_LOW + 1: - case GFRTC::TIME_LOW + 2: - case GFRTC::TIME_LOW + 3: - case GFRTC::TIME_HIGH + 0: - case GFRTC::TIME_HIGH + 1: - case GFRTC::TIME_HIGH + 2: - case GFRTC::TIME_HIGH + 3: + case GFRTC::TIME_LOW: { uint64 now = MkTime() * 1000'000'000U; - - switch (offset) { - case GFRTC::TIME_LOW + 0: - return (now >> 24) & 0xff; - case GFRTC::TIME_LOW + 1: - return (now >> 16) & 0xff; - case GFRTC::TIME_LOW + 2: - return (now >> 8) & 0xff; - case GFRTC::TIME_LOW + 3: - return now & 0xff; - - case GFRTC::TIME_HIGH + 0: - return (now >> 56) & 0xff; - case GFRTC::TIME_HIGH + 1: - return (now >> 48) & 0xff; - case GFRTC::TIME_HIGH + 2: - return (now >> 40) & 0xff; - case GFRTC::TIME_HIGH + 3: - return (now >> 32) & 0xff; - default: - __unreachable(); - } + return now & 0xffffffffU; } - - case GFRTC::INTR_STATUS + 0: - case GFRTC::INTR_STATUS + 1: - case GFRTC::INTR_STATUS + 2: - case GFRTC::INTR_STATUS + 3: - return 0; - - case GFRTC::ALARM_STATUS + 0: - case GFRTC::ALARM_STATUS + 1: - case GFRTC::ALARM_STATUS + 2: - case GFRTC::ALARM_STATUS + 3: + case GFRTC::TIME_HIGH: + { + uint64 now = MkTime() * 1000'000'000U; + return now >> 32; + } + case GFRTC::INTR_STATUS: + case GFRTC::ALARM_STATUS: return 0; - default: - return busdata::BusErr; + return BusData::BusErr; } }