# The Disk II: controller, sequencer, drive, images Usually the hardest part to get exact, and the part copy protection attacks. Three primary sources agree in outline: Wozniak's patent US 4,210,959 (the controller as designed, DOC: PAT-DISK), Sather's chapter 9 (the controller as built, with timing, DOC: UA2 ch. 9), and the WOZ reference's implementation notes, written from the Applesauce author's analysis of real drives (WOZ, tier 3: hardware-derived community document). The controller's behaviour is defined by a 256-byte PROM (P6) that the player supplies; the board models the hardware around it. ## The controller card - **P5**: 256-byte boot PROM at $Cn00 (16-sector: 341-0027; 13-sector: 341-0009). **P6**: 256-byte logic-state-sequencer PROM (16-sector: 341-0028). Both by SHA-1 only ([census.md](census.md)); never in the repository. - **Soft switches** at $C080,X-$C08F,X (X = slot x 16; slot 6 is $C0E0-$C0EF) (DOC: UA2 Table 9.1, p. 9-12): | Even / odd | Off | On | | --- | --- | --- | | $C080/1 .. $C086/7 | stepper phase 0..3 off | phase 0..3 on | | $C088/9 | drives off (after a delay) | selected drive on | | $C08A/B | select drive 1 | select drive 2 | | $C08C/D | Q6 low: shift while writing / read data | Q6 high: load while writing / read write-protect | | $C08E/F | Q7 low: read | Q7 high: write | RESET forces all switches off; **an access to any even address puts the data register on the data bus** (DOC: UA2 p. 9-12, Table 9.1 notes 1-2; WOZ "Abusing Disk Controller Soft Switches": "every soft switch on an even address should actually return the value of the data latch"). A CPU write to an even address fights the data register on the bus (DOC: UA2 p. 9-15). - **Drive on/off**: the off command is delayed about one second by half of an NE556 ("the drive never turns off between closely spaced accesses"); RESET clears the timer and turns the drive off almost at once (DOC: UA2 p. 9-14). WOZ: "a 1 second delay after accessing the 'drive motor off' soft-switch ... needs to be implemented"; protections read sectors during it (about five revolutions). - **Q7/Q6 (READ/WRITE, SHIFT/LOAD)** are sequencer address inputs (DOC: UA2 p. 9-14, Table 9.2): Q6 low + Q7 low = read; Q6 high + Q7 low = check write protect and initialise for writing; Q7 high = write, shifting (Q6 low) or loading (Q6 high) the data register every eighth sequencer clock. WOZ adds that reading $C08D,X resets the sequencer and clears the data latch (used by the "E7" protection). ## The logic state sequencer "A ROM wired up to behave like a little 2 MHz computer" (DOC: UA2 p. 9-14): - 256 bytes. **Four outputs (D4-D7) feed back through flip-flops to four address inputs (A5, A0, A6, A7)**: the sequence state, 16 values. **Four address inputs partition the ROM**: A1 = QA (the data register's MSB), A2 = SHIFT/LOAD (Q6), A3 = READ/WRITE (Q7), A4 = the read pulse from the drive (DOC: UA2 p. 9-15). - **The other four outputs (D0-D3) command the data register**: 0-7 CLR, 8 and C NOP, 9 SL0 (shift a zero in), A and E SR (shift the write-protect signal right in), B and F LD (load from the data bus), D SL1 (shift a one in) (DOC: UA2 Table 9.3). - **Clock**: the flip-flops and the data register are clocked by Q3 falling (the rising edge of Q3', about 15 ns later) **only while a drive is enabled**: about 2 MHz, two sequencer steps per CPU cycle; the read pulse is synchronised to that clock and quantised to one Q3 period (DOC: UA2 pp. 9-13..9-15 and footnote). With the long cycle, Q3 is stretched too (DOC: UA2 p. 3-13: "all 1 MHz and 2 MHz signals are elongated once every horizontal line"); the board must step the sequencer on the real Q3 edges in 14M time, not "twice per CPU cycle" blindly (U9). - **Writing**: the register accepts data only "on the clockpulse after the one which started the logic state sequencer and on every fourth clockpulse afterward"; the write interval is "eight cycles of the sequencer or four cycles of the MPU"; DOS stores at 32, 36 and 40-cycle intervals (DOC: UA2 pp. 4-22, 9-15). The proposal (open decision 3): **the board runs the player's P6 PROM as data**, as pcengine-python runs a System Card: the sequencer is eight flip-flops, a shift register and a table lookup per Q3 edge. A built-in table would be Apple's PROM contents in our source, which the firmware rule forbids. ## The drive - **Head positioning**: a four-phase stepper; ascending phase references move the head inward, two phases per track, so 70 positions on 35 tracks (half tracks); protected disks put data on the odd phases; programs wait about 20 ms per phase; "if phase-1 is left on, the drive will behave as if a write protected disk is installed" (the write-protect switch is powered from phase 1); the stop is at track 0, where the motor is phase-0 aligned (DOC: UA2 pp. 9-8, 9-13..9-14). WOZ's track map has 160 quarter-track entries (DOC: WOZ "TMAP"): the board tracks the head in quarter tracks, with the magnet arithmetic for adjacent phases on together (U10: the exact quarter-track stepping rules are not in UA2; WOZ and the detectors). - **Spindle**: 300 rpm (DOC: WOZ "When Off Isn't Really Off"), a 4 µs bit cell on 5.25" disks ("Optimal Bit Timing" 32 x 125 ns; 2 µs on 3.5"), so about 50,000 bit cells a revolution; WOZ uses 51,200 bits as the fake length of an empty track (DOC: WOZ). Spin-up time and speed variation: U11. - **Read path**: the MC3470 turns each flux reversal into a 1 µs pulse after a mask period of about 2 µs (DOC: UA2 p. 9-10). With no flux reversal for long, its automatic gain turns noise into random pulses: "fake bits" or "weak bits", which protections test for. WOZ recommends a 4-bit head window with output from bit 1 (the latency) and a random bit when the window is all zero, random bits about 30% ones (DOC: WOZ "Freaking Out Like a MC3470"). The board proposes this as a named, seeded model (the seed in the save state), tagged as the WOZ author's recommendation, not a measurement we hold. - **Write path**: Q7 high with the drive enabled raises WRITE REQUEST' unless the disk is write protected; the erase head is on while writing (DOC: UA2 p. 9-8). WOZ's WRIT chunk records how a track was written, for writing back. ## Images | Format | What it holds | Board use | | --- | --- | --- | | **WOZ 1 / 2 / 2.1** (Applesauce; public domain) | per quarter track: a bit stream with its bit count, the optimal bit timing, write protect, "synchronized", "cleaned" (MC3470 fake bits removed), compatible hardware, required RAM, a META chunk; 2.1 adds FLUX (transition times in 125 ns ticks) (DOC: WOZ) | the native format: everything the drive model needs | | DSK / DO / PO | 35 x 16 x 256 bytes, DOS 3.3 or ProDOS sector order | encoded to a bit stream by the board's GCR 6-and-2 encoder with standard gaps (a synthetic track: no timing claims) | | D13 | 13-sector, 5-and-3 | same, 13-sector encoder | | NIB | 35 x 6,656 nibbles | bytes to bits with sync gaps lost: a lossy legacy format | | 2MG, HDV, 3.5" PO | ProDOS block devices | later rows (SmartPort, IWM, hard-disk cards) | The census found 168 files named `.woz`, of which 5 are 143,360-byte sector images misnamed ([census.md](census.md)): the board identifies images by content, never by extension. ## The IWM (later) The IIc, the IIc Plus, the IIgs and the "Apple 3.5" cards use the IWM (Integrated Woz Machine), which folds the controller into one chip with a mode register and adds the 3.5" drive and SmartPort. It is a later row (the IIc); the MAME device list shows the IIgs with an IWM (`fdc`, "Apple IWM floppy controller"). Sources: A2CTRM, GSHR, and Clock Signal's `Components/DiskII/IWM.cpp` (MIT, tier 5). ## Oracles MAME's `apple2p` booting a WOZ image, with every read of $C0E0-$C0EF logged ([mame-oracle.md](mame-oracle.md)), is the first detector: the board's read stream must match it cycle for cycle until the first named difference. The WOZ test-image set and the census's WozADay images are the protection corpus (open decision 6). No hardware-tier capture of a Disk II controller is in hand.