diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 4c47172..a49fa6f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,12 +4,20 @@ use sdl2::pixels::Color; use sdl2::event::Event; use sdl2::keyboard::Keycode; use std::time::Duration; -use sdl2::rect::Rect; use chip8::Chip; +use std::env; pub fn main() { + //new chip struct + let args: Vec<String> = env::args().collect(); + if args.len() != 2 { panic!("Incorrect format; please pass a single rom file as a parameter"); } let mut chip = Chip::new(); + chip.init(); + chip.read_rom(args[1].as_str()); + + + //SDL initalizationa and window creation let sdl_context = sdl2::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); let window = video_subsystem.window("CHIP-8", chip8::WIDTH * chip8::SCALE, chip8::HEIGHT * chip8::SCALE) @@ -17,9 +25,12 @@ pub fn main() { .build() .unwrap(); + //Canvas to interact with let mut canvas = window.into_canvas().build().unwrap(); + //Keyboard input handler let mut event_pump = sdl_context.event_pump().unwrap(); + //Main loop called 'running', checks for keyboard input and renders the display grid 'running: loop { for event in event_pump.poll_iter() { match event { @@ -31,10 +42,15 @@ pub fn main() { } } // The rest of the game loop goes here... + //Draw black bg canvas.set_draw_color(Color::RGB(0, 0, 0)); + //clear the screen with black bg canvas.clear(); + //choose white color canvas.set_draw_color(Color::RGB(255, 255, 255)); - canvas.fill_rects(chip.render()); + //render all the rectangles as white pixels on the canvas + canvas.fill_rects(chip.render()).unwrap(); + //display canvas canvas.present(); std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60)); |