TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - SYS16/SYS Disassembled
Page Customization
Page Index
SYS16/SYS
Other Navigation
Introduction/Summary
NEWDOS/80 v2.0 SYS16/SYS Disassembly - PDRIVE (Model I)
SYS16/SYS finishes the PDRIVE command: it changes, copies and shows the ten drive records in a diskette's system data sector and computes their derived bytes. It loads into the overlay area at 4D00H-51E7H (1,256 bytes in five load records, transfer address 4D00H). SYS7 parses PDRIVE password:d, checks the diskette's password (when option AA is on) and calls SYS16 with RST 28H code 32H (function 1 of directory slot 12H), Register B = the drive and HL = the rest of the command line.
The page shows every byte of the file once, in address order.
Parameters (from the code)
| Keyword | Record byte | Value |
|---|---|---|
| TI= | +13, +14 | Letters A-P, one bit each. Exactly one of A (standard), B (Omikron), C (Percom), D (Radio Shack doubler), E (LNW) is required; F, G, N, O, P are not allowed; H, I, J, K, L, M set flags. |
| TD= | +15 | A letter A-H: bit 0 = 8-inch, bit 1 = two sides, bit 2 = double density. |
| TC=, SPT=, TSR=, GPL=, DDSL=, DDGA= | +3, +4, +12, +5, +8, +9 | Numbers 0-255 (decimal, or hex with H): tracks, sectors per track (at most 10/17/20/34/18/30/36/60 for TD A-H), step rate (0-3), granules per lump (1-8), the directory's lump and its size in granules (2-6). |
PDRIVE d shows the table; PDRIVE d,n,keyword=value,... changes record n; PDRIVE d,n=m copies record m to n. For drive 0 the first parameter may be A (after writing, the records of the drives in use, AL of them, are also put into SYS0's in-memory table at 4371H) or B (only the in-memory table; the diskette is not written). Keywords LLD= and NLD= are in the file after the table's end marker and cannot be used.
Each record then gets +0 (the directory's lump = DDSL), +1 (the number of lumps, at most 192), +2 (TSR, the interface in bits 2-4, TI M, K, H), +6 (the byte for the FDC's sector register at select, the same for all records: 00H, 80H/C0H for Omikron or LNW, 80H/A0H for the Radio Shack doubler) and +7 (the disk I/O flags). A record with an impossible combination shows *** ERROR ***; if record 0 is unusable, or two interface kinds are used, PDRIVE ends through SYS0 4030H after the table is shown (the sector has been written already).
Variables
Locations inside SYS16 whose contents change while it runs:
| Address Range | Purpose |
|---|---|
| 4DE2H-4DE8H 7 bytes | The sector write (CALL 4FD2H, CALL 443CH, RET NZ); option B replaces it with NOPs (51D9H). |
| 4E05H 1 byte | The A/B option of drive 0: 00H in the file, 41H after A or B (operand of 4E04H; written at 51C2H, 51CFH, cleared at 4FF8H). |
| 4EB1H 1 byte | The record being worked on, 0-9 (operand of 4EB0H; written at 4D1CH, 4DA5H and 4E25H). |
| 511DH-512AH 14 bytes | FCB for the PDRIVE sector: the drive at 5123H (written at 4D08H), NEXT at 5127H (sector 2, written at 4FD4H). |
Locations outside SYS16 that it reads or writes:
| Address Range | Purpose |
|---|---|
| 4200H-429FH 160 bytes | The ten 16-byte PDRIVE records in the sector buffer (record n at 4200H + 16 n). |
| 42A0H 1 byte | The SYSTEM option AL in the same sector: the number of drives (4E0EH, 4E31H). |
| 4371H-4398H 40 bytes | SYS0's in-memory PDRIVE table, 10 bytes per drive, updated for the drives in use with option A or B (4E0BH). |
Disassembly
4D00H - PDRIVE
SYS7 handles the start of PDRIVE password:d[,parameters]: it selects drive d, checks the diskette's password (when option AA is on) and calls SYS16 with RST 28H code 32H (function 1 of directory slot 12H), Register B = the drive and Register Pair HL = the rest of the command line (SYS7 4D65H). SYS16 reads the drive's system data sector (sector 2, the PDRIVE sector) into 4200H through its own FCB at 511DH, changes one record, recomputes every record's derived bytes, writes the sector back and shows the table. The forms, from the code: PDRIVE d (show), PDRIVE d,n,keyword=value[,...] (change record n, 0-9), PDRIVE d,n=m (copy record m to n), and for drive 0 a first parameter A (also copy the records of the drives in use to SYS0's in-memory table at 4371H) or B (only in memory, the diskette is not written). Each record is 16 bytes at 4200H + 16 times its number.
Store Register A (the drive) at 5123H, byte 6 of the FCB at 511DH (the drive).
Store Register A (the record number) at 4EB1H, the operand of the LD A,FFH at 4EB0H, which selects the record.
KEYWORD LOOP
Register Pair HL = the command line; the record being changed is the one in 4EB1H.
TI LETTER LOOP
Register Pair HL = the command line at the next letter; each letter A-P sets one bit of record bytes +13 (A-H) and +14 (I-P).
RECOMPUTE ALL TEN RECORDS
Register A = the record number, kept on the stack while 4EBFH works.
Store Register A (the record number) at 4EB1H, the operand of 4EB0H.
SELECT BYTE LOOP
Index Register IX = the record, Register B = the records left, Register C = the interface letters in use.
4DE9H - Show the Table
One line per record 0-9: its number (with * for the drives in use, below option AL), then every keyword with its value; an unusable record ends with *** ERROR ***. Then, with option A or B, SYS0's in-memory table is updated.
Load Register A with the A/B option; the operand 4E05H is 00H in the file, 41H (A) after option A or B (stored at 51C2H and 51CFH).
COPY LOOP
Register Pair HL = the record in the sector, Register Pair DE = SYS0's table, Register A = the records left.
Store Register A (the record number) at 4EB1H, the operand of 4EB0H.
KEYWORD DISPLAY LOOP
Register Pair BC walks the keyword table: the keyword's characters, 00H, the attribute byte.
4EA6H - The Field of a Record
4EA6H: Register A = the attribute at Register Pair BC; its low four bits are the field's offset in the record. 4EA9H: Index Register IX = 4200H + 16 times the record number (operand 4EB1H) + the offset in Register A. Register Pairs HL and DE are kept.
Load Register A with the record number; the operand 4EB1H (FFH in the file) is stored at 4D1CH, 4DA5H and 4E25H.
4EBFH - Compute a Record's Derived Bytes
From the typed values (TC at +3, SPT +4, GPL +5, DDSL +8, DDGA +9, TSR +12, TI +13/+14, TD +15) the record gets +0 (the lump where the directory starts), +1 (the number of lumps), +2 (TSR, the interface, TI M, K and H) and +7 (the disk I/O flags). Any value out of range returns early with +2's interface bits clear, which marks the record unusable. TD letters: bit 0 = 8-inch, bit 1 = two sides, bit 2 = double density. The record number is in 4EB1H.
COUNT THE INTERFACE LETTERS
Register Pair HL is shifted left 16 times; Register A counts the bits that come out.
4FD2H - Helpers
4FD2H points the FCB at sector 2. 4FDBH reads a separator and, the first time for drive 0, handles the A and B options (51C0H). 4FFBH checks that at most one interface kind is used. 501EH shows a character. 5026H looks up a keyword.
Store Register A (2) at 5127H, the low byte of NEXT (FCB + 10) of the FCB at 511DH.
COLLECT THE INTERFACE LETTERS
Register Pair HL = the record's TI byte, Register C = the letters B-G of all records so far.
KEYWORD LOOKUP
Register Pair BC = the table entry, Register Pair HL = the command line, Register D = the bytes after each keyword's 00H.
503DH - Read a Number
A decimal number, or a hexadecimal one ended by H (the same routine as in SYS7, SYS14 and SYS17). 503DH 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).
50A8H - Show a Number in Decimal
Shows Register Pair DE in decimal without leading zeros (the same routine as SYS17 4EDEH), using the negative powers of ten at 50D2H.
DIGIT LOOP
Register Pair DE = the part of the number not shown yet, Register Pair HL = the next power in the table.
50DAH - Messages and Tables
Data, not code, apart from three small routines at 5187H-519AH that 4EF2H, 4FA7H and 4DD5H call.
51C0H - The A and B Options of Drive 0
Reached from 4FECH for the first parameter of PDRIVE 0, with Register A = its first character, Register Pair DE = 4E05H (the option byte) and Register Pair HL at the character. A: after the sector is written, the records of the drives in use are also copied to SYS0's in-memory table (4371H). B: the same, but the diskette is not written: 4DE2H-4DE8H (the write) are replaced by NOPs and the B in the command line becomes an A.
Store Register A (the character) at Register Pair DE, 4E05H, the operand of 4E04H (4FF7H clears it again if this is not the option). LD does not change the flags.
Store Register A (41H) at Register Pair DE, 4E05H: the option is set.
Store Register C (00H, NOP) at Register Pair HL, over a byte of the write at 4DE2H-4DE8H.