diff --git a/src/cpu.zig b/src/cpu.zig index 67360cb..2dfa5ad 100644 --- a/src/cpu.zig +++ b/src/cpu.zig @@ -33,6 +33,7 @@ const format13 = @import("cpu/thumb/format13.zig").format13; const format14 = @import("cpu/thumb/format14.zig").format14; const format15 = @import("cpu/thumb/format15.zig").format15; const format16 = @import("cpu/thumb/format16.zig").format16; +const format18 = @import("cpu/thumb/format18.zig").format18; const format19 = @import("cpu/thumb/format19.zig").format19; pub const ArmInstrFn = fn (*Arm7tdmi, *Bus, u32) void; @@ -452,6 +453,10 @@ fn thumbPopulate() [0x400]ThumbInstrFn { lut[i] = format16(cond); } + if (i >> 5 & 0x1F == 0b11100) { + lut[i] = format18(); + } + if (i >> 6 & 0xF == 0b1111) { const is_low = i >> 5 & 1 == 1; diff --git a/src/cpu/thumb/format18.zig b/src/cpu/thumb/format18.zig new file mode 100644 index 0000000..e8a3139 --- /dev/null +++ b/src/cpu/thumb/format18.zig @@ -0,0 +1,15 @@ +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 format18() InstrFn { + return struct { + fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void { + const offset = u32SignExtend(11, opcode & 0x7FF) << 1; + cpu.r[15] = (cpu.r[15] + 2) +% offset; + } + }.inner; +}