From 45fc49b216b3d1cceac1f576ba511845efb68a03 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:54 -0300 Subject: [PATCH] fix: reimplement halt fast-forwarding --- src/emu.zig | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/emu.zig b/src/emu.zig index 815d5c8..faf62f1 100644 --- a/src/emu.zig +++ b/src/emu.zig @@ -51,14 +51,17 @@ pub fn run(quit: *Atomic(bool), fps: *FpsTracker, sched: *Scheduler, cpu: *Arm7t pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi) void { const frame_end = sched.tick + cycles_per_frame; - while (true) { - while (sched.tick < std.math.min(frame_end, sched.nextTimestamp())) { - if (cpu.stepDmaTransfer()) continue; // DMA is blocking, ticks scheduler - if (!cpu.isHalted()) cpu.step() else sched.tick += 1; + while (sched.tick < frame_end) { + if (!cpu.stepDmaTransfer()) { + if (cpu.isHalted()) { + // Fast-forward to next Event + sched.tick = sched.queue.peek().?.tick; + } else { + cpu.step(); + } } - if (sched.tick >= frame_end) break; - sched.handleEvent(cpu); + if (sched.tick >= sched.nextTimestamp()) sched.handleEvent(cpu); } }