From 22cab0210be4e777756ddca6a0f79b8ac6c8a0ca Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 12 Jan 2022 06:26:10 -0400 Subject: [PATCH] fix(cpu): make LDRH and STRH aware of r15 --- src/cpu/half_signed_data_transfer.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cpu/half_signed_data_transfer.zig b/src/cpu/half_signed_data_transfer.zig index 7ad507b..b46565f 100644 --- a/src/cpu/half_signed_data_transfer.zig +++ b/src/cpu/half_signed_data_transfer.zig @@ -13,7 +13,13 @@ pub fn halfAndSignedDataTransfer(comptime P: bool, comptime U: bool, comptime I: const rm = opcode & 0xF; const imm_offset_high = opcode >> 8 & 0xF; - const base = cpu.r[rn]; + var base: u32 = undefined; + if (rn == 0xF) { + base = cpu.fakePC(); + if (!L) base += 4; + } else { + base = cpu.r[rn]; + } var offset: u32 = undefined; if (I) { @@ -33,7 +39,8 @@ pub fn halfAndSignedDataTransfer(comptime P: bool, comptime U: bool, comptime I: }, 0b01 => { // LDRH - cpu.r[rd] = bus.read16(address); + const value = bus.read16(address & 0xFFFE); + cpu.r[rd] = std.math.rotr(u32, @as(u32, value), 8 * (address & 1)); }, 0b10 => { // LDRSB