keypress interrupts

This commit is contained in:
Alex Janka 2023-02-09 17:30:38 +11:00
parent 96af4b94a1
commit 615446faa7
2 changed files with 16 additions and 11 deletions

View file

@ -147,7 +147,9 @@ impl CPU {
} }
fn enter_vblank(&mut self) { fn enter_vblank(&mut self) {
self.memory.update_pressed_keys(self.window.get_keys()); if self.memory.update_pressed_keys(self.window.get_keys()) {
self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 4));
}
self.gpu.mode = DrawMode::VBlank; self.gpu.mode = DrawMode::VBlank;
self.render_window(); self.render_window();
self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 0)); self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 0));

View file

@ -12,13 +12,13 @@ pub(crate) mod rom;
pub(crate) type Address = u16; pub(crate) type Address = u16;
#[derive(Debug)] #[derive(Debug, Clone, Copy, PartialEq)]
enum JoypadBank { enum JoypadBank {
Action, Action,
Direction, Direction,
} }
#[derive(Debug)] #[derive(Debug, Clone, Copy, PartialEq)]
struct Joypad { struct Joypad {
bank_sel: JoypadBank, bank_sel: JoypadBank,
down: bool, down: bool,
@ -275,7 +275,8 @@ impl Memory {
} }
} }
pub fn update_pressed_keys(&mut self, keys: Vec<Key>) { pub fn update_pressed_keys(&mut self, keys: Vec<Key>) -> bool {
let old = self.joypad.clone();
self.joypad.down = keys.contains(&Key::Down) || keys.contains(&Key::S); self.joypad.down = keys.contains(&Key::Down) || keys.contains(&Key::S);
self.joypad.up = keys.contains(&Key::Up) || keys.contains(&Key::W); self.joypad.up = keys.contains(&Key::Up) || keys.contains(&Key::W);
self.joypad.left = keys.contains(&Key::Left) || keys.contains(&Key::A); self.joypad.left = keys.contains(&Key::Left) || keys.contains(&Key::A);
@ -284,5 +285,7 @@ impl Memory {
self.joypad.select = keys.contains(&Key::Minus); self.joypad.select = keys.contains(&Key::Minus);
self.joypad.a = keys.contains(&Key::Apostrophe); self.joypad.a = keys.contains(&Key::Apostrophe);
self.joypad.b = keys.contains(&Key::Semicolon); self.joypad.b = keys.contains(&Key::Semicolon);
self.joypad != old
}
} }
} }