--- nono/vm/fdc.cpp 2026/04/29 17:05:18 1.1.1.11 +++ 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; } @@ -169,62 +172,80 @@ FDCDevice::Init() void FDCDevice::ResetHard(bool poweron) { - // uPD765 マニュアルによると、リセット信号によるリセットでは - // SRT, HUT, HLT は影響を受けない。 - - // シリンダ位置 pcn はとりあえずわからないので放置。 - if (poweron) { // READY ポーリングはリセットの影響を受けないはず initialized = false; scheduler->StopEvent(motor_event); } + // uPD765 マニュアルによると、リセット信号によるリセットでは + // SRT, HUT, HLT は影響を受けない。 + + // シリンダ位置 pcn はとりあえずわからないので放置。 + + // US0,US1 を low (FDD0) に。 + us = 0; + // 割り込み (と DRQ) をネゲート。 + msr.ndm = false; + st0.ic = ST0_IC_IC; + st0.se = false; + st0.ec = false; + st0.nr = false; + st0.hd = false; + st0.us = 0; + ChangeInterrupt(); + scheduler->StopEvent(phase_event); scheduler->StopEvent(poll_event); CommandPhase(); } -uint64 -FDCDevice::Read(uint32 offset) +busdata +FDCDevice::ReadPort(uint32 offset) { - mpu->AddCycle(19); // InsideOut p.135 + busdata data; switch (offset) { case 0: - { if (dack) { // DACK が立っているときは A0 によらずデータレジスタをアクセス - return ReadData(); + data = ReadData(); + } else { + data = GetMSR(); + putlog(4, "STAT -> $%02x", data.Data()); } - - uint8 stat = GetMSR(); - putlog(4, "STAT -> $%02x", stat); - return stat; - } + break; case 1: - return ReadData(); + data = ReadData(); + break; case 2: - return ReadDriveStatus(); + data = ReadDriveStatus(); + break; case 3: - return 0xff; + data = 0xff; + 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; } -uint64 -FDCDevice::Write(uint32 offset, uint32 data) +busdata +FDCDevice::WritePort(uint32 offset, uint32 data) { - mpu->AddCycle(19); // InsideOut p.135 - switch (offset) { case 0: if (dack) { // DACK が立っているときは A0 によらずデータレジスタをアクセス WriteDataReg(data); - return 0; + break; } // ここはフェーズに関わらず 0x34, 0x35, 0x36 のコマンドだけを @@ -245,11 +266,11 @@ FDCDevice::Write(uint32 offset, uint32 d data); break; } - return 0; + break; case 1: WriteCmd(data); - return 0; + break; case 2: { @@ -267,7 +288,7 @@ FDCDevice::Write(uint32 offset, uint32 d bit <<= 1; } drivectrl = data; - return 0; + break; } case 3: @@ -277,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); @@ -319,15 +340,22 @@ FDCDevice::Write(uint32 offset, uint32 d f->SetDriveSelect(accdrive, is2DD); } } - return 0; + break; } default: - VMPANIC("corrupted offset=%d", offset); + VMPANIC("corrupted offset=%u", offset); } + + // InsideOut p.135 + const busdata wait = busdata::Wait(19 * 40_nsec); + + busdata r = wait; + r |= BusData::Size1; + return r; } -uint64 -FDCDevice::Peek(uint32 offset) +busdata +FDCDevice::PeekPort(uint32 offset) { switch (offset) { case 0: @@ -368,6 +396,12 @@ FDCDevice::Peek(uint32 offset) } } +bool +FDCDevice::PokePort(uint32 offset, uint32 data) +{ + return false; +} + // モニタ更新 void FDCDevice::MonitorUpdate(Monitor *, TextScreen& screen) @@ -453,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; @@ -481,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); @@ -502,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", @@ -537,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 { @@ -697,7 +731,7 @@ FDCDevice::ReadData() return data; default: - VMPANIC("corrupted phase=$%x", (int)phase); + VMPANIC("corrupted phase=$%x", (uint)phase); } } @@ -744,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) { @@ -773,7 +807,7 @@ FDCDevice::WriteCmd(uint32 data) break; default: - VMPANIC("corrupted phase=$%x", (int)phase); + VMPANIC("corrupted phase=$%x", (uint)phase); } } @@ -1047,8 +1081,8 @@ FDCDevice::PushDreg(uint8 data) } // 内部データレジスタから data を取り出す。 -// 空なら -1 を返す。 -int +// 空なら (uint32)-1 を返す。 +uint32 FDCDevice::PopDreg() { uint8 data; @@ -1061,7 +1095,7 @@ FDCDevice::PopDreg() st1.overrun = true; st0.ic = ST0_IC_AT; ChangeInterrupt(); - return -1; + return (uint32)-1; } } @@ -1085,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 のことは忘れる } @@ -1132,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; @@ -1180,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); @@ -1207,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); @@ -1288,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, @@ -1373,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: こうじゃなくてエラービットだけ立ててセクタ終了時処理かも @@ -1552,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); } @@ -1590,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(); }