--- nono/vm/opm.cpp 2026/04/29 17:05:13 1.1.1.5 +++ nono/vm/opm.cpp 2026/04/29 17:05:16 1.1.1.6 @@ -14,21 +14,29 @@ #include "mpu.h" #include "scheduler.h" -// グローバル参照用 -OPMDevice *gOPM; - // コンストラクタ OPMDevice::OPMDevice() - : inherited("OPM") + : inherited(OBJ_OPM) { - devaddr = baseaddr; - devlen = 0x2000; } // デストラクタ OPMDevice::~OPMDevice() { - gOPM = NULL; +} + +// 初期化 +bool +OPMDevice::Init() +{ + if (inherited::Init() == false) { + return false; + } + + adpcm = GetADPCMDevice(); + fdc = GetFDCDevice(); + + return true; } // リセット @@ -39,7 +47,7 @@ OPMDevice::ResetHard(bool poweron) busy_start = 0; busy_end = 0; - gFDC->SetForceReady(false); + fdc->SetForceReady(false); } uint64 @@ -47,11 +55,11 @@ OPMDevice::Read(uint32 offset) { uint8 data; - gMPU->AddCycle(19); // InsideOut p.135 + mpu->AddCycle(19); // InsideOut p.135 switch (offset) { case 0: - putlog(0, "Read $%06x (NOT IMPLEMENTED)", gMPU->GetPaddr()); + putlog(0, "Read $%06x (NOT IMPLEMENTED)", mpu->GetPaddr()); return 0; case 1: // OPM ステータスレジスタ @@ -64,16 +72,17 @@ OPMDevice::Read(uint32 offset) putlog(1, "STAT -> $%02x", data); return data; default: - __unreachable(); + VMPANIC("corrupted offset=%d", offset); + return 0xff; } } uint64 OPMDevice::Write(uint32 offset, uint32 data) { - gMPU->AddCycle(53); // InsideOut p.135 + mpu->AddCycle(53); // InsideOut p.135 - uint64 now = gScheduler->GetVirtTime(); + uint64 now = scheduler->GetVirtTime(); switch (offset) { case 0: @@ -104,7 +113,7 @@ OPMDevice::Write(uint32 offset, uint32 d // 時刻の起点は CPU 側の命令によって異なるはずだが // わからないので命令のぶんは無視しておく。 // 53 クロックのウェイトのほうは足す。 - busy_origin = now + 53 * gMPU->GetClock_nsec(); + busy_origin = now + 53 * mpu->GetClock_nsec(); // busy_start のほうはとりあえず 10 クロックにしておく。 busy_start = busy_origin + 10 * clk; @@ -112,18 +121,19 @@ OPMDevice::Write(uint32 offset, uint32 d switch (reg) { case 0x1b: - gADPCM->SetClock(data & 0x80); - gFDC->SetForceReady(data & 0x40); + adpcm->SetClock(data & 0x80); + fdc->SetForceReady(data & 0x40); // 他のビットは未対応 break; default: putlog(0, "Write $%06x <- $%02x (NOT IMPLEMENTED)", - gMPU->GetPaddr(), data); + mpu->GetPaddr(), data); break; } break; default: - __unreachable(); + VMPANIC("corrupted offset=%d", offset); + break; } return 0; @@ -140,7 +150,7 @@ OPMDevice::Peek(uint32 offset) bool OPMDevice::IsBusy() const { - uint64 now = gScheduler->GetVirtTime(); + uint64 now = scheduler->GetVirtTime(); return (busy_start <= now && now < busy_end); }