http://www.worldofspectrum.org/faq/reference/ports.htm http://www.cpctech.org.uk/docs/upd765a/necfdc.htm http:///Vintage/Schneider%20CPC/Das%20Schneider%20CPC%20Systembuch/z193.htm#A One Track on the Floppy Disk: Recording starts 92 bytes after start of index pulse. (TMS279X) CNT BYTE NAME ------------------------------------------- 80 4Eh GAP4A 12 00h SYNC 3 C2h IAM Byte 1…3 IAM (Index Address Mark) 1 FCh IAM Byte 4 s 50 4Eh GAP1/3 Gap1: 50 bytes; or Gap3: count programmable; dflt = 54 s 12 00h SYNC s s 3 A1h IDAM Byte 1…3 IDAM (Sector ID Address Mark) s 1 FEh IDAM Byte 4 s 1 TRACK_ID s 1 SIDE_ID s 1 SECTOR_ID s 1 LOG2_SECTOR_LENGTH log2(length_of_data) − 7 s 2 CRC CRC of [IDAM byte 1 … LOG2_SECTOR_LENGTH]; msb first s s 22 4Eh GAP2 ID gap s 12 00h SYNC s s 3 A1h DAM Byte 1…3 DAM or DDAM: FBh = DAM (Data Address Mark); F8h = DDAM (deleted DAM) s 1 FB/F8h DAM Byte 4 s nn DATA count as stored in LOG2_SECTOR_LENGTH s 2 CRC CRC of [DAM byte 1 … last byte of DATA]; msb first 652 4Eh GAP4B bis Indexsignal aktiv Anschluss im +3: -> kein DMA -> kein Interrupt -> keine MFM/FM-Umschaltung -> rw / seek mode: RW SEEK FLT_RES/STEP 0 STEP (fault reset always on) LC / DIR DIR DIR (step direction statt low current signal) EGAL FAULT/T0 0 TRACK0 (fault signal wird nicht ausgewertet) WPROT/2S WPROT WPROT (2sides-signal wird ignoriert) Access: Main Status Register r/- Data Register r/w FDC Commands: Command Parameters Exe Result Description %0ms00010 02+m+s HU TR HD ?? SZ NM GP SL S0 S1 S2 TR HD NM SZ READ TRACK %00000011 03 XX YY - SPECIFY: Laufwerksdaten (spd & dma) festlegen %00000100 04 HU - S3 SENSE DRIVE STATE: Statusregister 3 abfragen %tm000101 05+t+m HU TR HD SC SZ LS GP SL S0 S1 S2 TR HD LS SZ WRITE SECTOR(s) %tms00110 06+t+m+s HU TR HD SC SZ LS GP SL S0 S1 S2 TR HD LS SZ READ SECTOR(s) %00000111 07 HU - RECALIBRATE: Spur 0 suchen %00001000 08 - - S0 TP SENSE INTERRUPT STATE: Statusregister 0 abfragen %tm001001 09+t+m HU TR HD SC SZ LS GP SL S0 S1 S2 TR HD LS SZ WRITE DELETED SECTOR(s) %0m001010 0A+m HU - S0 S1 S2 TR HD LS SZ READ SECTOR ID %tms01100 0C+t+m+s HU TR HD SC SZ LS GP SL S0 S1 S2 TR HD LS SZ READ DELETED SECTOR(s) %0m001101 0D+m HU SZ NM GP FB S0 S1 S2 TR HD LS SZ FORMAT TRACK (WRITE ID) %00001111 0F HU TP - SEEK TRACK %tms10001 11+t+m+s HU TR HD SC SZ LS GP STP S0 S1 S2 TR HD LS SZ SCAN EQUAL %tms11001 19+t+m+s HU TR HD SC SZ LS GP STP S0 S1 S2 TR HD LS SZ SCAN LOW OR EQUAL %tms11101 1D+t+m+s HU TR HD SC SZ LS GP STP S0 S1 S2 TR HD LS SZ SCAN HIGH OR EQUAL t Bit7 Multi Track (continue multi-sector-function on other head) m Bit6 MFM-Mode-Bit (1=MFM) s Bit5 Skip-Bit (set if sectors with deleted DAM shall be skipped) Argument/Result bytes are: HU HeadUnit b01: Unit/Drive Number, b2: Head, b3…7: 0 TP RequestedTrack Physical Track Number TR TrackID usually same value as TP HD HeadID SC SectorID First Sector-ID to read or write SZ Log2SectorSize bytes_per_sector = 0x80 << SZ LS LastSectorID aka 'EOT' same as SectorID when reading single sector GP Gap3Len default=0x2A except command 0x0D: default = 0x52 SL SectorSize if Log2SectorSize = 0 (default = 0xFF) SRx Status Register x FB Fillbyte filler byte for sector data area (default = 0xE5) NM NumSectors (default = 9) XX b0…3: headunload n*32ms, b4…7: steprate (16-n)*2ms YY b0: DMA_disable, b1…7: headload n*4ms Interrupts: An interrupt signal is generated by the FDC for one of the following reasons: 1. Upon entering the Result phase of: a. Read Data command b. Read A Track command c. Read ID command d. Read Deleted Data command e. Write Data command f. Format A Cylinder command g. Write Deleted Data command h. Scan commands 2. Ready line of FDD changes state 3. End of Seek or Recalibrate command 4. During Executing phase in the non-DMA mode SPECIFY The Specify Command sets the initial values for each of the three internal timers. The HUT (Head Unload Time) defines the time from the end of the Execution Phase of one of the Read/Write Commands to the head unload state. This timer is programmable from 0 to 240 ms in increments of 16 ms (00 = 0 ms, 01 = 16 ms, 02 = 32 ms, etc.). The SRT (Step Rate Time) defines the time interval between adjacent step pulses. This timer is programmable from 1 to 16 ms in increments of 1 ms (F = 1 ms, E = 2 ms, D = 3 ms, etc,), The HLT (Head load Time) defines the time between when the Head load signal goes high and when the Read/Write operation starts. This timer is programmable from 2 to 256 ms in increments of 2 ms (00 = 2 ms, 01 = 4 ms, 02 = 6 ms, etc.). The time intervals mentioned above are a direct function of the clock (ClK on pin 19). Times indicated above are for an 8 MHz clock, if the clock was reduced to 4 MHz (mini-floppy application) then all time intervals are increased by a factor of 2. The choice of DMA or NON-DMA operation is made by the ND (NON-DMA) bit. When ND=1 then NON-DMA mode is selected, when ND=0 the DMA mode is selected. READ ID The FDC stores the values from the first ID Field it is able to read. If no proper ID Address Mark is found on the disk, before the INDEX HOLE is encountered for the second time then the MA (Missing Address Mark) flag in SR1 is set, and if no data is found then the NO (No Data) flag is also set in SR1. The command is then terminated with SR0 bit76 set to ICaborted. FORMAT TRACK The Format Command allows an entire track to be formatted. After the INDEX HOLE is detected, Data is written on the Disk; Gaps, Address Marks, ID Fields and Data Fields, all per the IBM System 34 (Double Density) or System 3740 (Single Density) Format are recorded. The particular format which will be written is controlled by the values programmed into N (number of bytes/sector), SC (sectors/cylinder), GPL (Gap Length), and D (Data Pattern) which are supplied by the processor during the Command Phase. The Data Field is filled with the Byte of data stored in D. The ID Field for each sector is supplied by the processor; that is, four data requests per sector are made by the FDC for C (Cylinder Number), H (Head Number), R (Sector Number) and N (Number of Bytes/Sector). This allows the diskette to be formatted with non-sequential sector numbers, if desired. After formatting each sector, the processor must send new values for C, H, R, and N to the µPD765 for each sector on the track. The contents of the R register is incremented by one after each sector is formatted, thus, the R register contains a value of R + 1 when it is read during the Result Phase. This incrementing and formatting continues for the whole cylinder until the FDC encounters the INDEX HOLE for the second time, whereupon it terminates the command. If a FAULT signal is received from the FDD at the end of a write operation, then the FDC sets the EC flag of SR0, and terminates the command after setting bits 7 and 6 of Status Register 0 to 0 and 1 respectively. Also the loss of a READY signal at the beginning of a command execution phase causes bits 7 and 6 of SR0 to be set to 0 and 1 respecitvely. Table 3 shows the relationship between N, SC, and GPL for various sector sizes: FORMAT SECTOR N SC GPL² GPL³ REMARKS SIZE 8" FM 128 0 26 07h 1Bh IBM Diskette 1 256 1 15 0Eh 2Ah IBM Diskette 2 512 2 8 1Bh 3Ah 1024 3 4 47h 8Ah 2048 4 2 C8h FFh 4096 5 1 C8h FFh MFM 256 1 26 0Eh 36h IBM Diskette 2D 512 2 15 1Bh 54h 1024 3 8 35h 74h IBM Diskette 2D 2048 4 4 ? ? 4096 5 2 C3h FFh 8192 6 1 C3h FFh 5.25" FM 128 0 18 07h 09h 128 0 16 10h 19h 256 1 8 18h 30h 512 2 4 46h 87h 1k 3 2 C8h FFh 2k 4 1 C8h FFh MFM 256 1 18 0Ah 0Ch 256 1 16 20h 32h 512 2 8 2Ah 50h 1k 3 4 80h F0h 2k 4 2 C8h FFh 4k 5 1 C8h FFh 3.5" FM 128 0 15 07h 1Bh 256 1 9 0Eh 2Ah 512 2 5 1Bh 3Ah MFM 256 1 15 1Bh 54h 512 2 9 1Bh 54h 1024 3 5 35h 74h ²) suggested gap length in READ or WRITE commands to avoid splice point between data field and ID field of contiguous sectors. ³) suggested gap length in FORMAT command In MFM mode the NEC765 cannot read/write/format 128 byte sectors. SCAN COMMANDS The SCAN Commands allow data which is being read from the disk to be compared against data which is being supplied from the main system (Processor in NON-DMA mode, and DMA Controller in DMA mode). The FDC compares the data on a byte-by-byte basis, and looks for a sector of data which meets the conditions of D(FDD) = D(Processor), D(FDD) ≤ DProcessor, or D(FDD) ≥ D(Processor). 0xFF = largest number, 0x00 = smallest number). After a whole sector of data is compared, if the conditions are not met, the sector number is incremented (R + STP -> R), and the scan operation is continued. The scan operation continues until one of the following conditions occur: the conditions for scan are met (equal, low, or high), the last sector on the track is reached (EOT), or the terminal count signal is received. If the conditions for SCAN EQUAL are met then the FDC sets the SH (Scan Equal Hit) flag of SR2, and terminates the Command, else if the conditions for scan are met then the FDC terminates the Command without setting the SH flag in SR2. If the conditions for scan are not met between the starting sector (as specified by R) and the last sector on the cylinder (EOT), then the FDC sets the SN (Scan Not Satisfied) flag of SR2, and terminates the Scan Command. The receipt of a TERMINAL COUNT signal from the Processor or DMA Controller during the scan operation will cause the FDC to complete the comparison of the particular byte which is in process, and then to terminate the command. If the FDC encounters a Deleted Data Address Mark on one of the sectors and SK = 0, then it regards the sector as the last sector on the cylinder, sets CM (Control Mark) flag of SR2 and terminates the command. If SK = 1, the FDC skips the sector with the Deleted Address Mark, and reads the next sector. In the second case (SK = 1), the FDC sets the CM flag of SR2 in order to show that a Deleted Sector had been encountered. When either the STP (contiguous sectors = 01, or alternate sectors = 02 sectors are read) or the MT (Multi-Track) are programmed, it is necessary to remember that the last sector on the track must be read. For example, if STP = 02, MT = 0, the sectors are numbered sequentially 1 through 26, and we start the Scan Command at sector 21; the following will happen. Sectors 21, 23, and 25 will be read, then the next sector (26) will be skipped and the Index Hole will be encountered before the EOT value of 26 can be read. This will result in an abnormal termination of the command. If the EOT had been set at 25 or the scanning started at sector 20, then the Scan Command would be completed in a normal manner. During the Scan Command data is supplied by either the processor or DMA Controller for comparison against the data read from the diskette. In order to avoid having the OR (Over Run) flag set in Status Register 1, it is necessary to have the data available in less than 27 µs (FM Mode) or 13 µS (MFM Mode). If an Overrun occurs the FDC ends the command with bits 7 and 6 of SR0 set to 0b01. READ TRACK This is a continuous READ operation where the entire contents of the track are read. Immediately after encountering the INDEX HOLE, the FDC starts reading all data on the track, Gap bytes, Address Marks and Data are all read as a continuous data stream, ignoring any CRC error. The FDC compares the ID information read from each sector with the value stored in the IDR, and sets the ND flag of SR1 if there is no comparison. Multi-track or skip operations are not supported with this command. The command terminates when EOT number of sectors have been read (EOTmax = 0xFF). If the FDC does not find an IDAM on the disk after it encounters the INDEX HOLE for the second time, then it sets the MA (missing address mask) flag in SR1, and terminates the command, setting SR0 bit76 to ICaborted. Note: Es fehlen Angaben: - terminal count (vermutlich ignoriert) - was genau passiert, wenn das Indexloch erneut gesehen wird, und den Befehl beendet. - ob der Befehl mit ICok oder ICaborted beendet wird, wenn EOT überschritten wird. READ DATA The FDC loads the head, if it is in the unloaded state and waits the specified head settling time. Then it begins reading ID Address Marks and ID fields. When the current sector number ("R") stored in the ID Register (IDR) compares with the sector number read off the disk, then the FDC outputs data from the data field byte-to-byte to the main system via the data bus. After completion of the read operation from the current sector, the Sector Number is incremented by one, and the data from the next sector is read and output on the data bus. This continuous read function is called a "Multi-Sector Read Operation." The Read Data Command may be terminated by the receipt of a Terminal Count signal. Upon receipt of this signal, the FDC stops outputting data to the processor, but will continue to read data from the current sector, check CRC the bytes, and then at the end of the sector terminate the Read Data Command. The "multi-track" function (MT) allows the FDC to read data from both sides of the diskette. For a particular cylinder, data will be transferred starting at Sector 0, Side 0 and completing at Sector L, Side 1 (Sector L = last sector on the side). Note, this function pertains to only one cylinder (the same track) on each side of the diskette. When N = 0, then DTL defines the data length which the FDC must treat as a sector. If DTL is smaller than the actual data length in a Sector, then the data beyond DTL in the Sector is not sent to the Data Bus. The FDC reads internally the complete Sector performing the CRC check, and depending upon the manner of command termination, may perform a Multi-Sector Read Operation. When N is non-zero, then DTL has no meaning and should be set to 0xFF. At the completion of the Read Data Command, the head is not unloaded until after Head Unload Time Interval has elapsed. If the processor issues another command before the head unloads then the head settling time may be saved between subsequent reads. If the FDC detects the Index Hole twice without finding the right sector, (indicated in "R"), then the FDC sets the ND (No Data) flag in SR1 and terminates the Read Data Command. (SR0 also has bits 7 and 6 set to 0 and 1 respectively.) After reading the ID and Data Fields in each sector, the FDC checks the CRC bytes. If a CRC error is detected the FDC sets the DE (Data Error) flag in SR1, and if a CRC error occurs in the Data Field the FDC also sets the DD (Data Error in Data Field) flag in SR2, and terminates the Read Data Command. (SR0 also has bits 7 and 6 set to 0 and 1 respectively.) If the FDC reads a Deleted Data Address Mark off the disk, and the SK bit (bit D5 in CMD) is not set (SK = 0), then the FDC sets the DM (Control Mark) flag in SR2, and terminates the Read Data Command, after reading all the data in the Sector. If SK = 1, the FDC skips the sector with the Deleted Data Address Mark and reads the next sector. During disk data transfers between the FDC and the CPU, the FDC must be serviced by the CPU every 27 µs in the FM Mode, and every 13 µs in the MFM Mode, or the FDC sets the OR (Over Run) flag in SR1, and terminates the Read Data Command. If the CPU 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 LS ('EOT') byte. Table 2 shows the values for C, H, R, and N, when the CPU terminates the Command. MT Final Sector Transfered ID Information at Result Phase to Processor C H R N -------------------------------------------------------------- 0 Sector 1 … EOT-1 C H R+1 N Sector EOT C+1 H 1 N 1 Sector 1 … EOT-1 C H R+1 N Sector EOT at Side 0 C H^1 1 N Sector EOT at Side 1 C+1 H^1 1 N WRITE DATA After the Write Data command has been issued the FDC loads the head, if it is in the unloaded state, waits the specified head settling time, and begins reading ID Fields. When the current sector number ("R"), stored in the ID Register (IDR) compares with the sector number read off the diskette, then the FDC takes data from the processor byte-by-byte via the data bus, and outputs it to the FDD. After writing data into the current sector, the Sector Number stored in "R" is incremented by one, and the next data field is written into. The FDC continues this "Multi Sector Write Operation" until the issuance of a Terminal Count signal. If a Terminal Count signal is sent to the FDC, it continues writing into the current sector to complete the data field. If the Terminal Count signal is received while a data field is being written then the remainder of the data field is filled with 0x00. The FDC reads the ID field of each sector and checks the CRC bytes. If the FDC detects a CRC error in one of the ID Fields, it sets the DE (Data Error) flag of SR1 and terminates the Write Data Command. (SR0 also has bits 7 and 6 set to 0 and 1 respectively.) The Write Command operates in much the same manner as the Read Command. The following items are the same, and one should refer to the Read Data Command for details: Transfer Capacity EN (End of Cylinder) Flag ND (No Data) Flag Head Unload Time Interval ID Information when the processor terminates command (see Table 2) Definition of DTL when N=0 and when N≠0 In the Write Data mode, data transfers between the processor and FDC, via the Data Bus, must occur every 31 ~µs in the FM mode, and every 15 µs in the MFM mode. If the time interval between data transfers is longer than this then the FDC sets the OR (Over Run) flag in SR1, and terminates the Write Data Command. (SR0 also has bit 7 and 6 set to 0 and 1 respectively.) SENSE INTERRUPT STATUS An Interrupt signal is generated by the FDC for one of the following reasons: 1. Upon entering the Result Phase of: Read Data Command Read a Track Command Read ID Command Read Deleted Data Command Write Data Command Format Cylinder Command Write Deleted Data Command Scan Commands 2. Ready Line of FDD changes state 3. End of Seek or Recalibrate Command 4. During Execution Phase in the NON-DMA Mode Interrupts caused by reasons 1 and 4 above occur during normal command operations and are easily discernible by the processor. However, interrupts caused by reasons 2 and 3 above may be uniquely identified with the aid of the Sense Interrupt Status Command. This command when issued resets the interrupt signal and, via bits 5, 6, and 7 of SR0, identifies the cause of the interrupt. Table Neither the Seek or Recalibrate Command have a Result Phase. Therefore, it is mandatory to use the Sense Interrupt Status Command after these commands to effectively terminate them and to provide verification of where the head is positioned (PCN). SENSE DRIVE STATUS This command may be used by the processor whenever it wishes to obtain the status of the FDDs. SR3 contains the Drive Status information. SEEK TRACK The read/write head within the FDD is moved from cylinder to cylinder under control of the Seek Command. The FDC compares the PCN (Present Cylinder Number) which is the current head position with the NCN (New Cylinder Numbed, and if there is a difference performs the following operation: PCN < NCN: Direction signal to FDD set to a 1 (high), and Step Pulses are issued. (Step In.) PCN> NCN: Direction signal to FDD set to a 0 (low), and Step Pulses are issued. (Step Out.) The rate at which Step Pulses are issued is controlled by SRT (Stepping Rate Time) in the SPECIFY Com- mand. After each Step Pulse is issued NCN is compared against PCN, and when NCN = PCN, then the SE (Seek End) flag is set in Status Register 0 to a 1 (high), and the command is terminated. During the Command Phase of the Seek operation the FDC is in the FDC BUSY state, but during the Execution Phase it is in the NON BUSY state. While the FDC is in the NON BUSY state, another Seek Command may be issued, and in this manner parallel seek operations may be done on up to 4 Drives at once. If an FDD is in a NOT READY state at the beginning of the command execution phase or during the seek operation, then the NR (NOT READY) flag is set in Status Register 0 to a 1 (high), and the command is terminated after bits 7 and 6 of Status Register 0 are set to 0 and 1 respectively. RECALIBRATE / SEEK TRACK0 The function of this command is to retract the read/write head within the FDD to the Track 0 position. The FDC clears the contents of the PCN counter, and checks the status of the Track 0 signal from the FDD. As long as the Track 0 signal is low, the Direction signal remains 1 (high) and Step Pulses are issued. When the Track 0 signal goes high, the SE (SEEK END) flag in Status Register 0 is set to a 1 (high) and the command is terminated. Ifthe Track 0 signal is still low after 77 Step Pulse have been issued, the FDC sets the SE (SEEK END) and EC (EQUIPMENT CHECK) flags of Status Register 0 to both 1s (highs), and terminates the command after bits 7 and 6 of Status Register 0 is set to 0 and 1 respectively. The ability to do overlap RECALIBRATE Commands to multiple FDDs and the loss of the READY signal, as described in the SEEK Command, also applies to the RECAll BRATE Command. INVALID If an invalid command is sent to the FDC, then the FDC will terminate the command after bits 7 and 6 of SR0 are set to ICinvalidCmd. A Sense Interrupt Status Command must be sent after a Seek or Recalibrate Interrupt, otherwise the FDC will consider the next command to be an Invalid Command. In some applications the user may wish to use this command as a No-Op command, to place the FOC in a standby state.