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.
1234567891011121314151617181920212223242526272829303132333435363738394041// 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 = "SHY"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x9c, .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 { if (addressing_mode != .@"Absolute, X") @compileError("illegal addressing mode"); const f = struct { /// Unstable. Stores Y ANDed with the high byte of the address /// plus one, and when indexing carries out of the low byte the /// store lands at the value it just computed rather than at the /// fixed up address. pub fn SHY(cpu: *CPU) error{}!void { const indexed = cpu.addressing_modes.decodeIndexed(addressing_mode); // the stored value is ANDed with one more than the high // byte of the address the chip started from const value = cpu.registers.get(.Y) & (indexed.base_high +% 1); cpu.memory.write(u8, indexed.target(value), value); } }; return f.SHY; } };}