ApriDisk file format

Header

The header is 128 bytes long. In all known examples it contains the C string

	"ACT Apricot disk image\032\004"
padded out to 128 bytes with zeros. LibDsk does not treat this as a magic number; it ignores it.

Sector records

The records for each sector now follow. In existing examples they are sorted by sector, head, cylinder; it is not known whether this is necessary for writing back. LibDsk does not sort ApriDisk files it generates, though ApriDisk files created by dsktrans will be in the correct order.

A sector header is at least 16 bytes long. It is formed:

	DD	item_type	;4 bytes, little-endian.
				;0xE31D0001 => sector
				;0xE31D0002 => comment
	DW	compression	;2 bytes, little-endian.
				;0x9E90 => not compressed
				;0x3E5A => compressed
	DW	header_size	;2 bytes, little-endian.
	DD	data_size	;4 bytes, little-endian. 
	DB	head		;Head ID, 0 or 1
	DB	sector		;Sector ID, 1 based
	DW	cylinder	;2 bytes, little-endian.
				;Cylinder ID, 0 based.

If the header_size is greater than 0x10, the remainder of the header then follows.

The data_size then gives the number of bytes to read. If the sector is not compressed, the bytes read will be the sector.

Compression

Compressed sectors use an RLE scheme:
	DW	count		;2 bytes, little-endian.
	DB	byte		;The byte to repeat count times. 

It is not known whether ApriDisk uses compression for any sectors except those in which all bytes are the same. LibDsk only generates a compressed sector if all bytes are the same.

Comment

After all the sectors, there may be a comment record. This is stored in the same way as a sector:

	DD	item_type	;4 bytes, little-endian.
				;0xE31D0001 => sector
				;0xE31D0002 => comment
	DW	compression	;2 bytes, little-endian.
				;0x9E90 => not compressed
				;0x3E5A => compressed
	DW	header_size	;2 bytes, little-endian.
	DD	data_size	;4 bytes, little-endian. 
	DB	0,0,0,0		;Unused

The comment itself is stored as an ASCII string, complete with terminating 0 byte. Newlines in it are stored as '\r' characters.