From c82f00c88b35013f96ba8a308a49e4622f6e42cf Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Thu, 2 Feb 2023 11:07:09 +1100 Subject: [PATCH] fix carry instruction flags --- src/processor/instructions/primitives.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/processor/instructions/primitives.rs b/src/processor/instructions/primitives.rs index d3fbd8c..9582333 100644 --- a/src/processor/instructions/primitives.rs +++ b/src/processor/instructions/primitives.rs @@ -44,18 +44,24 @@ impl CPU { rotated += get_rotation_carry(&direction); 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; } 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); - if old_carry > 0 { + if old_carry { rotated += get_rotation_carry(&direction); } if 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; }