--- nono/vm/crtc.cpp 2026/04/29 17:05:13 1.1.1.9 +++ nono/vm/crtc.cpp 2026/04/29 17:05:17 1.1.1.10 @@ -22,22 +22,19 @@ #include "scheduler.h" #include "tvram.h" -// グローバル参照用 -CRTCDevice *gCRTC; - // コンストラクタ CRTCDevice::CRTCDevice() - : inherited("CRTC") + : inherited(OBJ_CRTC) { - devaddr = 0xe80000; - devlen = 0x2000; - hsync_event.func = ToEventCallback(&CRTCDevice::HSyncCallback); hsync_event.Regist("CRTC H-Sync"); vdisp_event.func = ToEventCallback(&CRTCDevice::VDispCallback); vdisp_event.Regist("CRTC V-Disp"); - // ラスターコピーにかかる時間は最小 190nsec * 2 らしいので + // ラスターコピーは実際には CRTC の機能ではなく TVRAM (VRAM チップ) の + // 機能だが、イベントの時間管理が発生するのは CRTC 側なのでここで管理。 + // X68030 搭載の VRAM チップは HM514402A だが、ここでは X68000 XVI 搭載の + // HM53461 の値を使用し、これが最小 190nsec * 2 らしいので // とりあえず 400nsec としておく。 raster_event.func = ToEventCallback(&CRTCDevice::RasterCallback); raster_event.time = 400_nsec; @@ -51,7 +48,21 @@ CRTCDevice::CRTCDevice() // デストラクタ CRTCDevice::~CRTCDevice() { - gCRTC = NULL; +} + +// 初期化 +bool +CRTCDevice::Init() +{ + if (inherited::Init() == false) { + return false; + } + + mfp = GetMFPDevice(); + renderer = GetRenderer(); + tvram = GetTVRAMDevice(); + + return true; } // リセット @@ -65,10 +76,10 @@ CRTCDevice::ResetHard(bool poweron) // すぐに水平同期と垂直帰線期間を開始する hsync_event.time = 0; hsync_event.code = 1; - gScheduler->RestartEvent(hsync_event); + scheduler->RestartEvent(hsync_event); vdisp_event.time = 0; vdisp_event.code = 1; - gScheduler->RestartEvent(vdisp_event); + scheduler->RestartEvent(vdisp_event); } uint64 @@ -76,7 +87,7 @@ CRTCDevice::Read(uint32 offset) { uint64 data; - gMPU->AddCycle(9); // InsideOut p.135 + mpu->AddCycle(9); // InsideOut p.135 if (offset < 0x400 / 2) { // CRTC レジスタ // 0x40 バイトでミラー @@ -98,7 +109,7 @@ CRTCDevice::Read(uint32 offset) if (offset < countof(crtc.r)) { putlog(3, "R%02d -> $%04x", offset, (uint32)data); } else { - putlog(3, "$%06x -> $%04x", gMPU->GetPaddr(), (uint32)data); + putlog(3, "$%06x -> $%04x", mpu->GetPaddr(), (uint32)data); } break; } @@ -117,7 +128,7 @@ CRTCDevice::Read(uint32 offset) uint64 CRTCDevice::Write(uint32 offset, uint32 data) { - gMPU->AddCycle(9); // InsideOut p.135 + mpu->AddCycle(9); // InsideOut p.135 if (offset < 0x400 / 2) { // CRTC レジスタ // 0x40 バイトでミラー @@ -126,7 +137,7 @@ CRTCDevice::Write(uint32 offset, uint32 SetReg(offset, data); } else { // ここ何がいるんだ? - putlog(2, "$%06x <- $%04x", gMPU->GetPaddr(), data); + putlog(2, "$%06x <- $%04x", mpu->GetPaddr(), data); } } else { // 動作ポート @@ -247,16 +258,16 @@ CRTCDevice::SetReg(uint32 reg, uint32 da switch (reg) { case CRTC::R10: putlog(2, "R%02d <- $%04x", reg, data); - gTVRAM->SetScrollX(crtc.r[10]); + tvram->SetScrollX(crtc.r[10]); break; case CRTC::R11: putlog(2, "R%02d <- $%04x", reg, data); - gTVRAM->SetScrollY(crtc.r[11]); + tvram->SetScrollY(crtc.r[11]); break; case CRTC::R21: // 頻度が高いのでログレベルを上げておく putlog(3, "R%02d <- $%04x", reg, data); - gTVRAM->SetAccessPlane(crtc.r[21]); + tvram->SetAccessPlane(crtc.r[21]); break; case CRTC::R22: putlog(3, "R%02d <- $%04x", reg, data); @@ -264,7 +275,7 @@ CRTCDevice::SetReg(uint32 reg, uint32 da case CRTC::R23: // 頻度が高いのでログレベルを上げておく putlog(3, "R%02d <- $%04x", reg, data); - gTVRAM->SetAccessMask(crtc.r[23]); + tvram->SetAccessMask(crtc.r[23]); break; default: putlog(2, "R%02d <- $%04x (NOT IMPLEMENTED)", reg, data); @@ -319,7 +330,7 @@ CRTCDevice::HSyncCallback(Event& ev) ev.code++; // GPIP の状態を更新 - gMFP->SetHSync(true); + mfp->SetHSync(true); // ラスターコピーが指示されていたら実行 if (raster_copy) { @@ -327,10 +338,10 @@ CRTCDevice::HSyncCallback(Event& ev) int src = (crtc.r[22] >> 8) * 4; int dst = (crtc.r[22] & 0xff) * 4; - gTVRAM->RasterCopy(src, dst); + tvram->RasterCopy(src, dst); // 所定時間後に完了させる - gScheduler->RestartEvent(raster_event); + scheduler->RestartEvent(raster_event); } break; @@ -340,11 +351,11 @@ CRTCDevice::HSyncCallback(Event& ev) ev.code = 0; // GPIP の状態を更新 - gMFP->SetHSync(false); + mfp->SetHSync(false); break; } - gScheduler->StartEvent(ev); + scheduler->StartEvent(ev); } // ラスターコピー完了イベント @@ -363,12 +374,12 @@ CRTCDevice::VDispCallback(Event& ev) int vdisp = ev.code; // GPIP の状態を更新 - gMFP->SetVDisp(vdisp); + mfp->SetVDisp(vdisp); // 今はここで1画面まるごと作成 if (vdisp) { // Render に作画指示 - gRenderer->Render(); + renderer->Render(); } // 次のタイミングを計算 @@ -382,5 +393,5 @@ CRTCDevice::VDispCallback(Event& ev) ev.time = 191_usec + 1111_usec + 476_usec; ev.code = 1; } - gScheduler->StartEvent(ev); + scheduler->StartEvent(ev); }