--- nono/vm/dmac.cpp 2026/04/29 17:05:14 1.1.1.11 +++ nono/vm/dmac.cpp 2026/04/29 17:05:18 1.1.1.12 @@ -10,9 +10,9 @@ #include "dmac.h" #include "adpcm.h" -#include "bus.h" #include "fdc.h" #include "interrupt.h" +#include "mainbus.h" #include "mpu.h" #include "scheduler.h" @@ -21,19 +21,13 @@ #define CallAfter(func_, time_) do { \ event.func = ToEventCallback(&DMACDevice::func_); \ event.time = time_ * 80_nsec; \ - gScheduler->StartEvent(event); \ + scheduler->StartEvent(event); \ } while (0) -// グローバル参照用 -DMACDevice *gDMAC; - // コンストラクタ DMACDevice::DMACDevice() - : inherited("DMAC") + : inherited(OBJ_DMAC) { - devaddr = baseaddr; - devlen = 0x2000; - for (int i = 0; i < channel.size(); i++) { channel[i].ch = i; } @@ -64,7 +58,22 @@ DMACDevice::DMACDevice() // デストラクタ DMACDevice::~DMACDevice() { - gDMAC = NULL; +} + +// 初期化 +bool +DMACDevice::Init() +{ + if (inherited::Init() == false) { + return false; + } + + adpcm = GetADPCMDevice(); + fdc = GetFDCDevice(); + interrupt = GetInterruptDevice(); + mainbus = GetMainbusDevice(); + + return true; } // リセット @@ -97,7 +106,7 @@ DMACDevice::ResetHard(bool poweron) // イベントを停止 event.SetName("DMAC"); - gScheduler->StopEvent(event); + scheduler->StopEvent(event); } uint64 @@ -105,7 +114,7 @@ DMACDevice::Read8(uint32 addr) { uint8 data; - gMPU->AddCycle(37); // InsideOut p.135 + mpu->AddCycle(37); // InsideOut p.135 uint32 offset = addr & 0xff; int ch = offset / 0x40; @@ -265,7 +274,7 @@ DMACDevice::Read16(uint32 addr) { uint16 data; - gMPU->AddCycle(37); // InsideOut p.135 + mpu->AddCycle(37); // InsideOut p.135 uint32 offset = addr & 0xff; int ch = offset / 0x40; @@ -396,7 +405,7 @@ DMACDevice::Read16(uint32 addr) uint64 DMACDevice::Write8(uint32 addr, uint32 data) { - gMPU->AddCycle(31); // InsideOut p.135 + mpu->AddCycle(31); // InsideOut p.135 uint32 offset = addr & 0xff; int ch = offset / 0x40; @@ -568,7 +577,7 @@ DMACDevice::Write8(uint32 addr, uint32 d uint64 DMACDevice::Write16(uint32 addr, uint32 data) { - gMPU->AddCycle(31); // InsideOut p.135 + mpu->AddCycle(31); // InsideOut p.135 uint32 offset = addr & 0xff; int ch = offset / 0x40; @@ -1281,7 +1290,8 @@ DMACDevice::StartTransfer(DMACChan* chan chan->data.Clear(); // 転送モード - switch (chan->GetREQG()) { + uint reqg = chan->GetREQG(); + switch (reqg) { case DMAC::REQG_AUTO_LIM: VMPANIC("REQG_AUTO_LIM 未実装"); break; @@ -1300,7 +1310,7 @@ DMACDevice::StartTransfer(DMACChan* chan break; default: - __unreachable(); + VMPANIC("corrupted reqg=%d", reqg); } // 転送開始ログ。全パラメータは無理なので概要だけ表示。 @@ -1492,39 +1502,39 @@ DMACDevice::TransferCallback(Event& ev) data = 0; switch (op) { case RD_M8: - data = vm_phys_read_8(chan->mar); + data = mainbus->Read8(chan->mar); break; case RD_M16: - data = vm_phys_read_16(chan->mar); + data = mainbus->Read16(chan->mar); break; case RD_D8: - data = vm_phys_read_8(chan->dar); + data = mainbus->Read8(chan->dar); break; case RD_D16: - data = vm_phys_read_16(chan->dar); + data = mainbus->Read16(chan->dar); break; case WR_M8: data = chan->data.Dequeue(); - data = vm_phys_write_8(chan->mar, data); + data = mainbus->Write8(chan->mar, data); break; case WR_M16: data = chan->data.Dequeue() << 8; data |= chan->data.Dequeue(); - data = vm_phys_write_16(chan->mar, data); + data = mainbus->Write16(chan->mar, data); break; case WR_D8: data = chan->data.Dequeue(); - data = vm_phys_write_8(chan->dar, data); + data = mainbus->Write8(chan->dar, data); break; case WR_D16: data = chan->data.Dequeue() << 8; data |= chan->data.Dequeue(); - data = vm_phys_write_16(chan->dar, data); + data = mainbus->Write16(chan->dar, data); break; case NOP: break; default: - __unreachable(); + VMPANIC("corrupted op=%d", op); } // デバイスアクセスなら ACK#n 信号と DONE 信号のドライブ @@ -1581,7 +1591,7 @@ DMACDevice::TransferCallback(Event& ev) case NOP: break; default: - __unreachable(); + VMPANIC("corrupted op=%d", op); } // シーケンス完了で MTC の転送1回分 @@ -1616,7 +1626,7 @@ DMACDevice::TransferError(DMACChan *chan if (chan->retry < 100) { // 現在のイベントを再実行 event.time = 1 * 80_nsec; - gScheduler->StartEvent(event); + scheduler->StartEvent(event); return; } // タイムアウトしたらバスエラーにフォールスルー @@ -1637,7 +1647,7 @@ DMACDevice::TransferError(DMACChan *chan Error(chan, DMAC::CER_BUS_DAR); break; default: - __unreachable(); + VMPANIC("corrupted op=%d", op); } } @@ -1661,13 +1671,13 @@ DMACDevice::AssertACK(DMACChan *chan) { switch (chan->ch) { case 0: - gFDC->AssertDACK(chan->mtc == 1); + fdc->AssertDACK(chan->mtc == 1); break; case 1: // 接続されていない break; case 3: - gADPCM->AssertDACK(chan->mtc == 1); + adpcm->AssertDACK(chan->mtc == 1); break; default: VMPANIC("未実装"); @@ -1680,13 +1690,13 @@ DMACDevice::NegateACK(DMACChan *chan) { switch (chan->ch) { case 0: - gFDC->NegateDACK(); + fdc->NegateDACK(); break; case 1: // 接続されていない break; case 3: - gADPCM->NegateDACK(); + adpcm->NegateDACK(); break; default: VMPANIC("未実装"); @@ -1708,7 +1718,7 @@ DMACDevice::AssertREQ(int ch) } if (event.IsRunning() == false) { - gScheduler->StartEvent(event); + scheduler->StartEvent(event); } } @@ -1760,7 +1770,7 @@ DMACDevice::ChangeInterrupt() irq = true; } } - gInterrupt->ChangeINT(this, irq); + interrupt->ChangeINT(this, irq); } // 割り込みアクノリッジ