diff --git a/src/emulator/instructions/arithmetic.rs b/src/emulator/instructions/arithmetic.rs index 6af8f5d..8b06d44 100644 --- a/src/emulator/instructions/arithmetic.rs +++ b/src/emulator/instructions/arithmetic.rs @@ -48,8 +48,8 @@ pub fn dad(register: Register, state: &mut EmulatorState) { _ => panic!("Cannot perform DAD on register {:?}", register), }; - let result = num as u32 + u16::from_le_bytes([state.l, state.h]) as u32; - state.cc.c = result > 0xffff; + let (result, overflow) = num.overflowing_add(u16::from_le_bytes([state.l, state.h])); + state.cc.c = overflow; state.h = (result >> 8) as u8; state.l = result as u8; }