// 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 = "SLO"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x03, .addressing_mode = .@"(Indirect, X)", .cycles = 8, }, .{ .opcode = 0x07, .addressing_mode = .@"Zero Page", .cycles = 5, }, .{ .opcode = 0x0f, .addressing_mode = .Absolute, .cycles = 6, }, .{ .opcode = 0x13, .addressing_mode = .@"(Indirect), Y", .cycles = 8, }, .{ .opcode = 0x17, .addressing_mode = .@"Zero Page, X", .cycles = 6, }, .{ .opcode = 0x1b, .addressing_mode = .@"Absolute, Y", .cycles = 7, }, .{ .opcode = 0x1f, .addressing_mode = .@"Absolute, X", .cycles = 7, }, }; /// 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 { const f = struct { /// An ASL of the addressed byte, with the result also ORed /// into the accumulator. pub fn SLO(cpu: *CPU) error{}!void { const address = cpu.addressing_modes.decode(addressing_mode, .write); const value = cpu.memory.read(u8, address); // a read-modify-write drives the unmodified value back onto // the bus before the modified one cpu.memory.write(u8, address, value); cpu.flags.update(.C, value & 0x80 == 0x80); const result = @shlExact(value & 0x7f, 1); cpu.memory.write(u8, address, result); const a = cpu.registers.get(.A) | result; cpu.registers.set(.A, a); cpu.flags.updateNZ(a); } }; return f.SLO; } }; }