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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344// 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 = "PLA"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x68, .addressing_mode = .Implied, .cycles = 4, }, };
/// 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) CPU.Opcodes.Error!void { if (addressing_mode != .Implied) @compileError("illegal addressing mode"); const f = struct { /// Pulls the accumulator off the stack. /// /// (MOS Technology, 1976, Section 8.6, p. 118) /// (Carr, 1984, p. 268) pub fn PLA(cpu: *CPU) !void { // the discarded operand fetch, then the discarded read // of the stack slot the pointer is sitting on before it // moves cpu.program_counter.phantomRead(); cpu.stack.phantomRead(); const value = cpu.stack.pop(u8); cpu.registers.set(.A, value); cpu.flags.updateNZ(value); } }; return f.PLA; } };}