This is a disassembly of TRSDOS v2.3's BACKUP/CMD File.
There are 3 main parts to this routine. The first secures the SOURCE drive, DESTINATION drive, and BACKUP DATE. The second will FORMAT the disk if it is not otherwise determined to be a proper destination disk. The third will do the actual BACKUP to the destination disk.
In order to maximize the RAM available for a backup, the BACKUP routine is relocated to 4200H which overwrites DOS, so whether there is success or failure, a REBOOT is required.
SELF-MODIFYING CODE OPERANDS
| Address | Size | Name/Purpose | Values/Format | Set By | Used By |
|---|---|---|---|---|---|
| Relocated: 42ADH Original: 5648H | 1 | Saved FDC Track Position | Track number (00H-22H) where read phase left off | 42ABH during read phase | 42ACH during write phase (operand of LD A,nn) |
| Relocated: 42B2H Original: 564DH | 1 | Starting Track Number | First track number in current buffer batch | 42B0H during read phase | 42B1H during write phase (operand of LD D,nn) |
| Relocated: 4390H Original: 572BH | 1 | Original GAT Byte 0 | First byte of source GAT (allocation bits for Track 0) | 438EH (saved before 76H marker) | 438FH during finish (operand of LD A,nn) |
| Relocated: 449DH Original: 5838H | 1 | Destination Drive Select Code | 01H, 02H, 04H, or 08H | Initialization (52xxH) | 449CH (operand of LD A,nn) |
| Relocated: 44E8H Original: 5883H | 1 | Last Prompted Drive Code | Drive code with bit 6 = dest flag; 00H = force prompt | 44EBH, 4497H, 44E2H | 44E7H (operand of CP nn for smart prompt) |
| Relocated: 44EFH Original: 588AH | 1 | Drive Difference | 00H = single-drive, non-zero = two-drive backup | Initialization (source - dest) | 44EEH (operand of LD A,nn), 44BEH, 4441H |
| Relocated: 459CH Original: 5937H | 2 | COPYING Message - Track Digits | ASCII "00"-"34" | 42DEH via 4402H conversion | Message display at 457BH |
| Relocated: 45A7H Original: 5942H | 2 | COPYING Message - Sector Digits | ASCII "00"-"09" | 42E5H via 4402H conversion | Message display at 457BH |
| Relocated: 45BBH Original: 5956H | 2 | VERIFYING Message - Track Digits | ASCII "00"-"34" | 4316H via 4402H conversion | Message display at 457BH |
| Relocated: 45C6H Original: 5961H | 2 | VERIFYING Message - Sector Digits | ASCII "00"-"09" | 431DH via 4402H conversion | Message display at 457BH |
| Relocated: 45DAH Original: 5975H | 2 | LOADING Message - Track Digits | ASCII "00"-"34" | 4264H via 4402H conversion | Message display at 457BH |
| Relocated: 45E5H Original: 5980H | 2 | LOADING Message - Sector Digits | ASCII "00"-"09" | 426BH via 4402H conversion | Message display at 457BH |
| Original: 5435H | 1 | Format Track Counter | Current track being formatted (00H-22H) | Format routine | Format routine (operand of LD C,nn) |
PROGRAM VARIABLES
| Address | Size | Name/Purpose | Values/Format | Set By | Used By |
|---|---|---|---|---|---|
| Relocated: 4709H Original: 5AA4H | 1 | Directory Track Number | Usually 11H (17 decimal); copied from source GAT+02H | Initialization from GAT | Directory operations |
| Relocated: 4713H Original: 5AAEH | 1 | Tracks Per Buffer Count | Number of tracks that fit in RAM buffer (calculated at init) | RAM size calculation | 4289H, 429AH (buffer full check) |
| Relocated: 4714H Original: 5AAFH | 1 | Tracks Loaded Counter | Count of tracks currently in buffer; 00H=empty | 4286H (INC), 4339H (DEC) | 429AH (full check), 4346H (empty check) |
BUFFER AREAS
| Address | Size | Name/Purpose | Values/Format | Set By | Used By |
|---|---|---|---|---|---|
| Relocated: 4800H-4822H Original: 5B9BH-5BBDH | 35 | FDC Status Array | One byte per track; stores FDC status after reading each track | 4283H after each track read | 42F4H to build write commands (bits 5-6 → record type) |
Source Disk GAT Buffer (4900H-49FFH) - 256 bytes
| Address | Size | Name/Purpose | Values/Format | Set By | Used By |
|---|---|---|---|---|---|
| Relocated: 4900H-4922H Original: 5C9BH-5CBDH | 35 | Source Track Allocation Table | 2 bits per granule: 00=free, 01=1st used, 10=2nd used, 11=both/locked | Read from source Track 0, Sector 0 | 4247H (track copy decision) |
| Relocated: 4902H Original: 5C9DH | 1 | Source Directory Track Number | Usually 11H (17 decimal) | Read from source GAT | Copied to 4709H |
| Relocated: 4960H-4982H Original: 5CFBH-5D1DH | 35 | Source Track Lockout Table | Bit=1 means granule is locked out (bad sector) | Read from source GAT | 424EH (skip bad tracks) |
| Relocated: 49CEH-49D7H Original: 5D69H-5D72H | 10 | Source Pack ID | Disk identification string (for multi-disk sets) | Read from source GAT | 4481H-4487H (Pack ID comparison loop) |
Destination Disk GAT Buffer (4A00H-4AFFH) - 256 bytes
| Address | Size | Name/Purpose | Values/Format | Set By | Used By |
|---|---|---|---|---|---|
| Relocated: 4A00H-4A22H Original: 5D9BH-5DBDH | 35 | Destination Track Allocation Table | Same format as source; may differ due to bad sectors | Read from dest Track 0, Sector 0 | Track write decisions |
| Relocated: 4A60H-4A82H Original: 5DFBH-5E1DH | 35 | Destination Track Lockout Table | Bit=1 means granule locked out; OR'd with source lockout | Read from dest GAT; updated by 43FDH on format errors | 4253H (combined lockout check) |
| Relocated: 4ACEH-4AD7H Original: 5E69H-5E72H | 10 | Destination Pack ID | Must match source for non-format backup | Read from dest GAT | Pack ID verification |
General Purpose Sector Buffer (4B00H-4BFFH) - 256 bytes
| Address | Size | Name/Purpose | Values/Format | Set By | Used By |
|---|---|---|---|---|---|
| Relocated: 4B00H Original: 5E9BH | 1 | GAT Byte 0 / Backup Marker | 76H = backup in progress (also HALT opcode for safety) | 4218H (write marker), 4393H (restore original) | 44DEH (verify dest disk), boot safety |
| Relocated: 4B00H-4BFFH Original: 5E9BH-5F9AH | 256 | General Purpose Sector Buffer | Used for GAT read/write, Pack ID verification reads | Various disk I/O calls | GAT operations, verification |
Multi-Track Sector Buffer (4D00H+) - Variable size
| Address | Size | Name/Purpose | Values/Format | Set By | Used By |
|---|---|---|---|---|---|
| Relocated: 4D00H+ Original: 609BH+ | Variable | Multi-Track Sector Buffer | Holds (tracks_per_buffer × 10 × 256) bytes of sector data | Sector read loop (4275H) | Sector write loop (42FAH) |
MESSAGE STRINGS (Read-Only except for digit placeholders)
| Address | Size | Name/Purpose | Values/Format | Set By | Used By |
|---|---|---|---|---|---|
| Relocated: 458BH-45A9H Original: 5926H-5944H | 31 | "COPYING" Message | 1DH + "COPYING TRACK nn, SECTOR nn" + 03H | Constant | 42E9H (display during write) |
| Relocated: 45AAH-45C7H Original: 5945H-5962H | 30 | "VERIFYING" Message | "VERIFYING TRACK nn, SECTOR nn" + 03H | Constant | 4321H (display during verify) |
| Relocated: 45C8H-45E7H Original: 5963H-5982H | 32 | "LOADING" Message | 1DH + "LOADING TRACK nn, SECTOR nn" + 03H | Constant | 426FH (display during read) |
| Relocated: 45E8H-4600H Original: 5983H-599BH | 25 | "SOURCE DISK READ ERROR!" | 0AH + message + 0DH | Constant | 4455H (error handler) |
| Relocated: 4601H-461EH Original: 599CH-59B9H | 30 | "DESTINATION DISK READ ERROR!" | 0AH + message + 0DH | Constant | 44D5H (error handler) |
| Relocated: 461FH-463DH Original: 59BAH-59D8H | 31 | "DESTINATION DISK WRITE ERROR!" | 0AH + message + 0DH | Constant | Write error handler |
| Relocated: 463EH-4663H Original: 59D9H-59FEH | 38 | "DESTINATION DISK IS WRITE PROTECTED!" | 0AH + message + 0DH | Constant | 44AAH (write protect check) |
| Relocated: 4664H-4682H Original: 59FFH-5A1DH | 31 | "INSERT SOURCE DISK" Prompt | 1DH + "INSERT SOURCE DISK (ENTER)" + 1DH + 03H | Constant | 442AH (source prompt) |
| Relocated: 4683H-46A6H Original: 5A1EH-5A41H | 36 | "INSERT DESTINATION DISK" Prompt | 1DH + "INSERT DESTINATION DISK (ENTER)" + 1DH + 03H | Constant | 44A1H (dest prompt) |
| Relocated: 46A7H-46DDH Original: 5A42H-5A78H | 55 | "WAKE UP!!!" Error Message | 1DH + "WAKE UP!!! THAT'S NOT THE SAME SOURCE DISK!" + 0DH | Constant | 448DH (wrong disk error) |
| Relocated: 46DEH-46EEH Original: 5A79H-5A89H | 17 | "BACKUP COMPLETE" Message | Message + 0DH | Constant | Finish routine |
| Relocated: 46EFH-4708H Original: 5A8AH-5AA3H | 26 | "HIT 'ENTER' TO CONTINUE" | Message + 03H | Constant | 43A3H (error handler wait) |
GAT Sector Structure (Track 0, Sector 0)
| Offset | Size | Contents | Description |
|---|---|---|---|
| +00H | 35 | Track Allocation Table | 2 bits per granule × 5 granules/track × 35 tracks. Each byte covers one track's 5 granules. |
| +02H | 1 | Directory Track Number | Usually 11H (17). Location of directory/HIT. |
| +23H | 61 | (Reserved/Unused) | Padding to offset 60H. |
| +60H | 35 | Track Lockout Table | One byte per track. Bit=1 means that granule is locked out (bad). |
| +83H | 75 | (Reserved/Unused) | Padding to offset CEH. |
| +CEH | 10 | Pack ID | Disk identification string. Compared to verify correct source disk. |
| +D8H | 40 | (Reserved/Date/etc.) | May contain backup date, password hash, etc. |