improve accuracy and also performance

This commit is contained in:
Jaklyy 2024-12-21 17:28:32 -05:00
parent caa009ca03
commit 4940f940c7
1 changed files with 43 additions and 45 deletions

View File

@ -1760,54 +1760,55 @@ u32 NDS::RunFrame()
u64 target = NextTarget();
ARM9Target = target << ARM9ClockShift;
ARM7Target = target;
while (std::max(std::max(ARM9Timestamp, DMA9Timestamp), A9ContentionTS << ARM9ClockShift) < ARM9Target)
while (((std::max(std::max(ARM9Timestamp, DMA9Timestamp), A9ContentionTS << ARM9ClockShift) < ARM9Target) && (ARM9.MRTrack.Type == MainRAMType::Null))
|| (ARM7Timestamp < ARM7Target) && (ARM7.MRTrack.Type == MainRAMType::Null))
{
CurCPU = 0;
RunTimers(0);
GPU.GPU3D.Run();
while (std::max(std::max(ARM9Timestamp, DMA9Timestamp), A9ContentionTS << ARM9ClockShift) < ARM9Target)
{
CurCPU = 0;
RunTimers(0);
GPU.GPU3D.Run();
if (CPUStop & CPUStop_GXStall)
{
// GXFIFO stall
s32 cycles = GPU.GPU3D.CyclesToRunFor();
DMA9Timestamp = std::min(ARM9Target, std::max(ARM9Timestamp, DMA9Timestamp)+(cycles<<ARM9ClockShift));
}
else if (ARM9.MRTrack.Type == MainRAMType::Null)
{
if (CPUStop & CPUStop_DMA9)
if (CPUStop & CPUStop_GXStall)
{
DMAs[0].Run();
if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[1].Run();
if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[2].Run();
if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[3].Run();
if (ConsoleType == 1)
// GXFIFO stall
s32 cycles = GPU.GPU3D.CyclesToRunFor();
DMA9Timestamp = std::min(ARM9Target, std::max(ARM9Timestamp, DMA9Timestamp)+(cycles<<ARM9ClockShift));
}
else if (ARM9.MRTrack.Type == MainRAMType::Null)
{
if (CPUStop & CPUStop_DMA9)
{
auto& dsi = dynamic_cast<melonDS::DSi&>(*this);
dsi.RunNDMAs(0);
DMAs[0].Run();
if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[1].Run();
if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[2].Run();
if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[3].Run();
if (ConsoleType == 1)
{
auto& dsi = dynamic_cast<melonDS::DSi&>(*this);
dsi.RunNDMAs(0);
}
}
else
{
//if (ARM9.abt) ARM9Timestamp = ARM9Target;
ARM9.Execute<cpuMode>();
}
}
else
{
//if (ARM9.abt) ARM9Timestamp = ARM9Target;
ARM9.Execute<cpuMode>();
}
//printf("MAIN LOOP: 9 %lli %lli %08X %08llX %i 7 %lli %lli %08X %08llX %i\n", ARM9Timestamp, ARM9Target, ARM9.PC, ARM9.CurInstr, (u8)ARM9.MRTrack.Type, ARM7Timestamp, ARM7Target, ARM7.R[15], ARM7.CurInstr, (u8)ARM7.MRTrack.Type);
RunTimers(0);
GPU.GPU3D.Run();
if (MainRAMHandle()) break;
}
//printf("MAIN LOOP: 9 %lli %08X %08llX %i 7 %lli %08X %08llX %i %i %08X\n", ARM9Timestamp>>ARM9ClockShift, ARM9.PC, ARM9.CurInstr, (u8)ARM9.MRTrack.Type, ARM7Timestamp, ARM7.R[15], ARM7.CurInstr, (u8)ARM7.MRTrack.Type, IME[1], IE[1]);
RunTimers(0);
GPU.GPU3D.Run();
MainRAMHandle();
target = std::max(std::max(ARM9Timestamp, DMA9Timestamp) >> ARM9ClockShift, A9ContentionTS);
if (target == ARM7Timestamp) target++;
while (ARM7Timestamp < target)
while (ARM7Timestamp < ARM7Target)
{
ARM7Target = target;
//printf("A7 LOOP: %lli %lli\n", ARM9Timestamp>>ARM9ClockShift, ARM7Timestamp);
//printf("A7 LOOP: 9 %lli %lli %08X %08llX %i 7 %lli %lli %08X %08llX %i\n", ARM9Timestamp, ARM9Target, ARM9.PC, ARM9.CurInstr, (u8)ARM9.MRTrack.Type, ARM7Timestamp, ARM7Target, ARM7.R[15], ARM7.CurInstr, (u8)ARM7.MRTrack.Type);
CurCPU = 1;
RunTimers(1);
@ -1838,7 +1839,7 @@ u32 NDS::RunFrame()
}
}
RunSystem(target);
RunSystem(ARM7Target);
if (CPUStop & CPUStop_Sleep)
{
@ -1860,7 +1861,6 @@ u32 NDS::RunFrame()
SPU.TransferOutput();
break;
}
//printf("MAIN LOOP: 9 %lli %08X %08llX %i 7 %lli %08X %08llX %i %i %08X\n", ARM9Timestamp>>ARM9ClockShift, ARM9.PC, ARM9.CurInstr, (u8)ARM9.MRTrack.Type, ARM7Timestamp, ARM7.R[15], ARM7.CurInstr, (u8)ARM7.MRTrack.Type, IME[1], IE[1]);
// In the context of TASes, frame count is traditionally the primary measure of emulated time,
// so it needs to be tracked even if NDS is powered off.
@ -1894,13 +1894,11 @@ u32 NDS::RunFrame()
void NDS::Reschedule(u64 target)
{
if (CurCPU == 0)
if (target < ARM7Target)
{
if (target < (ARM9Target >> ARM9ClockShift))
ARM9Target = (target << ARM9ClockShift);
}
else if (target < ARM7Target)
ARM7Target = target;
ARM9Target = (target << ARM9ClockShift);
}
}
void NDS::RegisterEventFuncs(u32 id, void* that, const std::initializer_list<EventFunc>& funcs)