mfw overflowing_add

This commit is contained in:
Lea 2023-01-25 19:12:14 +01:00
parent 5be0da1a90
commit 1398de8181
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

View file

@ -48,8 +48,8 @@ pub fn dad(register: Register, state: &mut EmulatorState) {
_ => panic!("Cannot perform DAD on register {:?}", register), _ => panic!("Cannot perform DAD on register {:?}", register),
}; };
let result = num as u32 + u16::from_le_bytes([state.l, state.h]) as u32; let (result, overflow) = num.overflowing_add(u16::from_le_bytes([state.l, state.h]));
state.cc.c = result > 0xffff; state.cc.c = overflow;
state.h = (result >> 8) as u8; state.h = (result >> 8) as u8;
state.l = result as u8; state.l = result as u8;
} }