--- nono/vm/sio.cpp 2026/04/29 17:04:29 1.1.1.2 +++ nono/vm/sio.cpp 2026/04/29 17:05:06 1.1.1.8 @@ -1,10 +1,12 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "sio.h" -#include "mpu.h" +#include "interrupt.h" +#include "keyboard.h" // IODevice // | @@ -16,48 +18,45 @@ // SIODevice SCCDevice // (LUNA, uPD7201) (X68030, Z8530) -SIODevice *gSIO; +std::unique_ptr gSIO; SIODevice::SIODevice() + : inherited("SIO") { - logname = "sio"; - devname = "SIO"; devaddr = 0x51000000; cr.chan[0].desc = "Serial Console"; cr.chan[1].desc = "Keyboard"; -} -SIODevice::~SIODevice() -{ + // 153.6kHz = 6.510416...usec / bit; + // 12bit = 78.125usec + txc12_ns = 78.125_usec; + + // LUNA では SIO と呼ぶほうが通りがいい。 + for (int ch = 0; ch < txevent.size(); ch++) { + txevent[ch].SetName(string_format("SIO Ch%s TX", cr.chan[ch].name)); + } + monitor.Regist(ID_MONITOR_SIO); } -// 本体リセットスイッチによるリセット -void -SIODevice::ResetHard() +SIODevice::~SIODevice() { - // チップリセット - Reset(); } uint64 -SIODevice::Read8(uint32 addr) +SIODevice::Read(uint32 offset) { uint32 data; - // アドレスは8バイト単位でミラーのようだ。 - uint32 an = addr & 7; - - // 奇数バイトは偶数バイトのミラーが見えるようだ。 - switch (an / 2) { + switch (offset) { case 0: - data = ReadData(0); + data = ReadData(&cr.chan[0]); break; case 1: data = ReadCtrl(&cr.chan[0]); break; case 2: - data = ReadData(1); + data = ReadData(&cr.chan[1]); break; case 3: data = ReadCtrl(&cr.chan[1]); @@ -69,23 +68,9 @@ SIODevice::Read8(uint32 addr) } uint64 -SIODevice::Read16(uint32 addr) +SIODevice::Write(uint32 offset, uint32 data) { - uint32 data = Read8(addr); - - // 奇数バイトは偶数バイトのミラーが見えるようだ。 - return (data << 8) | data; -} - -uint64 -SIODevice::Write8(uint32 addr, uint32 data) -{ - // アドレスは8バイト単位でミラーのようだ。 - uint32 an = addr & 7; - - // 奇数バイトは偶数バイトのミラーが見えるようだ。 - // XXX 書き込み側は確認してないけど - switch (an / 2) { + switch (offset) { case 0: WriteData(&cr.chan[0], data); return 0; @@ -106,10 +91,22 @@ SIODevice::Write8(uint32 addr, uint32 da } uint64 -SIODevice::Write16(uint32 addr, uint32 data) +SIODevice::Peek(uint32 offset) { - // バイト書き込み1回だけになるはず? - return Write8(addr, data); + switch (offset) { + case 0: + return PeekData(&cr.chan[0]); + + case 1: + return PeekCtrl(&cr.chan[0]); + + case 2: + return PeekData(&cr.chan[1]); + + case 3: + return PeekCtrl(&cr.chan[1]); + } + __unreachable(); } // 割り込みを上げる @@ -117,5 +114,20 @@ void SIODevice::Interrupt() { putlog(2, "Interrupt"); - gMPU->Interrupt(6); + gInterrupt->AssertINT(this); +} + +void +SIODevice::Tx(int ch, uint32 data) +{ + switch (ch) { + case 0: + // TODO: シリアル送信処理 + break; + case 1: + gKeyboard->Command(data); + break; + default: + __unreachable(); + } }