// 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 = "WAI"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0xcb, .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, comptime widths: ?CPU.Widths, ) *const fn (*CPU) CPU.Opcodes.Error!void { if (addressing_mode != .Implied) @compileError("illegal addressing mode"); _ = widths; const f = struct { /// Stops until something interrupts. What happens then depends on whether interrupts are enabled: either the handler runs, or the processor simply carries on with the next instruction, which is the useful half — it is how a program waits for a scanline or a key without burning the bus. pub fn WAI(cpu: *CPU) !void { cpu.program_counter.internal(); cpu.program_counter.internal(); cpu.waiting = true; // And then it lets go of the bus, which is the point: a // waiting processor is not fetching anything, so anything // else on the bus may have it. cpu.memory.letGo(); } }; return f.WAI; } }; }