--- nono/vm/sysport.cpp 2026/04/29 17:05:13 1.1.1.9 +++ nono/vm/sysport.cpp 2026/04/29 17:05:20 1.1.1.11 @@ -10,31 +10,42 @@ #include "sysport.h" #include "keyboard.h" +#include "mainram.h" #include "mpu.h" #include "nmi.h" #include "power.h" -#include "ram.h" #include "romimg_x68k.h" #include "sram.h" #include -// グローバル参照用 -SysportDevice *gSysport; - // コンストラクタ SysportDevice::SysportDevice() - : inherited("SystemPort") + : inherited(OBJ_SYSPORT) { - AddAlias("SysPort"); - - devaddr = baseaddr; - devlen = 0x2000; } // デストラクタ SysportDevice::~SysportDevice() { - gSysport = NULL; +} + +// 初期化 +bool +SysportDevice::Init() +{ + if (inherited::Init() == false) { + return false; + } + + cgrom = GetCGROMDevice(); + iplrom1 = GetIPLROM1Device(); + iplrom2 = GetIPLROM2Device(); + keyboard = GetKeyboard(); + mainram = GetMainRAMDevice(); + nmi = GetNMIDevice(); + sram = GetSRAMDevice(); + + return true; } // リセット @@ -46,7 +57,7 @@ SysportDevice::ResetHard(bool poweron) sysport.rom_wait = 0; sysport.key_ctrl = false; sysport.pwoff_count = 0; - gPower->SetSystemPowerOn(true); + GetPowerDevice()->SetSystemPowerOn(true); } uint64 @@ -67,7 +78,7 @@ SysportDevice::Read(uint32 offset) case SYSPORT::KEY: // XXX bit3 以外は要実機確認 data = 0xf7; - if (gKeyboard->IsConnected()) { + if (keyboard->IsConnected()) { data |= 0x08; } break; @@ -84,9 +95,10 @@ SysportDevice::Read(uint32 offset) data = 0xff; break; default: - __unreachable(); + VMPANIC("corrupted offset=%d", offset); + return 0xff; } - putlog(2, "$%06x -> $%02x", gMPU->GetPaddr(), data); + putlog(2, "$%06x -> $%02x", mpu->GetPaddr(), data); return data; } @@ -110,7 +122,7 @@ SysportDevice::Write(uint32 offset, uint } // bit2: NMI リセット if ((data & 0x04)) { - gNMI->NegateNMI(); + nmi->NegateNMI(); } sysport.key_ctrl = (data & 0x08); break; @@ -122,14 +134,14 @@ SysportDevice::Write(uint32 offset, uint sysport.ram_wait = data; // ROM に指示。常に設定値 + 2 でよい - gIPLROM1->SetWait(sysport.rom_wait + 2); - gIPLROM2->SetWait(sysport.rom_wait + 2); - gCGROM->SetWait(sysport.rom_wait + 2); + iplrom1->SetWait(sysport.rom_wait + 2); + iplrom2->SetWait(sysport.rom_wait + 2); + cgrom->SetWait(sysport.rom_wait + 2); // RAM に指示。InsideOut p.124 int wait = sysport.ram_wait; if (wait > 0) wait += 2; - gRAM->SetWait(wait); + mainram->SetWait(wait); break; } @@ -138,9 +150,9 @@ SysportDevice::Write(uint32 offset, uint case SYSPORT::SRAMWP: if (data == 0x31) { - gSRAM->write_enable(true); + sram->WriteEnable(true); } else { - gSRAM->write_enable(false); + sram->WriteEnable(false); } break; @@ -148,8 +160,12 @@ SysportDevice::Write(uint32 offset, uint { static const std::array sig { 0x00, 0x0f, 0x0f }; - assertmsg(sysport.pwoff_count < sig.size(), - "sysport.pwoff_count=%d", sysport.pwoff_count); + if (sysport.pwoff_count >= sig.size()) { + // すでにカウントオーバーしている場合何もしない? + putlog(2, "$e8e00f (POWEROFF) <- %02x", data); + break; + } + if (data == sig[sysport.pwoff_count]) { sysport.pwoff_count++; } else { @@ -160,13 +176,14 @@ SysportDevice::Write(uint32 offset, uint if (sysport.pwoff_count == sig.size()) { // pwoff_count はここではクリアせず、電源オン時に再初期化する。 putlog(1, "$e8e00f (POWEROFF) Power Off"); - gPower->SetSystemPowerOn(false); + GetPowerDevice()->SetSystemPowerOn(false); } break; } default: - __unreachable(); + VMPANIC("corrupted offset=%d", offset); + break; } return 0; } @@ -189,7 +206,7 @@ SysportDevice::Peek(uint32 offset) case SYSPORT::KEY: // XXX bit3 以外は要実機確認 data = 0xf7; - if (gKeyboard->IsConnected()) { + if (keyboard->IsConnected()) { data |= 0x08; } break; @@ -206,7 +223,8 @@ SysportDevice::Peek(uint32 offset) data = 0xff; break; default: - __unreachable(); + data = 0xff; + break; } return data; }