diff --git a/emus/host/time.zig b/emus/host/time.zig index 6b926eb..e5cf6a3 100644 --- a/emus/host/time.zig +++ b/emus/host/time.zig @@ -41,6 +41,7 @@ pub fn after(micro_seconds: u64) bool { // a helper which triggers an action once after a delay pub const Once = struct { + elapsed_us: u64 = 0, delay_us: u64, triggered: bool, @@ -51,8 +52,9 @@ pub const Once = struct { }; } - pub fn once(self: *Once) bool { - if (!self.triggered and after(self.delay_us)) { + pub fn once(self: *Once, delta_us: u64) bool { + self.elapsed_us +%= delta_us; + if (!self.triggered and (self.elapsed_us >= self.delay_us)) { self.triggered = true; return true; } else { diff --git a/emus/kc85/kc85.zig b/emus/kc85/kc85.zig index 2e2a747..688ec91 100644 --- a/emus/kc85/kc85.zig +++ b/emus/kc85/kc85.zig @@ -85,7 +85,7 @@ export fn frame() void { .emu_stats = host.prof.stats(.EMU), }, }); - if (file_loaded.once()) { + if (file_loaded.once(frame_time_us)) { if (args.file_data) |file_data| { sys.load(.{ .data = file_data, .start = true, .patch = .{ .func = patch } }) catch |err| { print("Failed to load file into emulator with {}", .{err});