From 96d7285111c7e6db4653742735c817724be4e516 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:08 -0300 Subject: [PATCH] feat(cpu): implement format 10 THUMB instructions --- src/cpu.zig | 8 ++++++++ src/cpu/thumb/format10.zig | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/cpu/thumb/format10.zig diff --git a/src/cpu.zig b/src/cpu.zig index 0374583..f2d6953 100644 --- a/src/cpu.zig +++ b/src/cpu.zig @@ -27,6 +27,7 @@ const format4 = @import("cpu/thumb/format4.zig").format4; const format5 = @import("cpu/thumb/format5.zig").format5; const format6 = @import("cpu/thumb/format6.zig").format6; const format9 = @import("cpu/thumb/format9.zig").format9; +const format10 = @import("cpu/thumb/format10.zig").format10; const format12 = @import("cpu/thumb/format12.zig").format12; const format13 = @import("cpu/thumb/format13.zig").format13; const format14 = @import("cpu/thumb/format14.zig").format14; @@ -373,6 +374,13 @@ fn thumbPopulate() [0x400]ThumbInstrFn { lut[i] = format6(rd); } + if (i >> 6 & 0xF == 0b1000) { + const L = i >> 5 & 1 == 1; + const offset = i & 0x1F; + + lut[i] = format10(L, offset); + } + if (i >> 7 & 0x7 == 0b011) { const B = i >> 6 & 1 == 1; const L = i >> 5 & 1 == 1; diff --git a/src/cpu/thumb/format10.zig b/src/cpu/thumb/format10.zig new file mode 100644 index 0000000..fef8198 --- /dev/null +++ b/src/cpu/thumb/format10.zig @@ -0,0 +1,24 @@ +const std = @import("std"); + +const Bus = @import("../../Bus.zig"); +const Arm7tdmi = @import("../../cpu.zig").Arm7tdmi; +const InstrFn = @import("../../cpu.zig").ThumbInstrFn; + +pub fn format10(comptime L: bool, comptime offset: u5) InstrFn { + return struct { + fn inner(cpu: *Arm7tdmi, bus: *Bus, opcode: u16) void { + const rb = opcode >> 3 & 0x7; + const rd = opcode & 0x7; + + const address = cpu.r[rb] + (offset << 1); + + if (L) { + // LDRH + cpu.r[rd] = bus.read16(address & 0xFFFF_FFFE); + } else { + // STRH + bus.write16(address & 0xFFFF_FFFE, @truncate(u16, cpu.r[rd])); + } + } + }.inner; +}