--- nono/vm/lance.cpp 2026/04/29 17:04:35 1.1.1.4 +++ nono/vm/lance.cpp 2026/04/29 17:04:45 1.1.1.7 @@ -7,7 +7,7 @@ #include "lance.h" #include "bus.h" #include "config.h" -#include "mpu.h" +#include "interrupt.h" #include "mystring.h" #include "mythread.h" #include "zram.h" @@ -20,7 +20,7 @@ LanceDevice::LanceDevice() devname = "Lance"; devaddr = 0xf1000000; - monitor.Init(80, 34); + monitor_size = nnSize(80, 34); rx_event.dev = this; rx_event.func = (DeviceCallback_t)&LanceDevice::Callback; @@ -157,8 +157,8 @@ LanceDevice::Peek(uint32 addr) __unreachable(); } -bool -LanceDevice::MonitorUpdate() +void +LanceDevice::MonitorUpdate(TextScreen& monitor) { /* CSR0: $1111 ERR BABL CERR MISS MERR RINT TINT IDON IADR:$123456 @@ -194,8 +194,8 @@ LADRF:$12345678_12345678 TDRP: // CSR uint16 csr0 = reg.GetCSR0(); monitor.Print(0, y, "CSR0:$%04x", csr0); - MonitorReg(11, y, csr0 >> 8, csr0names); - MonitorReg(11, y + 1, csr0, csr0names + 8); + MonitorReg(monitor, 11, y, csr0 >> 8, csr0names); + MonitorReg(monitor, 11, y + 1, csr0, csr0names + 8); monitor.Print(54, y++, "IADR:$%06x", reg.iadr); monitor.Print(54, y, "CSR3:$%04x", reg.csr3); @@ -380,14 +380,13 @@ LADRF:$12345678_12345678 TDRP: } } } - - return true; } // レジスタをビットごとに表示する。 // data は下位8ビットのみ使用し、上位は無視する。 void -LanceDevice::MonitorReg(int x, int y, uint32 data, const char * const *names) +LanceDevice::MonitorReg(TextScreen& monitor, + int x, int y, uint32 data, const char * const *names) { for (int i = 0; i < 8; i++) { bool b = data & (1 << (7 - i)); @@ -505,16 +504,11 @@ LanceDevice::WriteData(uint32 data) // INEA は %0 も %1 も書き込める // INEA は STOP 中は設定できない if (!reg.IsSTOP()) { - uint16 old_inea = reg.csr0 & AM7990::CSR0_INEA; - uint16 new_inea = data & AM7990::CSR0_INEA; reg.csr0 &= ~AM7990::CSR0_INEA; - reg.csr0 |= new_inea; - - // INEA が 0->1 に変化して、INTR 立ってたら割り込み上げる? - if (old_inea == 0 && new_inea != 0 && reg.IsINTR()) { - Interrupt(); - } + reg.csr0 |= data & AM7990::CSR0_INEA; } + + ChangeInterrupt(); break; } @@ -710,24 +704,22 @@ LanceDevice::ChipStop() RecvEnabled = false; } -// 割り込み要因を CSR0 にセットし、許可されていれば割り込みを上げる。 +// 割り込み要因を CSR0 にセットし、必要なら割り込みを上げる。 void LanceDevice::SetInterrupt(uint32 bit) { reg.csr0 |= bit; - - Interrupt(); + ChangeInterrupt(); } -// 許可されていれば割り込みを上げる。 +// 現状に合わせて割り込み信号線の状態を変える。 void -LanceDevice::Interrupt() +LanceDevice::ChangeInterrupt() { - if ((reg.csr0 & AM7990::CSR0_INEA)) { - putlog(2, "割り込み"); - gMPU->Interrupt(this, 3); + if (reg.IsINTR() && (reg.csr0 & AM7990::CSR0_INEA)) { + gInterrupt->AssertINT(this); } else { - putlog(2, "割り込みはマスクされている"); + gInterrupt->NegateINT(this); } } @@ -737,7 +729,7 @@ lance_run(void *dummy) { PTHREAD_SETNAME("Lance worker"); - dynamic_cast(gEthernet.get())->ThreadRun(); + gEthernet->ThreadRun(); return NULL; } @@ -966,7 +958,7 @@ LanceDevice::TXNext() } // パケット受信。 -// これは mtx 取得状態で Nerdriver スレッドから呼ばれるので、 +// これは mtx 取得状態で Netdriver スレッドから呼ばれるので、 // パケットを手元にコピーして VM スレッドに通知を出すだけ。 bool LanceDevice::RecvPacket(qvector& buf) @@ -1172,12 +1164,12 @@ LanceDevice::RXMiss() // イベントハンドラ void -LanceDevice::Callback(int arg) +LanceDevice::Callback(Event& ev) { std::unique_lock lock(mtx); // ワーカスレッドにフェーズ遷移を伝えるだけ - request |= arg; + request |= ev.code; cv.notify_one(); }