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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>//// SPDX-License-Identifier: MIT
//! A cycle accurate 6502, and the pieces an emulator needs around it.//!//! CPU is parameterised over a clock so that timing can be counted or//! driven; everything else hangs off it.
pub const clock = @import("clock.zig");
/// What a stopped machine is: the run state and the reason it stopped, shared/// by the two front ends because their sessions are separate modules.pub const debug = @import("debug.zig");pub const CPU = @import("cpu8.zig").CPU;
/// The same processor made in CMOS: the 65C02, which has instructions the/// 6502 has not, does decimal arithmetic properly, and does not have the/// undocumented encodings programs written for the older one rely on.pub const CMOS = @import("cpu8.zig").CMOS;
/// A processor of whichever kind the options name, for a caller that wants to/// choose between them rather than name one.pub const Chip = @import("cpu8.zig").Chip;
/// A 6502 with nothing built around it, for tests and for the corpus.pub const Bare = @import("cpu8.zig").Bare;
/// And a 65C02, likewise.pub const BareCMOS = @import("cpu8.zig").BareCMOS;
/// Reading the text screen: what mode the display is in, and the characters/// on it in the order somebody looking at it would read them.pub const screen = @import("screen.zig");
/// A ProDOS block device: whole blocks rather than a stream of bits.pub const blockdevice = @import("blockdevice.zig");
/// The 6551 in a Super Serial Card: bytes in and out, at the rate asked for.pub const serial = @import("serial.zig");
/// The cassette port, whose output is the speaker over again.pub const cassette = @import("cassette.zig");
/// The speaker: when the cone moved, and turning that into sound.pub const speaker = @import("speaker.zig");
/// A parallel printer card, which is a latch and eight wires.pub const parallel = @import("parallel.zig");
/// A host console card, for a program embedding the emulator: character output/// to a `std.Io.Writer` and input from a `std.Io.Reader` the embedder supplies,/// reached from the machine by `PR#n` and `IN#n`.pub const console = @import("console.zig");
/// Sound written to a file, which is how either front end is listened to.pub const wav = @import("wav.zig");
/// WOZ: a disk written down as the bits that go past the head.pub const woz = @import("woz.zig");
/// ShrinkIt archives, which is how an Apple II disk usually arrives. The/// user's own `zig-shrinkit` package: `shrinkit.nufx` reads one and/// `shrinkit.writer` builds one, with the two LZW compressors in between.pub const shrinkit = @import("shrinkit");
/// A whole machine written down and read back: the save state.pub const snapshot = @import("snapshot.zig");
/// A disk out of whatever file somebody named, whichever of the three it is.pub const diskfile = @import("diskfile.zig");
/// Writing a disk back into the file it came out of, wrapper and all.pub const writeback = @import("writeback.zig");
/// Drawing the graphics screen: the dots the machine puts out, and the colour/// four of them at a time come to.pub const video = @import("video.zig");
/// The character generator: which dots a byte in the text page lights up, out/// of the shapes the chips hold.pub const font = @import("font.zig");
/// Super Hi-Res: the Apple IIgs's own graphics, which are pixels and palettes/// rather than dots and a colour subcarrier.pub const superhires = @import("superhires.zig");
/// Turning either of the displays above into pixels, and pixels into a file./// The one place here that knows what a picture is.pub const picture = @import("picture.zig");
/// The Disk II: the controller card, its drives, and the encoding that turns/// a disk image into what a drive would read off the surface.pub const disk2 = @import("disk2.zig");
/// The Apple 3.5-inch drive: the mechanism the IWM talks to, and the eight/// hundred kilobytes of six-and-two on the disk in it.pub const disk35 = @import("disk35.zig");
/// The CBus packets an Apple IIc with the 32K ROM sends to an intelligent/// drive such as a UniDisk 3.5, and the ones it expects back.pub const cbus = @import("cbus.zig");
/// The Corvus Omninet Transporter: the card that puts an Apple II on Corvus's/// network, told what to do in whole commands rather than worked a byte at a/// time.pub const omninet = @import("omninet.zig");
/// The UniDisk 3.5: a drive with a processor in it, answering the packets/// `cbus` frames rather than being worked as a mechanism.pub const unidisk = @import("unidisk.zig");
/// The seven expansion slots and what goes in them: which card is where, what/// its page answers, and what its sixteen switches do. One card kind can be in/// any slot, and a machine can have several of a kind.pub const slots = @import("slots.zig");
/// The 2IMG wrapper: a disk image that says which way round its sectors are/// and whether it was write protected, rather than leaving it to the file name.pub const twomg = @import("twomg.zig");
/// DOS 3.3 as it lies on a disk: making an image, and the files on it.pub const dos33 = @import("dos33.zig");
/// ProDOS as it lies on a volume: making an image, and the files on it.pub const prodos = @import("prodos.zig");
/// The UCSD p-System filesystem as Apple Pascal lies it on a disk.pub const pascal = @import("pascal.zig");
/// A clock card, which is how ProDOS comes to know the date.pub const clockcard = @import("clockcard.zig");pub const mm58167 = @import("mm58167.zig");pub const profile = @import("profile.zig");
/// The SCSI bus and a disk on the end of it: the phases, the REQ/ACK/// handshake, and the command set a ProDOS driver issues.pub const scsi = @import("scsi.zig");
/// The NCR 5380, which is the controller an Apple II SCSI Card has on it and/// the same part the Macintosh Plus, SE and II have.pub const ncr5380 = @import("ncr5380.zig");
/// An AppleMouse II card: where the mouse is, and what it interrupts for.pub const mouse = @import("mouse.zig");
/// A Videx Videoterm: eighty columns out of a card's own memory and its own/// character generator, on a machine whose video could not do it.pub const videx = @import("videx.zig");
/// A Videx UltraTerm: the card after that one, with four kilobytes, nine/// display formats, two dot clocks and an attribute for every character.pub const ultraterm = @import("ultraterm.zig");
/// An Applied Engineering RamFactor: a megabyte in a slot, reached a byte at a/// time through four addresses, and a RAMdisk once its firmware is in it.pub const ramfactor = @import("ramfactor.zig");
/// A Mockingboard: two sound chips, two 6522s, and turning what was written to/// them into sound.pub const mockingboard = @import("mockingboard.zig");
/// A Phasor: Applied Engineering's superset of the Mockingboard, four sound/// chips behind the same two 6522s with a software-latched mode.pub const phasor = @import("phasor.zig");
/// A Sound/Speech Mockingboard: an AY-3-8910 and a Votrax SC-01, the first of/// the family.pub const soundspeech = @import("soundspeech.zig");
/// The Votrax SC-01 phoneme speech chip on the Sound/Speech card.pub const sc01 = @import("sc01.zig");
/// The AY-3-8910 on a Mockingboard: three squares, a noise and an envelope.pub const ay3 = @import("ay3.zig");
/// The SSI 263A speech synthesizer, the voice on the Mockingboard C and Phasor.pub const ssi263 = @import("ssi263.zig");
/// The MC6840 programmable timer and MC6850 ACIA on a Passport MIDI interface.pub const mc6840 = @import("mc6840.zig");pub const mc6850 = @import("mc6850.zig");
/// The WIZnet W5100 on an Uthernet II: an Ethernet chip with its TCP/IP stack/// in silicon, so the host's own sockets are what stand in for it.pub const w5100 = @import("w5100.zig");
/// The host end of an Uthernet II: four of the machine's own sockets standing/// in for the four the W5100 has, driven once a frame from the session.pub const uthernet = @import("uthernet.zig");
/// A Hayes modem on the Super Serial Card, dialing out over the host's TCP.pub const modem = @import("modem.zig");
/// The Cirrus Logic CS8900A on the original Uthernet: a raw Ethernet/// controller, the driver's own stack on top of it.pub const cs8900 = @import("cs8900.zig");
/// The host end of an Uthernet: a UDP multicast group standing in for the/// Ethernet cable the CS8900A's frames cross.pub const ethernet = @import("ethernet.zig");
/// Standard MIDI Files, read into and written out of the machine's clock.pub const smf = @import("smf.zig");
/// The 6522 in front of each of them.pub const via = @import("via.zig");
/// What can be told about an Apple IIgs system ROM image from the image, which/// is more than can be told from its name or its size. Nothing loads one yet.pub const iigsrom = @import("iigsrom.zig");
/// What a ROM file is: the catalogue of the ones this has been tested against,/// by hash, and a reading of the marks in one that is not in it.pub const romid = @import("romid.zig");
/// What an Apple II looked like on a colour television: the composite signal/// demodulated rather than looked up in a table.pub const ntsc = @import("ntsc.zig");
/// The Apple Desktop Bus registers, which are how an Apple IIgs has a keyboard.pub const adb = @import("adb.zig");
/// The Apple IIgs's built-in clock chip, and the border colour that shares its/// control register.pub const rtc = @import("rtc.zig");
/// The Integrated Woz Machine: the disk port of an Apple IIgs.pub const iwm = @import("iwm.zig");
/// The Ensoniq 5503 and its glue: how an Apple IIgs makes a sound.pub const ensoniq = @import("ensoniq.zig");
/// The Video Graphics Controller's registers: colour, the character/// generator's language, and the bank latch that is not about video at all.pub const vgc = @import("vgc.zig");
/// The Zilog 8530, which is an Apple IIgs's printer port and modem port, and/// in its other mode the machine's LocalTalk.pub const scc = @import("scc.zig");
/// The far end of the LocalTalk cable: the bridge to LocalTalk over UDP.pub const localtalk = @import("localtalk.zig");
/// The 65816, which is its own core rather than an option on the one above./// See the header of cpu16.zig for why the two are not one.pub const cpu16 = @import("cpu16.zig");
/// The memory models that core can be given, addressed twenty-four bits wide.pub const memory16 = @import("memory16.zig");
/// The memory models a processor can be given. Flat is the only one so far;/// a machine with banking and soft switches goes alongside it.pub const memory = @import("memory8.zig");
/// Which processor's behaviour to follow where the families disagree,/// which for now means the decimal mode correction in add.zig.pub const Processor = enum { /// 6502 @"6502", /// The 6502 core inside Ricoh's RP2A03, which is the processor in a NES. /// The same chip in every way that shows on the bus, except that the /// decimal mode is not wired up: ADC and SBC add and subtract in binary /// whatever the D flag says. The flag itself is still there and SED, CLD /// and the stack still carry it about, so a program can set it and read /// it back; it just does not reach the adder. /// /// Ricoh also made the RP2A07 for the machines sold where the television /// standard was PAL. Its core is this one; what differs is the divider in /// front of it and the sound hardware beside it, neither of which is the /// processor's business. RP2A03, /// 65C02, the plain CMOS part: what Synertek, NCR and GTE made, and the /// instructions all the CMOS parts agree on. @"65C02", /// Rockwell's, which added sixteen instructions for setting and clearing /// a bit of a zero page byte and sixteen more for branching on one. R65C02, /// Western Design's, which has Rockwell's and two of its own for stopping /// the processor: one until an interrupt, one until reset. W65C02,
/// Whether this is one of the CMOS parts, which is what most of the /// differences hang off. pub fn cmos(self: Processor) bool { return switch (self) { .@"6502", .RP2A03 => false, .@"65C02", .R65C02, .W65C02 => true, }; }
/// Whether ADC and SBC look at the D flag at all. Every one of these /// parts has the flag; Ricoh's is the one where it goes nowhere, because /// the decimal correction was left off the die. pub fn decimal(self: Processor) bool { return self != .RP2A03; }
/// Whether it has Rockwell's bit instructions. pub fn bits(self: Processor) bool { return self == .R65C02 or self == .W65C02; }
/// Whether it can be told to stop. pub fn stops(self: Processor) bool { return self == .W65C02; }};
test { _ = Bare; _ = cpu16; _ = iigsrom; _ = adb; _ = rtc; _ = iwm; _ = ensoniq; _ = memory16; _ = @import("cpu16/opcodes.zig"); _ = @import("cpu16/add.zig"); _ = @import("cpu16/flags.zig"); _ = @import("cpu16/registers.zig"); _ = @import("cpu16/stack.zig"); _ = @import("scsi.zig"); _ = @import("romid.zig"); _ = @import("ntsc.zig"); _ = @import("ncr5380.zig"); _ = @import("cpu8/opcodes.zig"); _ = @import("instantiation.zig"); _ = @import("system_tests.zig"); _ = video; _ = font; _ = superhires; _ = picture; _ = disk2; _ = disk35; _ = cbus; _ = unidisk; _ = slots; _ = writeback; _ = omninet; _ = twomg; _ = dos33; _ = prodos; _ = pascal; _ = clockcard; _ = mouse; _ = ramfactor; _ = mockingboard; _ = phasor; _ = soundspeech; _ = sc01; _ = ay3; _ = ssi263; _ = w5100; _ = uthernet; _ = modem; _ = cs8900; _ = ethernet; _ = via; _ = screen; _ = speaker; _ = parallel; _ = console; _ = wav; _ = shrinkit; _ = woz; _ = diskfile; _ = cassette; _ = serial; _ = blockdevice; _ = scc; _ = localtalk; _ = vgc; _ = videx; _ = ultraterm; // @import("std").testing.refAllDecls(@This());}