A cycle-accurate Apple II and Apple IIgs emulator written in Zig, usable as both a program and a library.
zig65 README.md
488 kB · 8,096 lines
Markdown
at main

<!-- SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us> SPDX-License-Identifier: MIT --> # zig65 Cycle accurate 6502, 65C02 and 65816 cores written in Zig, and the machines that were built around them: an Apple-1, an Apple II, a II Plus, a IIe, a IIc, an Apple III and an Apple IIgs, each with its memory, its video, its disk drives and the cards that went in its slots. One program runs all of them, in a terminal window: `--machine` says which, and every machine and every processor is compiled in, so choosing one is a flag rather than a rebuild. They boot. A IIe comes up in Applesoft, reads a `.dsk` through the Disk II's own PROM and puts eighty columns of green text on the screen; a IIgs boots ProDOS off a 3.5-inch disk or a hard disk, formats a floppy, and runs the Apple II System Utilities in eighty columns with its mouse working; an Apple III runs its power-on diagnostics and boots SOS from the drive in its case. Everything a machine asks for is answered by something that was worked out from the hardware rather than guessed at, and where the manuals and the machine disagreed, [How it was found out](#how-it-was-found-out) says which won. It is a library as much as a program: the cores and the machines are exported for other code to embed, not only for the terminal front end here. [merle65][merle65], a Merlin-syntax assembler for the three processors, embeds zig65 as an oracle — running the Apple II versions of the real Merlin to settle what those assemblers' manuals leave unsaid — and to carry out Merlin's `USR` pseudo-opcode, which hands its line off to a user-written 6502 routine that the emulator runs to generate the output. And the IIgs here builds its own Mega II, the chip that is an Apple IIe underneath, out of the very eight-bit IIe the other machines run. [As a library](#as-a-library) has the detail. The processors come first, because nothing above them is worth anything if they are wrong. All 256 opcodes of each are implemented: on the NMOS parts the 151 documented ones and the 105 th…