diff --git a/src/DMA.cpp b/src/DMA.cpp index 18b8a2f1..8ad3918d 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< 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< 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< +void DMA::Run() +{ + if (!Running) return; + if (CPU == 0) return Run9(); + else return Run7(); +} + +template void DMA::Run<0>(); +template void DMA::Run<1>(); \ No newline at end of file diff --git a/src/DMA.h b/src/DMA.h index 0344fbac..b0b4ab2a 100644 --- a/src/DMA.h +++ b/src/DMA.h @@ -34,9 +34,12 @@ public: void WriteCnt(u32 val); void Start(); + template void Run(); + template void Run9(); + template void Run7(); bool IsInMode(u32 mode) @@ -86,11 +89,6 @@ private: bool Stall; bool IsGXFIFODMA; - - u16 (*BusRead16)(u32 addr); - u32 (*BusRead32)(u32 addr); - void (*BusWrite16)(u32 addr, u16 val); - void (*BusWrite32)(u32 addr, u32 val); }; #endif diff --git a/src/NDS.cpp b/src/NDS.cpp index 2b468be3..0b0263bb 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -908,7 +908,7 @@ void RunSystem(u64 timestamp) } } -template +template u32 RunFrame() { FrameStartTimestamp = SysTimestamp; @@ -934,10 +934,10 @@ u32 RunFrame() } else if (CPUStop & 0x0FFF) { - DMAs[0]->Run(); - if (!(CPUStop & 0x80000000)) DMAs[1]->Run(); - if (!(CPUStop & 0x80000000)) DMAs[2]->Run(); - if (!(CPUStop & 0x80000000)) DMAs[3]->Run(); + DMAs[0]->Run(); + if (!(CPUStop & 0x80000000)) DMAs[1]->Run(); + if (!(CPUStop & 0x80000000)) DMAs[2]->Run(); + if (!(CPUStop & 0x80000000)) DMAs[3]->Run(); if (ConsoleType == 1) DSi::RunNDMAs(0); } else @@ -962,10 +962,10 @@ u32 RunFrame() if (CPUStop & 0x0FFF0000) { - DMAs[4]->Run(); - DMAs[5]->Run(); - DMAs[6]->Run(); - DMAs[7]->Run(); + DMAs[4]->Run(); + DMAs[5]->Run(); + DMAs[6]->Run(); + DMAs[7]->Run(); if (ConsoleType == 1) DSi::RunNDMAs(1); } else @@ -1012,10 +1012,14 @@ u32 RunFrame() { #ifdef JIT_ENABLED if (Config::JIT_Enable) - return RunFrame(); + return NDS::ConsoleType == 1 + ? RunFrame() + : RunFrame(); else #endif - return RunFrame(); + return NDS::ConsoleType == 0 + ? RunFrame() + : RunFrame(); } void Reschedule(u64 target)