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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100// 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 = "JAM"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x02, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0x12, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0x22, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0x32, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0x42, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0x52, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0x62, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0x72, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0x92, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0xb2, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0xd2, .addressing_mode = .Implied, .cycles = 11, }, .{ .opcode = 0xf2, .addressing_mode = .Implied, .cycles = 11, }, };
/// 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 { /// Locks the processor up. Only a reset gets it back. pub fn JAM(cpu: *CPU) CPU.Opcodes.Error!void { // the operand fetch, discarded like any single byte // instruction cpu.program_counter.phantomRead(); // and then the processor stops fetching instructions // altogether. It never resumes, so the rest of this is only // what the bus does while it is stuck: it rattles on the // vector until a reset pulls it out. _ = cpu.memory.read(u8, 0xffff); _ = cpu.memory.read(u8, 0xfffe); _ = cpu.memory.read(u8, 0xfffe); for (0..6) |_| _ = cpu.memory.read(u8, 0xffff); return error.Jam; } }; return f.JAM; } };}