From 37bd6758fb72547766118f3d0e67823b9c722db0 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 14 Jan 2022 04:08:04 -0400 Subject: [PATCH] fix(cpu): fix imm value calculation in MSR --- src/cpu/psr_transfer.zig | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cpu/psr_transfer.zig b/src/cpu/psr_transfer.zig index b080c6c..a2d2bb9 100644 --- a/src/cpu/psr_transfer.zig +++ b/src/cpu/psr_transfer.zig @@ -24,15 +24,13 @@ pub fn psrTransfer(comptime I: bool, comptime isSpsr: bool) InstrFn { switch (@truncate(u3, opcode >> 16)) { 0b000 => { - const right = if (I) std.math.rotr(u32, opcode & 0xFF, opcode >> 8 & 0xF) else cpu.r[rm]; + const right = if (I) std.math.rotr(u32, opcode & 0xFF, opcode >> 7 & 0xF) else cpu.r[rm]; if (isSpsr) { std.debug.panic("[CPU] TODO: MSR (flags only) on SPSR_ is unimplemented", .{}); } else { - cpu.cpsr.n.write(right >> 31 & 1 == 1); - cpu.cpsr.z.write(right >> 30 & 1 == 1); - cpu.cpsr.c.write(right >> 29 & 1 == 1); - cpu.cpsr.v.write(right >> 28 & 1 == 1); + const mask: u32 = 0xF000_0000; + cpu.cpsr.raw = (cpu.cpsr.raw & ~mask) | (right & mask); } }, 0b001 => {