From 4eb715a1387e702f03b852b7c8df23a43c9c4017 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 28 Oct 2022 21:57:30 -0300 Subject: [PATCH] doc(emu): properly document + simply constants --- src/core/emu.zig | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/core/emu.zig b/src/core/emu.zig index ea4df44..ce6c502 100644 --- a/src/core/emu.zig +++ b/src/core/emu.zig @@ -9,18 +9,22 @@ const FpsTracker = @import("../util.zig").FpsTracker; const Timer = std.time.Timer; const Atomic = std.atomic.Atomic; -// 228 Lines which consist of 308 dots (which are 4 cycles long) -const cycles_per_frame: u64 = 228 * (308 * 4); //280896 -const clock_rate: u64 = 1 << 24; // 16.78MHz +/// 4 Cycles in 1 dot +const cycles_per_dot = 4; -// TODO: Don't truncate this, be more accurate w/ timing -// 59.6046447754ns (truncated to just 59ns) -const clock_period: u64 = std.time.ns_per_s / clock_rate; -const frame_period = (clock_period * cycles_per_frame); +/// The GBA draws 228 Horizontal which each consist 308 dots +/// (note: not all lines are visible) +const cycles_per_frame = 228 * (308 * cycles_per_dot); //280896 -// 59.7275005696Hz -pub const frame_rate = @intToFloat(f64, std.time.ns_per_s) / - ((@intToFloat(f64, std.time.ns_per_s) / @intToFloat(f64, clock_rate)) * @intToFloat(f64, cycles_per_frame)); +/// The GBA ARM7TDMI runs at 2^24 Hz +const clock_rate = 1 << 24; // 16.78MHz + +/// The # of nanoseconds a frame should take +const frame_period = (std.time.ns_per_s * cycles_per_frame) / clock_rate; + +/// Exact Value: 59.7275005696Hz +/// The inverse of the frame period +pub const frame_rate: f64 = @intToFloat(f64, clock_rate) / cycles_per_frame; const log = std.log.scoped(.Emulation);