From 1398de818129e6d8eb0a826708e15dfc18383a1c Mon Sep 17 00:00:00 2001 From: Lea Date: Wed, 25 Jan 2023 19:12:14 +0100 Subject: [PATCH] mfw overflowing_add --- src/emulator/instructions/arithmetic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; }