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 = "STX"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x86, .addressing_mode = .@"Zero Page", .cycles = 3, }, .{ .opcode = 0x8e, .addressing_mode = .Absolute, .cycles = 4, }, .{ .opcode = 0x96, .addressing_mode = .@"Zero Page, Y", .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) *const fn (*CPU) error{}!void { const f = struct { /// Stores the X register into memory. /// /// (MOS Technology, 1976, Section 7.2, p. 97) /// (Carr, 1984, p. 274) pub fn STX(cpu: *CPU) error{}!void { const address = cpu.addressing_modes.decode(addressing_mode, .write); cpu.memory.write(u8, address, cpu.registers.get(.X)); } }; return f.STX; } };}