feat(cpu): implement format 10 THUMB instructions

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-02-01 17:56:11 -04:00
parent 85927a943f
commit ca41f6a85c
2 changed files with 32 additions and 0 deletions

View File

@ -27,6 +27,7 @@ const format4 = @import("cpu/thumb/format4.zig").format4;
const format5 = @import("cpu/thumb/format5.zig").format5; 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 format9 = @import("cpu/thumb/format9.zig").format9; 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 format12 = @import("cpu/thumb/format12.zig").format12;
const format13 = @import("cpu/thumb/format13.zig").format13; const format13 = @import("cpu/thumb/format13.zig").format13;
const format14 = @import("cpu/thumb/format14.zig").format14; const format14 = @import("cpu/thumb/format14.zig").format14;
@ -373,6 +374,13 @@ fn thumbPopulate() [0x400]ThumbInstrFn {
lut[i] = format6(rd); 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) { if (i >> 7 & 0x7 == 0b011) {
const B = i >> 6 & 1 == 1; const B = i >> 6 & 1 == 1;
const L = i >> 5 & 1 == 1; const L = i >> 5 & 1 == 1;

View File

@ -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;
}