SYS10/SYS is the overlay the source calls SYSTEM 10 - DIRECTORY FOR BASIC. It has two jobs: the short directory display $DSPDIR (4419H, used by Disk BASIC's CMD"D:d") and the texts of BASIC's error messages for Disk BASIC.
TRS-80 DOS - TRSDOS v1.3 - SYS10/SYS Disassembled
General:
Program Overview
SYS10 loads at 4E00H-51D1H (978 bytes in four load records, transfer address 4E00H). SYSLD (4B82H) runs it through RST 28H with the request code in Register A and the caller's BC, DE and HL kept. START masks the code to bits 7-4 and picks one of two entries:
Entry 0, request 8AH: DODIR, the directory display. $DSPDIR at 4419H in SYS0 is LD A,8AH / RST 28H. The caller stores the drive as an ASCII digit ('0'-'3') in D10SAV (4271H); Disk BASIC's CMD"D:d" stores the character after the colon there and calls 4419H. DODIR clears OVLFLG (SYS6 is no longer resident), keeps bits 1-0 of D10SAV as the drive number, clears the screen, turns the cursor on and checks the drive against MAXDRV (4413H); a drive above it gives error 2 (Disk Drive Not in System) through ERROR with bits 6 and 7 set, so SYS4 shows the full text and returns to the caller. It then shows 'DRIVE :n' in the first 15 character column, reads sectors 2-18 of the directory track into 4300H one at a time through XREAD (4675H), and shows the name of each record whose attribute byte is not 00H and has neither bit 6 (system file) nor bit 3 (invisible file) set, as NAME/EXT padded to 15 characters, four columns to a line. A read error goes to ERROR with bits 6 and 7 set. The last 0DH is shown through a JUMP to 0033H, whose RET returns to the caller; all registers are changed.
Entry 1, request 9AH: DOERR, the BASIC error messages. SYSS10 at 427BH in SYS0 is LD A,9AH / RST 28H, and Disk BASIC puts JP 427BH into the ROM's error vector at 41A6H. The ROM's error routine calls 41A6H (at 19ECH) with Register E = BASIC's error code (twice the error number minus 2). DOERR turns the code into the number of a message in ERRTAB: errors 1-24 are messages 1-24, the disk errors 51-70 (codes 64H-8AH) are messages 25-44, and every other code gives message 20, 'Unprintable error'. It finds the message by counting the 00H bytes of the table and jumps to the ROM's 1A01H with Register Pair HL pointing to the text, which the ROM shows in place of its two letter code and ' Error', followed by the line number and READY.
Two faults in the shipped code. DIRLOP calls TRKGET (4B3EH) without loading Register C, so the directory track comes from the DIRTRK entry of whatever drive number Register C held when the caller ran 4419H (the source, SYS10.SRC, has an LD C,A that the file does not have). And DIRLO1 starts at sector 2, which is the HIT, so the five 48 byte pieces of the HIT are looked at as directory records before sectors 3-18. The zaps page has the patches for both (SYS10 at 4E2EH with 508AH, or 4E2AH, and 4E47H).
Memory Map
| Address Range | Label | Contents |
|---|---|---|
| 4E00H-4E06H | START | Entry point: mask the request code in Register A and go to DOERR (90H) or fall into DODIR (80H) |
| 4E07H-4E29H | DODIR, DIRGET | Clear OVLFLG, take the drive from D10SAV, clear the screen, turn the cursor on, check the drive against MAXDRV |
| 4E2AH-4E63H | DIRLOP, DIRLO1, DIRLO2 | Get the directory track (TRKGET), show 'DRIVE :n', read each sector 2-18 of the directory track into 4300H (XREAD) |
| 4E64H-4ED9H | NOERR, LOOP0, LOOP1, OUT0, OUT00, OUT1, LOOP2, OUT2, LOOP3, NXTNAM, TOTNXT | Show each visible user file of the sector as NAME/EXT in a 15 character column, four columns to a line; end with 0DH through 0033H |
| 4EDAH-4EEFH | DRIVE, TRK, DRVMSG, DRV, SAVE3, S10SEC, NUM | Variables and the heading text 'DRIVE :0' with seven spaces and 03H |
| 4EF0H-4F10H | DOERR, START1, START2, START3, START4 | Turn BASIC's error code in Register E into a message number, find the message in ERRTAB and jump to the ROM's 1A01H |
| 4F11H-51D1H | ERRTAB | 00H, then 44 error messages, each ending with 00H |
Complete Variable List
| Address | Label | Description |
|---|---|---|
| 4271H 1 byte | D10SAV | In SYS0: the drive for $DSPDIR as an ASCII digit, stored by the caller (Disk BASIC's CMD"D:d" stores the character after the colon). DODIR (4E0BH) keeps bits 1-0. |
| 442BH 1 byte | OVLFLG | In SYS0: the overlay flag byte. DODIR (4E08H) stores 00H, clearing bit 4 (SYS6 resident) and bit 7 (load only). |
| 4413H 1 byte | MAXDRV | In SYS0: the highest drive number in the system. DODIR (4E1FH) refuses a drive above it with error 2. |
| 4300H-43FFH 256 bytes | BUFF1 | In SYS0: the first disk buffer. XREAD puts each directory sector here; LOOP0 looks at its records at 4300H, 4330H, 4360H, 4390H and 43C0H. |
| 4E56H 1 byte | SAVTRK | The operand of LD D,00H at 4E55H (the source's SAVTRK EQU $+1): the directory track, stored by 4E32H from TRKGET's Register D and used as the track for XREAD. 00H in the file. |
| 4EDAH 1 byte | DRIVE | The drive number 0-3 being shown, stored by DIRGET (4E10H) and read at 4E1BH, 4E2AH and 4E51H. 00H in the file. |
| 4EDBH 1 byte | TRK | No instruction reads or writes it. 00H in the file. |
| 4EDCH-4EEBH 16 bytes | DRVMSG | 'DRIVE :0' with seven spaces (15 characters, the width of a column) and 03H, shown by PRINT (021BH) at 4E43H without a new line. |
| 4EE3H 1 byte | DRV | The drive digit in DRVMSG ('0' in the file), stored by 4E38H. |
| 4EECH-4EEDH 2 bytes | SAVE3 | The address of the directory record being looked at (4300H in the file), set by NOERR (4E67H) and moved on by 30H at TOTNXT (4EC6H). |
| 4EEEH 1 byte | S10SEC | The number of the next directory sector to read: 02H from DIRLO1 (4E48H), counted up by DIRLO2 (4E4FH) to 13H (19), where the display ends. 00H in the file. |
| 4EEFH 1 byte | NUM | The count of 15 character columns used on the current line: 01H after the heading (4E3DH), then counted up after each name; at 4 a 0DH is shown and it becomes 00H (4EBCH). 00H in the file. |
| 4F11H-51D1H 705 bytes | ERRTAB | 00H, then the 44 error messages, each ending with 00H; START4 (4F07H) counts the 00H bytes to find a message. |
| 41A6H 3 bytes | The ROM's error vector: Disk BASIC stores JP 427BH there, so the ROM's error routine (19ECH) reaches DOERR through SYSS10. |
Major Routine List
| Address | Label | Description / Entry-Exit |
|---|---|---|
| 4E00H | START | In: Register A = request code 8AH ($DSPDIR, 4419H) or 9AH (SYSS10, 427BH); BC, DE and HL as the caller had them. Goes to DOERR for 9AH, falls into DODIR for 8AH. |
| 4E07H | DODIR | $DSPDIR. In: (4271H) = ASCII drive digit. Shows the visible user files of the drive. Out: returns to the caller through 0033H with all registers changed, or through ERROR (bit 7 set) with error 2 or a read error. |
| 4E2AH | DIRLOP | Gets the directory track through TRKGET (4B3EH) into SAVTRK and shows 'DRIVE :n'. |
| 4E46H | DIRLO1 | Sets S10SEC to 2. |
| 4E4BH | DIRLO2 | Reads sector S10SEC of the directory track into 4300H through XREAD (4675H) and counts S10SEC up. |
| 4E64H | NOERR | Points SAVE3 to the first record of the sector. |
| 4E6AH | LOOP0 | Skips a record whose attribute byte is 00H or has bit 6 or bit 3 set; otherwise shows the name. |
| 4E7DH | LOOP1 | Shows the name, up to 8 characters, stopping at a space. |
| 4E89H | OUT0, OUT00 | Steps Register Pair HL to the extension at record offset 0DH. |
| 4E91H | OUT1, LOOP2 | Shows '/' and the 3 characters of the extension when its first character is not a space. |
| 4EA6H | OUT2, LOOP3 | Fills the column to 15 characters with spaces; after the fourth column of a line shows 0DH. |
| 4EBFH | TOTNXT | Moves SAVE3 to the next record (30H on); after five records reads the next sector, after sector 18 shows 0DH and returns. |
| 4EF0H | DOERR | In: Register E = BASIC's error code. Works out the message number (START1, START2, START3), finds the message (START4) and jumps to the ROM's 1A01H with Register Pair HL = the message. Does not return. |
| 4F11H | ERRTAB | The table of the 44 messages. |
Cross-references and Analysis Notes
Callers. $DSPDIR (4419H in SYS0, LD A,8AH / RST 28H) runs entry 0; the manual gives its entry condition as (X'4271') = ASCII-coded drive number '0', '1', '2' or '3' and its exit condition as all registers changed. SYSS10 (427BH in SYS0, LD A,9AH / RST 28H) runs entry 1, reached from the ROM's error vector 41A6H.
Source and file. The release file and the file assembled in the source tree (S:\2\SYS10) load the same 978 bytes. SYS10.SRC is a later version: it has LD C,A ;INTO C ALSO after the PUSH AF in DIRLOP, which the file does not have, so every address of the file after 4E2DH is one lower than that source assembles to. The page shows the file's bytes; the labels and comments come from SYS10.SRC.
Message numbers. Message n of ERRTAB is shown for error n (code 2n-2) when n is 1-24, and for error n+26 (code 2n+50) when n is 25-44; message 20 is also shown for errors 25-50 and for codes 8BH and up. The messages '?' (31, 34 and 35) belong to errors 57, 60 and 61. The manual lists the disk errors as 51 Field overflow, 52 Internal error, 53 Bad file number, 54 File not found, 55 Bad file mode, 58 Disk I/O error, 62 Disk full, 63 Input past end, 64 Bad record number, 65 Bad file name, 67 Direct statement in file, 68 Too many files, 69 Disk write-protect and 70 File access.
Zaps. The zaps page patches of SYS10 link into this page at 4E2AH (LD A,(4EDAH) becomes LD A,B / LD C,A / NOP), 4E2EH (CALL 4B3EH to CALL 508AH), 4E47H (the 02H of LD A,02H to 03H) and 508AH (the first four bytes of 'Disk Basic Feature' to LD C,A / JP 4B3EH).
Disassembly:
4E00H - START - Entry point: pick the directory display (request 8AH) or the BASIC error message (request 9AH)
Original Source Code Comment: MASK SYSTEM NUMBER
Original Source Code Comment: ERROR MESSAGES?
Original Source Code Comment: YES
4E07H - DODIR - Entry 0, $DSPDIR: take the drive from D10SAV, clear the screen and check the drive
Original Source Code Comment: SHOW SYS 6 NOT IN MEMORY
Original Source Code Comment: GET THE DRIVE NUMBER
Original Source Code Comment: MASK ALL BUT DRIVE
Original Source Code Comment: SAVE THE DRIVE NUMBER
Original Source Code Comment: CLEAR SCREEN
Original Source Code Comment: CURSOR ON CHAR
Original Source Code Comment: TURN CURSOR BACK ON
Original Source Code Comment: GET THE DRIVE NUMBER
Original Source Code Comment: INTO (B)
Original Source Code Comment: GET THE MAXIMUM DRIVE IN SYSTEM
Original Source Code Comment: WE TRYING FOR A NON-EXISTANT DRIVE?
Original Source Code Comment: NO, CONTINUE
Original Source Code Comment: DRIVE NOT IN SYSTEM ERROR
Original Source Code Comment: REPORT AND RETURN
4E2AH - DIRLOP - Get the directory track, show the heading, then read each sector 2-18 of the directory track into 4300H
Original Source Code Comment: GET BINARY DRIVE
Original Source Code Comment: SAVE IT
Original Source Code Comment: GET THE DIRECTORY S10SEC FOR THIS DRIVE
Original Source Code Comment: GET IT
Original Source Code Comment: SAVE THE TRACK NUMBER
Original Source Code Comment: MAKE IT ASCII
Original Source Code Comment: STORE IN DRIVE MESSAGE
Original Source Code Comment: POINT TO DRIVE # MSG
Original Source Code Comment: PRINT IT
Original Source Code Comment: SET FOR SECTOR 2
Original Source Code Comment: STORE FOR USE
Original Source Code Comment: POINT TO TRACK
Original Source Code Comment: GET SEC NUM
Original Source Code Comment: SET FOR NEXT SEC, NXT LOOP
Original Source Code Comment: PUT IN E FOR CALL
Original Source Code Comment: GET PRESENT DRIVE
Original Source Code Comment: PUT IN C FOR CALL
Original Source Code Comment: DIRECTORY TRACK SAVED HERE
Original Source Code Comment: WHERE TO STORE IT
Original Source Code Comment: READ DIR TRACK IN MEM
Original Source Code Comment: GOOD READ
Original Source Code Comment: SET DETAIL MESSAGE BIT ON
Original Source Code Comment: REPORT ERROR AND EXIT
4E64H - NOERR - Show the name of every visible user file in the sector at 4300H, four columns of 15 characters to a line
Original Source Code Comment: POINT TO BUFFER
Original Source Code Comment: SAVE IT
Original Source Code Comment: GET POINTER
Original Source Code Comment: GET CHARACTER FROM DIR
Original Source Code Comment: BLANK FILE?
Original Source Code Comment: YES
Original Source Code Comment: SYSTEM OR INVISIBLE FILE?
Original Source Code Comment: SKIP IF SO
Original Source Code Comment: MAX LENGTH OF NAME
Original Source Code Comment: NAME/EXT+SPACES
The next 3 instructions add 05H to Register L, so HL points to the name at record offset 05H.
Original Source Code Comment: GET LSB INTO A
Original Source Code Comment: SET FOR BEGIN OF NAME
Original Source Code Comment: PUT BACK FOR ADDRESS
Original Source Code Comment: GET A CHARACTER FROM NAME
Original Source Code Comment: SPACE?
Original Source Code Comment: DONE IF SO
Original Source Code Comment: PRINT OTHERWISE
Original Source Code Comment: DEC TOTAL COUNTER
Original Source Code Comment: PRINT ALL OF NAME
Original Source Code Comment: GET COUNT
Original Source Code Comment: SET FLAGS
Original Source Code Comment: NOTHING TO DO
Original Source Code Comment: BACK POINT UP ONE
At this point Register Pair HL points to the extension of the record (offset 0DH).
Original Source Code Comment: NOW AT EXT
Original Source Code Comment: ANY EXT?
Original Source Code Comment: IF NOT, SKIP
Original Source Code Comment: PRINT A SEPERATOR
Original Source Code Comment: DEC TOTAL COUNTER
Original Source Code Comment: 3 CHARS IN EXT
Original Source Code Comment: GET A CHAR OF EXT
Original Source Code Comment: POINT TO NEXT
Original Source Code Comment: PRINT IT
Original Source Code Comment: DEC TOTAL COUNTER
Original Source Code Comment: PRINT ALL OF EXT
Original Source Code Comment: GET TOTAL NUMBER
Original Source Code Comment: OUTPUT SPACES
Original Source Code Comment: GET HOW MANY THIS LINE
Original Source Code Comment: ADD ONE TO IT
Original Source Code Comment: 3 NAMES ON SCREEN?
Original Source Code Comment: IF NOT, KEEP GOING THIS LINE
The fourth column of this line is used: end the line and start the count again.
Original Source Code Comment: OUT A CR FOR NEXT LINE
Original Source Code Comment: CLEAR NUMBER COUNTER
Original Source Code Comment: SAVE COUNTER
4EBFH - TOTNXT - Go on to the next record, the next sector, or end the display
Original Source Code Comment: GET BUFFER POINTER
The next 3 instructions add 30H to Register L, so HL points to the next record.
Original Source Code Comment: PUT LSB INTO A
Original Source Code Comment: POINT TO NEXT NAME
Original Source Code Comment: PUT BACK FOR ADDRESS
Original Source Code Comment: PUT ADJUSTED BACK
Original Source Code Comment: WE AT END OF THIS SECTOR?
Original Source Code Comment: NEXT NAME IF NOT DONE
All five records of this sector have been looked at: go on to the next sector.
Original Source Code Comment: GET PRESENT TRACK
Original Source Code Comment: ALL DIR TRACKS YET?
Original Source Code Comment: IF NOT, KEEP GOING
Original Source Code Comment: NEW LINE PLEASE
Original Source Code Comment: DISPLAY AND EXIT
4EDAH - DRIVE - Variables and the heading text DRVMSG
4EF0H - DOERR - Entry 1: find the text for BASIC's error code in Register E and show it through the ROM's error routine
Original Source Code Comment: HIGHER THAN ALLOWABLE ERROR?
Original Source Code Comment: YES, FORCE TO 'UNPRINTABLE' ERROR
Original Source Code Comment: DISK ERROR?
Original Source Code Comment: YES, DO IT
Codes 2FH-62H (errors 25-50) fall through into START1 and get the Unprintable error message.
Original Source Code Comment: FORCE TO 'UNPRINTABLE' ERROR
Original Source Code Comment: HL => TABLE
At this point Register B holds the message number: START4 passes that many 00H bytes of ERRTAB.
Original Source Code Comment: GET A CHARACTER
Original Source Code Comment: BUMP TO NEXT CHARACTER
Original Source Code Comment: END OF THIS ERROR MESSAGE?
Original Source Code Comment: NO, LOOP TILL FOUND
A 00H was found: one more message has been passed.
Original Source Code Comment: LOOP FOR ERROR NUMBER
Original Source Code Comment: JP TO ERROR HANDLER
4F11H - ERRTAB - The 44 BASIC error messages, each ending with 00H
Original Source Code Comment: START OF TABLE