feat(cpu): implement some already decoded format 3 instructions

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-01-17 09:29:11 -04:00
parent e55d2dc323
commit ea5f0ce552
1 changed files with 19 additions and 2 deletions

View File

@ -11,16 +11,33 @@ pub fn format3(comptime op: u2, comptime rd: u3) InstrFn {
switch (op) { switch (op) {
0b00 => { 0b00 => {
// MOV
cpu.r[rd] = offset; cpu.r[rd] = offset;
cpu.cpsr.n.unset(); cpu.cpsr.n.unset();
cpu.cpsr.z.write(offset == 0); cpu.cpsr.z.write(offset == 0);
}, },
0b01 => { 0b01 => {
std.debug.panic("TODO: Implement cmp R{}, #0x{X:0>2}", .{ rd, offset }); // CMP
const left = cpu.r[rd];
const result = left -% offset;
cpu.cpsr.n.write(result >> 31 & 1 == 1);
cpu.cpsr.z.write(result == 0);
cpu.cpsr.c.write(offset <= left);
cpu.cpsr.v.write(((left ^ result) & (~offset ^ result)) >> 31 & 1 == 1);
}, },
0b10 => { 0b10 => {
std.debug.panic("TODO: Implement add R{}, #0x{X:0>2}", .{ rd, offset }); const left = cpu.r[rd];
var result: u32 = undefined;
const didOverflow = @addWithOverflow(u32, left, offset, &result);
cpu.r[rd] = result;
cpu.cpsr.n.write(result >> 31 & 1 == 1);
cpu.cpsr.z.write(result == 0);
cpu.cpsr.c.write(didOverflow);
cpu.cpsr.v.write(((left ^ result) & (offset ^ result)) >> 31 & 1 == 1);
}, },
0b11 => { 0b11 => {
std.debug.panic("TODO: Implement sub R{}, #0x{X:0>2}", .{ rd, offset }); std.debug.panic("TODO: Implement sub R{}, #0x{X:0>2}", .{ rd, offset });