Program Overview
SYS7 is the TRSDOS v1.3 overlay that runs the FORMAT and BACKUP commands on the TRS-80 Model III (the source's TITLE: SYSTEM 7 - FORMAT & BACKUP). The file loads 4E00H–5D71H (3944 bytes, transfer address 57A1H). Above it SYS7 uses 5E00H–61FFH for its buffers and the main buffer from 6200H up to the end of memory; none of these is in the file. SYS7 is assembled as the customer version of the source (CUST true), so the factory serial number code of the source is not in it.
SYS1 reaches SYS7 through two DOS vectors: FORMAT through 429FH (LD A,A7H / RST 28H, entry 2) and BACKUP through 42A2H (LD A,97H / RST 28H, entry 1). SYSLD loads the overlay and jumps to BEGIN (57A1H) with the request code in Register A and HL at the command line after the command name. BEGIN marks SYS6 as no longer resident (bit 4 of OVLFLG, 442BH), sets CFLAG (42B4H) to 55H so SYS1 clears the user memory at the next TRSDOS Ready, lowers the read and write retry counts of SYS0 (TRY1 467DH, TRY2 460AH) from 9 to 2, and goes to FRMAT (5762H) or BACKP (5739H). Both end through EXIT (4E50H), which returns to TRSDOS Ready through 402DH; a disk error goes to FATAL (4E00H), which shows the error through SYS4 (4409H).
FORMAT (FORMAT :d): FRMAT clears the screen and shows the title, takes the date from the ROM, the drive from the command line (:d) or a prompt, the diskette name and the master password (as its trap door code, TRAP at 57C3H), and looks at the diskette with CHKFOR (a diskette with files asks 'Diskette contains DATA. Use Disk or not?'; N returns to TRSDOS Ready). It puts the name, the date and the password code into the new GAT at 6100H and calls FOMAT (5803H). FOMAT restores the head to track 0 and calls FORM (5CBDH), which formats the 40 tracks one by one: TRKIMG (5C1FH) builds the 7010 byte image of the track at 6200H from the track building table (5BB5H–5C1EH: 18 sectors of 256 bytes in the order 1, 4, 7, ... 18, each filled with 240 E5H bytes and the text '(c) 1980 Tandy '), TRKWRT (5AB0H) writes it with the FDC's Write Track command, and VERFIT (5AEEH) reads the 18 sectors back. A track that fails 4 tries is marked FFH in the flaw table of the new GAT (offset 60H). From track 22 on, the drive select byte has the write precompensation bit set. Then BOTWRI (5A53H) writes the boot sector (5853H–5952H) to track 0, sector 1, the 'Not a SYSTEM Disk' load module (5953H–5A52H) to sector 2, the GAT to track 17, sector 1, and an empty HIT and empty directory sectors to sectors 2–18.
BACKUP (BACKUP :s :d): BACKP shows the title, takes the date, the source and destination drives (the command line or prompts) and the master password of the source, and calls BPREP (5560H). BPREP reads the HIT of the source (a source without SYS0 involving drive 0 makes SYS7 ask for a system diskette at the end), reads the GAT of the source and compares its master password code (offset CEH) with the code typed. DOLLAR (5518H) then looks at the destination with CHKFOR (it is formatted with FOMAT when it cannot be read, or when the operator answers Y to 'Do you wish to RE-FORMAT the diskette?'), reads both GATs with DGAT (54B9H, which aborts when a track holding data on the source is flawed on the destination), and copies the grans in use: MREAD (5438H) fills the main buffer with gran records (2 bytes sector and track, then the 768 bytes of the gran) as long as they fit below MEMTOP, MWRIT (53D3H) writes and verifies them, and this goes on until the source has no gran left. Last, the directory track of the source is read into the buffer (RDIR, 52B4H), given the flaw table of the destination, the allocation bytes and today's date, and written to the destination (WDIR, 52F2H). With the source and destination on one drive, the operator is asked to change the diskettes (CKSRC 5492H, CKDES 54A5H).
The backup counter. Byte 22H of every boot sector SYS7 writes (CNT1, 5875H) is a backup counter, FFH for no limit. When BACKUP reads the boot sector of the source (RBOOT, 5257H) with a counter of 1–FEH, it lowers the counter on the source; the copy gets 00H. When the counter is 00H, CXFLAG (4E85H) is set and RDIR takes every file whose attribute byte has bit 5 set out of the copy (EXMGRN 5312H, DEALOC 5351H, RELEAS 537CH): its grans are released in the GAT, its directory record and its HIT byte are cleared, and EXIT shows the two messages coded at 50DFH ('Maximum Backup Count Exceeded', 'Protected Files NOT Backed Up').
Release file and source. The bytes on this page are those of the release SYS7 in S:\1, with one exception: the release file carries a zap (on the zaps page, part of the upgrade to the Wed. July 1, 1981 version) at 5135H–5140H and 579CH–579DH. It shortens the text REFORM to 'Do you wish to RE-FORMAT? ' and puts LD A,(4E7DH) / CP 81H / JP Z,550DH / RET at 5138H, and FRMAT calls 5138H instead of CKSYS (579BH), so that formatting drive 0 asks for a system diskette. This page shows the source code there, as the source has it; the rows name the release bytes. The shipped code also has 7 instructions at 5814H–5823H (a wait for the index pulse after the Restore) that the source text in S:\2 does not have; they are documented from the bytes.
Code assembled for other addresses. The boot sector at 5853H–5952H is assembled to run at 4300H (SETLOC BUFF1), where the ROM loads it, and the NOSYS load module at 5957H–5975H to run at 4D00H (SETLOC BUFF2). The absolute addresses in their instructions (CALL 433EH, LD (43EAH),HL and so on) are run addresses; the rows show the addresses in this file, the links of their CALLs and JPs go to the rows in this file, and each comment gives both addresses. Their relative jumps are shown with the address in this file.
Memory Map
| Range | Label | Contents |
|---|---|---|
| 4E00H–4E7BH | FATAL, N12, RESTRY, ABRT, EXIT, CLRBUF | The error exit, the exits and their helpers. |
| 4E7CH–4EAAH | SDFLAG ... NAMBUF | Variables (NAMBUF, 4EA1H–4EAAH, is not in the file). |
| 4EABH–516DH | READM ... FDD | Screen messages, the two coded GEORGE messages (50DFH) and the source and destination drive message (5145H). |
| 516EH–5257H | SPRINT, RNEXT, RGRAN, WGRAN, VGRAN, FUNCTA–FUNCTC, GREAD, OUTHEX, BUMP, GBUMP | Decoding of the coded messages, gran and sector I/O with the 'Reading / Writing / Verifying Track nn, Sector nn' line. |
| 5257H–53B9H | RBOOT, RDIR, WDIR, EXMGRN, DEALOC, RELEAS, CLRBIT | The boot sector and the backup counter, the directory track, taking protected files out of a copy. |
| 53BAH–5464H | MEMCHK, MWRIT, FALOC, MREAD | The main buffer of BACKUP: finding the grans in use, reading and writing them. |
| 5465H–5517H | FWAIT, LINOFF, CKSRC, CKDES, DGAT, CKSYS | The flashing prompts, the diskette changes, the two GATs. |
| 5518H–5713H | DOLLAR, BPREP, GETSRC, GETDES, GETFOR, INPUT, GETPSF, GETPSB, GETNAM, GETDAT, CLRGAT, SETDAT, CHKFOR | The backup loop, the questions to the operator and the look at the destination diskette. |
| 5714H–57C2H | DOTITL, COMON, BACKP, FRMAT, BEGIN | The two commands and the entry point. |
| 57C3H–5802H | TRAP | The trap door code of a password. |
| 5803H–5852H | FOMAT | The formatter's entry. |
| 5853H–5952H | BOOT / ENT | The boot sector written to track 0, sector 1 (runs at 4300H–43FFH). |
| 5953H–5A52H | SYST / NOSYS | The sector written to track 0, sector 2: the 'Not a SYSTEM Disk' load module (runs at 4D00H). |
| 5A53H–5B6CH | BOTWRI, TRKWRT, VERFIT, STEPR, ASCII, PDATA | Writing the system sectors, writing and verifying a track, stepping the head. |
| 5B6DH–5BB4H | WRTDIR, VERMSG, FORMSG | The messages of the formatter. |
| 5BB5H–5C1EH | TRKNN, DDST, DDTAB ... DDTRL, SECTAB, CSECTB | The track building table and the sector order. |
| 5C1FH–5D71H | TRKIMG, TBLBMP, EXPAND, FORM, FLAWX | Building the track image and formatting the diskette. |
| 5E00H–5EFFH | SPAR_ | Copy of the boot sector of the source (RBOOT). Not in the file. |
| 5F00H–5FFFH | DUM1 | The empty HIT and directory sector FORM builds for BOTWRI. Not in the file. |
| 6000H–60FFH | SGAT | Copy of the allocation bytes of the source GAT that FALOC clears gran by gran. Not in the file. |
| 6100H–61FFH | FGAT, FLAWD | The GAT being built: the new GAT of FORMAT, or the source GAT with the destination's flaw table for BACKUP (FLAWD = 6160H, offset 60H). Not in the file. |
| 6200H up | BUFF | The main buffer: the track image of FORM (6200H–7D61H), the gran records of BACKUP (770 bytes each, up to MEMTOP), the directory track (6 gran records, 6200H–7413H). Not in the file. |
Variables and Self Modified Operands
| Address | Label | What it holds |
|---|---|---|
| 4E7CH 1 byte | SDFLAG | Which diskette is in for a backup on one drive: 00H the source, FFH the destination. |
| 4E7DH 1 byte | FDRIVE | Drive select byte for the formatter: the drive's bit, 80H (double density), and bit 5 (precompensation) while FORM is on tracks 22 and up. |
| 4E7EH 1 byte | FDRIVS | Source drive number of BACKUP. |
| 4E7FH 1 byte | FDRIVD | Destination drive number of BACKUP, and the drive FORMAT formats (01H in the file). |
| 4E80H 1 byte | FLAWC | Number of flawed tracks FORM found. |
| 4E81H 1 byte | BSIDES | Side of the source (00H; not changed by SYS7). |
| 4E82H 1 byte | BSIDED | Side of the destination (00H; not changed by SYS7). |
| 4E83H 1 byte | FLAG | State of the flashing prompt (bit 0). |
| 4E84H 1 byte | CLFN | Number of the directory record EXMGRN is looking at (0-79). |
| 4E85H 1 byte | CXFLAG | FFH when the backup counter of the source was at 0. |
| 4E86H 1 byte | CCFLAG | Not zero when a protected file was taken out of the copy. |
| 4E87H 1 byte | SINGLE | Destination drive minus source drive: 00H = backup on one drive. |
| 4E88H 2 bytes | PTRAP | Trap door code of the master password typed (8FD3H in the file). |
| 4E8AH 2 bytes | CSAVE | Command line pointer. |
| 4E8CH 2 bytes | BUFPNT | Address of the gran record MREAD or MWRIT is on (6200H in the file). |
| 4E8EH 2 bytes | MEMTOP | MEMEND minus 768: the highest address a gran record may start at. |
| 4E90H 8 bytes | DATBUF | Today's date, MM/DD/YY. |
| 4E98H 9 bytes | NAMEBF | Diskette name ('TRSDOS' and spaces in the file); 8 bytes are used. |
| 4EA1H 10 bytes | NAMBUF | Input buffer of INPUT (not in the file). |
| 4ED3H 2 bytes | FTRACK | Track digits of the 'Track nn, Sector nn' line. |
| 4EDEH 2 bytes | SEC | Sector digits of the same line. |
| 5152H 1 byte | FDS | Source drive digit of FDSMSG. |
| 516BH 1 byte | FDD | Destination drive digit of FDSMSG. |
| 51C5H 2 bytes | VER | Operand of LD DE at 51C4H: the track and first sector of the gran WGRAN wrote, for VGRAN. |
| 53B8H 1 byte | CLRBT2 | Second byte of the RES n,B at 53B7H, built by CLRBIT. |
| 550AH 1 byte | DATDSK | Operand of LD A at 5509H: FFH = ask for a system diskette at the end (SETDAT). |
| 5836H 1 byte | BCKFLG | Operand of LD A at 5835H: 0FH when BACKUP formats the destination (DOLLAR), 00H for FORMAT. |
| 5875H 1 byte | CNT1 | Backup counter of the boot sector written (FFH, no limit; 4322H when it runs). |
| 593DH 2 bytes | TRKSAV | Boot sector: the track and sector it reads next (43EAH when it runs). |
| 593FH 1 byte | EOFBYT | Boot sector: the offset of the next byte in the sector buffer 4D00H (43ECH when it runs). |
| 5B1BH 1 byte | FSVSEC | Operand of LD E at 5B1AH: the sector VERFIT reads. |
| 5B9AH 2 bytes | VERASC | Sector digits of 'Verifying sector nn'. |
| 5BAFH 2 bytes | FORASC | Track digits of 'Formatting track nn'. |
| 5BD3H 1 byte | DDTRK | Track number of the ID fields of the track image. |
| 5BD6H 1 byte | DDSID | Side number of the ID fields (00H; not changed by SYS7). |
| 5BD9H 1 byte | DDSEC | Sector number of the ID field being built. |
| 5C1DH 2 bytes | CSECTB | Pointer to the next entry of SECTAB. |
| 5C4DH 1 byte | SAVEA | Operand of LD A at 5C4CH: the track number TRKIMG is building. |
| 5CBCH 1 byte | WORK | Register A saved by EXPAND. |
| 5D61H 2 bytes | FLAWX | Digits of 'nn Flawed Tracks'. |
Major Routine List
| Address | Label | Description / Purpose |
|---|---|---|
| 4E00H | FATAL | Error exit, A = the error code: when CXFLAG is set, write 4100H-41FFH to the boot sector of the source (see the note on that row); clear SPAR_, reset the retry counts, then JP 4409H (ERROR) with bit 6 of the code set. |
| 4E35H | N12 | 'Cannot Backup Version 1.1. Diskette', then ABORT (4030H). |
| 4E41H | RESTRY | TRY1 and TRY2 back to 9. |
| 4E4AH | ABRT | 'Operation ABORTED due to flaws on diskette', then EXIT. |
| 4E50H | EXIT | The GEORGE messages when protected files were taken out, then CLRBUF and JP 402DH. |
| 4E6EH | CLRBUF | Clear 5E00H-5EFFH. |
| 516EH | SPRINT | Show a message coded with XOR 55H (count byte first). |
| 517AH / 517DH | RNEXT / RGRAN | Read a gran of the source into a gran record (D = track, E = sector; HL = the record, or BUFPNT for RNEXT). |
| 519AH | WGRAN | Write the gran record at HL to the destination. |
| 51BBH | VGRAN | Read back the gran WGRAN wrote. |
| 51D8H / 51E2H / 51ECH | FUNCTA / FUNCTB / FUNCTC | XREAD, XWRITE or XREAD with the Reading, Writing or Verifying line, through GREAD (51F4H). |
| 522CH | OUTHEX | A (0-99) as two decimal digits at HL. |
| 5238H / 5240H | BUMP / GBUMP | Next sector (E+1, HL+256) / next gran (E+3, next record). |
| 5257H | RBOOT | Read the boot gran of the source and handle the backup counter. |
| 52B4H / 52F2H | RDIR / WDIR | Read the directory track of the source / write it to the destination. |
| 5312H / 5351H / 537CH / 53ADH | EXMGRN / DEALOC / RELEAS / CLRBIT | Take the files with bit 5 of the attribute byte set out of the copy. |
| 53BAH | MEMCHK | Next gran record; CARRY when the buffer is full. |
| 53D3H / 5438H | MWRIT / MREAD | Write the buffer / fill the buffer. |
| 53FAH | FALOC | Next gran in use on the source (D = track, E = sector), CARRY at the end. |
| 5465H / 5488H | FWAIT / LINOFF | Flash a prompt until ENTER / erase the line. |
| 5492H / 54A5H / 5509H | CKSRC / CKDES / CKSYS | Ask for the source, destination or system diskette when needed. |
| 54B9H | DGAT | Read and check both GATs. |
| 5518H | DOLLAR | The backup itself. |
| 5560H | BPREP | Check the source and its master password, then DOLLAR. |
| 55CCH / 55F4H / 5626H | GETSRC / GETDES / GETFOR | The drives. |
| 5645H | INPUT | Show a prompt and read an answer into NAMBUF. |
| 5652H / 5657H | GETPSF / GETPSB | The master password (FORMAT / BACKUP). |
| 5666H / 568CH | GETNAM / GETDAT | The diskette name / the date. |
| 5693H / 56ABH | CLRGAT / SETDAT | Clear the GAT copies / ask for a system diskette at the end. |
| 56B1H | CHKFOR | Look at the destination: NZ = format it. |
| 5714H / 5728H | DOTITL / COMON | The title / the common start of both commands. |
| 5739H / 5762H | BACKP / FRMAT | BACKUP / FORMAT. |
| 57A1H | BEGIN | Entry point: A7H FORMAT, 97H BACKUP. |
| 57C3H | TRAP | Trap door code of a password (HL, B characters) into HL. |
| 5803H | FOMAT | Restore, FORM, Restore, BOTWRI. |
| 5853H | BOOT / ENT | The boot sector (runs at 4300H). |
| 5957H | NOSYS | 'Not a SYSTEM Disk' (runs at 4D00H). |
| 5A53H | BOTWRI | Write the system sectors of a new diskette. |
| 5AB0H / 5AEEH | TRKWRT / VERFIT | Write the track image / read back its 18 sectors. |
| 5B35H | STEPR | Step in one track and update SEKTRK. |
| 5B55H / 5B67H | ASCII / PDATA | A as two decimal digits at HL / show text, keeping DE (not called). |
| 5C1FH / 5C7BH / 5C8CH | TRKIMG / TBLBMP / EXPAND | Build the track image from the track building table. |
| 5CBDH | FORM | Format and verify the 40 tracks. |
Notes
- FATAL and 4100H. When an error ends a backup whose source counter was at 0, FATAL asks for the source diskette and writes the 256 bytes at 4100H-41FFH to its boot sector (the source comment: write out old counter). RBOOT keeps its copy of the source boot sector at 5E00H, and no code in SYS7 writes to 4100H-41FFH.
- The formatter's step. FORM tests the NZ FLAG after CALL NZ,STEPR (5CE8H, JP NZ,ABRT); STEPR always returns with the Z FLAG set, so that jump is never taken.
- Tracks 40 and above. GREAD (5202H) and TRKIMG (5C4EH) add 80H to the sector number on tracks 40 and above (the source calls such a track the secret track); a diskette formatted by SYS7 has tracks 0-39 only.