This document describes the format of L and D/E format directories.

For both formats the directory is arranged as follows:
DirHeader
Entries[n]
DirTail

The header and tail contain information about this directory, and the
entries are the directory entries.

The two directory formats have the same DirHeader:
Name            Bytes
StartMasSeq     1       Update sequence number to check dir start with dir end
StartName       4       'Hugo'; 'Nick'

The two directory formats have mostly the same entry format:
Name                    Bytes
DirObName               10
DirLoad                 4
DirExec                 4
DirLen                  4
DirIndDiscAdd           3
OldDirObSeq/NewDirAtts  1

The DirTail formats are quite different:

Old:
Name            Bytes
OldDirLastMark  1       0 to indicate end of entries
OldDirName      10      Directory name
OldDirParent    3       Indirect disc address of parent
OldDirTitle     19      Directory title
Reserved        14      unused (padding)
EndMasSeq       1       To match with StartMasSeq
EndName         4       'Hugo'; 'Nick'
DirCheckByte    1       Check byte on directory

New:            Bytes
NewDirLastMark  1       0 to indicate end of entries
Reserved        2       unused (padding)
NewDirParent    3       Indirect disc address of parent
NewDirTitle     19      Directory title
NewDirName      10      Directory name
EndMasSeq       1       To match with StartMasSeq
EndName         4       'Hugo'; 'Nick'
DirCheckByte    1       Check byte on directory

The directory sizes are:
Old:
&500 (1280) bytes/47 entries
New:
&800 (2048) bytes/77 entries

There should be an exact number of entry slots between the headers and tails
of both formats of directory (hence the padding). The last entry is
indicated by there being a 0 in the first byte of the next entry's DirObName
(hence xxxDirLastMark is there to indicate end of directory when the
directory is full). DirNames are control character terminated and may be the
full length of the field they sit in (in which case there is no terminator).

Calculating StartMasSeq and EndMasSeq:
StartMasSeq and EndMasSeq are there to check whether the directory was
completely written out when it was last written out. For an unbroken
directory they are always equal, and are increased by one (wrapping at 255
back to 0) whenever the directory is updated. This means that if the writing
of the directory was stopped halfway through then the start and end master
sequence numbers will not be the same, and so the directory will then be
identified as broken. Their values should equal each other, but, apart from
that, they can be anything.

Calculating DirCheckByte:
This is an accumulation of the used bytes in a directory. The used bytes are
all the bytes excluding the hole between the last directory entry and the
beginning of the structure at the tail of the directory. The generation of
the check byte is best described as an algorithm:
*  Starting at 0 an accumulation process is performed on a number of values.
Whatever the sort of the value (byte or word) it is accumulated in the same
way. Assuming r0 is the accumulation register and r1 the value to accumulate
this is the accumulation performed:
 EOR r0, r1, r0, ROR #13
*  All the whole words at the start of the directory are accumulated. This
will leave a number of bytes (0 to 3) in the last directory entry (or at the
end of the start structure in a directory if it's empty).
*  The last few bytes at the start of the directory are accumulated
individually.
*  The first few bytes at the beginning of the end structure of the
directory are accumulated. This is done to leave only a whole number of
words left in the directory to be accumulated.
*  The last whole words in the directory are accumulated, except the very
last word which is excluded as it contains the check byte.
*  The accumulated word has its four bytes exclusive-ored (EOR) together.
This value is the check byte.

The above description was written down from reading the FileCore code, so I
don't know whether a routine following this description will generate a
correct check byte.

