--- nono/vm/rtc.cpp 2026/04/29 17:05:11 1.1.1.8 +++ nono/vm/rtc.cpp 2026/04/29 17:05:29 1.1.1.10 @@ -11,29 +11,29 @@ #include "rtc.h" #include "config.h" #include "scheduler.h" -#include "sync.h" - -// グローバル参照用 -RTCDevice *gRTC; +#include "syncer.h" // コンストラクタ -RTCDevice::RTCDevice(const std::string& objname_) - : inherited(objname_) +RTCDevice::RTCDevice() + : inherited(OBJ_RTC) { - event.Regist("RTC ClockIn"); - event.time = period; - event.func = ToEventCallback(&RTCDevice::Callback); } // デストラクタ RTCDevice::~RTCDevice() { - gRTC = NULL; } +// 初期化 bool RTCDevice::Init() { + if (inherited::Init() == false) { + return false; + } + + syncer = GetSyncer(); + // TODO: use_localtime を設定可能にするべきかどうか // 時刻固定オプション (パフォーマンス測定用)。 @@ -93,6 +93,11 @@ RTCDevice::Init() rtc_tm.tm_sec = ss; } + event.func = ToEventCallback(&RTCDevice::Callback); + event.time = period; + event.SetName("RTC ClockIn"); + scheduler->RegistEvent(event); + return true; } @@ -104,7 +109,6 @@ RTCDevice::StartTime() struct tm tm; if (force_fixed) { - putmsgn("force_fixed"); // 固定の時刻を設定 struct tm fixed { .tm_sec = 16, @@ -155,9 +159,9 @@ RTCDevice::StartTime() SetYear(tm.tm_year + 1900); SetLeap(tm.tm_year & 3); - stime = gSync->GetRealTime(); + stime = syncer->GetRealTime(); - gScheduler->StartEvent(event); + scheduler->StartEvent(event); } // デバッグオプションの日付文字列を解析する。 @@ -244,9 +248,9 @@ RTCDevice::Callback(Event& ev) stime += period; ClockIn(); if (sync_rt) { - gScheduler->StartRealtimeEvent(ev, stime, period); + scheduler->StartRealtimeEvent(ev, stime, period); } else { - gScheduler->StartEvent(ev); + scheduler->StartEvent(ev); } } @@ -258,7 +262,7 @@ RTCDevice::ClockIn_PowerOff() ClockIn(); // XXX RealTime ではなく HostTime? - uint64 rt = gSync->GetRealTime(); + uint64 rt = syncer->GetRealTime(); if (rt > stime) { // RTC が現実より遅れているので早回し return 0; @@ -375,11 +379,11 @@ RTCDevice::CountUpMin() } // 現在の月の最終日を返す (月の繰り上がり処理用) -int +uint RTCDevice::GetLastMday() const { // 下記の理由により 0 月が必要。値は適当。 - static const int mdays[] = { + static const uint mdays[] = { 30, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; @@ -388,8 +392,8 @@ RTCDevice::GetLastMday() const // 範囲外の値に対するロジックは違うだろうが規定されていないので // こっち都合で実装しておく。 // m は 0..12 - int m = GetMon() % 13; - int lastday = mdays[m]; + uint m = GetMon() % 13; + uint lastday = mdays[m]; if (m == 2 && GetLeap() == 0) { lastday++; }