chip8-rs/src/main.rs
src/main.rsRaw
1extern crate sdl2;
2
3use sdl2::pixels::Color;
4use sdl2::render::Canvas;
5
6use clap::{App, Arg};
7
8use chip8::Chip8;
9
10struct SdlEmulator {
11 w: usize,
12 h: usize,
13 zoom: usize,
14 canvas: Canvas<sdl2::video::Window>,
15 chip8: Chip8,
16}
17
18impl SdlEmulator {
19 fn new(w: usize, h: usize, zoom: usize) -> SdlEmulator {
20 let mut c = Chip8::new();
21
22 let sdl_context = sdl2::init().unwrap();
23 let video_subsystem = sdl_context.video().unwrap();
24
25 let window = video_subsystem
26 .window("rust-sdl2 demo", 800, 600)
27 .position_centered()
28 .build()
29 .unwrap();
30
31 let mut canvas = window.into_canvas().build().unwrap();
32
33 SdlEmulator {
34 w,
35 h,
36 zoom,
37 canvas,
38 chip8: c,
39 }
40 }
41 fn draw_graphics(&mut self) {
42 // TODO
43 }
44 fn set_keys(&mut self) {
45 // TODO
46 }
47}
48
49fn main() {
50 let matches = App::new("chip8-rs")
51 .version("0.0.1")
52 .about("chip8 emulator")
53 .arg(
54 Arg::with_name("file")
55 .short("f")
56 .long("file")
57 .takes_value(true)
58 .help("File path of the rom to load"),
59 )
60 .get_matches();
61 let file = matches.value_of("file");
62 let file = match file {
63 Some(file) => file,
64 _ => panic!("Please specify file path of the rom to load"),
65 };
66 println!("{:?}", file);
67
68 let mut e = SdlEmulator::new(64, 32, 8);
69 loop {
70 e.chip8.emulate_cycle();
71 if e.chip8.draw_flag {
72 e.draw_graphics();
73 }
74 e.set_keys();
75 // delay
76 }
77}