TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - SYS2/SYS Disassembled
Page Customization
Page Index
SYS2/SYS
Other Navigation
Introduction/Summary
The SYS2/SYS file contains the code for several core utility and system commands in NEWDOS/80 v2.0. The routines within this module implement the essential DIR (Directory) command, which is responsible for scanning the disk directory and displaying the file list and disk usage status for a specified drive.
This overlay file also includes the logic for the DATE and TIME commands, which allow the user to view and set the system's current date and time information. As a system overlay, the code in SYS2/SYS is loaded into the transient program area when one of its contained commands is executed.
Variables:
| Address Range | Purpose |
|---|---|
| 4022H-4022H (1 byte) | Cursor State - Blink state storage: Non-zero = cursor ON, Zero = cursor OFF |
| 402DH-402FH (3 bytes) | No-Error Exit - DOS successful completion jump vector (JP nnnn) |
| 4030H-4032H (3 bytes) | Error-Shown Exit - DOS exit vector used when error has already been displayed |
| 4200H-42FFH (256 bytes) | Sector Buffer - DOS sector I/O buffer (aliased at 5100H-51FFH) |
| 4300H-4317H (24 bytes) | PDRIVE/SYS Spec - Storage area for PDRIVE and SYSTEM specifications |
| 4312H-4312H (1 byte) | BREAK Enable - BREAK key flag: C9H = RET (Enabled), C3H = JP (Disabled) |
| 4313H-4314H (2 bytes) | BREAK Handler - Address of the BREAK key handler (used when 4312H is C3H) |
| 4318H-4367H (80 bytes) | Command Buffer - Buffer for user input and DOS command processing |
| 4368H-4369H (2 bytes) | State Flags - System state and operation flags (bit 5 checks) |
| 436AH-436AH (1 byte) | Sys Flags 1 - B7: MINI-DOS, B6: DOS-CALL, B5: Cmd State, B4: State Flag |
| 436BH-436BH (1 byte) | Sys Flags 2 - B7: Special return, B6: Stack save, B2: Error state |
| 436CH-436CH (1 byte) | Sys Flags 3 - B6: Chaining active, B5: Additional state |
| 436DH-436DH (1 byte) | Sys Flags 4 - B5: Command repeat flag (R command) |
| 4371H-439AH (42 bytes) | PDRIVE Area - Physical drive configuration data storage |
| 439BH-439CH (2 bytes) | MINI-DOS Stack - Saved stack pointer (SP) used when entering MINI-DOS |
| 439DH-439EH (2 bytes) | DOS-CALL Stack - Saved stack pointer (SP) used during DOS-CALL mode |
| 43A7H-43A8H (2 bytes) | Saved Cmd Ptr - Original command buffer pointer for R command repeat functionality |
| 4408H-440AH (3 bytes) | Return Vector - Return address vector for DOS command execution |
| 4480H-449FH (32 bytes) | Parsing Buffer - Buffer for components of the parsed filename |
| 51A7H-51A9H (3 bytes) | "CMD" String - Constant: Command file extension |
| 51AAH-51ACH (3 bytes) | "JCL" String - Constant: Job Control Language extension |
| 51ADH-51AFH (3 bytes) | "TO" String - Constant: COPY command keyword with null terminator |
| 51B0H-51B4H (5 bytes) | "MINI-" String - Constant: Prefix for the MINI-DOS ready message |
| 51B5H-51C4H (16 bytes) | Ready String - "NEWDOS/80 READY" with CR terminator |
| 51C5H-51C8H (4 bytes) | Param Table - System parameters (1CH, 1FH, 03H, 00H) |
| 51E0H-51FFH (32 bytes) | Working Buffer - Temporary filename storage at the end of the overlay area |
Disassembly
4D00H - SVC File Operations Command Dispatcher
This is the main entry point for file operations Supervisor Calls (SVCs) in NEWDOS/80. Register A contains the command code on entry. The dispatch table handles commands spaced 20H apart: 24H (OPEN), 44H (INIT), 64H (CLOSE/READ), 84H (Hash calculation), A4H (Buffer setup), C4H (RENAME/REMOVE), and E4H (multiple sub-operations based on Register C).
Command E4H has sub-functions selected by the value in Register C (1-4). Register C is decremented to determine which sub-function to execute.
4D2EH - Invalid Command Error Return
Returns error code 2AH (Invalid function) when an unrecognized command code is passed to the dispatcher.
4D32H - E4/1: KILL File Handler
Sub-function 1 of command E4H: Deletes a file from the directory. On entry, DE points to the FCB (File Control Block). This routine opens the file, marks it for deletion, and updates the directory.
File type is valid for deletion. Now set up to open the file and mark it deleted.
File entry found. Now copy the delete marker and update the directory.
Now mark the file's granules as free in the GAT (Granule Allocation Table).
4D72H - E4/4: INIT with OPEN Handler
Sub-function 4 of command E4H: Creates a new file (INIT) and then opens it. Combines the INIT and OPEN operations into one call.
4D77H - Return Error Code 35H
Returns error code 35H (File not found) with NZ flag set.
4D7BH - E4/3: Parse Command and Execute
Sub-function 3 of command E4H: Parses a command line and executes the appropriate action. Uses the command line parser at 4CD5H.
4D80H - RENAME/REMOVE Command Handler (C4H)
Handles the C4H command (RENAME or REMOVE operations). Sets up file buffers and calls the A4H buffer setup routine.
4D92H - Buffer Setup Routine (A4H Command)
Sets up file buffers and validates the file operation. Called by the A4H command and by other file operations. On entry, DE points to FCB. On exit, HL points to directory entry if successful.
4DA0H - Process File After OPEN
Continues file processing after successful OPEN. Validates file attributes and sets up for the requested operation.
4DBDH - INIT File Handler (44H Command)
Creates a new file entry in the directory. Called by command 44H (INIT). On entry, DE points to the FCB containing the filename. The routine searches for a free directory slot and initializes the file entry.
File does not exist (error 18H) - proceed to create it. Find a free directory slot.
Drive is ready. Check for wildcard filename (hash value stored at 4D6EH).
4DE3H - INIT Error Retry Loop
Handles errors during INIT by prompting for retry. Error code 1AH means "Directory full".
4DEAH - Create File Entry in Directory
Creates the actual file entry in the directory after finding a free slot. Initializes all fields of the directory entry.
4E09H - Error Handler with Retry Option
Handles errors by checking retry count and returning appropriate status. On entry, D contains the previous error code, E contains the new error code. Returns with Z flag if retry should occur, or with NZ and error code in A if giving up.
4E1BH - Return Space Error (20H)
Returns error code 20H (space/parameter error) with NZ flag set.
4E1FH - Extract File Parameters from Directory Entry
Extracts file parameters from the directory entry pointed to by HL and stores them in working variables for later use.
4E2CH - OPEN File with B=0 Entry Point
Entry point for OPEN file routine with B pre-cleared to 0. Falls through to main OPEN handler.
4E2EH - OPEN File Handler (24H Command)
Main OPEN file routine. Opens a file for access by searching the directory for the filename and setting up the FCB. On entry: DE points to FCB with filename, B contains open mode flags. On exit: Z flag set if file found, A contains error code if not.
Parse the filename from the FCB into the 11-byte buffer at 51CDH.
Drive specifier found (colon detected). Parse the drive number (0-9).
Two-digit drive number: multiply first digit by 10 and add second digit.
ADD C to A (accumulate first digit × 10).
4E75H - Use Default Drive and Continue OPEN
Continues OPEN processing with drive number in B. This location contains self-modifying code - the JR instruction may be temporarily changed by other routines.
Calculate filename hash for quick directory searches.
Calculate simple checksum of filename to detect wildcards.
XOR byte at (HL) into accumulator A.
Drive not ready - set up error code and retry.
4EAEH - Search Directory for File
Searches the directory for a matching filename. Uses the hash value calculated earlier to speed up the search. Returns with Z flag set if file found, NZ if not found.
Load A with current directory position from B.
Save position in B.
4EDDH - Process Directory Matches
Processes the list of potential directory matches found during the search. Verifies each match by comparing the full filename.
Entry appears valid. Extract parameters and compare full filename.
INCrement HL to point to directory filename.
Full filename match found! Extract file information from directory entry.
Special file verification mode is enabled. Check file parameters.
4F2EH - Finalize File Open / FCB Setup
Completes the file open operation by setting up the FCB with all necessary information. Called after the file is found in the directory.
4F79H - Copy Extent Information
Copies extent information from directory entry to FCB. Copies 8 bytes of extent data.
4F82H - Close/Read Handler (64H Command)
Handles file close or sector read operations. On entry, IX points to FCB. Verifies file is open before proceeding.
File is open. Get drive-specific parameters and locate the sector.
Calculate which sector within the extent we need.
INCrement granule counter E.
Build bit mask for the specific sector within the granule.
Rotate C left - shift bit mask.
4FC5H - Allocate/Access Granule
Handles allocation of new granules or access to existing ones. E contains granule number, C contains sector bit mask.
4FD3H - Granule Allocation Loop
Main loop for finding and allocating free granules. Checks GAT entries and marks allocated sectors.
Fetch GAT byte at current granule position.
Rotate to next sector bit position within granule.
Finished current granule. Move to next granule in GAT.
Reached end of GAT. Check if this is first pass or retry.
Second pass failed - no free granules. Check for allocation mode.
4FFBH - Error Exit with Code
Common error exit point. Jumps to error processing routine.
4FFDH - Allocate Free Sector
Allocates a free sector found in the GAT. Marks it as used and updates extent information.
New extent needed. Store granule number and position.
Allocation complete. Check system flags for special handling.
Normal mode. Advance extent pointer for next allocation.
502AH - Cleanup After Allocation
Cleans up after granule allocation. Resets flags and writes updated directory.
5036H - Validate File Status
Validates file status flags. Checks if file is properly opened and not marked for special handling.
503DH - Error Processing and Exit
Processes errors and exits to the DOS error handler. Calls status update routine first.
5043H - Update Extent Entry
Updates an existing extent entry when adding sectors to a file.
504CH - Move to Next Extent
Advances to the next extent entry in the file's extent list.
Need to save current state and read next extent from directory.
508CH - Save State to Directory
Saves current file state (extent information) back to the directory on disk.
50AEH - Write Directory Sector
Writes the current directory sector to disk. Checks for errors and handles error exit.
50B4H - Prepare Extent Buffer
Prepares the extent buffer area for file operations. Copies extent data and initializes pointers.
DECrement HL.