feat: pass thumb.gba

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-07-03 08:44:48 -03:00
parent e17e9fb703
commit e694110fbd
4 changed files with 29 additions and 26 deletions

View File

@ -67,39 +67,31 @@ pub fn dataProcessing(comptime I: bool, comptime S: bool, comptime instrKind: u4
}, },
0x8 => { 0x8 => {
// TST // TST
if (rd == 0xF) { if (rd == 0xF)
undefinedTestBehaviour(cpu); return undefinedTestBehaviour(cpu);
return;
}
const result = op1 & op2; const result = op1 & op2;
setTestOpFlags(S, cpu, opcode, result); setTestOpFlags(S, cpu, opcode, result);
}, },
0x9 => { 0x9 => {
// TEQ // TEQ
if (rd == 0xF) { if (rd == 0xF)
undefinedTestBehaviour(cpu); return undefinedTestBehaviour(cpu);
return;
}
const result = op1 ^ op2; const result = op1 ^ op2;
setTestOpFlags(S, cpu, opcode, result); setTestOpFlags(S, cpu, opcode, result);
}, },
0xA => { 0xA => {
// CMP // CMP
if (rd == 0xF) { if (rd == 0xF)
undefinedTestBehaviour(cpu); return undefinedTestBehaviour(cpu);
return;
}
cmp(cpu, op1, op2); cmp(cpu, op1, op2);
}, },
0xB => { 0xB => {
// CMN // CMN
if (rd == 0xF) { if (rd == 0xF)
undefinedTestBehaviour(cpu); return undefinedTestBehaviour(cpu);
return;
}
cmn(cpu, op1, op2); cmn(cpu, op1, op2);
}, },

View File

@ -33,7 +33,8 @@ pub fn format14(comptime L: bool, comptime R: bool) InstrFn {
if (R) { if (R) {
if (L) { if (L) {
const value = bus.read(u32, address); const value = bus.read(u32, address);
cpu.r[15] = value & 0xFFFF_FFFE; cpu.r[15] = value & ~@as(u32, 1);
cpu.pipe.flush();
} else { } else {
bus.write(u32, address, cpu.r[14]); bus.write(u32, address, cpu.r[14]);
} }
@ -52,7 +53,13 @@ pub fn format15(comptime L: bool, comptime rb: u3) InstrFn {
const end_address = cpu.r[rb] + 4 * countRlist(opcode); const end_address = cpu.r[rb] + 4 * countRlist(opcode);
if (opcode & 0xFF == 0) { if (opcode & 0xFF == 0) {
if (L) cpu.r[15] = bus.read(u32, address) else bus.write(u32, address, cpu.r[15] + 4); if (L) {
cpu.r[15] = bus.read(u32, address);
cpu.pipe.flush();
} else {
bus.write(u32, address, cpu.r[15] + 2);
}
cpu.r[rb] += 0x40; cpu.r[rb] += 0x40;
return; return;
} }

View File

@ -99,14 +99,13 @@ pub fn format3(comptime op: u2, comptime rd: u3) InstrFn {
}.inner; }.inner;
} }
pub fn format12(comptime isSP: bool, comptime rd: u3) InstrFn { pub fn format12(comptime SP: bool, comptime rd: u3) InstrFn {
return struct { return struct {
fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void { fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void {
// ADD // ADD
const left = if (isSP) cpu.r[13] else (cpu.r[15] + 2) & 0xFFFF_FFFD; const left = if (SP) cpu.r[13] else cpu.r[15] & ~@as(u32, 2);
const right = (opcode & 0xFF) << 2; const right = (opcode & 0xFF) << 2;
const result = left + right; cpu.r[rd] = left + right;
cpu.r[rd] = result;
} }
}.inner; }.inner;
} }

View File

@ -11,19 +11,22 @@ pub fn format5(comptime op: u2, comptime h1: u1, comptime h2: u1) InstrFn {
const src_idx = @as(u4, h2) << 3 | (opcode >> 3 & 0x7); const src_idx = @as(u4, h2) << 3 | (opcode >> 3 & 0x7);
const dst_idx = @as(u4, h1) << 3 | (opcode & 0x7); const dst_idx = @as(u4, h1) << 3 | (opcode & 0x7);
const src = if (src_idx == 0xF) (cpu.r[src_idx] + 2) & 0xFFFF_FFFE else cpu.r[src_idx]; const src_mask = if (src_idx == 0xF) ~@as(u32, 1) else ~@as(u32, 0);
const dst = if (dst_idx == 0xF) (cpu.r[dst_idx] + 2) & 0xFFFF_FFFE else cpu.r[dst_idx]; const dst_mask = if (dst_idx == 0xF) ~@as(u32, 1) else ~@as(u32, 0);
const src = cpu.r[src_idx] & src_mask;
const dst = cpu.r[dst_idx] & dst_mask;
switch (op) { switch (op) {
0b00 => { 0b00 => {
// ADD // ADD
const sum = add(false, cpu, dst, src); const sum = add(false, cpu, dst, src);
cpu.r[dst_idx] = if (dst_idx == 0xF) sum & 0xFFFF_FFFE else sum; cpu.r[dst_idx] = sum & dst_mask;
}, },
0b01 => cmp(cpu, dst, src), // CMP 0b01 => cmp(cpu, dst, src), // CMP
0b10 => { 0b10 => {
// MOV // MOV
cpu.r[dst_idx] = if (dst_idx == 0xF) src & 0xFFFF_FFFE else src; cpu.r[dst_idx] = src & dst_mask;
}, },
0b11 => { 0b11 => {
// BX // BX
@ -32,6 +35,8 @@ pub fn format5(comptime op: u2, comptime h1: u1, comptime h2: u1) InstrFn {
cpu.pipe.flush(); cpu.pipe.flush();
}, },
} }
if (dst_idx == 0xF) cpu.pipe.flush();
} }
}.inner; }.inner;
} }