fix(emu): prevent infinite loop when advancing scheduler
This commit is contained in:
parent
c9f0e1632c
commit
1d4ba2e2b3
16
src/emu.zig
16
src/emu.zig
|
@ -1,19 +1,17 @@
|
||||||
const _ = @import("std");
|
|
||||||
|
|
||||||
const Scheduler = @import("scheduler.zig").Scheduler;
|
const Scheduler = @import("scheduler.zig").Scheduler;
|
||||||
const Arm7tdmi = @import("cpu.zig").Arm7tdmi;
|
const Arm7tdmi = @import("cpu.zig").Arm7tdmi;
|
||||||
const Bus = @import("bus.zig").Bus;
|
const Bus = @import("bus.zig").Bus;
|
||||||
|
|
||||||
const cycles_per_frame: u64 = 10_000; // TODO: How many cycles actually?
|
const cycles_per_frame: u64 = 100; // TODO: How many cycles actually?
|
||||||
|
|
||||||
pub fn runFrame(sch: *Scheduler, cpu: *Arm7tdmi, bus: *Bus) void {
|
pub fn runFrame(sch: *Scheduler, cpu: *Arm7tdmi, bus: *Bus) void {
|
||||||
const frame_end = sch.tick + cycles_per_frame;
|
var cycles: u64 = 0;
|
||||||
|
while (cycles < cycles_per_frame) : (cycles += 1) {
|
||||||
while (sch.tick < frame_end) {
|
sch.tick += 1;
|
||||||
while (sch.tick < sch.nextTimestamp()) {
|
_ = cpu.step();
|
||||||
sch.tick += cpu.step();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
while (sch.tick >= sch.nextTimestamp()) {
|
||||||
sch.handleEvent(cpu, bus);
|
sch.handleEvent(cpu, bus);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue