diff options
author | RSDuck <RSDuck@users.noreply.github.com> | 2021-09-27 03:29:54 +0200 |
---|---|---|
committer | RSDuck <RSDuck@users.noreply.github.com> | 2021-09-27 03:30:15 +0200 |
commit | 737171c90687f8bfb8827849e7a4bd6734009249 (patch) | |
tree | 2398c769251190bcab288f174bb00e7cd938a040 /src | |
parent | 1471c73ea69896e33bb0c12310809b1407a3efbb (diff) |
implement margins for scheduler
hopefully this does not break anything
Diffstat (limited to 'src')
-rw-r--r-- | src/NDS.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
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; |