a little bit of fixing

This commit is contained in:
Alex Janka 2023-02-12 14:05:50 +11:00
parent d7a60d1c97
commit a3dfec659a

View file

@ -208,13 +208,6 @@ impl Memory {
self.io[addr_l] = data;
} else {
match address {
0xFF02 => {
if data == 0x81 {
print!("{}", self.get(0xFF01) as char);
stdout().flush().unwrap();
}
}
0xFF04 => self.io[addr_l] = 0,
0xFF00 => {
// joypad
if !get_bit(data, 5) {
@ -224,13 +217,26 @@ impl Memory {
self.joypad.bank_sel = JoypadBank::Direction
}
}
0xFF02 => {
if data == 0x81 {
print!("{}", self.get(0xFF01) as char);
stdout().flush().unwrap();
}
}
0xFF04 => self.io[addr_l] = 0,
0xFF07 => {
self.masked_io(addr_l, data, 0b111);
}
0xFF0F => {
self.masked_io(addr_l, data, 0b11111);
}
0xFF11 | 0xFF14 | 0xFF16 | 0xFF19 | 0xFF1E | 0xFF23 | 0xFF26 => {
// sound
self.io[addr_l] = data;
}
0xFF41 => {
// mixed read/write
self.io[addr_l] = (self.io[addr_l] & 0b00000111) | (data & 0b11111000)
self.masked_io(addr_l, data, 0b01111000);
}
0xFF4D | 0xFF56 => {
// cgb only
@ -259,6 +265,10 @@ impl Memory {
}
}
fn masked_io(&mut self, addr_l: usize, data: u8, mask: u8) {
self.io[addr_l] = (self.io[addr_l] & (!mask)) | (data & mask);
}
pub fn update_pressed_keys(&mut self, keys: Vec<Key>) -> bool {
let old = self.joypad;
self.joypad.down = keys.contains(&Key::Down) || keys.contains(&Key::S);