From 737171c90687f8bfb8827849e7a4bd6734009249 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Mon, 27 Sep 2021 03:29:54 +0200 Subject: implement margins for scheduler hopefully this does not break anything --- src/NDS.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/NDS.cpp b/src/NDS.cpp index 8341687..4c2db69 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -88,6 +88,7 @@ u64 FrameStartTimestamp; int CurCPU; const s32 kMaxIterationCycles = 64; +const s32 kIterationCycleMargin = 8; u32 ARM9ClockShift; @@ -917,7 +918,7 @@ void RelocateSave(const char* path, bool write) u64 NextTarget() { - u64 ret = SysTimestamp + kMaxIterationCycles; + u64 minEvent = UINT64_MAX; u32 mask = SchedListMask; for (int i = 0; i < Event_MAX; i++) @@ -925,14 +926,19 @@ u64 NextTarget() if (!mask) break; if (mask & 0x1) { - if (SchedList[i].Timestamp < ret) - ret = SchedList[i].Timestamp; + if (SchedList[i].Timestamp < minEvent) + minEvent = SchedList[i].Timestamp; } mask >>= 1; } - return ret; + u64 max = SysTimestamp + kMaxIterationCycles; + + if (minEvent < max + kIterationCycleMargin) + return minEvent; + + return max; } void RunSystem(u64 timestamp) @@ -969,7 +975,6 @@ u32 RunFrame() while (Running && GPU::TotalScanlines==0) { - // TODO: give it some margin, so it can directly do 17 cycles instead of 16 then 1 u64 target = NextTarget(); ARM9Target = target << ARM9ClockShift; CurCPU = 0; -- cgit v1.2.3