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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445// 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 = "XBA"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0xeb, .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 { /// Swaps the two halves of the accumulator, which is how the hidden one is reached. The flags come from what ends up in the low half, eight bits of it whatever M says. pub fn XBA(cpu: *CPU) !void { const value = cpu.registers.get(.A); const swapped = value >> 8 | value << 8; cpu.registers.set(.A, swapped); cpu.flags.updateNZ(u8, @truncate(swapped)); // Two cycles of the chip's own, not one: swapping the // halves is work, and it is done in the second. cpu.program_counter.internal(); cpu.program_counter.internal(); } }; return f.XBA; } };}