chore: progress towards working pipeline

focus on THMB branching and a little bit of ARM data processing
This commit is contained in:
2022-07-02 04:45:34 -03:00
parent d279c4c519
commit 45f65ce877
6 changed files with 23 additions and 32 deletions

View File

@@ -11,8 +11,7 @@ pub fn branch(comptime L: bool) InstrFn {
fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u32) void {
if (L) cpu.r[14] = cpu.r[15] - 4;
const offset = sext(u32, u24, opcode) << 2;
cpu.r[15] = cpu.r[15] +% offset;
cpu.r[15] +%= sext(u32, u24, opcode) << 2;
cpu.pipe.flush();
}
}.inner;
@@ -21,13 +20,8 @@ pub fn branch(comptime L: bool) InstrFn {
pub fn branchAndExchange(cpu: *Arm7tdmi, _: *Bus, opcode: u32) void {
const rn = opcode & 0xF;
if (cpu.r[rn] & 1 == 1) {
cpu.r[15] = cpu.r[rn] & ~@as(u32, 1);
cpu.cpsr.t.set();
} else {
cpu.r[15] = cpu.r[rn] & ~@as(u32, 3);
cpu.cpsr.t.unset();
}
const thumb = cpu.r[rn] & 1 == 1;
cpu.r[15] = cpu.r[rn] & if (thumb) ~@as(u32, 1) else ~@as(u32, 3);
cpu.cpsr.t.write(thumb);
cpu.pipe.flush();
}

View File

@@ -15,8 +15,7 @@ pub fn dataProcessing(comptime I: bool, comptime S: bool, comptime instrKind: u4
// If certain conditions are met, PC is 12 ahead instead of 8
// TODO: What are these conditions? I can't remember
if (!I and opcode >> 4 & 1 == 1) cpu.r[15] += 4;
const op1 = if (rn == 0xF) cpu.fakePC() else cpu.r[rn];
const op1 = cpu.r[rn];
var op2: u32 = undefined;
if (I) {

View File

@@ -14,13 +14,8 @@ pub fn singleDataTransfer(comptime I: bool, comptime P: bool, comptime U: bool,
const rn = opcode >> 16 & 0xF;
const rd = opcode >> 12 & 0xF;
var base: u32 = undefined;
if (rn == 0xF) {
base = cpu.fakePC();
if (!L) base += 4; // Offset of 12
} else {
base = cpu.r[rn];
}
// If L is set, there is an offset of 12 from the instruction to the PC
const base = cpu.r[rn] + if (!L) 4 else @as(u32, 0);
const offset = if (I) shifter.immShift(false, cpu, opcode) else opcode & 0xFFF;