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

the head follows SEL, so a IIc Plus formats both sides of every track

The last thing standing between this machine and a formatted disk, and it was a mistake in the drive rather than anything to do with the IIc Plus. `disk35.zig` modelled the head as a latch that a *read* of register 1 or 3 sets, those two registers differing in nothing but the SEL bit. Reading is forgiving enough to hide that -- a firmware that finds itself on the wrong side reads an address field saying so and looks again -- so every read test passed throughout. Writing has no second chance. Over a IIc Plus's format all 1,457,979 bytes went to side nought, half the disk was never written, and the blame lay with 1,261 sense reads on register 1 that landed in the middle of runs of writing and quietly pulled the head back. Two tables on one page of *Inside Macintosh* settle it (Apple Computer, Inc., 1985c, p. III-35). The read table calls registers 1 and 3 "RDDATA0, read data, lower head" and "RDDATA1, read data, upper head" -- where the data comes *from*, with nothing said about a read leaving the drive on that head. The write table settles it from the other end: every control register is written with SEL at nought, "Next, set SEL to 0", so SEL is never spent on naming one and is free to be the head select the whole time. The circuit diagrams say it outright. On every Macintosh with a 3.5-inch drive the disk chip's own `HDSEL` output is marked *n.c.* and the line reaching the drive comes from VIA1 PA5 (Apple Computer, Inc., 1990, Figures 9-10 and 9-13, pp. 351 and 354, both checked against the page images). SEL is a plain latched output of the host -- bit 7 of `$c031` on a IIgs, the glue chip's `HDSEL` on a IIc Plus, a VIA pin on a Macintosh -- set by the firmware, held for as long as it works on one side, and connecting that head to the read amplifier and the write driver alike. This had been tried once before and appeared to fail, and the failure was borrowed: it was measured while `$ce40` and `$ce60` were modelled as one latch moved by a read or a write indifferently, so the firmware's writes to that pair dragged SEL about underneath its reads. With the two separated the measurement comes out the opposite way. Over a whole format SEL changes between one written byte and the next exactly 160 times -- twice per track for eighty tracks. It does not thrash. It sits still for a side and then moves. So `Drive.side` goes and `Controller.head()` returns SEL, and the format test comes in from the scratchpad where it has been waiting: it boots the System Disk, drives the System Utilities' Format a Disk to the drive on the back, swaps an unrecorded surface in when the program asks for the destination, and checks all 1600 blocks -- not a sample -- for a ProDOS volume of the name typed. The disk the machine booted from sits unprotected in the other drive throughout. The IIgs's own format test, every 3.5-inch read and write test, the 45 WOZ images and the four functional tests are unchanged by this. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aieuyb2KR2DsKyZWPJpas6


Author jcollie.dev
Co-author Claude Opus 5 (1M context) Date Commit Parent 0b45d140
+329 -97
4 changed files
+329 -97
4 changed files