diff options
author | Determinant <[email protected]> | 2017-11-13 13:20:08 -0500 |
---|---|---|
committer | Determinant <[email protected]> | 2017-11-13 13:20:08 -0500 |
commit | df4e6f91be136f18b734f3d6e16421b2610c9f75 (patch) | |
tree | 80f14f341557721935d9ec8e400a8615cd002d1e | |
parent | 4c599c84bda48401069a6d46163c6aef972c26a2 (diff) |
...
-rw-r--r-- | src/main.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 9e54547..112261d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,8 @@ extern crate sdl2; use sdl2::pixels::Color; use sdl2::rect::Rect; +use sdl2::event::Event; +use sdl2::keyboard::Keycode; struct Window { buff: RefCell<[[u8; 256]; 240]> @@ -37,7 +39,8 @@ impl ppu::Screen for Window { } struct SDLWindow { - canvas: RefCell<sdl2::render::WindowCanvas> + canvas: RefCell<sdl2::render::WindowCanvas>, + events: RefCell<sdl2::EventPump>, } impl SDLWindow { @@ -54,9 +57,22 @@ impl SDLWindow { canvas.clear(); canvas.present(); SDLWindow { - canvas: RefCell::new(canvas) + canvas: RefCell::new(canvas), + events: RefCell::new(sdl_context.event_pump().unwrap()) } } + + fn poll(&self) -> bool { + for event in self.events.borrow_mut().poll_iter() { + match event { + Event::Quit {..} | Event::KeyDown { keycode: Some(Keycode::Escape), .. } => { + return true; + }, + _ => () + } + } + false + } } const PIXEL_SIZE: u32 = 2; @@ -169,6 +185,7 @@ fn main() { mem.init(&mut cpu, &mut ppu); loop { + if win.poll() {break} cpu.step(); //println!("cpu at 0x{:04x}", cpu.get_pc()); while cpu.cycle > 0 { |