--- nono/vm/mk48t02.cpp 2026/04/29 17:05:18 1.1.1.13 +++ nono/vm/mk48t02.cpp 2026/04/29 17:06:01 1.1.1.17 @@ -20,7 +20,8 @@ #include "bitops.h" #include "config.h" #include "mainapp.h" -#include "mpu.h" +#include "mainbus.h" +#include "monitor.h" #include #include #include @@ -38,9 +39,9 @@ MK48T02Device::MK48T02Device() // 今の所 UTC として使うケースだけのようだ。 use_localtime = false; - monitor.func = ToMonitorCallback(&MK48T02Device::MonitorUpdate); - monitor.SetSize(40, 13); - monitor.Regist(ID_MONITOR_MK48T02); + monitor = gMonitorManager->Regist(ID_MONITOR_MK48T02, this); + monitor->SetCallback(&MK48T02Device::MonitorScreen); + monitor->SetSize(40, 13); } // デストラクタ @@ -91,7 +92,7 @@ MK48T02Device::Init() // たぶんこのバグはもう修正されることはないだろうから、こちらで補正する // スイッチを用意した。 if (gMainApp.Has(VMCap::LUNA)) { - if (gConfig->Find("luna-adjust-misused-epoch").AsInt()) { + if (gConfig->Find("luna-adjust-misused-epoch").AsBool()) { // エポック年のうるう年カウンタ相当を補正項として持つ adjust_leap = year_epoch % 4; } else { @@ -130,6 +131,7 @@ MK48T02Device::Init() file.SetDispname(dispname); mem = file.OpenCreate(2048); if (mem == NULL) { + // エラーメッセージは表示済み。 return false; } @@ -159,21 +161,23 @@ MK48T02Device::BCD2num(uint8 bcd) return (bcd >> 4) * 10 + (bcd & 0x0f); } -uint64 -MK48T02Device::Read(uint32 offset) +busdata +MK48T02Device::ReadPort(uint32 offset) { - uint32 data; + busdata data; data = mem[offset]; - putlog(3, "$%08x -> $%02x", mpu->GetPaddr(), data); + putlog(3, "$%08x -> $%02x", GetMainbusDevice()->GetPaddr(), data.Data()); + // XXX wait? + data |= BusData::Size1; return data; } -uint64 -MK48T02Device::Write(uint32 offset, uint32 data) +busdata +MK48T02Device::WritePort(uint32 offset, uint32 data) { - putlog(3, "$%08x <- $%02x", mpu->GetPaddr(), data); + putlog(3, "$%08x <- $%02x", GetMainbusDevice()->GetPaddr(), data); switch (offset - 2040) { case 0: // コントロール @@ -208,31 +212,33 @@ MK48T02Device::Write(uint32 offset, uint mem[offset] = data; - return 0; + // XXX wait? + busdata r = BusData::Size1; + return r; } -uint64 -MK48T02Device::Peek(uint32 offset) +busdata +MK48T02Device::PeekPort(uint32 offset) { return mem[offset]; } -uint64 -MK48T02Device::Poke(uint32 offset, uint32 data) +bool +MK48T02Device::PokePort(uint32 offset, uint32 data) { // 時計部分にはコントロールレジスタもあるので書き込み不可。 if (offset >= 2040) { - return (uint64)-1; + return false; } else { if ((int32)data >= 0) { mem[offset] = data; } - return 0; + return true; } } void -MK48T02Device::MonitorUpdate(Monitor *, TextScreen& screen) +MK48T02Device::MonitorScreen(Monitor *, TextScreen& screen) { uint32 addr; uint32 v; @@ -242,44 +248,44 @@ MK48T02Device::MonitorUpdate(Monitor *, // BCD なので %x で表示する screen.Print(0, y++, - "Internal: %04d[%02x]/%02x/%02x(%s) %02x:%02x:%02x.%1x", + "Internal: %04u[%02x]/%02x/%02x(%s) %02x:%02x:%02x.%1x", DecodeYear(reg.in.year), reg.in.year, reg.in.mon, reg.in.mday, wdays[reg.in.wday], reg.in.hour, reg.in.min, reg.in.sec, (uint32)((cnt >> 1) & 0xf)); auto ex = Load(); screen.Print(0, y++, - "Register: %04d[%02x]/%02x/%02x(%s) %02x:%02x:%02x", + "Register: %04u[%02x]/%02x/%02x(%s) %02x:%02x:%02x", DecodeYear(ex.year), ex.year, ex.mon, ex.mday, wdays[ex.wday], ex.hour, ex.min, ex.sec); screen.Print(0, y++, "TimeZone: %s", use_localtime ? "Local" : "UTC"); - screen.Print(0, y++, "Epoch : %4d (Adjust Leap: %d)", + screen.Print(0, y++, "Epoch : %4u (Adjust Leap: %u)", year_epoch, adjust_leap); y++; addr = 0x800; - v = Peek(--addr); + v = PeekPort(--addr); screen.Print(0, y++, "$%3x: $%02x (year=%02x)", addr, v, v); - v = Peek(--addr); + v = PeekPort(--addr); screen.Print(0, y++, "$%3x: $%02x (mon =%02x)", addr, v, v); - v = Peek(--addr); + v = PeekPort(--addr); screen.Print(0, y++, "$%3x: $%02x (date=%02x)", addr, v, v); - v = Peek(--addr); - screen.Print(0, y++, "$%3x: $%02x (wday=%02x FT=%d)", + v = PeekPort(--addr); + screen.Print(0, y++, "$%3x: $%02x (wday=%02x FT=%u)", addr, v, (v & 0x07), (v & MK48T02Clock::FREQTEST) ? 1 : 0); - v = Peek(--addr); - screen.Print(0, y++, "$%3x: $%02x (hour=%02x KS=%d)", + v = PeekPort(--addr); + screen.Print(0, y++, "$%3x: $%02x (hour=%02x KS=%u)", addr, v, (v & 0x3f), (v & MK48T02Clock::KICKSTART) ? 1 : 0); - v = Peek(--addr); + v = PeekPort(--addr); screen.Print(0, y++, "$%3x: $%02x (min =%02x)", addr, v, (v & 0x7f)); - v = Peek(--addr); - screen.Print(0, y++, "$%3x: $%02x (sec =%02x ST=%d)", + v = PeekPort(--addr); + screen.Print(0, y++, "$%3x: $%02x (sec =%02x ST=%u)", addr, v, (v & 0x7f), (v & MK48T02Clock::STOP) ? 1 : 0); - v = Peek(--addr); - screen.Print(0, y++, "$%3x: $%02x (W=%d R=%d)", + v = PeekPort(--addr); + screen.Print(0, y++, "$%3x: $%02x (W=%u R=%u)", addr, v, (v & MK48T02Clock::WRITE) ? 1 : 0, (v & MK48T02Clock::READ) ? 1 : 0); @@ -380,7 +386,7 @@ MK48T02Device::GetWday() const // 1を月曜…という運用ということにする。 // 戻り値は 0..6 (0が日曜)。 - int v = reg.in.wday; + uint v = reg.in.wday; if (v == 7) { v = 0; }