--- nono/vm/sysport.cpp 2026/04/29 17:04:28 1.1.1.1 +++ nono/vm/sysport.cpp 2026/04/29 17:04:32 1.1.1.2 @@ -18,17 +18,29 @@ SysportDevice::~SysportDevice() { } +// アドレスデコーダ +inline uint64 +SysportDevice::Decoder(uint32 addr) const +{ + // 折り返しは? + addr -= baseaddr; + + // 偶数アドレスはバスエラー? + if ((addr & 1) == 0) + return (uint64)-1; + + return addr >> 1; +} + uint64 SysportDevice::Read8(uint32 addr) { uint32 data; - if ((addr % 2) == 0) { - return 0xff; - } + switch (Decoder(addr)) { + default: + return (uint64)-1; - int n = (addr - baseaddr) / 2; - switch (n) { case SYSPORT::CONTRAST: data = 0xf0 | sysport.contrast; break; @@ -39,8 +51,8 @@ SysportDevice::Read8(uint32 addr) data = 0xff; break; case SYSPORT::KEY: - // キーボードは接続されていない - data = 0x00; + // キーボードは接続されてることにする + data = 0x08; break; case SYSPORT::WAIT: data = 0xff; @@ -51,8 +63,6 @@ SysportDevice::Read8(uint32 addr) case SYSPORT::SRAMWP: data = 0xff; break; - default: - return (uint64)-1; } putlog(1, "$%06X -> $%02x", addr, data); return data; @@ -67,12 +77,10 @@ SysportDevice::Read16(uint32 addr) uint64 SysportDevice::Write8(uint32 addr, uint32 data) { - if ((addr % 2) == 0) { + switch (Decoder(addr)) { + default: return (uint64)-1; - } - int n = (addr - baseaddr) / 2; - switch (n) { case SYSPORT::CONTRAST: sysport.contrast = data & 15; break; @@ -105,9 +113,6 @@ SysportDevice::Write8(uint32 addr, uint3 case SYSPORT::POWEROFF: putlog(0, "$E8E00F (POWEROFF) 未サポート書き込み %02x", data); break; - - default: - return (uint64)-1; } return 0; } @@ -123,12 +128,7 @@ SysportDevice::Peek8(uint32 addr) { uint32 data; - if ((addr % 2) == 0) { - return 0xff; - } - - int n = (addr - baseaddr) / 2; - switch (n) { + switch (Decoder(addr)) { case SYSPORT::CONTRAST: data = 0xf0 | sysport.contrast; break;