TR-DOS filesystem

From Sinclair Wiki
Jump to navigation Jump to search

The filesystem described here is used with Technology Research Ltd's Beta Disc and Beta 128 Disc disk interfaces. The TR-DOS operating system uses this filesystem.

Floppy disks formatted to 16 sectors per track, with 256-byte sectors. Either single-sided or double-sided disks may be used, and 40 or 80 tracks may be used per side.

The first track of the disk (h0t0s1..h0t0s15) contains the file descriptors (h0t0s1..h0t0s8) and the disk info (h0t0s9). The remaining space on this track is unused.

Space from h0t1s1 on a single sided disk or from h1t0s1 on a double sided disk can be allocated to files. The files are not fragmented.

File descriptor format

A file descriptors are 16 bytes length, so a disk can hold maximum 128 files (8×256/16). The maximum size of a file is 65535 byte.

Offset (dec) Offest (hex) Length (dec) Description
0 0x00 8 Filename, padded with spaces. (If first byte is 0x01 then file is deleted.)
8 0x08 1 File type (extension)
9 0x09 2
  • BASIC (B) files: Total file size including variables (But minus the bytes at the end containing the start line)
  • DATA (D) files: byte[0x09], 1x1yyyyy where x=0 for character arrays and x=1 for numeric arrays and y is undefined.
  • CODE (C) files: File start address little-endian format
  • Stream/other (#/?) files: not used
11 0x0b 2 for BASIC (B) files, start of the variables area within the file. All other files: file length.
13 0x0d 1 File length in sectors
14 0x0e 1 Starting sector
15 0x0f 1 Starting (logical) track

Note1: logical track numbering schema for double sided disks: 0 - h0t0, 1 - h1t0, 2 - h0t1 ... 79 - h1t39, 80 - h0t40 ... 159 - h1t79.

Note2: start line for basic programs is not saved in header file, indeed, it is stored directly at the end of file: after end of basic program (symbol #80), could be placed token #AA followed by little-endian word that reflects start line. See Example TR-DOS Basic file

Example file descriptors

BASIC

This is the directory entry for a small basic program with variables defined in it when it was saved. Note that for BASIC files, the referenced file sizes do NOT contain the additional bytes at the end of the file which are used to store the run line. This means if you are writing a program to manipulate these files, you must special case BASIC files to take these bytes into account. See Example TR-DOS Basic file for an example file.

The Raw dirent is as follows:

 62 61 73 69  63 20 20 20  42 EF 01 68  01 02 00 01  basic   B..h....
Offset (dec) Offest (hex) Bytes Content Description
0-7 00-07 62 61 73 69 63 20 20 20 "basic " Filename
8 08 43 "B" (Basic) File type
9-10 09-0A EF 01 495 bytes File size including variables area minus area at the end containing the line number.
11-12 0a-0b 68 01 360 bytes Pointer to the start of the variables area in the file.
13 0C 08 8 sectors long Number of sectors the file uses
14 0D 02 Start sector 2 Sector the file starts from (Note, sectors number from 0 regardless of the actual disk layout)
15 0E 01 Start logical track 1 Logical Track the file starts from. (Note, the tracks are encoded as CH, so for DS drives, track 0=C0H0, 1=C0H1, 2=C1H0, ect)

Numeric array

This is the directory entry for a numeric array of 3,2 and is of length 35 bytes. (See other articles on the encoding of arrays in saved files) The Raw dirent is as follows:

 6E 64 61 74  61 20 20 20  44 E1 5F 23  00 01 0B 01  ndata   D._#....
Offset (dec) Offest (hex) Bytes Content Description
0-7 00-07 6E 64 61 74 61 20 20 20 "ndata " Filename
8 08 44 "D" (Data) File type
9-10 09-0A E1 5F E1=11100001, Bit 6=1 marking a Numeric array. 5f value unused. Contains the marker for the array type, in this case, bit 6=1=Numeric array. Note the usage of bits 0-5 seem inconsistent, and don't necessarily contain the original variable name as they do in other media files, so its best to ignore them.
11-12 0a-0b 23 00 35 bytes long Length of the file
13 0C 01 1 sector long Number of sectors the file uses
14 0D 0B Start sector 11 Sector the file starts from (Note, sectors number from 0 regardless of the actual disk layout)
15 0E 01 Start logical track 1 Logical Track the file starts from. (Note, the tracks are encoded as CH, so for DS drives, track 0=C0H0, 1=C0H1, 2=C1H0, ect)

Character array

This is the directory entry for a character array of 10,5 and is of length 55 bytes. (See other articles on the encoding of arrays in saved files) The Raw dirent is as follows:

 63 64 61 74  61 20 20 20  44 A7 5F 37  00 01 0A 01  cdata   D._7....
Offset (dec) Offest (hex) Bytes Content Description
0-7 00-07 63 64 61 74 61 20 20 20 "cdata " Filename
8 08 44 "D" (Data) File type
9-10 09-0A A7 5F A7=10100111, Bit 6=0 marking a Character array. 5f value unused. Contains the marker for the array type, in this case, bit 6=0 =Character array. Note the usage of bits 0-5 seem inconsistent, and don't necessarily contain the original variable name as they do in other media files, so its best to ignore them.
11-12 0a-0b 37 00 55 bytes long Length of the file
13 0C 01 1 sector long Number of sectors the file uses
14 0D 0A Start sector 10 Sector the file starts from (Note, sectors number from 0 regardless of the actual disk layout)
15 0E 01 Start logical track 1 Logical Track the file starts from. (Note, the tracks are encoded as CH, so for DS drives, track 0=C0H0, 1=C0H1, 2=C1H0, ect)

CODE file

This is the directory entry for a CODE file saved with Start 30000 and length 2000 The Raw dirent is as follows:

 63 6F 64 65  20 20 20 20  43 30 75 D0  07 08 02 01  code    C0u.....
Offset (dec) Offest (hex) Bytes Content Description
0-7 00-07 63 6F 64 65 20 20 20 20 "code " Filename
8 08 43 "C" (Data) File type
9-10 09-0A 30 75 0x7530=30000 bytes Load address
11-12 0a-0b D0 07 0x07D0 = 2000 bytes Length of the file
13 0C 8 8 sectors long Number of sectors the file uses
14 0D 02 Start sector 2 Sector the file starts from (Note, sectors number from 0 regardless of the actual disk layout)
15 0E 01 Start logical track 1 Logical Track the file starts from. (Note, the tracks are encoded as CH, so for DS drives, track 0=C0H0, 1=C0H1, 2=C1H0, ect)

File types

  • B: Basic
  • C: Code
  • D: Data (array variable)
  • #: Sequential or Random access file

Disc information

Information for disc is stored at h0t0s9:

Offset (dec) Offest (hex) Length (dec) Description
0 0x00 1 :=0 - Signals end of catalogue (?)
1 0x01 224 Unused (Usually filled with zero - 0x00, but can be used for creation program, author, ect)
225 0xe1 2 First free sector address sec:track
227 0xe3 1 Disk type (0x16..0x19)
228 0xe4 1 Number of files on disk
229 0xe5 2 Number of free sectors on disk
231 0xe7 1 :=0x10 - TR-DOS ID
232 0xe8 1 Unused: 0x00
233 0xe9 9 Unused: 0x20 (space)
243 0xf3 1 Unused: 0x00
244 0xf4 1 Number of deleted files on disk
245 0xf5 8 Disk label
253 0xfd 3 End of disk info, filled with 0x00 (Unused?)

Disk types

  • 0x16: 80 tracks, double side
  • 0x17: 40 tracks, double side
  • 0x18: 80 tracks, single side
  • 0x19: 40 tracks, single side

See also

  • TRD format, a disk image format typically used for images of TR-DOS filesystems
  • SCL format, a compact representation of TR-DOS filesystem content

External links