TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - SYS13/SYS Disassembled
Page Customization
Page Index
SYS13/SYS
Other Navigation
Description:
SYS13 provides two essential functions for NEWDOS/80 BASIC: error message display and the first part of the RENUM (renumber) command. This overlay must be present on the system diskette whenever BASIC is active.
Error Message Handler (4D0CH-4D45H): When BASIC encounters an error, the error code is passed in Register E. This routine translates the error code into an index, locates the corresponding null-terminated error message string in the error table (4D47H-50FCH), and prepares it for display. The routine handles three error code ranges: DOS errors (9CH-A1H) which trigger a call to 5D5EH for DOS-specific handling, standard BASIC errors (2FH-62H), and extended errors (63H+). Error codes are mapped through a calculation that converts them to table indices.
Error Message Table (4D47H-50FCH): Contains 52 null-terminated ASCII strings for BASIC error messages, from "NEXT WITHOUT FOR" through "BAD FILE POSITIONING PARAM". Messages are indexed sequentially, with the lookup algorithm counting null terminators to find the correct string.
RENUM Command Handler (50FEH-51E7H): Implements the first part of BASIC's RENUM (renumber) command. This routine parses up to four optional parameters: new starting line number, increment, old starting line, and old ending line. It validates that the line number range is valid (not exceeding 65529/FFF9H) and prepares the renumbering operation. The actual line number modification is handled by subsequent code.
Routine Overview:
| Address | Purpose |
|---|---|
| 4D00H-4D0BH | Data area (parameters/work area) |
| 4D0CH-4D45H | Error message display routine (entry point) |
| 4D46H | Start of error message table (00H terminator before strings) |
| 4D47H-50FCH | Error message strings (you've already converted these) |
| 50FDH | Final 00H terminator |
| 50FEH-51E7H | RENUM command handler (Part 1) |
Variables:
| Address | Bytes | Purpose |
|---|---|---|
| 4D00H-4D01H | 2 | RENUM: New starting line number (default 10) OTHER: Current memory top (2 bytes) |
| 4D02H-4D03H | 2 | RENUM: Line increment value (default 10) OTHER: Buffer size (2 bytes) |
| 4D04H-4D05H | 2 | RENUM: Old starting line number (default 0) OTHER: Low memory limit (2 bytes) |
| 4D06H-4D07H | 2 | RENUM: Old ending line number (default FFFFH) OTHER: High memory limit (2 bytes) |
| 4D08H-4D09H | 2 | RENUM: Working storage for calculations OTHER: Memory top backup (2 bytes) |
| 4D0AH | 1 | RENUM: "U" flag - Update line references |
| 4D0BH | 1 | RENUM: "X" flag - Extended mode |
| 4D46H | 1 | Error table start marker (00H) |
| 4D47H-50FCH | 950 | Error message string table (null-terminated strings) |
| 50FDH | 1 | Error table end marker (00H - double null terminator) |
| 409AH | 1 | BASIC system flag (cleared for error code 02H) |
| 4317H | 1 | COMPRESS work variable (cleared by RENUM) |
| 40A4H | 2 | TXTTAB - Start of BASIC program text |
Key Routines:
| Address | Purpose |
|---|---|
| 4D00H-4D0B | System variables/flags area |
| 4D0CH-4D45 | Error message lookup routine
|
| 4D46 | Null terminator before message table |
| 4D47H-50FC | Error message string table (null-terminated strings) |
| 50FD | Final null terminator (double 00H ends table) |
| 50FEH-513E | Additional error/CLEAR related code (not fully analyzed) |
| 513FH-515A | CLEAR command parameter parsing
|
| 515CH-516F | File buffer chain initialization
|
| 5162H-51B2 | Buffer chain walk loop
|
| 51B5H-51C0 | Buffer block calculation
|
| 51C2H-51CC | DOS buffer initialization
|
| 51CDH-51E7 | Reserved space (27 NOPs) |
Self-Modifying Code Locations:
| Address | Set By | Purpose |
|---|---|---|
| 576EH | 5774H | SVC return value storage |
| 57B8H | 5DADH | Line number storage for GOSUB |
| 57E5H | 5E19H | Conditional return opcode |
| 5A72H | 59D4H | COMPRESS space handling (28H/00H) |
| 5A95H | 59D8H | COMPRESS REM handling (00H/C9H) |
| 5BA3H | 5B91H | February days (1CH=28 or 1DH=29) |
| 5C25H | 5C12H | Variable type code |
| 5C2AH | 5C16H | Variable name length |
| 5C30H | 5C1AH | Variable first character |
| 5C9EH | 5C67H | CLEAR memory difference |
| 5CB4H | 5C81H | CLEAR new SP value |
| 5E13H | 5E09H | Error code for delayed error |
| 61F1H | 61FDH | Position bounds value |
| 624DH | 6454H | Position update enable (00/non-zero) |
| 63A9H | 63AFH | Guard flag (00H=clear, C9H=RET) |
| 63BDH | 63B6H | Guard flag backup |
| 63EBH | 63F6H | Line number for display |
| 6421H | 6515H | System flag for chaining |
| 644EH | 64C1H | Callback address (modified to 64BDH) |
| 6447H → 6482H | 6438H/6445H | Print width (20H or 18H) |
| 6529H | (init value) | Maximum files count |
SYS11 (RENUM):
| 4D04H | Multiple | New line number (in LD HL,nnnn) |
| 4D08H | Multiple | Line increment (in LD DE,nnnn) |
| 4D4FH | 4D37H | Search line number |
| 4E60H | 4D80H | JP target for completion |
| 4E89H | 4E5AH | Current line being processed |
SYS12 (REF):
| 4E0CH | 4DD1H | Search mode flag (in LD A,nn) |
| 4E76H | 4D1DH, 4E17H, 50E7H | Target line number (in LD HL,nnnn) |
| 4E7AH | 4F70H | Current line pointer (in LD DE,nnnn) |
| 4ED9H | 4E9CH | Reference counter (in LD DE,nnnn) |
| 4EEFH | 5182H, 512AH | Reference table write pointer |
| 4EF2H | 5185H, 4E6DH | Reference table read pointer |
| 4F6DH | 4DF0H, 50DDH | End-of-program flag (CAH/C3H) |
| 4F7CH | 4D44H, 4D4DH | Search type flag (C3H/21H) |
| 4FBEH | 4DEBH | Column width (30H/18H) |
| 4FFCH | 4DDAH | JP opcode for conditional (C2H/DAH) |
| 5021H | 517CH | Variable comparison offset |
| 5085H | 4FB4H, 4DF6H | DEF statement pointer |
| 50A9H | 4DDDH | JP opcode for comparison (C2H/DAH) |
Disassembly:
4D00H - RENUM Parameter Storage Area
This 12-byte data area stores the RENUM command parameters and working variables. The first 8 bytes hold the four line number parameters (new start, increment, old start, old end), followed by working storage and option flags.
4D0CH - Error Message Display Entry Point
This is the main entry point for displaying BASIC error messages. Register E contains the error code when this routine is called. The routine determines which error message to display by converting the error code to a table index, then walks through the null-terminated string table to find the correct message.
Entry point: Register E contains the error code to display. Error codes fall into three ranges: DOS errors (9CH-A1H), standard BASIC errors (2FH-62H), and extended errors (63H+).
Check if this is a DOS-specific error (codes 9CH-A1H). These require special handling through the DOS error routine.
Now determine which error message table index to use. Error codes are mapped: 2FH-62H → standard errors, 63H+ → use code 5AH (which maps to "UNPRINTABLE ERROR").
Convert the adjusted error code to a table index. The RRCA divides by 2 (each error entry is indexed by increments of 2 in the original error code scheme).
[LOOP START] - Walk through the error table counting null terminators until we've found the Bth message.
Found a null terminator. Check if we've found enough nulls to reach our target message.
[LOOP END] - HL now points to the start of the target error message string.
4D47H - Error Message String Table
This table contains 52 null-terminated ASCII strings for all BASIC error messages. Each message ends with a 00H byte. The table is terminated by a double 00H (the final message's terminator followed by an additional 00H at 50FDH). Error messages are indexed 0-51, corresponding to error codes after translation by the lookup algorithm at 4D0CH.
50FDH - Error Table End Marker
The final null byte marking the end of the error message table. Combined with the preceding message's null terminator, this creates a double-null (00H 00H) sequence that signals the end of the table to the search algorithm.
50FEH - RENUM Command Entry Point
This is the entry point for BASIC's RENUM (renumber) command. The RENUM command syntax is: RENUM [new][,inc][,old][,oldend][,U][,X]. This routine parses the optional parameters and validates the line number range before proceeding with the renumbering operation. Default values are: new=10, increment=10, old=0, oldend=65529.
Entry: A=4FH (from the CP 4FH / JP Z at 4D0CH). HL points to command line after RENUM token.
[PARAMETER PARSE LOOP] - Parse up to 4 numeric parameters separated by commas.
Syntax error handler - invalid RENUM syntax detected.
Handle U or X flag parsing - store flag value then continue checking.
Check for U flag (update line references) or X flag (extended mode).
Neither 'U' nor 'X' found - check for end of statement
End of statement reached - validate memory boundaries before proceeding
515CH - File Buffer Chain Initialization
Initializes the file buffer chain scan. Sets up a counter and retrieves the pointer to the first file buffer from BASIC's TXTTAB pointer area. This begins the process of walking through all allocated file buffers.
5162H - File Buffer Chain Walk Loop
[LOOP START] Walks through the linked list of file buffers. Each buffer contains a pointer to the next buffer (or 0000H for end of chain). Counts buffers and validates each one's memory position against the CLEAR limits.
Check reserved memory flag - if set, skip memory recalculation
5171H - Buffer Memory Validation
Validates that the current buffer's address falls within the acceptable memory range. Retrieves the buffer address from offset +2/+3 and compares against the low and high memory limits established by CLEAR parameters.
Buffer address is valid - check against memory limits
518BH - Memory Pointer Adjustment
Buffer is within valid range. Updates memory tracking pointers by adding the buffer size to the current memory top. Saves backup and checks for overflow conditions.
51A4H - Update Buffer Pointer and Continue
Updates the buffer pointer in the chain with the new address and calls the buffer processing routine. Then pops the next buffer address and continues the chain walk loop.
51B5H - Buffer Allocation Finalization
End of buffer chain reached. Calculates the total buffer space required by counting how many 128-byte blocks are needed. Prepares for DOS buffer initialization call.
[LOOP START] Calculate number of 128-byte blocks needed
51C2H - DOS Buffer Initialization Call
Sets up parameters for the DOS RST 28H call to initialize file buffers. Loads the FCB work area address, buffer size, and file buffer chain pointer, then invokes DOS function 2DH.
51CDH - Reserved/Unused Space
NOP padding from 51CDH through 51E7H. This is unused reserved space at the end of the SYS13 overlay, likely preserved for future expansion or alignment purposes.