FDCOPY.COM is a program supplied on Amstrad's website to convert DOS-formatted floppies to/from disc image files. When using image files, there are two formats it can use - compressed and uncompressed.
This is simply a dump of all the bytes on the disc, identical to that which would be produced by "dd if=/dev/fd0 of=filename".
FDCOPY detects the compressed form by checking if the filename ends in .CFI; it can also be forced to use compression with the undocumented /CI option. There is no 'magic number' to detect if an image file is compressed.
In the compressed format, the disc image is stored as a sequence of tracks. The image file doesn't contain a track count anywhere; FDCOPY depends on the first track containing a DOS boot spec to work out how many tracks there are. LIBDSK contents itself with just checking for EOF after processing each track.
Each track starts with a 2-byte little-endian word, which gives the number of disc bytes in this track (not including the length word itself):
DEFW length ;Track header DEFS length ;Track data, <length> bytes
The header is followed by one or more data blocks. A block can either be compressed or uncompressed.
A compressed block is 3 bytes long, and is formed:
DEFW repeats | 08000h ; Number of repetitions of the byte ; Bit 15 set to indicate compressed DEFB byte ; The byte to repeat
An uncompressed block is formed:
DEFW length ; Number of bytes in this block ; at most 7FFFh, but FDCOPY doesn't ; create blocks with more than 2400h ; bytes in them. DEFS length ; The bytes.
FDCOPY creates a compressed block for a run of 5 or more identical bytes.
There is no end-of-track marker; the end of the track can only be detected by comparing the track length word with the number of bytes decoded.