derives + set stat properly + joypad improvements

This commit is contained in:
Alex Janka 2023-02-09 10:05:13 +11:00
parent ac6c2afd10
commit d5efdd6084

View file

@ -10,11 +10,13 @@ pub(crate) mod rom;
pub(crate) type Address = u16;
#[derive(Debug)]
enum JoypadBank {
Action,
Direction,
}
#[derive(Debug)]
struct Joypad {
bank_sel: JoypadBank,
down: bool,
@ -32,6 +34,7 @@ impl Joypad {
let mut reg = 0xFF;
match self.bank_sel {
JoypadBank::Action => {
reg = clear_bit(reg, 5);
if self.start {
reg = clear_bit(reg, 3);
}
@ -46,6 +49,7 @@ impl Joypad {
}
}
JoypadBank::Direction => {
reg = clear_bit(reg, 4);
if self.down {
reg = clear_bit(reg, 3);
}
@ -242,14 +246,15 @@ impl Memory {
}
0xFF11 | 0xFF14 | 0xFF16 | 0xFF19 | 0xFF1E | 0xFF23 | 0xFF26 => {
// sound
self.io[addr_l] = data;
}
0xFF41 => {
// mixed read/write addresses...
// need to fill these out more...
// just seeing what breaks...
// mixed read/write
self.io[addr_l] = self.io[addr_l] | (data & 0b1111000)
}
0xFF4D | 0xFF56 => {
// cgb only
self.io[addr_l] = data;
}
0xFF44 | 0xFF76 | 0xFF77 => {
// read-only addresses