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);