From 7013389288af421920609a7c4b582f64c1dd61e7 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:09 -0300 Subject: [PATCH] feat(cpu): implement format 18 THUMB instructions --- src/cpu.zig | 5 +++++ src/cpu/thumb/format18.zig | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/cpu/thumb/format18.zig diff --git a/src/cpu.zig b/src/cpu.zig index ba873a7..05b2c7f 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; @@ -472,6 +473,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; +}