From 798987eba0a9953ca7909dbf602368d6dab21262 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sat, 5 Feb 2022 23:29:34 -0400 Subject: [PATCH] chore: improve arm ldm/stm --- src/cpu/arm/block_data_transfer.zig | 10 +++++++--- src/cpu/thumb/block_data_transfer.zig | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cpu/arm/block_data_transfer.zig b/src/cpu/arm/block_data_transfer.zig index bdc70da..16aaded 100644 --- a/src/cpu/arm/block_data_transfer.zig +++ b/src/cpu/arm/block_data_transfer.zig @@ -9,11 +9,14 @@ pub fn blockDataTransfer(comptime P: bool, comptime U: bool, comptime S: bool, c fn inner(cpu: *Arm7tdmi, bus: *Bus, opcode: u32) void { const r15_present = opcode >> 15 & 1 == 1; const rn = opcode >> 16 & 0xF; - const base = cpu.r[rn]; + var address: u32 = cpu.r[rn]; - const in_list = opcode >> @truncate(u4, rn) & 1 == 1; + if (opcode & 0xFFFF == 0) { + if (L) cpu.r[15] = bus.read32(address) else bus.write32(address, cpu.r[15] + 8); + cpu.r[rn] += 0x40; + return; + } - var address: u32 = base; if (U) { // Increment var i: u5 = 0; @@ -40,6 +43,7 @@ pub fn blockDataTransfer(comptime P: bool, comptime U: bool, comptime S: bool, c } if (W) { + const in_list = opcode >> @truncate(u4, rn) & 1 == 1; if (!L or (L and !in_list)) { cpu.r[rn] = address; } diff --git a/src/cpu/thumb/block_data_transfer.zig b/src/cpu/thumb/block_data_transfer.zig index 7d9ae2a..098d344 100644 --- a/src/cpu/thumb/block_data_transfer.zig +++ b/src/cpu/thumb/block_data_transfer.zig @@ -54,7 +54,7 @@ pub fn format15(comptime L: bool, comptime rb: u3) InstrFn { const end_address = cpu.r[rb] + 4 * countRlist(opcode); if (opcode & 0xFF == 0) { - if (L) cpu.r[15] = bus.read32(address) else bus.write32(address, cpu.r[15] + 4); // TODO: Why is this r[15] + 4? + if (L) cpu.r[15] = bus.read32(address) else bus.write32(address, cpu.r[15] + 4); cpu.r[rb] += 0x40; return; }