From 1b9ab1f1d729eb0d30c5fbeec486acd5068297fb Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sat, 5 Feb 2022 23:08:47 -0400 Subject: [PATCH] fix: implement the same LDRSH logic as THUMB LDRSH --- src/cpu/arm/half_signed_data_transfer.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cpu/arm/half_signed_data_transfer.zig b/src/cpu/arm/half_signed_data_transfer.zig index ba97d62..e30570a 100644 --- a/src/cpu/arm/half_signed_data_transfer.zig +++ b/src/cpu/arm/half_signed_data_transfer.zig @@ -45,7 +45,13 @@ pub fn halfAndSignedDataTransfer(comptime P: bool, comptime U: bool, comptime I: }, 0b11 => { // LDRSH - result = util.u32SignExtend(16, bus.read16(address & 0xFFFF_FFFE)); + const value = if (address & 1 == 1) blk: { + break :blk util.u32SignExtend(8, bus.read8(address)); + } else blk: { + break :blk util.u32SignExtend(16, bus.read16(address)); + }; + + result = std.math.rotr(u32, value, 8 * (address & 1)); }, 0b00 => unreachable, // SWP }