feat(cpu): implement format 12 thumb instructions

This commit is contained in:
2022-01-17 10:07:50 -04:00
parent ea5f0ce552
commit 2a416fb2c6
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;
}