feat(cpu): implement format19 THUMB instructions

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-01-29 18:25:27 -04:00
parent 0c49bf2288
commit 4ca65caef0
2 changed files with 32 additions and 0 deletions

View File

@ -26,6 +26,7 @@ const format5 = @import("cpu/thumb/format5.zig").format5;
const format6 = @import("cpu/thumb/format6.zig").format6; const format6 = @import("cpu/thumb/format6.zig").format6;
const format12 = @import("cpu/thumb/format12.zig").format12; const format12 = @import("cpu/thumb/format12.zig").format12;
const format16 = @import("cpu/thumb/format16.zig").format16; const format16 = @import("cpu/thumb/format16.zig").format16;
const format19 = @import("cpu/thumb/format19.zig").format19;
pub const ArmInstrFn = fn (*Arm7tdmi, *Bus, u32) void; pub const ArmInstrFn = fn (*Arm7tdmi, *Bus, u32) void;
pub const ThumbInstrFn = fn (*Arm7tdmi, *Bus, u16) void; pub const ThumbInstrFn = fn (*Arm7tdmi, *Bus, u16) void;
@ -365,6 +366,12 @@ fn thumbPopulate() [0x400]ThumbInstrFn {
lut[i] = format16(cond); lut[i] = format16(cond);
} }
if (i >> 6 & 0xF == 0b1111) {
const is_low = i >> 5 & 1 == 1;
lut[i] = format19(is_low);
}
} }
return lut; return lut;

View File

@ -0,0 +1,25 @@
const std = @import("std");
const Bus = @import("../../Bus.zig");
const Arm7tdmi = @import("../../cpu.zig").Arm7tdmi;
const InstrFn = @import("../../cpu.zig").ThumbInstrFn;
const u32SignExtend = @import("../../util.zig").u32SignExtend;
pub fn format19(comptime is_low: bool) InstrFn {
return struct {
fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void {
const offset = opcode & 0x3FF;
if (is_low) {
// Instruction 2
const old_pc = cpu.r[15];
cpu.r[15] = cpu.r[14] + (offset << 1);
cpu.r[14] = old_pc | 1;
} else {
// Instruction 1
cpu.r[14] = (cpu.fakePC() & 0xFFFF_FFFC) + (u32SignExtend(11, @as(u32, offset)) << 12);
}
}
}.inner;
}