TRS-80 DOS - NEWDOS/80 v2.0 for the Model III - SYS1/SYS Disassembled
Page Customization
Page Index
SYS1/SYS
Other Navigation
Introduction/Summary
NEWDOS/80 v2.0 SYS1/SYS Disassembly - The Command Interpreter (Model III)
SYS1/SYS is the overlay (directory slot 03H) that runs the DOS command level. SYS0/SYS loads it into the overlay area at 4D00H through RST 28H and enters it at its first byte with the RST 28H code in Register A. It shows the NewDos/80 Ready and Mini-NewDos/80 Ready prompts, reads command lines into the command buffer at 4225H, looks the command name up in its table of 47 entries, parses the filespecs the command needs, opens the file if the command wants it, and starts the overlay function that carries out the command. It also handles DOS-CALL (commands run from a program, which can nest), MINI-DOS (entered with D-F-G from a running program), the exit after every command, filespec extraction, default extensions and the LIB, CLS, MDBORT and MDRET commands.
The file is 1,248 bytes in five load records, 4D00H-51DFH, transfer address 4D00H. Every byte is shown once on this page, checked against S:\1\SYS1.SYS and its listing.
Functions
| Code | Function |
|---|---|
| 23H | Function 1: DOS READY with no error (SYS0/SYS 4400H, 402DH), 4D8AH. |
| 43H | Function 2: the exit after an error that has already been displayed (SYS0/SYS 4030H), 4D7CH. |
| 63H | Function 3: execute the command at Register Pair HL (SYS0/SYS 4405H), 4E47H. |
| 83H | Function 4: extract a filespec (SYS0/SYS 441CH), 5154H. |
| A3H | Function 5: insert a default extension (SYS0/SYS 4473H), 4F41H. |
| C3H | Function 6: DOS-CALL (SYS0/SYS 4419H), 4D5BH. |
| E3H | Function 7, sub-function in Register C: 01H drop a word and return (4D59H), 02H LIB (50CEH), 03H refused (error 2AH), 04H enter MINI-DOS (50F2H, from D-F-G), 05H MDBORT (4D80H), 06H MDRET (5111H), 07H drop two words and exit (4D78H), 08H run the line typed at DOS READY (4E4BH), 09H CLS (4D48H), 0BH parse a filespec (5167H), 0CH the same as MDBORT; anything else error 2AH. |
How a Command Runs
The line is copied into 4225H in upper case (at most 80 characters, else error 36H). With option BE a line of just R repeats the previous command, whose first two characters were saved at 42C7H. The name is looked up in the table at 4F6FH; its three attribute bytes give the sub-function and MINI-DOS restriction (byte 1), the RST 28H code of the overlay function (byte 2) and the filespec handling (byte 3: parse into 4480H, open the file existing or new, a second filespec into 51E0H, nothing may follow, keep the command line pointer, default extension /CMD or /JCL). A name that is not in the table is a program to run (SYS2/SYS function 7, sub-function 03H, default extension /CMD); a name that starts with an asterisk is a named routine (SYS9/SYS function 7, sub-function 07H). The overlay is started through SYS0/SYS 4978H, and every command returns to SYS0/SYS 4408H, which goes on to DOS READY (402DH) or to the error exit (4409H).
The Command Exit (4D8BH)
Every command ends at 4D8BH with Register A and the flags giving the result. An error at reset (bit 2 of 428AH) calls SYS9/SYS's DOS FATAL ERROR (sub-function 0BH); an error while chaining calls SYS9/SYS sub-function 04H; RUN-ONLY at DOS READY shows 'RUN ONLY' STOPPED (sub-function 0CH). A DOS-CALL returns to its caller with the result (4E27H). Otherwise the stack is reset to 41E0H, the BREAK hook at 4478H is set from option AG, the prompt is shown (not while chaining), the ROM's protected screen lines, its BREAK vector and the cassette motor are reset at plain DOS READY, and the next line is read with the ROM's line input.
Notes from the Code
- 4D4EH-4D58H is never reached: nothing jumps there and SYS0/SYS enters the overlay only at 4D00H.
- Sub-function 03H of function 7 is tested but always ends with error 2AH (4D24H).
- The R command restores only the first two characters of the buffer: the ROM's line input overwrites only what is typed (4E76H-4E89H).
- The letter test (51A0H) accepts lower case letters, so filespecs may be typed in lower case; the command line itself is converted to upper case (4E66H).
- The table has an entry R (5087H) that runs SYS1/SYS function 1, DOS READY, when option BE is N.
Variables
Addresses Used by SYS1/SYS
| Address | Contents |
|---|---|
| 4022H 1 byte | The ROM's cursor flag (00H = off), saved and restored by MINI-DOS (50FEH, 512BH). |
| 4204H-4205H 2 bytes | The address part of the ROM's BREAK and disk error vector, set to 4030H at DOS READY (4E0BH). |
| 4214H 1 byte | The ROM's count of protected screen lines, cleared at DOS READY (4E05H). |
| 4225H-4274H 80 bytes | The command buffer (4E5AH-4E6BH); the line input reads into it (4E21H). |
| 4289H 1 byte | System flags: bit 5 chaining (4DA8H, 4E00H), bit 6 an overlay function running (cleared 4DACH), bit 4 (cleared 4E3CH). |
| 428AH 1 byte | DOS state flags: bit 7 MINI-DOS (5106H, 512FH), bit 6 DOS-CALL (4D67H, 4E3AH), bit 5 waiting at DOS READY (4DF8H, 4E58H), bit 4 a chain file at this DOS-CALL level (4E30H), bit 2 an error at reset (set by SYS4/SYS, tested 4D98H). |
| 428BH 1 byte | The overlays' temporary flags, cleared after every command (4D8FH). |
| 428CH 1 byte | Options: bit 6 AB RUN-ONLY (4DB5H), bit 5 AG BREAK as a key (4DCBH). |
| 428DH 1 byte | Options: bit 5 BE, the R command (4E79H). |
| 42BBH-42BCH 2 bytes | The Stack Pointer saved when MINI-DOS was entered (5102H; read 4DE3H, 5119H). |
| 42BDH-42BEH 2 bytes | The Stack Pointer of the current DOS-CALL level (4D70H, 4E28H, 4E3EH). |
| 42C7H-42C8H 2 bytes | The first two characters of the previous command line, for R (4E1CH, 4E86H). |
| 4478H-447AH 3 bytes | The BREAK key hook, set to JP 4546H or RET from option AG (4DD0H, 4DD9H). |
| 4480H-449FH 32 bytes | The DOS FCB, which receives a command's filespec (5164H) and is opened by 4F3BH/4F3EH. |
| 4300H 256 bytes | The buffer given to the open (4F36H). |
| 51E0H-51FFH 32 bytes | The second filespec of a command (4F01H), just past the end of the file. |
| 41E0H stack | The top of the DOS stack (4DC8H, 4E47H). |
Disassembly
4D00H - Overlay Entry: Function Dispatcher
SYS0/SYS enters every overlay at its first byte. Register A holds the RST 28H code that loaded SYS1/SYS (xxx00011B: bits 5-7 are the function number). Functions 1-6 are chosen by Register A alone. Function 7 (E3H) uses Register C as a sub-function number, which the DEC C chain below counts down.
Function 7 Sub-Function Chain
Anything else is taken as function 7 (E3H). Register C holds the sub-function number; each DEC C sets the Z FLAG when Register C reaches that number.
No Function Matched
Return error 2AH to the caller.
4D48H - CLS Command (Function 7, Sub-Function 09H)
Clears the screen by sending the three bytes at 51DCH (1CH cursor home, 1FH clear to end of screen, 03H end of message) to the display.
4D4EH - Unreferenced Code
Nothing in SYS1/SYS jumps or calls to 4D4EH, and SYS0/SYS enters the overlay only at 4D00H. The bytes push E301H (function 7, sub-function 01H) and 4978H (the SYS0/SYS routine that issues an RST 28H with the word on the stack) and then do an RST 28H with whatever is in Register A.
4D59H - Sub-Function 01H: Discard a Word and Return
Also the end of the unreferenced 4D4EH block. Used by callers that pushed E301H and 4978H to get back from another overlay function (the word E301H is dropped here).
4D5BH - Function 6: DOS-CALL
Entered through SYS0/SYS 4419H with Register Pair HL pointing to a DOS command. All registers are saved (5142H). DOS-CALLs can nest: bit 6 of 428AH shows that one is active, and each level pushes the previous level's saved Stack Pointer (42BDH) before storing its own. The command is then run by the normal command code at 4E4CH. When it finishes, the exit code at 4E27H unwinds one level and returns to the caller.
4D78H - Sub-Function 07H
Discards two words from the stack and goes to the exit code. The second word popped into Register Pair AF becomes the command's result that 4D8BH examines.
4D7CH - Function 2: Error Already Displayed
Used by SYS0/SYS at 4030H after an error message has been shown. Register A = 00H with the CARRY FLAG set tells 4D8BH that this is an error exit.
4D80H - MDBORT Command (Sub-Functions 05H and 0CH)
Clears the MINI-DOS, DOS-CALL and bit 4 flags in 428AH and bit 5 of 4289H, then exits with no error. With the MINI-DOS flag gone, 4D8BH resets the stack and shows NEWDOS/80 READY, so the program that was interrupted by MINI-DOS is abandoned.
4D8AH - Function 1: DOS READY (No Error)
Also reached from 510EH after MINI-DOS is entered.
4D8BH - Command Exit Processing
Every command ends here, with Register A and the flags giving the result: Z and NO CARRY = no error; CARRY = error already displayed; NZ = error code in Register A. The flag bytes decide what happens next: SYS9/SYS function 7 is called for sub-functions 0BH, 04H or 0CH; a DOS-CALL is unwound at 4E27H; otherwise the DOS READY (or MINI-DOS READY) prompt is shown and a new command line is read. Register B holds the flags from 428AH and Register C those from 4289H throughout.
An Error Occurred
Any error other than 38H.
Show the Prompt and Read a Command Line
4E27H - Return From a DOS-CALL
Reached from 4DB0H when bit 6 of 428AH is set. Register B = the 428AH flags, Register C = the 4289H flags, Register Pair HL = 4289H. Restores this level's stack, removes the level, and returns to the DOS-CALL caller with the command's result in Register A and the flags.
4E47H - Function 3: Execute a DOS Command
Entered through SYS0/SYS 4405H with Register Pair HL pointing to a command line. 4E4BH is the entry for sub-function 08H (a line typed at DOS READY). Both reach 4E4CH with one word less on the stack than they had at entry.
4E4CH - Copy the Command Line and Look It Up
Pushes 402DH and 4408H so that a command which RETurns goes to 4408H in SYS0/SYS (RET Z to 402DH, DOS READY, if there was no error; otherwise the DOS error exit at 4409H). Copies the line from Register Pair HL into the command buffer at 4225H, converting it to upper case, and handles the R command. The line may be at most 80 characters including the carriage return. Also entered from 4D75H for a DOS-CALL.
Copy Loop
Register Pair DE = the source, Register Pair HL = the buffer, Register B = room left.
The R Command
R repeats the previous command. The ROM line input overwrites only as much of the buffer as is typed, so after R and ENTER only the first two bytes of the previous line are lost; they were saved at 42C7H before the input.
Command Table Search
The table at 4F6FH: each entry is the name followed by three attribute bytes, the first of which has bit 7 set; the table ends with 00H.
Not a Command Name
A command beginning with an asterisk goes to SYS9/SYS function 7, sub-function 07H. Anything else is taken as the name of a program to run: SYS2/SYS function 7, sub-function 03H, with the attributes 43H (sub-function 03H, not under MINI-DOS) and 41H (parse the filespec, default extension /CMD).
4EBEH - Run a Command
The name matched. Register Pair DE points to the first attribute byte and Register Pair HL to the rest of the command line. The attributes are:
Byte 1 (Register C): bit 7 always set (end of name); bit 6 = not allowed under MINI-DOS; bits 0-4 = the sub-function number passed to the overlay.
Byte 2 (Register B): the RST 28H code of the overlay function that does the work.
Byte 3 (Register D): bit 7 = open the file (with bit 6: new or existing, 4420H; without: existing, 4424H); bit 6 or 7 = parse a filespec into 4480H; bit 5 = a second filespec follows, optionally after TO, parsed into 51E0H; bit 4 = nothing may follow; bit 3 = leave the command line pointer on the stack for the overlay; bits 0-2 = default extension (1 = /CMD, 2 = /JCL).
The overlay is started by pushing 4978H and returning to it: 4978H goes to the DOS error exit if the Z FLAG is clear, otherwise issues RST 28H with the code and sub-function left on the stack.
4F41H - Function 5: Insert a Default Extension
Entered through SYS0/SYS 4473H and from 4F28H. Register Pair DE points to a filespec, Register Pair HL to a three-character extension. The filespec is scanned for up to nine characters. If a / is found it already has an extension and nothing changes. Otherwise, at the first : or character below / (such as the . before a password or the 03H end marker), the rest of the filespec is moved four bytes to the right and / plus the extension is inserted. The move covers 1CH bytes counted from the start of the filespec. Register Pairs DE and BC are preserved.
Scan Loop
4F6FH - Command Table (Data)
One entry per DOS command handled by an overlay: the name in ASCII, then three attribute bytes (see 4EBEH). Byte 1 has bit 7 set and ends the name; bit 6 = not allowed under MINI-DOS; bits 0-4 = the sub-function. Byte 2 = the RST 28H code of the overlay function. Byte 3 = the filespec flags. The table ends with 00H at 50CDH. LIB (50CEH) lists the names.
50CEH - LIB Command (Sub-Function 02H)
Lists the command names from the table at 4F6FH, eight to a line, each in an eight-character column.
Name Loop
Register Pair HL = the table, Register B = columns left, Register C = names left on the line.
50F2H - Enter MINI-DOS (Sub-Function 04H)
Saves every register, remembers the Stack Pointer at 42BBH and the cursor state from 4022H, sets bit 7 of 428AH, starts a new line and goes to the exit code, which shows MINI-NEWDOS/80 READY and reads commands. If MINI-DOS or a DOS-CALL is already active it just returns.
5111H - MDRET Command (Sub-Function 06H)
Leaves MINI-DOS and returns to the interrupted program. Restores the stack saved at 5102H, turns the cursor on (0EH) and back off (0FH) if it was off, restores 4022H, clears the MINI-DOS flag and restores all registers. Error 2AH if MINI-DOS is not active.
5131H - Restore All Registers and Return
Undoes 5142H. 5131H returns Register A = 00H with the Z FLAG set; 5132H (from 4E44H) returns the Register A and flags it is entered with. The EX AF,AF' pair keeps the result in AF while the saved AF' is popped.
5142H - Save All Registers
Pushes Register Pairs HL, DE, BC, HL', DE', BC', AF', IX and IY under the return address. The caller's AF is not saved: the POP AF at 5142H takes the return address into it, and EX AF,AF' parks it while AF' is pushed.
5154H - Function 4: Extract a Filespec
Entered through SYS0/SYS 441CH with Register Pair HL pointing to the text and Register Pair DE to a 32-byte buffer. Parses the filespec (5167H), then moves Register Pair HL past the character that ended it unless that character is 03H or 0DH. Returns the Z FLAG if the filespec was valid.
5164H - Parse a Filespec
5164H parses into the buffer at 4480H (called from 4EE3H). 5167H parses into the buffer at Register Pair DE (from 4F04H, 5154H and sub-function 0BH at 4D3EH). At most 32 bytes are used. Register Pair DE is preserved and Register B is returned as 00H.
5171H - Copy the Filespec Characters
An optional asterisk is copied first. The next character must be a digit or a letter. Then digits, letters, ., / and : are copied until any other character, which is left at Register Pair HL; the filespec in the buffer is ended with 03H and the routine returns with Register A = 00H and the Z FLAG. If the first character is not a digit or letter, or the buffer fills, it returns NZ with Register Pair HL back at the start and Register A = that character.
Copy Loop
51A0H - Letter Test
Entered with the CARRY FLAG already set if an earlier test passed. Returns the CARRY FLAG set if the character at Register Pair HL is A-Z or a-z (or if it was set on entry).
51ACH - Display Spaces
Displays Register B spaces. Called from 50EDH.
51B4H - Display a Carriage Return
51B6H displays the character in Register A, keeping Register Pairs AF and DE.
51BEH - Extensions and Messages (Data)
The default extensions, the word TO, the two READY prompts and the CLS message.