TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - SYS1/SYS Disassembled
Page Customization
Page Index
SYS1/SYS
Other Navigation
Introduction/Summary
SYS1/SYS is the DOS command overlay of NEWDOS/80 v2.0 for the Model I. It loads at 4D00H-51DFH (1,248 bytes, entry point 4D00H) and runs whenever SYS0 issues an RST 28H with a code whose low five bits are 03H (directory sector 5, first file). It shows the NEWDOS/80 READY and MINI-NEWDOS/80 READY prompts, reads a command line, looks the command up in its library table and starts the overlay that carries it out. It also provides DOS-CALL, filespec extraction and default extension insertion to the rest of the system, and the LIB, CLS, MDRET and MDBORT commands itself.
SYS1 Functions
SYS0 selects the function with bits 5-7 of the RST 28H code. Function 7 takes a sub-function number in Register C.
| Code | Handler | Purpose |
|---|---|---|
| 23H | 4D8AH | Function 1: DOS READY with no error (SYS0 4400H, reached from 402DH). Also the target of the R table entry. |
| 43H | 4D7CH | Function 2: exit after an error has already been displayed (SYS0 4030H). |
| 63H | 4E30H | Function 3: execute the DOS command at HL (SYS0 4405H). |
| 83H | 513DH | Function 4: extract a filespec from HL into the buffer at DE (SYS0 441CH). |
| A3H | 4F2AH | Function 5: insert the default extension at HL into the filespec at DE (SYS0 4473H). |
| C3H | 4D5BH | Function 6: DOS-CALL, execute the command at HL and return (SYS0 4419H). |
| E3H, C=01H | 4D59H | Discard one stack word and return. |
| E3H, C=02H | 50B7H | LIB: list the library commands. |
| E3H, C=04H | 50DBH | Enter MINI-DOS. |
| E3H, C=05H | 4D80H | MDBORT: abandon MINI-DOS and the interrupted program. |
| E3H, C=06H | 50FAH | MDRET: leave MINI-DOS and resume the interrupted program. |
| E3H, C=07H | 4D78H | Discard two stack words and exit with no error. |
| E3H, C=08H | 4E34H | Execute the line just typed at DOS READY (set up at 4DFAH). |
| E3H, C=09H | 4D48H | CLS: clear the screen. |
| E3H, C=0BH | 5150H | Parse a filespec from HL into the buffer at DE. |
| E3H, C=0CH | 4D80H | The same as MDBORT. |
| other | 4D44H | Error 2AH (this includes sub-functions 03H and 0AH). |
Command Table Format
The library command table at 4F58H holds 46 commands in alphabetical order. Each entry is the name in plain ASCII followed by three attribute bytes; the table ends with 00H. A command that is not in the table is run as a program (default extension /CMD) by SYS2, unless it starts with *, which goes to SYS9.
| Byte | Meaning |
|---|---|
| 1 | Bit 7 always set (marks the end of the name). Bit 6 = not allowed under MINI-DOS (error 38H). Bits 0-4 = sub-function number passed to the overlay in Register C. |
| 2 | The RST 28H code of the overlay function: bits 0-2 = directory sector minus 2, bits 3-4 = file within that sector, bits 5-7 = function. For example E9H = SYS7 function 7, EBH = SYS9 function 7, E5H = SYS3 function 7, F0H = SYS14 function 7. |
| 3 | Bit 7 = open the file in the FCB at 4480H (bit 6 also set: new or existing, SYS0 4420H; otherwise existing only, 4424H). Bit 6 or 7 = parse a filespec into 4480H. Bit 5 = a second filespec follows, optionally after TO, into 51E0H. Bit 4 = nothing may follow (error 34H). Bit 3 = leave the command line pointer on the stack for the overlay. Bits 0-2 = default extension: 1 = /CMD, 2 = /JCL. |
Error Codes Set by SYS1
- 2AH - unknown function or sub-function; MDRET when MINI-DOS is not active (4D44H).
- 30H - a filespec could not be parsed (4EF1H).
- 34H - a separator was missing or something followed a command that allows nothing after it (set by SYS0 4CD5H/4CD9H).
- 36H - the command line is longer than 80 characters (4E5BH).
- 38H - the command is not allowed under MINI-DOS (4EBCH).
Variables
Memory Used by SYS1
| Address Size | Contents |
|---|---|
| 4022H 1 byte | Cursor Byte The ROM's cursor byte (00H = cursor off, otherwise the character under the cursor). Saved when MINI-DOS is entered (50E7H) and restored by MDRET (5114H). |
| 4200H-42FFH 256 bytes | Sector Buffer Passed in Register Pair HL when a command's file is opened (4F1FH). |
| 4312H-4314H 3 bytes | BREAK Key Hook Rewritten at 4DCDH-4DD9H as JP 45B0H (BREAK ignored, Register A = 00H) or RET (BREAK is a key), chosen by option AG (bit 5 of 436CH). |
| 4318H-4367H 80 bytes | Command Buffer The ROM line input writes here (4E0AH); every command is copied here in upper case (4E43H). |
| 4369H 1 byte | DOS Flags Bit 5 (chaining): suppresses the READY message (4DF0H), sends errors to SYS9 sub-function 04H (4DA8H), and keeps a DOS-CALL at the prompt when bit 4 of 436AH is also set (4E15H); cleared by MDBORT. Bit 6: cleared at every exit (4DACH). Bit 4: cleared when a nested DOS-CALL returns (4E25H). |
| 436AH 1 byte | DOS State Flags Bit 7 MINI-DOS active. Bit 6 DOS-CALL active. Bit 5 waiting for a command line at DOS READY (set at 4DF8H, cleared at 4E41H). Bit 4 chaining under DOS-CALL (4E19H); cleared by MDBORT and when the outermost DOS-CALL returns. Bit 2 an error at reset: every exit goes to SYS9 sub-function 0BH (4D98H). |
| 436BH 1 byte | Temporary Flags Cleared at every exit (4D8FH). |
| 436CH 1 byte | Options F0H Bit 6 option AB (RUN-ONLY): exits go to SYS9 sub-function 0CH unless chaining (4DB5H). Bit 5 option AG: selects the BREAK hook (4DCBH). |
| 436DH 1 byte | Options F1H Bit 5 option BE: the R command repeats the previous command (4E62H). |
| 439BH-439CH 2 bytes | MINI-DOS Stack The Stack Pointer saved when MINI-DOS is entered (50EBH), reloaded at 4DE3H and 5102H. |
| 439DH-439EH 2 bytes | DOS-CALL Stack The Stack Pointer of the innermost DOS-CALL level (4D70H); each level pushes the previous value (4D6FH). |
| 43A7H-43A8H 2 bytes | Previous Command The first two bytes of the command buffer before a new line is read (4E05H), for the R command. |
| 41E0H | DOS Stack The Stack Pointer is reset here at DOS READY (4DC8H) and by function 3 (4E30H). |
| 4480H-449FH 32 bytes | First Filespec and FCB A command's filespec is parsed here (514DH) and the file opened from it (4F24H). |
| 51E0H-51FFH 32 bytes | Second Filespec Just past the end of the file; used by MDCOPY and RENAME (4EEAH). |
Outside Routines Called
| Address Size | Contents |
|---|---|
| 0033H | ROM: display the character in Register A (4DEDH, 50F4H, 5108H, 5110H, 51A1H). |
| 0040H | ROM: line input into Register Pair HL, Register B characters (4E0DH). |
| 402DH, 4408H, 4409H | SYS0: the exits pushed at 4E35H-4E3CH. |
| 4420H, 4424H | SYS0: open a file (4F24H, 4F27H). |
| 4467H | SYS0: display a message (4D4BH, 4DF2H). |
| 45B0H, 45B5H | SYS0: BREAK ignored (4DCDH) and upper case conversion (4E4FH). |
| 49D3H, 49D6H | SYS0: return points that issue RST 28H with the word on the stack (4F16H, 4DFDH). |
| 4CC5H, 4CD5H, 4CD9H | SYS0: keyword compare and separator tests (4EDEH, 4E85H, 4ED5H). |
SYS1 has no self-modifying code.
Disassembly
4D00H - Overlay Entry: Function Dispatcher
SYS0 enters every overlay at its first byte. Register A holds the RST 28H code that loaded SYS1 (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 51C5H (1CH cursor home, 1FH clear to end of screen, 03H end of message) to the display.
4D4EH - Unreferenced Code
Nothing in SYS1 jumps or calls to 4D4EH, and SYS0 enters the overlay only at 4D00H. The bytes push E301H (function 7, sub-function 01H) and 49D3H (the SYS0 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 49D3H to get back from another overlay function (the word E301H is dropped here).
4D5BH - Function 6: DOS-CALL
Entered through SYS0 4419H with Register Pair HL pointing to a DOS command. All registers are saved (512BH). DOS-CALLs can nest: bit 6 of 436AH shows that one is active, and each level pushes the previous level's saved Stack Pointer (439DH) before storing its own. The command is then run by the normal command code at 4E35H. When it finishes, the exit code at 4E10H 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 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 436AH and bit 5 of 4369H, 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 50F7H 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 function 7 is called for sub-functions 0BH, 04H or 0CH; a DOS-CALL is unwound at 4E10H; otherwise the DOS READY (or MINI-DOS READY) prompt is shown and a new command line is read. Register B holds the flags from 436AH and Register C those from 4369H throughout.
An Error Occurred
Any error other than 38H.
Show the Prompt and Read a Command Line
4E10H - Return From a DOS-CALL
Reached from 4DB0H when bit 6 of 436AH is set. Register B = the 436AH flags, Register C = the 4369H flags, Register Pair HL = 4369H. 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.
4E30H - Function 3: Execute a DOS Command
Entered through SYS0 4405H with Register Pair HL pointing to a command line. 4E34H is the entry for sub-function 08H (a line typed at DOS READY). Both reach 4E35H with one word less on the stack than they had at entry.
4E35H - Copy the Command Line and Look It Up
Pushes 402DH and 4408H so that a command which RETurns goes to 4408H in SYS0 (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 4318H, 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 43A7H before the input.
Command Table Search
The table at 4F58H: 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 * goes to SYS9 function 7, sub-function 07H. Anything else is taken as the name of a program to run: SYS2 function 7, sub-function 03H, with the attributes 43H (sub-function 03H, not under MINI-DOS) and 41H (parse the filespec, default extension /CMD).
4EA7H - 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 49D3H and returning to it: 49D3H 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.
4F2AH - Function 5: Insert a Default Extension
Entered through SYS0 4473H and from 4F11H. 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
4F58H - Command Table (Data)
One entry per DOS command handled by an overlay: the name in ASCII, then three attribute bytes (see 4EA7H). 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 50B6H. LIB (50B7H) lists the names.
50B7H - LIB Command (Sub-Function 02H)
Lists the command names from the table at 4F58H, 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.
50DBH - Enter MINI-DOS (Sub-Function 04H)
Saves every register, remembers the Stack Pointer at 439BH and the cursor state from 4022H, sets bit 7 of 436AH, 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.
50FAH - MDRET Command (Sub-Function 06H)
Leaves MINI-DOS and returns to the interrupted program. Restores the stack saved at 50EBH, 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.
511AH - Restore All Registers and Return
Undoes 512BH. 511AH returns Register A = 00H with the Z FLAG set; 511BH (from 4E2DH) 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.
512BH - 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 512BH takes the return address into it, and EX AF,AF' parks it while AF' is pushed.
513DH - Function 4: Extract a Filespec
Entered through SYS0 441CH with Register Pair HL pointing to the text and Register Pair DE to a 32-byte buffer. Parses the filespec (5150H), 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.
514DH - Parse a Filespec
514DH parses into the buffer at 4480H (called from 4ECCH). 5150H parses into the buffer at Register Pair DE (from 4EEDH, 513DH and sub-function 0BH at 4D3EH). At most 32 bytes are used. Register Pair DE is preserved and Register B is returned as 00H.
515AH - Copy the Filespec Characters
An optional * 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
5189H - 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).
5195H - Display Spaces
Displays Register B spaces. Called from 50D6H.
519DH - Display a Carriage Return
519FH displays the character in Register A, keeping Register Pairs AF and DE.
51A7H - Default Extensions and Messages (Data)
The extensions are selected by bits 0-2 of the third attribute byte (4F08H). The two messages are shown by 4DF2H through SYS0 4467H: NEWDOS/80 READY starts at 51B5H, MINI-NEWDOS/80 READY at 51B0H.
51E0H - Second Filespec Buffer
Not part of the file. The second filespec of MDCOPY and RENAME is parsed here by 4EEDH (at most 31 characters and the 03H end marker).