From 8cabcd8901c51c4708a6d2005027431e16b2d219 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 4 Jan 2022 01:57:37 -0600 Subject: [PATCH] fix(cpu): resolve reversed if statement + write back on W = 0 --- src/cpu/single_data_transfer.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpu/single_data_transfer.zig b/src/cpu/single_data_transfer.zig index bdea0b7..2febda2 100644 --- a/src/cpu/single_data_transfer.zig +++ b/src/cpu/single_data_transfer.zig @@ -13,7 +13,7 @@ pub fn comptimeSingleDataTransfer(comptime I: bool, comptime P: bool, comptime U const rd = opcode >> 12 & 0xF; const base = cpu.r[rn]; - const offset = if (I) opcode & 0xFFF else registerOffset(cpu, opcode); + const offset = if (I) registerOffset(cpu, opcode) else opcode & 0xFFF; const modified_base = if (U) base + offset else base - offset; var address = if (P) modified_base else base; @@ -40,7 +40,7 @@ pub fn comptimeSingleDataTransfer(comptime I: bool, comptime P: bool, comptime U } address = modified_base; - if (W and P) cpu.r[rn] = address; + if (W and P or !W) cpu.r[rn] = address; // TODO: W-bit forces non-privledged mode for the transfer }