From efdf18dadb89c929ce2f441bd168f0e1492c52d0 Mon Sep 17 00:00:00 2001 From: Sour Date: Sat, 28 Sep 2024 20:14:56 +0900 Subject: [PATCH] NES: DMAs interrupted during a write shouldn't start after the write --- Core/NES/NesCpu.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Core/NES/NesCpu.cpp b/Core/NES/NesCpu.cpp index 8e87a21b..78dbd4b3 100644 --- a/Core/NES/NesCpu.cpp +++ b/Core/NES/NesCpu.cpp @@ -531,9 +531,17 @@ void NesCpu::StartDmcTransfer() void NesCpu::StopDmcTransfer() { - if(_needHalt && _dmcDmaRunning) { - _abortDmcDma = true; - _needDummyRead = false; + if(_dmcDmaRunning) { + if(_needHalt) { + //If interrupted before the halt cycle starts, cancel DMA completely + //This can happen when a write prevents the DMA from starting after being queued + _dmcDmaRunning = false; + _needDummyRead = false; + _needHalt = false; + } else { + //Abort DMA if possible (this only appears to be possible if done within the first cycle of DMA) + _abortDmcDma = true; + } } }