Changes

765 FDC

4,433 bytes added, 14 May
/* Datasheets */
µPD765 - Floppy Disc Controller (used in CPC 664, CPC 6128, 6128 Plus and [[DDI-1]] and CPC 664/6128expansion).
The ports used by Besides the Amstrad CPC, this chip equipped the [[PCW|Amstrad PCW]], the [[ZX Spectrum|ZX Spectrum +3]], the [[SC-3000|Sega SC-3000]], and compatible interfaces use:the [[PC|IBM PC]] (including [[Amstrad PC]]).
* Port &FA7E - Floppy Motor On/Off Flipflop* Port &FB7E - FDC 765 Main Status Register (read only)* Port &FB7F - FDC 765 Data Register (read/write)The recommended ports used by Amstrad and compatible interfaces are:
The [[Vortex Disc Drives{|Vortex disc interface]] uses other ports. See its dedicated wiki page.class="wikitable"|-!I/O port address!Function|-|&FA7E||Floppy Motor On/Off Flipflop|-|&FB7E||FDC 765 Main Status Register (read only)|-|&FB7F||FDC 765 Data Register (read/write)|}
<br>Note: Bit b10 of the address port is reset as the FDC is seen as an expansion, even if it is an internal chip. Bit b7 is reset to select the FDC. Bits b8 and b0 are used to select the specific mode of operation. All other bits should be set to 1 to avoid conflict. [https://www.cpc-power.com/cpcarchives/index.php?page=articles&num=48 Source]
== IC Models used in CPC ==Note2: The [[Vortex Disc Drives|Vortex disc interface]] uses other ports. See its dedicated wiki page.
More than one manufacturer made 765 compatible ICs. These are the ones known to be used in the CPC by looking at pictures of CPC mainboards.<br>
All should operate almost identically== Motor On/Off Flip-Flop ==Writing 00h to Port &FA7E turns all disk drive motors off, writing 01h turns all motors on. It is not possible to turn on/off the motor of a specific drive separately.
* NEC D765AC [https://www.cpcwiki.eu/imgs/3/3c/CPC664_Z70205_MC0005B_PCB_Top.jpg Source]* NEC D765ACAn exception are the Vortex F1-2 [https://wwwS, F1-D, M1-S and M1-D drives.cpcwiki.eu/imgs/4/45/CPC6128_PCB_Top_%28Z70210_MC0009A%29.jpg Source]* UMC UM8272A [[Media:Amstrad cpc 6128 azerty (fHow are they different?) placa2.jpg|Source]]* Zilog Z765APS [https://www.cpcwiki.eu/imgs/f/fb/CPC6128_Z70290_MC0020C_PCB_Top.jpg Source]* [[Zilog]] Z0765A08PSC [https://www.cpcwiki.eu/imgs/6/67/CPC6128_PCB_Top_%28Z70290_MC0020F%29.jpg Source]
The following data seperators Another exception is the Gotek drives. They don't take the motor flip-flop into account and are usedalways on. [https://64nops.wordpress.com/2021/07/04/a-la-decouverte-du-fdc/ Source]
* FDC9216 [https://wwwSome FDC commands don't require the motor to be on.cpcwikiFor example, the seek or recalibrate commands, that move the floppy drive head, work fine with the motor off.euAnd seek/imgs/4/45/CPC6128_PCB_Top_%28Z70210_MC0009A%29recalibrate also work with an empty drive (ie. without a floppy disk inserted).jpg Source]* SED9420C [https://www64nops.cpcwikiwordpress.eucom/imgs2021/307/3c10/a-la-decouverte-du-fdc-episode-2/CPC6128_PCB_Top_%28Z70290_MC0020A%29.jpg Source]
The CPC464floppy disk rotates at a nominal speed of 300rpm, CPC472, 464 Plus and GX4000 are not equipped with a some tolerance. This tolerance of the FDC chiphas been measured by [[Roudoudou]] to be ±12% (it worked from 220 kbits/s to 283 kbits/s for a reference of 250 kbits/s).[https://64nops.wordpress.com/2021/09/02/a-la-decouverte-du-fdc-episode-4/ Source]
All The FDC speed is more impressive when you realize the floppy disk drive models Amstrad CPC’s tape loads at only 2 kbits/s in fast mode. Note: tape loading can be way faster than that if an MP3 player is used by Amstrad are referenced instead of a real physical tape, as it has been demonstrated here: [https://wwwyoutu.cpcwiki.eube/index.php/Amstrad_FDD_part Amstrad FDD part]MAIsOIwgJWA
<br>
== Accessing the FDC 765 ==
The Main Status Register (Port &FB7E) signalizes when the FDC is ready to send/receive the next byte through the Data Register.
The Data Register (Port &FB7F) is used to write Commands and Parameters, to read/write data bytes, and to receive result bytes. These 3 operations are called Command-, Execution-, and Result-Phase.:
<br> === * Command Phase === : A command consists of a command byte (eventually including the MT, MF, SK bits), and up to 8 parameter bytes. <br> === Execution Phase === During this phase, the actual data is transferred (if any). Usually that are the data bytes for the read/written sector(s), except for the Format Track Command, in that case 4 bytes for each sector are transferred. During data transfers between the FDC and the processor, the FDC must be serviced every 26µs (for MFM mode with CPC timings) or the FDC terminates the FDC command. <br>
=== Result * Execution Phase ===: During this phase, the actual data is transferred (if any). Usually that are the data bytes for the read/written sector(s), except for the Format Track Command, in that case 4 bytes for each sector are transferred. During data transfers between the FDC and the processor, the FDC must be serviced every 26µs (for MFM mode with CPC timings) or the FDC terminates the FDC command.
* Result Phase: Returns up to 7 result bytes (depending on the command) that are containing status information. The Recalibrate and Seek Track commands do not return During the result bytes directlyphase, instead all the program result bytes must wait until the Main Status Register signalizes that the command has been completed, and then it must (!) send be read. The FDC will not accept a Sense Interrupt State new command to 'terminate' until all the Seek/Recalibrate commandresult bytes are read.
During the Note: The Recalibrate and Seek Track commands do not return result phasebytes directly. Instead, all the result bytes program must be readwait until the Main Status Register signalizes that the command has been completed. The FDC will not accept And then it must (!) send a new Sense Interrupt State command until all to 'terminate' the result bytes are readSeek/Recalibrate command.
<br>
=== The 15 FDC Commands ===
{|
Abbreviations used:
*N = 2^(n+7) bytes, with N between 0 and 7. For example, N=2 means 512 bytes. There is conflicting info about the meaning of N=8: CPC-Power thinks it means 32768 bytes [https://www.cpc-power.com/SectorView.php?fiche=4225&slot=10&rang=0 Source]. Same for Roudoudou [https://64nops.wordpress.com/2021/09/09/a-la-decouverte-du-fdc-episode-5/ Source]. While CPCWiki Simon Owen thinks it means N=0 (128 bytes) [https://www.cpcwiki.eu/index.php/Format:DSK_disk_image_file_format Source]. On the Intel 82078 datasheet, it is precised that all values up to 7 are allowable.
*MT = Multi-track (continue multi-sector function on other head)
*MF = MFM mode (1 = Double Density)
<br>
=== FDC Status Registers ===
The Main Status register can always be read through Port &FB7E. The other 4 Status Registers cannot be read directly, instead they are returned through the data register as result bytes in response to specific commands.
<br>
=== C, H, R, N values at result phase ===
If the processor terminates a read (or write) operation in the FDC, then the ID information in the Result phase is dependent upon the state of the MT bit and EOT byte:
<br>
== Motor On/Off Flip-Flop =Notes =Writing 00h to Port &FA7E turns all disk drive motors off, writing 01h turns all motors on. It is not possible to turn on/off the motor of a specific drive separately. An exception are the Vortex F1-S, F1-D, M1-S and M1-D drives. (How are they different?) Another exception is the Gotek drives. They don't take the motor flip-flop into account and are always on. [https://64nops.wordpress.com/2021/07/04/a-la-decouverte-du-fdc/ Source] Some FDC commands don't require the motor to be on. For example, the seek or recalibrate commands that move the floppy drive head work fine with the motor off. And seek/recalibrate also work with an empty drive (ie. without a floppy disk inserted). [https://64nops.wordpress.com/2021/07/10/a-la-decouverte-du-fdc-episode-2/ Source] The floppy disk rotates at a nominal speed of 300rpm, with some tolerance. This tolerance of the FDC has been measured by [[Roudoudou]] to be ±12% (it worked from 220 kbits/s to 283 kbits/s for a reference of 250 kbits/s). [https://64nops.wordpress.com/2021/09/02/a-la-decouverte-du-fdc-episode-4/ Source] The FDC speed is more impressive when you realize the Amstrad CPC’s tape loads at only 2 kbits/s in fast mode. Note: tape loading can be way faster than that if an MP3 player is used instead of a real physical tape, as it has been demonstrated here: https://youtu.be/MAIsOIwgJWA <br> == Notes ==
Before accessing a disk you should issue a ''recalibrate'' command to the drive to move the head backwards until the ''track zero'' signal from the drive is sensed by the FDC. The FDC will also set its track counter for that drive to zero.
The SYSTEM format is a VENDOR format with the addition of information to boot the CP/M on:
* Track 0: sectors &41(boot sector), &42(configuration sector), &48, &49
* Track 1: sectors &41, &46, &42, &47, &43, &48, &44, &49, &45
| 16–31 || Block IDs where to find the file data || 1 byte is used per 1KB block.
|}
 
Note: AMSDOS files are usually stored with an [[AMSDOS Header]] but can also be headerless. CP/M files do not have headers.
<br>
'''Sector''': The smallest physically addressable unit on a disk, 512 bytes in size on Amstrad CPC. CP/M accessed the disk at the sector level, though users typically worked with records.
 
<br>
 
==== File Headers ====
 
Cassette files are divided into 2KB blocks (then subdivided in 256-byte segments + CRC), each block being preceded by a 64-byte header.
 
AMSDOS files are usually stored with a 128-byte [[AMSDOS Header]] (based on cassette header) but can also be headerless, depending on the contents of the file. Unprotected ASCII files do not have header.
 
CP/M files do not have AMSDOS headers.
 
<br>
 
=== Random File Access ===
 
One of the major computing flaws of the Amstrad CPC machines has been the inability to handle simple Random Access Filing even when equipped with disc drives. The only way random access data handling was possible was if the program was written entirely in CP/M. [https://cpcrulez.fr/applications_bureau-random_accesss_database.htm Source]
 
Nowadays, files can be random accessed in SymbOS, so you can always set the current file pointer to any position in a file and load any amount of data in one step from this position (in CP/M this is at least possible in 128byte steps, in Unidos also byte-based). [https://www.cpcwiki.eu/forum/games/micro-machine-for-symbos-g9k/msg248806/#msg248806 Source]
<br>
RSX programs exist on top of AMSDOS to get up to 208 KB of usable space per side, by using 42 tracks with 10 sectors per track.
The problem with that is there is not much gap between sectors anymore, and so the diskette becomes very sensitive to rotation speed.
The FDC controller can be used to control 80-tracks and/or double sided drives, though AMSDOS doesn't support such formats. To use 80-track drives and/or dual-head drives, you need to use another CPC DOS instead of AMSDOS. The most popular one is [[ParaDOS]]. It can handle up to 796 KB instead of 178 KB for AMSDOS and it supports 22 different disk file formats, including the three standard AMSDOS ones.
There is also a special version of ParaDOS, called [[VaraDOS]], that supports the [[Vortex Format]].
 
[[UniDOS]] goes beyond and supports various mass-storage expansions, but also includes support for AMSDOS/ParaDOS floppy discs and tape.
<br>
The 765 FDC only supports the single-density IBM 3740 track format and the double-density IBM System/34 track format, which are the defacto standards for floppy disks in most computer systems. These formats have been created by an IBM engineer named Alan Shugart (not to be confused with Amstrad's CEO, Alan Sugar).
On Amstrad CPC, the [[File:FDC765 - FM and MFM MODE pin of the FDC is not connected. So the FM mode is unusable.png|900px]]
[[File:FDC765 Track FormatOn Amstrad CPC, the MFM MODE pin of the FDC is not connected. So the FM mode is unusable.png]]
On Amstrad CPC, an MFM track contains about 6250 raw bytes: 200 ms per track (at 300rpm) / 32 µs per byte (with a bit cell of 4µs). Fun fact: You can squeeze a few more bytes on disk by using a floppy drive that spins a little slower, and counting on the tolerance of the FDC to make that disk readable on unmodified floppy drives.
Notes:
* The Index Address Mark (IAM) signifies the beginning of a track.* The ID Address Mark (IDAM) marks the beginning of a sector's header.* The Data Address Mark DAM (DATA AMor DDAM) marks the beginning of the actual data in a sector.* There are 2 types of sectors based on their DATA AM value. Data Deleted data sectors are marked by an F8 byte instead of an FB byte.* In MFM encoding, while deleted sectors IDAM and DAM are marked always preceded by an F8 bytethree A1 bytes to help the FDC lock onto the data stream after a gap and accurately read the following datas. This is needed because MFM is more compact and harder to read than earlier encoding methods.
* Gaps are necessary to accommodate variations in rotation speed between different drives and avoid overlapping.
 
In MFM encoding, the IDAM and DATA AM are always preceded by three A1 bytes to help the FDC lock onto the data stream after a gap and accurately read the following datas. This is needed because MFM is more compact and harder to read than earlier encoding methods.
 
The CRC error-detecting code is initialised to FFFF. It is updated byte by byte and uses the CCITT-CRC16 algorithm. It is written after the ID and data fields of each sector in big-endian format (high byte first and then low byte).
 
The main competitor of the µPD765 FDC chip on the market was the WD179x FDC chip family. The primary difference between 765 and 179x controllers is that the 765 only does standard track formats (preamble, marks and data fields), while the 179x will write anything you tell it in the write track (formatting a track) mode.
<br>
The trick is that the FDC cannot unmagnetize portions of a sector or leave portions of a sector unmagnetized to recreate this effect on another floppy disk.
 
<br>
 
=== Error Detection ===
 
The FDC765 happens to use the exact same algorithm for error detection as the one the Amstrad firmware uses to check each 256-byte tape segments.
 
The CRC error-detecting code is initialised to &FFFF. It is updated byte by byte and uses the CCITT-CRC16 algorithm. It is written after the ID and data fields of each sector in big-endian format (high byte first and then low byte).
<br>
== FDC Block Diagram ==
 
The FDC chip is quite different from the other CPC chips. It contains its own internal CPU, ROM and RAM.
[[File:WDC37C65 block diagram.png|700px]]
=== Internal details of the chip ===
* Internally this is a microcoded part with a primative controller of NEC’s own design. Testing microcode embedded in a part can be troublesome. The uPD765 had a few extra gates associated with the DMA Request and DMA Ack pins. Presenting a certain illegal combination here places the part into a “test” mode and allows the sequencer microcode to be output on the normal Data pins. The sequencer microcode is responsible for high level commands such as Read Track, Recalibrate, Format Track, or Write Data. There is a similar test mode for the nano-code array which serializes data at the floppy disk head. [https://scarybeastsecurity.blogspothackaday.com/20202012/1108/reverse13/taking-engineeringa-forgottenlook-at-1970s.html The decapped photos of -ics/#comment-734991 Source] <br> === Intel 8271, 8272 FDC === NEC uPD765 (or just D765 ) is exactly the same chip as the 8272. NEC and Intel cross-licensed a bunch of IP back in the day. [https://forum.vcfed.org/index.php?threads/8272 chips-fdc-to-8-drive-connections.45816/#post-557651 Source] prove that  The 8272/µPD765 was the result of a cross-licensing deal between NEC D765 and Intel 8272 chips are identical.It was essentially NEC design. [https://classiccmp.org/mailman3/hyperkitty/list/cctalk@classiccmp.org/thread/MMWRWPGKWRVOLMUBIFQTZSCRRMF3YOXF/ Source]
* From [https://hackadayscarybeastsecurity.blogspot.com/20122020/0811/13/takingreverse-aengineering-look-atforgotten-1970s.html The decapped-ics/#comment-734991 a comment in the hackaday websitephotos of Intel 8271, NEC D765 and Intel 8272 chips]: "prove that NEC uPD765 Floppy Disk Controller: Internally this is a microcoded part with a primative controller of NEC’s own design. Testing microcode embedded in a part can be troublesome. The uPD765 had a few extra gates associated with the DMA Request D765 and DMA Ack pins. Presenting a certain illegal combination here places the part into a “test” mode and allows the sequencer microcode to be output on the normal Data pins. The sequencer microcode is responsible for high level commands such as Read Track, Recalibrate, Format Track, or Write Data. There is a similar test mode for the nano-code array which serializes data at the floppy disk headIntel 8272 chips are identical."
<br>
The IBM PC supports 3 standard diskette formats on a 5.25 inch drive:
* The earliest IBM PCs used single-sided, double density, 40 cylinders, 300 RPM, floppy drives which yield a capacity of 160 KB per side. And MS-DOS 1.0 only supported single-sided floppy drives.
* Double-sided floppy drives were introduced in the IBM PC in 1982 and are supported in MS-DOS 1.1. They originally had a capacity of 320 KB per diskette. MS-DOS 2.0 extended the capacity to 360 KB with a new disk format(9 sectors per track instead of 8). [https://minuszerodegrees.net/5150/early/5150_early.htm Source]
* A new floppy drive was introduced with the PC/AT in 1984. It is double sided, quad density, 80 cylinders, with a total capacity of 1.2 MB. The high density drive rotates at '''360 RPM''', so only 15 sectors can be written on a track instead of 18.
== FDD Block Diagram ==
[[File:Floppy Disk Drive - Block Diagram.png|700px]]
 
<br>
 
== Chip Variants ==
 
=== IC Models used in CPC ===
 
More than one manufacturer made 765 compatible ICs. These are the ones known to be used in the CPC by looking at pictures of CPC mainboards. All should operate almost identically.
 
* NEC D765AC [https://www.cpcwiki.eu/imgs/3/3c/CPC664_Z70205_MC0005B_PCB_Top.jpg Source]
* NEC D765AC-2 [https://www.cpcwiki.eu/imgs/4/45/CPC6128_PCB_Top_%28Z70210_MC0009A%29.jpg Source]
* UMC UM8272A [[Media:Amstrad cpc 6128 azerty (f) placa2.jpg|Source]]
* Zilog Z765APS [https://www.cpcwiki.eu/imgs/f/fb/CPC6128_Z70290_MC0020C_PCB_Top.jpg Source]
* [[Zilog]] Z0765A08PSC [https://www.cpcwiki.eu/imgs/6/67/CPC6128_PCB_Top_%28Z70290_MC0020F%29.jpg Source]
 
The following data seperators are used:
 
* FDC9216 [https://www.cpcwiki.eu/imgs/4/45/CPC6128_PCB_Top_%28Z70210_MC0009A%29.jpg Source]
* SED9420C [https://www.cpcwiki.eu/imgs/3/3c/CPC6128_PCB_Top_%28Z70290_MC0020A%29.jpg Source]
 
The CPC464, CPC472, 464 Plus and GX4000 are not equipped with a FDC chip.
 
All the floppy disk drive models used by Amstrad are referenced here: [https://www.cpcwiki.eu/index.php/Amstrad_FDD_part Amstrad FDD part]
 
=== Other Variants ===
 
NEC has developed various successors to the original uPD765, such as the uPD72065 (used in the [[Sharp X68000]]), uPD72067, and uPD72069.
 
Intel has also produced successors of the 8272, such as the 82072, 82077 and 82078.
 
The КР1810ВГ72А is a Soviet clone of the Intel i8272. It is used in the [[Aleste 520EX]] clone of the Amstrad CPC computer.
 
The [https://map.grauw.nl/resources/disk/toshiba_tc8566af.pdf Toshiba TC8566AF] is also a variant of the FDC765.
 
=== Competitors ===
 
The main competitor of the µPD765 FDC chip on the market was the WD179x FDC chip family. Its main differences are:
* the 765 has 3 scan commands, while the 179x has none.
* the 765 has 5 status registers, while the 179x only has one.
* the 765 has multi-byte "command phase", while commands are issued to the 179x by writing a single byte to the Command Register, after having set parameters in its dedicated registers.
* the 765 has multi-byte "result phase", while the 179x has none. After a command completes, all the status information is contained in the Status Register as a single byte.
* the 765 has drive select pins to directly select one of four floppy drives, while the 179x has none. Instead, external logic must be used to handle multiple drives.
* the 765 only does standard track formats (preamble, marks and data fields), while the 179x will write anything you tell it in the write track (formatting a track) mode.
 
Some other computers adopted 3inch floppy disks like Amstrad, but used different FDC chips:
* [[Oric-1/Atmos|Oric]] uses the WD1773 (Jasmin) or WD1793 (Microdisc) FDC chip
* [[Tatung Einstein]] uses the WD1770 FDC chip
 
Third-party 3inch floppy disk drives (like the Amdek Amdisk) were also available for many systems: Apple II, Atari 8-bit, Tandy CoCo, BBC Micro, etc..
<br>
* [[Media:UPD765_App_Note_Mar79.pdf| NEC uPD765 Datasheet preliminary (1979)]] [[Media:D765 NEC.pdf]] [[Media:UPD765-NEC.pdf]] [[Media:Z765A datasheet.pdf]] - uPD765 disc controller
* [[Media:Intel 8272A Datasheet preliminary (1982).pdf]] [[Media:Datasheet.hk_d8272a_2873060.pdf|Intel 8272A Datasheet (1986)]] [[Media:Floppy Disk Controller(FDC) UM8272A UM8272A-4.pdf]] - Licensed clone of the uPD765
* [[Media:WD37C65 datasheet.pdf]] - NEC 765 controller clone with onboard data seperator and AT/EISA compatibility
* [[Media:TN6-1 9216 Floppy Disk Data Separator Jun82.pdf]] [[Media:FDC9216 datasheet.PDF]] [[Media:SED9420.pdf]] - Data separators
* [[Media:DDI Schematic.png]] - DDI-1 Schematic (disc interface for CPC464)
*[http://quasar.cpcscene.net/doku.php?id=assem:fdc Quasar FDC documentation (in french)]
*[https://64nops.wordpress.com/2021/07/04/a-la-decouverte-du-fdc/ FDC blog articles (in french)]
*[https://en.wikipedia.org/wiki/History_of_the_floppy_disk History of the floppy disk] Wikipedia article
*[https://www.cpc-power.com/cpcarchives/index.php?page=articles&num=92 Floppy disk formats (in french)]
*[https://www.fvempel.nl/3bible.html The 3inch bible]
*[https://info-coach.fr/atari/hardware/FD-Hard.php Atari ST Floppy Drive hardware analysis]
*[https://map.grauw.nl/articles/low-level-disk/ MSX low-level disk storage article]
*[https://youtu.be/aoXr7Anr5DY Réparation de lecteurs Amstrad] [https://youtu.be/-A-USMg9xvE Un Gotek dans un CPC] [https://youtu.be/QPFVfgaMv68 Les disquettes : Le fonctionnement] [https://youtu.be/RMTYevdGH6I Les protections] by [[Rodrik Studio]]
*[https://github.com/dbalsom/fluxfox FluxFox] A floppy disk image library in Rust
 
<br>
[[Category:CPC Internal Components]][[Category:Programming]][[Category:DATA Storage]][[Category:Electronic Component]]
13,173
edits