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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354// 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 = "STZ"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x64, .addressing_mode = .@"Zero Page", .cycles = 3, }, .{ .opcode = 0x74, .addressing_mode = .@"Zero Page, X", .cycles = 4, }, .{ .opcode = 0x9c, .addressing_mode = .Absolute, .cycles = 4, }, .{ .opcode = 0x9e, .addressing_mode = .@"Absolute, X", .cycles = 5, }, };
/// 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) error{}!void { const f = struct { /// Stores nothing at all. /// /// Clearing a byte on the NMOS part meant putting nought in a /// register first, and the register was then gone. This writes /// it without one, which is why it turns up all over code /// written for the CMOS part. pub fn STZ(cpu: *CPU) error{}!void { const address = cpu.addressing_modes.decode(addressing_mode, .write); cpu.memory.write(u8, address, 0); } }; return f.STZ; } };}