--- nono/vm/sysport.cpp 2026/04/29 17:05:17 1.1.1.10 +++ nono/vm/sysport.cpp 2026/04/29 17:05:37 1.1.1.15 @@ -11,18 +11,22 @@ #include "sysport.h" #include "keyboard.h" #include "mainram.h" +#include "monitor.h" #include "mpu.h" #include "nmi.h" #include "power.h" #include "romimg_x68k.h" #include "sram.h" +#include "videoctlr.h" #include // コンストラクタ SysportDevice::SysportDevice() : inherited(OBJ_SYSPORT) { - AddAlias("SysPort"); + monitor = gMonitorManager->Regist(ID_MONITOR_SYSPORT, this); + monitor->func = ToMonitorCallback(&SysportDevice::MonitorUpdate); + monitor->SetSize(56, 8); } // デストラクタ @@ -34,10 +38,6 @@ SysportDevice::~SysportDevice() bool SysportDevice::Init() { - if (inherited::Init() == false) { - return false; - } - cgrom = GetCGROMDevice(); iplrom1 = GetIPLROM1Device(); iplrom2 = GetIPLROM2Device(); @@ -45,6 +45,7 @@ SysportDevice::Init() mainram = GetMainRAMDevice(); nmi = GetNMIDevice(); sram = GetSRAMDevice(); + videoctlr = GetVideoCtlrDevice(); return true; } @@ -53,7 +54,6 @@ SysportDevice::Init() void SysportDevice::ResetHard(bool poweron) { - sysport.contrast = 0; // XXX 未調査 sysport.ram_wait = 0; sysport.rom_wait = 0; sysport.key_ctrl = false; @@ -61,54 +61,25 @@ SysportDevice::ResetHard(bool poweron) GetPowerDevice()->SetSystemPowerOn(true); } -uint64 -SysportDevice::Read(uint32 offset) +busdata +SysportDevice::ReadPort(uint32 offset) { - uint32 data; + busdata data; - switch (offset) { - case SYSPORT::CONTRAST: - data = 0xf0 | sysport.contrast; - break; - case SYSPORT::SCOPE3D: - data = 0xff; - break; - case SYSPORT::IMAGEUNIT: - data = 0xff; - break; - case SYSPORT::KEY: - // XXX bit3 以外は要実機確認 - data = 0xf7; - if (keyboard->IsConnected()) { - data |= 0x08; - } - break; - case SYSPORT::WAIT: - data = 0xff; - break; - case SYSPORT::MPU: - data = 0xdc; - break; - case SYSPORT::SRAMWP: - data = 0xff; - break; - case SYSPORT::POWEROFF: - data = 0xff; - break; - default: - VMPANIC("corrupted offset=%d", offset); - return 0xff; - } - putlog(2, "$%06x -> $%02x", mpu->GetPaddr(), data); + data = PeekPort(offset); + putlog(2, "$%06x -> $%02x", mpu->GetPaddr(), data.Data()); + + data |= BusData::Size1; return data; } -uint64 -SysportDevice::Write(uint32 offset, uint32 data) +busdata +SysportDevice::WritePort(uint32 offset, uint32 data) { switch (offset) { case SYSPORT::CONTRAST: - sysport.contrast = data & 15; + putlog(1, "$e8e001 <- $%02x", data); + videoctlr->SetContrast(data & 15); break; case SYSPORT::SCOPE3D: @@ -130,19 +101,24 @@ SysportDevice::Write(uint32 offset, uint case SYSPORT::WAIT: { - // 設定値で保持 - sysport.rom_wait = data >> 4; - sysport.ram_wait = data; - - // ROM に指示。常に設定値 + 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; - mainram->SetWait(wait); + uint32 rom_wait = data >> 4; + uint32 ram_wait = data & 0xf; + + // InsideOut p.124 + rom_wait += 2; + if (ram_wait > 0) { + ram_wait += 2; + } + + // ROM/RAM に指示。 + iplrom1->SetWait(rom_wait); + iplrom2->SetWait(rom_wait); + cgrom->SetWait(rom_wait); + mainram->SetWait(ram_wait); + + // ROM/RAM への指定値で保持する。 + sysport.rom_wait = rom_wait; + sysport.ram_wait = ram_wait; break; } @@ -172,7 +148,7 @@ SysportDevice::Write(uint32 offset, uint } else { sysport.pwoff_count = 0; } - putlog(2, "$e8e00f (POWEROFF) <- %02x (count=%d)", + putlog(2, "$e8e00f (POWEROFF) <- %02x (count=%u)", data, sysport.pwoff_count); if (sysport.pwoff_count == sig.size()) { // pwoff_count はここではクリアせず、電源オン時に再初期化する。 @@ -183,20 +159,22 @@ SysportDevice::Write(uint32 offset, uint } default: - VMPANIC("corrupted offset=%d", offset); + VMPANIC("corrupted offset=%u", offset); break; } - return 0; + + busdata r = BusData::Size1; + return r; } -uint64 -SysportDevice::Peek(uint32 offset) +busdata +SysportDevice::PeekPort(uint32 offset) { uint32 data; switch (offset) { case SYSPORT::CONTRAST: - data = 0xf0 | sysport.contrast; + data = 0xf0 | videoctlr->GetContrast(); break; case SYSPORT::SCOPE3D: data = 0xff; @@ -229,3 +207,66 @@ SysportDevice::Peek(uint32 offset) } return data; } + +bool +SysportDevice::PokePort(uint32 offset, uint32 data) +{ + return false; +} + +void +SysportDevice::MonitorUpdate(Monitor *, TextScreen& screen) +{ + screen.Clear(); + + static const char * const name[] = { + "Contrast", + "3D Scope", + "Image Unit", + "Keyboard Control", + "ROM/RAM Wait", + "MPU/FPU Type", + "SRAM Protect", + "PowerOff Sequence", + }; + + uint8 val[8]; + const uint32 disphex = 0x39; + for (int i = 0; i < 8; i++) { + char hex[4]; + if ((disphex & (1U << i)) != 0) { + val[i] = PeekPort(i); + snprintf(hex, sizeof(hex), "%02x", val[i]); + } else { + strlcpy(hex, "--", sizeof(hex)); + } + + screen.Print(0, i, "$%06x %s: #%u %-17s:", + baseaddr + 1 + i * 2, hex, i, name[i]); + } + + int x = 34; + // #0 Contrast + screen.Print(x, 0, "%2u", videoctlr->GetContrast()); + screen.Puts(x, 1, "(Not Supported)"); + screen.Puts(x, 2, "(Not Supported)"); + // #3 Keyboard + if ((val[SYSPORT::KEY] & 0x08) != 0) { + screen.Puts(x, 3, "Connected"); + } else { + screen.Puts(x, 3, "Not connected"); + } + // #4 ROM/RAM Wait + screen.Print(x, 4, "ROM %2u clk, RAM %2u clk", + sysport.rom_wait, sysport.ram_wait); + // #5 MPU/FPU Type + screen.Puts(x, 5, "MC68030 / 25MHz"); + // #6 SRAM + if (sram->IsWriteable()) { + screen.Puts(x, 6, "Writeable"); + } else { + screen.Puts(x, 6, "Protected"); + } + // #7 PowerOff + screen.Print(x, 7, "%u/3", sysport.pwoff_count); +}