The bytes of a track block are the bits the drive head reads, most significant bit first, one after the other round the track. The code table is that of Wikipedia’s Group coded recording (Commodore section), fetched and compared with ours. The block layouts below are the standard description of the 1541’s disk format, written from it; no second source was fetched on the day (the page says so under Not described on the overview).
The 4-to-5 bit code
Every 4-bit nibble is written as a 5-bit group, so that the stream never holds more than two zero bits or four one bits in a row inside data, which leaves a run of ten or more one bits to mean “sync”.
| Nibble | Group | Nibble | Group |
|---|---|---|---|
| 0 | 01010 ($0A) | 8 | 01001 ($09) |
| 1 | 01011 ($0B) | 9 | 11001 ($19) |
| 2 | 10010 ($12) | A | 11010 ($1A) |
| 3 | 10011 ($13) | B | 11011 ($1B) |
| 4 | 01110 ($0E) | C | 01101 ($0D) |
| 5 | 01111 ($0F) | D | 11101 ($1D) |
| 6 | 10110 ($16) | E | 11110 ($1E) |
| 7 | 10111 ($17) | F | 10101 ($15) |
Four bytes (eight nibbles) become five bytes (forty bits). A group not in the table is a decoding error; the viewer drops the block.
Sector header and data blocks
A sync mark (ten or more one bits) is followed by a block that starts at the first zero bit. The viewer decodes the first byte of the block and goes on by it:
| Block | Decoded bytes |
|---|---|
| Header, 8 bytes (80 bits) | $08; a checksum (the exclusive or of the next four bytes); the sector; the track; the disk ID’s second and first characters; $0F $0F |
| Data, 260 bytes (2,600 bits) | $07; the 256 bytes of the sector; a checksum (the exclusive or of the 256 bytes); $00 $00 |
Between them the drive writes gap bytes and a second sync mark. A data block belongs to the header before it; the track is read as a circle, so a block that runs past the end of the stream continues at its start and a sync mark may be split across the end. The viewer pairs each header with the next data block, checks both checksums and lists the sector.
Rebuilding a D64
When tracks 1 to 35 of a GCR-1541 file are all present, the viewer offers “disk.d64”: the sector data of every sector in D64 order. A sector with no good header gets zero bytes and an error byte of 2 (header block not found); one whose data checksum differs keeps its bytes and gets error byte 5 (checksum error in data block); the file then has error bytes after the sectors, as a D64 with error bytes. The number of sectors a track should have is that of the 1541 zones.
Not described
Known, not yet covered
- Gap lengths, the speed zones’ bit rates and the byte count of each track (the viewer decodes by bits and does not need them).
- Copy-protection constructions: blocks with other first bytes, tracks with no sync, density tricks, and half tracks.
Unknown
- The header and data layouts above rest on the standard description and were checked only against our own encoder.