Skip to content

Commit

Permalink
kc85 fix file loading delay
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Aug 9, 2024
1 parent eed9806 commit cd7927b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions emus/host/time.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion emus/kc85/kc85.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down

0 comments on commit cd7927b

Please sign in to comment.