fix: reimplement halt fast-forwarding

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-10-21 05:12:54 -03:00
parent 0939d6d7bc
commit 45fc49b216
1 changed files with 9 additions and 6 deletions

View File

@ -51,14 +51,17 @@ pub fn run(quit: *Atomic(bool), fps: *FpsTracker, sched: *Scheduler, cpu: *Arm7t
pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi) void { pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi) void {
const frame_end = sched.tick + cycles_per_frame; const frame_end = sched.tick + cycles_per_frame;
while (true) { while (sched.tick < frame_end) {
while (sched.tick < std.math.min(frame_end, sched.nextTimestamp())) { if (!cpu.stepDmaTransfer()) {
if (cpu.stepDmaTransfer()) continue; // DMA is blocking, ticks scheduler if (cpu.isHalted()) {
if (!cpu.isHalted()) cpu.step() else sched.tick += 1; // Fast-forward to next Event
sched.tick = sched.queue.peek().?.tick;
} else {
cpu.step();
}
} }
if (sched.tick >= frame_end) break; if (sched.tick >= sched.nextTimestamp()) sched.handleEvent(cpu);
sched.handleEvent(cpu);
} }
} }