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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647// 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 = "BRL"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x82, .addressing_mode = .@"Relative Long", // Three when it is taken, and four when it is taken across a // page while emulating. A branch that is not taken is the // cheapest instruction there is. .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, comptime widths: ?CPU.Widths, ) *const fn (*CPU) CPU.Opcodes.Error!void { if (addressing_mode != .@"Relative Long") @compileError("illegal addressing mode"); _ = widths; const f = struct { /// Branches anywhere in the bank, always. A signed word rather than a signed byte, which is how position-independent code gets about without a jump. pub fn BRL(cpu: *CPU) !void { const displacement = cpu.program_counter.read(u16); // Always taken, and always the same length: no page to // cross, because the whole bank is in reach. This is what // the 6502 had to write as a branch over a jump. const from = cpu.program_counter.value; cpu.memory.internal(cpu.program_counter.addressOf(from -% 1)); cpu.program_counter.jump(from +% displacement); } }; return f.BRL; } };}