From 43d011538e7eee0ab81ffa06e94ba86950ad57bf Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:11:59 -0300 Subject: [PATCH] feat(cpu): implement ADC ADC interacting w/ the Barrel Shifter is not working though --- src/cpu/arm/data_processing.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cpu/arm/data_processing.zig b/src/cpu/arm/data_processing.zig index 4f05ca1..f648d56 100644 --- a/src/cpu/arm/data_processing.zig +++ b/src/cpu/arm/data_processing.zig @@ -54,6 +54,22 @@ pub fn dataProcessing(comptime I: bool, comptime S: bool, comptime instrKind: u4 cpu.cpsr.v.write(((op1 ^ result) & (op2 ^ result)) >> 31 & 1 == 1); } }, + 0x5 => { + // ADC + const carry = @boolToInt(cpu.cpsr.c.read()); + var result: u32 = undefined; + + const did = @addWithOverflow(u32, op1, op2, &result); + const overflow = @addWithOverflow(u32, result, carry, &result); + cpu.r[rd] = result; + + if (S and rd != 0xF) { + cpu.cpsr.n.write(result >> 31 & 1 == 1); + cpu.cpsr.z.write(result == 0); + cpu.cpsr.c.write(did or overflow); + cpu.cpsr.v.write(((op1 ^ result) & (op2 ^ result)) >> 31 & 1 == 1); + } + }, 0x8 => { // TST const result = op1 & op2;