// 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 = "STP"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0xdb, .addressing_mode = .Implied, .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) *const fn (*CPU) error{}!void { if (addressing_mode != .Implied) @compileError("illegal addressing mode"); const f = struct { /// Stops until reset. /// /// Not a halt in the sense the NMOS part's undocumented jams /// were, which were a processor left fetching the same byte /// for ever: this one stops the clock, and a machine built /// around it draws almost nothing until the reset line moves. /// /// The corpus has nothing to say about this one either, for /// the same reason as WAI. pub fn STP(cpu: *CPU) error{}!void { // Two discarded fetches, and then it is not fetching any // more. cpu.program_counter.phantomRead(); cpu.program_counter.phantomRead(); cpu.stopped = true; } }; return f.STP; } }; }