From 6ddb13685238be54926cdc0501e23dcb74c3f1a3 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Tue, 9 Jul 2019 00:39:35 +0300 Subject: [PATCH] alu: Also fix carry detection for unsigned addition Former-commit-id: d405f885e2b54c23aef5faab86cc1da681bd05ec --- src/arm7tdmi/alu.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arm7tdmi/alu.rs b/src/arm7tdmi/alu.rs index ce2a2a1..8b8cb3c 100644 --- a/src/arm7tdmi/alu.rs +++ b/src/arm7tdmi/alu.rs @@ -238,11 +238,11 @@ impl Core { } fn alu_add_flags(a: i32, b: i32, carry: &mut bool, overflow: &mut bool) -> i32 { - let res = a.wrapping_add(b); - *carry = res < a; + let res = a.wrapping_add(b) as u32; + *carry = res < a as u32|| res < b as u32; let (_, would_overflow) = a.overflowing_add(b); *overflow = would_overflow; - res + res as i32 } #[allow(non_snake_case)]