// 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 = "RTI"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x40, .addressing_mode = .Implied, .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) *const fn (*CPU) error{}!void { if (addressing_mode != .Implied) @compileError("illegal addressing mode"); const f = struct { /// Returns from an interrupt, pulling the status register and /// then the program counter, which unlike RTS's was pushed /// ready to use. /// /// (MOS Technology, 1976, Section 9.6, p. 132) /// (Carr, 1984, p. 270) pub fn RTI(cpu: *CPU) error{}!void { // the discarded operand fetch, then the discarded read // of the stack slot the pointer is sitting on before it // moves cpu.program_counter.phantomRead(); cpu.stack.phantomRead(); cpu.flags.restore(cpu.stack.pop(u8)); cpu.program_counter.value = cpu.stack.pop(u16); } }; return f.RTI; } }; }