keypress interrupts
This commit is contained in:
parent
96af4b94a1
commit
615446faa7
|
@ -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));
|
||||||
|
@ -233,14 +235,14 @@ impl CPU {
|
||||||
let pos_y = self.memory.get(0xFF4A);
|
let pos_y = self.memory.get(0xFF4A);
|
||||||
// subtracting 7 to get the Real Number...
|
// subtracting 7 to get the Real Number...
|
||||||
let pos_x = self.memory.get(0xFF4B);
|
let pos_x = self.memory.get(0xFF4B);
|
||||||
self.render_tiles(
|
self.render_tiles(
|
||||||
scanline,
|
scanline,
|
||||||
&lcdc.window_tilemap,
|
&lcdc.window_tilemap,
|
||||||
&lcdc.tile_area,
|
&lcdc.tile_area,
|
||||||
palette,
|
palette,
|
||||||
pos_x.wrapping_sub(7),
|
pos_x.wrapping_sub(7),
|
||||||
pos_y,
|
pos_y,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue