--- nono/vm/mainbus.cpp 2026/04/29 17:05:17 1.1 +++ nono/vm/mainbus.cpp 2026/04/29 17:05:20 1.1.1.2 @@ -15,6 +15,9 @@ MainbusDevice::MainbusDevice() : inherited(OBJ_MAINBUS) { + monitor.func = ToMonitorCallback(&MainbusDevice::MonitorUpdate); + monitor.SetSize(75, 33); + monitor.Regist(ID_MONITOR_MAINBUS); } // デストラクタ @@ -171,6 +174,52 @@ MainbusDevice::CopyDevtable(int dst, int memcpy(&devtable[dst], &devtable[src], sizeof(devtable[0]) * len); } +void +MainbusDevice::MonitorUpdate(Monitor *, TextScreen& screen) +{ + screen.Clear(); + + // 012345678901234567890 + // $0000'0000: 1234567 + + for (int i = 0; i < 8; i++) { + screen.Print(12 + i * 8, 0, "+$0%x", i); + } + + int idx = 0; + for (int i = 0; i < devtable.size() / 8; i++) { + screen.Print(0, i + 1, "$%02x00'0000:", idx); + for (int j = 0; j < 8; j++) { + auto pair = FormatDevName(devtable[idx]); + const std::string& name = pair.first; + TA attr = pair.second; + screen.Print(12 + j * 8, i + 1, attr, "%s", name.c_str()); + idx++; + } + } +} + +// モニタ表示用にデバイス名を整形。 +// 7文字に切り詰めるのと、括弧があれば取り除いて Disable 色にする。 +/*static*/ std::pair +MainbusDevice::FormatDevName(const Device *dev) +{ + std::string name = dev->GetName(); + TA attr; + + if (name[0] == '(') { + // 括弧付きなら、括弧を取り除いて Disable 色で表示 + int len = std::min(7, (int)name.size() - 2); + name = name.substr(1, len); + attr = TA::Disable; + } else { + name = name.substr(0, 7); + attr = TA::Normal; + } + + return std::make_pair(name, attr); +} + // Mainbus は1つしかないので、スタティック変数にしておく。 /*static*/ std::array MainbusDevice::devtable;