arnaucube
arnaucube/chip8-rsPublic Self-hosted repository
chip8-rs/src/main.rs
src/main.rsRaw
 1use clap::{App, Arg};
 2
 3use chip8::Chip8;
 4
 5struct SdlEmulator {
 6    w: usize,
 7    h: usize,
 8    zoom: usize,
 9    chip8: Chip8,
10}
11
12impl SdlEmulator {
13    fn new(w: usize, h: usize, zoom: usize) -> SdlEmulator {
14        let mut c = Chip8::new();
15
16        SdlEmulator {
17            w,
18            h,
19            zoom,
20            chip8: c,
21        }
22    }
23    fn draw_graphics(&mut self) {
24        // TODO
25    }
26    fn set_keys(&mut self) {
27        // TODO
28    }
29}
30
31fn main() {
32    let matches = App::new("chip8-rs")
33        .version("0.0.1")
34        .about("chip8 emulator")
35        .arg(
36            Arg::with_name("file")
37                .short("f")
38                .long("file")
39                .takes_value(true)
40                .help("File path of the rom to load"),
41        )
42        .get_matches();
43    let file = matches.value_of("file");
44    let file = match file {
45        Some(file) => file,
46        _ => panic!("Please specify file path of the rom to load"),
47    };
48    println!("{:?}", file);
49
50    let mut e = SdlEmulator::new(64, 32, 8);
51    loop {
52        e.chip8.emulate_cycle();
53        if e.chip8.draw_flag {
54            e.draw_graphics();
55        }
56        e.set_keys();
57        // delay
58    }
59}