Wednesday 25 September 2013

Floppy Disk Format From Bytes to Bits

Floppy Disk Track Format

The original TRS-80 Expansion Interface supported single-sided, single-density floppy disks with 35 tracks and ten sectors per track with 256 bytes per sector. The floppy disk controller supported many more format variations, but this was the standard format used on the first systems sold.

The actual track data contains padding bytes at the start of the track and between sectors. Each sector starts with a header that contains a special address byte followed by the track number, the head number (used in later drives), the sector number, a sector length code and a two byte CRC.

A typical track layout would look something like this:

  • 16 bytes of 0xFF
  • 6 bytes of 0x00
  • 1 byte ID Address Mark - 0xFE (with special bit pattern)
  • 1 byte track number (0x00 for track zero)
  • 1 byte head number (always 0x00 for original TRS-80 drives)
  • 1 byte sector number (sector numbers start at zero)
  • 1 byte sector length code (always 0x01 for standard format)
  • 2 byte CRC (calculated by the floppy disk controller)
  • 256 bytes of sector data
  • 11 bytes of 0xFF for sector 0, 12 bytes of 0xFF for all other sectors
  • 6 bytes of zero
  • 1 byte Data Address Mark - 0xFB (with special bit pattern)
  • 256 bytes of sector data.
  • 2 byte CRC (calculate by the floppy disk controller)
  • 12 bytes of 0xFF
  • 6 bytes of 0x00
  • Then nine more sectors as above, starting with another ID Address Mark
  • Finish with a bunch of 0xFF until the sector is finished. Typically around 130 bytes.
The extra zeros and 0xFF between the sectors headers and sector data allow the floppy disk controller to synchronize to the data stream while waiting for the special address marks. Since the drive speed can vary slightly between drives, especially on older models drives, sectors can be slightly shorter or longer. The padding allows room for these speed variations and on a disk that's been written on different drives there may be slight variations in the number of padding bytes.

Soon after the introduction of the original floppy disk drives, third-party manufacturers started to offer disks with 40 and even 80 tracks. 80 track drives had twice as many tracks per inch and therefore floppy disks formatted on those drives could not be read or written in older 35/40 track drives.

Data Encoding

The actual data on a single density floppy disk is written using a scheme called FM - Frequency Modulation. In FM encoding each byte is represented by a stream of clock bits and data bits.


The picture above is from an actual floppy disk as captured by a Saleae Logic Analyzer with the data bits colored red and the clock bits colored blue. The picture represents a single byte of data. Since all the data bits are present, the byte is 0xFF. If none of the data bits were present and only the clock bits appeared, the byte would be 0x00. On the TRS-80 Model I with single-density the clock and data bits are 1 microsecond wide and the gaps between clock and data bits are 3 microseconds wide. That corresponds to 8 microseconds per bit.

For all normal data bytes from 0x00 to 0xFF the clock bits are always present and the data bits are present or missing according to what byte value is represented. However, there are seven special address mark exceptions to this rule which are used by the 1771 floppy disk controller. These are 0xF8 through 0xFE but with certain clock bits missing. The missing clock bits allow the floppy disk controller to find these address marks in the stream of bits coming from the drive.

The Address Marks look like this:

'Deleted' Address Mark 0xF8

Non Standard Address Mark 0xF9 (only used by 1771 FDC)

Non Standard Address Mark 0xFA (only used by 1771 FDC)

Data Address Mark 0xFB
'Index' Address Mark 0xFC

Address Mark 0xFD
'ID' Address Mark 0xFE





Two file formats that are commonly used to store TRS-80 floppy disk as files are described here. When turning these formats into raw bit data the correct bit patterns for both normal data bits and the address marks need to be generated. Therefore knowledge of the address marks is important for correct emulation. The emulator will also have to add the various padding bytes to create a complete bit image of a track. Since the drive rotates at a speed of 300 rpm an ideal track should contain 50,000 bits of raw data (including both clock and data bits) which will take 0.2 seconds to transmit at a data rate of 4 microseconds per bit.

No comments:

Post a Comment