--- nono/vm/fdc.cpp 2026/04/29 17:05:25 1.1.1.12 +++ nono/vm/fdc.cpp 2026/04/29 17:05:33 1.1.1.14 @@ -80,7 +80,7 @@ #include "config.h" #include "dmac.h" #include "fdd.h" -#include "mpu.h" +#include "monitor.h" #include "pedec.h" #include "scheduler.h" @@ -97,19 +97,9 @@ FDCDevice::FDCDevice() : inherited(OBJ_FDC) { - phase_event.Regist("FDC Phase"); - - poll_event.func = ToEventCallback(&FDCDevice::PollEventCallback); - poll_event.time = 1024_usec; - poll_event.Regist("FDC Polling"); - - motor_event.func = ToEventCallback(&FDCDevice::MotorEventCallback); - motor_event.time = 38.54_sec; - motor_event.Regist("FDC SED9420A TMOUT"); - - monitor.func = ToMonitorCallback(&FDCDevice::MonitorUpdate); + monitor = gMonitorManager->Regist(ID_MONITOR_FDC, this); + monitor->func = ToMonitorCallback(&FDCDevice::MonitorUpdate); // サイズは Create() 時に確定する - monitor.Regist(ID_MONITOR_FDC); } // デストラクタ @@ -133,7 +123,7 @@ FDCDevice::Create() } // モニタサイズはここで決定。FDD は横に2台で、それ以上は縦に伸ばす。 - monitor.SetSize(80, 15 + (ndrive / 2) * 10); + monitor->SetSize(80, 15 + (ndrive / 2) * 10); // vector は面倒なので一旦 unique_ptr[] に確保して // 生ポインタの vector を作る。うーん。 @@ -162,6 +152,19 @@ FDCDevice::Init() dmac = GetDMACDevice(); pedec = GetPEDECDevice(); + phase_event.SetName("FDC Phase"); + scheduler->RegistEvent(phase_event); + + poll_event.func = ToEventCallback(&FDCDevice::PollEventCallback); + poll_event.time = 1024_usec; + poll_event.SetName("FDC Polling"); + scheduler->RegistEvent(poll_event); + + motor_event.func = ToEventCallback(&FDCDevice::MotorEventCallback); + motor_event.time = 38.54_sec; + motor_event.SetName("FDC SED9420A TMOUT"); + scheduler->RegistEvent(motor_event); + return true; } @@ -198,7 +201,7 @@ FDCDevice::ResetHard(bool poweron) } busdata -FDCDevice::Read(uint32 offset) +FDCDevice::ReadPort(uint32 offset) { busdata data; @@ -223,18 +226,19 @@ FDCDevice::Read(uint32 offset) break; default: - VMPANIC("corrupted offset=%d", offset); + VMPANIC("corrupted offset=%u", offset); } // InsideOut p.135 const busdata wait = busdata::Wait(19 * 40_nsec); data |= wait; + data |= BusData::Size1; return data; } busdata -FDCDevice::Write(uint32 offset, uint32 data) +FDCDevice::WritePort(uint32 offset, uint32 data) { switch (offset) { case 0: @@ -294,7 +298,7 @@ FDCDevice::Write(uint32 offset, uint32 d bool motor_on_bit_new = data & 0x80; if (motor_on_bit_new) { - putlog(1, "Access Drive <- $%02x (MotorOn %s #%d)", data, + putlog(1, "Access Drive <- $%02x (MotorOn %s #%u)", data, is2DD ? "2DD" : "2HD", accdrive); @@ -339,17 +343,19 @@ FDCDevice::Write(uint32 offset, uint32 d break; } default: - VMPANIC("corrupted offset=%d", offset); + VMPANIC("corrupted offset=%u", offset); } // InsideOut p.135 const busdata wait = busdata::Wait(19 * 40_nsec); - return wait; + busdata r = wait; + r |= BusData::Size1; + return r; } busdata -FDCDevice::Peek(uint32 offset) +FDCDevice::PeekPort(uint32 offset) { switch (offset) { case 0: @@ -390,6 +396,12 @@ FDCDevice::Peek(uint32 offset) } } +bool +FDCDevice::PokePort(uint32 offset, uint32 data) +{ + return false; +} + // モニタ更新 void FDCDevice::MonitorUpdate(Monitor *, TextScreen& screen) @@ -475,17 +487,17 @@ FDCDevice::MonitorUpdate(Monitor *, Text x = 52; y = 0; - screen.Print(x, y++, "HD=%d", hd); - screen.Print(x, y++, "US=%d", us); - screen.Print(x, y++, "TC=%d", tc); - screen.Print(x, y++, "DACK=%d", dack); + screen.Print(x, y++, "HD=%u", hd); + screen.Print(x, y++, "US=%u", us); + screen.Print(x, y++, "TC=%u", tc); + screen.Print(x, y++, "DACK=%u", dack); x = 60; y = 0; - screen.Print(x, y++, "srt=%d (seek=%d)", srt, seek_srt); - screen.Print(x, y++, "hut=%d", hut); - screen.Print(x, y++, "hlt=%d", hlt); - screen.Print(x, y++, "nd=%d", nd); + screen.Print(x, y++, "srt=%u (seek=%u)", srt, seek_srt); + screen.Print(x, y++, "hut=%u", hut); + screen.Print(x, y++, "hlt=%u", hlt); + screen.Print(x, y++, "nd=%u", nd); x = 52; y = 5; @@ -503,7 +515,7 @@ FDCDevice::MonitorUpdate(Monitor *, Text screen.Print(x, y++, "Phase: %s", phase_str[(int)phase]); if (cmdbuf.len > 0) { screen.Puts(x, y, "Command:"); - for (int i = 0; i < cmdbuf.len; i++) { + for (uint i = 0; i < cmdbuf.len; i++) { screen.Print(x + 9 + i * 4, y, "$%02x", cmdbuf.buf[i]); } screen.Print(x + 49, y, "(%s)", cmd->name); @@ -524,9 +536,9 @@ FDCDevice::MonitorUpdate(Monitor *, Text f = NULL; } - screen.Print(x, y, "#%d", i); + screen.Print(x, y, "#%u", i); if (f) { - screen.Print(x + 5, y, "%3d %3d", u.pcn, u.ncn); + screen.Print(x + 5, y, "%3d %3u", u.pcn, u.ncn); screen.Print(x + 13, y, TA::OnOff(u.ready), "Ready"); static const char * state_str[] = { "Idle", @@ -559,7 +571,7 @@ void FDCDevice::MonitorReg(TextScreen& screen, int x, int y, uint8 reg, const char * const *names) { - for (int i = 0; i < 8; i++) { + for (uint i = 0; i < 8; i++) { if (names[i][0] == '-') { screen.Puts(x + i * 4, y, TA::Disable, "---"); } else { @@ -719,7 +731,7 @@ FDCDevice::ReadData() return data; default: - VMPANIC("corrupted phase=$%x", (int)phase); + VMPANIC("corrupted phase=$%x", (uint)phase); } } @@ -766,7 +778,7 @@ FDCDevice::WriteCmd(uint32 data) } msr.rqm = false; - putlog(2, "CMD[%d] <- $%02x", cmdbuf.len, data); + putlog(2, "CMD[%u] <- $%02x", cmdbuf.len, data); cmdbuf.buf[cmdbuf.len++] = data; // コマンドの1バイト目でディスパッチ if (cmdbuf.len == 1) { @@ -795,7 +807,7 @@ FDCDevice::WriteCmd(uint32 data) break; default: - VMPANIC("corrupted phase=$%x", (int)phase); + VMPANIC("corrupted phase=$%x", (uint)phase); } } @@ -1069,8 +1081,8 @@ FDCDevice::PushDreg(uint8 data) } // 内部データレジスタから data を取り出す。 -// 空なら -1 を返す。 -int +// 空なら (uint32)-1 を返す。 +uint32 FDCDevice::PopDreg() { uint8 data; @@ -1083,7 +1095,7 @@ FDCDevice::PopDreg() st1.overrun = true; st0.ic = ST0_IC_AT; ChangeInterrupt(); - return -1; + return (uint32)-1; } } @@ -1107,7 +1119,7 @@ FDCDevice::UnitSelect(uint8 us_) // LUNA では XP 側の PSG の I/O と US 信号線の組み合わせで決まる。 us = us_ & 0x03; - putlog(3, "UnitSelect US:%d", us); + putlog(3, "UnitSelect US:%u", us); // いまのところ LUNA のことは忘れる } @@ -1154,7 +1166,7 @@ FDCDevice::CmdSpecify() hut = cmdbuf.specify.srt_hut & 15; hlt = cmdbuf.specify.hlt_nd >> 1; nd = cmdbuf.specify.hlt_nd & 1; - putlog(2, " SRT:%d HUT:%d HLT:%d ND:%d", srt, hut, hlt, nd); + putlog(2, " SRT:%u HUT:%u HLT:%u ND:%u", srt, hut, hlt, nd); // 初期化完了、ポーリング開始 initialized = true; @@ -1202,13 +1214,13 @@ FDCDevice::CmdWriteData() hd = (cmdbuf.data.hd_us & 0x04) >> 2; if (loglevel >= 2) { - putlogn(" MT:%d MF:%d SK:%d HD:%d", (int)mt, (int)mf, (int)sk, hd); - putlogn(" C:%2d H:%d R:%2d N:%d", + putlogn(" MT:%u MF:%u SK:%u HD:%u", (uint)mt, (uint)mf, (uint)sk, hd); + putlogn(" C:%2u H:%u R:%2u N:%u", cmdbuf.data.c, cmdbuf.data.h, cmdbuf.data.r, cmdbuf.data.n); - putlogn(" EOT:%2d GSL:$%02x DTL:$%02x", + putlogn(" EOT:%2u GSL:$%02x DTL:$%02x", cmdbuf.data.eot, cmdbuf.data.gsl, cmdbuf.data.dtl); @@ -1229,13 +1241,13 @@ FDCDevice::CmdReadData() hd = (cmdbuf.data.hd_us & 0x04) >> 2; if (loglevel >= 2) { - putlogn(" MT:%d MF:%d SK:%d HD:%d", (int)mt, (int)mf, (int)sk, hd); - putlogn(" C:%2d H:%d R:%2d N:%d", + putlogn(" MT:%u MF:%u SK:%u HD:%u", (uint)mt, (uint)mf, (uint)sk, hd); + putlogn(" C:%2u H:%u R:%2u N:%u", cmdbuf.data.c, cmdbuf.data.h, cmdbuf.data.r, cmdbuf.data.n); - putlogn(" EOT:%2d GSL:$%02x DTL:$%02x", + putlogn(" EOT:%2u GSL:$%02x DTL:$%02x", cmdbuf.data.eot, cmdbuf.data.gsl, cmdbuf.data.dtl); @@ -1310,7 +1322,7 @@ FDCDevice::XferStartCallback(Event& ev) resbuf.data.h = fdd->PeekByte(2); resbuf.data.r = fdd->PeekByte(3); resbuf.data.n = fdd->PeekByte(4); - putlog(2, "IDAM C:%2d H:%d R:%2d N:%d", + putlog(2, "IDAM C:%2u H:%u R:%2u N:%u", resbuf.data.c, resbuf.data.h, resbuf.data.r, @@ -1395,8 +1407,8 @@ FDCDevice::XferDataCallback(Event& ev) if (xfer_remain > 0) { if (__predict_false(xfer_write)) { - int data = PopDreg(); - if (data >= 0) { + uint32 data = PopDreg(); + if ((int32)data >= 0) { fdd->WriteByte(data); } else { // XXX: こうじゃなくてエラービットだけ立ててセクタ終了時処理かも @@ -1574,7 +1586,7 @@ FDCDevice::CmdReadID() mf = cmdbuf.code & 0x40; hd = (cmdbuf.data.hd_us & 0x04) >> 2; - putlog(2, " MF:%d HD:%d", (int)mf, hd); + putlog(2, " MF:%u HD:%u", (uint)mf, hd); XferStart(false); } @@ -1612,7 +1624,7 @@ FDCDevice::CmdSeek() msr.db[us] = true; unitinfo[us].ncn = cmdbuf.seek.ncn; unitinfo[us].state = UnitState::Seek; - putlog(2, " NCN:%d", unitinfo[us].ncn); + putlog(2, " NCN:%u", unitinfo[us].ncn); CommandPhase(); StartPoll(); }