Skip to content

Commit

Permalink
update speed based on refresh rate
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchUsr64 committed Jan 10, 2024
1 parent c652eea commit f71f296
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const RNG_MEMORY_LOCATION: usize = 0xff;

use clap::Parser;

const DEFAULT_INSTRUCTIONS_PER_FRAME: u32 = 100;

/// A simple 6502 emulator
#[derive(Parser, Debug)]
struct Args {
Expand All @@ -33,9 +35,8 @@ struct Args {
#[arg(short, long, default_value_t = false)]
start_debug: bool,
/// Number of CPU instructions to execute per frame
// TODO: Change default value depending on screen's refresh rate
#[arg(short, long, default_value_t = 100)]
instructions_per_framce: u32,
#[arg(short, long, default_value_t = DEFAULT_INSTRUCTIONS_PER_FRAME)]
instructions_per_frame: u32,
/// Debug symbols generated by the provided assembler
#[arg(short, long, default_value_t = String::from("symbols.dbg"))]
debug_symbols: String,
Expand Down Expand Up @@ -95,7 +96,12 @@ async fn main() {
let mut app = App::new(debug_symbols, source_file);

app.paused = args.start_debug;
app.instructions_per_frame = args.instructions_per_framce;
// TODO: Handle the case when the user explicity sets the value to be the default
app.instructions_per_frame = if args.instructions_per_frame != DEFAULT_INSTRUCTIONS_PER_FRAME {
args.instructions_per_frame
} else {
args.instructions_per_frame * 60 / macroquad::time::get_fps() as u32
};
loop {
if app.reset {
cpu = Cpu::new();
Expand Down

0 comments on commit f71f296

Please sign in to comment.