From 60680a36e22aa97db7411b17bece37adb430f4c7 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:13:00 -0300 Subject: [PATCH] fix: account for lateness in RTC scheduler event --- src/core/bus/GamePak.zig | 4 ++-- src/core/scheduler.zig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/bus/GamePak.zig b/src/core/bus/GamePak.zig index b75d934..7bfde15 100644 --- a/src/core/bus/GamePak.zig +++ b/src/core/bus/GamePak.zig @@ -505,8 +505,8 @@ pub const Clock = struct { cpu.sched.push(.RealTimeClock, 1 << 24); // Every Second } - pub fn updateTime(self: *This) void { - self.cpu.sched.push(.RealTimeClock, 1 << 24); // Reschedule + pub fn updateTime(self: *This, late: u64) void { + self.cpu.sched.push(.RealTimeClock, (1 << 24) -| late); // Reschedule const now = DateTime.now(); self.year = toBcd(u8, @intCast(u8, now.date.year - 2000)); diff --git a/src/core/scheduler.zig b/src/core/scheduler.zig index af6989c..4c96c3b 100644 --- a/src/core/scheduler.zig +++ b/src/core/scheduler.zig @@ -66,7 +66,7 @@ pub const Scheduler = struct { if (device.kind != .Rtc or device.ptr == null) return; const clock = @ptrCast(*Clock, @alignCast(@alignOf(*Clock), device.ptr.?)); - clock.updateTime(); + clock.updateTime(late); }, .FrameSequencer => cpu.bus.apu.tickFrameSequencer(late), .SampleAudio => cpu.bus.apu.sampleAudio(late),