From 34233fa654f83bb7b2091c9190807b933c571e61 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Tue, 9 Jul 2019 01:29:34 +0300 Subject: [PATCH] alu: Fix bug in SBC and RSC ops Former-commit-id: 1cb23d6280e1816395c46a7571dd9f48df870202 --- 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 8b8cb3c..b71f80b 100644 --- a/src/arm7tdmi/alu.rs +++ b/src/arm7tdmi/alu.rs @@ -239,7 +239,7 @@ impl Core { fn alu_add_flags(a: i32, b: i32, carry: &mut bool, overflow: &mut bool) -> i32 { let res = a.wrapping_add(b) as u32; - *carry = res < a as u32|| res < b as u32; + *carry = res < a as u32 || res < b as u32; let (_, would_overflow) = a.overflowing_add(b); *overflow = would_overflow; res as i32 @@ -267,8 +267,8 @@ impl Core { RSB => Self::alu_sub_flags(op2, op1, &mut carry, &mut overflow), ADD | CMN => Self::alu_add_flags(op1, op2, &mut carry, &mut overflow), ADC => Self::alu_add_flags(op1, op2.wrapping_add(C), &mut carry, &mut overflow), - SBC => Self::alu_sub_flags(op1, op2.wrapping_sub(1 - C), &mut carry, &mut overflow), - RSC => Self::alu_sub_flags(op2, op1.wrapping_sub(1 - C), &mut carry, &mut overflow), + SBC => Self::alu_sub_flags(op1, op2, &mut carry, &mut overflow).wrapping_sub(1 - C), + RSC => Self::alu_sub_flags(op2, op1, &mut carry, &mut overflow).wrapping_sub(1 - C), ORR => op1 | op2, MOV => op2, BIC => op1 & (!op2),