keypress interrupts
This commit is contained in:
parent
96af4b94a1
commit
615446faa7
|
@ -147,7 +147,9 @@ impl CPU {
|
|||
}
|
||||
|
||||
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.render_window();
|
||||
self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 0));
|
||||
|
|
|
@ -12,13 +12,13 @@ pub(crate) mod rom;
|
|||
|
||||
pub(crate) type Address = u16;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
enum JoypadBank {
|
||||
Action,
|
||||
Direction,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
struct Joypad {
|
||||
bank_sel: JoypadBank,
|
||||
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.up = keys.contains(&Key::Up) || keys.contains(&Key::W);
|
||||
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.a = keys.contains(&Key::Apostrophe);
|
||||
self.joypad.b = keys.contains(&Key::Semicolon);
|
||||
self.joypad != old
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue