fix carry instruction flags

This commit is contained in:
Alex Janka 2023-02-02 11:07:09 +11:00
parent d73fbc827c
commit c82f00c88b

View file

@ -44,18 +44,24 @@ impl CPU {
rotated += get_rotation_carry(&direction); rotated += get_rotation_carry(&direction);
self.set_flag(Flags::Carry); self.set_flag(Flags::Carry);
} }
self.set_or_clear_flag(Flags::Zero, rotated == 0x0);
self.clear_flag(Flags::HalfCarry);
self.clear_flag(Flags::NSubtract);
return rotated; return rotated;
} }
pub(crate) fn rotate(&mut self, byte: u8, direction: Direction) -> u8 { pub(crate) fn rotate(&mut self, byte: u8, direction: Direction) -> u8 {
let old_carry = self.get_flag(Flags::Carry); let old_carry = self.is_flag(Flags::Carry);
let (mut rotated, carry) = rotate(byte, &direction); let (mut rotated, carry) = rotate(byte, &direction);
if old_carry > 0 { if old_carry {
rotated += get_rotation_carry(&direction); rotated += get_rotation_carry(&direction);
} }
if carry { if carry {
self.set_flag(Flags::Carry); self.set_flag(Flags::Carry);
} }
self.set_or_clear_flag(Flags::Zero, rotated == 0x0);
self.clear_flag(Flags::HalfCarry);
self.clear_flag(Flags::NSubtract);
return rotated; return rotated;
} }