fix(joypad): fix bug where gameboy overwrites read only bits
This commit is contained in:
parent
4abb2833c4
commit
5a59c31b72
|
@ -243,7 +243,7 @@ impl Bus {
|
|||
0xFF00..=0xFF7F => {
|
||||
// IO Registers
|
||||
match addr {
|
||||
0xFF00 => self.joypad.status = byte.into(),
|
||||
0xFF00 => self.joypad.status.update(byte),
|
||||
0xFF01 => self.serial.next = byte,
|
||||
0xFF02 => self.serial.control = byte.into(),
|
||||
0xFF04 => self.timer.divider = 0x00,
|
||||
|
|
|
@ -27,6 +27,16 @@ bitfield! {
|
|||
from into ButtonState, right_a, _set_right_a: 0, 0;
|
||||
}
|
||||
|
||||
impl JoypadStatus {
|
||||
pub(crate) fn update(&mut self, byte: u8) {
|
||||
let action_row = (byte >> 5) & 0x01;
|
||||
let direction_row = (byte >> 4) & 0x01;
|
||||
|
||||
self.set_action_row(action_row.into());
|
||||
self.set_direction_row(direction_row.into());
|
||||
}
|
||||
}
|
||||
|
||||
impl JoypadStatus {
|
||||
pub fn set_down_start(&mut self, state: ButtonState, int: &mut bool) {
|
||||
if !(*int) {
|
||||
|
@ -74,12 +84,6 @@ impl Clone for JoypadStatus {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<u8> for JoypadStatus {
|
||||
fn from(byte: u8) -> Self {
|
||||
Self(byte)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JoypadStatus> for u8 {
|
||||
fn from(status: JoypadStatus) -> Self {
|
||||
status.0
|
||||
|
|
Loading…
Reference in New Issue