aboutsummaryrefslogtreecommitdiff
path: root/src/DMA.cpp
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2020-12-04 18:28:15 +0100
committerArisotura <thetotalworm@gmail.com>2020-12-04 18:28:15 +0100
commit129018a6626cbec915ef73484c51c9d07af8e8b9 (patch)
tree8e5712bd241319731f7b6ade3363cefe845e3a5e /src/DMA.cpp
parent6aad429383015a0ac135b081931ae9c5876a7ad0 (diff)
parent42e083960e52cce31589714dcc7fab8e173efb81 (diff)
Merge remote-tracking branch 'remotes/origin/master' into dsi_camera
Diffstat (limited to 'src/DMA.cpp')
-rw-r--r--src/DMA.cpp55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/DMA.cpp b/src/DMA.cpp
index 18b8a2f..8ad3918 100644
--- a/src/DMA.cpp
+++ b/src/DMA.cpp
@@ -77,21 +77,6 @@ void DMA::Reset()
Running = false;
InProgress = false;
-
- if (NDS::ConsoleType == 1)
- {
- BusRead16 = (CPU==0) ? DSi::ARM9Read16 : DSi::ARM7Read16;
- BusRead32 = (CPU==0) ? DSi::ARM9Read32 : DSi::ARM7Read32;
- BusWrite16 = (CPU==0) ? DSi::ARM9Write16 : DSi::ARM7Write16;
- BusWrite32 = (CPU==0) ? DSi::ARM9Write32 : DSi::ARM7Write32;
- }
- else
- {
- BusRead16 = (CPU==0) ? NDS::ARM9Read16 : NDS::ARM7Read16;
- BusRead32 = (CPU==0) ? NDS::ARM9Read32 : NDS::ARM7Read32;
- BusWrite16 = (CPU==0) ? NDS::ARM9Write16 : NDS::ARM7Write16;
- BusWrite32 = (CPU==0) ? NDS::ARM9Write32 : NDS::ARM7Write32;
- }
}
void DMA::DoSavestate(Savestate* file)
@@ -198,13 +183,7 @@ void DMA::Start()
NDS::StopCPU(CPU, 1<<Num);
}
-void DMA::Run()
-{
- if (!Running) return;
- if (CPU == 0) return Run9();
- else return Run7();
-}
-
+template <int ConsoleType>
void DMA::Run9()
{
if (NDS::ARM9Timestamp >= NDS::ARM9Target) return;
@@ -242,7 +221,10 @@ void DMA::Run9()
{
NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift);
- BusWrite16(CurDstAddr, BusRead16(CurSrcAddr));
+ if (ConsoleType == 1)
+ DSi::ARM9Write16(CurDstAddr, DSi::ARM9Read16(CurSrcAddr));
+ else
+ NDS::ARM9Write16(CurDstAddr, NDS::ARM9Read16(CurSrcAddr));
CurSrcAddr += SrcAddrInc<<1;
CurDstAddr += DstAddrInc<<1;
@@ -278,7 +260,10 @@ void DMA::Run9()
{
NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift);
- BusWrite32(CurDstAddr, BusRead32(CurSrcAddr));
+ if (ConsoleType == 1)
+ DSi::ARM9Write32(CurDstAddr, DSi::ARM9Read32(CurSrcAddr));
+ else
+ NDS::ARM9Write32(CurDstAddr, NDS::ARM9Read32(CurSrcAddr));
CurSrcAddr += SrcAddrInc<<2;
CurDstAddr += DstAddrInc<<2;
@@ -317,6 +302,7 @@ void DMA::Run9()
NDS::ResumeCPU(0, 1<<Num);
}
+template <int ConsoleType>
void DMA::Run7()
{
if (NDS::ARM7Timestamp >= NDS::ARM7Target) return;
@@ -354,7 +340,10 @@ void DMA::Run7()
{
NDS::ARM7Timestamp += unitcycles;
- BusWrite16(CurDstAddr, BusRead16(CurSrcAddr));
+ if (ConsoleType == 1)
+ DSi::ARM7Write16(CurDstAddr, DSi::ARM7Read16(CurSrcAddr));
+ else
+ NDS::ARM7Write16(CurDstAddr, NDS::ARM7Read16(CurSrcAddr));
CurSrcAddr += SrcAddrInc<<1;
CurDstAddr += DstAddrInc<<1;
@@ -390,7 +379,10 @@ void DMA::Run7()
{
NDS::ARM7Timestamp += unitcycles;
- BusWrite32(CurDstAddr, BusRead32(CurSrcAddr));
+ if (ConsoleType == 1)
+ DSi::ARM7Write32(CurDstAddr, DSi::ARM7Read32(CurSrcAddr));
+ else
+ NDS::ARM7Write32(CurDstAddr, NDS::ARM7Read32(CurSrcAddr));
CurSrcAddr += SrcAddrInc<<2;
CurDstAddr += DstAddrInc<<2;
@@ -425,3 +417,14 @@ void DMA::Run7()
InProgress = false;
NDS::ResumeCPU(1, 1<<Num);
}
+
+template <int ConsoleType>
+void DMA::Run()
+{
+ if (!Running) return;
+ if (CPU == 0) return Run9<ConsoleType>();
+ else return Run7<ConsoleType>();
+}
+
+template void DMA::Run<0>();
+template void DMA::Run<1>(); \ No newline at end of file