feat(cpu): implement format 1 THUMB instructions

This commit is contained in:
2022-01-29 01:37:50 -04:00
parent 995633e9e8
commit d85e0c8d05
2 changed files with 36 additions and 0 deletions

28
src/cpu/thumb/format1.zig Normal file
View File

@@ -0,0 +1,28 @@
const std = @import("std");
const Bus = @import("../../Bus.zig");
const Arm7tdmi = @import("../../cpu.zig").Arm7tdmi;
const InstrFn = @import("../../cpu.zig").ThumbInstrFn;
const shifter = @import("../arm/barrel_shifter.zig");
pub fn format1(comptime op: u2, comptime offset: u5) InstrFn {
return struct {
fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void {
const rs = opcode >> 3 & 0x7;
const rd = opcode & 0x7;
const result = switch (op) {
0b00 => shifter.logicalLeft(true, &cpu.cpsr, cpu.r[rs], offset),
0b01 => shifter.logicalRight(true, &cpu.cpsr, cpu.r[rs], offset),
0b10 => shifter.arithmeticRight(true, &cpu.cpsr, cpu.r[rs], offset),
else => std.debug.panic("{} is an invalid op for Format 1 THUMB Instructions", .{op}),
};
cpu.r[rd] = result;
// Instructions of this type are equivalent to a MOVS
cpu.cpsr.n.write(result >> 31 & 1 == 1);
cpu.cpsr.z.write(result == 0);
}
}.inner;
}