From d714ffb4f99fe822388416fb33ececbebfb3f13b Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:04 -0300 Subject: [PATCH] chore: account for THUMB BL instruction when mimicking mGBA logs --- src/cpu.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cpu.zig b/src/cpu.zig index 30704f2..305a95b 100644 --- a/src/cpu.zig +++ b/src/cpu.zig @@ -272,7 +272,14 @@ pub const Arm7tdmi = struct { var log_str: []u8 = undefined; if (self.cpsr.t.read()) { - log_str = try std.fmt.bufPrint(&buf, thumb_fmt, .{ r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, c_psr, opcode }); + if (opcode >> 11 == 0x1E) { + // Instruction 1 of a BL Opcode, print in ARM mode + const tmp_opcode = self.bus.read32(self.r[15] - 2); + const be_opcode = tmp_opcode << 16 | tmp_opcode >> 16; + log_str = try std.fmt.bufPrint(&buf, arm_fmt, .{ r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, c_psr, be_opcode }); + } else { + log_str = try std.fmt.bufPrint(&buf, thumb_fmt, .{ r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, c_psr, opcode }); + } } else { log_str = try std.fmt.bufPrint(&buf, arm_fmt, .{ r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, c_psr, opcode }); }