--- nono/vm/scc.cpp 2026/04/29 17:05:17 1.1.1.12 +++ nono/vm/scc.cpp 2026/04/29 17:05:28 1.1.1.14 @@ -12,7 +12,10 @@ #include "bitops.h" #include "hostcom.h" #include "keyboard.h" -#include "mpu.h" + +// InsideOut p.135 +static const busdata read_wait = busdata::Wait(41 * 40_nsec); +static const busdata write_wait = busdata::Wait(49 * 40_nsec); // コンストラクタ SCCDevice::SCCDevice() @@ -165,6 +168,8 @@ SCCDevice::ResetChannel(MPSCCChan& chan) chan.wr15 = 0xf8; // RR0 b0,1=%0、b2,6=%1 + chan.rxlen = 0; + chan.txlen = 0; chan.tx_underrun = true; // RR1 b1,2=%1、b3-7=%0 @@ -184,12 +189,10 @@ SCCDevice::ResetChannel(MPSCCChan& chan) ResetChannelCommon(chan); } -uint64 -SCCDevice::Read(uint32 offset) +busdata +SCCDevice::ReadPort(uint32 offset) { - uint64 data; - - mpu->AddCycle(41); // InsideOut p.135 + busdata data; switch (offset) { case 0: // $E98001 @@ -205,16 +208,17 @@ SCCDevice::Read(uint32 offset) data = ReadData(mpscc.chan[0]); break; default: - VMPANIC("corrupted offset=%d", offset); + VMPANIC("corrupted offset=%u", offset); } + + data |= read_wait; + data |= BusData::Size1; return data; } -uint64 -SCCDevice::Write(uint32 offset, uint32 data) +busdata +SCCDevice::WritePort(uint32 offset, uint32 data) { - mpu->AddCycle(49); // InsideOut p.135 - switch (offset) { case 0: // $E98001 WriteCtrl(mpscc.chan[1], data); @@ -229,13 +233,16 @@ SCCDevice::Write(uint32 offset, uint32 d WriteData(mpscc.chan[0], data); break; default: - VMPANIC("corrupted offset=%d", offset); + VMPANIC("corrupted offset=%u", offset); } - return 0; + + busdata r = write_wait; + r |= BusData::Size1; + return r; } -uint64 -SCCDevice::Peek(uint32 offset) +busdata +SCCDevice::PeekPort(uint32 offset) { uint64 data; @@ -261,20 +268,20 @@ SCCDevice::Peek(uint32 offset) // 書き込みレジスタ名を返す。 const char * -SCCDevice::CRName(const MPSCCChan& chan, int ptr_) const +SCCDevice::CRName(const MPSCCChan& chan, uint ptr_) const { assert(ptr_ < 16); - int idx = ptr_ * 2 + chan.id; + uint idx = ptr_ * 2 + chan.id; assert(idx < countof(wrnames)); return wrnames[idx]; } // 読み込みレジスタ名を返す。 const char * -SCCDevice::SRName(const MPSCCChan& chan, int ptr_) const +SCCDevice::SRName(const MPSCCChan& chan, uint ptr_) const { assert(ptr_ < 16); - int idx = ptr_ * 2 + chan.id; + uint idx = ptr_ * 2 + chan.id; assert(idx < countof(rrnames)); return rrnames[idx]; } @@ -331,12 +338,12 @@ SCCDevice::ReadCtrl(MPSCCChan& chan) case 14: case 15: case 11: - putlog(0, "ReadCtrl %d (NOT IMPLEMENTED)", chan.ptr); + putlog(0, "ReadCtrl %u (NOT IMPLEMENTED)", chan.ptr); data = 0xff; break; default: - VMPANIC("corrupted chan.ptr=%d", chan.ptr); + VMPANIC("corrupted chan.ptr=%u", chan.ptr); } chan.ptr = 0; return data; @@ -400,7 +407,7 @@ SCCDevice::WriteCtrl(MPSCCChan& chan, ui WriteWR15(chan, data); break; default: - VMPANIC("corrupted chan.ptr=%d", chan.ptr); + VMPANIC("corrupted chan.ptr=%u", chan.ptr); } // アクセス後は WR0 へ戻す chan.ptr = 0; @@ -457,7 +464,7 @@ SCCDevice::PeekCtrl(const MPSCCChan& cha break; default: - VMPANIC("corrupted chan.ptr=%d", chan.ptr); + VMPANIC("corrupted chan.ptr=%u", chan.ptr); } return data; } @@ -487,7 +494,7 @@ SCCDevice::GetWR1(const MPSCCChan& chan) data |= MPSCC::WR1_RXINT_SPONLY; break; default: - VMPANIC("corrupted rxint_mode=%d", (int)chan.rxint_mode); + VMPANIC("corrupted rxint_mode=%u", (uint)chan.rxint_mode); } if (chan.sp_parity) data |= MPSCC::WR1_SP_INC_PE; @@ -568,14 +575,14 @@ SCCDevice::WriteWR0(MPSCCChan& chan, uin if (chan.crc_cmd != 0) { // CRC は非同期モードでは不要のはず - putlog(3, "%s CRC Reset %d (NOT IMPLEMENTED)", + putlog(3, "%s CRC Reset %u (NOT IMPLEMENTED)", WRName(chan, 0), chan.crc_cmd); } if (chan.cmd == 0 || chan.cmd == 1) { // コマンド 0、1 がレジスタ切り替え chan.ptr = data & MPSCC::WR0_PTR; - putlog(3, "%s <- $%02x (ptr=%d)", WRName(chan, 0), data, chan.ptr); + putlog(3, "%s <- $%02x (ptr=%u)", WRName(chan, 0), data, chan.ptr); } else { // それ以外ならコマンド発行 putlog(2, "%s <- $%02x", CRName(chan, 0), data); @@ -600,7 +607,7 @@ SCCDevice::WriteWR0(MPSCCChan& chan, uin ResetHighestIUS(chan); break; default: - VMPANIC("corrupted chan.cmd=%d", chan.cmd); + VMPANIC("corrupted chan.cmd=%u", chan.cmd); } } } @@ -670,7 +677,7 @@ SCCDevice::WriteWR9(uint32 data) ResetHard(false); break; default: - VMPANIC("corrupted mpscc.wr9_cmd=%d", mpscc.wr9_cmd); + VMPANIC("corrupted mpscc.wr9_cmd=%u", mpscc.wr9_cmd); } // これらはハードウェアリセットと同時に指定されたら、 @@ -857,7 +864,7 @@ SCCDevice::MonitorUpdateCh(TextScreen& s screen.Print(x, y++, "RR0: $%02x", rr0); screen.Print(x, y++, "RR1: $%02x", rr1); screen.Print(x, y++, "RR10:$%02x", rr10); - screen.Print(x, y, "RXbuf: %d", rxlen); + screen.Print(x, y, "RXbuf: %u", rxlen); int i; for (i = 0; i < rxlen; i++) { screen.Print(x + 9 + i * 4, y, "$%02x", chan.rxbuf[i]); @@ -869,7 +876,7 @@ SCCDevice::MonitorUpdateCh(TextScreen& s y = ybase + 1; x = xbase; // WR0 - screen.Print(x + 9, y, "CRC=%d", crc); + screen.Print(x + 9, y, "CRC=%u", crc); static const char * const cmd_str[] = { // 012345678901234 "Null command", @@ -881,8 +888,8 @@ SCCDevice::MonitorUpdateCh(TextScreen& s "Error Reset", "ResetHighestIUS", }; - screen.Print(x + 19, y, "CMD=%d(%s)", cmd, cmd_str[cmd]); - screen.Print(x + 43 - (ptr > 9 ? 1 : 0), y, "PTR=%d", ptr); + screen.Print(x + 19, y, "CMD=%u(%s)", cmd, cmd_str[cmd]); + screen.Print(x + 43 - (ptr > 9 ? 1 : 0), y, "PTR=%u", ptr); y++; // WR1 @@ -1003,8 +1010,8 @@ SCCDevice::MonitorUpdateCh(TextScreen& s } y++; 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); + screen.Print(x, y++, "Rx Bits/Frame: %2u", chan.rxframebits); + screen.Print(x, y++, "Tx Bits/Frame: %2u", chan.txframebits); } // 内部の送信データクロックの設定 @@ -1016,7 +1023,7 @@ SCCDevice::SetXC(MPSCCChan& chan) } // 割り込みアクノリッジ -int +busdata SCCDevice::InterruptAcknowledge() { return GetSR2B(); @@ -1051,7 +1058,7 @@ SCCDevice::Tx(int ch, uint32 data) // ChB はマウスだが TxD は接続されていない break; default: - VMPANIC("corrupted ch=%d", ch); + VMPANIC("corrupted ch=%u", ch); } }