// 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 = "PEI"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0xd4, .addressing_mode = .Stack, .cycles = 6, }, }; /// 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 { /// Pushes the word the direct page operand points at, which is how a pointer already in the direct page is handed on. pub fn PEI(cpu: *CPU) !void { const address = cpu.addressing_modes.decode(.@"Direct Page", .read); cpu.stack.push(u16, .unconfined, cpu.addressing_modes.readData(.@"Direct Page", u16, address)); } }; return f.PEI; } }; }