From 4e6735bb5c94811a9b0d4bc105b58cf0751d2daa Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Fri, 15 May 2020 16:08:56 +0300 Subject: [PATCH] Fix gba-suite arm test #207 Arm Data-Processing instruction was not initializign `self.bs_carry_out` before activating the barrel-shifter. Current ARM7 is too much spaghetti for me to handle anymore, maybe time for some refactoring. Former-commit-id: b21fe75496ccd89611fc56f5f00e885532c5ff20 Former-commit-id: 5b11f640d306ebc2afb95d76a3dd3e1530a87c36 --- rustboyadvance-core/src/arm7tdmi/alu.rs | 3 +++ rustboyadvance-core/src/arm7tdmi/arm/exec.rs | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rustboyadvance-core/src/arm7tdmi/alu.rs b/rustboyadvance-core/src/arm7tdmi/alu.rs index e31414f..d114326 100644 --- a/rustboyadvance-core/src/arm7tdmi/alu.rs +++ b/rustboyadvance-core/src/arm7tdmi/alu.rs @@ -223,6 +223,9 @@ impl Core { carry_in: bool, immediate: bool, ) -> u32 { + // TODO get rid of Core::bs_carry_out field in favour sending the carry as a &mut reference, + // Forcing calling functions to do something with the carry : + self.bs_carry_out = carry_in; // // From GBATEK: // Zero Shift Amount (Shift Register by Immediate, with Immediate=0) diff --git a/rustboyadvance-core/src/arm7tdmi/arm/exec.rs b/rustboyadvance-core/src/arm7tdmi/arm/exec.rs index cff3beb..50fb107 100644 --- a/rustboyadvance-core/src/arm7tdmi/arm/exec.rs +++ b/rustboyadvance-core/src/arm7tdmi/arm/exec.rs @@ -193,19 +193,20 @@ impl Core { let rn = raw_insn.bit_range(16..20) as usize; let rd = raw_insn.bit_range(12..16) as usize; - let mut op1 = if rn == REG_PC { insn.pc + 8 } else { self.get_reg(rn) }; - let mut s_flag = insn.set_cond_flag(); let opcode = insn.opcode(); let op2 = if raw_insn.bit(25) { let immediate = raw_insn & 0xff; let rotate = 2 * raw_insn.bit_range(8..12); + // TODO refactor out + let bs_carry_in = self.cpsr.C(); + self.bs_carry_out = bs_carry_in; self.ror(immediate, rotate, self.cpsr.C(), false, true) } else { let reg = raw_insn & 0xf;