From faced77161d5f81c0705eaef2b9ad5fee13ed730 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:11:47 -0300 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 }