fix: resolve issue when handling event sooner than expected
This commit is contained in:
parent
9d839a0328
commit
fc7f2a2959
|
@ -51,10 +51,7 @@ 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 (true) {
|
||||||
const next = sched.nextTimestamp();
|
while (sched.tick < std.math.min(frame_end, sched.nextTimestamp())) {
|
||||||
const run_until = std.math.min(next, frame_end);
|
|
||||||
|
|
||||||
while (sched.tick < run_until) {
|
|
||||||
if (cpu.bus.io.haltcnt == .Execute) cpu.step() else sched.tick += 1;
|
if (cpu.bus.io.haltcnt == .Execute) cpu.step() else sched.tick += 1;
|
||||||
cpu.handleDMATransfers();
|
cpu.handleDMATransfers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,10 +90,12 @@ pub const Scheduler = struct {
|
||||||
self.queue.add(.{ .kind = kind, .tick = self.now() + end }) catch unreachable;
|
self.queue.add(.{ .kind = kind, .tick = self.now() + end }) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nextTimestamp(self: *Self) u64 {
|
pub inline fn nextTimestamp(self: *const Self) u64 {
|
||||||
if (self.queue.peek()) |e| return e.tick;
|
@setRuntimeSafety(false);
|
||||||
|
|
||||||
unreachable; // There's always the HeatDeath event scheduled
|
// Typically you'd use PriorityQueue.peek here, but there's always at least a HeatDeath
|
||||||
|
// event in the PQ so we can just do this instead. Should be faster in ReleaseSafe
|
||||||
|
return self.queue.items[0].tick;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue