--- nono/vm/spc.cpp 2026/04/29 17:04:50 1.1.1.8 +++ nono/vm/spc.cpp 2026/04/29 17:04:56 1.1.1.10 @@ -27,9 +27,8 @@ std::unique_ptr gSPC; // コンストラクタ SPCDevice::SPCDevice() + : inherited("SPC") { - logname = "spc"; - devname = "SPC"; // これらは XIOSpace で必要なので、LUNA ではダミー。 // もうちょっといい方法を考えたほうがいい。 devaddr = 0xe96000; @@ -40,13 +39,15 @@ SPCDevice::SPCDevice() // 汎用イベント // 名前とコールバック関数は都度セットする。 - event.dev = this; event.SetName("SPC phase"); // TC カウンタイベント - event_tc.dev = this; event_tc.code = 0; event_tc.SetName("SPC Timer"); + + monitor.func = (MonitorCallback_t)&SPCDevice::MonitorUpdate; + // サイズは Init で決まる + monitor.Regist(ID_MONITOR_SPC); } // デストラクタ @@ -111,7 +112,7 @@ SPCDevice::Init() connected_devices.push_back(target[id].get()); } } - monitor_size = nnSize(70, 15 + connected_devices.size()); + monitor.SetSize(70, 15 + connected_devices.size()); return true; } @@ -428,7 +429,7 @@ SPCDevice::Peek(uint32 offset) } void -SPCDevice::MonitorUpdate(TextScreen& monitor) +SPCDevice::MonitorUpdate(Monitor *, TextScreen& screen) { int x; int y; @@ -442,7 +443,7 @@ SPCDevice::MonitorUpdate(TextScreen& mon uint32 pctl; uint32 tc; - monitor.Clear(); + screen.Clear(); sctl = spc.sctl; scmd = spc.scmd; @@ -455,30 +456,30 @@ SPCDevice::MonitorUpdate(TextScreen& mon tc = spc.tc; y = 0; - monitor.Print(0, y++, "BDID: $%02x (ID=%d)", (1 << myid), myid); - monitor.Print(0, y++, "SCTL: $%02x", sctl); - monitor.Print(0, y++, "SCMD: $%02x", scmd); - monitor.Print(0, y++, "INTS: $%02x", ints); - monitor.Print(0, y++, "PSNS: $%02x", psns); - monitor.Print(0, y++, "SDGC: $%02x", sdgc); - monitor.Print(0, y++, "SSTS: $%02x", ssts); - monitor.Print(0, y++, "SERR: $%02x", serr); - monitor.Print(0, y++, "PCTL: $%02x", pctl); - monitor.Print(0, y++, "MBC : $XX"); - monitor.Print(0, y, "DREG: "); + screen.Print(0, y++, "BDID: $%02x (ID=%d)", (1 << myid), myid); + screen.Print(0, y++, "SCTL: $%02x", sctl); + screen.Print(0, y++, "SCMD: $%02x", scmd); + screen.Print(0, y++, "INTS: $%02x", ints); + screen.Print(0, y++, "PSNS: $%02x", psns); + screen.Print(0, y++, "SDGC: $%02x", sdgc); + screen.Print(0, y++, "SSTS: $%02x", ssts); + screen.Print(0, y++, "SERR: $%02x", serr); + screen.Print(0, y++, "PCTL: $%02x", pctl); + screen.Print(0, y++, "MBC : $XX"); + screen.Print(0, y, "DREG: "); { uint i; for (i = 0; i < spc.dreg.Length(); i++) { - monitor.Print(6 + i * 4, y, "$%02x", spc.dreg.Peek(i)); + screen.Print(6 + i * 4, y, "$%02x", spc.dreg.Peek(i)); } for (; i < 8; i++) { - monitor.Print(6 + i * 4, y, TA::Disable, "---"); + screen.Print(6 + i * 4, y, TA::Disable, "---"); } } y++; - monitor.Print(0, y++, "TEMP: $%02x(IN) $%02x(OUT)", + screen.Print(0, y++, "TEMP: $%02x(IN) $%02x(OUT)", spc.temp_in, spc.temp_out); - monitor.Print(0, y++, "TC : $%06x", tc); + screen.Print(0, y++, "TC : $%06x", tc); x = 10; y = 1; @@ -487,14 +488,14 @@ SPCDevice::MonitorUpdate(TextScreen& mon static const char * const sctl_bits[] = { "RST", "CTRL", "DIAG", "ARB", "PARI", "SEL", "RESL", "INTR" }; - MonitorReg(monitor, x, y, sctl, sctl_bits); + MonitorReg(screen, x, y, sctl, sctl_bits); y++; // SCMD static const char * const scmd_bits[] = { "", "", "", "RST", "INTC", "PROG", "", "TERM" }; - MonitorReg(monitor, x, y, scmd, scmd_bits); + MonitorReg(screen, x, y, scmd, scmd_bits); static const char * const scmd_cmd[] = { //12345678901234 "(Bus Release)", @@ -506,35 +507,35 @@ SPCDevice::MonitorUpdate(TextScreen& mon "(ResetACK/REQ)", "(Set ACK/REQ)", }; - monitor.Puts(x, y, scmd_cmd[scmd >> 5]); + screen.Puts(x, y, scmd_cmd[scmd >> 5]); y++; // INTS static const char * const ints_bits[] = { "Sel", "Resl", "Disc", "Cmpl", "SReq", "TOut", "HErr", "Rst" }; - MonitorReg(monitor, x, y, ints, ints_bits); + MonitorReg(screen, x, y, ints, ints_bits); y++; // PSNS static const char * const psns_bits[] = { "REQ", "ACK", "ATN", "SEL", "BSY", "MSG", "C/D", "I/O" }; - MonitorReg(monitor, x, y, psns, psns_bits); + MonitorReg(screen, x, y, psns, psns_bits); y++; // SDGC static const char * const sdgc_bits[] = { "", "", "XfEn", "", "", "", "", "" }; - MonitorReg(monitor, x, y, sdgc, sdgc_bits); + MonitorReg(screen, x, y, sdgc, sdgc_bits); y++; // SSTS static const char * const ssts_bits[] = { "", "", "SBSY", "XInP", "RSTI", "TCZ", "Full", "Empt" }; - MonitorReg(monitor, x, y, ssts, ssts_bits); + MonitorReg(screen, x, y, ssts, ssts_bits); static const char * const ssts_conn[] = { //12345678 "(NotConn)", @@ -542,21 +543,21 @@ SPCDevice::MonitorUpdate(TextScreen& mon "(As Init)", "(undef?)", }; - monitor.Puts(x, y, ssts_conn[ssts >> 6]); + screen.Puts(x, y, ssts_conn[ssts >> 6]); y++; // SERR static const char * const serr_bits[] = { "", "", "XOut", "", "PErr", "", "Shrt", "" }; - MonitorReg(monitor, x, y, serr, serr_bits); + MonitorReg(screen, x, y, serr, serr_bits); y++; // PCTL static const char * const pctl_bits[] = { "BIE", "", "", "", "", "MSG", "C/D", "I/O" }; - MonitorReg(monitor, x, y, pctl, pctl_bits); + MonitorReg(screen, x, y, pctl, pctl_bits); y++; // バス状態 @@ -586,47 +587,47 @@ SPCDevice::MonitorUpdate(TextScreen& mon ack = GetACK(); data = GetData(); } - monitor.Print(x, y++, "Phase: %s", SCSI::GetPhaseName(ph)); - monitor.Puts(x, y++, TA::OnOff(rst), "RST"); - monitor.Puts(x, y++, TA::OnOff(bsy), "BSY"); - monitor.Puts(x, y++, TA::OnOff(sel), "SEL"); - monitor.Puts(x, y++, TA::OnOff(msg), "MSG"); - monitor.Puts(x, y++, TA::OnOff(cd), "CD"); - monitor.Puts(x, y++, TA::OnOff(io), "IO"); - monitor.Puts(x, y++, TA::OnOff(atn), "ATN"); - monitor.Puts(x, y++, TA::OnOff(req), "REQ"); - monitor.Puts(x, y++, TA::OnOff(ack), "ACK"); - monitor.Print(x, y++, "DATA:$%02x", data); + screen.Print(x, y++, "Phase: %s", SCSI::GetPhaseName(ph)); + screen.Puts(x, y++, TA::OnOff(rst), "RST"); + screen.Puts(x, y++, TA::OnOff(bsy), "BSY"); + screen.Puts(x, y++, TA::OnOff(sel), "SEL"); + screen.Puts(x, y++, TA::OnOff(msg), "MSG"); + screen.Puts(x, y++, TA::OnOff(cd), "CD"); + screen.Puts(x, y++, TA::OnOff(io), "IO"); + screen.Puts(x, y++, TA::OnOff(atn), "ATN"); + screen.Puts(x, y++, TA::OnOff(req), "REQ"); + screen.Puts(x, y++, TA::OnOff(ack), "ACK"); + screen.Print(x, y++, "DATA:$%02x", data); y = 2; - monitor.Puts(x + 4, y++, "(________)"); - monitor.Puts(x + 4, y++, "(________)"); - monitor.Puts(x + 4, y++, "+"); - monitor.Puts(x + 4, y++, "|"); - monitor.Puts(x + 4, y++, "+"); + screen.Puts(x + 4, y++, "(________)"); + screen.Puts(x + 4, y++, "(________)"); + screen.Puts(x + 4, y++, "+"); + screen.Puts(x + 4, y++, "|"); + screen.Puts(x + 4, y++, "+"); // BSY, SEL の内訳。"(76543210)" の順。 y = 2; for (int i = 0; i < 8; i++) { if ((bsy & (1 << i))) { - monitor.Print(x + 4 + 8 - i, y, "%d", i); + screen.Print(x + 4 + 8 - i, y, "%d", i); } else { - monitor.Print(x + 4 + 8 - i, y, "_"); + screen.Print(x + 4 + 8 - i, y, "_"); } } y++; for (int i = 0; i < 8; i++) { if ((sel & (1 << i))) { - monitor.Print(x + 4 + 8 - i, y, "%d", i); + screen.Print(x + 4 + 8 - i, y, "%d", i); } else { - monitor.Print(x + 4 + 8 - i, y, "_"); + screen.Print(x + 4 + 8 - i, y, "_"); } } // 転送フェーズ中なら現在の XferPhase y += 2; if (ph == SCSI::Phase::Transfer) { - monitor.Puts(x + 5, y, SCSI::GetXferPhaseName(GetXfer())); + screen.Puts(x + 5, y, SCSI::GetXferPhaseName(GetXfer())); } // デバイス一覧 @@ -637,7 +638,7 @@ SPCDevice::MonitorUpdate(TextScreen& mon // 7: Initiator x = 0; y = 14; - monitor.Print(x, y++, "ID Device Command"); + screen.Print(x, y++, "ID Device Command"); for (const auto d : connected_devices) { std::string desc = "?"; switch (d->GetDevType()) { @@ -668,7 +669,7 @@ SPCDevice::MonitorUpdate(TextScreen& mon } else { idc = '-'; } - monitor.Print(x, y, "%c: %s", idc, desc.c_str()); + screen.Print(x, y, "%c: %s", idc, desc.c_str()); y++; } @@ -690,7 +691,7 @@ SPCDevice::MonitorUpdate(TextScreen& mon } } const char *cmdname = SCSI::GetCommandName(cmds[0]); - monitor.Print(x, y + i, "$%02x %s", cmds[0], cmdname ?: ""); + screen.Print(x, y + i, "$%02x %s", cmds[0], cmdname ?: ""); } } } @@ -699,12 +700,12 @@ SPCDevice::MonitorUpdate(TextScreen& mon // レジスタをビットごとに表示する。MonitorUpdate の下請け。 void -SPCDevice::MonitorReg(TextScreen& monitor, +SPCDevice::MonitorReg(TextScreen& screen, int x, int y, uint32 reg, const char * const *names) { for (int i = 0; i < 8; i++) { bool b = reg & (1 << (7 - i)); - monitor.Puts(x + i * 5, y, TA::OnOff(b), names[i]); + screen.Puts(x + i * 5, y, TA::OnOff(b), names[i]); } } @@ -949,10 +950,10 @@ SPCDevice::GetSSTS() const if (spc.tc == 0) { // TC がゼロか data |= SPC::SSTS_TC_ZERO; } - if (spc.dreg.Length() == 8) { + if (spc.dreg.IsFull()) { data |= SPC::SSTS_DREG_FULL; } - if (spc.dreg.Length() == 0) { + if (spc.dreg.Empty()) { data |= SPC::SSTS_DREG_EMPTY; }