diff options
-rw-r--r-- | src/DMA.cpp | 55 | ||||
-rw-r--r-- | src/DMA.h | 8 | ||||
-rw-r--r-- | src/NDS.cpp | 26 |
3 files changed, 47 insertions, 42 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 @@ -34,9 +34,12 @@ public: void WriteCnt(u32 val); void Start(); + template <int ConsoleType> void Run(); + template <int ConsoleType> void Run9(); + template <int ConsoleType> 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 2b468be..0b0263b 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -908,7 +908,7 @@ void RunSystem(u64 timestamp) } } -template <bool EnableJIT> +template <bool EnableJIT, int ConsoleType> 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<ConsoleType>(); + if (!(CPUStop & 0x80000000)) DMAs[1]->Run<ConsoleType>(); + if (!(CPUStop & 0x80000000)) DMAs[2]->Run<ConsoleType>(); + if (!(CPUStop & 0x80000000)) DMAs[3]->Run<ConsoleType>(); 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<ConsoleType>(); + DMAs[5]->Run<ConsoleType>(); + DMAs[6]->Run<ConsoleType>(); + DMAs[7]->Run<ConsoleType>(); if (ConsoleType == 1) DSi::RunNDMAs(1); } else @@ -1012,10 +1012,14 @@ u32 RunFrame() { #ifdef JIT_ENABLED if (Config::JIT_Enable) - return RunFrame<true>(); + return NDS::ConsoleType == 1 + ? RunFrame<true, 1>() + : RunFrame<true, 0>(); else #endif - return RunFrame<false>(); + return NDS::ConsoleType == 0 + ? RunFrame<false, 1>() + : RunFrame<false, 0>(); } void Reschedule(u64 target) |