--- nono/vm/mfp.cpp 2026/04/29 17:04:45 1.1.1.7 +++ nono/vm/mfp.cpp 2026/04/29 17:05:17 1.1.1.14 @@ -4,35 +4,36 @@ // Licensed under nono-license.txt // +// +// MFP (MC68901) +// + #include "mfp.h" #include "interrupt.h" #include "keyboard.h" -#include "mpu680x0.h" -#include "mystring.h" - -std::unique_ptr gMFP; +#include "mpu.h" +#include "scheduler.h" +#include "x68kkbd.h" // コンストラクタ MFPDevice::MFPDevice() + : inherited(OBJ_MFP) { - logname = "mfp"; - devname = "MFP"; - devaddr = baseaddr; - devlen = 0x2000; - monitor_size = nnSize(77, 26); - - for (int ch = 0; ch < countof(event); ch++) { + for (int ch = 0; ch < event.size(); ch++) { event[ch].dev = this; - event[ch].func = (DeviceCallback_t)&MFPDevice::TimerCallback; + event[ch].func = ToEventCallback(&MFPDevice::TimerCallback); event[ch].code = ch; - event[ch].SetName(string_format("MFP Timer-%c", ch + 'A')); + event[ch].Regist(string_format("MFP Timer-%c", ch + 'A')); } // キーボード周りは x68kkbd.cpp のコメント参照 - key_event.dev = this; - key_event.func = (DeviceCallback_t)&MFPDevice::KeyCallback; + key_event.func = ToEventCallback(&MFPDevice::KeyCallback); key_event.time = 3750_usec; - key_event.SetName("MFP USART"); + key_event.Regist("MFP USART"); + + monitor.func = ToMonitorCallback(&MFPDevice::MonitorUpdate); + monitor.SetSize(77, 26); + monitor.Regist(ID_MONITOR_MFP); } // デストラクタ @@ -40,23 +41,23 @@ MFPDevice::~MFPDevice() { } -// 本体リセットスイッチによるリセット -void -MFPDevice::ResetHard() +// 初期化 +bool +MFPDevice::Init() { - Reset(); -} + if (inherited::Init() == false) { + return false; + } -// MPU の RESET 命令によるリセット -void -MFPDevice::ResetSoft() -{ - Reset(); + interrupt = GetInterruptDevice(); + keyboard = dynamic_cast(GetKeyboard()); + + return true; } -// リセット(共通) +// リセット void -MFPDevice::Reset() +MFPDevice::ResetHard(bool poweron) { // All internal registers are cleared expect the TxDR, UDR, and TSR. mfp.aer = 0; @@ -76,10 +77,10 @@ MFPDevice::Reset() mfp.tsr = MFP::TSR_BE; // All timers are stopped. - for (int ch = 0; ch < countof(event); ch++) { - event[ch].Stop(); + for (auto& ev : event) { + scheduler->StopEvent(ev); } - key_event.Stop(); + scheduler->StopEvent(key_event); // USART RX and TX are disabled. // SO line is placed in HighZ. @@ -92,18 +93,18 @@ MFPDevice::Reset() mfp.vr_vec = 0; mfp.vr_s = 0; - // 信号線 - rr = false; + // CIRQ | FMIRQ | EXPON | ALARM にしておく + mfp.gpip = 0x6b; } uint64 -MFPDevice::Read(uint32 addr) +MFPDevice::Read(uint32 offset) { uint8 data; - gMPU->AddCycle(24); // InsideOut p.135 + mpu->AddCycle(24); // InsideOut p.135 - switch (addr) { + switch (offset) { case MFP::GPIP: data = mfp.gpip; break; @@ -174,7 +175,9 @@ MFPDevice::Read(uint32 addr) data = mfp.tsr; break; case MFP::UDR: + // UDR からデータを読み出したら Buffer Full をクリア data = mfp.udr; + ClearBF(); break; default: data = 0xff; @@ -184,22 +187,22 @@ MFPDevice::Read(uint32 addr) } uint64 -MFPDevice::Write(uint32 addr, uint32 data) +MFPDevice::Write(uint32 offset, uint32 data) { - gMPU->AddCycle(24); // InsideOut p.135 + mpu->AddCycle(24); // InsideOut p.135 - switch (addr) { + switch (offset) { case MFP::GPIP: - putlog(0, "GPIP <- $%02x 未実装書き込み", data); + putlog(0, "Write GPIP <- $%02x (NOT IMPLEMENTED)", data); mfp.gpip = data; break; case MFP::AER: - putlog(0, "AER <- $%02x 未実装書き込み", data); + putlog(2, "AER <- $%02x", data); mfp.aer = data; break; case MFP::DDR: if (data != 0) { - putlog(0, "DDR <- $%02x 未実装書き込み", data); + putlog(0, "Write DDR <- $%02x (NOT IMPLEMENTED)", data); } mfp.ddr = data; break; @@ -274,7 +277,7 @@ MFPDevice::Write(uint32 addr, uint32 dat SetTDR(3, data); break; case MFP::SCR: - putlog(0, "SCR <- $%02x 未実装書き込み", data); + putlog(0, "SCR <- $%02x (NOT IMPLEMENTED)", data); mfp.scr = data; break; case MFP::UCR: @@ -286,7 +289,10 @@ MFPDevice::Write(uint32 addr, uint32 dat SetRSR(data); break; case MFP::TSR: - putlog(0, "TSR <- $%02x 未実装書き込み", data); + if ((data & 0x0e)) { + // SO 端子関係の B, H, L ビットは未実装 + putlog(0, "TSR <- $%02x (B,H,L bit NOT IMPLEMENTED)", data); + } mfp.tsr = (mfp.tsr & 0xf0) | (data & 0x0f); break; case MFP::UDR: @@ -305,11 +311,11 @@ MFPDevice::Write(uint32 addr, uint32 dat } uint64 -MFPDevice::Peek(uint32 addr) +MFPDevice::Peek(uint32 offset) { uint8 data; - switch (addr) { + switch (offset) { case MFP::GPIP: data = mfp.gpip; break; @@ -389,18 +395,18 @@ MFPDevice::Peek(uint32 addr) } void -MFPDevice::MonitorUpdate(TextScreen& monitor) +MFPDevice::MonitorUpdate(Monitor *, TextScreen& screen) { int x; int y; - monitor.Clear(); + screen.Clear(); // 0 1 2 3 4 5 6 // 01234567890123456789012345678901234567890123456789012345678901234567890 // $e88001(GPIP):$00 $e88007(IERA):$00 $e88019(TACR):$00 $e88027 - // IER IMR IPR ISR Mode TDR Cnt - // An:MPSC TxEmpty Enable Mask Pend Serv Timer-A Delay(50us) 255 255 + // IER IMR IPR ISR Mode TDR Cnt + // An:MPSC TxEmpty Enable Mask Pend Serv Timer-A Delay(50us) 255 255 #define A(x) (baseaddr + (x * 2) + 1) @@ -408,53 +414,53 @@ MFPDevice::MonitorUpdate(TextScreen& mon // 1列目(GPIP 関連と VR) x = 0; y = 0; - monitor.Print(x, y++, "$%06x(GPIP):$%02x", A(MFP::GPIP), mfp.gpip); - monitor.Print(x, y++, "$%06x(AER): $%02x", A(MFP::AER), mfp.aer); - monitor.Print(x, y++, "$%06x(DDR): $%02x", A(MFP::DDR), mfp.ddr); - monitor.Print(x, y++, "$%06x(VR): $%02x", A(MFP::VR), mfp.GetVR()); + screen.Print(x, y++, "$%06x(GPIP):$%02x", A(MFP::GPIP), mfp.gpip); + screen.Print(x, y++, "$%06x(AER): $%02x", A(MFP::AER), mfp.aer); + screen.Print(x, y++, "$%06x(DDR): $%02x", A(MFP::DDR), mfp.ddr); + screen.Print(x, y++, "$%06x(VR): $%02x", A(MFP::VR), mfp.GetVR()); // 2列目(割り込み関連) x = 20; y = 0; - monitor.Print(x, y++, "$%06x(IERA):$%02x", A(MFP::IERA), mfp.ier.a); - monitor.Print(x, y++, "$%06x(IERB):$%02x", A(MFP::IERB), mfp.ier.b); - monitor.Print(x, y++, "$%06x(IPRA):$%02x", A(MFP::IPRA), mfp.ipr.a); - monitor.Print(x, y++, "$%06x(IPRB):$%02x", A(MFP::IPRB), mfp.ipr.b); - monitor.Print(x, y++, "$%06x(ISRA):$%02x", A(MFP::ISRA), mfp.isr.a); - monitor.Print(x, y++, "$%06x(ISRB):$%02x", A(MFP::ISRB), mfp.isr.b); - monitor.Print(x, y++, "$%06x(IMRA):$%02x", A(MFP::IMRA), mfp.imr.a); - monitor.Print(x, y++, "$%06x(IMRB):$%02x", A(MFP::IMRB), mfp.imr.b); + screen.Print(x, y++, "$%06x(IERA):$%02x", A(MFP::IERA), mfp.ier.a); + screen.Print(x, y++, "$%06x(IERB):$%02x", A(MFP::IERB), mfp.ier.b); + screen.Print(x, y++, "$%06x(IPRA):$%02x", A(MFP::IPRA), mfp.ipr.a); + screen.Print(x, y++, "$%06x(IPRB):$%02x", A(MFP::IPRB), mfp.ipr.b); + screen.Print(x, y++, "$%06x(ISRA):$%02x", A(MFP::ISRA), mfp.isr.a); + screen.Print(x, y++, "$%06x(ISRB):$%02x", A(MFP::ISRB), mfp.isr.b); + screen.Print(x, y++, "$%06x(IMRA):$%02x", A(MFP::IMRA), mfp.imr.a); + screen.Print(x, y++, "$%06x(IMRB):$%02x", A(MFP::IMRB), mfp.imr.b); // 3列目(タイマー関連) x = 40; y = 0; - monitor.Print(x, y++, "$%06x(TACR): $%02x", A(MFP::TACR), mfp.tcr[0]); - monitor.Print(x, y++, "$%06x(TBCR): $%02x", A(MFP::TBCR), mfp.tcr[1]); - monitor.Print(x, y++, "$%06x(TCDCR):$%02x", A(MFP::TCDCR), + screen.Print(x, y++, "$%06x(TACR): $%02x", A(MFP::TACR), mfp.tcr[0]); + screen.Print(x, y++, "$%06x(TBCR): $%02x", A(MFP::TBCR), mfp.tcr[1]); + screen.Print(x, y++, "$%06x(TCDCR):$%02x", A(MFP::TCDCR), (mfp.tcr[2] << 4) | mfp.tcr[3]); - monitor.Print(x, y++, "$%06x(TADR): $%02x", A(MFP::TADR), GetTDR(0)); - monitor.Print(x, y++, "$%06x(TBDR): $%02x", A(MFP::TBDR), GetTDR(1)); - monitor.Print(x, y++, "$%06x(TCDR): $%02x", A(MFP::TCDR), GetTDR(2)); - monitor.Print(x, y++, "$%06x(TDDR): $%02x", A(MFP::TDDR), GetTDR(3)); + screen.Print(x, y++, "$%06x(TADR): $%02x", A(MFP::TADR), GetTDR(0)); + screen.Print(x, y++, "$%06x(TBDR): $%02x", A(MFP::TBDR), GetTDR(1)); + screen.Print(x, y++, "$%06x(TCDR): $%02x", A(MFP::TCDR), GetTDR(2)); + screen.Print(x, y++, "$%06x(TDDR): $%02x", A(MFP::TDDR), GetTDR(3)); // 4列目(USART 関連) x = 61; y = 0; - monitor.Print(x, y++, "$%06x(SCR):$%02x", A(MFP::SCR), mfp.scr); - monitor.Print(x, y++, "$%06x(UCR):$%02x", A(MFP::UCR), mfp.ucr); - monitor.Print(x, y++, "$%06x(RSR):$%02x", A(MFP::RSR), mfp.rsr); - monitor.Print(x, y++, "$%06x(TSR):$%02x", A(MFP::TSR), mfp.tsr); - monitor.Print(x, y, "$%06x(UDR):", A(MFP::UDR)); + screen.Print(x, y++, "$%06x(SCR):$%02x", A(MFP::SCR), mfp.scr); + screen.Print(x, y++, "$%06x(UCR):$%02x", A(MFP::UCR), mfp.ucr); + screen.Print(x, y++, "$%06x(RSR):$%02x", A(MFP::RSR), mfp.rsr); + screen.Print(x, y++, "$%06x(TSR):$%02x", A(MFP::TSR), mfp.tsr); + screen.Print(x, y, "$%06x(UDR):", A(MFP::UDR)); if ((int16)mfp.udr >= 0) { - monitor.Print(x + 13, y, "$%02x", mfp.udr); + screen.Print(x + 13, y, "$%02x", mfp.udr); } else { - monitor.Print(x + 13, y, "---"); + screen.Print(x + 13, y, "---"); } // 割り込み関連 y = 9; - monitor.Print(0, y++, " %-6s %-4s %-4s %-4s", + screen.Print(0, y++, " %-6s %-4s %-4s %-4s", "IER", "IMR", "IPR", "ISR"); for (int i = 15; i >= 0; i--, y++) { uint16 mask = (1 << i); - monitor.Print(0, y, "%c%d:%-12s %-6s %-4s %-4s %-4s", + screen.Print(0, y, "%c%d:%-12s %-6s %-4s %-4s %-4s", i >= 8 ? 'A' : 'B', (i % 8), intrname[i], @@ -465,33 +471,33 @@ MFPDevice::MonitorUpdate(TextScreen& mon } // タイマー関連 - x = 39; + x = 40; y = 9; - monitor.Print(x, y++, " Mode TDR Ini"); + screen.Print(x, y++, " Mode TDR Ini"); for (int ch = 0; ch < 4; ch++) { - monitor.Print(x, y, "Timer-%c", ch + 'A'); + screen.Print(x, y, "Timer-%c", ch + 'A'); if (mfp.tcr[ch] == 0) { - monitor.Print(x + 8, y, "Stopped"); + screen.Print(x + 8, y, "Stopped"); } else if (mfp.tcr[ch] == 8) { - monitor.Print(x + 8, y, "Event"); + screen.Print(x + 8, y, "Event"); } else if (mfp.tcr[ch] > 8) { - monitor.Print(x + 8, y, "Pulse(%s)", prescale_str[mfp.tcr[ch] - 8]); + screen.Print(x + 8, y, "Pulse(%s)", prescale_str[mfp.tcr[ch] - 8]); } else { - monitor.Print(x + 8, y, "Delay(%s)", prescale_str[mfp.tcr[ch]]); + screen.Print(x + 8, y, "Delay(%s)", prescale_str[mfp.tcr[ch]]); } - monitor.Print(x + 19, y, "%3d", GetTDR(ch)); - monitor.Print(x + 23, y, "%3d", mfp.initial_tdr[ch]); + screen.Print(x + 20, y, "%3d", GetTDR(ch)); + screen.Print(x + 24, y, "%3d", mfp.initial_tdr[ch]); y++; } // GPIP 関連 - x = 39; + x = 40; y = 9 + 8; - monitor.Puts(x, y++, " GPIP AER DDR"); + screen.Puts(x, y++, " GPIP AER DDR"); for (int i = 7; i >= 0; i--, y++) { uint mask = (1 << i); - monitor.Print(x, y, "b%d %-6s %d %d %s", i, gpipname[i], + screen.Print(x, y, "b%d %-6s %d %d %s", i, gpipname[i], (mfp.gpip & mask) ? 1 : 0, (mfp.aer & mask) ? 1 : 0, (mfp.ddr & mask) ? "OUT" : "IN"); @@ -580,18 +586,18 @@ MFPDevice::SetTCR(int ch, uint32 data) return; } else if (prev < 8) { // タイマー停止 - putlog(1, "Timer-%c 停止", ch + 'A'); + putlog(1, "Timer-%c Stop", ch + 'A'); // ここで TDR を確定させる。 // タイマー動作中の TDR の参照はイベント終了時刻から現在値を逆算 // していたが、イベントを停止すると求められなくなるので、イベント // 停止前に求めておく。 uint64 period = prescale_ns[prev]; - uint64 now = gMPU->GetVirtTime(); + uint64 now = scheduler->GetVirtTime(); mfp.tdr[ch] = ((event[ch].vtime - now) + period - 1) / period; // でイベント停止 - event[ch].Stop(); + scheduler->StopEvent(event[ch]); return; } else if (prev == 8) { // イベントカウントモードから停止しても何も起きないはず @@ -607,12 +613,13 @@ MFPDevice::SetTCR(int ch, uint32 data) mfp.tdr[ch] = mfp.initial_tdr[ch]; // タイマースタート uint64 period = prescale_ns[mfp.tcr[ch]]; - event[ch].time = period * (mfp.tdr[ch] ?: 256); - event[ch].Start(); + uint count = mfp.tdr[ch] ?: 256; + event[ch].time = period * count; + scheduler->RestartEvent(event[ch]); - putlog(1, "Timer-%c ディレイモード開始(%u x %u.%uusec)", + putlog(1, "Timer-%c Start Delay mode(%u x %u.%uusec)", ch + 'A', - mfp.initial_tdr[ch], + count, (uint)period / 1000, (uint)(period / 100) % 10); return; @@ -622,11 +629,11 @@ MFPDevice::SetTCR(int ch, uint32 data) // TDR をロードする mfp.initial_tdr[ch] = mfp.tdr[ch]; - putlog(1, "Timer-%c イベントカウントモード", ch + 'A'); + putlog(1, "Timer-%c Event count mode", ch + 'A'); return; } else { - putlog(0, "T%cCR パルス幅測定モード $%02x 未実装", + putlog(0, "T%cCR Pulse-Width Measurement Mode $%02x (NOT IMPLEMENTED)", ch + 'A', data); return; } @@ -648,7 +655,7 @@ MFPDevice::GetTDR(int ch) const // プリスケーラと終了時刻から算出。 uint64 period = prescale_ns[tcr]; - uint64 now = gMPU->GetVirtTime(); + uint64 now = scheduler->GetVirtTime(); return ((event[ch].vtime - now) + period - 1) / period; } else { @@ -670,13 +677,13 @@ MFPDevice::SetTDR(int ch, uint32 data) mfp.initial_tdr[ch] = data; } else if (tcr < 8) { - // ディレイモード動作中の書き込み + // ディレイモード動作中の書き込み。 // メインカウンタは影響を受けず、次回値を更新するだけ。 mfp.initial_tdr[ch] = data; } else { // イベントモード、パルス幅測定モードは未対応 - putlog(0, "T%cDR サポートしてないモード中の書き込み $%02x", + putlog(0, "Write T%cDR $%02x during unsupported mode (NOT IMPLEMENTED)", ch + 'A', data); } } @@ -699,12 +706,15 @@ MFPDevice::TimerCallback(Event& ev) // period が1メインパルス期間 // time が1タイムアウトパルス期間 uint64 period = prescale_ns[mfp.tcr[ch]]; - uint64 time = period * (mfp.tdr[ch] ?: 256); - // 次のタイムアウトパルスは、今回のタイムアウト時刻から数える - // (現在時刻はそれを通り過ぎた任意の時刻なので) - uint64 now = gMPU->GetVirtTime(); - ev.time = ev.vtime + time - now; - ev.Start(); + ev.time = period * (mfp.tdr[ch] ?: 256); + scheduler->RestartEvent(ev); +} + +// HSync 入力 +void +MFPDevice::SetHSync(bool hsync) +{ + SetGPIP(MFP::GPIP_HSYNC, hsync); } // VDisp 入力 @@ -731,6 +741,20 @@ MFPDevice::SetVDisp(bool vdisp) SetGPIP(MFP::GPIP_VDISP, vdisp); } +// 電源ボタン状態入力 (PowerDevice から呼ばれる) +void +MFPDevice::SetPowSW(bool powsw) +{ + SetGPIP(MFP::GPIP_POWSW, powsw); +} + +// ALARM 信号入力 (RTC の ALARM_OUT 出力端子) +void +MFPDevice::SetAlarmOut(bool alarm) +{ + SetGPIP(MFP::GPIP_ALARM, alarm); +} + // GPIP への入力。 // num はビット番号(0..7)。 void @@ -750,7 +774,17 @@ MFPDevice::SetGPIP(int num, bool val) // 1 1 0 0 // 1 1 1 0 if ((old != val) && (aer == val)) { - // XXX ここで割り込みを上げる + // ここで割り込みを上げる + // XXX GPIP ビット番号と INTR の対応どうなってんの + int intr; + if (num < 4) { + intr = num; + } else if (num < 6) { + intr = num + 2; + } else { + intr = num - MFP::GPIP_CIRQ + MFP::INTR_CRTC_IRQ; + } + SetInterrupt(intr); } if (val) { @@ -767,13 +801,13 @@ MFPDevice::SetUCR(uint32 data) mfp.ucr = data; if ((mfp.ucr & MFP::UCR_CLK) == 0) { - putlog(0, "UCR CLK=0 未実装"); + putlog(0, "UCR CLK=0 (NOT IMPLEMENTED)"); } if (((mfp.ucr & MFP::UCR_WL) >> 5) != 0) { - putlog(0, "UCR WL=%d 未実装", (mfp.ucr >> 5) & 3); + putlog(0, "UCR WL=%d (NOT IMPLEMENTED)", (mfp.ucr >> 5) & 3); } if (((mfp.ucr & MFP::UCR_ST) >> 3) != 1) { - putlog(0, "UCR ST=%d 未実装", (mfp.ucr >> 3) & 3); + putlog(0, "UCR ST=%d (NOT IMPLEMENTED)", (mfp.ucr >> 3) & 3); } } @@ -787,60 +821,111 @@ MFPDevice::SetRSR(uint32 data) if ((old & MFP::RSR_RE) == 0 && (mfp.rsr & MFP::RSR_RE)) { // RE 0 -> 1 - rr = true; } if ((old & MFP::RSR_RE) && (mfp.rsr & MFP::RSR_RE) == 0) { // RE 1 -> 0 - rr = false; - mfp.rsr &= 0x0f; // 上位4ビットのステータスを %0 に + // 上位4ビットのステータスを %0 に + mfp.rsr &= ~(MFP::RSR_OE | MFP::RSR_PE | MFP::RSR_FE); + ClearBF(); } } +// RSR::BF (Buffer Full) をセットする +void +MFPDevice::SetBF() +{ + mfp.rsr |= MFP::RSR_BF; +} + +// RSR::BF (Buffer Full) をクリアする +void +MFPDevice::ClearBF() +{ + mfp.rsr &= ~MFP::RSR_BF; + + // バッファが空いたのでキーボードに次の転送を催促。 + // 実際のハードウェアでは、キーボードが本体 MFP が Ready になるのを待って + // いるが、それに相当。 + // システムポートの KEYCTRL はキーボード側で処理している。 + keyboard->Ready(); +} + // UDR への書き込み void MFPDevice::SetUDR(uint32 data) { if ((mfp.tsr & MFP::TSR_TE)) { - gKeyboard->Command(data); + keyboard->Command(data); } } -// システムポート#4 の KEY CTRL の状態を受け取る。 -void -MFPDevice::SetKeyCtrl(bool val) +// __ +// RR 線の状態を返す。アサートなら true。 +bool +MFPDevice::IsRR() const { - key_ctrl = val; - putlog(1, "KEYCTRL = %d", key_ctrl); + // __ + // 実際の RR 信号線は、BF が立っていて、PE | FE がクリアされている場合に + // アサートされる。ただしエミュレータでは Parity Error も Frame Error も + // 起きないので、この2ビットは無視する。 + return ((mfp.rsr & MFP::RSR_BF) != 0); } -// RR (Receiver Ready) 線の状態を返す。true なら Ready。 -// これはシステムポート#4 の KEY CTRL の状態も加味したもの。 +// キーボードからの受信が可能なら true を返す。 bool -MFPDevice::IsRR() const +MFPDevice::RxIsReady() const { - return rr && key_ctrl; + // __ + // RR は本来 MFP から CPU/DMAC など上位に対しての Ready で、 + // UDR にデータが用意できたので引き取ってほしいの意。 + // X680x0 ではこれを CPU/DMAC (上位) 向けではなく、下位のキーボードからの + // フロー制御に流用しており、 + // 上位への(本来の)「UDR にデータが用意できた」(IsRR() = true) は、 + // キーボードに対しては「UDR にデータがあるので送信禁止」、 + // 上位への(本来の)「UDR にデータが用意できていない」(IsRR() = false) は、 + // キーボードに対しては「UDR は空いているので送信してよい」と + // ここで意味が論理反転することに注意。 + // + // また、システムポートの KEYCTRL は X680x0Keyboard 側で処理しているので + // こちらでは不要。 + // + // UDR が空いていてキーボードからデータが送られてきている間は RR は Ready + // だが、そもそもキーボードは送出作業中で、新たな送信はできないはずなので + // この場合、つまり key_event の動作中も false (送信不可) にする。 + + return !IsRR() && !key_event.IsRunning(); } // キーボードからデータを受信 void MFPDevice::Rx(uint32 data) { - // Ready を下げる - rr = false; + // ここは受信したビットをシフトレジスタへ入れ始めたところに相当する + // ので、まだ Buffer Full は立てない。 key_event.code = data; - key_event.Start(); + scheduler->RestartEvent(key_event); } // キーボードからのデータが受信し終わった頃に呼ばれるイベント。 void MFPDevice::KeyCallback(Event& ev) { - // Ready を元に戻す - rr = true; - + // UDR にデータを置いて Buffer Full をセット mfp.udr = ev.code; - mfp.rsr |= MFP::RSR_BF; + SetBF(); + + // Manual 7-5 7.2.1 Receiver Interrupt Channels より + // | 割り込みは1文字受信ごとに1回しか発生しませんが、2つの専用割り込み + // | チャネルにより、正常な受信状態と異常な受信状態に別々のベクター番号を + // | 割り当てることができます。受信したワードにエラーがあり、エラー割り込み + // | チャネルが有効な場合は、エラーチャネルのみに割り込みが発生します。 + // | しかし、エラーチャネルが無効の場合、エラー状態の割り込みは、 + // | バッファフル状態の割り込みと一緒にバッファフル割り込みチャネルに + // | 生成されます。どのエラー条件で割り込みが発生したかを判断するためには、 + // | 常にRSRを読み出す必要があります。 + // XXX: まだエラー状態は実装されていない、なおエラーは起きないので + // メモだけのままかも知れない。 SetInterrupt(MFP::INTR_RXFULL); } @@ -874,7 +959,7 @@ MFPDevice::ChangeInterrupt() // ペンディングの割り込みがあればアサートされる、 // IPR をクリアするか IMR をクリアすると /IRQ はネゲートされる。 bool irq = ((mfp.ipr.w & mfp.imr.w) != 0); - gInterrupt->ChangeINT(this, irq); + interrupt->ChangeINT(this, irq); } // 割り込みアクノリッジ