Introduction
A .nib file is what the Disk II drive reads off a floppy, not what the file system stores on it: the nibbles, the disk bytes, of each of the 35 tracks, 6,656 of them a track, 232,960 bytes in all. It keeps what a
sector image throws away: the volume number in every address field, the gaps, the order the sectors were written in, and checksums and sectors that are damaged or missing. Disks with
non-standard formats can therefore be kept, in the simplest cases, which a sector image cannot hold. The same extension is used for Cocoa interface files, which are not this format.
A track
Every disk byte has its high bit set, and no two zero bits in a row (so that the drive can keep time). Between the fields are gaps of $FF bytes. On the disk they are written as 10-bit self-sync bytes ($FF and two zero bits); in a .nib file they are plain $FF bytes. A track is a ring: reading wraps from its last byte to its first, and a field may straddle the join. A DOS 3.3 track of 16 sectors is about 6,400 nibbles (the tracks built for the tests here are 6,384: 48 sync bytes, then 16 sectors of 396) and the file pads the rest of the 6,656 with $FF.
Each sector is two fields:
The address field
| Bytes | Meaning |
|---|---|
| 3 | Prologue D5 AA 96 (D5 AA B5 for a 13-sector disk) |
| 2 | Volume number, 4-and-4 encoded |
| 2 | Track number, 4-and-4 |
| 2 | Sector number, 4-and-4: the physical position on the track (0 to 15), not the DOS or ProDOS logical number |
| 2 | Checksum: volume xor track xor sector, 4-and-4 |
| 3 | Epilogue DE AA EB (the last byte is often not read) |
4-and-4 puts one byte in two disk bytes: first (v >> 1) | $AA (the odd bits), then v | $AA (the even bits); a reader combines them with ((a << 1) | 1) & b. Volume 254 is FF FE.
The data field
| Bytes | Meaning |
|---|---|
| 3 | Prologue D5 AA AD |
| 342 | The sector's 256 bytes in the 6-and-2 encoding |
| 1 | Checksum |
| 3 | Epilogue DE AA EB |
6-and-2. A disk byte carries only 6 bits (only 64 bytes have no two adjacent zeros and the high bit set, the table 96 97 9A 9B 9D 9E 9F A6 A7 AB AC AD AE AF B2 B3 …FF), so 256 bytes are split into the top 6 bits of each (256 values) and the low 2 bits of each, packed 3 to a value (86 values). On the disk the 86 packed values come first. Value m of the 86 holds the low two bits (bit 0 and bit 1 swapped) of bytes m, m + 86 and m + 172, those of byte m in its lowest bits. The 256 six-bit values follow in byte order. Each of the 342 values is written as the exclusive-or of itself and the one before it, and the 343rd byte is the last value on its own: the checksum.
What was compared. The 64-byte table was read out of the KEGS emulator's source (to_disk_byte in iwm.c), and the encoding and decoding were compared with a port of KEGS's own routines (sector_to_partial_nib and the data part of iwm_denib_track525): the viewer's encoder is decoded by that port, and the viewer's decoder reads what the port encodes, on 40 test sectors including all zeros and all $FF. A NIB built from the real DOS 3.3 System Master disk with the viewer's encoder was also decoded by the port: all 560 sectors came back as the disk's own sectors. No real .nib file was available, so real gap lengths, sync patterns and half-tracks were not seen.
In the explorer
The tree has the 35 tracks and in each the fields in the order they are: gaps, address fields with their six parts, data fields with prologue, 342 encoded values, checksum and epilogue, named by the sector and the file it belongs to. A field that straddles the end of the track is shown in two parts. A checksum that is wrong, a missing field and a duplicate sector are problems of the track. The explorer takes the sectors by their physical numbers, builds the disk in DOS order and in ProDOS order, and keeps the order in which a file system reads (a tie goes to ProDOS order for a ProDOS disk and DOS order for the rest, since both give the same disk). The table of tracks lists the sectors decoded of each; the disk shown after that is the one a sector image would give.
Not described
Known, not yet covered
- Viewer: the 5-and-3 data field of 13-sector disks is recognised by its address field (
D5 AA B5) and reported as not decoded. - Viewer: 36-track and 40-track
.nibfiles, half-track images and 2IMG format 2 are not read; only the 232,960-byte form is. - Viewer: disks protected by non-standard fields (other prologues, data checksums that are meant to fail) show the sectors that decode and list the others.
Unknown
- Reference and viewer: no real
.nibis available here; every reading is of built files.
Variants
- Apple II sector image (.DSK, .DO, .PO) – the sectors with no header, in DOS or ProDOS order
- 2IMG disk image – a 64-byte header in front of the sectors
- NIB nibble image – the nibbles of each track as the drive reads them
- WOZ disk image – the bit stream of every track, in chunks
Links
Software
- AppleWin – Apple II emulator that loads .nib files (Windows)
- CiderPress II – tool to view and convert Apple II disk images (Windows, macOS, Linux)