// 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 = "BRK"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x00, .addressing_mode = .Stack, .cycles = 7, }, }; /// 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, comptime widths: ?CPU.Widths, ) *const fn (*CPU) CPU.Opcodes.Error!void { if (addressing_mode != .Stack) @compileError("illegal addressing mode"); _ = widths; const f = struct { /// Breaks to the handler, by software rather than by a line going low. pub fn BRK(cpu: *CPU) !void { // The byte after the opcode is fetched and thrown away. // It is there so that the handler can read it back off the // stack and find out which call this was, which is the // whole point of a software interrupt having a signature. _ = cpu.program_counter.read(u8); cpu.interrupt(.brk); } }; return f.BRK; } }; }