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,7 +1760,11 @@ u32 NDS::RunFrame()
u64 target = NextTarget();
ARM9Target = target << ARM9ClockShift;
ARM7Target = target;
while (((std::max(std::max(ARM9Timestamp, DMA9Timestamp), A9ContentionTS << ARM9ClockShift) < ARM9Target) && (ARM9.MRTrack.Type == MainRAMType::Null))
|| (ARM7Timestamp < ARM7Target) && (ARM7.MRTrack.Type == MainRAMType::Null))
{
while (std::max(std::max(ARM9Timestamp, DMA9Timestamp), A9ContentionTS << ARM9ClockShift) < ARM9Target)
{
CurCPU = 0;
@ -1794,20 +1798,17 @@ u32 NDS::RunFrame()
}
}
//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]);
//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();
MainRAMHandle();
if (MainRAMHandle()) break;
}
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))
ARM7Target = target;
ARM9Target = (target << ARM9ClockShift);
}
else if (target < ARM7Target)
ARM7Target = target;
}
void NDS::RegisterEventFuncs(u32 id, void* that, const std::initializer_list<EventFunc>& funcs)