A cycle-accurate Apple II and Apple IIgs emulator written in Zig, usable as both a program and a library.

give the IIgs its own graphics, and the scan-line interrupt its source

Super Hi-Res is the video controller's display and it is nothing like the one the machine inherited. No dot stream and no colour subcarrier: pixels, with colour numbers in them, and the numbers mean whatever a palette in memory says. Different chip, different grid, different idea of what a colour is, so it is src/superhires.zig rather than more of src/video.zig. Every one of the two hundred lines has a control byte and decides for itself: which of the sixteen palettes it uses, 320 pixels or 640, Color Fill on or off, and whether the beam reaching it interrupts. That last is the only interrupt in this machine whose source is a byte in the middle of the picture rather than a register -- a program changes what interrupts and when by drawing -- so updateVideo now walks the control bytes as the beam crosses them, counted rather than caught and clamped to one frame back. Color Fill turns colour $0 from a colour into "the same as the pixel to my left". 640 mode divides the palette into four groups and picks the group from where in the byte the pixel sits, which is not four colours a line but sixteen, and which is arranged so that the pairs that dither well are adjacent. Both PNG writers now sit on src/png.zig rather than one of them carrying ninety lines of plumbing the other would have had to copy. It gained a reader too, because a writer nobody reads is a writer nobody has checked -- and reading found a real bug immediately: a stored deflate block holds up to 65,535 bytes, and 5 + that does not fit in the u16 it was being added to. A 560-wide screen is one block and never showed it; a 640-wide one is two. Checked by writing a picture through the real machine into bank $e1, using all four features at once. That caught the seam again, where it always catches people: writing just bit 7 of $c029 to turn the display on clears bit 0, which is the bank latch, and without the latch writes to bank $e1 land in the main half of the Mega II and the screen stays black. The firmware comes up with the latch set, which is why the picture worked before the test did.


Author jcollie.dev
Date Commit Parent 8223d21f