Skip to content
Snippets Groups Projects
Verified Commit d2c32c9d authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: added joypad int

parent 74b14bc6
No related branches found
No related tags found
1 merge request!6Window drawing support 🪟
Pipeline #979 passed
......@@ -90,6 +90,7 @@ impl Cpu {
if ((self.mmu.ie & 0x01 == 0x01) && self.mmu.ppu().int_vblank())
|| ((self.mmu.ie & 0x02 == 0x02) && self.mmu.ppu().int_stat())
|| ((self.mmu.ie & 0x04 == 0x04) && self.mmu.timer().int_tima())
|| ((self.mmu.ie & 0x10 == 0x10) && self.mmu.pad().int_pad())
{
self.halted = false;
}
......@@ -154,6 +155,26 @@ impl Cpu {
self.halted = false;
}
return 20;
}
// @todo aggregate the handling of these interrupts
else if (self.mmu.ie & 0x10 == 0x10) && self.mmu.pad().int_pad() {
debugln!("Going to run JoyPad interrupt handler (0x60)");
self.disable_int();
self.push_word(pc);
self.pc = 0x60;
// acknowledges that the pad interrupt has been
// properly handled
self.mmu.pad().ack_pad();
// in case the CPU is currently halted waiting
// for an interrupt, releases it
if self.halted {
self.halted = false;
}
return 20;
}
}
......
......@@ -110,7 +110,9 @@ impl Mmu {
0xf00 => match addr & 0x00ff {
0x0f => {
let value = if self.ppu.int_vblank() { 0x01 } else { 0x00 }
| if self.timer.int_tima() { 0x04 } else { 0x00 };
| if self.ppu.int_stat() { 0x02 } else { 0x00 }
| if self.timer.int_tima() { 0x04 } else { 0x00 }
| if self.pad.int_pad() { 0x10 } else { 0x00 };
value
}
0x80..=0xfe => self.ppu.hram[(addr & 0x007f) as usize],
......@@ -181,6 +183,7 @@ impl Mmu {
self.ppu.set_int_vblank(value & 0x01 == 0x01);
self.ppu.set_int_stat(value & 0x02 == 0x02);
self.timer.set_int_tima(value & 0x04 == 0x04);
self.pad.set_int_pad(value & 0x10 == 0x10);
}
0x80..=0xfe => self.ppu.hram[(addr & 0x007f) as usize] = value,
0xff => self.ie = value,
......
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;
pub struct Pad {
down: bool,
up: bool,
left: bool,
right: bool,
start: bool,
select: bool,
b: bool,
a: bool,
selection: PadSelection,
}
#[derive(Clone, Copy, PartialEq)]
pub enum PadSelection {
Action,
......@@ -31,6 +19,19 @@ pub enum PadKey {
B,
}
pub struct Pad {
down: bool,
up: bool,
left: bool,
right: bool,
start: bool,
select: bool,
b: bool,
a: bool,
selection: PadSelection,
int_pad: bool
}
impl Pad {
pub fn new() -> Self {
Self {
......@@ -43,6 +44,7 @@ impl Pad {
b: false,
a: false,
selection: PadSelection::Action,
int_pad: false,
}
}
......@@ -103,6 +105,10 @@ impl Pad {
PadKey::A => self.a = true,
PadKey::B => self.b = true,
}
// signals that a JoyPad interrupt is pending to be
// handled as a key pressed has been done
self.int_pad = true;
}
pub fn key_lift(&mut self, key: PadKey) {
......@@ -117,4 +123,16 @@ impl Pad {
PadKey::B => self.b = false,
}
}
pub fn int_pad(&self) -> bool {
self.int_pad
}
pub fn set_int_pad(&mut self, value: bool) {
self.int_pad = value;
}
pub fn ack_pad(&mut self) {
self.set_int_pad(false);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment