// 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 = "INX"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0xe8, .addressing_mode = .Implied, .cycles = 2, }, }; /// 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) CPU.Opcodes.Error!void { if (addressing_mode != .Implied) @compileError("illegal addressing mode"); const f = struct { /// Increments the X register by one. /// /// (MOS Technology, 1976, Section 7.4, p. 97) /// (Carr, 1984, p. 260) pub fn INX(cpu: *CPU) CPU.Opcodes.Error!void { const value = cpu.registers.get(.X) +% 1; cpu.registers.set(.X, value); cpu.flags.updateNZ(value); // the operand fetch every single byte instruction performs // and discards cpu.program_counter.phantomRead(); } }; return f.INX; } }; }