fix(cpu): account for r15 in LDR and STR instructions

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-01-12 06:16:59 -04:00
parent 98c5803208
commit 5812b9713c
1 changed files with 10 additions and 4 deletions

View File

@ -13,7 +13,14 @@ pub fn singleDataTransfer(comptime I: bool, comptime P: bool, comptime U: bool,
const rn = opcode >> 16 & 0xF; const rn = opcode >> 16 & 0xF;
const rd = opcode >> 12 & 0xF; const rd = opcode >> 12 & 0xF;
const base = cpu.r[rn]; var base: u32 = undefined;
if (rn == 0xF) {
base = cpu.fakePC();
if (!L) base += 4; // Offset of 12
} else {
base = cpu.r[rn];
}
const offset = if (I) registerOffset(cpu, opcode) else opcode & 0xFFF; const offset = if (I) registerOffset(cpu, opcode) else opcode & 0xFFF;
const modified_base = if (U) base + offset else base - offset; const modified_base = if (U) base + offset else base - offset;
@ -25,9 +32,8 @@ pub fn singleDataTransfer(comptime I: bool, comptime P: bool, comptime U: bool,
cpu.r[rd] = bus.read8(address); cpu.r[rd] = bus.read8(address);
} else { } else {
// LDR // LDR
const value = bus.read32(address & 0xFFFF_FFFC);
// FIXME: Unsure about how I calculate the boundary offset cpu.r[rd] = std.math.rotr(u32, value, 8 * (address & 0x3));
cpu.r[rd] = std.math.rotl(u32, bus.read32(address), address % 4);
} }
} else { } else {
if (B) { if (B) {