From 7dbd2fc556b60c80ac0e85d23e7a6f65005752b8 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:10 -0300 Subject: [PATCH] fix(cpu): account for rn in rlist in block data transfer --- src/cpu/arm/block_data_transfer.zig | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/cpu/arm/block_data_transfer.zig b/src/cpu/arm/block_data_transfer.zig index bc4209c..bdc70da 100644 --- a/src/cpu/arm/block_data_transfer.zig +++ b/src/cpu/arm/block_data_transfer.zig @@ -11,34 +11,39 @@ pub fn blockDataTransfer(comptime P: bool, comptime U: bool, comptime S: bool, c const rn = opcode >> 16 & 0xF; const base = cpu.r[rn]; - var address: u32 = undefined; + const in_list = opcode >> @truncate(u4, rn) & 1 == 1; + + var address: u32 = base; if (U) { // Increment - address = if (P) base + 4 else base; - var i: u5 = 0; while (i < 0x10) : (i += 1) { if (opcode >> i & 1 == 1) { + if (P) address += 4; transfer(cpu, bus, r15_present, i, address); - address += 4; + if (!P) address += 4; } } } else { // Decrement - address = if (P) base - 4 else base; var i: u5 = 0x10; while (i > 0) : (i -= 1) { const j = i - 1; if (opcode >> j & 1 == 1) { + if (P) address -= 4; transfer(cpu, bus, r15_present, j, address); - address -= 4; + if (!P) address -= 4; } } } - if (W and P or !P) cpu.r[rn] = if (U) address else address + 4; + if (W) { + if (!L or (L and !in_list)) { + cpu.r[rn] = address; + } + } } fn transfer(cpu: *Arm7tdmi, bus: *Bus, r15_present: bool, i: u5, address: u32) void {