DOSPLUS 3.5 for the Model III - REF/CMD Disassembled
Page Customization
Page Index
REF/CMD
Other Navigation
Introduction/Summary
DOSPLUS 3.5 REF/CMD Disassembly - CMD"REF", the Cross Reference of a BASIC Program (Model III)
REF/CMD is the cross referencer of Extended Disk BASIC, CMD"REF"; its heading reads REF - BASIC Program refrencer - 1.7. It is a load module of 4 blocks, 992 bytes, at 5200H-55DFH, with the transfer address 5200H, after the two comment records (the name REF and the copyright notice). The Model I and Model III files are identical byte for byte, and so are the two pages apart from their links.
It runs only from Extended Disk BASIC: BASIC/CMD's CMD (5C48H) passes REF to CMNDI@ as a DOS command, the DOS loads REF/CMD at 5200H and calls it, and REF takes BASIC's text pointer off the stack (5216H). It ends at the ROM's READY, which resets the stack and sends the output back to the display. From the DOS command level it only shows its heading. TBASIC cannot run it, since its CMD runs no DOS commands.
The Statement
CMD"REF",option,... with the options L (every number in the program, as line numbers), V (the variables), K (the keywords) and P (the output to the printer, through the ROM's 409CH), in any order; or CMD"REF",S=item[,P] for one line number, variable or keyword. The lists come in the order line numbers, variables, keywords, whatever the order of the options (52CAH). Each item is shown in a column of 8 characters, then the numbers of the lines it occurs in, nine to a row (5472H).
The Parts of REF/CMD
| Address | Contents |
|---|---|
| 5200H-5296H | The start and S= with one item (5200H, 526BH). |
| 5297H-532EH | The options and the passes over the program for each kind (5297H, 52CAH). |
| 532FH-5400H | The scan of a line for numbers, variables and keywords (532FH). |
| 5401H-5471H | A key offered: the least key of the pass and the list of its lines (5401H). |
| 5472H-54F9H | The listing of an item and its lines (5472H). |
| 54FAH-5589H | The keys of a variable and of a number, the number as text, the character class, the output (54FAH, 5539H, 5560H, 5572H, 557AH). |
| 558AH-5BFEH | The heading, the flags, the keys and the list of lines (558AH). |
How REF Works
REF keeps no table of the items. For each kind it passes over the whole program again and again: every item met is offered as a key of 4 bytes (5401H); a pass keeps the least key above the one listed last, with the lines it occurs in, and when the pass ends that key is listed and becomes the one listed last (52F8H). The keys are a line number in its two bytes followed by 80H 00H, a keyword's token followed by 00H 80H 00H, and a variable's first letter, second character, suffix and the ( of an array, a space for each part that is missing (54FAH); so the variables are listed in the order of these bytes (A, then the array A(, then A$), and a variable and the array of the same name are two items. The text of a line is read with the ROM's RST 10H code (1D78H), so spaces do not count; strings in quotes are passed over, the rest of a line after DATA or REM is passed over, and in a FIELD statement the word AS is not taken as a variable (53C3H). A line holding an item several times is listed once. The list of the lines of one item has room for 774 lines, up to 5BFEH, below BASIC/CMD's code at 5C00H; more lines are not listed (545EH).
Differences from the Manual
The manual (Disk BASIC, REF) gives the options as the bytes take them. What it does not say: the lists always come in the order L, V, K; after S= only P may follow (anything else is Illegal function call); a number above 65529 is not referenced (and after S= is a Syntax error); keywords and variables in DATA and REM lines are not referenced after the DATA or REM; a variable and an array of the same name are listed apart; and no more than 774 lines are listed for one item.
Variables
REF/CMD Variables
| Address Size | Contents |
|---|---|
| 55DEH 1 byte | Flags Bit 0 K, 1 V, 2 L, 3 P, 4 lines collected, 5 the rest of the line passed over, 6 FIELD, 7 S= (55DEH). |
| 55DFH 1 byte | Kind 03H line numbers, 02H variables, 01H keywords (55DFH). |
| 55E0H-55E1H 2 bytes | Line number The line being scanned (5336H). |
| 55E2H-55E3H 2 bytes | Last place The place of the last line in the list (5466H). |
| 55E4H-55E7H 4 bytes | Current key The least key of the pass so far (5436H). |
| 55E8H-55EBH 4 bytes | Key listed last No key at or below it is taken again (5301H). |
| 55ECH-55F2H 7 bytes | Number text A line number as decimal text (5560H). |
| 55F3H-5BFEH 1548 bytes | Line list The lines of the current key, two bytes each (5444H). |
Memory Outside REF/CMD
| Address Size | Contents |
|---|---|
| 409CH 1 byte | Output device 01H, the printer, for the option P (52BCH). |
| 40A2H-40A3H 2 bytes | Current line number Set to FFFFH, the direct mode (52CDH). |
| 4121H-4122H 2 bytes | Accumulator The integer converted to text (5561H). |
Outside Routines
| Address | Contents |
|---|---|
| 4467H | SYS0/SYS: DSPLY@, the heading (520CH). |
| 402DH | SYS0/SYS: EXIT@ (520FH). |
| 1D78H | ROM: the RST 10H code, the next character of the text (533EH and others). |
| 1650H | ROM: the table of the reserved words (5491H). |
| 132FH | ROM: an integer as decimal digits (556CH). |
| 032AH | ROM: output a character (5585H). |
| 1D9BH | ROM: test BREAK and SHIFT @ (5325H, 54F2H). |
| 1A19H | ROM: READY (528FH, 52D4H). |
Disassembly
5200H - CMD"REF"
REF/CMD's transfer address. REF is the cross referencer of BASIC programs, run from Extended Disk BASIC as CMD"REF",option,...: BASIC/CMD's CMD passes REF to CMNDI@ as a DOS command, and the DOS loads REF/CMD at 5200H and calls it. From the DOS command level (return address 402DH) it only shows its heading. From BASIC it takes the options L (line numbers), V (variables), K (keywords) and P (printer), or S= with one line number, variable or keyword, and lists each item in order with the lines it occurs in. It ends at the ROM's READY.
526BH - One Item
S=: the key is stored as the current one (55E4H), the current line number is set to FFFFH, and every line of the program is scanned (532FH); the lines that hold the item are collected (5401H) and, if there are any, listed (5472H). The end is READY.
5297H - The Options
L, V and K set bits 2, 1 and 0 of the flags; P sets bit 3 and sends the output to the printer (409CH = 01H); anything else is Illegal function call. The options are separated by commas.
52CAH - The Lists
The kinds are taken in the order 3, 2, 1 (Index Register IX+01H, 03H as loaded): line numbers, variables, keywords; a kind whose option was not given is passed over. For a kind, each pass over the program finds the least key above the one listed last (55E8H) and collects the lines it occurs in; the key and its lines are listed and the next pass begins, until a pass finds no key.
532FH - Scan a Line
Register Pair HL at the line number of a line. Its number is kept (55E0H) and its text is read with the ROM's 1D78H (spaces passed over): quoted strings are passed over; a digit starts a number, taken as a line number for the kind 3; a letter starts a variable for the kind 2 (after FIELD the word AS is passed over); a token is a keyword for the kind 1, and after DATA or REM the rest of the line is passed over. Each item of the kind being listed is offered to 5401H. Returns Register Pair HL at the next line.
5401H - Offer a Key
The key in Register Pairs DE and BC (D first, C last) is compared with the current key (55E4H-55E7H). Equal: the current line number is added to the list of its lines. Above the current key, or in the S= mode below it: nothing. Below the current key and above the key listed last (55E8H-55EBH): it becomes the current key and its list starts again with this line. The list (55F3H on) gets a line only once in a row and stops at 5BFDH.
5472H - List an Item
Shows the current key by its kind: a keyword by its word from the ROM's table at 1650H (each word's first character has bit 7 set), a variable by its name, suffix and ( for an array, a line number in decimal; padded with spaces to 8 columns (Register B). Then its lines, nine to a row, each row after the first indented by 8 spaces, with the ROM's test of BREAK and SHIFT @ between the rows.
54FAH - A Variable's Key
Takes a variable name at Register Pair HL: Register D its first letter, Register E its second character (a letter or a digit; a space for a one letter name), Register B its suffix % ! $ # (else a space), Register C ( for an array (else a space). The rest of a longer name is passed over. Returns Register Pair HL at the last character taken.
5539H - A Number's Key
Takes the decimal number at Register Pair HL: Register Pair DE the number, Register Pair BC 8000H, Register Pair HL at its last digit. A number above 65529 (a value that would pass 1998H before its last digit) returns the C FLAG, with Register Pair HL inside the number.
5560H - A Number as Text
Puts the integer in Register Pair DE into 55ECH as decimal text through the ROM's 132FH (the accumulator at 4121H holds it), and returns Register Pair HL = 55ECH.
5572H - Classify a Character
Register A: the C FLAG below 41H (not a letter), the Z FLAG for 41H-7EH (a letter), the NC and NZ FLAGS for 7FH and above (a token).
557AH - Show a Text
Shows the text at Register Pair HL up to its 00H through 5585H, counting the columns in Register B. 5583H outputs a carriage return; 5585H outputs the character in Register A through the ROM's 032AH and decrements Register B.
558AH - The Heading and the Variables
Data.