From 6aa36c2ead2673cc13fe5f3eb6a36b8240f8c1b7 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 24 Sep 2019 23:55:57 +1000 Subject: [PATCH] SPU: Hook up DMA reads/writes to RAM --- src/pse/spu.cpp | 29 ++++++++++++++++++++++++----- src/pse/spu.h | 2 ++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/pse/spu.cpp b/src/pse/spu.cpp index c8aa7dbbf..55aa8773d 100644 --- a/src/pse/spu.cpp +++ b/src/pse/spu.cpp @@ -75,10 +75,9 @@ void SPU::WriteRegister(u32 offset, u16 value) case 0x1F801DA8 - SPU_BASE: { - std::memcpy(&m_ram[m_transfer_address], &value, sizeof(value)); Log_TracePrintf("SPU transfer data register <- 0x%04X (RAM offset 0x%08X)", ZeroExtend32(value), m_transfer_address); - m_transfer_address = (m_transfer_address + sizeof(value)) & RAM_MASK; + RAMTransferWrite(value); return; } @@ -107,11 +106,17 @@ void SPU::WriteRegister(u32 offset, u16 value) u32 SPU::DMARead() { - Log_ErrorPrintf("SPU DMA READ"); - return UINT32_C(0xFFFFFFFF); + const u16 lsb = RAMTransferRead(); + const u16 msb = RAMTransferRead(); + return ZeroExtend32(lsb) | (ZeroExtend32(msb) << 16); } -void SPU::DMAWrite(u32 value) {} +void SPU::DMAWrite(u32 value) +{ + // two 16-bit writes to prevent out-of-bounds + RAMTransferWrite(Truncate16(value)); + RAMTransferWrite(Truncate16(value >> 16)); +} void SPU::UpdateDMARequest() { @@ -119,3 +124,17 @@ void SPU::UpdateDMARequest() const bool request = (mode == RAMTransferMode::DMAWrite || mode == RAMTransferMode::DMARead); m_dma->SetRequest(DMA::Channel::SPU, request); } + +u16 SPU::RAMTransferRead() +{ + u16 value; + std::memcpy(&value, &m_ram[m_transfer_address], sizeof(value)); + m_transfer_address = (m_transfer_address + sizeof(value)) & RAM_MASK; + return value; +} + +void SPU::RAMTransferWrite(u16 value) +{ + std::memcpy(&m_ram[m_transfer_address], &value, sizeof(value)); + m_transfer_address = (m_transfer_address + sizeof(value)) & RAM_MASK; +} diff --git a/src/pse/spu.h b/src/pse/spu.h index e61849669..91a211ad0 100644 --- a/src/pse/spu.h +++ b/src/pse/spu.h @@ -82,6 +82,8 @@ private: #endif void UpdateDMARequest(); + u16 RAMTransferRead(); + void RAMTransferWrite(u16 value); System* m_system = nullptr; DMA* m_dma = nullptr;