// 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 = "PHY"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x5a, .addressing_mode = .Stack, .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, comptime widths: ?CPU.Widths, ) *const fn (*CPU) CPU.Opcodes.Error!void { if (addressing_mode != .Stack) @compileError("illegal addressing mode"); const f = struct { /// Pushes index register Y. pub fn PHY(cpu: *CPU) !void { if (comptime widths) |w| { if (comptime w.x) at(cpu, u8) else at(cpu, u16); } else { if (cpu.flags.isSet(.X)) at(cpu, u8) else at(cpu, u16); } } fn at(cpu: *CPU, comptime T: type) void { // The cycle before the push is the chip's own; the // push itself is one cycle a byte, high half first. cpu.program_counter.internal(); cpu.stack.push(T, .page_one, cpu.registers.getNarrow(.Y, T)); } }; return f.PHY; } }; }