# The floppy disk controller: NEC uPD72065 ## The chip (DOC: FDC72065, NEC's 1989 Intelligent Peripheral Devices data book, printed p. 5-43 on; FDC765, the uPD765 data sheet, December 1978; AN-08) "The uPD72065/65B CMOS Floppy-Disk Controller (FDC) is NEC's follow-on to the uPD765A/B" with "100% 765A/B microcode compatibility" (FDC72065, p. 5-43). It drives up to four drives, FM or MFM, DMA or non-DMA ("In non-DMA mode, the FDC generates interrupts to the processor every time a data byte is to be transferred"), from a "single-phase clock (8 MHz maximum)". It executes **19 commands**: the uPD765A's fifteen (Read Data, Read Deleted Data, Read ID, Write Data, Write ID (format), Write Deleted Data, Specify, Read Diagnostics (read track), Scan Equal, Scan High or Equal, Scan Low or Equal, Seek, Recalibrate, Sense Interrupt Status, Sense Drive Status) plus **Set Standby, Reset Standby, Software Reset and Version** (p. 5-43). The Version command's ST0 answer is **80H for the uPD72065 and 90H for the uPD72065B** (p. 5-54, checked on the page image). The same page's table 1 lists what differs from the uPD765A/B: Recalibrate steps up to **255** tracks (765A/B: 77); index-pulse skipping 0.2 ms at 4 MHz (1.2 ms); DRQ-to-RD response one clock (0.8/1.6 us); unit-select latency 2.5/5.0 us (0.5/1.0 us); multitrack write by tunnel-erase head, the standby function and Software Reset (765A/B: none). Its text: on the uPD72065 (not the B) an overrun on the last byte of a sector of a read or write command is not reported in the result's OR bit, and after an overrun the FDC needs DACK to reset DRQ, or an external DMAC keeps transferring "and stored result status may be transferred accidentally as ordinary data" (p. 5-54). These two non-B quirks matter on a DMA board like the X68000 (U17: which revision the X68000 models carry). The command, execution and result phases, the main status register's RQM/DIO handshake, overrun and TC are the uPD765's (FDC765; AN-08). ## On the X68000 - At E94000: main status E94001, data E94003 (OBSERVED: the IPL reads E94001 and gets 80, then 90; writes three command bytes to E94003). E94005 is a drive control port (the IPL writes 01, 02, 04, 08 to it in turn, each followed by 00, many times: a per-drive strobe, most likely the eject-mask, LED and insertion-sense controls: HYPOTHESIS) and E94007 the drive select, motor and 2DD/2HD control (HYPOTHESIS: U16). - **The IPL's only command in 60 frames is Specify: 03 D0 10** (OBSERVED). Read through the data sheet: SRT = D, HUT = 0; HLT = 08, **ND = 0, so DMA mode** (contrast the Spectrum +3, where +3DOS sets ND = 1: zxspectrum-python `docs/fdc-upd765.md`). DMA runs through the HD63450's channel 0 (HYPOTHESIS: dmac.md). - The FDC's INT goes to the I/O controller (E9C001), which interrupts at level 1 with vectors from the base written to E9C003 (= 60, OBSERVED). The I/O controller also carries the drives' insertion and ejection interrupts (HYPOTHESIS). - The drives' READY reaches the FDC through the YM2151's CT1 output (ym2151-python `docs/users.md`, from MAME's BSD-3-Clause driver lines it cites): a cross-chip wire the board must model as a channel (domains-and-speed.md). - MAME: "NEC uPD72065 FDC @ 8.00 MHz" with four 5.25" high-density drive slots (OBSERVED). **The 2HD format.** 77 cylinders x 2 heads x 8 sectors x 1,024 bytes = 1,261,568 bytes, exactly the payload of the `.dim` and `.xdf` images in the census (1,261,824 = that + a 256-byte DIM header; 1,261,568 for XDF: census.md, MEASURED from the files' sizes). The 1.44 MB "2HQ" images (1,474,816 bytes, 42 of the TOSEC games) are 80 x 2 x 18 x 512 + 256. 5.25" 2HD at 360 rpm and 500 kbit/s MFM puts a byte every 16 us (HYPOTHESIS for the X68000's drives; standard figures for 2HD), or 160 68000 clocks at 10 MHz: easy for the DMAC, which is why the IPL picks DMA. ## Modelling level Byte level in execution (each data byte a DMA request at its time on the rotating track), with the drive modelled as a rotating track of sectors from a sector image (DIM, XDF, D88, HDM) and, later, from flux (the No-Intro KryoFlux `.raw` set, HFE, SCP) for copy protection. Every time constant (rotation, step, head load, the index pulse) in one table tagged FITTED or HYPOTHESIS. ## The extraction under discussion: `upd765-python` | Family user | Part | Mode | What it needs | | --- | --- | --- | --- | | sms-python (SF-7000) | uPD765A | non-DMA, polled, one single-sided 3" drive | the existing in-board class `UPD765` (`src/sms_python/sf7000.py`) | | zxspectrum-python (+3) | uPD765A | non-DMA, polled, two units, INT/TC wiring unknown | proposes extracting `upd765-python` before its M8 (its handoff brief, decision 3) | | msx-python (Panasonic, turbo R) | TC8566AF (765-compatible) | | proposes extraction when that row starts (its decision 9) | | cpc-python | uPD765A | non-DMA | its fdc-upd765.md | | **x68000-python** | **uPD72065** | **DMA**, four drives, 1,024-byte sectors, 500 kbit/s, the four extra commands | a variant row (`Upd72065`) with Version = 80H, the standby and software-reset commands, DRQ/DACK and TC driven by the DMAC | Five boards want the same chip family: the chip rule is long met. Recommendation (open decision 4): extract `upd765-python` from sms-python with history, as zxspectrum-python proposed, with the uPD72065 as a variant of the one core (a part parameter selecting the command set and the Version answer), and DMA as a socket (DRQ out, DACK and TC in) that non-DMA boards leave unconnected. The X68000 needs it at its floppy milestone (M5), so it is not on the critical path for the IPL screen.