Something went wrong. Try again.
A cycle-accurate Apple II and Apple IIgs emulator written in Zig, usable as both a program and a library.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>//// 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 = "SBX"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0xcb, .addressing_mode = .Immediate, .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 != .Immediate) @compileError("illegal addressing mode"); const f = struct { /// Puts the accumulator ANDed with X, minus an immediate, /// into X. pub fn SBX(cpu: *CPU) error{}!void { const value = cpu.memory.read(u8, cpu.addressing_modes.decode(addressing_mode, .read)); const register = cpu.registers.get(.A) & cpu.registers.get(.X); // the subtraction goes through the comparator rather than // the adder, so it ignores both carry in and decimal mode cpu.flags.update(.C, register >= value); const result = register -% value; cpu.registers.set(.X, result); cpu.flags.updateNZ(result); } }; return f.SBX; } };}