# The 1541 disk drive and the IEC serial bus ## What it is "An intelligent device, containing its own microprocessor, RAM, ROM and operating system": a MOS 6502 at 1 MHz, 2K RAM, 16K ROM (two 8K chips, 325302-01 and 901229-xx, or one 16K chip on the 1541C/1541-II), two 6522 VIAs, the read/write electronics (discrete logic on the long board, a 40-pin gate array on the later short "CR" board, the 64H156 in MAME's device list), a stepper (one step = half a track) and a 300 rpm DC spindle under closed-loop control (DOC: DSM pp. "Product specification", "Overview", "Circuit theory"; MAME 0.285 `-listdevices c64` lists `ucd5` 6502 @ 1.00 MHz, VIAs `uab1` and `ucd4`, `uc4` 64H156 @ 16 MHz). - **Clock:** a 16 MHz crystal divided by 16 gives the 6502's 1 MHz; a programmable counter (÷16, ÷15, ÷14, ÷13) gives the bit clock for the four speed zones, faster on the outer tracks (DSM "The clock circuits"). **Its crystal is not the C64's**: the drive is its own clock domain. - **The VIAs:** one drives the serial bus (ATN in on PB7 and CA1, ATNA out on PB4, the CLK and DATA drivers) and the device-number jumpers; the other drives the read/write path (port A the data byte, the shift register in the PLA/gate array, "byte ready" on the 6502's SO pin by the commonly published account), the stepper, motor and LED (DSM). **DSM places the serial VIA (UC3) at $1C00 and the read/write VIA (UC2) at $1800**, the reverse of the common account (C5). - **Media:** single-sided, 35 tracks, 170K formatted, GCR encoded (DSM). `.d64` holds the decoded sectors only (no GCR, no timing, no errors unless the 683-byte error table is appended); `.g64` holds the GCR bit streams per half track; `.p64` holds flux. Copy protections need `.g64` or better (VICE manual 17 documents the formats: facts only). - **Computers:** "C64, VIC 20, SX64, Educator 64, Plus/4, C16" (DSM spec page). ## Socket device or separate board? **Recommendation: a separate board repository, `c1541-python`**, plugged into `c64-python`'s IEC socket, for four reasons: 1. It is a whole computer with its own firmware (the DOS ROM), its own CPU and its own clock domain; the channel between it and the C64 is three open-collector lines and RESET, nothing else. 2. Five other Commodore machines use it unchanged (DSM spec page): a VIC-20 or Plus/4 board in the family would reuse it without depending on `c64-python`. 3. It needs its own gate: the 1541 test suites (VICE `drive/1541-testsuite`, `drive/*`: 55 entries in the C64 list; `rpm`, `inertia`, `openbus` mention real hardware) run with the drive alone or through the bus. 4. The family's shape for add-on hardware is a separate board that plugs into sockets on the base board (the Phase 0 rules; sega32x-python on megadrive-python). The 1541-II, 1541C, 1570/1571 and 1581 are rows or further boards later (the No-Intro set carries their DOS ROMs: census.md). Until Aubrey decides, the drive's Phase 0 lives here; `c1541-python` would start from this document. Open decision 2. ## The IEC socket (proposed) `IecBus`: three wired-AND lines (ATN, CLK, DATA) plus RESET; each device contributes its pulled-low outputs and reads the bus level. The C64 side drives through CIA 2 PA3-PA5 (inverted outputs) and reads PA6-PA7 (cia.md); the drive side through its serial VIA and the ATNA exclusive-OR (DSM). A line change is a timestamped event on the channel; both sides must see the other's changes at the right cycle, because fast loaders bit-bang the bus with cycle-counted code on both CPUs. ## The chips it needs | Chip | Family core | Need | | --- | --- | --- | | 6502 | 6502-python (`MOS6502`) | the plain NMOS core; the SO (set overflow) input, which the drive uses for "byte ready": **6502-python has no SO input** (README and docs read: not mentioned) — an upstream request | | 6522 VIA x 2 | inside vectrex-python as `VIA6522` (`via.py`, "no Vectrex names inside", its open decision 2) | **this is the second family user**: by the chip rule the VIA becomes its own core, extracted from vectrex-python with history (open decision 3) | | read/write logic / 64H156 | none | stays in `c1541-python`; modelled from DSM's circuit description and the 1541 test suite | | the drive mechanics | none | head position in half tracks, motor spin-up and speed (`rpm`, `inertia` tests), the disk's GCR stream | ## Judges | Tier | Judge | Decides | | --- | --- | --- | | 2 | DSM, DMG, the R6522 data sheets (CAT 2-35) | circuits, addresses (with C5), VIA behaviour | | 3 | VICE `drive/*` and `drive/1541-testsuite` with hardware notes | drive corners | | 3 | the DOS ROM itself, run | addresses by construction (it must find its VIAs) | | 5 | MAME `:iec8:c1541:ucd5` trace (mame-oracle.md: 283,621 instructions in the first second) | detector | ## The high-level shortcut (not proposed) Many emulators offer "virtual drive" or kernal traps that skip the drive. That is a concession (it changes what software sees: fast loaders and protections fail); it does not belong in the specification. If a host wants it, it is a named turbo concession.