--- nono/vm/adpcm.cpp 2026/04/29 17:05:16 1.1.1.2 +++ nono/vm/adpcm.cpp 2026/04/29 17:05:49 1.1.1.6 @@ -10,6 +10,7 @@ #include "adpcm.h" #include "dmac.h" +#include "event.h" #include "mpu.h" #include "pio.h" #include "scheduler.h" @@ -18,8 +19,6 @@ ADPCMDevice::ADPCMDevice() : inherited(OBJ_ADPCM) { - event.func = ToEventCallback(&ADPCMDevice::EventCallback); - event.Regist("ADPCM"); } // デストラクタ @@ -31,13 +30,14 @@ ADPCMDevice::~ADPCMDevice() bool ADPCMDevice::Init() { - if (inherited::Init() == false) { - return false; - } - dmac = GetDMACDevice(); ppi = GetPPIDevice(); + auto evman = GetEventManager(); + event = evman->Regist(this, + ToEventCallback(&ADPCMDevice::EventCallback), + "ADPCM"); + return true; } @@ -53,12 +53,10 @@ ADPCMDevice::ResetHard(bool poweron) div = 512; } -uint64 -ADPCMDevice::Read(uint32 offset) +busdata +ADPCMDevice::ReadPort(uint32 offset) { - uint8 data; - - mpu->AddCycle(18); // InsideOut p.135 + busdata data; switch (offset) { case 0: // STAT @@ -66,24 +64,27 @@ ADPCMDevice::Read(uint32 offset) if (playing) { data |= STAT_PLAY; } - putlog(1, "STAT -> $%02x", data); + putlog(1, "STAT -> $%02x", data.Data()); break; case 1: // DATA putlog(0, "Read $%06x (NOT IMPLEMENTED)", mpu->GetPaddr()); data = 0xff; break; default: - VMPANIC("corrupted offset=%d", offset); + VMPANIC("corrupted offset=%u", offset); } + // InsideOut p.135 + const busdata wait = busdata::Wait(18 * 40_nsec); + data |= wait; + + data |= BusData::Size1; return data; } -uint64 -ADPCMDevice::Write(uint32 offset, uint32 data) +busdata +ADPCMDevice::WritePort(uint32 offset, uint32 data) { - mpu->AddCycle(22); // InsideOut p.135 - switch (offset) { case 0: // CMD putlog(1, "CMD <- $%02x", data); @@ -106,26 +107,37 @@ ADPCMDevice::Write(uint32 offset, uint32 } break; default: - VMPANIC("corrupted offset=%d", offset); + VMPANIC("corrupted offset=%u", offset); } - return 0; + // InsideOut p.135 + const busdata wait = busdata::Wait(22 * 40_nsec); + + busdata r = wait; + r |= BusData::Size1; + return r; } -uint64 -ADPCMDevice::Peek(uint32 offset) +busdata +ADPCMDevice::PeekPort(uint32 offset) { // XXX 未実装 return 0xff; } +bool +ADPCMDevice::PokePort(uint32 offset, uint32 data) +{ + return false; +} + // 再生開始 void ADPCMDevice::StartPlay() { // PPI で設定されているサンプリングレートをここで読み出す。 // XXX パンは未対応 - int rate = ppi->GetADPCMRate(); + uint rate = ppi->GetADPCMRate(); switch (rate) { case 0: div = 1024; @@ -138,19 +150,19 @@ ADPCMDevice::StartPlay() div = 512; break; default: - VMPANIC("corrupted ADPCM rate=%d", rate); + VMPANIC("corrupted ADPCM rate=%u", rate); } playing = true; dmac->AssertREQ(3); - event.time = div / clk; + event->time = div / clk; scheduler->StartEvent(event); } // イベント void -ADPCMDevice::EventCallback(Event& ev) +ADPCMDevice::EventCallback(Event *ev) { // XXX 適当 if (playing) {