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 | 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 - 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.
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.
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.
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.
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.
Build bit mask for the specific sector within the granule.
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.
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.