--- nono/vm/sio.cpp 2026/04/29 17:05:09 1.1.1.9 +++ nono/vm/sio.cpp 2026/04/29 17:05:24 1.1.1.12 @@ -14,14 +14,14 @@ #include "keyboard.h" #include "mainapp.h" -// グローバル参照用 -SIODevice *gSIO; - // コンストラクタ SIODevice::SIODevice() - : inherited("SIO") + : inherited() { - devaddr = 0x51000000; + SetName("SIO"); + ClearAlias(); + AddAlias("SIO"); + AddAlias("MPSCC"); mpscc.chan[0].desc = "Serial Console"; mpscc.chan[1].desc = "Keyboard"; @@ -30,7 +30,7 @@ SIODevice::SIODevice() // デバイス自身は自分が配置されるアドレスを知らなくてよい構造になって // いるが、直接アクセスしたりする場合などに毎回アドレスを確認するのが // 面倒なので(全機種で向きと間隔が異なる)、モニタで表示されてほしい。 - if (gMainApp.GetVMType() == VMTYPE_LUNA1) { + if (gMainApp.IsLUNA1()) { mpscc.chan[0].dataaddr = 0x51000000; mpscc.chan[0].ctrladdr = 0x51000002; mpscc.chan[1].dataaddr = 0x51000004; @@ -44,7 +44,8 @@ SIODevice::SIODevice() // 153.6kHz = 6.510416...usec / bit; // 12bit = 78.125usec - xc12_ns = 78.125_usec; + mpscc.chan[0].xc12_ns = 78.125_usec; + mpscc.chan[1].xc12_ns = 78.125_usec; // LUNA では SIO と呼ぶほうが通りがいい。 // イベントの登録は親クラスで行ってある。 @@ -55,14 +56,26 @@ SIODevice::SIODevice() } monitor.func = ToMonitorCallback(&SIODevice::MonitorUpdate); - monitor.SetSize(70, 22); + monitor.SetSize(70, 24); monitor.Regist(ID_MONITOR_SIO); } // デストラクタ SIODevice::~SIODevice() { - gSIO = NULL; +} + +// 初期化 +bool +SIODevice::Init() +{ + if (inherited::Init() == false) { + return false; + } + + keyboard = GetKeyboard(); + + return true; } // リセット @@ -101,12 +114,11 @@ SIODevice::ResetChannel(MPSCCChan& chan) chan.wait_enable = false; // CR3 b0-7 = %0 - chan.cr3 = 0; - chan.rx_enable = false; + SetCR3(chan, 0x00); // CR5 b1,2,3,4,7 = %0 - chan.cr5 &= 0x61; - chan.tx_enable = false; + uint8 val = GetCR5(chan); + SetCR5(chan, val & 0x61); // SR0 b0,1 = %0、b2,6 = %1 chan.rxlen = 0; @@ -123,10 +135,10 @@ SIODevice::ResetChannel(MPSCCChan& chan) ResetChannelCommon(chan); } -uint64 +busdata SIODevice::Read(uint32 offset) { - uint64 data; + busdata data; switch (offset) { case 0: @@ -142,12 +154,13 @@ SIODevice::Read(uint32 offset) data = ReadCtrl(mpscc.chan[1]); break; default: - __unreachable(); + VMPANIC("corrupted offset=%d", offset); } + // XXX wait? return data; } -uint64 +busdata SIODevice::Write(uint32 offset, uint32 data) { switch (offset) { @@ -164,12 +177,13 @@ SIODevice::Write(uint32 offset, uint32 d WriteCtrl(mpscc.chan[1], data); break; default: - __unreachable(); + VMPANIC("corrupted offset=%d", offset); } + // XXX wait? return 0; } -uint64 +busdata SIODevice::Peek(uint32 offset) { uint64 data; @@ -188,7 +202,8 @@ SIODevice::Peek(uint32 offset) data = PeekCtrl(mpscc.chan[1]); break; default: - __unreachable(); + data = 0xff; + break; } return data; } @@ -241,7 +256,7 @@ SIODevice::ReadCtrl(MPSCCChan& chan) default: // XXX どうなる? - putlog(0, "%s 未実装レジスタ読み込み", SRName(chan)); + putlog(0, "Read %s (NOT IMPLEMENTED)", SRName(chan)); // SR0 へ戻る? chan.ptr = 0; return 0xff; @@ -335,7 +350,7 @@ SIODevice::WriteCtrl(MPSCCChan& chan, ui WriteCR7(chan, data); break; default: - __unreachable(); + VMPANIC("corrupted chan.ptr=%d", chan.ptr); } // アクセス後は CR0 へ戻す chan.ptr = 0; @@ -453,7 +468,8 @@ SIODevice::WriteCR0(MPSCCChan& chan, uin chan.ptr = data & MPSCC::CR0_PTR; if (chan.crc_cmd != 0) { - putlog(0, "%s crc_cmd %d 未実装", CRName(chan, 0), chan.crc_cmd); + putlog(0, "%s crc_cmd %d (NOT IMPLEMENTED)", + CRName(chan, 0), chan.crc_cmd); } if (chan.cmd == 0) { @@ -491,11 +507,12 @@ SIODevice::WriteCR0(MPSCCChan& chan, uin if (chan.id == 0) { ResetHighestIUS(chan); } else { - putlog(0, "%s: Command 'End of Interrupt' 未定義", CRName(chan, 0)); + putlog(0, "%s: Command 'End of Interrupt' undefined", + CRName(chan, 0)); } break; default: - __unreachable(); + VMPANIC("corrupted chan.cmd=%d", chan.cmd); } } @@ -595,12 +612,12 @@ SIODevice::MonitorUpdate(Monitor *, Text screen.Clear(); for (int i = 0; i < 2; i++) { int x = 0; - y = i * 10; + y = i * 11; MonitorUpdateCh(screen, i, x, y); } // CR2A - y = 20; + y = 22; screen.Print(0, y, "CR2A:$%02x", cr2a); if ((cr2a & MPSCC::CR2_SYNCB)) { screen.Print(9, y, TA::On, "SYNC"); @@ -633,6 +650,8 @@ SIODevice::MonitorUpdateCh(TextScreen& s uint cr3; uint cr4; uint cr5; + uint cr6; + uint cr7; uint sr0; uint sr1; uint rxlen; @@ -642,8 +661,10 @@ SIODevice::MonitorUpdateCh(TextScreen& s cr0 = GetCR0(chan); cr1 = GetCR1(chan); cr3 = GetCR3(chan); - cr4 = chan.cr4; + cr4 = GetCR4(chan); cr5 = GetCR5(chan); + cr6 = chan.cr6; + cr7 = chan.cr7; sr0 = GetSR0(chan); sr1 = chan.sr1; rxlen = chan.rxlen; @@ -664,6 +685,7 @@ SIODevice::MonitorUpdateCh(TextScreen& s screen.Print(x, y++, "CR3: $%02x", cr3); screen.Print(x, y++, "CR4: $%02x", cr4); screen.Print(x, y++, "CR5: $%02x", cr5); + screen.Print(x, y++, "CR7/CR6: $%02x%02x", cr7, cr6); screen.Print(x, y++, "SR0: $%02x", sr0); screen.Print(x, y++, "SR1: $%02x", sr1); screen.Print(x, y, "RXbuf: %d", rxlen); @@ -725,6 +747,9 @@ SIODevice::MonitorUpdateCh(TextScreen& s // CR3,CR4,CR5 y = MonitorUpdateCR345(screen, x, y, cr3, cr4, cr5); + // CR6,CR7 + y++; + // SR0 static const char * const sr0_str[] = { "BrAb", "TxUn", "!CTS", "!SYN", "!DCD", "TxEm", "IntP", "RxAv" @@ -741,14 +766,14 @@ SIODevice::MonitorUpdateCh(TextScreen& s y++; // 右列 - y = ybase; + y = ybase + 1; x = xbase + 51; - screen.Print(x, y++, "DataAddr $%08x", chan.dataaddr); - screen.Print(x, y++, "CtrlAddr $%08x", chan.ctrladdr); + screen.Print(x, y++, "DataAddr: $%08x", chan.dataaddr); + screen.Print(x, y++, "CtrlAddr: $%08x", chan.ctrladdr); y++; - screen.Print(x, y++, "Param %12s", GetParamStr(chan).c_str()); - screen.Print(x, y++, "Rx Bits/Frame %2d", chan.rxbits); - screen.Print(x, y++, "Tx Bits/Frame %2d", chan.txbits); + screen.Print(x, y++, "Param:%13s", GetParamStr(chan).c_str()); + screen.Print(x, y++, "Rx Bits/Frame: %2d", chan.rxframebits); + screen.Print(x, y++, "Tx Bits/Frame: %2d", chan.txframebits); } // ペンディングのうち最も優先度の高い割り込み要因を返す @@ -799,10 +824,10 @@ SIODevice::Tx(int ch, uint32 data) hostcom->Tx(data); break; case 1: - gKeyboard->Command(data); + keyboard->Command(data); break; default: - __unreachable(); + VMPANIC("corrupted ch=%d", ch); } }