--- nono/vm/sysport.cpp 2026/04/29 17:05:09 1.1.1.8 +++ nono/vm/sysport.cpp 2026/04/29 17:05:13 1.1.1.9 @@ -12,9 +12,11 @@ #include "keyboard.h" #include "mpu.h" #include "nmi.h" +#include "power.h" #include "ram.h" #include "romimg_x68k.h" #include "sram.h" +#include // グローバル参照用 SysportDevice *gSysport; @@ -43,6 +45,8 @@ SysportDevice::ResetHard(bool poweron) sysport.ram_wait = 0; sysport.rom_wait = 0; sysport.key_ctrl = false; + sysport.pwoff_count = 0; + gPower->SetSystemPowerOn(true); } uint64 @@ -82,7 +86,7 @@ SysportDevice::Read(uint32 offset) default: __unreachable(); } - putlog(1, "$%06X -> $%02x", gMPU->GetPaddr(), data); + putlog(2, "$%06x -> $%02x", gMPU->GetPaddr(), data); return data; } @@ -102,7 +106,7 @@ SysportDevice::Write(uint32 offset, uint data &= 0x0e; // bit1 if ((data & 0x02)) { - putlog(0, "$E8E007 未サポート書き込み $%02x", data); + putlog(0, "$e8e007 <- $%02x (HRL NOT IMPLEMENTED)", data); } // bit2: NMI リセット if ((data & 0x04)) { @@ -141,8 +145,25 @@ SysportDevice::Write(uint32 offset, uint break; case SYSPORT::POWEROFF: - putlog(0, "$e8e00f (POWEROFF) 未サポート書き込み %02x", data); + { + static const std::array sig { 0x00, 0x0f, 0x0f }; + + assertmsg(sysport.pwoff_count < sig.size(), + "sysport.pwoff_count=%d", sysport.pwoff_count); + if (data == sig[sysport.pwoff_count]) { + sysport.pwoff_count++; + } else { + sysport.pwoff_count = 0; + } + putlog(2, "$e8e00f (POWEROFF) <- %02x (count=%d)", + data, sysport.pwoff_count); + if (sysport.pwoff_count == sig.size()) { + // pwoff_count はここではクリアせず、電源オン時に再初期化する。 + putlog(1, "$e8e00f (POWEROFF) Power Off"); + gPower->SetSystemPowerOn(false); + } break; + } default: __unreachable();