TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - SYS17/SYS Disassembled
Page Customization
Page Index
SYS17/SYS
Other Navigation
Introduction/Summary
NEWDOS/80 v2.0 SYS17/SYS Disassembly - SYSTEM, WRDIRP and the End of a Diskette COPY (Model I)
SYS17/SYS holds the SYSTEM command (setting and showing the options in a diskette's system data sector), the WRDIRP command (rewriting the directory sectors with the directory data mark) and, since zap 057, the last part of a diskette COPY, which SYS6 calls. It loads into the overlay area at 4D00H-51E7H (1,256 bytes in five load records, transfer address 4D00H); 508FH-51E7H are unused zero bytes.
The page shows every byte of the file once, in address order.
Entry Codes
| Code | From | Function |
|---|---|---|
| 33H | SYS7 (SYSTEM) | SYSTEM, with Register B = the drive (4D0CH). |
| 53H | SYS1 (WRDIRP) | WRDIRP d (4F5DH). |
| F3H, C = FFH | SYS6 62ADH | Returns at once (error 2AH, ignored) so that SYS17 is in memory; SYS6 then jumps to 501CH. |
Variables
Locations inside SYS17 whose contents change while it runs:
| Address Range | Purpose |
|---|---|
| 4D74H 1 byte | Second byte of the RES n,(HL) at 4D73H: the bit of the Y/N option being set (written at 4D5EH). |
| 4D7AH 1 byte | Second byte of the SET n,(HL) at 4D79H (written at 4D63H). |
| 4E04H 1 byte | Second byte of the BIT n,(HL) at 4E03H: the bit of the option being shown (written at 4DF6H). |
| 4F10H-4F15H 6 bytes | Hex display buffer: 0, four digits written by SYS0 4063H at 4F11H, H. |
| 4F16H-4F23H 14 bytes | FCB for the system data sector: drive at 4F1CH (written at 4D0DH), NEXT at 4F20H (sector 2, written at 4E23H). |
| 500EH-501BH 14 bytes | WRDIRP's FCB, writing with the directory data mark: drive at 5014H (written at 4F69H), NEXT at 5018H-5019H (written at 4F96H, 4FB5H and 4FBBH). |
Locations outside SYS17 that it reads or writes:
| Address Range | Purpose |
|---|---|
| 4200H-42FFH 256 bytes | Sector buffer: the system data sector (options at 42A0H-42A9H, 42D0H-42D1H and 42F0H-42FAH), the boot sector, the directory sectors, the GAT. |
| 430FH 1 byte | SYS0's granules per lump of the drive just used (4F8CH). |
| 436DH 1 byte | SYS0's copy of SYSTEM option byte F1H; bit 4 = BK, WRDIRP allowed (4F5DH). |
| 5981H-599BH in SYS6 | SYS6's COPY data: password code 5981H, name and date 5983H, option flags 5994H-5995H, source lumps 59B8H, granules per lump 59BCH, source sectors 59C1H, source granules 59C3H, destination lumps 59C6H, destination granules 59D1H. |
SYSTEM Options
The table at 4F24H gives, for each option code, where its value lives in the system data sector: Y/N options in the bits of bytes F0H-F1H and F8H-FAH, numbers in A0H-A9H, and AP as a word at D0H-D1H. AH, AK, BB, BL and BM are not options. After the options are set AL (the number of drives) is forced into 1-4. The settings are shown as XY=Y/N or XY=decimal/hexH.
Disassembly
4D00H - Function Dispatcher
SYS17 is entered by the SYS0 RST 28H dispatcher (4BC2H) with Register A = the RST 28H code. 33H (function 1 of directory slot 13H) is SYSTEM, from SYS7 with Register B = the drive; 53H (function 2) is WRDIRP, from SYS1's command table. Any other code returns error 2AH: SYS6 uses this to load SYS17 (code F3H with Register C = FFH, SYS6 62A7H) and then jumps to 501CH, the end of a diskette COPY. Register Pair HL points at the command line after the command word.
4D0CH - SYSTEM
SYSTEM password:d[,XY=value...]. SYS7 has selected drive d and checked its password; Register B holds the drive and Register Pair HL the command line after the drive. The drive's system data sector (sector 2) is read into 4200H through the FCB at 4F16H. Each option XY (two letters; its code = 26 times the first letter's number plus the second's, A = 0) is looked up in the table at 4F24H and set: Y or N into a bit of 42F0H-42FAH, a number into 42A0H-42A9H or, for AP, the word at 42D0H. The sector is then written back. Without options the settings are shown.
Store Register A (the drive) at 4F1CH, byte 6 of the FCB at 4F16H (the drive), inside this overlay.
OPTION LOOP
Register Pair HL = the command line at the next option.
Store Register A at 4D74H, the second byte of the RES n,(HL) at 4D73H.
Store Register A at 4D7AH, the second byte of the SET n,(HL) at 4D79H.
RES n,(HL): clear the option's bit in the byte at Register Pair HL; the bit number is in the second byte 4D74H, stored at 4D5EH (86H, bit 0, in the file).
SET n,(HL): set the option's bit in the byte at Register Pair HL; the bit number is in the second byte 4D7AH, stored at 4D63H (C6H, bit 0, in the file). SET does not change the flags.
4DC0H - Show the Settings
Every option in code order: its two letters, =, and Y or N, or the number in decimal and hexadecimal (for example AP=65535/0FFFFH). The first is preceded by a carriage return, the others by a comma. Register Pair HL walks the option table and Register Pair DE holds the code.
DISPLAY LOOP
Register Pair HL = the table byte, Register Pair DE = the option's code, Register B = the separator to show.
Store Register A at 4E04H, the second byte of the BIT n,(HL) at 4E03H.
BIT n,(HL): test the option's bit in the byte at Register Pair HL; the bit number is in the second byte 4E04H, stored at 4DF6H (46H, bit 0, in the file).
Store Register A (2) at 4F20H, the low byte of NEXT (FCB + 10) of the FCB at 4F16H.
SKIP LEADING ZEROS
Register Pair HL steps through the digits; Register B counts the digits left, keeping at least one.
4E73H - Read a Number
A decimal number, or a hexadecimal one ended by H (the same routine as in SYS7, SYS14 and SYS16). 4E73H also requires it to be 0-255 and returns it in Register A. A bad number is error 2FH BAD PARAMETER(S). Register Pair HL is the command line.
DIGIT LOOP
Register Pair HL = the command line, Register Pair DE = the number so far, Register B = the flags (bit 0 hexadecimal, bit 1 a digit read).
4EDEH - Show a Number in Decimal
Shows Register Pair DE in decimal without leading zeros (the same routine as SYS16 50A8H), using the negative powers of ten at 4F08H.
DIGIT LOOP
Register Pair DE = the part of the number not shown yet, Register Pair HL = the next power in the table.
4F24H - The Option Table
Data, not code: one byte for each option code (26 times the first letter's number plus the second letter's, A = 0), in code order. FEH = no such option, FFH = the end. Bit 7 clear: a Y/N option, whose bit (bits 4-6) lies in the byte 42F0H + (bits 0-3) of the system data sector. Bit 7 set: a number at 42A0H + (bits 0-4), a 16-bit one 30H higher if bit 6 is set. SYS0's reset code reads the same sector bytes (Part 5, section 3.4).
4F5DH - WRDIRP
WRDIRP d (only with the SYSTEM option BK = Y, else error 37H). Reads drive d's boot sector, finds the directory (the lump in boot sector byte 2), checks that the first two directory entries are BOOT/SYS and DIR/SYS, and writes back every directory sector that was read without the directory data mark, now with it (the FCB at 500EH writes with the mark). A wrong boot sector or entry is error 2CH BAD DIRECTORY DATA. Register Pair HL points at the command line after WRDIRP.
Store Register A (the drive) at 5014H, byte 6 of the FCB at 500EH (the drive).
Store Register Pair HL (the HIT sector's number) at 5018H, NEXT in the FCB at 500EH.
MARK THE DIRECTORY SECTORS
Register Pair HL = the sector's number, Register B = the sectors left.
Store Register Pair HL (the sector's number) at 5018H, NEXT in the FCB.
Store Register Pair HL (the same sector) at 5018H again, since the read moved NEXT on.
COMPARE LOOP
Register Pair DE = the entry's name, Register Pair HL = the text expected, Register B = the characters left.
501CH - The End of a Diskette COPY (Zap 057)
Zap 057 moved this code out of SYS6. SYS6 loads SYS17 at 62ADH and jumps here from 54D4H when a diskette COPY has written all sectors; Index Register IX is SYS6's FCB. It verifies the rest of the destination diskette and, unless SYS6's option flag 5994H bit 1 is set, brings the destination's GAT up to date: allocation bytes where a larger destination has them, the password, the name and date, and the granules beyond the source's size made free. Every call goes to SYS6 (or SYS0).
FILL LOOP
Register Pair HL = the GAT byte, Register E = the bytes left.
508FH - Unused Bytes
508FH-51E7H fill the last load record; nothing reads or executes them.