Memory Organization
The TRS-80 Disk Operating System is comprised of 1K of ROM resident CIO (Character-oriented I/O) drivers and 4K of RAM drivers, schedulers, tables, pointers, etc. The ROM resident CIO drivers are also used by LEVEL II BASIC and therefore are part of its 12K ROM requirement.
Since LEVEL II is upward compatible with DISK BASIC, an additional 0.5K of RAM is required for both versions of BASIC. This means that user memory starts at hex 5200, resulting in 11.5K of user RAM in a 16K machine.
Note: The memory which is completely untouched by both TRSDOS and DISK BASIC code begins at hex 7000.
TRSDOS is comprised of a resident system and several overlays which are loaded from disk as the need arises (for example, to open or close a file). The system has a modular design. System entry-point vectors are in the lowest portion of the 4K RAM, followed by the interrupt handling, disk file handling, task scheduling and general purpose resident system routines. System buffers and overlays comprise the last portion of the 4K RAM requirement.
Since all major system commands are actually loaded as needed from disk in the form of utilities (the “library commands” and the extended utility programs), the TRSDOS system facilities can easily be enhanced without affecting the RAM memory requirement.
Disk Organization
Each TRSDOS system diskette contains a TRSDOS system, a utility command library, a file directory, and system tables. The minimum system overhead amounts to one full track of directory information and a half track of TRSDOS bootstrap program and other information.
This means that every TRSDOS diskette is self-loading, although it may or may not actually contain the TRSDOS system. This is done to prevent the Computer from attempting to bootstrap a diskette containing only user data files.
The utility command library is optionally available on the diskette. Since the utility command programs are not always required, it will often be advantageous for multi-drive users to format diskettes for use in drives 1 through 3. Such “data diskettes” contain a minimum of system code, leaving more space for user files.
Maximum file size is limited only by the physical size of the diskette, since a file must be wholly contained on one diskette. Each diskette is single-sided and has 35 tracks of information. Each track contains 10 sectors of 256 bytes each.
Normally, data read/write operations may only be initiated at sector boundaries, and must consist of exactly 256 bytes. However, TRSDOS allows the user to have maximum flexibility with minimal effort by automatically blocking and de-blocking all file accesses to user-specified logical record lengths, even if this requires “spanning” of two sectors.
The system disk file structure allows maximum use of disk file space by automatically segmenting files across a diskette in several small pieces. These pieces are correlated into one logically contiguous file by the system without your needing to know the physical file location. This structure eliminates time-consuming disk-packing operations.
File Structure
A TRSDOS file is composed of one or more segments of storage space. Each segment consists of from one to 32 physically contiguous granules of storage. A granule is the minimum allocatable unit of storage, and consists of five sectors (1.25K bytes).
Since a file is always lengthened by granules, a small amount of free storage is generally present at the end of every file. This free storage allows minor file additions to be made in space which is physically contiguous to the file. The effect is to decrease the amount of “thrashing” present in a file which has had frequent additions made. (A wholly sector-mapped system could not offer this benefit.)
Every time a disk file is extended (either initialized or lengthened), extra granules may be allocated to that file, depending on the file’s accumulated length, diskette space, saturation, etc. These extra granules, along with all granules after the one containing the file’s EOF mark, are recovered and returned to the system when the file is closed.
| Term | Explanation |
| LRN | Logical Record Number: Used to specify an individual, user-defined logical record. |
| File | A group of logical records; the largest unit of information addressable by a TRSDOS command. |
| Sector | A physical record, composed of 256 contiguous bytes. |
| Granule | The minimum allocatable unit of storage for a particular file. |
System Routines for Assembly-Language I/O
This information is provided for customers who wish to write their own assembly level I/O routines. An explanation of the calling sequence and parameters for each necessary I/O routine is given. A knowledge of Z-80 machine code is assumed.
| Notation | Explanation |
| HL => xxxx | Registers HL contain the address of (point to) xxxx in machine format. |
| DE => xxxx | Registers DE contain the address of (point to) xxxx in machine format. |
| B = xx | Register B contains the numeric value of xx in binary form. |
| A = xx | Register A contains the numeric value of xx in binary form. |
| Z = OK | Zero flag is set (OK) if successful return from the system routines. |
| X'nnnn' | Hard RAM address in hex notation (e.g., 402D is X'402D'). |
| LRL | Logical Record Length. 1–255 bytes only. |
| BUFFER | 256 user-designated bytes in RAM for TRSDOS to read sectors from or write sectors into. |
| UREC | User Record: the address of the contiguous RAM byte-string assigned by the user as the logical record area. |
Data/Device Control Blocks (DCB)
The DCB is defined as 32 contiguous bytes of RAM designated by the user. Before OPEN and after CLOSE, it is a left justified, compressed (no spaces) ASCII string, as in a standard TRSDOS filespec.
| Addr. | Len. | Explanation |
| DCB+0 | 3 | Reserved |
| +3 | 2 | Physical Buffer address (LSB/MSB) |
| +5 | 1 | Offset to delimiter at end of current record |
| +6 | 1 | File drive number residence |
| +7 | 1 | Reserved |
| +8 | 1 | EOF offset of last delimiter in last physical record |
| +9 | 1 | LRL (Logical Record Length) |
| +10 | 2 | NRN (Next Record Number — LSB/MSB) |
| +12 | 2 | ERN (Ending Record Number — LSB/MSB) |
Physical and Logical Records
| Bytes | Sectors | Granules | Tracks | Disk |
| 256 | 1 | — | — | — |
| 1280 | 5 | 1 | — | — |
| 2560 | 10 | 2 | 1 | — |
| 89600 | 350 | 70 | 35 | 1 |
Fundamental TRSDOS I/O Calls
| Routine (Address) | Description |
| INIT (4420H) | Creates a new file in the directory and opens it for use. |
| OPEN (4424H) | Opens an existing disk file for use. |
| READ (4436H) | Reads one logical record into UREC or physical record into BUFFER. |
| WRITE (4439H) | Writes one logical or physical record to disk. |
| CLOSE (4428H) | Closes an open file and updates directory entries. |
TRSDOS Error Codes
| Decimal | Causes | Description |
| 00 | — | No error |
| 02 | D | Seek error during read |
| 15 | UDX | Write protected diskette |
| 24 | UP | File not in directory |
| 27 | UP | Disk space full (70 granules max) |
| 28 | P | EOF encountered (End Of File) |
| 32 | UP | Illegal drive number specified |
C = CPU fault, D = Drive, F = Format, M = Media, P = Program/User, S = System, X = Expansion.