From f9e7128061b3ee4b3a76564a48f99cc147384766 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:18 -0300 Subject: [PATCH] fix: properly decode format 11 instructions --- src/cpu.zig | 2 +- src/cpu/thumb/block_data_transfer.zig | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cpu.zig b/src/cpu.zig index 688bae8..1cf426e 100644 --- a/src/cpu.zig +++ b/src/cpu.zig @@ -496,7 +496,7 @@ fn thumbPopulate() [0x400]ThumbInstrFn { }, 0b001 => blk: { const L = i >> 5 & 1 == 1; - const rd = i >> 2 & 0x3; + const rd = i >> 2 & 0x7; break :blk format11(L, rd); }, 0b010 => blk: { diff --git a/src/cpu/thumb/block_data_transfer.zig b/src/cpu/thumb/block_data_transfer.zig index 975623d..62789de 100644 --- a/src/cpu/thumb/block_data_transfer.zig +++ b/src/cpu/thumb/block_data_transfer.zig @@ -5,12 +5,12 @@ const InstrFn = @import("../../cpu.zig").ThumbInstrFn; pub fn format14(comptime L: bool, comptime R: bool) InstrFn { return struct { fn inner(cpu: *Arm7tdmi, bus: *Bus, opcode: u16) void { - const count = countRlist(opcode); - const start = cpu.r[13] - if (!L) 4 * (@boolToInt(R) + count) else 0; + const count = @boolToInt(R) + countRlist(opcode); + const start = cpu.r[13] - if (!L) count * 4 else 0; var end = cpu.r[13]; if (L) { - end += 4 * (@boolToInt(R) + count); + end += count * 4; } else { end -= 4; } @@ -40,7 +40,7 @@ pub fn format14(comptime L: bool, comptime R: bool) InstrFn { address += 4; } - cpu.r[13] = if (L) end else cpu.r[13] - 4 * (@boolToInt(R) + count); + cpu.r[13] = if (L) end else start; } }.inner; }