diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-03-21 02:05:40 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-03-21 02:05:40 +0100 |
commit | 08a634371a60549d6e73fb1a3ddf6c9668fb00ce (patch) | |
tree | 6e2ef0894b6b21597f0f596c4681f4fc1713ffe5 /src | |
parent | 3a89513c93d857cbdc63012a698d390e5a20f0f0 (diff) |
fix bug that happened when HDMA got interrupted (or any repeating DMA, for that matter)
Diffstat (limited to 'src')
-rw-r--r-- | src/DMA.cpp | 25 | ||||
-rw-r--r-- | src/DMA.h | 1 |
2 files changed, 15 insertions, 11 deletions
diff --git a/src/DMA.cpp b/src/DMA.cpp index 14fe791..d4e6d70 100644 --- a/src/DMA.cpp +++ b/src/DMA.cpp @@ -115,6 +115,7 @@ void DMA::Reset() DstAddrInc = 0; Running = false; + InProgress = false; } void DMA::WriteCnt(u32 val) @@ -162,15 +163,18 @@ void DMA::Start() { if (Running) return; - u32 countmask; - if (CPU == 0) - countmask = 0x001FFFFF; - else - countmask = (Num==3 ? 0x0000FFFF : 0x00003FFF); + if (!InProgress) + { + u32 countmask; + if (CPU == 0) + countmask = 0x001FFFFF; + else + countmask = (Num==3 ? 0x0000FFFF : 0x00003FFF); - RemCount = Cnt & countmask; - if (!RemCount) - RemCount = countmask+1; + RemCount = Cnt & countmask; + if (!RemCount) + RemCount = countmask+1; + } if (StartMode == 0x07 && RemCount > 112) IterCount = 112; @@ -211,6 +215,7 @@ void DMA::Start() // TODO eventually: not stop if we're running code in ITCM Running = true; + InProgress = true; NDS::StopCPU(CPU, 1<<Num); } @@ -260,9 +265,6 @@ s32 DMA::Run(s32 cycles) if (RemCount) { - Cnt &= ~CountMask; - Cnt |= RemCount; - if (IterCount == 0) { Running = false; @@ -282,6 +284,7 @@ s32 DMA::Run(s32 cycles) NDS::SetIRQ(CPU, NDS::IRQ_DMA0 + Num); Running = false; + InProgress = false; NDS::ResumeCPU(CPU, 1<<Num); return cycles - 2; @@ -65,6 +65,7 @@ private: u32 CountMask; bool Running; + bool InProgress; }; #endif |