fix: reimplement halt fast-forwarding

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-07-21 11:25:49 -03:00
parent 03ded099d2
commit c7c4a90948
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 {
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);
}
}