TRS-80 DOS - TRSDOS v1.3 - Internals

Overview of the TRSDOS v1.3 Directory Structure

The TRSDOS v1.3 directory is located on Track #17 (11H), and occupies the entire track. Because of the Model-III's double density format, this amounts to 18, 256 byte sectors. The first sector (#0) contains the Granule Allocation Table (GAT), the diskette Master Password encode, the diskette name and any AUTO command which may be active. Sector #1 contains the Hash Index Table (HIT) and the information by which TRSDOS is able to locate the SYSTEM files. The remaining sixteen sectors of the directory track contain the directory entries for the diskettes user files, five entries per sector.

The Granule Allocation Table

The GAT is stored at sector 01 of Track 17. The first 40 bytes (00H to 27H) make up the GAT and represent Tracks 0 to 39 on the diskette. Each byte is a "bit map" of the allocated granules in the corresponding track. Bits 0 through 5 represent the 6 granules of the track and bits 6 and 7 are not used (always 0). Thus, a fully allocated track would appear as a '3F' in the GAT. In binary this would be 00111111. If a byte is '25', a binary 00100101, it means that the first, third and sixth granules are allocated.

Bytes CEH and CFH of Sector #0 are the encoded Master Password for the diskette. This is normally D38F for "PASSWORD". Bytes D0H - DFH are the diskette's name in ASCII and the creation date in MM/DD/YY format. Bytes E0H - FFH are used to store any AUTO command which may have been set up for the diskette. If byte E0H is a '0D' (carriage return), no AUTO command is in effect.

The detailed layout is:

Byte RangePurpose
00-5FEach of these 96 bytes represents a track on the disk, with each bit representing a granule.
Byte RangePurpose
60-BFEach of these 96 bytes represents a track on the disk, 00H is available and valid and FFH if not available or locked.
Byte RangePurpose
CE-CFThis 2 byte location stores the hashed master disk password.
D0-D7Diskette NAME, up to 8 characters.
D8-DFDiskette CREATION DATE, up to 8 characters.
E0-FFThe AUTO command, up to 32 characters.

The Hash Index Table

The HIT sector is stored in sector 02 of Track 17. The detailed layout is:

The first 80 bytes (00H to 4FH) make up the Hash Index Table (HIT). Each non-zero byte is the hash code for an active file in the directory, and its position in the HIT indicates in which sector and where in the sector the directory entry is located. For example, on a standard Radio Shack TRSDOS diskette, the first two bytes are 'F0' and 'F4', which are the hash codes for BASIC/CMD and CONVERT/CMD. A glance at Sector #2 will confirm that these files are the first two entries in that sector. The Model-III uses the same algorithm as the Model-I for computing hash codes.

Bytes E0H - FDH are used to store the size and location of the TRSDOS SYSTEM files. There are 15 pairs of bytes and each pair represent one of the SYS files. The first byte of the pair contains the granule offset and the size of the file in granules. The second byte of the pair is the number of the track in HEX where the file starts. To see how this works, let's take a look at bytes E4H-E5H which are '4210'. The '42' is 01000010 in binary notation. Because the byte has two pieces of information embedded in it, we'll write it as 010 00010. The '00010' is the granule count for the file, which is TWO. The '010' is the granule offset from the start of the track which is also TWO. Remember that a granule is three sectors in the Model-III. The second byte of the pair is '10' which means that the file starts on Track #16 (10H). Putting it all together, we see that the file starts on Track #16 (10H), beginning on Sector #6 (offset of TWO granules) and occupies TWO granules or six sectors. This particular file, by the way, is very similar to SYS2/SYS on the Model-I. The fifteen pairs of bytes in this area represent the TRSDOS resident module and fourteen overlay modules making up the entire DOS. The sixteenth pair is presently 'FFFF' and is not in use, no doubt being reserved for a future overlay, like a spooler (just a guess). Since the user never calls the DOS modules directly, they need not have names and the information in these byte pairs is all that TRSDOS needs in order to locate them when program execution calls for them.

The Directory

The directory is stored in sectors 3-17 of Track 17, with 5 entries per sector. There is room for five, three line (48 byte) directory entries on each of these sixteen sectors. This gives a total capacity of 80 named files. The sixteenth line on each sector is not used, so Radio Shack placed a '(c) 1980 Tandy' on it as a filler.

It is important to note that the order of the extents is switched between the directory and the overlays. A detailed explanation of extents is found in the overlays section, below, but in the directory the order is TRACK NUMBER / ENCODED GRANS instead of ENCODED GRANS / TRACK NUMBER

The detailed layout is:

Line 1

BytePurposeByte
for BASIC
Meaning
for BASIC
00Bit 7: EITHER Unused or
0=Primary Directory Entry
1=Extended Directory Entry
Bit 6: 1=SYSTEM FILE, 0=User
Bit 5: 1=Limited Backups
Bit 4: 1=Is Assigned a HIT entry
Bit 3: 1=Invisible
Bits 2,1,0 = Security Access Level
5EH5EH = 01011110
Bit 7: Primary Directory Entry
Bit 6: 1=SYSTEM FILE
Bit 5: 0=Unlimited Backups
Bit 4: 1=Entry is Assigned
Bit 3: 1=Invisible
Bits 2,1,0 = 110 = 6 (i.e., Execute only)
01File Creation MONTH05H05 = May
02File Creation YEAR51H51H = 81 Decimal = 1981
03Relative byte in the sector of the EOF00HRelative byte in the sector of the EOF is 00H
04Logical Record Length00HLogical Record Length = 256
05-0CFilename42 41 53 49 43 20 20 20"BASIC   "
0D-FFExtension43 4D 44"CMD"

Line 2

BytePurposeByte
for BASIC
Meaning
for BASIC
10H-11HUpdate Password Hash (2 bytes)00H 00H 
12H-13HAccess Password Hash (2 bytes)EFH 5CHEF5CH which is code for "NO PASSWORD"
14H-15HNo. of Sectors (LSB,MSB)14H 00H0014H = 20 Decimal = 20 Sectors
16H ...File Extents
13 sets of 2-bytes each.
First is Track #
2nd is Encoded Grans
02H 87HThe file starts on Track # 02H
87H = 100 00111 = 4/7
Starts at Gran 12 (4*3) and continues for 21 (7*3) Grans.

The File Control Block

FCB OffsetPurpose
00This byte identifies the TYPE of FCB. Bit 0:
1=Read Only
Bit 1: 1=Write Only
Bit 4: 1=The next 2 bytes are simply the address of another FCB
Bit 7=1: Then the next 50 bytes are the description of an open file.
01This byte identifies the I/O OPTIONS of the file.
Bit 7: 0=Full Sector I/O
Bit 6: 0=Update the EOF when done
Bit 5: 1=Sector is already loaded into the RAM buffer
Bit 4: 1=The RAM buffer needs to be written to disk
Bit 3: 1=Remove all unused grans after the EOF on CLOSE
Bits 2-0: File Access Level (0-7)
02Unused
03File Buffer RAM Address
05Buffer offset in the sector of the NEXT byte to be readh
06Drive number of the file
07Logical File Number (i.e., Directory Entry Number)
08Byte offset in Sector of the last byte in the file
09Logical Record Length
10Relative Record Number of the NEXT SECTOR to read
12Relative Recored Number of the LAST SECTOR in the file
14Side Number of file
15Unused
1613 2-byte file extents. Each identifies a contiguous block of up to 32 grans for that file, with the first byte being the track number of the start of the extent or FE/FF if it is the end of the extent. The second byte is the number of contiguous grans in that extent (=Bits 0-4) AND the offset into the track of the starting gran (=Bits 7-5).

OVERLAY FILES

What each System/Overlay file does

SYS FileRequired?Purpose
SYS0/SYSMandatoryBoot and resident part of the operating system. Must be present on any bootable disk
SYS1/SYSMandatoryTRSDOS command interpreter. Must be available on all SYSTEM disks.
SYS2/SYSMandatory$OPEN and $INIT calls. Must be available on all SYSTEM disks.
SYS3/SYSMandatory$CLOSE and $KILL calls. Must be available on all SYSTEM disks.
SYS4/SYSMandatorySystem error dictionary. Note: Very Small; May Not Be Worth Deleting
SYS5/SYSOptionalDEBUG command. May be deleted if you don't need to use DEBUG.
SYS6/SYSOptionalAPPEND, ATTRIB, AUTO, BUILD, CLEAR, CLOCK, CREATE, DATE, DIR, DO, DUMP, ERROR, FREE, LIB, LOAD, PAUSE, PROT, RENAME, and TIME.
SYS7/SYSOptionalBACKUP and FORMAT.
SYS8/SYSOptionalHELP.
SYS9/SYSOptionalCOPY, DUAL, FORMS, KILL, MASTER, PATCH, RELO, ROUTE, SETCOM, and WP.
SYS10/SYSOptional$DSPDIR and BASIC Error Messages.
SYS11/SYSOptionalLIST, PURGE, and TAPE.
SYS12/SYSOptionalBASIC Commands: NAME and CMD "C"
SYS13/SYSOptionalBASIC Commands: CMD "J", CMD "O", and CMD "X"
SYS14/SYSOptional$FILPTR and $RAMDIR calls.

Location of each System/Overlay File

The HIT table for the overlays are found in bytes E0-FF of sector 02 of Track 17. They are 2 byte pairs in the order of the overlay. The first byte in each pair is the coded for the starting granule on the track and the number of grans it takes, and the second byte in each pair is the track.

Since TRSDOS v1.3 uses Granule sizes of 3, every item dealing with Granules must be multplied by 3.

A HIT entry of FF means Not Present.

Overlay
Number
HIT
Entry
Byte 1Byte 2
=Track #
1st Part of Byte 1
a/k/a Starting Granule
2nd Part of Byte 1
a/k/a Gran Count
0005 0005H = 0000010100H000 Bin = 00 Decimal. * 3 = 0000101 Bin = 05 Decimal. * 3 = 15
0102 1002H = 0000001010H000 Bin = 00 Decimal. * 3 = 0000010 Bin = 02 Decimal. * 3 = 06
 So ... Overlay 1 starts at Granule 0 on track 10H, and goes for 6 granules.
0242 1042H = 0100001010H010 Bin = 02 Decimal. * 3 = 0600010 Bin = 02 Decimal. * 3 = 06
0383 1083H = 1000001110H100 Bin = 04 Decimal. * 3 = 1200011 Bin = 03 Decimal. * 3 = 09
04A1 10A1H = 1010000110H101 Bin = 05 Decimal. * 3 = 1500011 Bin = 03 Decimal. * 3 = 09
0606 1206H = 0000011012H000 Bin = 00 Decimal. * 3 = 0000110 Bin = 06 Decimal. * 3 = 18
0746 0146H = 0100011001H010 Bin = 02 Decimal. * 3 = 0600110 Bin = 06 Decimal. * 3 = 18
0806 1306H = 0000011013H000 Bin = 00 Decimal. * 3 = 0000110 Bin = 06 Decimal. * 3 = 18
0905 1405H = 0000010114H000 Bin = 00 Decimal. * 3 = 0000101 Bin = 05 Decimal. * 3 = 15
1002 0F02H = 000000100FH000 Bin = 00 Decimal. * 3 = 0000010 Bin = 02 Decimal. * 3 = 06
11A4 14A4H = 1010010014H101 Bin = 05 Decimal. * 3 = 1500100 Bin = 04 Decimal. * 3 = 12
1242 0F42H = 010000100FH010 Bin = 02 Decimal. * 3 = 0600010 Bin = 02 Decimal. * 3 = 06
1382 0F82H = 100000100FH100 Bin = 04 Decimal. * 3 = 1200010 Bin = 02 Decimal. * 3 = 06
1461 1561H = 0110000115H011 Bin = 03 Decimal. * 3 = 0900001 Bin = 01 Decimal. * 3 = 03
15FF FFFFHFFHFF = Not PresentFF = Not Present

Calling an Overlay in Assembly

TRSDOS v1.3 operates via OVERLAYS which are loaded into RAM as called. To trigger an OVERLAY load, the RST 28H instruction is used, with Register A pre-loaded with a value signifying what is wanted. Register A is set as follows:

BitPurpose
07Must be set.
06-04The routine number of the overlay being requested, so, in combination with a set Bit 7, the possible entries are 80H, 90H, A0H, B0H, C0H, D0H, E0H, and F0H.
03-00Overlay number being requested, maximum of 16 overlays possible in 4 bits.

Examples:

Reg ABinaryBits
06-04
Bits
03-00
Calls ...
8A100010100001010Routine 0 (000) of Overlay 10 (1010)
C1110000011000001Routine 4 (100) of Overlay 1 (0001)
92100100100010010Routine 1 (001) of Overlay 2 (0010)
A2101000100100010Routine 2 (010) of Overlay 2 (0010)

Note: If a routine is called which does not exist, the overlay load routine returns right back; albeit with the overlay having been loaded.