TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - SYS6/SYS Disassembled
Page Customization
Page Index
SYS6/SYS
Other Navigation
NEWDOS/80 v2.0 - SYS6/SYS: FORMAT, COPY, and BACKUP Commands
SYS6/SYS is the disk utility overlay for NEWDOS/80, providing the FORMAT, COPY, and BACKUP commands. It loads at address 4D00H and extends through 6FF9H (approximately 9KB). This overlay handles all low-level disk formatting operations, disk-to-disk copying, and backup functions with support for multi-disk operations when source and destination are on the same physical drive.
Command Entry Points
The module entry point at 4D00H examines the command code in Register A and dispatches to the appropriate handler:
- 68H ('h') → 6F4BH: File transfer/copy operation
- 28H ('(') → 65FAH: FORMAT command with system initialization
- 48H ('H') → 4D1EH: FORMAT command (standard entry)
- Other → 5208H: COPY and BACKUP commands
FORMAT Command (4D1EH, 65FAH)
The FORMAT command prepares blank diskettes for use with NEWDOS/80. Key features include:
- Track Formatting: Low-level format using the WD1771/1791 controller's format command, writing sector headers and data areas with proper CRC values
- Sector Interleave: Configurable sector interleave pattern stored in a table at 6485H, optimized for the system's read/write timing
- Boot Sector Creation: Writes the boot loader code from template at 64BAH to track 0, sector 0
- Directory Initialization: Creates the Granule Allocation Table (GAT) and Hash Index Table (HIT) on tracks 1-2
- System Disk Option: When the $ option is specified, copies system files to make a bootable diskette
- Multi-Format Support: Supports single/double density, single/double sided, and various track counts (35, 40, 77, 80)
COPY Command (5208H with bit 3 of 5996H set)
The COPY command duplicates files or entire diskettes:
- File Copy Mode: Copies individual files from source to destination disk
- Disk Copy Mode: Creates an exact duplicate of an entire diskette
- Same-Drive Operation: Supports copying when source and destination are the same physical drive, prompting for disk swaps
- Track Buffering: Reads multiple tracks into memory before writing, minimizing disk swaps (buffer at 5D16H, size calculated at 5273H-528EH based on available memory)
- Verification: Optional verify pass reads back written data and compares against source (routine at 5400H-544EH)
BACKUP Command (5208H with bit 2 of 5996H set)
The BACKUP command creates archival copies with additional features:
- Granule-Based Copying: Only copies allocated granules, skipping empty space for faster backups
- Directory Synchronization: Copies the directory structure and updates destination GAT/HIT
- Space Management: Tracks remaining granules at 5B21H, handles disk-full conditions gracefully
Memory Organization
SYS6 uses an extensive work area from 593BH-5B60H:
- 593BH-5941H: Control flags and status bytes
- 5942H-595FH: Three 10-byte drive parameter blocks (primary, source, destination)
- 5960H-5977H: Filename buffers for source and destination
- 5994H-5997H: Option flags parsed from command line
- 59D3H-5AD7H: Message strings for user prompts and errors
- 5AE5H-5B16H: Source disk control block (DCB)
- 5B17H-5B48H: Destination disk control block
- 5D12H-5D14H: Track buffer pointers
Multi-Disk Operation
When source and destination are on the same drive (indicated by bit 7 of 593BH), the code implements a sophisticated disk-swapping system:
- Disk Detection: Verifies correct disk is mounted by checking disk name/date at 67C3H-6886H
- User Prompts: Displays "PRESS ENTER WHEN [disk] MOUNTED ON DRIVE n" messages
- Buffer Management: Swaps buffer contents when switching between disks (routine at 5626H)
- Batch Operations: Accumulates multiple tracks in memory to minimize disk swaps
Error Handling
The module includes comprehensive error handling:
- Error Handler Entry: 521AH receives errors and displays appropriate messages
- Retry Logic: User prompted with "REPLY C (CANCEL), R (RETRY) OR P (PROCEED)" for recoverable errors
- Disk Full Handling: Detects full destination disk (errors 1AH/1BH) and offers options
- Verification Failures: Reports comparison errors (3AH) and verification failures (31H) with track/sector information
- Wrong Disk Detection: Error 33H when incorrect disk detected during multi-disk operation
Low-Level Disk I/O
SYS6 performs direct disk controller access for formatting:
- Controller Interface: Writes directly to FDC registers at 37ECH-37EFH
- Format Timing: Critical timing loops for writing sector headers and gaps (6AB2H-6B90H)
- Density Selection: Handles FM (single density) and MFM (double density) encoding
- Side Selection: Controls head selection for double-sided drives via bit 5 of drive control byte
Boot Sector Structure
The boot sector template at 64BAH contains:
- Boot Code: Initial loader that reads DOS into memory
- Disk Parameters: Track count, sector count, density flags at offset EFH
- Signature Byte: A5H at offset EFH indicates valid boot sector
- System Filename: "BOOT/SYS" pointer for loading the operating system
Option Flags
Command-line options are parsed into flags at 5994H-5997H:
- 5994H Bit 0: $ (system disk) option
- 5994H Bit 1: Skip boot sector flag
- 5994H Bit 6: QUERY option - prompt before each operation
- 5995H Bit 7: Abort on error flag
- 5996H Bit 2: BACKUP command active
- 5996H Bit 3: COPY command active
- 5996H Bit 7: Multi-disk mode active
Key Subroutines
| Address | Function |
|---|---|
| 521AH | Main error handler entry point |
| 5273H | Calculate track batch size based on available memory |
| 529DH | Read track loop - reads source tracks into buffer |
| 5324H | Write track batch to destination disk |
| 5400H | Post-write verification loop |
| 546DH | Write single sector to disk |
| 5578H | Initialize source drive parameters |
| 557DH | Initialize destination drive parameters |
| 5646H | Flush all drive buffers |
| 57C8H | Disk read operation |
| 57D4H | Disk write operation |
| 585AH | Error display with retry prompt |
| 5881H | Display message string |
| 6959H | Format track with sector interleave |
| 67C3H | Verify correct disk is mounted |
Dependencies
SYS6 calls numerous routines in the resident DOS (SYS0):
- 4424H: Open file for read
- 4428H: Close file
- 4467H: Display message string
- 4776H: Select drive and verify ready
- 4CB4H: Calculate granule from track/sector
- 4CC5H: Parse filename from command line
- 4CD9H: Skip whitespace in command buffer
- 4CEDH: Allocate buffer space
Self-Modifying Code
SYS6 uses self-modifying code extensively for efficiency:
- 5314H: Track counter incremented during batch operations
- 531AH: Batch size limit set during initialization
- 53D7H: Disk full flag toggled during copy operations
- 53ECH: Write counter for verification phase
- 57EBH: Disk command byte (80H=read, 40H=write, 20H=verify)
- 6C63H: Side selection toggle for double-sided formatting
Variables:
REFERENCED DOS WORK AREA VARIABLES (in SYS0 area):
| 4049H | HIGH$ pointer (BASIC high memory limit) |
| 430CH | DOS configuration byte |
| 4311H | DOS status word |
| 4317H | DOS error code |
| 4369H | DOS status flags byte |
| 436AH | DOS mode flags |
| 436BH | DOS control byte |
| 436CH | DOS control byte 2 |
| 4399H | DOS buffer pointer |
| 4930H | Drive parameter update flag |
SELF-MODIFYING CODE LOCATIONS:
| 5314H | Track counter (modified by code at 5313H, 5316H, 53F5H) |
| 531AH | Batch size limit (set at 528EH, tested at 5319H) |
| 53D7H | Disk full flag (set at 53CEH, tested at 53D6H) |
| 53ECH | Write counter (modified at 53EBH, 53EEH, tested at 53FBH) |
| 544FH | Buffer end pointer (modified at 5454H, loaded at 5411H) |
| 5401H | Granule count save (set at 5336H, loaded at 5400H) |
| 57EBH | Disk operation command flag (80H=read, 40H=write, 20H=verify) |
BUFFER POINTERS:
| 5D10H | Sector data pointer |
| 5D12H | Track buffer start pointer |
| 5D14H | Track buffer end pointer |
| 5D16H | Track buffer relocation base |
SYS6 CONTROL/STATUS VARIABLES (593BH-5941H):
| 593BH | Multi-disk operation mode flag (bit 7 = multi-disk active) |
| 593CH-593DH | Saved HIGH$ pointer (2 bytes) |
| 593EH-593FH | Current drive parameter block pointer (2 bytes) |
| 5940H | Operation status byte 1 |
| 5941H | Operation status byte 2 |
PRIMARY DRIVE PARAMETER BLOCK (5942H-594BH, 10 bytes):
| 5942H | Drive number (FFH = uninitialized) |
| 5943H | Drive status flags |
| 5944H-5945H | (reserved) |
| 5946H-5947H | Pointer 1 (5999H) |
| 5948H-5949H | Pointer 2 (5999H) |
| 594AH-594BH | DCB pointer (5A51H) |
SOURCE DRIVE PARAMETER BLOCK (594CH-5955H, 10 bytes):
| 594CH | Source drive number (FFH = uninitialized) |
| 594DH | Source drive status flags |
| 594EH-594FH | Source buffer pointer (5AE5H) |
| 5950H-5951H | Pointer 1 (59B7H) |
| 5952H-5953H | Pointer 2 (59A3H) |
| 5954H-5955H | Source DCB pointer (5A3CH) |
DESTINATION DRIVE PARAMETER BLOCK (5956H-595FH, 10 bytes):
| 5956H | Destination drive number (FFH = uninitialized) |
| 5957H | Destination drive status flags |
| 5958H-5959H | Destination DCB pointer (5B17H) |
| 595AH-595BH | Pointer 1 (59C5H) |
| 595CH-595DH | Pointer 2 (59ADH) |
| 595EH-595FH | Destination info pointer (5A44H) |
FILENAME BUFFER (5960H-5977H):
| 5960H-5967H | Source filename (8 bytes, space-padded) |
| 5968H-596FH | Source extension area |
| 5970H-5977H | Destination filename (8 bytes, space-padded) |
DISK OPERATION PARAMETERS (5978H-5982H):
| 5978H-5979H | Parameter block 1 pointer |
| 597AH-597BH | Parameter block 2 pointer |
| 597CH | Sector size indicator |
| 597DH | Sector size indicator 2 |
| 597EH | Track layout byte (82H) |
| 597FH-5980H | Reserved |
| 5981H-5982H | Parameter block 3 pointer |
BOOT SECTOR TEMPLATE (5983H-5994H):
| 5983H-598AH | "BOOTNAME" - default boot filename template |
| 598BH-5993H | Default format parameters ":2:/4:/:" with terminators |
OPTION FLAGS (5994H-5997H):
| 5994H | Option flags byte 1: Bit 0: $ option (system disk) Bit 1: Skip boot sector flag Bit 2: (unused) Bit 3: (unused) Bit 4: (unused) Bit 5: (unused) Bit 6: QUERY option (40H) Bit 7: (unused) |
| 5995H | Option flags byte 2: Bit 0: (unused) Bit 1: (unused) Bit 2: (unused) Bit 3: (unused) Bit 4: (unused) Bit 5: (unused) Bit 6: (unused) Bit 7: Abort on error flag |
| 5996H | Option flags byte 3: Bit 0: (unused) Bit 1: (unused) Bit 2: BACKUP option (04H) Bit 3: COPY option (08H) Bit 4: (unused) Bit 5: Set during FORMAT init Bit 6: (unused) Bit 7: (unused) |
| 5997H | Option flags byte 4 |
WORK AREA (5998H-59D2H):
| 5998H-59B6H | General work area (zeroed on init) |
| 59B7H-59B8H | Format parameter pointer |
| 59B9H-59BBH | Additional parameters |
| 59BCH | Configuration byte |
| 59BDH-59BEH | Reserved |
| 59BFH-59C0H | Reserved |
| 59C1H-59C2H | Reserved |
| 59C3H-59C4H | Program end address |
| 59C5H-59C6H | Parameter storage |
| 59C7H-59C8H | Parameter storage |
| 59C9H | Reserved |
| 59CAH-59CBH | Parameter storage |
| 59CCH-59CDH | Parameter storage |
| 59CEH-59CFH | Parameter storage |
| 59D0H | Reserved |
| 59D1H-59D2H | High memory limit |
MESSAGE STRINGS:
| 59D3H | "ERROR WHILE " + 03H |
| 59EEH | "PRESS \"ENTER\" WHEN " + 03H |
| 5A02H | " DISKETTE MOUNTED ON DRIVE 0" + 0DH |
| 5A1DH | Drive number ASCII (modified at runtime) |
| 5A1FH | "DONE" + 0DH |
| 5A24H | "SOURCE & DEST SAME FILE" + 0DH |
| 5A3CH | "SOURCE " + 03H |
| 5A44H | "DESTINATION " + 03H |
| 5A51H | "** SYSTEM **" + 03H |
| 5A5FH | "SECTOR " + 03H |
| 5A67H | "READING " + 03H |
| 5A70H | "WRITING " + 03H |
| 5A79H | "VERIFYING " + 03H |
| 5A84H | "CPR" + 00H (Cancel/Proceed/Retry codes) |
| 5A88H | "REPLY C (CANCEL), R (RETRY) OR P (PROCEED)" + 0DH |
| 5AB3H | "NY" + 00H (No/Yes codes) |
| 5AB6H | " (Y OR N) " + 03H |
| 5AC2H | "DISKETTE/GAT OVERFLOW" + 0DH |
| 5AD8H | "DISK FULL - " + 03H |
SOURCE DISK CONTROL AREA (5AE5H-5B16H):
| 5AE5H-5AE7H | Source file control bytes |
| 5AE8H-5AE9H | Source sector buffer pointer |
| 5AEBH-5AECH | Source disk identifier |
| 5AEDH | Source disk type byte |
| 5AEEH | Reserved |
| 5AEFH-5AF0H | Source track number (16-bit) |
| 5AF1H-5AF2H | Source disk total granule count |
| 5AF3H-5AF4H | Reserved |
| 5AF5H-5B16H | Source disk sector buffer (32 bytes) |
DESTINATION DISK CONTROL AREA (5B17H-5B48H):
| 5B17H | Destination DCB status byte (bit 7 = initialized) |
| 5B18H | Destination DCB flags |
| 5B19H | Reserved |
| 5B1AH-5B1BH | Destination buffer pointer |
| 5B1CH | Reserved |
| 5B1DH-5B1EH | Destination disk identifier |
| 5B1FH | Destination disk type byte |
| 5B20H | Reserved |
| 5B21H-5B22H | Remaining granule count |
| 5B23H-5B24H | Destination total granule count |
| 5B25H | Reserved |
| 5B26H | Reserved |
| 5B27H-5B48H | Destination disk sector buffer (32 bytes) |
THIRD CONTROL AREA (5B49H-5B56H):
| 5B49H-5B56H | Third parameter block (used for three-disk operations) |
BUFFER SWAP CONTROL LIST (5B57H-5B5FH):
| 5B57H | Entry type (02H = process this entry) |
| 5B58H | Byte count for swap |
| 5B59H-5B5AH | Buffer 1 pointer (5B64H) |
| 5B5BH | Entry type |
| 5B5CH | Byte count |
| 5B5DH-5B5EH | Buffer 2 pointer (5BA3H) |
| 5B5FH | Entry type (end marker) |
Disassembly
4D00H - SYS6 Entry Point and Function Dispatcher
SYS6 is entered with the function code in Register A. This dispatcher examines the function code and routes execution to the appropriate handler. SYS6 handles the FORMAT, COPY, and BACKUP commands among others. The IY register is set to point to the DOS work area at 4380H.
NOTE: 4380H is the base address of the DOS work area. Many subsequent instructions will use IY+offset to access DOS variables.
NOTE: This sets a marker/flag indicating SYS6 has been entered.
NOTE: This is a status flag indicating a SYS6 operation is in progress.
4D1EH - FORMAT Command Handler Entry
This section begins processing the FORMAT command (function code 48H). It first checks bit 6 of 436AH to determine if special handling is needed, then saves the high memory pointer and calls subroutines to parse the command line and set up for formatting.
NOTE: Bit 6 of this byte indicates a special condition (possibly batch mode or protected state).
NOTE: 4049H contains the highest usable memory address.
NOTE: 4467H is the DOS message display routine (vectors to 44CFH).
4D8BH - FORMAT Error/Alternate Path Handler
This section handles cases where the initial parameter parsing encountered an issue. It sets up default values in the control area and re-parses the drive specification.
4D98H - Check for Dollar Sign Prefix
This section checks if the current character on the command line is a dollar sign ($), which indicates a special filename format in NEWDOS/80. If found, a flag is set and the pointer is advanced.
4DA6H - Copy Filename to Buffer and Set Up Parsing
This section copies up to 80 characters from the command line to a working buffer, then begins parsing for special characters like colon (:), period (.), and slash (/) which indicate drive or extension separators.
NOTE: This will be pushed onto the stack as a return point.
NOTE: This copies the command line to the working buffer.
4DC6H - Handle Filename Separator Characters
When a separator character (colon, period, or slash) is found, this section scans back through the parsed filename buffer to insert the separator at the correct position.
4DDEH - Set Parsing Flags and Continue
After handling any separators, this section sets flags at 5996H and 5997H to indicate the parsing state, then calls the option parsing routine with parameter 08H.
4DF3H - FORMAT Execution Setup Subroutine
This subroutine sets up the sector data for the FORMAT operation. It initializes a block of memory with sector header information.
4E3DH - Continue FORMAT Parameter Setup
This section continues setting up FORMAT parameters based on various option flags. It checks for double-sided format options and adjusts the sector configuration accordingly.
4E68H - User Prompt Subroutine
This subroutine displays a prompt message to the user and waits for a response. It's used to confirm operations like formatting when certain conditions are met.
4E86H - Combine D and C into D
4E8AH - Filename Parse Entry Point (Alternate)
This is an alternate entry point for filename parsing that uses a different destination buffer.
NOTE: 4CD5H is a SYS0 routine that validates filename characters.
4EA7H - Main Option Parsing Routine
This is the main option parsing routine for FORMAT/COPY/BACKUP commands. Register B contains a mode flag on entry. It scans the command line for option keywords and sets appropriate flags in the option bytes at 5994H-5997H.
4ECAH - Option Flag Validation
This section loads the option flag words from 5994H-5997H and validates the combination of options. It checks for conflicting or incompatible options and adjusts flags as needed.
4F1DH - Process Option Keyword
When an option keyword is found on the command line, this section looks it up in a table at 505CH to determine what flags to set. It matches the keyword and extracts the corresponding flag values.
4F49H - Option Error Exit
This is the error exit point for conflicting or invalid option combinations. It jumps to the error handler at 5218H.
4F4CH - Skip to Next Option Table Entry
When an option keyword doesn't match, this section skips to the next entry in the option table by finding the end-of-keyword marker (bit 7 set).
NOTE: The 0000H is a placeholder - the actual address was stored by the previous instruction!
4F8BH - Option Handler Entry Points
These are entry points for specific option handlers. Each sets up DE with a destination buffer address and calls a common processing routine.
4F9EH - Numeric Option Parser (2-6)
This subroutine parses a single-digit numeric option value (2-6) and stores it at 64AFH.
4FACH - Copy Name to DCB Buffer
This subroutine copies a name (up to 32 characters) from the command line to the DCB buffer at 4480H, terminated by 0DH (carriage return).
4FC3H - Parse Numeric Value to 64ACH
4FCEH - Parse Numeric Value to 68ABH
4FD6H - Parse Numeric Value to 68ACH
4FDDH - Parse and Store 16-bit Value at 5978H
4FE5H - Parse and Store 16-bit Value at 5981H
4FEDH - Parse and Store 16-bit Value at 597AH
4FF5H - Parse Retry Count Option
NOTE: This is a self-modifying write into the code area!
4FFFH - Parse Option with Range Check
500DH - Parse 3-Character Hex/Alphanumeric String
This subroutine parses up to 3 hexadecimal or alphanumeric characters from the command line and stores them at 624CH. Valid characters are 0-9 and A-Z.
5025H - Parse 16-bit Hexadecimal Value
This subroutine parses a 16-bit hexadecimal value from the command line and returns it in DE. It also calculates a CRC-like checksum of the input.
505CH - Option Keyword Table (DATA)
Option keyword lookup table for FORMAT, COPY, and BACKUP commands. Each entry contains the keyword (some prefixed with 'O' for parser use), a flag/terminator byte, and parameter bytes defining option behavior, conflicts, and handlers. Prefix bytes before keywords belong to the previous entry's parameters.
5186H-51FFH - NO CODE PRESENT
5200H - Error Exit Points
This section contains multiple error exit entry points. Each loads a specific error code into Register A and jumps to the common error handler at 521AH. The error codes correspond to NEWDOS/80 error numbers.
521AH - Common Error Handler Entry
This is the common error handler for SYS6. It saves the error code, calls cleanup routines, then invokes the DOS error display mechanism. The handler restores system state before reporting the error.
523CH - Flush Error Handler
This code handles the case where the buffer flush at 5230H failed. It displays an error message and then loops back to retry the error exit sequence.
524EH - Format Buffer Initialization
This routine initializes the format buffer by loading the current buffer pointers and preparing for the track data relocation.
Format is not complete - display status and calculate how many tracks can be formatted with available memory.
[LOOP START] - Count how many track entries (258 bytes each) can fit in the remaining memory.
[LOOP END] - Register A now contains the number of tracks that can be formatted in one batch.
529DH - Main Track Formatting Loop
[MAIN LOOP START] - This loop reads each track from the source disk and stores it in the track buffer. Each iteration handles one track.
Error 1CH or 1DH occurred - check if COPY option is set which requires special end-of-track handling.
Disk error occurred that wasn't an expected end condition - attempt error recovery.
Read succeeded (or user chose to skip) - store the track entry in the buffer.
52D0H - Store Track Entry in Buffer
At this point, either the track was read successfully (A=00) or a "Record Not Found" error occurred (A=06), indicating an unformatted track. The code stores the track marker and status in the track table.
FORMAT only (no COPY/BACKUP) - check if this is track 0 and if we need to copy the boot sector template.
Track 1 or 2 - copy the directory boot sector template from 64BAH.
Check if this is track 0 and if the track data contains a valid boot sector signature.
Valid NEWDOS/80 boot sector found - copy the 16-byte boot overlay from 6EB5H.
[BATCH COMPLETE] - All tracks in this batch have been read. Now write them to the destination disk.
5324H - Write Track Batch to Destination
This subroutine writes all the tracks that were read into the buffer to the destination disk. It handles COPY/BACKUP modes which may write to a different drive.
COPY mode - verify source and destination tracks match before writing.
Track mismatch in COPY - need to seek to correct track on destination before writing.
5360H - COPY/BACKUP Granule Allocation Check
This section handles space allocation for COPY and BACKUP operations. It checks if there's room on the destination disk before writing.
No granules allocated yet - need to request allocation from destination disk's directory.
COPY mode - use destination disk's granule parameters instead of source.
Allocation returned an error - check if it's a recoverable condition.
Disk full condition - finalize the partial copy and prepare to complete.
53D5H - Write Track to Destination Disk
This is the actual track write section. It processes each track in the buffer and writes it to the destination disk.
53FBH - Finalize Write Batch
This subroutine is called when a write batch is complete or when switching tracks during COPY. It ensures all pending operations are completed.
5400H - Post-Write Verification Loop
After writing tracks to the destination disk, this code performs verification by reading back the data to ensure it was written correctly. This is part of the FORMAT/COPY/BACKUP verification phase.
Status mismatch - the track didn't verify correctly. Update granule count and flag error.
Track verified successfully - compare the sector data with the original to ensure data integrity.
All 256 bytes verified successfully - advance to the next track entry.
Data mismatch found during verification - handle the compare error.
546DH - Write Sector to Disk
This subroutine writes a sector (track) from the buffer to the destination disk. It handles error recovery and sets up the proper write command.
Track was unformatted (status 06H) - set a flag to indicate format-only operation.
Write error occurred - call error handler and potentially retry.
5492H - Decrement Granule Count
This small utility subroutine decrements the remaining granule count when a track operation fails or is skipped.
549CH - End of Copy/Backup Operation
This code is reached when the end of the source disk is detected during a COPY operation. It writes any remaining buffered tracks to the destination, then finalizes the operation based on mode.
BACKUP mode completion - copy the directory from source to destination.
54D7H - Drive Parameter Check Utility
This utility subroutine checks drive parameters for double-sided disk handling and side selection.
Double-sided disk - toggle the side selection bit.
54ECH - Store Sector and Track Parameters
This utility stores sector and track values into the drive control block.
54F3H - Copy Drive Parameters from Work Area
This subroutine copies drive configuration parameters from the appropriate work area based on the option flags.
FORMAT mode - use different source parameters.
Memory is available - set up the hash table or directory buffer.
5535H - Set Up Destination Drive
This subroutine configures the system to use the destination drive for write operations.
Drive not initialized - perform drive selection and initialization.
Drive access successful - verify source and destination match for COPY operation.
Source and destination match - display warning about copying to same disk.
5578H - Drive Setup Entry Points
These are multiple entry points for the drive setup routine, each loading a different drive parameter address into HL before falling through to the common setup code at 5585H.
Drive is initialized - save registers and check for disk change.
Status mismatch - update the second status byte to reflect current state.
No disk present - prompt user to insert disk.
Wait for user to press ENTER after inserting the disk.
55FBH - Disk Parameter Processing Loop
This code processes disk parameters, handling different disk types and swapping buffers as needed for multi-disk operations.
Buffer swap needed - exchange buffer contents between source and destination.
[LOOP] - Buffer swap loop: exchange bytes between two buffers.
Entry type < 02H - done processing, restore registers and return.
5646H - Flush All Drive Buffers
This subroutine iterates through all three drive parameter blocks (at 5942H, 594CH, and 5956H) and flushes any pending buffer data for drives that are currently active. It is called from the error handler at 5230H before exiting to ensure no data is lost. Register B on entry contains a retry count (typically 5).
[LOOP START] - Begin iterating through each drive parameter block.
5658H - Flush Single Drive Buffer
This subroutine flushes the buffer for a single drive. On entry, HL points to the drive parameter block and A contains the drive status byte. Register B (from the caller) contains a retry/error handling flag. This routine interfaces with the DOS buffer management system to write any dirty sectors back to disk.
Buffer was found. Now determine whether it's a read buffer or write buffer by checking bit 0 of the flags in B, and copy the appropriate data.
[SUCCESS PATH] - Buffer flush completed successfully.
[ERROR PATH] - Check if errors should be suppressed or reported.
568BH - Initialize Primary Drive with Retry
This subroutine initializes the primary (system) drive with error code 04H and sets up for operation with error retry enabled.
56A2H - Verify End-of-Disk Condition (COPY Mode)
This subroutine checks for the end-of-disk condition during COPY operations. It loops until bit 5 of a status byte is set, indicating the disk operation is complete.
End-of-disk detected. Save the current position and set up for the next operation.
56D4H - Calculate Sector Address
This subroutine calculates the absolute sector address from a logical sector number. It uses the disk geometry parameters from the IY register base.
56DDH - Get Directory Entry Address
This subroutine retrieves the address of a directory entry. It calls the SYS0 directory lookup routine.
56E2H - Seek to Specified Sector
This subroutine seeks to a specified sector, handling track changes as needed. On entry, A contains the target sector number.
56F4H - Seek to Track
This is a simpler seek routine that positions the head to a track without sector positioning.
56F9H - Home Drive Head
This routine homes the drive head (seeks to track 0).
5701H - Read Disk Sector
This subroutine reads a sector from the disk.
5706H - Initialize Sector Counter
This routine initializes the sector counter from the system value.
570DH - Update Sector Counter
This subroutine updates the sector counter, potentially triggering a track seek if necessary.
571BH - Toggle Track Progress Indicator
This subroutine toggles an asterisk (*) character on the screen to indicate track processing progress. It displays at position 3C3FH (top-right corner of the video display, column 63 of row 0).
572BH - Check for BREAK Key with Delay
This subroutine checks for the BREAK key while providing a small delay. It allows the user to cancel long-running operations like FORMAT or COPY. Returns the key code in A.
Fall through to check for BREAK key and special conditions.
Check if BREAK+UP or BREAK+DOWN is pressed (keyboard row 3840H).
[BREAK DETECTED] - Wait for key release and check for retry/cancel.
5751H - Check Free Space and Allocate Sectors
This subroutine manages sector allocation for the disk bitmap. It checks if there's room for more sectors and handles bitmap manipulation. Called during FORMAT and COPY operations to track used/free sectors.
[SECTOR ALLOCATION LOOP] - Process the bitmap to mark sectors.
Rotate the mask to position the correct bit.
5784H - Reserved/Padding Area
This area contains NOP instructions, likely reserved space or padding for alignment.
578AH - Initialize Verify Operation
This subroutine initializes the verify operation, setting up pointers and counters for verifying disk data. It's typically called after a FORMAT or COPY to verify the written data.
[VERIFY LOOP] - Read and verify each sector.
57C8H - Disk Read Subroutine
This subroutine reads a sector from disk using the FCB pointed to by IX. It's a wrapper that sets up the DE register and calls the SYS0 read routine.
57CEH - Disk Write Subroutine
This subroutine writes a sector to disk using the FCB pointed to by IX. Similar to the read routine, it's a wrapper for the SYS0 write function.
57D4H - Disk Write with Verify
This subroutine writes a sector and optionally verifies it. Uses IX as the FCB pointer.
57DAH - Display Error Status
This subroutine displays an error status message on the screen, showing the error type and the affected file/sector. It saves all registers before displaying and restores them after.
Continue the error display by showing the filename and prompting for retry.
584AH - Display Retry/Cancel Prompt
This subroutine displays a retry/cancel prompt after an error. It checks if user interaction is allowed and either prompts the user or automatically cancels. Register A on entry contains error flags; Register B contains operation flags.
585AH - Error Handler with Retry Prompt
This is the main error handler that displays the error, prompts for retry, and optionally updates the error counter. Called when a disk error occurs during read/write/verify operations.
User chose to retry. Increment the error counter at IX+0AH/0BH (16-bit counter).
5868H - Display Disk Error Message
This subroutine displays a detailed disk error message including the filename. The error code is expected in a self-modifying location (5869H). Returns NZ if an error was displayed.
587EH - Message Display Subroutine
This is a general-purpose message display routine that prints a string pointed to by HL, followed by a carriage return.
Fall through to output a carriage return.
5881H - Output Carriage Return
This subroutine outputs a carriage return character (0DH) to move the cursor to the beginning of the next line.
5886H - Display String with Control Characters Filtered
This subroutine displays B characters from the string at HL, converting control characters (below 20H) and high characters (80H and above) to spaces. Used for safe display of directory entries and user input.
5898H - Display B Spaces
This subroutine displays B space characters. Used for padding output and alignment.
58A0H - Display Filename from Directory Entry
This subroutine displays a filename in the format "FILENAME/EXT" from a directory entry. On entry, HL points to the directory entry. The filename is at offset +5 (8 characters) and extension at offset +13 (3 characters).
Now display the extension with a "/" separator if present.
Fall through to display the extension characters.
58B3H - Display Non-Space Characters from String
This subroutine displays characters from the string at HL, skipping trailing spaces. B contains the maximum number of characters to check. Used for compact filename display.
58BDH - Character Output Routine
This is the low-level character output routine. It saves DE, calls the ROM display routine, and restores DE. Character to output is in Register A.
58C5H - Display String and Prompt
This routine displays a string and then shows the retry/cancel prompt. Used for error messages that require user response.
Fall through to display the retry/cancel prompt.
58C8H - Retry/Cancel Prompt Handler
This subroutine displays the "REPLY C (CANCEL), R (RETRY) OR P (PROCEED)" prompt and waits for user input. Returns Z flag set if user chose Retry, NZ if Cancel or Proceed.
58DEH - Yes/No Prompt Handler
This subroutine displays a yes/no prompt and returns the user's choice. Used for confirmation dialogs.
Fall through to the menu handler.
58E4H - Menu Prompt Handler
This is the general menu prompt handler. HL points to a null-terminated string of valid option characters. It displays the prompt, waits for a valid key, and returns the index of the chosen option in A (0-based).
Find the end of the option string to display the full prompt.
[INPUT LOOP] - Wait for a valid key press.
Search for the pressed key in the option string.
Match found! Display the selected character and return.
5909H - Display Decimal Number
This subroutine displays the 16-bit number in DE as a decimal value. It uses a powers-of-10 table at 5933H to perform the conversion. Leading zeros are suppressed.
[DIGIT LOOP] - Process each decimal digit position.
[SUBTRACTION LOOP] - Count how many times we can subtract the power of 10.
Display the final (units) digit.
5933H - Powers of 10 Table (DATA)
This table contains the powers of 10 used by the decimal display routine. Each entry is a 16-bit value stored in little-endian format. The values represent: -10000, -1000, -100, -10 (stored as two's complement negatives for the subtraction algorithm).
593BH - System Variables and Buffers
This area contains system variables, flags, and buffer pointers used throughout the SYS6 FORMAT/COPY utility. Values shown are initial/default values; many are modified during operation.
5942H - Drive Parameter Block Table
This table contains three 10-byte drive parameter blocks, one for each possible drive (0, 1, 2). Each block stores the drive status and buffer pointers. A value of FFH in the first byte indicates the drive slot is unused.
5960H - Filename Buffer Area
This area is used as a buffer for filename storage and manipulation during COPY operations. Initially filled with spaces (20H).
5978H - Disk Geometry Parameters
This area stores disk geometry and format parameters. These values are set during FORMAT initialization and used throughout disk operations.
5982H - Boot Sector Template
This is the boot sector name template that gets written to track 0 during FORMAT. Contains "BOOTNAME" followed by disk parameters.
5994H - Operation Mode Flags
These bytes control the operation mode of the FORMAT/COPY utility. They are set based on command line options and modified during execution.
5999H - Scratch/Buffer Area
This large area (5999H-59D2H) serves as a scratch buffer and temporary storage area. It is used for sector data during read/write operations.
59D3H - Message Strings
This area contains the ASCII message strings displayed by the FORMAT/COPY utility. Each string is terminated with a control character (03H) or null. The disassembler shows these as instructions but they are actually string data.
5AE5H - File Control Block (FCB) Template
This area contains the File Control Block used for disk I/O operations. It stores the current filename, extension, drive number, and sector information.
5AF3H - Sector Buffer Control Area
This area contains control structures for the sector buffer management. It tracks buffer allocation, dirty flags, and sector addresses.
This area contains an FFH-filled buffer used for sector data during COPY/BACKUP operations. The FFH bytes serve as uninitialized/available buffer space.
5B17H - Destination File Control Block (FCB)
This is the second File Control Block used during COPY operations to track the destination file. It follows the same structure as the FCB at 5AE5H.
5B49H - Third File Control Block (FCB)
A third FCB structure used for intermediate file operations during multi-file copy or backup operations.
5B57H - Option Handler Dispatch Table
This table maps option codes to their handler routines. Each entry contains: option code, parameter bytes, and either inline code or a jump to the handler. The table is processed by the option parser at 55FBH to handle FORMAT/COPY command-line options.
5B64H - Option Handler: DD (Double Density) Parameter
This handler processes double-density format parameters. The structure contains SYS0 function references and parameter values used during FORMAT operations.
5B72H - Option Handler: Stepping Rate Parameter
This handler processes disk stepping rate parameters for the FDC (Floppy Disk Controller).
5B7CH - Option Handler: Verify Parameter
This handler processes the verify flag for FORMAT/COPY operations.
5B82H - Option Handler: Head Load/Sectors Per Track
This handler processes head load timing and sectors-per-track parameters.
5B90H - Option Handler: Track/Cylinder Parameters
This handler processes track count and cylinder configuration parameters.
5BA3H - Option Handler: Buffer/Memory Parameters
This handler processes buffer size and memory allocation parameters for COPY operations.
5BC4H - Inline Option Code: Name Validation
This inline code validates disk name parameters during FORMAT operations.
5BCDH - Option Handler: Directory Parameters
This handler processes directory entry count and allocation parameters.
5BD8H - Option Handler: System Configuration
This handler processes system configuration parameters and memory mapping options.
5BE1H - Option Handler: Disk Geometry Parameters
This handler processes disk geometry parameters including sector size, track count, and side configuration.
5C00H - Sector Size Configuration Data
This area contains configuration data for sector size settings. The values are used by the FORMAT command to set up disk parameters.
5C0BH - DD Option Handler: Double Density Processing
This routine handles the double-density option for FORMAT operations. It checks the current density setting and adjusts format parameters accordingly.
5C1EH - Head Load Option Handler
This routine processes head load timing parameters for the FDC. It calculates the appropriate head load value based on drive capabilities and user settings.
5C3EH - Stepping Rate Option Handler
This routine handles the stepping rate parameter for the FDC. It validates the stepping rate and configures the controller accordingly.
5C43H - Verify Option Handler
This routine handles the verify flag for FORMAT operations. When verify is enabled, each track is read back after writing to confirm data integrity.
5C5BH - Name Validation Handler
This routine validates disk name parameters by scanning the input buffer for valid characters. Names can be up to 80 characters.
5C69H - Geometry Parameter Handler
This routine processes disk geometry parameters and updates the format configuration accordingly.
5C71H - System Memory Parameter Handler
This routine reads system memory configuration values and stores them in the format parameter block.
5C80H - Set Up Sector Size (Returns BC=256)
This routine sets up the sector size parameter. For standard TRS-80 disks, this returns BC=0100H (256 bytes per sector).
5C8EH - Set Up Sector Buffer Address
This routine stores the sector buffer address and sets the FCB flag to indicate the buffer is configured.
5C96H - FORMAT Initialization
This routine initializes FORMAT operation parameters by reading source and destination drive configurations and checking for compatibility. It sets up the option dispatch table pointers for double-sided disk operations.
The following code sets up dispatch table pointers for double-sided disk operations by redirecting option handlers to the appropriate routines.
5CE4H - DOS Configuration Check
This routine checks the DOS configuration flags and sets FCB parameters based on system capabilities.
5CF2H - Extended Mode Sector Count Check
This routine checks if extended disk mode is active and returns the appropriate sector count multiplier.
5D04H - Scratch Area / Reserved Space
This area contains 13 bytes of zeros used as scratch space or reserved for future use. Some bytes may be modified during FORMAT operations.
5D11H - PDRIVE/AUTO Processing Variables
This area contains variables for processing PDRIVE (physical drive) and AUTO configuration parameters during FORMAT with system disk creation.
5D16H - FORMAT System Disk Initialization
This routine handles the initialization for creating a system disk during FORMAT. It clears FCB flags, checks for PDRIVE/AUTO options, and sets up the source drive for file copying.
The following loop reads the AUTO/PDRIVE command string from the terminal, validating each character.
Handle comment - skip to end of line.
Store valid characters and validate filename format.
Error handler - invalid AUTO/PDRIVE parameter.
5D71H - Read Character from Input
This subroutine reads a single character from the input stream, handling special cases like BREAK key and end-of-file. Returns Z flag set if carriage return (end of line).
Handle special input condition (EOF or BREAK).
5D86H - Continue FORMAT Drive Setup
This routine continues the FORMAT drive setup by initializing the source drive parameters and calculating buffer space.
Clear the track table for PDRIVE operation.
5DB5H - Process AUTO/PDRIVE File List
This routine processes the file list for AUTO command or PDRIVE configuration, opening each file specified in the input buffer.
Copy filename from input buffer to filename buffer.
Append drive number to filename.
5DF1H - Record File Track in Table
This routine records the track number of an opened file in the track table for later copying during system disk creation.
5E07H - Finish AUTO/PDRIVE Processing
This routine completes the AUTO/PDRIVE file list processing and returns to normal FORMAT operation.
5E0FH - Initialize AUTO Command Pointers
This routine initializes the AUTO command buffer pointers for system disk operations.
5E36H - Check Directory Entry Flags
This code checks directory entry flags to determine if the entry should be processed during FORMAT/COPY operations.
Compare file extension with filter pattern.
5E5BH - Process Valid Directory Entry
This routine processes a valid directory entry that passed all filters, checking for additional conditions like password protection.
Display confirmation prompt for this file.
5E87H - Store Directory Entry in Track List
This routine stores the directory entry information in the track list for later processing during FORMAT/COPY operations.
5EAAH - Advance to Next Directory Entry
This routine advances to the next directory entry and checks if there are more entries to process.
5EB3H - Begin Track Processing
This routine begins processing the collected track list, reading and copying data from source to destination.
5ECEH - Copy Track Entry Data
This routine copies the track entry data to the destination buffer.
5EE4H - Set Up Destination Drive Parameters
This routine sets up the destination drive parameters by reading disk geometry and calculating sector counts.
5EFCH - Special Track Processing Mode
This routine handles special track processing mode for disk copy operations.
5F32H - Process Matching File Entry
This routine processes a matching file entry found in the destination directory.
5F71H - Handle Extended File Attributes
This routine handles files with extended attributes by writing additional directory information.
5F89H - Continue Track List Processing
This routine continues processing the track list and loops until all entries are handled.
5F92H - Standard Track Processing
This routine handles standard (non-special) track processing for normal COPY operations.
5FD7H - Mark Track Entry and Copy Extent Data
This section executes when an unused track table entry is found. It marks the directory entry as processed, copies the track number into the table, and transfers extent information for file allocation.
[LOOP START] Initialize 10 granule allocation bytes to FFH (unallocated).
600BH - Process Extended File Attributes
This section handles files with extended attributes (bit 6 set), calculating granule positions for multi-extent files.
The following instruction at 6027H is self-modified - the immediate value 00H was patched at 5FE1H with the actual sector number.
6030H - Calculate Granule Position
This section performs complex calculations to determine the correct granule position within the disk allocation map.
[LOOP START] Increment DE by granules per lump times.
6053H - Alternate Granule Calculation Path
This path handles the case where the subtraction resulted in underflow.
6058H - Complete Granule Position Calculation
Final steps to calculate the absolute granule position and store it in the allocation map.
6064H - Store Granule Allocation Entry
This section stores the calculated granule information into the allocation map and handles overflow conditions.
6083H - Directory Loop Continuation
This is the common exit point for directory loop iterations. It advances to the next entry and loops back to 5FA7H.
6092H - Finalize Directory Processing
This routine is called when all directory entries have been processed. It finalizes the track processing and writes allocation data.
60A9H - Write Extended Directory Data
This routine writes extended directory information for files with special attributes. Called from 5F7BH.
60BFH - Source Directory Scan Entry
This routine initiates scanning of the source disk directory for COPY operations.
[DIRECTORY SCAN LOOP] Scan source directory entries.
60E1H - Mark and Copy Source Entry
This section marks a source directory entry as processed and copies its extent data.
60F1H - End of Source Scan - Switch to Destination
This section handles the end of source directory scan and prepares to process the destination.
60F5H - Process Destination Directory
This routine scans the destination directory and allocates entries for files being copied.
[DESTINATION SCAN LOOP]
613AH - Store File Addresses in Directory Entry
This section stores the load address and entry point in the directory entry for executable files.
614FH - Write Directory Entry and Continue
This section writes the completed directory entry and continues processing.
6157H - Complete COPY Operation
This routine marks the COPY operation as complete and returns to the main DOS handler.
6162H - Read Disk Parameters
This routine reads disk parameters and sets up the track allocation table buffer.
616FH - Copy 256 Bytes to System Buffer
This utility routine copies 256 bytes from HL to the system buffer at 4200H.
6172H - Block Copy 256 Bytes
General purpose 256-byte block copy routine. Entry: HL=source, DE=destination.
6178H - Calculate Directory Sector Parameters
This routine calculates sector parameters based on directory configuration.
[LOOP START] Calculate granule count by repeated subtraction.
6190H - Reset Track Position from Directory Pointers
This routine initializes the directory scan position from system pointers at 5D12H-5D14H.
619DH - Track Table Lookup
This routine looks up a track entry in the allocation table at 6291H and validates it.
61BAH - Advance Sector Counter
This routine advances the sector counter and checks if we've reached the end of the track. Returns Carry if track is complete.
61CBH - Granule Boundary Calculation
This routine calculates granule boundaries by repeated subtraction, storing intermediate values.
[LOOP START] Increment marker and subtract until underflow.
61D6H - Get Directory Entry Parameters
This routine retrieves directory entry parameters using RST 18H (DOS function call) and calculates the entry pointer.
61EAH - Validate Directory Entry
This routine validates a directory entry by checking attribute flags. Returns Z if entry is valid for processing.
61F6H - Check Double-Density Mode Flag
This routine checks if the disk is operating in double-density mode by examining bit 5 of the drive configuration byte.
61FCH - Check File Attributes
This routine checks file attributes for special handling requirements during copy operations.
6209H - Finalize Directory Entry Attributes
This routine finalizes directory entry attributes, adjusting load/entry addresses based on file type.
621CH - Write Granule Entry to Allocation Map
This routine writes a granule allocation entry to the GAT (Granule Allocation Table). It sets the appropriate bit in the allocation bitmap.
[LOOP START] Rotate bit mask to correct position.
6249H - Granule Allocation Error
This routine handles errors during granule allocation (overflow or duplicate allocation).
624CH - Message Strings and Response Table (DATA)
This section contains ASCII message strings used for COPY command prompts and status messages. The strings are terminated with 03H (ETX).
6291H - Main COPY/FORMAT Processing Entry
This is a major entry point for COPY/FORMAT processing. It checks option flags and sets up file operations. Note: Address 6291H is also used as the base of the track allocation table (256 bytes) - this code executes from a different context.
62B0H - Initialize Source Drive and Check Options
This section initializes the source drive and checks various COPY option flags to determine the operation mode.
6314H - Validate Disk Geometry Match
This section validates that source and destination disk geometries are compatible.
632CH - Continue COPY Setup
This section continues COPY setup after option validation, clearing flags and checking for special modes.
6377H - Two-Drive Copy Initialization
This routine initializes parameters for copying between two different drives.
6392H - Parse Destination Drive Number
This routine parses and validates the destination drive number from the command line.
63A0H - Parse Track Count Parameter
This routine parses track count parameter from command line (e.g., "=40" or "=80").
63B3H - Flush Drives and Initialize Parameters
This routine flushes both source and destination drives and loads disk parameters into working storage.
[LOOP START] Apply parameter overrides from table.
63ECH - Load Drive Parameters
This routine loads drive parameters from PDRIVE table into working storage. Entry: A=track count (FFH=use default), BC=drive info, HL=destination buffer.
Same drive for source and destination - set single-drive copy mode flags.
6424H - Read PDRIVE Table from Disk
Reads the PDRIVE configuration sector (sector 2) from disk into the system buffer at 4200H. Called from 6417H during drive parameter initialization.
6437H - Parse Drive Specification
Parses drive specification from command line. Handles "d:" format for drive numbers 0-5. Entry: DE=command line pointer, HL=5940H (drive flags), BC=parameter storage. Returns drive number or handles filespec parsing.
Handle end-of-text (03H) - generate drive spec from drive count.
Check if ILF/XLF options allow filespec parsing.
64A3H - Override Parameter Table (DATA)
Table of parameter override addresses used during COPY/FORMAT operations. Each entry is 3 bytes: count + address. Referenced by 63DDH during parameter override processing.
64B0H - Clear System Buffer
Clears 256 bytes of the system buffer at 4200H by writing the value in A. Uses DJNZ loop with B=0 (256 iterations).
64BAH - Boot Sector Loader Entry
This is the bootstrap loader code that gets written to the boot sector during FORMAT. It loads the system from disk into memory. The code runs at low memory addresses after being loaded by the ROM bootstrap. Contains FDC (Floppy Disk Controller) programming sequences.
| WD 1771 FDC Command Code: FEH (11111110) | |||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Function/Parameters | |
| 1 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | Command=Write Track (Format) Bit 7-4: Write Command (1111) Bit 3-0: Specific Code (0100) On its own, this would be an invalid command to send to the stock FDC. HOWEVER, as Blair Robbins has pointed out, this is a perfectly valid command to a Percom Doubler, and it sets the doubler to use the 1771 single density chip instead of the 1791 double density chip. | |
| WD 1771 FDC Command Code: D0H (11010000) | |||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | I3 | I2 | I1 | I0 | Function/Parameters | |
| 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | Command=Force Interrupt Bit 7-4: Command Code (1101) I3: 1=Interrupt Immediately I2: 1=Interrupt on the next Index Pulse I1: 1=Interrupt the next time Ready goes to Not Ready I0: 1=Interrupt the next time Not Ready goes to Ready | |
650CH - FDC Sector Read Subroutine (Boot Loader Helper)
This subroutine is called during the boot process to read sectors from the floppy disk. It handles buffer pointer management and interfaces with the WD1771 FDC (Floppy Disk Controller). The addresses 37E1H, 37ECH, 37EEH, and 37EFH are the FDC hardware registers. This code runs from the boot sector after being loaded into memory.
[RETRY LOOP START] - The following code attempts to read a sector from the FDC, retrying up to 10 times on failure.
| WD 1771 FDC Command Code: 1BH (00011011) | Function Description | ||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Summary of Bits | |
| 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | Command=Seek Bit 7-4: Command Code (0001) h=1: Enable Head Load/Settle delay V=0: No verification r1,r0=11: Stepping Motor Rate = 15ms | |
| WD 1771 FDC Command Code: 88H (10001000) | Function Description | ||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Summary of Bits | |
| 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | Command=Read Sector Bit 7-5: Read Command (100) m=0: Single Record b=1: IBM format E=0: Assume Head Already Engaged, no Delay Remainder: Unused (00) | |
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Not Ready | Protected | Head Loaded | Seek Error | CRC Error | Track 00 | Index | Busy |
[DATA TRANSFER LOOP] - Read bytes from FDC data register as they become available.
[READ COMPLETE] - Sector read finished. Check for errors and update pointers.
| WD 1771 FDC Command Code: D0H (11010000) | Function Description | ||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | I3 | I2 | I1 | I0 | Summary of Bits | |
| 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | Command=Force Interrupt Bit 7-4: Command Code (1101) I3=0: No immediate interrupt I2=0: No interrupt on Index Pulse I1=0: No interrupt on Ready change I0=0: No interrupt on Not Ready change | |
6573H - FDC Error Recovery and Retry
This section handles FDC read errors. It sends a RESTORE command to recalibrate the head to track 0, then retries the operation. If all retries fail, it enters a fatal error display loop.
| WD 1771 FDC Command Code: 0BH (00001011) | Function Description | ||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Summary of Bits | |
| 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | Command=Restore Bit 7-4: Command Code (0000) h=1: Enable Head Load/Settle delay V=0: No verification of Track 0 ID r1,r0=11: Stepping Motor Rate = 15ms | |
[FATAL ERROR] - All retries exhausted. Display error message and halt.
6588H - Wait for FDC Not Busy
This short subroutine waits for the FDC to finish any pending operation by polling the BUSY bit (bit 0) of the status register.
6591H - Short Delay Loop
A simple timing delay loop that counts down from 6 to 0. Used to provide brief delays for FDC timing requirements.
6597H - Boot Error Message Strings
This section contains the error message strings displayed during boot failures. The strings are prefixed with cursor positioning codes (1CH = cursor home, 1FH = cursor down) and terminated with 03H (ETX - End of Text).
65B0H - Boot Sector FCB Template: BOOT/SYS
This is an FCB (File Control Block) template for the BOOT/SYS file. During FORMAT, this data is copied and modified to create the directory entry for the boot system file. The FCB structure follows the standard NEWDOS/80 directory entry format.
65D0H - Boot Sector Padding
Padding bytes and filler data in the boot sector template area.
65DAH - Boot Sector FCB Template: DIR/SYS
FCB template for the DIR/SYS system file (directory handler). This is written to the disk directory during FORMAT.
65F0H - Boot Sector Configuration Data
Configuration data for the boot sector, including track/sector information that gets patched during FORMAT based on the target disk format.
65FAH - COPY Command: File Copy Handler
This is the entry point for the COPY command's file copy operation. It handles the TO parameter parsing and sets up flags for the copy operation.
6643H - Initialize Copy Operation
This routine initializes the copy operation, checking various flags to determine the copy mode and whether disk swapping prompts are needed for single-drive copies.
66BFH - Write System Sectors Loop
This loop writes the system sectors to the disk during FORMAT. It writes the boot sector, directory, and system file entries. The loop processes sectors 0-9 (10 sectors total).
Sector 1 processing - set up GAT (Granule Allocation Table) header.
Check for directory sectors (sectors 2-3) to copy FCB templates.
6710H - Calculate Disk Space Requirements
This routine calculates and displays the disk space requirements for a copy or format operation. It reads disk parameters and calculates free space, sectors needed, etc.
[ERROR PATH] - Disk format exceeds maximum capacity or other error.
674DH - Validate Disk Space for Copy
Validates that sufficient disk space exists for the copy operation.
6759H - Patch Boot Sector Parameters
This routine patches the boot sector template with the actual disk parameters. It modifies self-modifying code targets in the boot loader to match the disk format being used.
67AAH - Wait for User Response
Waits for user input (keypress) and sets up parameters for disk write operations.
67C3H - Copy/Format Setup Routine
This routine sets up the parameters for a COPY or FORMAT operation. It patches the boot sector, initializes the FCB, and checks various disk compatibility flags.
Disk read successful - validate disk format and copy parameters.
[DATE MISMATCH ERROR] - Disk date doesn't match expected date.
6840H - Copy Disk Name and Date
Copies disk name and date information from the source disk to the destination parameters. Handles various copy options like preserving original dates.
6886H - Proceed with Copy/Format Operation
After setup and validation, this section proceeds with the actual copy or format operation. It checks density compatibility and prompts for physical formatting if needed.
Track-by-track format mode - format each track individually.
68D0H - Full Disk Format Mode
Handles full disk format operation, formatting all tracks. Checks for system requirements and double-density support.
Double-density format setup - configure for double-density operation.
692FH - Display Error with Disk Info
Displays an error message followed by disk identification information.
693BH - Display Disk Name and Date Prompt
Displays a prompt message along with the current disk name and date from the sector buffer.
6959H - Format Track Initialization
This routine initializes the format track operation. It selects timing parameters based on CPU speed (from system flags at 4311H) and patches self-modifying code locations throughout the format routine. The timing is critical for proper FDC operation across different TRS-80 CPU speeds (1.77MHz, 2.03MHz, 4MHz).
[PATCH TIMING VALUES] - Copy timing values from table to self-modifying code targets.
[LOAD 16-BIT TIMING VALUES] - Load word values for more complex timing patches.
[INITIALIZE FORMAT VARIABLES] - Clear working variables for format operation.
6A13H - Generate Sector Interleave Table
This routine generates the sector interleave table at 6485H. The interleave pattern determines the physical order of sectors on the track to optimize read performance by allowing time for the system to process data between sequential sector reads.
[ADJUST INTERLEAVE TABLE] - Post-process table for proper ordering.
6A58H - Adjust Sector Numbers for Base
Adjusts sector numbers in the interleave table if the disk format uses 1-based sector numbering (some formats start sectors at 1 instead of 0).
6A67H - Format Track Main Entry
This is the main entry point for formatting a single track. It sets up the FDC registers, positions the head, and initiates the WRITE TRACK command. The track formatting writes ID fields, data fields, gaps, and sync patterns in the proper sequence.
| WD 1771 FDC Command Code: F4H (11110100) | |||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Function | |
| 1 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | Command=Write Track (Format) | |
6AB2H - Format Track: Write Sector ID Field
This section writes the sector ID field during formatting. The timing is critical - the code uses EX AF,AF' to quickly switch between checking FDC status (DRQ bit) and writing data bytes. The pattern: check status, wait for DRQ, switch registers, write byte, repeat.
[WRITE ID ADDRESS MARK AND TRACK/HEAD/SECTOR]
6B27H - Format Track: Write Data Field
This section writes the data field for each sector - the gap before data, data address mark, 256 bytes of data (E5H fill pattern), and CRC.
[WRITE 256 DATA BYTES] - Write sector data (E5H fill pattern, 256 bytes total).
6B82H - Format Track: Write Inter-Sector Gap
Writes the gap between sectors (Gap 3). After completing all sectors, the routine continues filling the track with gap bytes until the next index pulse.
[FILL REMAINDER OF TRACK] - All sectors written, fill to index pulse.
[FORMAT COMPLETE] - Track formatting finished.
6BB8H - Format Track Verification
After writing the track, this section verifies the format by reading back sectors and checking for errors. It handles retry logic and reports format failures.
[VERIFY FORMAT BY READING SECTORS]
[VERIFY ERROR - RETRY]
[FORMAT FAILED - ALL RETRIES EXHAUSTED]
[CONTINUE VERIFICATION]
6C5CH - Format Next Side/Track
After completing one side of a track, this section handles double-sided disks by formatting the back side, then advances to the next track.
[ADVANCE TO NEXT TRACK]
6C7DH - Motor Speed Errors
Error handlers for motor speed problems detected during format.
6C89H - FDC Error Handler
Handles FDC errors during format by analyzing the status bits and determining retry behavior.
6CA4H - Get Sectors Per Track
Utility routine to get the sectors per track value, adjusting for double-sided disks.
6CAFH - Motor Step Delay
Provides timing delay for drive motor stepping between tracks.
6CC2H - Format Timing Parameter Tables
These tables contain CPU speed-dependent timing parameters for the format routine. Each 26-byte (1AH) block contains values for a different CPU speed: 1.77MHz, 2.03MHz, and 4MHz. The values are copied to self-modifying code locations at runtime.
6D5EH - Message Strings
ASCII message strings used by the FORMAT and COPY commands. Strings are terminated with 0DH (carriage return) or 03H (ETX). Control codes: 1CH=home cursor, 1FH=cursor down.
6EB5H - Skip Whitespace and Check End
Utility routine to skip whitespace in command line input and check for end of line.
6EC0H - Check End of Line
Checks if current character is end of line (0DH = carriage return).
6ECBH - Parse Drive Number
Parses a drive number from the command line (0-7).
6EE7H - Validate and Parse Number
Validates a parsed number is within range and continues parsing.
6F0FH - Parse Decimal/Hex Number
Parses a decimal or hexadecimal number from input. Numbers ending in 'H' are treated as hexadecimal.
6FB8H - Validate Source/Destination Compatibility
Validates that source and destination disk parameters are compatible for copy operations.
6FE5H - Search for File
Searches for a file matching the current filespec.
6FF7H - "TO" Keyword Constant
The "TO" keyword used for COPY command syntax (e.g., "COPY file1 TO file2").