TRS-80 DOS - NEWDOS/80 v2.0 for the Model III - SYS12/SYS Disassembled
Page Customization
Page Index
SYS12/SYS
Other Navigation
Introduction/Summary
NEWDOS/80 v2.0 SYS12/SYS Disassembly - REF (Model III)
SYS12/SYS carries out the Disk BASIC direct command REF, which lists where line numbers, variable names or a piece of text are used in the program. It loads 4D00H-51D2H in five load records (transfer address 4D00H); the code ends at 51B1H, 51B2H-51BEH are data and 51BFH-51D2H are 20 bytes of 00H. Its variables 51D3H-51FFH lie after the file. SYS18/SYS runs it from its command table (REF, code 2EH): at its 5531H it pushes BASIC/CMD's 641EH (the end of the statement) and does RST 28H. When REF is done SYS12/SYS returns through the SYS0/SYS dispatcher (4BC5H) to 641EH and then to the ROM's READY at 1A25H; a plain REF that finds a line jumps into the ROM's LIST at 2B33H instead, a bad parameter goes to the ROM's SYNTAX ERROR at 1997H, and 4F2BH is described below.
The page shows every byte of the file once, in address order.
The Forms of REF
| Form | What it does |
|---|---|
| REF name, REF number | Mode 2: every line that uses the variable (the item must have one or two characters; in the text only the first two characters of a name count) or refers to the line number (up to 5 digits). The item is shown right-aligned in 5 columns, then each line number; for a name the line number is followed by the form: /$ /% /! /# for a type character, an opening parenthesis for an array, and the count when it is used more than once in the line. |
| REF "text, REF =text | Mode 2 with a text search: every line holding the bytes after the quote or the = token (up to 16, a closing quote included) is shown. Strings and remarks are searched too. |
| REF followed by the multiplication sign, or by $ | The full report: every line number referred to and then every name, in order (mode 0 finds the next item and keeps up to 32 of its lines at 4300H, mode 1 reports them and scans on if the list was full). With $ the output is printed as well (BASIC/CMD's printer switch 5D45H). Holding BREAK pauses between items, ENTER goes on, the up arrow stops. |
| the same, followed by a name or number | The full report from that item on. |
| REF, REF @n | Mode 3: lists (through the ROM's LIST) the next line after the last one shown, or from line n on, that holds the remembered item or text; Text End when there is none. The last line shown (4E76H) is reset to FFFFH at the end of every other report, so a plain REF then starts at the first line. |
The scan (4F46H) passes strings, REM and ' remarks, DATA statements, numbers with a fraction and constants after &H and &O; the AS of a FIELD statement in the same line is not taken as a name. A line with a match changes the JP Z,4DFCH at 4F6DH into JP 4DFCH, so the line is reported when the scan reaches the next one.
At 4F2BH a plain REF that walks past the last line of the program (no line after the last one shown) jumps to the Text End message with a line address still on the stack, so the RET at the end of BASIC 5D70H goes to that address, the program's end marker, and not back through the dispatcher.
Variables
ROM Addresses
| Address Size | Contents |
|---|---|
| 3840H 1 byte | Keyboard Row Bit 0 ENTER, bit 2 BREAK, bit 3 the up arrow (4DB6H-4DC9H). |
| 4020H-4021H 2 bytes | Cursor Address The ROM's cursor in the video memory; its column decides the line breaks of the report (51A1H). |
| 40A4H-40A5H 2 bytes | TXTTAB The first program line (4DCCH, 4F1DH). |
DOS Addresses
| Address Size | Contents |
|---|---|
| 4300H-433FH 64 bytes | Line List SYS0/SYS's sector buffer, used for up to 32 line addresses of the item found in mode 0 (5101H); 4340H marks a full list. |
BASIC/CMD Addresses
| Address Size | Contents |
|---|---|
| 5D45H 1 byte | Printer Switch The operand of BASIC/CMD's 5D44H: 4D04H stores the first character after REF there; 24H ($) makes 5D3FH print as well. |
Operands and Opcodes Changed at Run Time
| Address Size | Contents |
|---|---|
| 4E0CH 1 byte | Mode Operand of 4E0BH: 0 find the next item, 1 report it (full report), 2 one item, 3 list one line (4DD1H). |
| 4E76H-4E77H 2 bytes | Last Line Shown Operand of 4E75H: the number of the line found (50E7H); n - 1 after REF @n (4D1DH); FFFFH after a report (4E17H). |
| 4E7AH-4E7BH 2 bytes | Line Address Operand of 4E79H: the line being scanned (4F70H). |
| 4ED9H-4EDAH 2 bytes | Count Operand of 4ED8H: the count shown with a form (4E9CH). |
| 4EEFH-4EF0H 2 bytes | List End Operand of 4EEEH (512AH, 5182H). |
| 4EF2H-4EF3H 2 bytes | List Next Operand of 4EF1H (4E6DH, 5185H). |
| 4F6DH 1 byte | Line Matched Opcode: CAH, JP Z (4DF0H), or C3H, JP (50DDH) after a match. |
| 4F7CH 1 byte | Text Search Opcode: 21H, LD HL (4D4DH), or C3H, JP 512FH (4D44H). |
| 4FBEH 1 byte | Numbers Looked At Opcode: 30H, JR NC (numbers compared), or 18H, JR (numbers passed) (4DEBH). |
| 4FFCH, 50A9H 2 bytes | Compare Condition Opcodes: DAH, JP C (mode 0), or C2H, JP NZ (modes 1 to 3) (4DDAH, 4DDDH). |
| 5021H 1 byte | Best Test Opcode: 38H, JR C (the best is a number), or 18H, JR (a name or none) (517CH). |
| 5085H-5086H 2 bytes | FIELD Position Operand of 5084H: the last FIELD token (4FB4H), cleared at 4DF6H. |
Variables After the File
| Address Size | Contents |
|---|---|
| 51D3H-51D8H 6 bytes | Item Compared Length byte and characters. |
| 51D9H-51DEH 6 bytes | Best or Reported Item Length byte and characters; FFH FFH for none. |
| 51DFH-51E4H 6 bytes | Number Found The digits of a number in the text. |
| 51E5H-51EEH 10 bytes | Counters Plain, $, %, !, # and the same as arrays. |
| 51EFH-51FFH 17 bytes | Search Text Up to 16 bytes and a 00H. |
Outside Routines
| Where | Addresses |
|---|---|
| ROM | 002BH (read a key), 1997H (SYNTAX ERROR), 1E5BH (LINGET), 2B33H (LIST4); the READY entry 1A25H is pushed by SYS18/SYS. |
| BASIC/CMD | 5D30H (spaces), 5D3DH (a space), 5D3FH (a character), 5D4FH (a space and a carriage return), 5D52H (a carriage return), 5D67H (a number in decimal), 5D70H (Register B characters); 641EH (the end of the statement) is pushed by SYS18/SYS. |
| SYS0/SYS | The dispatcher's return 4BC5H. |
Disassembly
4D00H - REF: Read the Parameter
SYS18/SYS runs REF from its command table (the entry REF, code 2EH) at its 5531H: it pushes BASIC/CMD's 641EH (the end of the statement) above the ROM's READY entry 1A25H (pushed at its 5518H) and does RST 28H with Register A = 2EH (slot 0EH, function 1). The SYS0/SYS dispatcher calls 4D00H with Register Pair HL = the command line after REF; SYS12/SYS's RET goes back through the dispatcher (4BC5H) to 641EH. Forms, from the code: REF alone (list the next line that holds the remembered item), REF @n (the same from line n on), REF name or REF number (every line that uses it), REF "text or REF =text (every line holding the text), REF followed by the multiplication sign or $ (every line number and name in the program, in order; $ also prints), and either of those followed by a name or number (the full report from that item on).
Store Register Pair DE (n - 1, or 0) at 4E76H, the operand of LD HL,nnnn at 4E75H: the number of the last line shown, after which the search starts.
COPY THE SEARCH TEXT
Register Pair DE = the command line, Register Pair HL = the buffer, Register B = the bytes left. The search text ends at its first 00H; a closing quote, if typed, is part of it.
Store Register A (C3H) at 4F7CH: the LD HL,512FH there becomes JP 512FH, so every byte of the program is compared with the search text instead of being parsed.
Store Register A (21H) at 4F7CH, putting back the LD HL,512FH there: no text search.
COPY THE ITEM
Register Pair DE = the command line, Register Pair HL = the buffer, Register B counts down from 6.
4DB0H - The Full Report: the Next Item
Each round of the full report first scans the whole program in mode 0 for the smallest line number or name above the last one reported (51D3H), keeping the addresses of up to 32 lines that use it in the DOS sector buffer at 4300H; then it reports that item in mode 1. Line numbers come before names. Holding BREAK pauses between items (ENTER goes on), the up arrow stops the report.
PAUSE
Register Pair HL = 3840H; the loop waits for ENTER (go on) or the up arrow (stop).
Store Register A (the mode) at 4E0CH, the operand of LD A,nn at 4E0BH, read at 4E80H, 5013H and 50B2H.
Store Register A at 4FFCH, the opcode of the number test: JP C (mode 0) skips the numbers below the last item, JP NZ (modes 1 to 3) skips every number that is not the item.
Store Register A at 50A9H, the opcode of the same test for names.
Store Register A (30H or 18H) at 4FBEH, the opcode of the number test there.
Store Register A (CAH) at 4F6DH, putting back the JP Z,4DFCH there: no match in the line yet.
Store Register Pair HL (0000H) at 5085H, the operand of LD DE,nnnn at 5084H, the position of the last FIELD token.
4DFCH - At the Next Line
Reached through the JP at 4F6DH with Register Pair DE at the link field of the next line: always when the line just scanned had a match (4F6DH was made JP), otherwise only when the link's low byte is 00H. A line with a match is reported (4E80H); the end marker ends the scan.
The end of the program: load Register A with the mode, the operand 4E0CH (00H in the file; stored at 4DD1H).
Store Register Pair HL (FFFFH) at 4E76H, the operand of LD HL,nnnn at 4E75H: the number of the last line shown.
Store Register Pair HL (the next entry) at 4EF2H, the operand of LD HL,nnnn at 4EF1H.
Load Register Pair HL with the number of the line found, the operand 4E76H (0000H in the file; stored at 50E7H, and at 4D1DH and 4E17H).
Load Register Pair HL with the address of the line found, the operand 4E7AH (0000H in the file; stored at 4F70H for each line).
4E80H - Report a Line
Reached from 4E01H with Register Pair DE at the next line's link field, after a line with a match. In mode 3 the line is listed. Otherwise the line's number (4E76H) is shown once for every form of use counted in it (51E5H-51EEH): the name alone, with $ % ! # (the type characters at 51B2H-51B5H), and each of these as an array (followed by an opening parenthesis), with the count when it is more than one. A line number or a text search has only the first counter.
COUNTER LOOP
Register Pair HL = the counter, Register C = its number (0-9), Register B = the counters left.
Store Register A (the count) at 4ED9H, the low byte of the operand of LD DE,nnnn at 4ED8H.
Load Register Pair DE with the count, the operand 4ED9H (0000H in the file; its low byte stored at 4E9CH, its high byte stays 00H).
Mode 1: load Register Pair BC with the end of the line list, the operand 4EEFH (0000H in the file; stored at 512AH and 5182H).
Load Register Pair HL with the next entry of the line list, the operand 4EF2H (0000H in the file; stored at 4E6DH and 5185H).
4F07H - Plain REF and REF @n
Finds the first line after the last one shown (4E76H; FFFFH = from the first line, n - 1 after REF @n) and scans from there in mode 3 for the remembered item (or the search text), listing the first line that holds it.
FIND THE LINE AFTER THE LAST ONE SHOWN
Register Pair HL = the line, Register Pair BC = the number of the last line shown.
4F46H - Scan the Text
Register Pair DE walks through the program's text. Strings, REM and ' remarks, DATA, constants after & and decimal fractions are passed; line numbers (strings of digits) and variable names are collected and compared with the item. A match counts in the counters 51E5H-51EEH and turns the JP Z,4DFCH at 4F6DH into JP 4DFCH, so that the line is reported when the scan reaches the next line. During a text search the JP 512FH at 4F7CH compares every byte with the search text instead.
PASS A STRING
Register Pair DE steps through the string; Register B = the closing quote.
PASS DATA
DATA (88H): Register Pair DE steps through the statement to its colon or the line's end.
PASS A REMARK
REM (93H) or ' (FBH): Register Pair DE steps to the line's 00H end.
If the Z FLAG is set (the link's low byte is 00H, which may be the end marker), JUMP to 4DFCH. The opcode at 4F6DH is CAH (JP Z, stored at 4DF0H) or, after a match in the line just scanned, C3H (JP, stored at 50DDH): then every next line goes to 4DFCH, which reports the line.
Store Register Pair DE (the address of the line about to be scanned; 4E08H enters here) at 4E7AH, the operand of LD HL,nnnn at 4E79H, read at 5087H, 50DFH and 5114H.
BYTE LOOP
Register Pair DE = the byte of the line being looked at, in Register A.
Load Register Pair HL with 512FH, which nothing here uses; the opcode at 4F7CH is 21H (LD HL, stored at 4D4DH) or, during a text search, C3H (stored at 4D44H): JP 512FH, which compares the byte with the search text.
Store Register Pair DE (the address of the FIELD token) at 5085H, the operand of LD DE,nnnn at 5084H, so that FIELD ... AS name counts the name and not AS.
A digit (the CARRY FLAG is set from 4FBAH): JR NC,4FE1H is never taken. The opcode at 4FBEH is 30H (JR NC, stored at 4DEBH when the item compared is a number) or 18H (JR, when it is a name): then every number is passed at 4FE1H.
COLLECT THE DIGITS
Register Pair HL = the buffer, Register B counts down the room left, Register A = the byte.
PASS DIGITS
Register Pair DE steps over the digits that follow.
JUMP to 4F78H (pass this number) under the condition stored at 4DDAH: JP C (DAH, mode 0: a shorter number is smaller than the item compared) or JP NZ (C2H, modes 1 to 3: a number of another length is another number). 5005H and 500EH come back here with new flags.
The opcode at 5021H (stored at 517CH) is 38H, JR C,5037H, when the best item so far is a number (a smaller number becomes the new best), or 18H, JR 5037H, when the best is a name or none (FFFFH): any number comes before every name. 502AH and 5033H come back here with new flags.
PASS HEXADECIMAL DIGITS
Register Pair DE steps over 0-9 and A-F.
Load Register Pair DE with the address of the last FIELD token, the operand 5085H (0000H in the file; stored at 4FB4H, cleared at 4DF6H).
PASS THE REST OF THE NAME
Only the first two characters count.
JUMP to 4F78H (pass this name) under the condition stored at 4DDDH: JP C (mode 0: names below the item compared are passed) or JP NZ (modes 1 to 3: other names are passed). 50B0H comes back here with new flags.
FIND THE TYPE
Index Register IY steps back through # ! % $ (51B5H-51B2H), Register Pair HL through their counters (51E9H-51E6H).
Store C3H (JP) at Register Pair HL, 4F6DH: the line is reported when the scan reaches the next line.
Store Register Pair BC (the line's number) at 4E76H, the operand of LD HL,nnnn at 4E75H: the number shown in the report, and the last line shown for a plain REF.
5101H - Remember the Line
Adds the address of the line being scanned (4E7AH) to the list at 4300H-433FH (32 lines) unless the list is full or the line is already its last entry.
Store Register Pair HL (the new end of the list) at 4EEFH, the operand of LD BC,nnnn at 4EEEH.
512FH - Text Search
Reached through JP 512FH at 4F7CH with Register A = the byte of the line at Register Pair DE. Compares the bytes from there with the search text at 51EFH up to its 00H end; a match counts in 51E5H, the scan goes on after it.
COMPARE LOOP
Register Pair DE steps through the line, Register Pair HL through the search text.
514BH - Small Helpers
514BH: the next byte of the line in Register A, passing spaces, 09H and 0AH. 515AH: the CARRY FLAG if Register A is not a letter or digit; 5161H: the CARRY FLAG if it is not a letter. 5168H and 516EH: store the best item's characters (Register Pair BC) and length byte, set 5021H and empty the line list; 5171H: only the last two.
Store Register A (18H or 38H) at 5021H, the opcode of the test of a number found against the best.
Store Register Pair HL (4300H) at 4EEFH, the operand of LD BC,nnnn at 4EEEH: the list's end is its start, the list is empty.
Store Register Pair HL (4300H) at 4EF2H, the operand of LD HL,nnnn at 4EF1H: the list's next entry is its first.
5189H - Compare Characters
Compares Register C characters from 51E0H with those at Index Register IY. The Z FLAG is set if they are all equal (or Register C is 0); otherwise the flags of the first difference.
COMPARE LOOP
Register Pair HL and Index Register IY step through the two strings; Register B counts.
519BH - Position the Output
519EH displays a space; at column 53 or beyond it starts a new line, and near the start of a line it indents to column 7, past the item's column.
51B2H - Data
The type characters and the message of 4E20H.
51D3H - Variables After the File
Not loaded by SYS12/SYS (the file ends at 51D2H); they keep their contents while no other overlay overwrites them.