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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475// 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 = "RLA"; pub const opcodes = [_]CPU.Opcodes.Init{ .{ .opcode = 0x23, .addressing_mode = .@"(Indirect, X)", .cycles = 8, }, .{ .opcode = 0x27, .addressing_mode = .@"Zero Page", .cycles = 5, }, .{ .opcode = 0x2f, .addressing_mode = .Absolute, .cycles = 6, }, .{ .opcode = 0x33, .addressing_mode = .@"(Indirect), Y", .cycles = 8, }, .{ .opcode = 0x37, .addressing_mode = .@"Zero Page, X", .cycles = 6, }, .{ .opcode = 0x3b, .addressing_mode = .@"Absolute, Y", .cycles = 7, }, .{ .opcode = 0x3f, .addressing_mode = .@"Absolute, X", .cycles = 7, }, };
/// 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 { /// A ROL of the addressed byte, with the result also ANDed /// into the accumulator. pub fn RLA(cpu: *CPU) error{}!void { const address = cpu.addressing_modes.decode(addressing_mode, .write); const value = cpu.memory.read(u8, address); // a read-modify-write drives the unmodified value back onto // the bus before the modified one cpu.memory.write(u8, address, value); const carry = value & 0x80 == 0x80; const result = @shlExact(value & 0x7f, 1) | cpu.flags.carry(u8); cpu.flags.update(.C, carry); cpu.memory.write(u8, address, result); const a = cpu.registers.get(.A) & result; cpu.registers.set(.A, a); cpu.flags.updateNZ(a); } }; return f.RLA; } };}