From 3cb92ad809f15ee619df2844f4b0a6dedd8421cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Thu, 7 Jul 2022 17:20:34 +0100 Subject: [PATCH] fix: issues related to WASM --- examples/sdl/src/main.rs | 32 +++++++++++++++++++------------- src/inst.rs | 6 ------ src/ppu.rs | 11 +++++++---- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index d9abec78..2c916122 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -118,12 +118,18 @@ fn main() { Event::KeyDown { keycode: Some(keycode), .. - } => game_boy.key_press(key_to_pad(keycode)), + } => match key_to_pad(keycode) { + Some(key) => game_boy.key_press(key), + None => (), + }, Event::KeyUp { keycode: Some(keycode), .. - } => game_boy.key_lift(key_to_pad(keycode)), + } => match key_to_pad(keycode) { + Some(key) => game_boy.key_lift(key), + None => (), + }, _ => (), } @@ -160,17 +166,17 @@ fn main() { } } -fn key_to_pad(keycode: Keycode) -> PadKey { +fn key_to_pad(keycode: Keycode) -> Option<PadKey> { match keycode { - Keycode::Up => PadKey::Up, - Keycode::Down => PadKey::Down, - Keycode::Left => PadKey::Left, - Keycode::Right => PadKey::Right, - Keycode::Return => PadKey::Start, - Keycode::Return2 => PadKey::Start, - Keycode::Space => PadKey::Select, - Keycode::A => PadKey::A, - Keycode::S => PadKey::B, - _ => PadKey::A, //@todo this does not make sence, make it an Option + Keycode::Up => Some(PadKey::Up), + Keycode::Down => Some(PadKey::Down), + Keycode::Left => Some(PadKey::Left), + Keycode::Right => Some(PadKey::Right), + Keycode::Return => Some(PadKey::Start), + Keycode::Return2 => Some(PadKey::Start), + Keycode::Space => Some(PadKey::Select), + Keycode::A => Some(PadKey::A), + Keycode::S => Some(PadKey::B), + _ => None, } } diff --git a/src/inst.rs b/src/inst.rs index 4062d8d2..5f4df2cf 100644 --- a/src/inst.rs +++ b/src/inst.rs @@ -555,12 +555,6 @@ pub const EXTENDED: [(fn(&mut Cpu), u8, &'static str); 256] = [ fn nop(_cpu: &mut Cpu) {} -fn noimpl(_cpu: &mut Cpu) { - let ten_millis = time::Duration::from_millis(10000); - thread::sleep(ten_millis); // @todo remove this hack - todo!("Instruction not implemented"); -} - fn illegal(_cpu: &mut Cpu) { panic!("Illegal instruction"); } diff --git a/src/ppu.rs b/src/ppu.rs index 86e9f0d7..9152939b 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -58,15 +58,18 @@ impl Tile { self.buffer[y * TILE_WIDTH + x] = value; } - pub fn get_row(&self, y: usize) -> &[u8] { - &self.buffer[y * TILE_WIDTH..(y + 1) * TILE_WIDTH] - } - pub fn buffer(&self) -> Vec<u8> { self.buffer.to_vec() } } +impl Tile { + pub fn get_row(&self, y: usize) -> &[u8] { + &self.buffer[y * TILE_WIDTH..(y + 1) * TILE_WIDTH] + } +} + + impl Tile { pub fn palette_buffer(&self, palette: Palette) -> Vec<u8> { self.buffer -- GitLab