mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
harmless DMA micro optimisation
This commit is contained in:
55
src/DMA.cpp
55
src/DMA.cpp
@ -77,21 +77,6 @@ void DMA::Reset()
|
|||||||
|
|
||||||
Running = false;
|
Running = false;
|
||||||
InProgress = 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)
|
void DMA::DoSavestate(Savestate* file)
|
||||||
@ -198,13 +183,7 @@ void DMA::Start()
|
|||||||
NDS::StopCPU(CPU, 1<<Num);
|
NDS::StopCPU(CPU, 1<<Num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMA::Run()
|
template <int ConsoleType>
|
||||||
{
|
|
||||||
if (!Running) return;
|
|
||||||
if (CPU == 0) return Run9();
|
|
||||||
else return Run7();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DMA::Run9()
|
void DMA::Run9()
|
||||||
{
|
{
|
||||||
if (NDS::ARM9Timestamp >= NDS::ARM9Target) return;
|
if (NDS::ARM9Timestamp >= NDS::ARM9Target) return;
|
||||||
@ -242,7 +221,10 @@ void DMA::Run9()
|
|||||||
{
|
{
|
||||||
NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift);
|
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;
|
CurSrcAddr += SrcAddrInc<<1;
|
||||||
CurDstAddr += DstAddrInc<<1;
|
CurDstAddr += DstAddrInc<<1;
|
||||||
@ -278,7 +260,10 @@ void DMA::Run9()
|
|||||||
{
|
{
|
||||||
NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift);
|
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;
|
CurSrcAddr += SrcAddrInc<<2;
|
||||||
CurDstAddr += DstAddrInc<<2;
|
CurDstAddr += DstAddrInc<<2;
|
||||||
@ -317,6 +302,7 @@ void DMA::Run9()
|
|||||||
NDS::ResumeCPU(0, 1<<Num);
|
NDS::ResumeCPU(0, 1<<Num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <int ConsoleType>
|
||||||
void DMA::Run7()
|
void DMA::Run7()
|
||||||
{
|
{
|
||||||
if (NDS::ARM7Timestamp >= NDS::ARM7Target) return;
|
if (NDS::ARM7Timestamp >= NDS::ARM7Target) return;
|
||||||
@ -354,7 +340,10 @@ void DMA::Run7()
|
|||||||
{
|
{
|
||||||
NDS::ARM7Timestamp += unitcycles;
|
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;
|
CurSrcAddr += SrcAddrInc<<1;
|
||||||
CurDstAddr += DstAddrInc<<1;
|
CurDstAddr += DstAddrInc<<1;
|
||||||
@ -390,7 +379,10 @@ void DMA::Run7()
|
|||||||
{
|
{
|
||||||
NDS::ARM7Timestamp += unitcycles;
|
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;
|
CurSrcAddr += SrcAddrInc<<2;
|
||||||
CurDstAddr += DstAddrInc<<2;
|
CurDstAddr += DstAddrInc<<2;
|
||||||
@ -425,3 +417,14 @@ void DMA::Run7()
|
|||||||
InProgress = false;
|
InProgress = false;
|
||||||
NDS::ResumeCPU(1, 1<<Num);
|
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>();
|
@ -34,9 +34,12 @@ public:
|
|||||||
void WriteCnt(u32 val);
|
void WriteCnt(u32 val);
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
|
template <int ConsoleType>
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
|
template <int ConsoleType>
|
||||||
void Run9();
|
void Run9();
|
||||||
|
template <int ConsoleType>
|
||||||
void Run7();
|
void Run7();
|
||||||
|
|
||||||
bool IsInMode(u32 mode)
|
bool IsInMode(u32 mode)
|
||||||
@ -86,11 +89,6 @@ private:
|
|||||||
bool Stall;
|
bool Stall;
|
||||||
|
|
||||||
bool IsGXFIFODMA;
|
bool IsGXFIFODMA;
|
||||||
|
|
||||||
u16 (*BusRead16)(u32 addr);
|
|
||||||
u32 (*BusRead32)(u32 addr);
|
|
||||||
void (*BusWrite16)(u32 addr, u16 val);
|
|
||||||
void (*BusWrite32)(u32 addr, u32 val);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
26
src/NDS.cpp
26
src/NDS.cpp
@ -908,7 +908,7 @@ void RunSystem(u64 timestamp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool EnableJIT>
|
template <bool EnableJIT, int ConsoleType>
|
||||||
u32 RunFrame()
|
u32 RunFrame()
|
||||||
{
|
{
|
||||||
FrameStartTimestamp = SysTimestamp;
|
FrameStartTimestamp = SysTimestamp;
|
||||||
@ -934,10 +934,10 @@ u32 RunFrame()
|
|||||||
}
|
}
|
||||||
else if (CPUStop & 0x0FFF)
|
else if (CPUStop & 0x0FFF)
|
||||||
{
|
{
|
||||||
DMAs[0]->Run();
|
DMAs[0]->Run<ConsoleType>();
|
||||||
if (!(CPUStop & 0x80000000)) DMAs[1]->Run();
|
if (!(CPUStop & 0x80000000)) DMAs[1]->Run<ConsoleType>();
|
||||||
if (!(CPUStop & 0x80000000)) DMAs[2]->Run();
|
if (!(CPUStop & 0x80000000)) DMAs[2]->Run<ConsoleType>();
|
||||||
if (!(CPUStop & 0x80000000)) DMAs[3]->Run();
|
if (!(CPUStop & 0x80000000)) DMAs[3]->Run<ConsoleType>();
|
||||||
if (ConsoleType == 1) DSi::RunNDMAs(0);
|
if (ConsoleType == 1) DSi::RunNDMAs(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -962,10 +962,10 @@ u32 RunFrame()
|
|||||||
|
|
||||||
if (CPUStop & 0x0FFF0000)
|
if (CPUStop & 0x0FFF0000)
|
||||||
{
|
{
|
||||||
DMAs[4]->Run();
|
DMAs[4]->Run<ConsoleType>();
|
||||||
DMAs[5]->Run();
|
DMAs[5]->Run<ConsoleType>();
|
||||||
DMAs[6]->Run();
|
DMAs[6]->Run<ConsoleType>();
|
||||||
DMAs[7]->Run();
|
DMAs[7]->Run<ConsoleType>();
|
||||||
if (ConsoleType == 1) DSi::RunNDMAs(1);
|
if (ConsoleType == 1) DSi::RunNDMAs(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1012,10 +1012,14 @@ u32 RunFrame()
|
|||||||
{
|
{
|
||||||
#ifdef JIT_ENABLED
|
#ifdef JIT_ENABLED
|
||||||
if (Config::JIT_Enable)
|
if (Config::JIT_Enable)
|
||||||
return RunFrame<true>();
|
return NDS::ConsoleType == 1
|
||||||
|
? RunFrame<true, 1>()
|
||||||
|
: RunFrame<true, 0>();
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
return RunFrame<false>();
|
return NDS::ConsoleType == 0
|
||||||
|
? RunFrame<false, 1>()
|
||||||
|
: RunFrame<false, 0>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reschedule(u64 target)
|
void Reschedule(u64 target)
|
||||||
|
Reference in New Issue
Block a user