-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
89 lines (77 loc) · 2.38 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
mod chip8;
mod emusdl2;
use std::path::PathBuf;
use clap::Parser;
use clap_num::maybe_hex;
use emusdl2::EmuSdl2;
use crate::{
chip8::{Chip8, Quirks},
emusdl2::Options,
};
#[derive(Debug, Parser)]
#[command(author, version, about)]
/// A simple Chip8 emulator that uses SDL
struct Cli {
/// Path to the binary Chip8 program to run
program: PathBuf,
/// Frames per second
#[arg(short, long, default_value_t = 60)]
fps: u16,
/// Instruction multiplier (instructions per frame)
#[arg(short, long, default_value_t = 20)]
mul: u16,
/// Scale of display
#[arg(short, long, default_value_t = 10)]
scale: u8,
/// Foreground color. Format ARGB8888 (hex possible, e.g. 0xff0000ff)
#[arg(short, long, value_parser=maybe_hex::<u32>, default_value_t = 0xff222222)]
color: u32,
/// Background color. Format ARGB8888 (hex possible, e.g. 0xff111111)
#[arg(short, long, value_parser=maybe_hex::<u32>, default_value_t = 0xff666f66)]
background: u32,
/// Pitch of buzzer in Hz
#[arg(short, long, default_value_t = 220)]
pitch: u16,
/// Quirk: AND, OR, XOR reset VF to zero
#[arg(long)]
quirk_vf_reset: bool,
/// Quirk: Memory load/store registers operations increment I
#[arg(long)]
quirk_memory: bool,
/// Quirk: Only one draw operation per frame
#[arg(long)]
quirk_display_wait: bool,
/// Quirk: Drawing operations clip instead of wrap
#[arg(long)]
quirk_clipping: bool,
/// Quirk: Shifting operations use VY instead of only VX
#[arg(long)]
quirk_shifting: bool,
/// Quirk: Jump with offset operation BNNN will work as BXNN.
#[arg(long)]
quirk_jumping: bool,
}
fn main() {
let cli = Cli::parse();
println!("{:?}", cli);
let program = std::fs::read(&cli.program).expect("could not read file");
let quirks = Quirks {
vf_reset: cli.quirk_vf_reset,
memory: cli.quirk_memory,
display_wait: cli.quirk_display_wait,
clipping: cli.quirk_clipping,
shifting: cli.quirk_shifting,
jumping: cli.quirk_jumping,
};
let chip8 = Chip8::new(program, quirks);
let options: Options = Options {
fps: cli.fps,
mul: cli.mul,
scale: cli.scale,
color: cli.color,
background: cli.background,
pitch: cli.pitch,
};
let mut emusdl = EmuSdl2::new(chip8, options);
emusdl.run();
}