From 14cbfd4112f2a6fa92efb04f704f7e87905c739a Mon Sep 17 00:00:00 2001 From: John Date: Tue, 25 Jun 2024 21:21:57 -0500 Subject: [PATCH] bugfix: `bit r8, n` should return true when bit n is zero --- src/cpu.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cpu.rs b/src/cpu.rs index 8c0ad08..b073b03 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -687,9 +687,9 @@ mod instructions { *self.flags_mut() = Flags::new().with_z(value == 0).with_c(value & 1 > 0); Ok(()) } - /// Tests whether the given bit of r8 is set + /// Tests whether the given bit of r8 is zero pub fn bit(&mut self, reg: R8, bit: u8, bus: &impl BusIO) -> Result<(), Error> { - let value = self.get_r8(reg, bus) & (1 << bit) == 1; + let value = self.get_r8(reg, bus) & (1 << bit) == 0; self.set_z(value).set_n(false).set_h(true); Ok(()) } @@ -699,6 +699,7 @@ mod instructions { self.set_r8(reg, value & !(1 << bit), bus); Ok(()) } + /// Sets the given bit of the given register to 1 pub fn set(&mut self, reg: R8, bit: u8, bus: &mut impl BusIO) -> Result<(), Error> { let value = self.get_r8(reg, bus); self.set_r8(reg, value | 1 << bit, bus);