TRS-80 DOS – TRSDOS v1.3 – Internals

Page Menu:

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 Range
Purpose
00-5F
Each of these 96 bytes represents a track on the disk, with each bit representing a granule.

Byte Range
Purpose
60-BF
Each of these 96 bytes represents a track on the disk, 00H is available and valid and FFH if not available or locked.

Byte Range
Purpose
CE-CF
This 2 byte location stores the hashed master disk password.
D0-D7
Diskette NAME, up to 8 characters.
D8-DF
Diskette CREATION DATE, up to 8 characters.
E0-FF
The 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:

Byte
Purpose
Byte
for BASIC
Meaning
for BASIC
00
Bit 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
5EH
5EH = 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)
01
File Creation MONTH
05H
05 = May
02
File Creation YEAR
51H
51H = 81 Decimal = 1981
03
Relative byte in the sector of the EOF
00H
Relative byte in the sector of the EOF is 00H
04
Logical Record Length
00H
Logical Record Length = 256
05-0C
Filename
42 41 53 49 43 20 20 20
“BASIC “
0D-FF
Extension
43 4D 44
“CMD”

Line 2

10H-11H
Update Password Hash (2 bytes)
00H 00H
 
12H-13H
Access Password Hash (2 bytes)
EFH 5CH
EF5CH which is code for “NO PASSWORD”
14H-15H
No. of Sectors (LSB,MSB)
14H 00H
0014H = 20 Decimal = 20 Sectors
16H …
File Extents
13 sets of 2-bytes each.
First is Track #
2nd is Encoded Grans
02H 87H
The 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 Offset
Purpose
00
This 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.
01
This 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)
02
Unused
03
File Buffer RAM Address
05
Buffer offset in the sector of the NEXT byte to be readh
06
Drive number of the file
07
Logical File Number (i.e., Directory Entry Number)
08
Byte offset in Sector of the last byte in the file
09
Logical Record Length
10
Relative Record Number of the NEXT SECTOR to read
12
Relative Recored Number of the LAST SECTOR in the file
14
Side Number of file
15
Unused
16
13 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

SYS0/SYS
Mandatory
Boot and resident part of the operating system. Must be present on any bootable disk
SYS1/SYS
Mandatory
TRSDOS command interpreter. Must be available on all SYSTEM disks.
SYS2/SYS
Mandatory
$OPEN and $INIT calls. Must be available on all SYSTEM disks.
SYS3/SYS
Mandatory
$CLOSE and $KILL calls. Must be available on all SYSTEM disks.
SYS4/SYS
Mandatory
System error dictionary. Note: Very Small; May Not Be Worth Deleting
SYS5/SYS
Optional
DEBUG command. May be deleted if you don’t need to use DEBUG.
SYS6/SYS
Optional
APPEND, ATTRIB, AUTO, BUILD, CLEAR, CLOCK, CREATE, DATE, DIR, DO, DUMP, ERROR, FREE, LIB, LOAD, PAUSE, PROT, RENAME, and TIME.
SYS7/SYS
Optional
BACKUP and FORMAT.
SYS8/SYS
Optional
HELP.
SYS9/SYS
Optional
COPY, DUAL, FORMS, KILL, MASTER, PATCH, RELO, ROUTE, SETCOM, and WP.
SYS10/SYS
Optional
$DSPDIR and BASIC Error Messages.
SYS11/SYS
Optional
LIST, PURGE, and TAPE.
SYS12/SYS
Optional
BASIC Commands: NAME and CMD “C”
SYS13/SYS
Optional
BASIC Commands: CMD “J”, CMD “O”, and CMD “X”
SYS14/SYS
Optional
$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 1
Byte 2
=Track #
1st Part of Byte 1
a/k/a Starting Granule
2nd Part of Byte 1
a/k/a Gran Count
00
05 00
05H = 000 00101
00H
000 Bin = 00 Decimal. * 3 = 00
00101 Bin = 05 Decimal. * 3 = 15
01
02 10
02H = 000 00010
10H
000 Bin = 00 Decimal. * 3 = 00
00010 Bin = 02 Decimal. * 3 = 06

So … Overlay 1 starts at Granule 0 on track 10H, and goes for 6 granules.

02
42 10
42H = 010 00010
10H
010 Bin = 02 Decimal. * 3 = 06
00010 Bin = 02 Decimal. * 3 = 06
03
83 10
83H = 100 00011
10H
100 Bin = 04 Decimal. * 3 = 12
00011 Bin = 03 Decimal. * 3 = 09
04
A1 10
A1H = 101 00001
10H
101 Bin = 05 Decimal. * 3 = 15
00001 Bin = 01 Decimal. * 3 = 03
05
A3 00
A3H = 101 00011
00H
101 Bin = 05 Decimal. * 3 = 15
00011 Bin = 03 Decimal. * 3 = 09
06
06 12
06H = 000 00110
12H
000 Bin = 00 Decimal. * 3 = 00
00110 Bin = 06 Decimal. * 3 = 18
07
46 01
46H = 010 00110
01H
010 Bin = 02 Decimal. * 3 = 06
00110 Bin = 06 Decimal. * 3 = 18
08
06 13
06H = 000 00110
13H
000 Bin = 00 Decimal. * 3 = 00
00110 Bin = 06 Decimal. * 3 = 18
09
05 14
05H = 000 00101
14H
000 Bin = 00 Decimal. * 3 = 00
00101 Bin = 05 Decimal. * 3 = 15
10
02 0F
02H = 000 00010
0FH
000 Bin = 00 Decimal. * 3 = 00
00010 Bin = 02 Decimal. * 3 = 06
11
A4 14
A4H = 101 00100
14H
101 Bin = 05 Decimal. * 3 = 15
00100 Bin = 04 Decimal. * 3 = 12
12
42 0F
42H = 010 00010
0FH
010 Bin = 02 Decimal. * 3 = 06
00010 Bin = 02 Decimal. * 3 = 06
13
82 0F
82H = 100 00010
0FH
100 Bin = 04 Decimal. * 3 = 12
00010 Bin = 02 Decimal. * 3 = 06
14
61 15
61H = 011 00001
15H
011 Bin = 03 Decimal. * 3 = 09
00001 Bin = 01 Decimal. * 3 = 03
15
FF FF
FFH
FFH
FF = Not Present
FF = 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:

Bit
Purpose
07
Must be set.
06-04
The 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-00
Overlay number being requested, maximum of 16 overlays possible in 4 bits.

Examples:

Reg A
Binary
Bits
06-04
Bits
03-00
Calls …
8A
10001010
000
1010
Routine 0 (000) of Overlay 10 (1010)
C1
11000001
100
0001
Routine 4 (100) of Overlay 1 (0001)
92
10010010
001
0010
Routine 1 (001) of Overlay 2 (0010)
A2
10100010
010
0010
Routine 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.