// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie // // SPDX-License-Identifier: MIT /// Describes one instruction: its mnemonic, and every opcode that selects /// it together with that opcode's addressing mode and cycle count. Opcodes /// collects these at comptime to build the dispatch table. pub fn data(comptime CPU: type) type { return struct { pub const mnemonic = "BRA"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x80, .addressing_mode = .Relative, .cycles = 3, }, }; /// The implementation for a single addressing mode. Resolved at /// comptime so the dispatch table holds a plain function pointer with /// no mode left to branch on at runtime. pub fn func(comptime addressing_mode: CPU.AddressingModes) *const fn (*CPU) error{}!void { if (addressing_mode != .Relative) @compileError("illegal addressing mode"); const f = struct { /// Branches, whatever the flags say. /// /// The NMOS part had a branch for each way each flag could be, /// and no way to say "always" in two bytes: a jump is three. /// This is the CMOS part's answer, and it is what makes code /// written for one shorter than the same code written for the /// other. pub fn BRA(cpu: *CPU) error{}!void { const address = cpu.addressing_modes.decode(addressing_mode, .read); cpu.program_counter.branch(address); } }; return f.BRA; } }; }