TRS-80 DOS - LDOS 5.3.1 for the Model I - Disassembled

Overview & History

Overview

LDOS 5.3.1 for the Model I is a Disk Operating System originally developed by Logical Systems, Inc. and, in this final release, maintained and published by MISOSYS, Inc. (1991). The system disk carries the banner "LDOS - THE LOGICAL DISK OPERATING SYSTEM - VER 5.3.1" and the header "Copyright 1991 MISOSYS, Inc., All rights reserved."

The operating system is built around a resident core, SYS0/SYS (SYSRES), which stays permanently in memory, plus a set of system overlays (SYS1/SYS through SYS12/SYS) that are loaded from the system drive on demand. Two additional system files, BOOT/SYS and DIR/SYS, are written to a diskette by the FORMAT utility and are never copied from one disk to another; DOS maintains them automatically. Because overlays are only pulled in when their functions are needed, unneeded overlays can be purged to free space on a working system diskette.

On the Model I, LDOS drives the WD1771 Floppy Disk Controller through memory-mapped I/O (command/status at 37ECH, track at 37EDH, sector at 37EEH, and data at 37EFH, with the drive-select and interrupt-status latches at 37E1H and 37E0H). System services and overlay loading are reached through a single Z80 instruction, RST 28H (see "How Service Calls Work" below).

One of LDOS's defining features is media and code interchangeability: a diskette created under LDOS on a Model I or Model III can be read or written on either machine, and assembly-language programs written to the LDOS SVC table are portable across LDOS installations regardless of the host computer. The bundled LBASIC language allows most standard Microsoft BASIC programs to run unmodified.

History

LDOS was created by Logical Systems, Inc. and first released in 1981 as LDOS 5.1 for the TRS-80 Model I and Model III. It was the product of a collaboration among three companies: MISOSYS (Roy Soltoff, of Alexandria, Virginia), Galactic Software Ltd. (Bill Schroeder, of Mequon, Wisconsin), and Lobo Drives (of Goleta, California) - and the "LDOS" name originally stood for "Lobo Drives Operating System." The development team credited in the original manual comprised Bill Schroeder (project leader), Roy Soltoff (systems analyst), Chuck Jensen, Doug Kennedy, Dick Konop, and Tim Mann.

LDOS set itself apart from Radio Shack's own Model I and III TRSDOS by providing full media interchangeability between the two machines, allowing programs to be written or patched to run on both, and by supporting hard drives. On the strength of that hard-drive support, Tandy licensed LDOS as its official hard-drive operating system and sold it through the Radio Shack catalog as RS26-2213, and Logical Systems was subsequently chosen to write TRSDOS 6 for the Model 4.

The 5.1 line was maintained by Logical Systems through updates 5.1.3 and 5.1.4 (1981-1983). Roy Soltoff's company, MISOSYS, later took over maintenance of the Model I/III product, releasing LDOS 5.3.0 in 1987 and LDOS 5.3.1 in 1991 - the final release of the line. The 5.3 series expanded the date range to accept dates from January 1, 1980 through December 31, 1999, added a modification time stamp to each directory entry, and brought the on-disk directory convention into line with LS-DOS 6.3. The disk disassembled on this page is that final LDOS 5.3.1 release.

Disassembly Highlights

This page serves as the index for the commented disassembly of the LDOS 5.3.1 system and related files.

How Service Calls Work

In LDOS, the RST 28H (Restart 28 Hex) instruction is the central gateway to operating-system services and overlay management. It is a single-byte Z80 instruction that acts as a high-speed trap into the resident kernel (SYS0/SYS), letting programs invoke disk operations, file services, and system extensions without needing to know the physical addresses of those routines, which may shift between releases.

When an RST 28H is executed, the CPU vectors through ROM address 0028H into the resident DOS vector at 400CH, which jumps to the supervisor-call dispatcher at 4BCDH. The request being made is encoded in the A register:

  1. Request Code Evaluation: The value in the Accumulator (A register) is treated as a request code.
  2. Resident vs. Overlay Service: If the high bit of the code is set (code >= 80H), the dispatcher saves and disarms the DEBUG-trap flag (at 4315H) and calls the overlay loader (at 4BF5H). The loader finds the matching SYS overlay in the directory, reads it into the transient region at 4E00H, and patches the dispatcher's self-modified CALL with the overlay's entry point. The overlay runs and returns, after which the trap flag is restored.
  3. Resident Return Path: If the high bit is clear (code < 80H), the request is typically handled resident - most often a simple return (code 1) or an error path at 4BEF.
  4. Overlay Tracking: Location 430EH holds the number of the overlay currently resident in the transient area, so the loader can avoid reloading an overlay that is already present.

In addition to this internal supervisor mechanism, LDOS (DOS version 5) offers a user-loadable SVC table - a jump table placed in high memory by the SYSTEM (SVC) command - that gives assembly-language programs a stable, machine-independent set of entry points. The SVC table requires the KI/DVR keyboard driver to be active.

Resident SVC Vector Table

The resident core exposes a fixed vector table (addresses 4420H-4454H) that overlays and applications call for essential services. These vector addresses are stable across the Model I DOSes, which is what makes SVC-level program compatibility possible. The confirmed vectors on this LDOS 5.3.1 build are:

VectorAddressPurpose
@INIT4420HOpen or initialize a file/logical device (serviced by SYS2/SYS).
@OPEN4424HOpen an existing file.
@CLOSE4428HClose a file or logical device (serviced by SYS3/SYS).
@KILL442CHDelete a file and release its space (serviced by SYS10/SYS).
@LOAD4430HLoad a program load-module into memory.
@RUN4433HLoad and execute a program.
@READ4436HRead a logical record from an open file.
@WRITE4439HWrite a logical record to an open file.
@VER443CHWrite and verify a record.
@REW443FHRewind a file to its first record.
@POSN4442HPosition a file to a given record.
@BKSP4445HBackspace one record.
@PEOF4448HPosition to the end of file.
@DSPLY4467HDisplay a string to the video (*DO).
@PRINT446AHSend a string to the printer (*PR).
@DIV4451HArithmetic divide helper.

Known RST 28H Request Codes

Request codes with the high bit set select an overlay service. The overlay loader at 4BF5H turns a code into a SYS file number by taking its low nibble and subtracting two, and the overlay itself masks the code with 70H to pick a sub-function, so 84H is SYS2 sub-function 00H, 94H is SYS2 sub-function 10H, and so on. A code whose sub-function no overlay recognises simply returns, which makes it a way of loading an overlay and nothing more. The codes decoded so far in the SYS0/SYS, SYS1/SYS, SYS2/SYS, SYS3/SYS, SYS4/SYS, SYS5/SYS, SYS6/SYS, SYS7/SYS, SYS8/SYS, SYS9/SYS, SYS10/SYS, SYS11/SYS, SYS12/SYS, FORMAT/CMD and BACKUP/CMD disassemblies are:

Code (A)Function
84HLoad SYS2/SYS and return. The code masks to sub-function 00H, which the SYS2/SYS entry dispatcher at 4E00H matches against none of its five sub-functions, so it falls onto the RET at 4E16H and the overlay does nothing at all. The whole effect is that SYS2/SYS becomes the resident overlay, recorded in OVRLY$ at 430EH, so a later request with the same low nibble is satisfied from memory without a directory read. Issued by SYS6/SYS COPY through the stub at 57C5H before a one-drive copy starts swapping diskettes, and by FORMAT/CMD at 7277H before it touches the disk. COPY prints its own Insert SOURCE disk prompt; this request does not.
85HLoad SYS3/SYS and return, the same construction as 84H. The code masks to sub-function 00H, which SYS3/SYS does not recognise, so the overlay returns immediately and the only effect is that SYS3/SYS is made resident ahead of the diskette swapping. Issued by SYS6/SYS COPY through the stub at 57CBH.
87H
@DEBUG
SYS5/SYS Loads and enters the DEBUG monitor. Only 44B4H issues it (PUSH AF / LD A,87H / RST 28H); RST 30H (400FH), the BREAK trap and @DEBUG (440DH) lead there. The overlay copies every register to 4065H-407CH, takes back its breakpoints and runs its command loop; it never returns to the dispatcher.
88HSYS6/SYS Library A: run the member whose header holds the member byte in Register B, with Register Pair HL at the parameters of the command (issued by SYS1/SYS for MEMORY, DIR, KILL, LIB, CLS, TOF, DO, SPOOL, APPEND, COPY, LIST, RENAME, DEVICE, LINK, RESET, ROUTE, SET, FILTER, LOAD and RUN).
89HSYS7/SYS Library B: run the member whose header holds the member byte in Register B, with Register Pair HL at the parameters of the command (issued by SYS1/SYS for AUTO, TIME, DATE, CREATE, VERIFY, DEBUG, FREE, SYSTEM, BUILD, ATTRIB, DUMP, PURGE, FORMS and SETCOM, and by SYSTEM (SYSGEN) for member byte 1CH, SYSGEN).
8BHLoad the extended DEBUG command set (issued by the DEBUG command in SYS7/SYS when its EXT option is given; serviced by SYS9/SYS). The overlay lowers HIGH$ by 03D8H, copies itself into the reserved space as a resident module named EXTDBG, and points the resident unrecognised-command vector at 4310H at the copy. DEBUG OFF and RESET in SYS7/SYS undo it by restoring 4876H to that vector.
8AHLoad SYS8/SYS and return, the same construction as 84H and 85H. SYS8/SYS carries out function 10H only, so for function 00H it returns at once (its 4E00H) and the request only loads SYS8/SYS into the overlay area, where SYS0/SYS finds it when a write needs space. Issued by SYS6/SYS COPY through the stub at 57C8H. The three stubs at 57C5H, 57C8H and 57CBH sit nose to tail in the COPY overlay and are CALLed separately from 531FH, 53C3H and 5424H; because the RST 28H dispatcher discards the address the RST pushed, each two-instruction stub returns to the caller of that stub and needs no RET of its own.
93HReturn to DOS (DOS Ready).
94H@OPEN - open or initialize a file or logical device; also performs the drive-availability check for @CKDRV (serviced by SYS2/SYS, which hashes the filename to a one-byte directory HIT code and the password to a 16-bit value).
95H@CLOSE - close a file or logical device; for a disk file this finalizes the directory entry (end-of-file, ending record number, and modification date/time stamp) and frees the granules the file does not need, unless the file was made by CREATE (serviced by SYS3/SYS).
96H@ERROR - display a system error message; the message text is built from a packed 56-word dictionary and, in the full form, followed by the file or device of the latest file call and the address of the program's CALL into the file system (serviced by SYS4/SYS).
9AH@ALLOC, issued by SYS0/SYS (4AB3H) when the record it positions to lies in a granule that none of the five extent slots of the file control block holds, with Index Register IX = the control block and Register Pair BC = the granule wanted. SYS8/SYS counts the granules of the extents in the file's directory records up to that granule; when the file is shorter it allocates the granules missing, first by growing the last extent with the granule after it, else by starting a new extent at the first free granule from cylinder 1, and makes and links an extension record when the four extents of a record are full. It returns the granule's offset in its extent and the extent for the control block (serviced by SYS8/SYS).
9CH
@KILL
@KILL - delete a file or close out a logical device. For a disk file the overlay checks that it was opened at an access level permitting removal, releases every granule of every extent back into the Granule Allocation Table, clears bit 4 of each directory record's attribute byte, zeroes the record's Hash Index Table byte, follows any FXDE link to a secondary extended record, writes both tables back and clears the caller's File Control Block. For a device it rebuilds the control block as a re-openable *XX specification (serviced by SYS10/SYS).
9DHExecute a compiled SYSTEM/JCL job (issued by SYS6/SYS DO at 5301H; serviced by SYS11/SYS). The overlay saves the real *KI driver address out of KIDCB$ at 4016H into KIJCL$ at 43BEH and puts its own job-file reader in its place, so the ordinary ROM line-input routine collects each line of the job into INBUF$ as though it had been typed, and hands it to the command interpreter through @CMNDI.
9EH
@RAMDIR
@RAMDIR - build a table of directory records in memory (serviced by SYS12/SYS as sub-function 10H). Register B holds the drive number, Register Pair HL the caller's buffer, and Register C selects the reply: 0FFH returns the kilobytes in use followed by the kilobytes free, 00H returns one 22-byte record for every visible file on the disk ended by a 2BH marker, and any other value returns the single directory record whose number is one greater than the value given. Each record is a fifteen-character blank-padded file specification, the access level, the end-of-file byte, the logical record length, the ending record number and the file size in kilobytes. There is no resident vector for this code; callers issue the RST 28H themselves.
A3HCommand-line execute - hands a command line (Register Pair HL) to DOS for execution through the resident stub at 4451H (LD A,0A3H; RST 28H). Used to re-run a stored command by SYS6/SYS SPOOL and SYS7/SYS AUTO. This is not @DIV; @DIV is the resident routine at 44C4H.
A5H@FNAME - build the printable file specification (NAME/EXT:d) for a directory record into a caller-supplied buffer (serviced by SYS3/SYS).
ADH@EXIT launch stub - reports to SYS11/SYS that a program run by a job has exited normally, so that the next line of the job is read and executed. One of the two codes written over the @EXIT and @ABORT vectors at 402DH when a job starts (with BDH).
AEH
@DODIR
@DODIR - the abbreviated directory service, loaded by the resident @DODIR vector at 4463H and serviced by SYS12/SYS as sub-function 20H. Register C holds the drive number, Register Pair HL the caller's buffer and Register B a function code: 0 displays the directory four file specifications to a line and fifteen lines to a screen, 1 copies eighteen raw directory bytes per file into the buffer and ends the list with 0FFH, 2 and 3 do the same but keep only files whose extension matches the three-character mask in the first three bytes of the buffer (a dollar sign matches anything), and 4 returns the disk name, the disk date, the disk capacity in kilobytes and the free space in kilobytes. Both scans walk the Hash Index Table rather than reading every directory sector.
BCHResident module/driver control-block lookup - Register Pair DE points at the module or device name; the service walks the chain of modules installed above HIGH$ (4049H), matching each header's name, and returns the module's start in Register Pair HL and the byte after its name in Register Pair DE (NZ with error 8 if not found). The chain is taken to start at HIGH$ less the top of memory at 4403H, which is HIGH$ + 1 only on a 48K computer (top FFFFH). Issued by SYS6/SYS LINK and ROUTE and by SYS7/SYS SYSTEM (5AF6H), FORMS (53BAH) and SETCOM (54FFH); serviced by SYS10/SYS at 4F28H, which reaches it as sub-function 30H.
BDH@ABORT launch stub - reports to SYS11/SYS that a program run by a job has aborted, which ends the job with the message Job aborted. The second of the two codes written over the exit vectors when a job starts (with ADH).
C3H@FSPEC - parse a file specification.
0D4HFilename hash - Register Pair HL points at an eleven-byte packed name and extension; the service exclusive-ORs and rotates them into the one-byte Hash Index Table hash, forces a zero result to 1 so that it can never look like a free slot, returns it in Register A and leaves it in the name-hash cell at 51E1H. Masked with 70H it is sub-function 50H of SYS2/SYS, the same routine @OPEN uses internally. Issued by SYS6/SYS RENAME through the trampoline at 52D0H, which then updates the Hash Index Table itself using the SYS2/SYS entry points at 51BDH and 51BEH.
0E4HPassword hash - hashes an eight-character password to the 16-bit value stored in a directory record, returned in Register Pair HL. Masked with 70H it is sub-function 60H of SYS2/SYS at 4E27H: the eight bytes are folded in reverse order into a running value seeded with 0FFFFH. Eight blanks hash to 4296H and the default master password PASSWORD hashes to 42E0H. Issued by SYS7/SYS ATTRIB at 532EH and PURGE at 54E5H.
CDH
@DOKEY
Keyboard request issued by the resident @DOKEY vector at 44BEH. While a Job Control Language job is running this reaches SYS11/SYS at 4ECFH. Because the supervisor discards the return address the RST 28H pushed, the overlay can read the calling program's own stack frame: finding the ROM line-input routine's return address 05E3H there means the request is part of collecting a command line, which the job answers from the job file; anything else is chained to the real keyboard driver.
DDHKeyboard request while a job's INPUT directive is being answered. SYS11/SYS writes 0DDH over the request-code operand at 44BFH inside the @DOKEY vector so that every keyboard request goes straight to the operator, and sets it back to 0CDH once the reply is terminated.

Additional codes (including B3H, D3H, E3H and C4H) are implemented in the various SYS overlays and are decoded as each overlay is analyzed.

BOOT/SYS

Purpose:

BOOT/SYS is granule 0 of cylinder 0 (sectors 0-4), written by FORMAT/CMD and never copied from one diskette to another. It is not a load module. Sector 0 is the boot sector: the Model I ROM reads it into 4200H and jumps to it. It reads the directory record of SYS0/SYS (sector 4 of the directory cylinder, whose number is byte 2 of the sector), reads the file's first extent sector by sector into a buffer at 5100H through the WD1771 registers at 37ECH-37EFH (Seek 1BH with the bootstrap step rate, Read Sector 88H, two tries), copies each load block to its address and jumps to the transfer address 4E00H; it displays No System or Disk Error otherwise. Sector 1 is the boot sector for a boot through a disk driver: it is entered with Index Register IY pointing at drive 0's drive code table and reads through the driver. Sector 2 is the system information sector that SYS0/SYS reads into 4200H at every boot: the CONFIG/SYS flag, the days of the months, two blocks of drive code tables for drives 0-7, the date and time prompt switches and the day and month names. Sector 3 is a copy of the granule allocation table and sector 4 is not used. The file on the disassembly page holds two more sectors of cylinder 0: sector 6 carries the second part of the double density boot module SOLE/CMD writes, which nothing reads on this diskette.

Disassembly:

A disassembly of BOOT/SYS can be found here.

SYS0/SYS

Purpose:

SYS0/SYS is the resident part of LDOS. The boot sector of BOOT/SYS loads it and jumps to its transfer address, 4E00H; it must be on every diskette the system boots from. The file is a load module of 4165 bytes: a header with the name SYS0 and the copyright text, 35 load blocks and the transfer address.

Everything it loads below 4E00H stays in memory: the sign-on screen (loaded straight into video memory), the restart vectors at 400CH, the device control blocks of the keyboard, video and printer at 4015H, the clock, date and interrupt vectors at 4040H-405CH, the system variables at 4300H (SFLAG$, OVRLY$, INBUF$), the supervisor call vectors at 4400H, the control block for system files at 44A0H, the task table at 4500H, the interrupt service routine and the clock task, the floppy disk driver at 45E0H, the drive code tables at 4700H, the disk primitives at 4750H, the file routines (@READ, @WRITE, @POSN and the others), the directory sector routines, the multiply and divide routines, the RST 28H supervisor dispatcher, the overlay loader at 4BF5H and the module loader at 4C8DH.

The code at 4E00H-50FFH is the reset, which runs once at every boot: it finds the top of memory, saves the ROM driver addresses, installs a lower case video driver when the computer has lower case, sets up drive 0 from the boot, reads the system information sector, asks for the date and time, starts the clock, copies the drive code tables, shows the diskette name and date, loads CONFIG/SYS and carries out the AUTO command. Keys held at the boot change this: ENTER skips the AUTO command, D enters DEBUG, CLEAR or SPACE skips CONFIG/SYS. 4E00H-51FFH then becomes the overlay area every other system file loads into.

Role:

It provides the services every program and every other system file relies on:

  • Sector reads and writes through the drive code tables and the floppy disk driver, which works the WD1771 controller at 37ECH-37EFH.
  • The record level file routines: reading, writing, positioning and the end of file, for files already opened by SYS2/SYS.
  • The interrupt service routine: the 25 millisecond clock, the task slots, the disk controller interrupt and the BREAK key.
  • The supervisor call vectors and the RST 28H dispatcher, which loads the system file a request code names into 4E00H.

Disassembly:

A detailed, commented disassembly of SYS0/SYS can be found here.

SYS1/SYS

Purpose:

SYS1/SYS is the command interpreter of LDOS, a system file that the supervisor dispatcher of SYS0/SYS loads into the overlay area at 4E00H (4E00H-51F8H) for every request code whose low four bits are 3; it must be on every system diskette. The file is a load module of 1094 bytes: the copyright record, four load blocks for 4E00H-51F8H, a load block for 4BC9H-4BCAH (the length 03F9H) and the transfer address 4E00H.

Request 93H (@EXIT, @ABORT and @CMD) runs the LDOS Ready command loop: it resets the stack to 41E0H, arms the BREAK trap when DEBUG is on, displays LDOS Ready and reads a line of up to 63 characters into INBUF$ (4318H-4357H). Requests B3H (@CMNDI, then LDOS Ready) and A3H (return to the caller) carry out a command line a program gives. A line that starts with a period is a comment; ! runs the word as a program file. The first word is taken into CFCB$ (4480H) and looked up in the table of 35 library commands at 4EBDH: each entry names a member of SYS6/SYS (request 88H) or SYS7/SYS (request 89H), which is loaded at 5200H and run with Register Pair HL at the parameters, except BOOT, which seeks drive 0 to cylinder 0 and executes a HALT, which restarts the Model I. Any other word gets the extension /CMD and is run by @RUN.

It also serves three supervisor calls: @FSPEC (request C3H) copies a file specification NAME/EXT.PASSWORD:D or a device name into a control block and passes over the words TO, ON, OVER and USING; @FEXT (D3H) adds a default extension; @PARAM (E3H) reads a parameter list (NAME=value,...) against a table of names, with decimal, X'hex', quoted text and Y, N, ON and OFF values.

Disassembly:

A detailed, commented disassembly of SYS1/SYS can be found here.

SYS2/SYS

Purpose:

SYS2/SYS opens files and devices: a system file that the supervisor dispatcher of SYS0/SYS loads into the overlay area at 4E00H for every request code whose low four bits are 4; it must be on every system diskette. The file is a load module of 1061 bytes: the copyright record, six load blocks for 4E00H-51FEH, a load block for 4BC9H-4BCAH (the length 0400H: SYS2/SYS takes up 4E00H-51FFH, its work cells included) and the transfer address 4E00H.

Request 94H (@OPEN) opens the file or device named in a control block. A device specification (an asterisk and two letters) is looked up in the device control blocks at 4015H and 43C0H. For a file the specification NAME/EXT.PASSWORD:D is taken apart, the name and extension hashed to one byte and the password to a word; the Hash Index Table of the drive named, or of drives 0-7 in turn, is searched for the byte, and each match is checked against its directory record. The master password RS0LT0FF (hash code 113DH) or the file's own password gives every access; otherwise the file's protection level applies: level 7 is refused, and an execute only file loaded by @RUN runs without DEBUG and with the BREAK trap off. The control block is then filled from the directory record. Request A4H (@INIT) does the same and, when the file is on no diskette, creates it on the drive named or the first ready drive that is not write protected and has a free directory record.

Request C4H (@CKDRV) checks a drive: present in its drive code table, a diskette that turns (the index hole within half a second) and an allocation table that reads; it brings the drive code table into line with the diskette (highest cylinder, two sides, cylinder 0 single density) and sets the drive's bit in the date stamping flags (475DH) for a diskette with the directory date format of this release. It returns the CARRY FLAG for a write protected diskette. Requests D4H and E4H return the hash codes of a file name and of a password.

Disassembly:

A detailed, commented disassembly of SYS2/SYS can be found here.

SYS3/SYS

Purpose:

SYS3/SYS closes files and devices and serves @FNAME: a system file that the supervisor dispatcher of SYS0/SYS loads into the overlay area at 4E00H for every request code whose low four bits are 5; the manual says it must not be left off a system diskette. The file is a load module of 751 bytes: the copyright record, three load blocks for 4E00H-50A5H, a load block for 4BC9H-4BCAH (the length 02A6H) and the transfer address 4E00H.

Request 95H (@CLOSE) closes the file or device of a control block. An open device gets its specification (an asterisk and its two letters) back. For a file the directory record is read, the file's buffer written when it was changed, and the end of file byte and the ending record number copied into the record. When a sector of the file was written the record gets the MOD flag and the date, and on a diskette with the directory date format of this release also the hours, the minutes and the year from 1980 (+12H-+13H). Unless the record's create flag is set (a file made by CREATE keeps its space), the granules the file does not need are freed from its last extent back: their bits in the allocation table are cleared, and an extension record left with no extent is freed and unlinked. On a write protected diskette the close succeeds without writing. The control block is left holding the file specification NAME/EXT:d.

Request A5H (@FNAME) writes the file specification NAME/EXT:d of directory record B on drive C into the buffer at DE.

Disassembly:

A detailed, commented disassembly of SYS3/SYS can be found here.

SYS4/SYS

Purpose:

SYS4/SYS serves @ERROR (4409H, request 96H): it turns an error number into its message and displays it. It is a system file that the supervisor dispatcher of SYS0/SYS loads into the overlay area at 4E00H for every request code whose low four bits are 6; the manual says that without it every system error gives the message SYS ERROR, and that it takes one granule. The file is a load module of 1020 bytes: the copyright record, four load blocks for 4E00H-51AEH, a load block for 4BC9H-4BCAH (the length 03AFH) and the transfer address 4E00H.

The 46 messages (error numbers 00H-2DH; a larger number gets the message of 2DH, unknown error code) are not stored as text: a dictionary of 56 words, each with bit 7 set on its last character, a run of word numbers for each message, and an index of the runs by error number. The program calls @ERROR with the error number in bits 5-0 of A, bit 6 set for the short message (the text alone) and bit 7 set to get control back instead of ending at @ABORT. The full message is a line *** Error code =NN, text ***, a line naming the file or device of the latest file call (<File=NAME/EXT:d> from the directory record of an open file, <Device=*XX>, or the file specification as typed for the errors of an open or a load), and Referenced at X'NNNN', the address of the program's CALL into the file system. Bit 6 of SFLAG$ (430FH) forces the full message; bit 6 of the command interpreter's status byte 4758H suppresses the message, and bit 7 has the short text built in the program's buffer at DE without displaying it.

Disassembly:

A detailed, commented disassembly of SYS4/SYS can be found here.

SYS5/SYS

Purpose:

SYS5/SYS is the DEBUG monitor (the manual's ghost debugger). The supervisor dispatcher loads it into 4E00H for request 87H, which only 44B4H issues, after pushing the program's Register Pair AF. Four roads lead there: a breakpoint (an F7H byte, RST 30H, through the vector at 400FH), the start of a program run by @RUN while DEBUG is on (bit 7 of SFLAG$, 430FH; SYS0/SYS 4C73H), BREAK when the BREAK trap at 4315H-4317H is on with 400FH as its address (DEBUG (ON) and DEBUG's own G command set it so), and @DEBUG at 440DH (the D key held at boot). The address under the pushed AF is taken as the program's PC.

On entry every register, both sets, IX, IY, the Stack Pointer and the PC, is copied to 4065H-407CH in one move; the PC is moved back one byte when the byte before it is F7H, and the two breakpoint slots at 405DH-405FH and 4060H-4062H are cleared with their saved bytes put back. Between breakpoints the same six bytes hold the memory display mode (405DH), the screen layout (405EH) and the address the M command changes (4060H-4061H); 4063H-4064H is the memory display address. DEBUG works on the program's stack and uses no disk call: it reads keys and writes the screen through the ROM (002BH, 0049H, 0033H) and places the cursor through 4020H-4021H.

The register screen shows the twelve register pairs, with the flags of AF and AF' by name and sixteen bytes of memory for the others, and four lines of memory; S gives a full screen of 256 bytes. The commands: A and H (characters or hexadecimal), C and I (single step over or into a call), D (memory display address), G (go, with up to two breakpoints; G402D ends at LDOS Ready), M (change memory), R (change any register pair, SP and PC too), S and X (the screens), U (keep drawing), ; and - (move the display by 64 or 256 bytes). Any other key goes to the address at 4310H-4311H, where SYS9/SYS puts its extended commands; SYS9/SYS also calls SYS5/SYS's key reader, number reader and hexadecimal output. The single step plants a breakpoint after the instruction and one at its target, using three tables of masks for the length and kind of each instruction; the target of JP (IX) is taken from the saved IY, since the code tests the byte after the prefix instead of the prefix.

Disassembly:

A detailed, commented disassembly of SYS5/SYS can be found here.

SYS6/SYS

Purpose:

SYS6/SYS is Library A: fifteen members, each a separate program loaded at 5200H (the member of FILTER and SET at 5A00H), that carry out twenty commands. SYS1/SYS finds the command word in its command table at 4EBDH and issues request 88H with Register B = the member byte; the overlay loader at 4BF5H finds the member header with that byte among the twenty headers at the start of the file, reads the member's load blocks and calls its entry with Register Pair HL at the text after the command word. The parameters in brackets are read by @PARAM straight into the operands of the instructions that use them. A member ends with Register Pair HL = 0000H, or FFFFH for a failure, which ends a JCL job through @ABORT. Without SYS6/SYS on the system diskette none of these commands can run, and DO, which starts every JCL job, is among them.

The members and their commands (member byte, entry):

  • 1: MEMORY (1EH)
  • 2: DIR (21H)
  • 3: KILL (18H)
  • 4: LIB (19H, 5200H), CLS (24H, 5203H), TOF (25H, 5206H)
  • 5: DO (91H)
  • 6: SPOOL (A2H)
  • 7: COPY (32H, 5200H), APPEND (31H, 5203H)
  • 8: LIST (41H)
  • 9: RENAME (53H)
  • 10: DEVICE (61H)
  • 11: LINK (62H)
  • 12: RESET (63H)
  • 13: ROUTE (64H)
  • 14: FILTER (66H, 5A00H), SET (65H, 5A01H)
  • 15: RUN (82H, 5200H), LOAD (81H, 5203H)

DO compiles a /JCL file into SYSTEM/JCL and starts it through request 9DH (SYS11/SYS). SPOOL, LINK and ROUTE to a file put modules into high memory with the header that request BCH (SYS10/SYS) searches; FILTER and SET load a /FLT or /DVR file with @LOAD and jump to it with Register Pair DE at the device's control block. COPY loads SYS2/SYS, SYS8/SYS and SYS3/SYS into the overlay area with requests 84H, 8AH and 85H, so that a copy between two diskettes on one drive (X) finds them there; RENAME uses request D4H for the hash of the new name.

Disassembly:

A detailed, commented disassembly of SYS6/SYS can be found here.

SYS7/SYS

Purpose:

SYS7/SYS is Library B: thirteen members, each a separate program loaded at 5200H, that carry out fourteen commands, and SYSGEN, which SYSTEM (SYSGEN) runs. SYS1/SYS finds the command word in its command table at 4EBDH (bit 6 of the entry's flags byte marks Library B) and issues request 89H with Register B = the member byte; the overlay loader at 4BF5H finds the member header with that byte among the fifteen headers at the start of the file, reads the member's load blocks and calls its entry with Register Pair HL at the text after the command word. The parameters in brackets are read by @PARAM straight into the operands of the instructions that use them. A member ends with Register Pair HL = 0000H, or FFFFH for a failure, which ends a JCL job through @ABORT. The commands of Library B are not needed to run programs, so a working system diskette can do without SYS7/SYS.

The members and their commands (member byte, entry):

  • 1: AUTO (11H)
  • 2: TIME (16H, 5200H), DATE (15H, 5203H)
  • 3: CREATE (13H)
  • 4: VERIFY (1BH, 5200H), DEBUG (14H, 5203H)
  • 5: SYSGEN (1CH), run by SYSTEM (SYSGEN)
  • 6: FREE (22H)
  • 7: SYSTEM (A1H)
  • 8: BUILD (33H)
  • 9: ATTRIB (51H)
  • 10: DUMP (71H)
  • 11: PURGE (72H)
  • 12: FORMS (B1H)
  • 13: SETCOM (B2H)

SYSTEM sets the options of the system: the clock speed, BREAK, the date and time prompts of the boot, the drives' code tables (DRIVE, WP, CYL, DISABLE, ENABLE, STEP, DELAY, SWAP, SYSTEM, DRIVER) and the modules it puts in high memory with the header that request BCH (SYS10/SYS) searches: $UP (UPDATE), $BL (BLINK), $AL (ALIVE), $SVC (SVC, the supervisor calls below 80H) and $SR (SYSRES, system files kept in memory). SYSGEN writes CONFIG/SYS, which SYS0/SYS's reset loads to restore that configuration. FORMS and SETCOM change the settings of the modules $FF (PR/FLT) and $CL (RS232/DVR); DEBUG (EXT) loads the extended DEBUG commands through request 8BH (SYS9/SYS); ATTRIB and PURGE hash passwords through request E4H (SYS2/SYS).

Disassembly:

A detailed, commented disassembly of SYS7/SYS can be found here.

SYS8/SYS

Purpose:

SYS8/SYS is @ALLOC, the dynamic allocation of file space while a file is written. The manual says it must be on every working system diskette. SYS0/SYS keeps up to five extents of an open file in its control block; when the record it positions to lies in a granule that none of them holds, it issues request 9AH, and SYS8/SYS, loaded into the overlay area at 4E00H-5095H (662 bytes), is called with Index Register IX = the file control block and Register Pair BC = the granule wanted, counted from 0. It returns the granule's offset in its extent and the extent, and either brings the slot that held the extent up to date or moves the second to fourth slots on by one so that SYS0/SYS can put the extent in the second slot.

It reads the file's directory record (DIRRD) and counts the granules of its four extents at +16H-+1DH (a cylinder byte, then a granule byte with the first granule on that cylinder in bits 7-5 and the granules less one in bits 4-0), following FEH at +1EH to the extension record numbered at +1FH. When it meets an extent not in use (FFH) before the granule wanted, it reads the granule allocation table into 5100H and allocates the granules missing one at a time: the granule after the last extent, counted on over the granules of a cylinder, is added to that extent while it is free and the extent holds fewer than 32 granules; otherwise the next extent of the record starts at the first free granule found from cylinder 1 (the byte at 4767H) to the last cylinder and then from cylinder 0. When the four extents are full it writes the table and the record back, takes a free record from the hash index table (giving it the file's hash byte), builds it as an extension record (attributes 90H, the number of the record it extends, no extents) and links it with FEH and its number. Then it counts again. Errors: 27 (1BH) disk space full, 30 (1EH) directory full, and the read and write errors of the directory, the allocation table and the hash index table.

The code before the search still builds a random number from the refresh register and TIMER$ and fetches the number of cylinders, which this release does not use: the 5.1.4 update notes say space is now allocated from the lower numbered cylinders and give a six byte patch that brings back the random start.

Disassembly:

A disassembly of SYS8/SYS can be found here.

SYS9/SYS

Purpose:

SYS9/SYS contains the routines that service the extended debugging commands available after a DEBUG (EXT) is performed. It may be purged if the extended debugging commands are not needed; if SYS5/SYS has also been purged, keeping SYS9/SYS serves no purpose.

From the disassembly, only the first 38 bytes of SYS9/SYS run where it is loaded. They install the rest: when the word at 4310H, the address DEBUG jumps to with a key it does not know, still holds 4876H (an OR A / RET of SYS0/SYS), HIGH$ at 4049H is lowered by 03D8H, the 984 bytes 4E26H-51FDH are copied into the space above it with the old HIGH$ in their link word, and 4310H is pointed at the copy. A second DEBUG (EXT) finds 4310H changed and installs nothing.

The copy is a module with the header of the modules kept above HIGH$: a JR over the header, the link word, the length of the name and the name EXTDBG. Every branch inside it is relative, and the absolute addresses it uses belong to the ROM, SYS0/SYS or SYS5/SYS, whose key reader, number reader and hexadecimal output it calls for all its input and output; it runs where it is copied, and returns to DEBUG's command loop, which draws the screen again. DEBUG hands it the key in lower case.

Thirteen commands: o leaves DEBUG through @EXIT; b moves a block; e and t change memory in hexadecimal and as typed text; f fills a range (from the first address up to the last, and nothing when the first is not below the last); j steps the program's PC over a byte; l and w search all memory for a byte or a word; n moves from one record of a load module to the next; q reads or writes a port; v compares two blocks and stops on the first difference; the digits 0 to 7 read or write sectors of that drive (r, w, or the asterisk key for a write with the deleted data mark, a whole cylinder when no sector is given); and p prints a range of memory on the printer in hexadecimal and as characters. The commands leave their results in DEBUG's M address (4060H) and memory display address (4063H), so DEBUG's screen shows them.

Disassembly:

A disassembly of SYS9/SYS can be found here.

SYS10/SYS

Purpose:

SYS10/SYS contains the procedures that service the request to delete a file (the @KILL function). It should remain on working SYSTEM diskettes.

From the disassembly, SYS10/SYS is 371 bytes, 4E00H-4F72H. Request 9CH, issued by @KILL (442CH), deletes the file whose control block is at Register Pair DE. A control block with bits 7-5 of +00H clear is a device: it is turned back into its specification, an asterisk, its two letters and 03H, and nothing else is done. A disk file must be open with the access level 0 or 1 (bits 2-0 of +01H), else error 37 (25H). The granule allocation table is read into 5000H; for the file's directory record and then each extension record linked by FEH at +1EH, the granules of every extent are freed in the table (running on into the next cylinder past a cylinder's last granule), bit 4 of the record's attributes is cleared and its sector written, and its byte in the hash index table is set to 00H and the table written. Only then is the allocation table written back, and the 32 bytes of the control block are cleared.

Request BCH (function 30H, at 4F28H) finds a module kept above HIGH$ by its name: each module starts with a JR (18H) over its header, a link word (the HIGH$ before it was installed, whose value + 1 is the module before it, FFFFH ending the chain), the length of its name in bits 3-0 and the name. It returns Register Pair HL = the module and Register Pair DE = the byte after the name, or error 8, device not available. The search starts at HIGH$ less the top of memory that the reset found (4403H), which is HIGH$ + 1 only when the top is FFFFH; on a 16K or 32K computer it starts elsewhere. SYS6/SYS LINK and ROUTE and SYS7/SYS SYSTEM, FORMS and SETCOM use it.

Disassembly:

A disassembly of SYS10/SYS can be found here.

SYS11/SYS

Purpose:

SYS11/SYS contains the procedures that perform the Job Control Language (JCL) execution phase. It may be removed from working disks if no JCL functions will be invoked. Because the DO command that launches JCL resides in SYS6/SYS, keeping SYS11/SYS serves no purpose if SYS6/SYS has been purged.

From the disassembly, SYS11/SYS loads 4E00H-5180H and 5187H-51FBH; the six bytes 5181H-5186H between them are not in the file and hold a directive's name or the three numbers of WAIT. DO (SYS6/SYS) compiles the job into SYSTEM/JCL, opens it in JFCB$ (4358H), saves the six bytes of @EXIT and @ABORT (402DH-4032H) at 4065H and puts LD A,ADH / RST 28H and LD A,BDH / RST 28H at 406BH, then issues request 9DH.

A job is the list of lines the operator would type, so the overlay makes the job file the keyboard. At the start it keeps the keyboard driver address (4016H) in KIJCL$ (43BEH), copies the six bytes at 406BH over @EXIT and @ABORT, so that a command that ends comes back with request ADH and one that aborts with BDH, reads the first line from the job file and runs it through @CMNDI. From then on the keyboard driver is @DOKEY (44BEH), which issues request CDH. Because the supervisor drops the return address of the RST, the overlay can look at the stack of the caller: only a request whose return address at the Stack Pointer +0EH is 05E3H, inside the ROM's line input routine, is answered from the job file, and the counts of that routine at +0AH show whether a line is starting; any other request goes to the real keyboard driver.

Lines that start with // are carried out by the overlay on the way: a name is looked up in the table of ten directives at 51B5H (ABORT, ALERT, DELAY, EXIT, FLASH, KEYIN, PAUSE, STOP, WAIT, INPUT; five characters and the address of the routine), and lines of three slashes or two slashes and a digit are the labels of KEYIN, which shows its line, takes one key and passes the job file over to the line //key or ///. ALERT plays tones and silences in turn on the cassette output (port FFH, the levels 01H and 02H), repeating a bracketed group until ENTER; INPUT hands the keyboard to the operator for the rest of a line by changing @DOKEY's request code to DDH. The job ends with Job done at the end of the file or EXIT, with Job aborted for BREAK, @ABORT or ABORT, and with Bad JCL, Job aborted for a line of more than 63 characters or a bad WAIT or ALERT; the keyboard driver and the six bytes of @EXIT and @ABORT are put back.

Disassembly:

A disassembly of SYS11/SYS can be found here.

SYS12/SYS

Purpose:

SYS12/SYS contains the routines that service the @DODIR and @RAMDIR directory vectors. These routines are used by the MiniDOS filter and may also be used by other application programs that provide a directory display. It can be removed if the two "mini" directory routines are not needed.

From the disassembly, SYS12/SYS occupies 4E00H through 50FDH, 766 bytes in one contiguous piece, and deposits that same length as the two-byte load block 02FEH at 4BC9H. Entry is at 4E00H with the request code still in Register A; masking it with 70H gives 20H for @DODIR, whose resident vector at 4463H issues code AEH, and 10H for @RAMDIR, whose resident vector at 4396H issues code 9EH. Both services go through the file prologue of SYS0/SYS (49F1H), so the caller gets its Register Pairs BC, DE and HL back: the results are in the caller's buffer, Register A and the flags.

Neither service reads the directory record by record. Both read the Hash Index Table, the second sector of the directory cylinder, into the scratch page at 5100H and step a record number through it in slot-major order, adding 20H at a time so that all eight slots of one directory sector are visited before the sector number is advanced. Only slots whose hash byte is non-zero are looked up, and a self-modifying compare remembers which directory sector already sits in the shared buffer at 4200H, so a run of eight records costs one disk read. The remembered sector is FFH only in the file and is not set back on a new call, so a second call while SYS12/SYS is still in the overlay area takes 4200H as the sector of the call before when its first record lies there.

@DODIR offers five functions. Function 0 displays file specifications four to a line and fifteen lines to a screen, pausing for a keypress and clearing the screen when one fills; function 1 copies eighteen raw directory bytes per file into the caller's buffer and ends the list with 0FFH; functions 2 and 3 repeat those two with an extension mask filter in which a dollar sign matches any character; and function 4 returns the disk name and date copied straight out of the Granule Allocation Table together with the capacity and the free space. @RAMDIR instead produces fixed 22-byte records - a fifteen-character blank-padded file specification, the access level, the end-of-file byte, the logical record length, the ending record number and the file size in kilobytes - ending the table with a 2BH marker that each new record overwrites.

Free space is counted by rotating each Granule Allocation Table byte right with a one shifted in from the left, which tests one granule bit per pass and ends naturally when the byte has become 0FFH. The number of cylinders to examine comes from the configuration byte at Granule Allocation Table offset CCH, which holds the cylinder count less 35, and sectors are turned into kilobytes by adding two and dividing by four. Before any of this, every entry seeks the drive and watches the WD1771 index-pulse status bit go clear, set and clear again, which proves a diskette is actually turning; twenty clock ticks without that cycle returns error 8, device not available.

Disassembly:

A disassembly of SYS12/SYS can be found here.

BACKUP/CMD

Purpose:

BACKUP/CMD copies a diskette: BACKUP [-][partspec]:s :d (parameters), with the parameters MPW, SYS (S), INV (I), MOD (M), QUERY (Q), X, DATE (D), NEW (N) and OLD (O). A drive not named on the command line is asked for (Source drive number ?, Destination drive number ?); the parameters must then be on the line before it, since the rest of the line is not read after a question.

The file holds three programs. The front end (5A00H, the transfer address) reads the line, mounts the source and destination diskettes (on one drive they are asked for in turn, which a JCL job does not allow), checks the source's master password (PASSWORD needs nothing; MPW or the reply must match the diskette or be RS0LT0FF) and chooses an engine. Two engines are loaded elsewhere and moved to 5A00H, over the front end, by the selector at 6C00H: the mirror image engine (5E00H-6208H in the file) and the file by file engine (6300H-6A47H). The endings, the prompts for the diskettes and the calls of the drive's driver lie below 5A00H (5285H-5486H) for both.

A partspec (a leading minus sign excludes the files that match it) or any of SYS, INV, MOD, QUERY, DATE, NEW and OLD makes a backup by class, done file by file. Otherwise drives of one size, a formatted destination and the same density, sides and cylinder 0 format in both allocation tables (bits 6-4 of +CDH) give a mirror image copy; a different cylinder count asks Cylinder count differs - Attempt mirror-image backup ?. A hard disk destination or diskettes not alike give Backup-reconstruct invoked: the file by file engine with every file. The file by file engine refuses one drive (Single drive BACKUP invalid by files), and with X it needs SYS2/SYS, SYS3/SYS, SYS8/SYS and SYS10/SYS kept in memory by SYSRES: BACKUP reads the operand of the supervisor dispatcher's CALL at 4BDFH and the entries of those files in the $SR module's table.

The mirror image engine checks the pack identities (+CEH-+D7H of the allocation tables: Different pack IDs! Abort backup ?) and that no granule with data on the source is locked out on the destination, marks the destination's boot sector with 76H (by which the prompts recognise it), stores C9H at 4012H with interrupts off (hence Note: Real time clock no longer accurate) and copies every cylinder with data in groups as large as memory holds: read, write (the directory cylinder with the deleted data mark), verify. The boot sectors (cylinder 0 sectors 0 and 1) are not copied; for a diskette with cylinder 0 in single density the source's bytes 09H-0AH and 16H-25H of the boot sector go into the destination's. At the end the destination gets the source's identity, AUTO command and today's date in its allocation table, both boot sectors get the directory cylinder, and the bit of a changed file is cleared in both directories (Source disk is write protected, can't clear mod flags when the source cannot be written).

The file by file engine walks the source's hash index table and tests each record: in use and not an extension record, changed for MOD, a system file only with SYS, an invisible file only with INV, the partspec ($ and a space match any character), the DATE range, NEW and OLD (by an @OPEN on the destination), and QUERY (Backup NAME/EXT + {DD-Mmm-YY} ?: Y, or C for this file and no more questions). Each file is copied through the file system as NAME/EXT.RS0LT0FF:d: the master password RS0LT0FF in the specification opens any file whatever its password. The whole length is written first, so a full destination is found at once (Disk is full! - Enter new formatted destination disk); a file larger than the destination's room is passed over. The destination's record gets the source's attributes, date and password; an old dated source copied to a diskette with this release's date format gets its year at +13H. With SYS the destination becomes a system diskette: the 15 records of the system files are claimed in its hash index table, and SYS0/SYS brings sectors 2-4 of cylinder 0 with it.

Disassembly:

A disassembly of BACKUP/CMD can be found here.

DATECONV/CMD

Purpose:

DATECONV/CMD puts the directory of a diskette written by an earlier release of LDOS into the date format of 5.3. In that format bytes +12H-+13H of each directory record, which earlier releases used for the access password of the file, hold the time of the last change and a year from 1980 to 2011, and bit 3 of the configuration byte of the allocation table (offset CDH) marks the diskette. The command is DATECONV :d; the program takes nothing from the command line but the drive, and without a colon and a digit 0-7 it stops with error 20H, Illegal drive number.

DATECONV is a load module at 5200H-5473H. It checks the drive with @CKDRV (not ready: error 20H; write protected: Write protected drive!) and reads the allocation table from sector 0 of the directory cylinder. On a diskette of an earlier release that holds the system files (the first record of directory sector 5 in use) the system information sector must start with 53H or 63H, else it stops with SYSTEM disk conversion requires a 5.3 or 6.3 disk!; a configuration byte with bit 7 set skips that test. It then reads every sector of directory records (their number from the ending record number of DIR/SYS, at most 32), and for each primary record in use with a date stores 00H at +12H and the year of the date (bits 2-0 of +02H) at +13H: a time of 00:00. On a diskette already in this format only records whose +12H-+13H hold 4296H, the hash of a blank password, are changed, so that real time stamps are kept.

Each sector is written back with the deleted data mark and verified, and every read accepts a sector with that mark. BREAK, tested after every record, stops the conversion with Date conversion aborted! before the diskette is marked. At the end bit 3 of the configuration byte is set and n file(s) updated, conversion complete is displayed and written to the job log. The program returns with Register Pair HL = 0000H, or FFFFH after an error or a refusal; during a JCL job an error ends at @ABORT. It issues no supervisor request of its own.

Disassembly:

A disassembly of DATECONV/CMD can be found here.

FDUBL/CMD

Purpose:

FDUBL/CMD installs $FDD, a floppy disk driver for double density on the Model I: FDUBL (TANDY) for the Radio Shack adapter (the default) or FDUBL (PERCOM) for a Percom type doubler; both together give Can't specify both Percom and Tandy!. When a drive's driver is already a module named $FDD it stops with Driver is already resident!. The module (344 bytes, 327 for PERCOM) is copied to end at HIGH$ (4049H), which is lowered below it, and every drive code table whose +04H has bit 4 clear gets its JP pointed at the module and bit 6 of +04H set, which FORMAT/CMD reads as a controller that can do double density.

The driver takes the functions of SYS0/SYS's floppy driver and leaves select, restore, step and the wait to SYS0/SYS's routines (45E0H, 4659H, 461CH). For the sector and track functions it first sets the adapter's density from bit 6 of +03H: 80H or A0H to the sector register 37EEH for the Tandy adapter, FEH or FFH to the command register 37ECH followed by D0H for the Percom doubler. On the Tandy adapter a seek also sets its write precompensation (C0H off, E0H on above half of (the highest cylinder plus 7)). Its transfer loop tests for the next byte five times between each test of BUSY; reads get 10 tries, verifies 4, writes 6, and a write with the deleted data mark uses A9H in double density and ABH in single density. When a sector is not found the drive's density is changed (with its geometry 2409H or 4511H in +07H and +08H) and the operation tried again, so diskettes of either density are read. Errors go through SYS0/SYS's decoder at 46F4H, whose first error number the driver stores at 46F6H.

The file carries the applied patch FDUBL1 (a record of type 07H and two load blocks): CALL 5574H at 5265H gives the PERCOM build's header, moved to 5421H, the JR displacement 2CH that reaches the driver at 544FH.

Disassembly:

A disassembly of FDUBL/CMD can be found here.

FORMAT/CMD

Purpose:

FORMAT/CMD writes the tracks of a diskette, verifies every sector, and writes the system information: FORMAT :d (NAME="name",MPW="password",SDEN,DDEN,SIDES=n,CYL=n,STEP=n,ABS,QUERY=N,SYSTEM,WAIT=n,DIR=n). The parameters are read only when :d is on the command line; whatever is not given is asked for (Which drive is to be used ?, Diskette name ?, Master password ?, Single or Double density <S,D> ? when the drive's controller can do double density, Enter number of sides <1,2> ?, Number of cylinders ? for a 5 inch floppy, the bootstrap step rate in milliseconds) or, with Q=N or any of SDEN, DDEN, SIDES, CYL or STEP, taken as a default: the name LDOSDISK, the password PASSWORD, double density when the controller can do it (bit 6 of +04H of the drive code table, which FDUBL/CMD sets), one side, the cylinders and the step rate of the system information sector of drive 0. Number of cylinders ? and CYL take at most 95.

The program is a load module of 23 blocks (4842 bytes, 6000H-7673H, transfer address 6E00H). Its front end (6E00H-7264H) asks the questions, copies the target drive's drive code table to 6564H and checks the diskette: ready, on track 0, turning (the index hole within half a second), not write protected, enough memory below HIGH$, and, when cylinder 0 can be read, Disk contains data -- with its name and date, and Are you sure you want to format it ? unless ABS (a JCL job ends there). Then the engine (6000H-6563H) builds each track from one of four templates (5 or 8 inch, single or double density) at 6E00H, over the front end, and calls the drive's driver itself through the copy, so the system's own table never changes; the clock interrupt is shut out meanwhile (Note: Realtime clock no longer accurate).

Every cylinder is written (both sides with SIDES=2) and every sector verified, every second sector around the track; a cylinder with a sector not found or a CRC error is shown with an asterisk and locked out. With SYSTEM on a 5 inch double density floppy, cylinder 0 is formatted again in single density, for the ROM to boot (bit 4 of the configuration byte); any other format refuses SYSTEM. The directory goes on DIR=n or the middle cylinder, or the nearest good one; every sector there is written with the deleted data mark: the allocation table, the hash index table (A2H, C4H), the records of BOOT/SYS and DIR/SYS and empty sectors. Cylinder 0 gets boot sector 0 (from the image at 6B00H, run by the ROM) and boot sector 1 (6C00H, for a boot through a disk driver) with the directory cylinder and the step rate, the system information sector (53H and 00H) and a copy of the allocation table. A drive whose table has bit 4 of +04H set gets no tracks (a hard disk only after Y; its driver gets function 0CH unless SYSTEM), only the system information.

Disassembly:

A disassembly of FORMAT/CMD can be found here.

PATCH/CMD

Purpose:

PATCH/CMD changes the bytes of a disk file, or adds load blocks to a program, from patch lines: PATCH filespec1 [USING] filespec2 (parms) reads them from a file (/FIX by default), and PATCH filespec (lines) takes them from the command line, a colon between two lines. The file to patch gets /CMD by default. A D line, Drr,bb=data, writes hex bytes or a quoted string into record rr from byte bb on; the F line after it names the bytes that must be there first, unless OPTION=N is given. An X line, X'nnnn'=data, becomes a load block for address nnnn; the X lines of a patch, with a record of type 07H that names the patch (the patch file's name, or CLP for the command line), are put into the program just before its transfer record, and every byte after that place is moved on. Lnn puts the X lines at the end of member nn of a library file and moves on the starts of the members after it in the member headers.

REMOVE takes a D patch out: each D line and its F line change places once the D line's bytes are found in the file, so the old bytes are written back. YANK turns every load block after the named record of type 07H into a record of type 10H, which the loader passes over. The lines are read into memory from 5F00H and gone through twice: the first pass checks the D lines and writes nothing, the second does the work and closes the file. PATCH makes no RST 28H request of its own; it uses the supervisor call vectors and the ROM's $GET and $PUT.

Found in the code: a record number of four hex digits keeps only its last two; only X lines can follow an L line; the member header search reads from wherever the file stands; after the first member header it moves, the library map compares the rest with 0000H; the rest of the file after the new records is held in memory from 7300H with no test of the top of memory; the patch file is opened with the length of its name as its record length and is not closed; a yank loses its place after a load block whose length byte is 1 or 2.

Disassembly:

A disassembly of PATCH/CMD can be found here.

SOLE/CMD

Purpose:

SOLE/CMD (SOLE :d) makes a double density system diskette bootable. The diskette must be formatted with a single density cylinder 0 and double density elsewhere (FORMAT with DDEN and SYSTEM), since the ROM boots only from a single density cylinder 0. SOLE requires the colon and the drive digit (without them it stops with Drive spec required!), refuses a drive that is not a 5 inch floppy drive, is not ready or is write protected, and a diskette whose cylinder 0 is not single density.

It writes a boot module of two sectors to cylinder 0, sectors 5 and 6, as a load module that runs at 5200H-53D0H, changes the boot sector so that it loads that module (Index Register IY = 421CH, a drive code table for the boot at 421CH-4225H, and a jump into its loader with cylinder 0, sector 5), marks granule 1 of cylinder 0 in use in the allocation table and gives the two sectors to BOOT/SYS in its directory record (ending record number 7). At boot the module reads the directory and loads SYS0/SYS in double density through its own driver, which tries 5 times, chooses the side from the sector number and changes the density on a record not found; then it copies its drive code table to drive 0 (4700H) and starts SYS0/SYS with Index Register IY = 0000H. The driver sets the density for the Tandy adapter (80H or A0H to the sector register) unless byte 9 of the drive's double density driver is not CDH, when it uses the Percom doubler's way (FEH or FFH to the command register, then D0H).

Disassembly:

A disassembly of SOLE/CMD can be found here.

KI/DVR

Purpose:

KI/DVR is the keyboard driver of LDOS for the Model I, set with SET *KI TO KI/DVR (TYPE,JKL,DELAY=d,RATE=r). The program runs only when the SET command runs it (bit 3 of 4758H; else Must be installed via: SET!). It is a load module of 1341 bytes at 5200H-573CH with no copyright record, and it puts up to three modules above HIGH$ (4049H), each made the driver of the keyboard's device control block (4015H) in front of the one before, or, during a JCL job, of KIJCL$ (43BEH): $KI, the keyboard driver, always (363 bytes; DFLAG$ 441FH bit 4); $TA, the type ahead, with TYPE (177 bytes below a buffer of 256 bytes; bit 1); $JKL, the screen print, with JKL (86 bytes; bit 2). A module whose bit is set is refused (KI/dvr is already active!, Type-ahead is already active!, JKL is already active!). 4DF8H, 4DF2H and 4DF4H keep where each went, so a later SET puts it back in the same place.

$KI compares the seven keyboard rows (3801H-3840H) with their picture at 4036H-403CH and gives the lowest key that went down: letters in lower case, upper case with SHIFT or with CAPS (KFLAG$ 4423H bit 5, toggled by SHIFT 0), control codes 00H-1AH with SHIFT DOWN and a letter, row 6 from one of two tables at 52A0H and 52B0H (KFLAG$ bit 6, toggled by CLEAR SHIFT SPACE), bit 7 added while CLEAR is held, and 5BH-5FH, 7BH-7FH and 1BH-1EH from the comma, slash, period, semicolon and ENTER with CLEAR or SHIFT DOWN. BREAK gives 00H while BREAK is off. A held key repeats after DELAY ticks of TIMER$ (4040H, 40 a second; 20 when not given, at least 10) every RATE ticks (2 when not given, at least 1); the key held and its next tick are kept at +03H and +04H of the device control block.

$TA's task runs in task slot 10 on every tick and stores the keys $KI gives, with their flags, in its buffer of 127 places; its driver gives them back in order (KFLAG$ bit 7 set while keys wait), drops repeats while keys wait, and empties the buffer for CLEAR @ or a control request with code 00H. $JKL prints the screen (3C00H-3FFFH, 0DH before each line of 64) through the ROM printer routine on SHIFT DOWN with the asterisk; graphics characters go as a period unless DFLAG$ bit 7 is set. A bad parameter gives error 2CH, Parameter error. KI/DVR issues no supervisor request of its own.

Disassembly:

A disassembly of KI/DVR can be found here.

PR/FLT

Purpose:

PR/FLT is the forms filter for the printer: FILTER *PR USING PR/FLT (parms) puts a module of 0125H bytes, named $FF, above HIGH$ in front of the driver of *PR. It counts columns and lines, wraps a line at CHARS bytes and starts the rest with INDENT spaces, puts MARGIN spaces before every line, expands tabs with TAB, changes one byte into another with XLATE, and skips the rest of every page after LINES lines, with line ends or with one 0CH (FFHARD); 06H sets the line count to the top of a page and ADDLF sends a line feed after every carriage return. PAGE and LINES go into +03H and +05H of the device control block, which counts the lines in +04H; SLINE=1 makes them 67 and 1 instead of 66 and 0. The FORMS command of SYS7/SYS changes the values later, and RESET *PR takes the filter out.

The file is a program FILTER runs at 5200H with Register Pair DE = the device control block and Register Pair HL = the parameters (1135 bytes: 5200H-550CH and 5517H-5629H, transfer 5200H). A NIL, routed or input only device is refused, and so is a second PR/FLT (DFLAG$ 441FH bit 3, which it then sets). The module goes above a HIGH$ lowered by 0125H, or into the memory of an earlier install, whose address 4DF6H keeps; 17 operands are moved from a relocation table. When the device still has the printer driver saved in PRSV$ (43BCH), the module puts its own driver in its place, which waits on 37E8H (or the port of PORT=n) and does not wait when the status reads F0H, so that no printer attached does not hang the computer. The device control block is copied into the module, every byte is passed on through that copy, and an installed spooler is given the copy as well. PR/FLT makes no RST 28H request of its own.

Found in the code: a bad SLINE value is reported after DFLAG$ bit 3 is set, so the bit stays set with no filter installed; SYSTEM (PRTIME) takes the byte at module +19H as the offset of a time out byte, but in this filter that byte is the code of a JR C, so PRTIME writes over a POP DE (553DH) and the next byte printed returns to a wrong address, and there is no time out; an INDENT not below CHARS wraps with no end; LINES is not compared with PAGE; a 0DH 0AH pair counts two lines; a result of the driver behind the filter is not passed back for a byte sent.

Disassembly:

A disassembly of PR/FLT can be found here.

BASIC/CMD

Purpose:

BASIC/CMD is LBASIC, the Disk BASIC supplied with LDOS. It is not a complete interpreter: the Level II ROM holds the tokenizer, the expression evaluator, the statement executor and the arithmetic, and jumps through 49 vectors at 4152H-41E4H for the disk keywords and at its exits (a byte out, the keyboard, a line typed, READY, an error, CLEAR, PRINT, INPUT, LIST); without a disk those vectors hold RET or an error. BASIC/CMD fills them. The file is a load module of 5414 bytes with the transfer address 52CCH: the image of the vectors at 4E00H-4E9EH and the code and data at 5200H-65FBH. The start copies the image to 4152H-41E4H and the restart vectors to 4000H-400BH, with RST 10H sent to 6579H, where SET EOF and RESTORE with a line number are added; then the code of the start becomes the line buffer.

The command line is BASIC [*] [(FILES=n,MEM=a,BLK=sw,EXT=sw)] [command], read with @PARAM. FILES (0-15, 3 if not given) is the number of files; buffers for files 0 to n are laid out above the code, and file 0 is kept for LOAD, SAVE, MERGE, RUN and KILL. MEM sets the top of memory for BASIC, BLK (on by default) allows records shorter than 256 bytes, and EXT (on) gives the program file the extension /BAS. BASIC with an asterisk goes back to the program in memory; a command after the parameters is run as if typed. LDOS 5.3 or later is needed.

A current file (65F8H) receives the ROM's own output and supplies its input, so PRINT#, INPUT#, LIST to a file and the loading of a program saved with A all go through the ROM's exits; a program saved without A is read straight into memory. At READY the first key may be an arrow, a period or a comma to show or edit a line, and a single letter A, D, E or L is taken as AUTO, DELETE, EDIT or LIST. CMD"N", CMD"X" and CMD"V" run BASIC/OV1, BASIC/OV2 and BASIC/OV4 over 5200H; BASIC/OV3 (the long error messages, the DOS errors, CMD"O", the variables kept by RUN with V, and the M and C line commands) is loaded at 4E00H and called, and is entered at once while OVRLY$ (430EH) holds 01H. Any other CMD text is run as an LDOS command with BASIC's memory moved below the stack and brought back afterwards.

Disassembly:

A disassembly of BASIC/CMD can be found here.

BASIC/OV1

Purpose:

BASIC/OV1 renumbers the BASIC program in memory for CMD"N [!]first,new,increment,last" and changes the line numbers that follow THEN, ELSE, RESUME, GOTO, GOSUB, RUN and ERL (so ON n GOTO and ON n GOSUB lists too); a 0 where a number would start is left alone (GOTO 0, RESUME 0). The values in the file are first 1, new 20, increment 20 and last 65529; a comma alone keeps one, and a value of 0 is not stored, so the next number takes its place. Without the exclamation mark every reference is first checked (Can not find line, Buffer overflow) before anything is changed; with it the references are changed in one pass, and an error leaves the lines before it changed. A program whose first line is numbered 0 gives Error in line 0.

BASIC/CMD runs the file with @RUN over its own image at 5200H, with Register Pair HL at the text after the N. The stack is moved to HIGH$. The first pass writes each line's new number into its link bytes (lines below the range and above it keep their numbers; numbers that would put the lines out of order give Bad parameters), the reference pass copies each line to a buffer at 5700H with the new numbers in its references and writes a changed line back, moving the rest of the program, then the new numbers go into place, the links are rebuilt from the text, the variables are cleared (40F9H, 40FBH and 40FDH set after the program) and BASIC/CMD is run again with an asterisk, back to the program in memory.

Disassembly:

A disassembly of BASIC/OV1 can be found here.

BASIC/OV2

Purpose:

BASIC/OV2 lists the variables of the BASIC program in memory and the line numbers it refers to, each with the lines where it is met: CMD"X [devspec or filespec] [-V or -L or =entry] [<title>]". The listing goes to the video unless a device or file is given first (a file gets /TXT when it has no extension); -V lists only the variables, -L only the line numbers, =entry only one entry, and the text between angle brackets, folded to upper case like the rest of the command line, heads every page. Only the first of a minus sign and an equals sign is read.

BASIC/CMD runs the file with @RUN over its own image at 5200H, with Register Pair HL at the text after the X. Each pass over the program finds the lowest entry above the one listed last, with the lines that have it in a list above the end of the arrays, and lists it: a rule line, a reference column of a colon, the first five characters and a colon, then the lines, eight to an output line, with a new page after 50 or 55 lines. A variable is its first two characters, its type character and a parenthesis for an array; a line number after THEN, ELSE, RESUME, GOTO, GOSUB, RUN or ERL is five digits with zeros in front, so line numbers come before the variables. Strings, remarks, DATA items and constants are passed over. BREAK ends the listing and SHIFT @ pauses it. At the end the file is closed and BASIC/CMD run again with an asterisk, back to the program with its variables.

Found in the code: an error writing the listing file reaches 5656H, whose CALL 5648H unwinds the stack wrongly and returns to an address in the program text instead of reaching @ERROR; the list of line numbers may grow up to the bottom of string space (40A0H), with the stack below it; an error on a device is not reported.

Disassembly:

A disassembly of BASIC/OV2 can be found here.

BASIC/OV3

Purpose:

BASIC/OV3 is the overlay BASIC/CMD calls back into while BASIC runs, so it must be on a disk whenever BASIC is used. BASIC/CMD's 54B6H loads it at 4E00H, the overlay area of LDOS, and enters it at 4E00H with the number of a function in Register A'; the overlay puts 01H in OVRLY$ (430EH), and while that byte holds 01H BASIC/CMD enters it again without reading the disk. The file is a load module of 1229 bytes: a copyright record, 4E00H-5281H in five load blocks and the transfer address 4E00H; its last 130 bytes load over the start of BASIC/CMD's image, its banner and the messages of its start.

Function 01H turns the E value of a BASIC error into its text at 5414H: a dictionary of 78 words (each ended by bit 7 on its last letter) and 49 messages (each a list of word numbers ended by bit 7); the errors of the ROM give messages 2-25, the disk errors (E values 64H-90H) messages 26-48, any other even value Unprintable error. Function 02H keeps an LDOS error code at 65F7H for CMD"E" and enters the ROM's error handler with the E value its table gives: most codes give Disk I/O error, and every code from 29H up gives Internal error. Function 03H is CMD"O",count,array$(first), a Shell sort of the string descriptors in ascending order; nothing tests the type of the variable or the bounds of the array.

Function 04H prepares RUN"file",V: DEF FN functions are left undefined, string constants still in the program text are copied into string space, and the variables and arrays are moved up to end 128 bytes below the stack, with 40A0H set below them; the old pointers go into five operands of BASIC/CMD (5F5EH, 5F65H, 5F71H, 5F7EH, 5F84H) and 65F4H gets D6H, so that BASIC/CMD's 5F5CH puts the variables back after the new program. Functions 05H and 06H are M old,new and C old,new typed at READY: the old line must exist and the new one must not; the old line is turned back into text in the input buffer and the ROM's EDIT exit (2FEBH) stores it as the new line. For M the line input vector 41AFH is pointed at 501AH, so the next line input deletes the old line with the ROM's DELETE and shows READY; when the new line cannot be stored the old one is deleted all the same. BASIC/OV3 makes no request of the DOS: OVRLY$ is the only cell of LDOS it uses, and it calls only the ROM.

Disassembly:

A disassembly of BASIC/OV3 can be found here.

BASIC/OV4

Purpose:

BASIC/OV4 lists the variables and arrays of the BASIC program in memory with their values, and the functions made by DEF FN with their definitions: CMD"V [*DO or *PR] [-S] [-A] [=letter]". The device comes first, the video unless *PR is given (another device gives Invalid output device!); -S lists only the simple variables, -A only the arrays, =letter only the names that start with that letter; anything else is Parameter error!. It reads only the tables of the variables (40F9H, 40FBH, 40FDH), so it can be given while a program is stopped. SHIFT @ holds the listing and BREAK ends it.

BASIC/CMD runs the file with @RUN over its own image at 5200H, with Register Pair HL at the text after the V; the file is 960 bytes, 5200H-5569H and 5574H-557EH in five load blocks, and the ten bytes between, the counters of the subscripts, are not in the file. BASIC/OV4 does not turn values into text itself: for each variable it builds the items of a PRINT statement, a quoted text with the name and an equals sign followed by the name again, and the ROM runs them from 2069H, inside LPRINT, with the device in Register A. Every element of an array is listed, its subscripts counted from 0 with the rightmost fastest; a DEF FN function is shown as its definition turned back into text by the ROM's BUFLIN, followed by <User Def Func>. At the end BASIC/CMD is run again with an asterisk, back to the program with its variables.

Found in the code: the banner in the file is never shown; an array of 6 or more dimensions gets a text that ends with a right parenthesis with no left one; the copy of <User Def Func>, which ends with 0DH, runs on through the two messages after it.

Disassembly:

A disassembly of BASIC/OV4 can be found here.