TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - SYS1/SYS Disassembled
Page Customization
Page Index
SYS1/SYS
Other Navigation
Introduction/Summary
The SYS1/SYS module is the second part of the NEWDOS/80 v2.0 bootstrap sequence for the TRS-80 Model I, loaded immediately after BOOT/SYS and SYS0/SYS. Its main purpose is to set up the necessary input/output (I/O) routines and disk error handling before transferring control to the next DOS component.
Core Functionality
SYS1/SYS primarily consists of two major sections:
I/O and Driver Setup
This section loads and initializes key I/O routines required by the DOS.
It contains the code for the printer driver (for outputting to a parallel printer).
It also contains routines for the keyboard input and screen output used by the DOS command line interface and internal commands.
The module ensures that the fundamental system I/O is configured and ready for the higher-level DOS components.
Disk Error Processing
This is a critical component of the SYS1/SYS module.
It holds the routine that handles all Disk Errors encountered during disk operations (like reading or writing a sector).
When an error occurs, this routine is executed to analyze the status reported by the Floppy Disk Controller (FDC).
It is responsible for determining the type of error (e.g., CRC error, seek error, write protect) and taking the appropriate action, which typically involves displaying an error message and giving the user options, such as Retry (R), Ignore (I), or Cancel (C).
In essence, SYS1/SYS acts as the DOS's primary interface to the machine's I/O hardware and establishes the low-level logic for reliable disk usage and error recovery. After executing and setting up these services, it passes control to the next stage of the DOS loading sequence.
Variables:
| Address | Bytes | Purpose |
|---|---|---|
| 4022H | 1 | Cursor blink state storage. Non-zero = cursor was on, Zero = cursor was off. |
| 402DH | 3 | DOS No-Error Exit vector (JP instruction). Programs jump here on successful completion. |
| 4030H | 3 | DOS Error-Already-Displayed Exit vector. Jump here when error message already shown. |
| 4200H | 256 | DOS Sector buffer (also aliased at 5100H-51FFH for overlay area). |
| 4300H | 24 | Storage area including PDRIVE and SYSTEM specifications. |
| 4312H | 1 | BREAK key enable flag. C9H = enabled (RET instruction), C3H = disabled (JP instruction). |
| 4313H | 2 | BREAK key handler jump address (used when 4312H contains C3H). |
| 4318H | 80 | DOS Command buffer. User input and commands are stored here (4318H-4367H). |
| 4368H | 1 | SYSTEM storage - system state flags. |
| 4369H | 1 | SYSTEM storage - additional flags (bit 5 checked for certain operations). |
| 436AH | 1 | DOS system flags byte 1.
|
| 436BH | 1 | DOS system flags byte 2.
|
| 436CH | 1 | DOS system flags byte 3.
|
| 436DH | 1 | DOS system flags byte 4.
|
| 4371H | 42 | PDRIVE storage area (4371H-439AH). Contains physical drive configuration data. |
| 439BH | 2 | Saved stack pointer for MINI-DOS. Stores SP when entering MINI-DOS for later restoration. |
| 439DH | 2 | Saved stack pointer for DOS-CALL. Stores SP when entering DOS-CALL mode. |
| 43A7H | 2 | Saved command buffer pointer. Stores original (4318H) value for R command repeat functionality. |
| 4408H | 3 | DOS command execution return address vector. |
| 4467H | — | DOS message display routine entry point. |
| 4480H | 32 | Filename parsing buffer. Parsed filename components stored here. |
| 45B0H | — | BREAK key handler routine address (stored into 4313H). |
| 45B5H | — | Character case conversion routine. |
| 4CD5H | — | Filespec parsing subroutine. |
| 4CD9H | — | Filespec validation subroutine. |
| 4CC5H | — | String comparison subroutine. |
| 4F58H | — | Command name lookup table. Contains DOS command names with attributes. |
| 51A7H | 3 | ASCII string "CMD" - command file extension. |
| 51AAH | 3 | ASCII string "JCL" - job control language extension. |
| 51ADH | 3 | ASCII string "TO" with null terminator - COPY command keyword. |
| 51B0H | 5 | ASCII string "MINI-" - prefix for MINI-DOS ready message. |
| 51B5H | 16 | ASCII string "NEWDOS/80 READY" with CR terminator - DOS prompt message. |
| 51C5H | 4 | System parameter table (1CH, 1FH, 03H, 00H). |
| 51E0H | 32 | Working buffer at end of overlay area. Used for temporary filename storage. |
Disassembly
4D00H - DOS OVERLAY COMMAND DISPATCHER
This is the entry point of the NEWDOS/80 DOS Overlay module (SYS6/SYS). When the DOS receives a command, it loads this overlay and jumps here with Register A containing a command dispatch code to determine which function to execute. Register C also contains a secondary dispatch counter for some functions.
The following section uses Register C as a countdown counter to dispatch to different command handlers. Each DEC C decrements the counter, and when it reaches zero, that handler is called.
If none of the dispatch codes matched, return an ILLEGAL ENTRY error (error code 2AH).
4D48H - ERROR MESSAGE DISPLAY AND EXIT
This routine displays an error message and exits via the DOS display routine at 4467H. HL points to a message table entry at 51C5H.
4D4EH - RST 28H SVC PREPARATION ROUTINE
This routine prepares for a DOS supervisor call (RST 28H) by saving the alternate register set and setting up parameters. This is used internally by DOS to load and execute system modules.
4D59H - SIMPLE POP AND RETURN
Simple return routine that pops the AF register and returns. Used when a command completes with the status already set.
4D5BH - DOS-CALL ENTRY HANDLER
This routine handles entry into DOS-CALL mode, which allows user programs to invoke DOS functions and commands. It saves all registers, manages the DOS-CALL nesting level, and sets up the stack for DOS operations. Address 4419H vectors here via dispatch code C3H.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
4D78H - DOUBLE POP AND CONTINUE TO EXIT
This routine pops two values from the stack (discarding return addresses) and continues to the standard exit routine.
4D7CH - SET CARRY AND EXIT
This routine clears A, sets the Carry flag, and exits. Used to indicate a specific completion state (possibly indicating BREAK was pressed or a special condition).
4D80H - CLEAR SYSTEM FLAGS AND EXIT
This routine clears certain system flags in the DOS status bytes at 4369H and 436AH, then exits cleanly. Used when completing operations that need to reset DOS state.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
4D8AH - CLEAN EXIT ENTRY POINT
This is a common entry point for clean exits. A is zeroed and processing continues to check DOS state and return appropriately.
4D8BH - MAIN EXIT PROCESSING ROUTINE
This is the main exit processing routine for DOS commands. It disables interrupts, checks DOS state flags to determine if in DOS-CALL or MINI-DOS mode, and handles the appropriate exit sequence. The entry flags (Z, C) from previous code indicate the exit status.
- Bit 7 = special return mode
- Bit 6 = stack save mode
- Bit 2 = error state
- Bit 7 = special return mode
- Bit 6 = stack save mode
- Bit 2 = error state
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
If we reach here, NZ and NC are set, meaning there's a non-zero error code in A.
Continue with normal error/exit processing.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
- Bit 6 = chaining active flag
- Bit 5 = additional state
- Bit 6 = chaining active flag
- Bit 5 = additional state
Execute RST 28H to invoke DOS error handler or load another module.
Check if MINI-DOS mode is active.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
Normal DOS READY mode - reset stack to DOS area and set up BREAK key handling.
- Bit 6 = chaining active flag
- Bit 5 = additional state
Set up to display DOS READY prompt.
MINI-DOS mode - restore stack and display MINI-DOS prompt.
Display the prompt and wait for next command.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
Set up to read the next command from keyboard.
4E10H - DOS-CALL EXIT HANDLER
This routine handles exiting from DOS-CALL mode. It restores the stack pointer and registers that were saved on DOS-CALL entry, and manages nested DOS-CALL levels.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
Pop the previous stack pointer and manage DOS-CALL nesting.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
4E30H - COMMAND EXECUTION WITH STACK RESET
This routine resets the stack pointer to the DOS stack area and then processes a command. Used for dispatch code 63H.
4E34H - COMMAND EXECUTION WITHOUT STACK RESET
Entry point for command execution without resetting stack. Falls through from 4E33H or jumped to directly.
4E35H - COMMAND SETUP AND PARSING
This routine sets up error handling vectors and begins parsing the command in the DOS command buffer. HL points to the command string. This is the main entry point after DOS-CALL setup or direct command entry.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
[LOOP START] Copy the command from DE to the DOS command buffer at 4318H, converting to uppercase via 45B5H.
Command too long - return error code 36H (LINE TOO LONG).
Command copied successfully. Check for "R" (recall) command.
- Bit 5 = R command repeat flag
The "R" command was entered - recall the previous command.
Continue with command lookup in command table.
[LOOP START] Compare command against entries in the command table. Each table entry has the command name followed by attribute byte and jump address.
Characters didn't match. Check if we've matched enough (bit 7 of table char indicates end of command name).
Bit 7 was set - we reached end of table command name. Now check if input command also ended here.
Command name in table doesn't match. Skip to next table entry.
Reached end of this table entry's name. Skip the 2-byte attribute and address that follow.
End of command table - command not found. Check if it might be a * (asterisk/star) command for running programs.
Asterisk command - invoke RST 28H to load and run a program file.
4EA7H - COMMAND FOUND - EXECUTE HANDLER
A matching command was found in the table. DE points to the attribute byte. Extract the attribute and jump address, then execute the command.
Check command attributes and permissions before executing.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
Extract module number from attribute and prepare to load/execute the command handler.
Additional command parameter processing (for commands like CLTO, etc.).
Check more attribute bits and continue setup.
Check attribute bits 0-2 for additional handler setup.
[LOOP] Calculate offset into abbreviation table based on parameter count.
Final setup before calling the command handler.
Handler needs to be loaded from disk. Set up RST 28H call to load the SYS module.
4F2AH - INSERT DRIVE SPECIFICATION INTO FILESPEC
This routine inserts a drive specification (e.g., "0/") at the beginning of a filename if one isn't already present. DE points to the command buffer, HL points to a table of 3-byte entries containing default drive info.
Top of loop to scan the filename to see if it already has a drive spec or colon.
No drive spec found - need to insert one. First, shift the filename right to make room.
Clean up and return.
4F58H - DOS COMMAND NAME TABLE
This is the DOS Command Name Table. Each entry contains: the command name (with bit 7 set on the last character), an attribute byte, and a 2-byte handler address. The table is terminated by a 00H byte. The disassembler has interpreted these as instructions, but they are actually ASCII data.
Attribute: 68H, Address: 0068H (points to handler)
The remaining entries follow the same pattern. Here are a few notable ones identified in the data:
50B7H - LIB COMMAND - DISPLAY LIBRARY LIST
This routine implements the LIB command, which displays a list of all available DOS commands from the command table. It walks through the table at 4F58H and displays each command name, formatting them in columns.
[LOOP START] - Process each command table entry.
[INNER LOOP START] - Display characters of one command name.
Done with this command name - skip the attribute and address bytes.
50DBH - MINI-DOS ENTRY HANDLER
This routine handles entry into MINI-DOS mode. MINI-DOS is a special feature of NEWDOS/80 that allows the user to execute DOS commands while a user program is suspended (typically entered by pressing DFG simultaneously). This routine saves the current program state and prepares the system for MINI-DOS operation.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
At this point, we've confirmed DOS is in a normal state and can safely enter MINI-DOS mode. Now save the current context and set up MINI-DOS.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
50FAH - MINI-DOS EXIT HANDLER (MDRET Command)
This routine handles exiting from MINI-DOS mode and returning to the interrupted user program. It corresponds to the MDRET DOS command. The routine restores all saved CPU state and resumes execution of the suspended program.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
MINI-DOS mode is confirmed active. Now restore the saved state and return to the interrupted program.
- Bit 7 = MINI-DOS active
- Bit 6 = DOS-CALL active
- Bit 5 = command processing state
- Bit 4 = additional state flag
511AH - REGISTER RESTORATION AND RETURN
This routine restores all CPU registers from the stack and returns to the caller. It is used both as the exit path from MINI-DOS (MDRET) and as an abort path when MINI-DOS entry is rejected.
512BH - SAVE ALL REGISTERS TO STACK
This routine saves all CPU registers (including alternate register sets, IX, and IY) onto the stack. It is called at the start of operations that need to preserve the complete CPU state, such as entering MINI-DOS or handling DOS-CALL.
513DH - SKIP FILENAME EXTENSION HANDLER
This routine processes a filename and skips past any extension marker (period or slash) to position HL at the start of the actual filename or past the extension.
514DH - PARSE FILENAME WITH DESTINATION BUFFER
Entry point that sets up a destination buffer address before calling the main filename parser.
5150H - FILENAME PARSER
This routine parses a filename from the source buffer (pointed to by HL) and copies valid characters to the destination buffer (pointed to by DE). It handles special cases like asterisk wildcards and validates alphanumeric characters.
515AH - CHARACTER-BY-CHARACTER FILENAME PARSER
This is the inner parsing loop that processes each character of a filename. It handles wildcards (*), validates alphanumeric characters, and copies valid characters to the destination buffer. Called with HL pointing to source, DE pointing to destination, and B containing the maximum character count.
Character is an asterisk (*) wildcard - copy it and advance pointers.
[LOOP START] - Main character validation loop begins here.
Character passed the digit test or was confirmed alphabetic. Now check for special delimiters.
Character is a delimiter (like period) - mark end of filename portion.
Character is valid - copy it to destination and continue loop.
Reached end of loop (maximum characters processed) or hit invalid character.
5189H - ALPHABETIC CHARACTER CHECK
This subroutine checks if the character at (HL) is an alphabetic letter (A-Z or a-z). Returns with CARRY set if the character is alphabetic. If called after a digit test fails, it determines if the character is a valid filename character.
Not an uppercase letter - check for lowercase.
5195H - DISPLAY MULTIPLE SPACES
This routine displays multiple space characters. Called with B containing the count of spaces to display.
519DH - DISPLAY CARRIAGE RETURN
This routine displays a carriage return character (0DH), moving the cursor to the beginning of the next line.
519FH - DISPLAY CHARACTER WITH REGISTER PRESERVATION
This utility routine displays the character in Register A while preserving the DE register pair. This is important when DE is being used as a pointer during string operations.
51A7H - DOS COMMAND NAME STRINGS
This area contains ASCII strings used by DOS, including abbreviated command names. These are not executable code but data referenced by command lookup and display routines.
51B0H - MINI-DOS READY MESSAGE
This is the "MINI-" prefix displayed before "NEWDOS/80 READY" when in MINI-DOS mode.
51B5H - NEWDOS/80 READY MESSAGE
This is the main DOS prompt message displayed when DOS is ready for command input.
51C5H - SYSTEM PARAMETER TABLE
This small table contains system configuration parameters used by various DOS routines.
51E0H - END OF DOS OVERLAY AREA
The remaining bytes from 51E0H to 51FFH are reserved space at the end of the DOS overlay area. This area may be used for temporary storage or left as padding.