# The disc interface: uPD765A, drives and images Source names as in start-here.md. ## What the interface is (DOC: ap12 I, K; KT `fdc`) Built into the 664, 6128 and 6128 Plus; the DDI-1 adds the same interface to a 464 through the expansion port (KT `fdc`; MAME lists `cpc_ddi1` with the same AMSDOS ROM, census.md). The 464 Plus board has the footprint but the parts are not fitted (KT). - An NEC uPD765A clocked at **4.00 MHz** (ap12 I: "rather than the 8.00 MHz used with larger disc drives"; KT; MAME agrees, OBSERVED). - Ports (A10 = 0, A7 = 0): `FB7E` main status register (read), `FB7F` data register, `FA7E` motor latch, bit 0 = all motors on (ap12 K; KT). "On power-up and other system resets the motors are not stopped" (ap12 I). - **No interrupts and no DMA**: INT, DRQ, /DACK and TC are not connected (KT; ap12 I: "the exception of interrupts and DMA which are not supported"). AMSDOS polls the main status register for every byte. - **US1 is not decoded**: two drives, seen again as units 2 and 3 (ap12 I; KT: "DS1 is not connected"). - Disc ROM: AMSDOS, upper ROM 7 by default (a link selects 0), and it grounds the expansion port's /EXP so other peripherals avoid ROM 7 (ap12 I). - The internal drive is a 3" single-sided drive; AMSDOS uses one side and 40 tracks; CP/M and other DOSes use double-sided and 80-track external drives (KT). **C6. Density.** ap12 I: "The controller supports both single and double sided and single and double density". KT `fdc`: "The density select signal (MFM) is fixed at '1', therefore only double-density is supported." Amstrad's sentence may describe the uPD765A's ability rather than the board's wiring. The board accepts both encodings in images (an FM sector on a CPC image would come from a non-CPC source) and treats MFM as the only density the CPC reads, until a schematic settles it. Because TC is not connected, every multi-sector read and write ends with the FDC running off the end of the track and reporting "end of cylinder" (an abnormal termination AMSDOS ignores); this is the same situation zxspectrum-python records for the +3 (its U6), here stated by both ap12 and KT rather than inferred. ## The chip (DOC: NEC uPD765 data sheet, December 1978, pinned; KT's uPD765A/uPD7265 transcription) Command, execution and result phases through the data register, gated by RQM and DIO in the main status register; in non-DMA mode each execution byte must be taken within the byte time or the FDC flags an overrun. At 4 MHz with 250 kbit/s MFM a byte passes every 32 µs: 32 Z80 microseconds ("NOPs") per byte, so AMSDOS's polling loop has a tight budget, and copy-protection loaders that read with their own loops depend on it (HYPOTHESIS for the loaders; the arithmetic is from the data sheet's data rates and the 4 MHz clock). ## Reuse `sms-python`'s SF-7000 `UPD765` (`sf7000.py`, `7066415`): non-DMA, polled, one single-sided drive, rotation timed in CPU cycles, unknown commands answered as invalid, no overrun. The CPC needs, beyond it: two units (and the US1 mirror), double-sided drives (side select), 512-byte and other sector sizes, Read Track, Read/Write Deleted Data and the Scan commands (AMSDOS and CP/M use Read ID, Read Data, Write Data, Format, Seek, Recalibrate, Sense Interrupt Status, Sense Drive Status, Specify: the full list to take from a firmware trace in MAME), overrun, the no-TC termination, and copy-protected images (weak sectors, odd IDs, deleted data, gaps). The family now has three boards that want a uPD765A: sms-python (SF-7000, in-board), zxspectrum-python (+3, Phase 0; recommends extracting `upd765-python` before its +3 milestone) and msx-python (TC8566AF-compatible rows). The CPC is the fourth. Open decision 6: extract `upd765-python` from sms-python with history, before the CPC's disc milestone. ## Images (census.md) - **DSK** (standard, "MV - CPC") and **extended DSK** ("EXTENDED CPC DSK"), the CPCEMU formats (KT `extdsk`, Rev. 5, by Marco Vieth, Ulrich Doewich and Kevin Thacker; the standard format's page `dsk.html` was not archived in 2024, so the standard layout is to be pinned from another copy at the disc milestone, U12). Sector-level with per-sector status bytes and sizes, which is enough for most copy protection. These are the bulk of every collection on hand. - **IPF** (SPS/CAPS flux-level): 2 images in the collections on hand. Needs a decoder whose library has its own terms (as zxspectrum-python's decision 6): deferred. - No HFE or SCP images on hand. ## The FDC in MAME's 6128 boot (OBSERVED, closed box) With no disc, the 6128 ROM writes `FA7E <- 00` (motor off) at 387 µs, then reads the main status register three times and writes the data register three times in the first two seconds (mame-oracle.md); the full command decode is for the disc milestone.