feat(cpu): implement format 12 thumb instructions

This commit is contained in:
2022-10-21 05:11:57 -03:00
parent 2fb01577af
commit daad98bbfe
2 changed files with 24 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
const std = @import("std");
const Bus = @import("../../Bus.zig");
const Arm7tdmi = @import("../../cpu.zig").Arm7tdmi;
const InstrFn = @import("../../cpu.zig").ThumbInstrFn;
pub fn format12(comptime isSP: bool, comptime rd: u3) InstrFn {
return struct {
fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void {
const left = if (isSP) cpu.r[13] else cpu.r[15] + 2 & 0xFFFF_FFFD; // fetch (+2)
const right = @truncate(u10, opcode & 0xFF) << 2;
const result = left + right; // TODO: What about overflows?
cpu.r[rd] = result;
}
}.inner;
}