// 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 = "SEI"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x78, .addressing_mode = .Implied, .cycles = 2, }, }; /// 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 { /// Sets the interrupt disable, masking interrupts. /// /// (MOS Technology, 1976, Section 3.2.1, p. 26) /// (Carr, 1984, p. 273) pub fn SEI(cpu: *CPU) error{}!void { cpu.flags.set(.I); // the operand fetch every single byte instruction performs // and discards cpu.program_counter.phantomRead(); } }; return f.SEI; } }; } test "SEI" { const std = @import("std"); const CPU = @import("../../cpu8.zig").Bare; var cpu: CPU = undefined; try cpu.init(null, null); cpu.flags.clear(.I); try cpu.memory.loadProgram(0x0000, &[_]u8{0x78}); const actual = try cpu.executeInstruction(); try std.testing.expectEqual({}, actual); try std.testing.expectEqual(@as(u16, 0x0001), cpu.program_counter.value); try std.testing.expectEqual(@as(usize, 2), cpu.clock.cycles); try std.testing.expect(cpu.flags.isClear(.N)); try std.testing.expect(cpu.flags.isClear(.V)); try std.testing.expect(cpu.flags.isClear(.B)); try std.testing.expect(cpu.flags.isClear(.D)); try std.testing.expect(cpu.flags.isSet(.I)); try std.testing.expect(cpu.flags.isSet(.Z)); try std.testing.expect(cpu.flags.isClear(.C)); }