--- nono/vm/crtc2.cpp 2026/04/29 17:05:14 1.1.1.9 +++ nono/vm/crtc2.cpp 2026/04/29 17:05:24 1.1.1.11 @@ -12,15 +12,10 @@ #include "renderer.h" #include "scheduler.h" -// グローバル参照用 -CRTC2Device *gCRTC2; - // コンストラクタ CRTC2Device::CRTC2Device() - : inherited("CRTC2") + : inherited(OBJ_CRTC2) { - devaddr = 0xd1000000; - vdisp_event.func = ToEventCallback(&CRTC2Device::VDispCallback); vdisp_event.Regist("CRTC2 V-DISP"); } @@ -28,7 +23,19 @@ CRTC2Device::CRTC2Device() // デストラクタ CRTC2Device::~CRTC2Device() { - gCRTC2 = NULL; +} + +// 初期化 +bool +CRTC2Device::Init() +{ + if (inherited::Init() == false) { + return false; + } + + renderer = GetRenderer(); + + return true; } // リセット @@ -47,10 +54,10 @@ CRTC2Device::ResetHard(bool poweron) // すぐに垂直帰線期間を開始する vdisp_event.time = 0; vdisp_event.code = 1; - gScheduler->RestartEvent(vdisp_event); + scheduler->RestartEvent(vdisp_event); } -uint64 +busdata CRTC2Device::Read(uint32 offset) { uint32 data; @@ -88,19 +95,22 @@ CRTC2Device::Read(uint32 offset) break; default: - __unreachable(); + VMPANIC("corrupted offset=%d", offset); } - return data; + + busdata bd = data; + // XXX wait? + return bd; } -uint64 +busdata CRTC2Device::Write(uint32 offset, uint32 data) { switch (offset) { case 0: // アドレスレジスタ ar = data & 0x3f; putlog(3, "Address Register <- $%02x", ar); - return 0; + break; case 1: // データレジスタ switch (ar) { @@ -118,14 +128,18 @@ CRTC2Device::Write(uint32 offset, uint32 putlog(2, "R%02d <- $%02x", ar, data); break; } - return 0; + break; default: - __unreachable(); + VMPANIC("corrupted offset=%d", offset); + break; } + + // XXX wait? + return 0; } -uint64 +busdata CRTC2Device::Peek(uint32 offset) { switch (offset) { @@ -136,7 +150,7 @@ CRTC2Device::Peek(uint32 offset) return reg[ar]; default: - __unreachable(); + return 0xff; } } @@ -150,7 +164,7 @@ CRTC2Device::VDispCallback(Event& ev) // 今はここで1画面まるごと作成 if (vdisp) { // Render に作画指示 - gRenderer->Render(); + renderer->Render(); } // 次のタイミングを計算 @@ -164,5 +178,5 @@ CRTC2Device::VDispCallback(Event& ev) ev.time = 507.328_usec; // 32*Ht ev.code = 1; } - gScheduler->StartEvent(ev); + scheduler->StartEvent(ev); }