From df4e6f91be136f18b734f3d6e16421b2610c9f75 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 13 Nov 2017 13:20:08 -0500 Subject: ... --- src/main.rs | 21 +++++++++++++++++++-- 1 file 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 + canvas: RefCell, + events: RefCell, } 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 { -- cgit v1.2.3-70-g09d2