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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051// 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 = "JSL"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x22, .addressing_mode = .@"Absolute Long", .cycles = 8, }, };
/// 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 { /// Calls a subroutine anywhere, leaving the bank on the stack as well as the address. pub fn JSL(cpu: *CPU) !void { if (addressing_mode != .@"Absolute Long") @compileError("illegal addressing mode"); const low: u24 = cpu.program_counter.read(u16); // The bank goes on the stack before the last operand byte // is even fetched, which is the odd shape of this // instruction and not something to tidy up. const pushed_at = cpu.stack.raw; cpu.stack.push(u8, .unconfined, cpu.registers.program_bank); // The cycle after that push is spent with the stack on the // bus rather than the counter, and at the slot just // written rather than the next one down. cpu.memory.internal(pushed_at); const bank: u8 = cpu.program_counter.read(u8); cpu.stack.push(u16, .unconfined, cpu.program_counter.value -% 1); cpu.registers.program_bank = bank; cpu.program_counter.jump(@truncate(low)); } }; return f.JSL; } };}