From 84e63edcda26ba396fd0128da19a4cc9274e1400 Mon Sep 17 00:00:00 2001 From: Fiskbit <2811896+Fiskbit@users.noreply.github.com> Date: Sun, 10 May 2026 01:49:03 -0700 Subject: [PATCH] NES: Adds MMC5 PCM read mode Based on Heemin's changes in PR #96. Related Work Items: #9 --- Core/NES/Mappers/Audio/Mmc5Audio.h | 10 +++++++++- Core/NES/Mappers/Nintendo/MMC5.h | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Core/NES/Mappers/Audio/Mmc5Audio.h b/Core/NES/Mappers/Audio/Mmc5Audio.h index 3b104450c..2acd91462 100644 --- a/Core/NES/Mappers/Audio/Mmc5Audio.h +++ b/Core/NES/Mappers/Audio/Mmc5Audio.h @@ -104,6 +104,14 @@ class Mmc5Audio : public BaseExpansionAudio _pcmOutput = 0; } + __forceinline bool GetPcmReadMode() { return _pcmReadMode; } + void HandlePcmRead(uint16_t addr, uint8_t value) + { + if((addr & 0xC000) == 0x8000 && value) { + _pcmOutput = value; + } + } + uint8_t ReadRegister(uint16_t addr) { switch(addr) { @@ -139,7 +147,7 @@ class Mmc5Audio : public BaseExpansionAudio break; case 0x5010: - //TODO: Read mode & PCM IRQs are not implemented + //TODO: PCM IRQs _pcmReadMode = (value & 0x01) == 0x01; _pcmIrqEnabled = (value & 0x80) == 0x80; break; diff --git a/Core/NES/Mappers/Nintendo/MMC5.h b/Core/NES/Mappers/Nintendo/MMC5.h index f1cec4906..cdfe27781 100644 --- a/Core/NES/Mappers/Nintendo/MMC5.h +++ b/Core/NES/Mappers/Nintendo/MMC5.h @@ -441,6 +441,15 @@ class MMC5 : public BaseMapper, public IExtModeMapperDebug } } + uint8_t ReadRam(uint16_t addr) override + { + uint8_t value = BaseMapper::ReadRam(addr); + if(_audio->GetPcmReadMode()) { + _audio->HandlePcmRead(addr, value); + } + return value; + } + void WriteRam(uint16_t addr, uint8_t value) override { if(addr >= 0x5C00 && addr <= 0x5FFF && _extendedRamMode <= 1 && !_ppuInFrame) {