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 = "PER"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x62, .addressing_mode = .Stack, .cycles = 6, }, };
/// 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 != .Stack) @compileError("illegal addressing mode"); _ = widths; const f = struct { /// Pushes an address worked out from where the instruction is: the signed word after the opcode, added to what the program counter holds afterwards. Position-independent code is what this is for. pub fn PER(cpu: *CPU) !void { const started = cpu.program_counter.value; const displacement = cpu.program_counter.read(u16); // The cycle spent adding keeps the last operand byte's // address on the bus, as every other one here does, and // stays inside the bank while it is at it. cpu.memory.internal(cpu.program_counter.addressOf(started +% 1)); cpu.stack.push(u16, .unconfined, cpu.program_counter.value +% displacement); } }; return f.PER; } };}