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) {
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));
@ -233,14 +235,14 @@ impl CPU {
let pos_y = self.memory.get(0xFF4A);
// subtracting 7 to get the Real Number...
let pos_x = self.memory.get(0xFF4B);
self.render_tiles(
scanline,
&lcdc.window_tilemap,
&lcdc.tile_area,
palette,
self.render_tiles(
scanline,
&lcdc.window_tilemap,
&lcdc.tile_area,
palette,
pos_x.wrapping_sub(7),
pos_y,
false,
pos_y,
false,
);
}

View file

@ -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
}
}
}