TRS-80 DOS - NEWDOS/80 v2.0 for the Model III - SYS13/SYS Disassembled
Page Customization
Page Index
SYS13/SYS
Other Navigation
SYS13/SYS - NEWDOS/80 v2.0 BASIC Error Message Table and ERROR/RESUME Handler
SYS13/SYS is a BASIC/CMD overlay module that provides two major functions: (1) the complete BASIC error message lookup table containing 58 null-terminated ASCII strings covering ROM BASIC errors 0-22 and NEWDOS/80 DOS-specific errors 50-84, and (2) the ERROR/RESUME/ON ERROR GOTO statement handler at 50FEH. The error message table occupies the bulk of the overlay (4D47H-50FDH) and is accessed by the error display routine in SYS0 through an index-based lookup algorithm at 4D0CH. The overlay loads into memory at 4D00H-4D45H (the lookup dispatcher) and 4D47H-51E7H (error strings, handler code, and NOP padding).
Program Entry Point
4D0CH - Error message lookup dispatcher. Called with the error code in Register E and token 4FH in Register A when the error display routine needs to retrieve the text of an error message.
Secondary Entry Point
50FEH - ERROR/RESUME/ON ERROR GOTO statement handler. Jumped to when the BASIC interpreter encounters an ERROR statement token (4FH) during program execution.
SYS13 Variable and Data Area List
The following memory locations are used as working variables or parameters by SYS13.
Overlay Header Area (4D00H-4D0BH)
| Address | Variable | Description |
|---|---|---|
| 4D00H-4D01H | Start line number parameter | Two-byte value loaded into the start line number register pair for the ERROR statement handler. Written by the error handler at 518BH and 519FH; read at 518BH and 5155H. |
| 4D02H-4D03H | Increment value parameter | Two-byte value used as the increment for the ERROR statement line number calculation. Read at 519BH. |
| 4D04H-4D05H | Range start parameter | Two-byte value specifying the lower bound of the line number range for the ERROR statement handler. Read at 514BH and 517DH. |
| 4D06H-4D07H | Range end parameter | Two-byte value specifying the upper bound of the line number range for the ERROR statement handler. Read at 514FH and 5185H. |
| 4D08H-4D09H | Saved line number value | Two-byte value used to store the current line number during ERROR handler processing. Written at 518EH. |
| 4D0AH | USING flag | Single byte. When non-zero, signals that a USING modifier is active in the ERROR statement, causing the handler to skip the line number range check and proceed directly to the next-line scan. Read at 516BH. |
| 4D0BH | Reserved / additional flag | Single byte. Used in conjunction with 4D0AH for secondary flag purposes. Written at 5141H. |
External Variables Referenced
| Address | Variable | Description |
|---|---|---|
| 409AH | Error recovery flag | Single byte in the DOS work area. Cleared to 00H at 4D30H when the error index evaluates to 1 (specific error code 02H, SYNTAX ERROR). Used by the DOS to suppress error recovery when a syntax error is detected during tokenization. |
| 4288H | Error state flag | Single byte in the DOS work area. Cleared to 00H at 50FFH when the ERROR/RESUME handler initializes. Indicates whether an error condition is currently active. |
| 40A4H | BASIC program start pointer | Two-byte pointer to the start of the BASIC program text in memory. Read at 515FH and 51C7H to begin scanning the line link chain. |
SYS13 Major Routine List
The following major routines are defined within the SYS13 overlay.
| Address | Routine | Description |
|---|---|---|
| 4D0CH | Error Message Lookup Dispatcher | Entry point for error message retrieval. Receives the error code in Register E, converts it to a table index using a three-range algorithm (0-46 direct, 47-98 clamped to “UNPRINTABLE ERROR”, 99+ offset), then walks the null-terminated string table at 4D47H counting entries to find the matching message. Returns with HL pointing to the error message string and the return address manipulated to vector through 1A01H for display. |
| 4D47H | Error Message String Table | Data area containing 58 null-terminated ASCII error message strings. Entries 0-22 are ROM BASIC error messages (NEXT WITHOUT FOR through DISK BASIC FEATURE). Entries 23-57 are NEWDOS/80 DOS error messages (UNDEFINED USER FUNCTION through BAD FILE POSITIONING PARAM). The table is terminated by an additional 00H byte at 50FDH. Each entry is accessed by index; the lookup routine at 4D0CH walks the table counting null terminators to reach the desired entry. |
| 50FEH | ERROR/RESUME/ON ERROR GOTO Handler | Handles the BASIC ERROR statement (token 4FH). Parses up to 4 comma-separated numeric parameters from the statement, validates line number ranges, walks the BASIC program line chain to locate target lines, updates line link pointers, and manages the cross-reference table at 64A3H. Uses RST 10H for expression evaluation and RST 18H for 16-bit unsigned comparison. |
Disassembly
4D00H – Overlay Header and Error Message Lookup Dispatcher
This is the start of the SYS13 overlay. Addresses 4D00H–4D0BH serve as a parameter/variable area used by the ERROR statement handler at 50FEH. The executable code begins at 4D0CH, which is the program entry point. The dispatcher receives an error code in Register E, converts it to a zero-based table index, then walks the null-terminated error message table at 4D46H counting entries until the target index is reached. On exit, HL points to the first character of the error message string, and the return address is manipulated so that execution vectors through 1A01H (the ROM’s error message display continuation).
Parameter/Variable Area
The first 12 bytes (4D00H–4D0BH) are not executable code. They are used as a data area by the ERROR statement handler at 50FEH. The disassembler has misinterpreted these data bytes as instructions. See the Variable List above for the meaning of each location.
Error Message Lookup Entry Point
Execution enters here when the error display routine in SYS0 needs to retrieve the text of an error message. Register A contains 4FH (the ERROR statement token from the BASIC token table) and Register E contains the internal error code. The token is checked first to distinguish an error lookup call from an ERROR statement execution.
Error Code Preprocessing
At this point, Register A does not equal 4FH, so this is an error message lookup call. Register E holds the internal error code. The code saves the error code, checks for a special range of error codes (9CH–A1H) that require additional handling, then converts the error code to a table index.
Error Code to Table Index Conversion
The error code in Register A is now converted to a zero-based table index. The algorithm has three ranges:
1. Error codes 00H–2EH (0–46 decimal): Index = error_code / 2 (via RRCA). These are ROM BASIC errors and the first DOS error.
2. Error codes 2FH–62H (47–98 decimal): Clamped to index 19, which maps to “UNPRINTABLE ERROR”.
3. Error codes 63H+ (99+ decimal): Index = (error_code − 34H) / 2. These are NEWDOS/80 DOS-specific errors.
Special Case: Error Index 1 (Syntax Error)
If the computed table index is 1 (SYNTAX ERROR), the code clears the error recovery flag at 409AH. This prevents the DOS from attempting error recovery when a syntax error occurs during BASIC tokenization, because the program text is in an inconsistent state.
Error Message Table Walk Loop
This loop walks through the null-terminated string table at 4D47H. Each error message is terminated by 00H. The loop counts past B null terminators to reach the target entry. On exit, HL points to the first character of the target error message string. [LOOP START]
At this point, a null terminator has been found. HL now points to the byte after the null (the first character of the next message, or another null if at the end of the table).
Return Sequence
The target error message has been located. HL points to its first character. The code now manipulates the return address stack so that execution continues at the ROM’s error message display routine at 1A01H, which will print the error message string pointed to by HL.
4D46H – Sentinel Byte
This null byte precedes the error message table and serves as the starting point for the table walk loop. The loop at 4D33H scans forward from 4D46H, and the INC HL at 4D35H advances past this byte to reach the first message at 4D47H
4D47H – Error Message String Table (ROM BASIC Errors 0–22)
This is the beginning of the error message string table. Each entry is a null-terminated ASCII string. The first 23 entries (indices 0–22) correspond to ROM BASIC error messages. These are the same error texts used by Level II BASIC, duplicated here in the SYS13 overlay because the overlay replaces the ROM’s built-in error table when NEWDOS/80 is active. The error code displayed to the user is the table index (0–22).
4ECDH – Error Message String Table (NEWDOS/80 DOS Errors 50–84)
Continuing the error message string table, entries 23–57 (indices 23–57) correspond to NEWDOS/80 DOS-specific error messages. These errors are unique to Disk BASIC and the NEWDOS/80 operating system. The displayed error number is the table index plus 27 (e.g., index 23 = error 50, index 24 = error 51, through index 57 = error 84). Five entries contain only “?” and serve as placeholders for undefined error numbers (57, 60, 61, 74, and 81). The table ends with a final 00H terminator at 50FDH that marks the absolute end of the error list.
50FEH – ERROR/RESUME/ON ERROR GOTO Statement Handler
This routine handles the BASIC ERROR statement (token 4FH). When the BASIC interpreter encounters the ERROR token during program execution, it jumps here from 4D0EH. The handler clears the error state flag at 4288H, then parses up to 4 comma-separated numeric parameters from the ERROR statement. These parameters specify: the start line number (stored at 4D00H), the end line number (stored at 4D02H), and optionally USING/XREF modifiers (stored at 4D0AH/4D0BH). The routine validates line number ranges against the bounds stored at 4D04H–4D07H, walks the BASIC program line chain via the pointer at 40A4H, updates line link addresses, and manages the cross-reference table at 64A3H. RST 10H is used for expression evaluation and RST 18H for 16-bit unsigned comparison.
Top of Loop
Parameter Parsing Loop
End of Loop
Parameter Parsing Loop
Error Exit for Invalid Parameters
USING/XREF Modifier Detection
After numeric parameters have been parsed, the code checks for the optional USING keyword (token 55H) or XREF keyword (token 58H). These keywords modify the behavior of the ERROR statement to control output formatting or cross-reference generation.
Parameter Validation and Line Scan Initialization
All parameters and modifiers have been parsed. The code validates the start and end line numbers against the configured range bounds, then begins scanning the BASIC program line chain.
BASIC Program Line Scan
The parameters are valid. The code now scans the BASIC program’s linked-list line chain starting from the program start pointer at 40A4H. Register Pair BC is initialized to 0000H as a line counter. Each line link is a 2-byte pointer to the next line; a link of 0000H marks the end of the program. [LOOP START — main line scan]
Line Number Range Check
The USING modifier is not active, so the code reads the current line’s line number and checks whether it falls within the specified range (4D04H to 4D06H). If within range, the line is processed; if outside the range, the line is skipped.
Line Within Range — Process It
The current line number falls within the specified range. The code saves the current start line number from 4D00H, stores the current line number, and calculates the next start value by adding the increment from 4D02H.
Update Line Link and Continue Scan
The line has been processed and the start line number advanced. The code now updates the line link pointer and proceeds to the next line in the chain.
End of Program — Cross-Reference Table Setup
The scan has reached the end of the BASIC program (a line link of 0000H was found at 5167H). Register Pair BC holds the total line count. The code now calculates which page of the cross-reference table at 64A3H to populate, determines the number of entries (up to 128), and calls the SVC routine to initialize the table.
Top of Loop
Page Count Calculation
End of Loop