From 46c694d95a478030d7f5a6b2003e01273d0daaa8 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:11:48 -0300 Subject: [PATCH] fix(cpu): properly implement SUB/CMP CSPSR carry bit condition --- src/cpu/data_processing.zig | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cpu/data_processing.zig b/src/cpu/data_processing.zig index a7ebb84..18fb0c5 100644 --- a/src/cpu/data_processing.zig +++ b/src/cpu/data_processing.zig @@ -33,17 +33,15 @@ pub fn comptimeDataProcessing(comptime I: bool, comptime S: bool, comptime instr }, 0xA => { // CMP - var result: u32 = undefined; - const op1_val = cpu.r[op1]; const v_ctx = (op1_val >> 31 == 0x01) or (op2 >> 31 == 0x01); - const didOverflow = @subWithOverflow(u32, op1_val, op2, &result); + const result = op1_val -% op2; - cpu.cpsr.v.write(v_ctx and (result >> 31 & 0x01 == 0x01)); - cpu.cpsr.c.write(didOverflow); - cpu.cpsr.z.write(result == 0x00); cpu.cpsr.n.write(result >> 31 & 0x01 == 0x01); + cpu.cpsr.z.write(result == 0x00); + cpu.cpsr.c.write(op2 <= op1_val); + cpu.cpsr.v.write(v_ctx and (result >> 31 & 0x01 == 0x01)); }, else => std.debug.panic("[CPU] TODO: implement data processing type {}", .{instrKind}), }