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.
12345678910111213141516171819202122232425262728293031323334353637383940414243// 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 = "RTL"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x6b, .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 { _ = widths; const f = struct { /// Comes back from a subroutine anywhere, taking the bank off the stack too. pub fn RTL(cpu: *CPU) !void { if (addressing_mode != .Stack) @compileError("illegal addressing mode"); cpu.program_counter.internal(); cpu.program_counter.internal(); const address = cpu.stack.pop(u16, .unconfined); const bank = cpu.stack.pop(u8, .unconfined); cpu.registers.program_bank = bank; cpu.program_counter.jump(address +% 1); } }; return f.RTL; } };}