# The diskette adapter and the uPD765 Source names: **A81** IBM PC Technical Reference, Aug 1981; **DS** NEC uPD765 data sheet, Dec 1978; **AN** NEC uPD765 application note, Mar 1979 (PDF pages). ## The IBM 5-1/4" adapter (A81 p.105-121 / 2-89-2-105) - "NEC uPD765 compatible" controller, double-density MFM with write precompensation and an analogue PLL, up to four drives (A81 p.105 / 2-89). - Ports 3F2 digital output register (bits 0-1 drive select, bit 2 "Not FDC Reset", bit 3 enable interrupt and DMA requests, bits 4-7 motors A-D; drive select works only "if its motor is on"), 3F4 main status, 3F5 data (A81 p.107, p.119 / 2-91, 2-103). - "Interrupt 6, DMA 2" (A81 p.120 / 2-104). - Format: one head (the original 160 KB drive), 40 tracks, 8 sectors of 512 bytes, MFM, 250 kbit/s; constants SRT = C, HUT = F, HLT = 01; head load 35 ms, settle 25 ms, motor start 500 ms (A81 p.120, p.128 / 2-104, 2-112). The 9-sector, double-sided 360 KB format came with DOS 2.0 (not in A81; DOC to find, U14). - The FDC's clock on the adapter is not in the prose (U15: the logic diagram decides; the data sheet's "mini-floppy application" uses 4 MHz, DS PDF 16). ## The uPD765 (DS, AN) - Fifteen commands (DS PDF 1): Read Data, Read ID, Read Deleted Data, Read a Track, Scan Equal, Scan Low or Equal, Scan High or Equal, Specify, Write Data, Format a Track, Write Deleted Data, Seek, Recalibrate, Sense Interrupt Status, Sense Drive Status; invalid commands are covered (DS PDF 9, 16). - Command, execution and result phases; the main status register's RQM (bit 7) and DIO (bit 6) gate every byte; NDM (bit 5) marks non-DMA execution; CB (bit 4) busy; bits 0-3 drives seeking (DS PDF 7). - Overrun: a read must be serviced "every 27 us in the FM Mode, and every 13 us in the MFM Mode, or the FDC sets the OR (Over Run) flag" (DS PDF 12) at 8 MHz; the application note doubles or quadruples these for mini-floppies (AN PDF 17): 26 us per byte at 250 kbit/s MFM. The PC uses DMA channel 2, so overrun is the DMA's and the bus's business: a long DMA hold-off (a LOCKed instruction keeps the DMA-wait logic from taking the bus, cpu-8088.md) can delay it (HYPOTHESIS: whether any PC software hits this). - Specify timers at 8 MHz: SRT 1-16 ms, HUT 0-240 ms, HLT 2-256 ms; "if the clock was reduced to 4 MHz ... all time intervals are increased by a factor of 2" (DS PDF 16). ## Reuse: the `upd765-python` extraction under discussion sms-python has an in-board `UPD765` (`src/sms_python/sf7000.py`: non-DMA, polled, one single-sided drive). The CPC Phase 0 (`../cpc-python/docs/fdc-upd765.md`) counts three more wanting it (zxspectrum-python +3, msx-python TC8566AF rows, cpc-python) and recommends extracting `upd765-python` from sms-python with history. The PC is the fifth user and the first with **DMA** and an IRQ: it needs DRQ/DACK/TC as pins, two-sided drives, 512-byte sectors and the timing of the data rate. The chip's command logic is shared; the drive and the data separator are the board's (open decision 5: support the extraction; the PC's DMA and TC pins become part of the core's interface). ## Images (census.md) Sector images (`.ima`/`.img`, 160-360 KB) need only the controller. Flux streams (KryoFlux `.raw` sets tagged `[kfx]`, SuperCard Pro `[SCP]`) and TeleDisk `[TD0]` carry copy protection (weak bits, odd sector sizes, timing); they need a flux-level drive and a data separator model. fluxfox (`dbalsom/fluxfox`, MIT, GitHub's licence field; by MartyPC's author) is a permissive library for these formats: a candidate to read for formats, recorded as a source row, not fetched. Hard disks (the XT's Xebec controller, `isa_hdc` in MAME) are a later row.