From 6575eb5531aa749e1143fe4f7b0ae06c73bf91c7 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 5 May 2021 19:23:01 -0500 Subject: [PATCH] chore(bus): ensure no read-only bits are overwritten by the cpu --- src/joypad.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/joypad.rs b/src/joypad.rs index f926172..b6fea58 100644 --- a/src/joypad.rs +++ b/src/joypad.rs @@ -29,11 +29,11 @@ bitfield! { impl JoypadStatus { pub(crate) fn update(&mut self, byte: u8) { - let action_row = (byte >> 5) & 0x01; - let direction_row = (byte >> 4) & 0x01; + // Bytes 3 -> 0 are Read Only + let mask = 0b00001111; - self.set_action_row(action_row.into()); - self.set_direction_row(direction_row.into()); + let read_only = self.0 & mask; + self.0 = (byte & !mask) | read_only; } }