TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - SYS12/SYS Disassembled

Page Customization

Introduction/Summary

NEWDOS/80 v2.0 SYS12/SYS Disassembly - BASIC REF (Model I)

SYS12/SYS is the BASIC command REF, a cross reference of line numbers, variable names and text in the program. It loads into the overlay area at 4D00H-51D2H (1,235 bytes in five load records, transfer address 4D00H) and is called through RST 28H by BASIC's direct statement code in SYS18 (555DH), with BASIC's end of statement (6445H) as the return address. Because it stays in the overlay area until another overlay is loaded, a plain REF can continue the last search. The work areas 51D3H-51EBH lie after the file.

The page shows every byte of the file once, in address order. Calls into BASIC/CMD (5700H up) are linked only where the BASIC page has a row with the right bytes at that address.

REF Parameters (from the code)

FormWhat it does
REFLists the next line after the last one shown that holds the last item looked for (mode 3). SYNTAX ERROR if there is none; TEXT END when no further line holds it.
REF @nThe same, from line n on.
REF name / REF numberEvery line that uses the variable name (1 or 2 characters, in all its forms: alone, with $ % ! #, and as an array) or the number (up to 5 digits; any number in the text counts, leading zeros ignored) (mode 2).
REF "text / REF =textEvery line holding the up to 16 bytes that follow the quote or the = (as they stand in the command line, so after = the text is tokenized) (mode 2).
REF * / REF $All line numbers used in the text, in numerical order, then all variable names in alphabetical order, each with its lines (modes 0 and 1). REF *name / REF $name start at that item. BREAK pauses, ENTER continues, the up arrow key stops.

When the character after REF is $, the output also goes to the printer (BASIC 5D6CH). Each line is shown as its number, followed by / or ( (array) and the type character when the item is used in that form, and by a count when it is used more than once.

Bug in the file: REF @n with n above the last program line ends at 4F2BH with a line address left on the stack (4F2BH).

Variables and Patched Code

Locations inside SYS12 whose contents change while it runs:

Address RangePurpose
4E0CH
1 byte
The mode: 0 find the next item, 1 report it (full report), 2 report one item, 3 find and list the next line (operand of 4E0BH; written at 4DD1H).
4E76H-4E77H
2 bytes
The number of the line being scanned or last shown; FFFFH = start at the top (operand of 4E75H; written at 4D1DH, 4E17H, 50E7H).
4E7AH-4E7BH
2 bytes
The address of the line being scanned (operand of 4E79H; written at 4F70H).
4ED9H-4EDAH
2 bytes
The count of one counter while it is printed (operand of 4ED8H; written at 4E9CH).
4EEFH-4EF0H
2 bytes
The end of the list of up to 32 line addresses at 4200H-423FH (operand of 4EEEH; written at 512AH, 5182H).
4EF2H-4EF3H
2 bytes
The list's next entry (operand of 4EF1H; written at 4E6DH, 5185H).
4F6DH
1 byte
CAH (JP Z) or C3H (JP) after a match: the line is reported at its end (written at 4DF0H, 50DDH).
4F7CH
1 byte
21H (LD HL, no effect) or C3H: JP 512FH for a text search (written at 4D44H, 4D4DH).
4FBEH
1 byte
30H (JR NC, never taken) when the item is a number, 18H (JR, skip numbers) otherwise (written at 4DEBH).
4FFCH, 50A9H
1 byte each
DAH (JP C, mode 0) or C2H (JP NZ, other modes): the comparison of numbers and of names (written at 4DDAH, 4DDDH).
5021H
1 byte
38H (JR C) or 18H (JR): how a number compares with the best item so far (written at 517CH).
5085H-5086H
2 bytes
Where the last FIELD token is, so FIELD ... AS name counts the name and not AS (operand of 5084H; written at 4FB4H, cleared at 4DF6H).
51BFH-51D2H
20 bytes
The item compared, the best item found, the number collected and the first counters (see 51B2H).

Locations outside SYS12 that it reads or writes:

Address RangePurpose
3840H
1 byte
Keyboard row 6: ENTER (bit 0), BREAK (bit 2), up arrow (bit 3).
4020H
1 byte
Low byte of the ROM's cursor address: the output column (51A1H).
40A4H-40A5H
2 bytes
The ROM's pointer to the first program line.
4200H-423FH
64 bytes
The DOS sector buffer, used as the list of up to 32 line addresses.
51D3H-51EBH
25 bytes
After the file: the remaining counters (51D3H-51DAH) and the search text (51DBH-51EBH).
5D6CH
1 byte
In BASIC/CMD: $ here sends REF's output to the printer too (written at 4D04H).

Disassembly

4D00H - REF: Read the Parameter

SYS12 is called through RST 28H by BASIC's direct statement code (SYS18 555DH) with Register Pair HL = the text after REF and the return address 6445H (BASIC's end of statement) on the stack. It stays in the overlay area afterwards, so a plain REF can go on from where the last one stopped as long as no other overlay has been loaded. Forms, from the code: REF (the next line holding the last item, listed), 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 * / REF $ (every line number and variable name of the program, in order; *name / $name start at that name). A $ right after REF also sends the output to the printer.

4D00
GOSUB to BASIC 5D76H, which prints a space and starts a new output line.
4D03
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the first character after REF.
4D04
LD (5D6CH),A 32 6C 5D
Store Register A at 5D6CH in BASIC/CMD: when it is $, BASIC's print routine 5D66H sends the output to the printer as well.
4D07
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set if nothing follows REF.
4D08
If the Z FLAG is set (a plain REF), JUMP to 4D21H.
4D0A
CP 40H FE 40
Compare Register A against 40H, the character @.
4D0C
If the Z FLAG is set (@), JUMP to 4D12H to read the line number.
4D0E
CP 60H FE 60
Compare Register A against 60H, shift-@, which counts as @ too.
4D10
If the NZ FLAG is set (neither), JUMP to 4D24H.
4D12
GOSUB to the ROM's LINGET at 1E5BH, which reads the line number after the @ at Register Pair HL into Register Pair DE; Register A returns the character after it.
4D15
OR A B7
OR Register A (the character after the number) with itself: the Z FLAG is set at the end of the line.
4D16
If the NZ FLAG is set (something follows), JUMP to 4D7FH for SYNTAX ERROR.
4D18
LD A,D 7A
Load Register A with Register D, the high byte of the line number.
4D19
OR E B3
OR Register A with Register E: the Z FLAG is set for line 0.
4D1A
If the Z FLAG is set (line 0), JUMP to 4D1DH without subtracting.
4D1C
DEC DE 1B
Decrement Register Pair DE: the line number minus 1, so line n itself is searched too.
4D1D
LD (4E76H),DE ED 53 76 4E
Self-Modifying Code
Store Register Pair DE at 4E76H, the operand of the LD HL at 4E75H: the last line shown, the search starts after it.
4D21
JUMP to 4F07H to find and list the next line holding the remembered item.
4D24
CP 22H FE 22
Compare Register A against 22H, a quote: a text search.
4D26
If the Z FLAG is set (a quote), JUMP to 4D2CH.
4D28
CP D5H FE D5
Compare Register A against D5H, the BASIC token for =: a text search too.
4D2A
If the NZ FLAG is set (neither), JUMP to 4D49H: a name or a number.
4D2C
EX DE,HL EB
Text search: exchange Register Pairs DE and HL, so DE = the command line at the quote or =.
4D2D
LD HL,51DBH 21 DB 51
Load Register Pair HL with 51DBH, the search text buffer just after the file.
4D30
LD B,10H 06 10
Load Register B with 10H (16), the bytes to copy.

COPY THE SEARCH TEXT
Register Pair DE = the command line, Register Pair HL = the buffer, Register B = the bytes left.

4D32
INC DE 13
Increment Register Pair DE to the next byte of the command line.
4D33
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, a byte of the search text.
4D34
LD (HL),A 77
Store Register A at Register Pair HL in the buffer.
4D35
INC HL 23
Increment Register Pair HL to the next place in the buffer.
4D36
Decrement Register B and LOOP back to 4D32H for 16 bytes; a 00H among them ends the search text.
4D38
LD (HL),B 70
Store Register B (00H) at Register Pair HL, after the 16 bytes.
4D39
LD HL,3000H 21 00 30
Load Register Pair HL with 3000H: a length byte of 00H and a first character of 30H.
4D3C
LD (51BFH),HL 22 BF 51
Store Register Pair HL at 51BFH, the item compared.
4D3F
LD (51C5H),HL 22 C5 51
Store Register Pair HL at 51C5H, the item reported.
4D42
LD A,C3H 3E C3
Load Register A with C3H, the opcode JP, for the text search patch.
4D44
LD (4F7CH),A 32 7C 4F
Self-Modifying Code
Store Register A (C3H) at 4F7CH: the LD HL,512FH there becomes JP 512FH, so every byte of the text is compared with the search text.
4D47
JUMP to 4D9AH to report the lines holding the text.
4D49
LD B,06H 06 06
A name or a number: load Register B with 06H, one more than the longest item (5 characters).
4D4B
LD A,21H 3E 21
Load Register A with 21H, the opcode LD HL,nnnn.
4D4D
LD (4F7CH),A 32 7C 4F
Self-Modifying Code
Store Register A (21H) at 4F7CH, putting back the LD HL,512FH there (no text search).
4D50
EX DE,HL EB
Exchange Register Pairs DE and HL: DE = the command line.
4D51
LD HL,51C6H 21 C6 51
Load Register Pair HL with 51C6H, the characters of the item to report.
4D54
LD C,00H 0E 00
Load Register C with 00H: the item is not preceded by $ or *.
4D56
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, the first character.
4D57
CP 24H FE 24
Compare Register A against 24H, the character $.
4D59
If the Z FLAG is set ($), JUMP to 4D5FH for a full report.
4D5B
CP CFH FE CF
Compare Register A against CFH, the BASIC token for *.
4D5D
If the NZ FLAG is set (neither), JUMP to 4D68H.
4D5F
INC DE 13
Increment Register Pair DE past the $ or * in the command line.
4D60
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, the character after it.
4D61
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the end of the line.
4D62
If the Z FLAG is set (REF * or REF $ alone), JUMP to 4DAAH to report everything from the start.
4D64
INC C 0C
Increment Register C to 01H: report everything from this name on.
4D65
LD HL,51C0H 21 C0 51
Load Register Pair HL with 51C0H, the characters of the item to start after.
4D68
PUSH HL E5
Save Register Pair HL (the buffer for the item's characters) on the stack.
4D69
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, the item's first character.
4D6A
SUB 30H D6 30
Subtract 30H (the digit 0) from Register A, the item's first character.
4D6C
CP 0AH FE 0A
Compare Register A against 0AH: the CARRY FLAG is set for a digit.
4D6E
If the CARRY FLAG is set (a number), JUMP to 4D76H.
4D70
SUB 11H D6 11
Subtract 11H more from Register A: the letters A-Z become 00H-19H.
4D72
CP 1AH FE 1A
Compare Register A against 1AH: the NO CARRY FLAG is set if it is not a letter.
4D74
If the NO CARRY FLAG is set, JUMP to 4D7FH for SYNTAX ERROR.

COPY THE ITEM
Register Pair DE = the command line, Register Pair HL = the buffer, Register B counts down from 6.

4D76
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, a character of the item.
4D77
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the end of the line.
4D78
INC DE 13
Increment Register Pair DE (the flags are not changed).
4D79
If the Z FLAG is set (the end), JUMP to 4D82H.
4D7B
LD (HL),A 77
Store Register A (the character) at Register Pair HL in the buffer.
4D7C
INC HL 23
Increment Register Pair HL to the next place.
4D7D
Decrement Register B (the room left) and LOOP back to 4D76H.
4D7F
JUMP to the ROM's SNERR at 1997H to report SYNTAX ERROR: an item longer than 5 characters, or not a name or number.
4D82
LD A,05H 3E 05
Load Register A with 05H, to work out the item's length byte.
4D84
SUB B 90
Subtract Register B (6 minus the characters copied) from Register A: Register A = the number of characters minus 1, the length byte.
4D85
EX DE,HL EB
Exchange Register Pairs DE and HL: DE = the byte after the characters in the buffer.
4D86
POP HL E1
Restore Register Pair HL from the stack: the buffer's first character.
4D87
BIT 6,(HL) CB 76
Test bit 6 of the byte at Register Pair HL: set for a letter (a name).
4D89
If the Z FLAG is set (a line number), JUMP to 4D94H.
4D8B
CP 02H FE 02
Compare Register A (the length byte) against 02H: a variable name has 1 or 2 characters (length byte 0 or 1).
4D8D
If the NO CARRY FLAG is set (longer), JUMP to 4D7FH for SYNTAX ERROR.
4D8F
LD A,20H 3E 20
Load Register A with 20H, a space, to pad a one-letter name.
4D91
LD (DE),A 12
Store Register A (a space) at Register Pair DE, after the name: a one-letter name gets a space as its second character.
4D92
LD A,01H 3E 01
Load Register A with 01H: every name counts as two characters.
4D94
DEC HL 2B
Decrement Register Pair HL to the length byte before the characters.
4D95
LD (HL),A 77
Store Register A (the number of characters minus 1) at Register Pair HL, the length byte.
4D96
BIT 0,C CB 41
Test bit 0 of Register C: set for REF *name or REF $name.
4D98
If the NZ FLAG is set (REF *name or REF $name), JUMP to 4DA2H.
4D9A
One item: GOSUB to 5171H, which sets 5021H for the kind of item at 51C6H and empties the line list.
4D9D
LD A,02H 3E 02
Load Register A with 02H: mode 2, report one item.
4D9F
JUMP to 4E2FH to print the item and scan the program.
4DA2
LD B,00H 06 00
Load Register B with 00H, the high byte of the count in Register Pair BC.
4DA4
LD C,(HL) 4E
Load Register C with the byte at Register Pair HL, the length byte. Register Pair BC = the characters minus 1.
4DA5
INC C 0C
Increment Register C: Register Pair BC = the number of characters.
4DA6
ADD HL,BC 09
Add Register Pair BC to Register Pair HL: HL = the item's last character.
4DA7
DEC (HL) 35
Decrement the byte at Register Pair HL, the last character, so that the name itself is the first item above it.
4DA8
JUMP to 4DB0H to start the full report from the item at 51BFH.
4DAA
LD HL,0000H 21 00 00
Everything: load Register Pair HL with 0000H.
4DAD
LD (51BFH),HL 22 BF 51
Store Register Pair HL (0000H) at 51BFH, the item to start after: a length byte of 0 and a first character of 0, below every item.

4DB0H - The Full Report: the Next Item

Each round of REF * or REF $ first scans the whole program for the smallest line number or name above the last one reported (mode 0), keeping the addresses of up to 32 lines that use it in the DOS sector buffer at 4200H; then it reports that item (mode 1). Line numbers come before names. Holding BREAK pauses between items (ENTER goes on), the up arrow key stops.

4DB0
LD BC,FFFFH 01 FF FF
Load Register Pair BC with FFFFH: no item found yet (FFH FFH is above every name).
4DB3
GOSUB to 5168H, which stores Register Pair BC as the best item's characters (51C6H), sets its length byte and empties the line list.
4DB6
LD HL,3840H 21 40 38
Load Register Pair HL with 3840H, keyboard row 6 (ENTER bit 0, BREAK bit 2, up arrow bit 3).
4DB9
BIT 3,(HL) CB 5E
Test bit 3 of the byte at Register Pair HL: the up arrow key.
4DBB
If the NZ FLAG is set (held), JUMP to the ROM's keyboard scan at 002BH, whose RET returns to BASIC's end of statement: REF ends.
4DBE
BIT 2,(HL) CB 56
Test bit 2 of the byte at Register Pair HL: the BREAK key.
4DC0
If the Z FLAG is set (not held), JUMP to 4DCBH.

PAUSE
Register Pair HL = 3840H; the loop waits for ENTER (go on) or the up arrow (stop).

4DC2
BIT 3,(HL) CB 5E
Test bit 3 of the byte at Register Pair HL: the up arrow key.
4DC4
If the NZ FLAG is set (pressed), JUMP to 4DBBH to stop.
4DC7
BIT 0,(HL) CB 46
Test bit 0 of the byte at Register Pair HL: the ENTER key.
4DC9
If the Z FLAG is set (not pressed), LOOP back to 4DC2H.
4DCB
XOR A AF
Load Register A with 00H (XOR A with itself): mode 0, find the next item.
4DCC
LD DE,(40A4H) ED 5B A4 40
Load Register Pair DE with the 16-bit value at 40A4H, the ROM's pointer to the first program line.
4DD0
OR A B7
OR Register A (the mode) with itself to set the flags: the Z FLAG is set for mode 0.
4DD1
LD (4E0CH),A 32 0C 4E
Self-Modifying Code
Store Register A (the mode) at 4E0CH, the operand of the LD A,00H at 4E0BH.
4DD4
LD A,DAH 3E DA
Load Register A with DAH, the opcode JP C. LD does not change the flags.
4DD6
If the Z FLAG is set (mode 0), JUMP to 4DDAH with JP C.
4DD8
LD A,C2H 3E C2
Load Register A with C2H, the opcode JP NZ, for modes 1 to 3.
4DDA
LD (4FFCH),A 32 FC 4F
Self-Modifying Code
Store Register A at 4FFCH: mode 0 looks for items above 51BFH (JP C skips smaller ones), the other modes for the same item (JP NZ skips others).
4DDD
LD (50A9H),A 32 A9 50
Self-Modifying Code
Store Register A at 50A9H, the same test for names.
4DE0
LD A,(51C0H) 3A C0 51
Load Register A with the byte at 51C0H, the first character of the item compared.
4DE3
CP 3AH FE 3A
Compare Register A against 3AH: the CARRY FLAG is set for a digit (a line number).
4DE5
LD A,30H 3E 30
Load Register A with 30H, the opcode JR NC, which is never taken at 4FBEH. LD does not change the flags.
4DE7
If the CARRY FLAG is set (the item is a number), JUMP to 4DEBH: numbers in the text are compared.
4DE9
LD A,18H 3E 18
Load Register A with 18H, the opcode JR: numbers in the text are skipped.
4DEB
LD (4FBEH),A 32 BE 4F
Self-Modifying Code
Store Register A at 4FBEH, the opcode of the number test there.
4DEE
LD A,CAH 3E CA
Load Register A with CAH, the opcode JP Z, for the end-of-line test.
4DF0
LD (4F6DH),A 32 6D 4F
Self-Modifying Code
Store Register A at 4F6DH, putting back the JP Z,4DFCH there: no match in the line yet.
4DF3
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H, meaning no FIELD seen yet.
4DF6
LD (5085H),HL 22 85 50
Self-Modifying Code
Store Register Pair HL (0000H) at 5085H, the operand of 5084H: no FIELD seen yet.
4DF9
JUMP to 4F6BH to scan the program from the line at Register Pair DE.

4DFCH - End of a Line

Reached through the JP at 4F6DH at the end of each line, with Register Pair DE at the line's 00H end. If the line had a match (4F6DH was made a JP), its references are reported (4E80H); otherwise the scan goes on with the next line.

4DFC
LD A,(4F6DH) 3A 6D 4F
Load Register A with the byte at 4F6DH, the opcode of the end-of-line jump.
4DFF
CP C3H FE C3
Compare Register A against C3H: the Z FLAG is set if a match in this line made it JP.
4E01
If the Z FLAG is set (a match), JUMP to 4E80H to report the line.
4E04
INC DE 13
Increment Register Pair DE to the next line's link high byte.
4E05
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, the link's high byte.
4E06
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the end of the program.
4E07
DEC DE 1B
Decrement Register Pair DE back to the line's 00H end (the flags are not changed).
4E08
If the NZ FLAG is set (another line), JUMP to 4F70H to scan it.
4E0B
LD A,00H 3E 00
Self-Modifying Code
The end of the program: load Register A with the mode; the operand 4E0CH (00H in the file) is stored at 4DD1H.
4E0D
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set for mode 0.
4E0E
If the Z FLAG is set (mode 0), JUMP to 4E28H.
4E10
PUSH AF F5
Save Register Pair AF (Register A = the mode) on the stack.
4E11
GOSUB to BASIC 5D79H, which starts a new output line.
4E14
LD HL,FFFFH 21 FF FF
Load Register Pair HL with FFFFH, meaning start at the top.
4E17
LD (4E76H),HL 22 76 4E
Self-Modifying Code
Store Register Pair HL (FFFFH) at 4E76H, the last line shown: a plain REF starts at the top again.
4E1A
POP AF F1
Restore Register Pair AF from the stack: Register A = the mode.
4E1B
DEC A 3D
Decrement Register A: the Z FLAG is set for mode 1.
4E1C
If the Z FLAG is set (mode 1, the full report), LOOP back to 4DB0H for the next item.
4E1E
DEC A 3D
Decrement Register A: the Z FLAG is set for mode 2.
4E1F
RET Z C8
If the Z FLAG is set (mode 2, one item), RETURN: done.
4E20
LD B,09H 06 09
Mode 3 with no further line: load Register B with 09H, the length of the TEXT END message.
4E22
LD HL,51B6H 21 B6 51
Load Register Pair HL with 51B6H, the message TEXT END.
4E25
JUMP to BASIC 5D97H, which prints Register B characters at Register Pair HL; its RET ends REF.
4E28
LD A,(51C6H) 3A C6 51
The end of a mode 0 scan: load Register A with the byte at 51C6H, the best item's first character.
4E2B
INC A 3C
Increment Register A: the Z FLAG is set if it is still FFH, nothing found.
4E2C
RET Z C8
If the Z FLAG is set (every item reported), RETURN: the full report is complete.
4E2D
LD A,01H 3E 01
Load Register A with 01H: mode 1, report the item found.
4E2F
PUSH AF F5
Save Register Pair AF (Register A = the mode, 1 or 2) on the stack.
4E30
LD HL,51C5H 21 C5 51
Load Register Pair HL with 51C5H, the length byte of the item to report.
4E33
LD C,(HL) 4E
Load Register C with the byte at Register Pair HL, the length byte.
4E34
INC C 0C
Increment Register C: the number of characters.
4E35
LD A,(4F7CH) 3A 7C 4F
Load Register A with the byte at 4F7CH, the opcode there.
4E38
CP C3H FE C3
Compare Register A against C3H: the Z FLAG is set for a text search.
4E3A
LD A,06H 3E 06
Load Register A with 06H, the spaces printed when no name is shown. LD does not change the flags.
4E3C
If the Z FLAG is set (a text search), JUMP to 4E53H: no name is shown.
4E3E
PUSH HL E5
Save Register Pair HL (51C5H, the length byte) on the stack.
4E3F
INC HL 23
Increment Register Pair HL to the item's first character (51C6H).
4E40
LD A,05H 3E 05
Load Register A with 05H, the width of the item's column.
4E42
SUB C 91
Subtract Register C (the characters) from Register A: the spaces needed to right-align the item.
4E43
CALL NZ,5D57H C4 57 5D
If the NZ FLAG is set (spaces needed), GOSUB to BASIC 5D57H, which prints Register A spaces.
4E46
LD B,C 41
Load Register B with Register C, the number of characters.
4E47
GOSUB to BASIC 5D97H, which prints Register B characters at Register Pair HL: the item.
4E4A
POP HL E1
Restore Register Pair HL from the stack: 51C5H.
4E4B
LD DE,51BFH 11 BF 51
Load Register Pair DE with 51BFH, the item compared.
4E4E
INC C 0C
Increment Register C: the characters plus the length byte.
4E4F
LDIR ED B0
LDIR: copy BC bytes (Register B is 00H after 5D97H) from Register Pair HL (the item reported) to Register Pair DE (51BFH): the next round looks for items above it.
4E51
LD A,01H 3E 01
Load Register A with 01H, one space after the item.
4E53
CALL 5D57H CD 57 5D
GOSUB to BASIC 5D57H, which prints Register A spaces.
4E56
LD HL,51D1H 21 D1 51
Load Register Pair HL with 51D1H, the ten reference counters.
4E59
LD B,0AH 06 0A
Load Register B with 0AH (10), the counters to clear.
4E5B
LD (HL),00H 36 00
Store 00H at Register Pair HL, clearing a counter.
4E5D
INC HL 23
Increment Register Pair HL to the next counter.
4E5E
Decrement Register B and LOOP back to 4E5BH for all ten.
4E60
POP AF F1
Restore Register Pair AF from the stack: Register A = the mode.
4E61
CP 01H FE 01
Compare Register A against 01H: the Z FLAG is set for mode 1.
4E63
If the NZ FLAG is set (mode 2), JUMP to 4DCCH to scan the whole program.
4E66
LD HL,4200H 21 00 42
Mode 1: load Register Pair HL with 4200H, the list of line addresses found in mode 0.
4E69
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of a listed line's address.
4E6A
INC HL 23
Increment Register Pair HL to the high byte of the listed line's address.
4E6B
LD D,(HL) 56
Load Register D with the byte at Register Pair HL. Register Pair DE = the line to scan.
4E6C
INC HL 23
Increment Register Pair HL to the next entry of the list.
4E6D
LD (4EF2H),HL 22 F2 4E
Self-Modifying Code
Store Register Pair HL (the next entry) at 4EF2H, the operand of the LD HL at 4EF1H.
4E70
JUMP to 4DD0H to scan from the line at Register Pair DE (Register A = 1, mode 1).
4E73
POP AF F1
Mode 3, a line found: restore Register Pair AF from the stack, discarding the top word, a return address the listing does not use (LIST4 ends at READY).
4E74
POP AF F1
Restore Register Pair AF from the stack, discarding the next word as well, so that the two words pushed below are what LIST4 finds.
4E75
LD HL,0000H 21 00 00
Self-Modifying Code
Load Register Pair HL with the line's number; the operand 4E76H (0000H in the file) is stored at 50E7H, 4D1DH and 4E17H.
4E78
PUSH HL E5
Push Register Pair HL (the line's number): the last line to list.
4E79
LD HL,0000H 21 00 00
Self-Modifying Code
Load Register Pair HL with the line's address; the operand 4E7AH (0000H in the file) is stored at 4F70H.
4E7C
PUSH HL E5
Push Register Pair HL (the line's address): the first line to list.
4E7D
JUMP to LIST4 at 2B33H inside the ROM's LIST routine, which lists the line and returns to BASIC.

4E80H - Report a Line

Prints the line's number once for every kind of use found in the line: the name alone, with $ % ! # (the type characters at 51B2H-51B5H), and each of these as an array (followed by an opening parenthesis, shown with ( instead of /), with the count when it is used more than once. A line-number item or a text search has only the first counter. Register Pair DE is the text pointer at the line's end.

4E80
LD A,(4E0CH) 3A 0C 4E
Load Register A with the byte at 4E0CH, the mode (the operand of 4E0BH).
4E83
CP 03H FE 03
Compare Register A against 03H: the Z FLAG is set for mode 3 (plain REF).
4E85
If the Z FLAG is set, JUMP to 4E73H to list the line.
4E87
PUSH AF F5
Save Register Pair AF (Register A = the mode) on the stack.
4E88
PUSH DE D5
Save Register Pair DE (the text pointer at the line's end) on the stack.
4E89
LD A,(51C6H) 3A C6 51
Load Register A with the byte at 51C6H, the reported item's first character.
4E8C
LD BC,0100H 01 00 01
Load Register Pair BC with 0100H: Register B = 1 counter, Register C = 0, the counter's number.
4E8F
CP 41H FE 41
Compare Register A against 41H: the NO CARRY FLAG is set for a letter (a name).
4E91
If the CARRY FLAG is set (a number or text), JUMP to 4E95H with one counter.
4E93
LD B,0AH 06 0A
Load Register B with 0AH (10): a name has ten counters.
4E95
LD HL,51D1H 21 D1 51
Load Register Pair HL with 51D1H, the first counter.

COUNTER LOOP
Register Pair HL = the counter, Register C = its number (0-9), Register B = the counters left.

4E98
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the counter: how often the item was used in this form in the line.
4E99
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set if it was not used in this form.
4E9A
If the Z FLAG is set, JUMP to 4EE3H for the next counter.
4E9C
LD (4ED9H),A 32 D9 4E
Self-Modifying Code
Store Register A (the count) at 4ED9H, the operand of the LD DE at 4ED8H.
4E9F
LD (HL),00H 36 00
Store 00H at Register Pair HL, clearing the counter for the next line.
4EA1
PUSH HL E5
Save Register Pair HL (the counter's address) on the stack.
4EA2
PUSH BC C5
Save Register Pair BC (the counters left and the counter's number) on the stack.
4EA3
GOSUB to 519EH, which prints a space and starts a new, indented line when the column is 53 or more.
4EA6
LD DE,(4E76H) ED 5B 76 4E
Load Register Pair DE with the 16-bit value at 4E76H, the line's number (the operand of 4E75H).
4EAA
GOSUB to BASIC 5D8EH, which prints Register Pair DE in decimal.
4EAD
POP BC C1
Restore Register Pair BC from the stack: Register C = the counter's number.
4EAE
LD A,C 79
Load Register A with Register C, the counter's number.
4EAF
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set for counter 0, the plain name.
4EB0
PUSH BC C5
Save Register Pair BC on the stack again (the flags are not changed).
4EB1
If the NZ FLAG is set (not the first counter), JUMP to 4EBBH.
4EB3
LD A,(4ED9H) 3A D9 4E
The first counter: load Register A with the byte at 4ED9H, the count.
4EB6
CP 02H FE 02
Compare Register A against 02H: the CARRY FLAG is set if the item was used once.
4EB8
If the CARRY FLAG is set, JUMP to 4EE1H: the line number alone is enough.
4EBA
LD A,C 79
Load Register A with Register C (00H), the counter's number.
4EBB
CP 05H FE 05
Compare Register A (the counter's number) against 05H: the NO CARRY FLAG is set for an array counter (5-9).
4EBD
LD A,2FH 3E 2F
Load Register A with 2FH, a slash, the mark of a plain use. LD does not change the flags.
4EBF
If the CARRY FLAG is set (counters 0-4), JUMP to 4EC7H with the slash.
4EC1
LD A,C 79
Load Register A with Register C, the counter's number.
4EC2
SUB 05H D6 05
Subtract 05H from Register A: the type number (0 none, 1 $, 2 %, 3 !, 4 #).
4EC4
LD C,A 4F
Load Register C with Register A, the type number.
4EC5
LD A,28H 3E 28
Load Register A with 28H, an opening parenthesis, the mark of an array use.
4EC7
GOSUB to BASIC 5D66H, which prints the character in Register A.
4ECA
LD A,C 79
Load Register A with Register C, the type number.
4ECB
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set for no type character.
4ECC
If the Z FLAG is set (no type character), JUMP to 4ED8H.
4ECE
LD B,00H 06 00
Load Register B with 00H, so Register Pair BC = the type number.
4ED0
LD HL,51B1H 21 B1 51
Load Register Pair HL with 51B1H, one byte before the type characters $ % ! #.
4ED3
ADD HL,BC 09
Add Register Pair BC (the type number) to Register Pair HL: HL = the type character.
4ED4
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the type character.
4ED5
GOSUB to BASIC 5D66H, which prints the type character in Register A.
4ED8
LD DE,0000H 11 00 00
Self-Modifying Code
Load Register Pair DE with the count; the operand 4ED9H (0000H in the file) is stored at 4E9CH (its high byte stays 00H).
4EDB
LD A,E 7B
Load Register A with Register E, the count of uses in this form.
4EDC
CP 02H FE 02
Compare Register A against 02H: the NO CARRY FLAG is set for 2 or more.
4EDE
If the NO CARRY FLAG is set, GOSUB to BASIC 5D8EH, which prints the count in Register Pair DE.
4EE1
POP BC C1
Restore Register Pair BC from the stack: the counters left and the counter's number.
4EE2
POP HL E1
Restore Register Pair HL from the stack: the counter's address.
4EE3
INC HL 23
Increment Register Pair HL to the next counter.
4EE4
INC C 0C
Increment Register C, the next counter's number.
4EE5
Decrement Register B (the counters left) and LOOP back to 4E98H.
4EE7
POP DE D1
Restore Register Pair DE from the stack: the text pointer at the line's end.
4EE8
POP AF F1
Restore Register Pair AF from the stack: Register A = the mode.
4EE9
CP 01H FE 01
Compare Register A against 01H: the Z FLAG is set for mode 1.
4EEB
If the NZ FLAG is set (mode 2), JUMP to 4DD0H to go on with the next line.
4EEE
LD BC,0000H 01 00 00
Self-Modifying Code
Load Register Pair BC with the end of the line list; the operand 4EEFH (0000H in the file) is stored at 512AH and 5182H.
4EF1
LD HL,0000H 21 00 00
Self-Modifying Code
Load Register Pair HL with the next entry of the list; the operand 4EF2H (0000H in the file) is stored at 4E6DH and 5185H.
4EF4
OR A B7
OR Register A with itself to clear the CARRY FLAG for the subtraction.
4EF5
SBC HL,BC ED 42
Subtract Register Pair BC (the end) from Register Pair HL (the next entry): the Z FLAG is set when the list is used up.
4EF7
ADD HL,BC 09
Add Register Pair BC back: HL = the next entry again (the Z FLAG is kept).
4EF8
If the NZ FLAG is set (lines left in the list), JUMP to 4E69H for the next one.
4EFB
LD BC,4240H 01 40 42
Load Register Pair BC with 4240H, the end of a full list (32 lines).
4EFE
OR A B7
OR Register A with itself to clear the CARRY FLAG for the subtraction.
4EFF
SBC HL,BC ED 42
Subtract Register Pair BC from Register Pair HL: the Z FLAG is set if the list was full, so more lines may follow.
4F01
If the Z FLAG is set (the list was full), JUMP to 4DD0H to scan the rest of the program from here.
4F04
JUMP to 4E0BH: the item is done; Register A decides what follows.

4F07H - Plain REF and REF @n

Finds the first line after the last one shown (or from line n on) that holds the remembered item, in mode 3, and lists it.

4F07
LD A,(4F7CH) 3A 7C 4F
Load Register A with the byte at 4F7CH, the opcode there (C3H during a text search).
4F0A
CP C3H FE C3
Compare Register A against C3H: the Z FLAG is set for a text search.
4F0C
LD A,(51C6H) 3A C6 51
Load Register A with the byte at 51C6H, the remembered item's first character. LD does not change the flags.
4F0F
If the NZ FLAG is set (not a text search), JUMP to 4F15H.
4F11
LD A,(51DBH) 3A DB 51
A text search: load Register A with the byte at 51DBH, the first character of the search text.
4F14
DEC A 3D
Decrement Register A, so that the INC below gives the Z FLAG for 00H (no search text).
4F15
INC A 3C
Increment Register A: the Z FLAG is set if the item is FFH (none remembered), or for a text search if the text is empty.
4F16
If the Z FLAG is set (nothing to look for), JUMP to the ROM's SNERR at 1997H to report SYNTAX ERROR.
4F19
LD BC,(4E76H) ED 4B 76 4E
Load Register Pair BC with the 16-bit value at 4E76H, the number of the last line shown.
4F1D
LD DE,(40A4H) ED 5B A4 40
Load Register Pair DE with the 16-bit value at 40A4H, the ROM's pointer to the first program line.
4F21
LD A,B 78
Load Register A with Register B, the high byte of the last line shown.
4F22
AND C A1
AND Register A with Register C: FFH only for FFFFH.
4F23
INC A 3C
Increment Register A: the Z FLAG is set for FFFFH, start at the top.
4F24
If the Z FLAG is set, JUMP to 4F41H with Register Pair DE = the first line.
4F26
EX DE,HL EB
Exchange Register Pairs DE and HL: HL = the line to test.

FIND THE LINE AFTER THE LAST ONE SHOWN
Register Pair HL = the line, Register Pair BC = the last line shown.

4F27
PUSH HL E5
Save Register Pair HL (the line's address) on the stack.
4F28
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of the line's link.
4F29
INC HL 23
Increment Register Pair HL to the high byte of the line's link.
4F2A
OR (HL) B6
OR Register A with the byte at Register Pair HL: the Z FLAG is set at the end of the program.
4F2B
Bug in the file: if the Z FLAG is set (the end of the program), JUMP to 4E20H for TEXT END, with the line's address still on the stack from 4F27H. BASIC 5D97H's RET then goes to that address (the program's end marker) instead of back to BASIC.
4F2E
INC HL 23
Increment Register Pair HL to the line number's low byte.
4F2F
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the line number's low byte.
4F30
INC HL 23
Increment Register Pair HL to the high byte of the line number.
4F31
LD D,(HL) 56
Load Register D with the byte at Register Pair HL. Register Pair DE = the line's number.
4F32
INC HL 23
Increment Register Pair HL to the line's text.
4F33
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, a byte of the line.
4F34
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the line's 00H end.
4F35
INC HL 23
Increment Register Pair HL (the flags are not changed).
4F36
If the NZ FLAG is set, LOOP back to 4F33H: Register Pair HL ends at the next line.
4F38
EX DE,HL EB
Exchange Register Pairs DE and HL: HL = the line's number, DE = the next line.
4F39
SBC HL,BC ED 42
Subtract Register Pair BC (the last line shown) from Register Pair HL, with the CARRY FLAG (clear after the OR at 4F34H): the Z FLAG is set if equal, the CARRY FLAG if this line comes before.
4F3B
POP HL E1
Restore Register Pair HL from the stack: the line's address. POP does not change the flags.
4F3C
If the Z FLAG is set (the last line shown), JUMP to 4F41H with Register Pair DE = the line after it.
4F3E
EX DE,HL EB
Exchange Register Pairs DE and HL: DE = this line, HL = the next.
4F3F
If the CARRY FLAG is set (this line comes before), LOOP back to 4F27H with the next line.
4F41
LD A,03H 3E 03
Load Register A with 03H: mode 3, find and list one line.
4F43
JUMP to 4DD0H to scan from the line at Register Pair DE.

4F46H - Scan the Text

Register Pair DE walks through the program's text. Strings, REM and ' comments, DATA, constants after & and decimal fractions are skipped; line numbers (digit strings) and variable names are collected and compared with the item. A match counts in the counters at 51D1H-51DAH and turns the JP Z,4DFCH at 4F6DH into JP 4DFCH, so the line is reported at its end.

4F46
LD BC,4F77H 01 77 4F
A quote: load Register Pair BC with 4F77H, the scan's next-byte entry.
4F49
PUSH BC C5
Push Register Pair BC (4F77H) as the return address after the string.
4F4A
LD B,A 47
Load Register B with Register A, the quote character that ends the string.

SKIP A STRING
Register Pair DE steps through the string; Register B = the closing quote.

4F4B
INC DE 13
Increment Register Pair DE to the next byte of the line.
4F4C
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE.
4F4D
CP B B8
Compare Register A with Register B, the closing quote.
4F4E
RET Z C8
If the Z FLAG is set (the string ends), RETURN (to 4F77H, or to 4F63H when called from DATA).
4F4F
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the line's 00H end.
4F50
If the NZ FLAG is set (more of the string), LOOP back to 4F4BH.
4F52
POP AF F1
The line ended inside the string: restore Register Pair AF from the stack, discarding the return address.
4F53
JUMP to 4F6AH for the next line, Register Pair DE at the 00H.

SKIP DATA
Register Pair DE steps through the DATA statement to its colon or the line's end.

4F55
INC DE 13
Increment Register Pair DE to the next byte of the DATA statement.
4F56
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE.
4F57
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the line's end.
4F58
If the Z FLAG is set, JUMP to 4F6AH for the next line.
4F5A
CP 3AH FE 3A
Compare Register A against 3AH, a colon, the end of the statement.
4F5C
If the Z FLAG is set, JUMP to 4F77H to go on with the next statement.
4F5E
CP 22H FE 22
Compare Register A (the DATA byte) against 22H, a quote.
4F60
If the Z FLAG is set (a quoted DATA item), GOSUB to 4F4AH to skip the string.
4F63
LOOP back to 4F55H for the next byte of the DATA statement.

SKIP A REMARK
REM or ': Register Pair DE steps to the line's 00H end.

4F65
INC DE 13
Increment Register Pair DE to the next byte of the remark.
4F66
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE.
4F67
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the line's end.
4F68
If the NZ FLAG is set (not the end), LOOP back to 4F65H.
4F6A
INC DE 13
Increment Register Pair DE past the line's 00H end, to the next line's link.
4F6B
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, the low byte of the link (4DF9H enters here at the first line).
4F6C
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set if the low byte is 00H.
4F6D
Self-Modifying Code
If the Z FLAG is set, JUMP to 4DFCH, which ends the line or the program. The opcode 4F6DH is CAH (JP Z) or, after a match in the line, C3H (JP, always to 4DFCH); set at 4DF0H and 50DDH.
4F70
LD (4E7AH),DE ED 53 7A 4E
Self-Modifying Code
Store Register Pair DE (the line's address) at 4E7AH, the operand of the LD HL at 4E79H.
4F74
INC DE 13
Increment Register Pair DE: 1 of 3 over the link and the line number.
4F75
INC DE 13
Increment Register Pair DE: 2 of 3 over the link and the line number.
4F76
INC DE 13
Increment Register Pair DE: 3 of 3, to the line number's high byte.

BYTE LOOP
Register Pair DE = the byte of the line being looked at.

4F77
INC DE 13
Increment Register Pair DE to the next byte of the line.
4F78
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE.
4F79
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the line's 00H end.
4F7A
If the Z FLAG is set, JUMP to 4F6AH for the next line.
4F7C
LD HL,512FH 21 2F 51
Self-Modifying Code
Load Register Pair HL with 512FH, which does nothing here; for a text search the opcode 4F7CH is C3H and this is JP 512FH, comparing every byte with the search text (set at 4D44H and 4D4DH).
4F7F
CP 41H FE 41
Compare Register A (the byte) against 41H: the NO CARRY FLAG is set for a letter or a token.
4F81
If the NO CARRY FLAG is set (a letter or token), JUMP to 4F9BH.
4F83
CP 30H FE 30
Compare Register A against 30H: the NO CARRY FLAG is set for a digit or 3AH-40H.
4F85
If the NO CARRY FLAG is set (a digit or 3AH-40H), JUMP to 4FBAH.
4F87
CP 20H FE 20
Compare Register A (the byte of the line) against 20H, a space.
4F89
If the Z FLAG is set, JUMP to 4F77H for the next byte.
4F8B
CP 22H FE 22
Compare Register A (the byte of the line) against 22H, a quote.
4F8D
If the Z FLAG is set, JUMP to 4F46H to skip the string.
4F8F
CP 26H FE 26
Compare Register A against 26H, the character & (a hexadecimal or octal constant).
4F91
If the Z FLAG is set (&), JUMP to 504BH to skip the constant.
4F94
CP 2EH FE 2E
Compare Register A against 2EH, a period (a fraction such as .5).
4F96
If the Z FLAG is set, JUMP to 4FE1H to skip the digits.
4F99
Anything else: JUMP to 4F77H for the next byte.
4F9B
LD C,A 4F
Load Register C with Register A, the letter or token. LD does not change the flags (the Z FLAG is from CP 41H).
4F9C
If the Z FLAG is set (the letter A), JUMP to 5073H: it may be the AS of a FIELD.
4F9F
CP 5BH FE 5B
Compare Register A against 5BH: the CARRY FLAG is set for a letter B-Z.
4FA1
If the CARRY FLAG is set, JUMP to 5091H: a name.
4FA4
CP 93H FE 93
Compare Register A against 93H, the REM token.
4FA6
If the Z FLAG is set, JUMP to 4F65H to skip the remark.
4FA8
CP FBH FE FB
Compare Register A against FBH, the token for ' (a remark).
4FAA
If the Z FLAG is set, JUMP to 4F65H to skip the remark.
4FAC
CP 88H FE 88
Compare Register A against 88H, the DATA token.
4FAE
If the Z FLAG is set, JUMP to 4F55H to skip the DATA.
4FB0
CP A3H FE A3
Compare Register A against A3H, the FIELD token.
4FB2
If the NZ FLAG is set (another token), JUMP to 4F77H.
4FB4
LD (5085H),DE ED 53 85 50
Self-Modifying Code
Store Register Pair DE (where the FIELD token is) at 5085H, the operand of 5084H, so FIELD ... AS name counts the name and not AS.
4FB8
JUMP to 4F77H for the next byte at Register Pair DE.
4FBA
CP 3AH FE 3A
Compare Register A against 3AH: the NO CARRY FLAG is set for 3AH-40H (not a digit).
4FBC
If the NO CARRY FLAG is set (not a digit), JUMP to 4F77H.
4FBE
Self-Modifying Code
A digit: JR NC to 4FE1H is never taken here (the CARRY FLAG is set). With opcode 18H at 4FBEH, set at 4DEBH when the item is not a number, it is a JUMP to 4FE1H that skips every number.
4FC0
LD HL,51CBH 21 CB 51
Load Register Pair HL with 51CBH, the buffer for the number found in the text.
4FC3
LD B,06H 06 06
Load Register B with 06H, one more than the digits kept.
4FC5
CP 30H FE 30
Compare Register A (the first digit) against 30H, the digit 0.
4FC7
If the NZ FLAG is set (not a leading 0), JUMP to 4FD9H.
4FC9
LD (HL),A 77
Store Register A (the 0) at Register Pair HL, the buffer's first digit.
4FCA
GOSUB to 514BH, which moves Register Pair DE to the next byte that is not a space, 09H or 0AH, in Register A.
4FCD
CP 30H FE 30
Compare Register A (the next byte) against 30H, another 0.
4FCF
If the Z FLAG is set, LOOP back to 4FCAH: leading zeros count as a single 0.

COLLECT THE DIGITS
Register Pair HL = the buffer, Register B counts down the room left.

4FD1
CP 30H FE 30
Compare Register A against 30H: the CARRY FLAG is set below the digit 0.
4FD3
If the CARRY FLAG is set (the number ends), JUMP to 4FEEH.
4FD5
CP 3AH FE 3A
Compare Register A against 3AH: the NO CARRY FLAG is set above the digit 9.
4FD7
If the NO CARRY FLAG is set (the number ends), JUMP to 4FF2H.
4FD9
LD (HL),A 77
Store Register A (the digit) at Register Pair HL in the buffer.
4FDA
INC HL 23
Increment Register Pair HL to the next place in the buffer.
4FDB
GOSUB to 514BH for the next byte that is not a blank, in Register A.
4FDE
Decrement Register B and LOOP back to 4FD1H for up to 6 digits.
4FE0
DEC DE 1B
Too many digits for a line number: decrement Register Pair DE, stepping back, and skip the rest.

SKIP DIGITS
Register Pair DE steps over the remaining digits.

4FE1
GOSUB to 514BH for the next byte that is not a blank, in Register A.
4FE4
CP 3AH FE 3A
Compare Register A against 3AH: the NO CARRY FLAG is set above the digit 9.
4FE6
If the NO CARRY FLAG is set (above 9), JUMP to 4FECH.
4FE8
CP 30H FE 30
Compare Register A against 30H: the NO CARRY FLAG is set for a digit.
4FEA
If the NO CARRY FLAG is set, LOOP back to 4FE1H.
4FEC
JUMP to 4F78H to look at the byte in Register A.
4FEE
CP 2EH FE 2E
Compare Register A against 2EH, a period (the number has a fraction, so it is no line number).
4FF0
If the Z FLAG is set, JUMP to 4FE1H to skip the rest.
4FF2
LD A,05H 3E 05
Load Register A with 05H, to work out the number's length byte.
4FF4
SUB B 90
Subtract Register B (the room left) from Register A.
4FF5
ADC A,00H CE 00
Add 00H with the CARRY FLAG (set when the loop ended below 0) to Register A: the number of digits minus 1, the length byte.
4FF7
LD C,A 4F
Load Register C with Register A, the length byte of the number found.
4FF8
LD HL,(51BFH) 2A BF 51
Load Register Pair HL with the 16-bit value at 51BFH: Register L = the length byte of the item compared, Register H = its first character.
4FFB
CP L BD
Compare Register A (this number's length byte) with Register L: the CARRY FLAG is set if this number is shorter.
4FFC
Self-Modifying Code
JUMP to 4F78H (skip this number) under the condition set at 4DDAH: JP C (DAH, mode 0: a shorter number is smaller) or JP NZ (C2H, other modes: a different length is another number).
4FFF
If the NZ FLAG is set (mode 0 and longer, so larger), JUMP to 501CH.
5001
LD A,(51CBH) 3A CB 51
The same length: load Register A with the byte at 51CBH, the number's first digit.
5004
CP H BC
Compare Register A with Register H, the item's first digit.
5005
If the NZ FLAG is set (they differ), JUMP to 4FFCH to decide with these flags.
5007
LD IY,51C1H FD 21 C1 51
Load Index Register IY with 51C1H, the rest of the item's digits.
500B
GOSUB to 5189H, which compares Register C digits at 51CCH with those at Index Register IY: the Z FLAG is set if equal.
500E
If the NZ FLAG is set (they differ), JUMP to 4FFCH to decide.
5010
LD HL,51D1H 21 D1 51
The same number: load Register Pair HL with 51D1H, the first counter.
5013
LD A,(4E0CH) 3A 0C 4E
Load Register A with the byte at 4E0CH, the mode.
5016
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set for mode 0.
5017
If the NZ FLAG is set (modes 1-3), JUMP to 50D9H to count the use.
501A
Mode 0: JUMP to 4FECH; only numbers above the item matter.
501C
LD HL,(51C5H) 2A C5 51
Mode 0, a number above the last item: load Register Pair HL with the 16-bit value at 51C5H: Register L = the best item's length byte, Register H = its first character.
501F
LD A,C 79
Load Register A with Register C, this number's length byte.
5020
CP L BD
Compare Register A with Register L: the CARRY FLAG is set if this number is shorter than the best.
5021
Self-Modifying Code
The opcode 5021H, set at 517CH, decides: JR C,5037H (38H) when the best item so far is a number (JUMP to 5037H if this one is smaller), or JR 5037H (18H) when it is a name (always JUMP, as any number comes first).
5023
If the NZ FLAG is set (longer, so larger), JUMP to 4F78H.
5026
LD A,(51CBH) 3A CB 51
The same length: load Register A with the byte at 51CBH, this number's first digit.
5029
CP H BC
Compare Register A with Register H, the best item's first digit.
502A
If the NZ FLAG is set, JUMP to 5021H to decide with these flags.
502C
LD IY,51C7H FD 21 C7 51
Load Index Register IY with 51C7H, the rest of the best item's digits.
5030
GOSUB to 5189H, which compares Register C digits at 51CCH with those at Index Register IY.
5033
If the NZ FLAG is set (they differ), JUMP to 5021H to decide.
5035
The same number as the best: JUMP to 5048H to remember the line.
5037
LD A,C 79
A new best number: load Register A with Register C, its length byte.
5038
INC C 0C
Increment Register C: the number of digits to copy.
5039
PUSH DE D5
Save Register Pair DE (the text pointer) on the stack.
503A
LD HL,51CBH 21 CB 51
Load Register Pair HL with 51CBH, the digits found.
503D
LD DE,51C6H 11 C6 51
Load Register Pair DE with 51C6H, the best item's characters.
5040
LD B,00H 06 00
Load Register B with 00H, so Register Pair BC = the digits.
5042
LDIR ED B0
LDIR: copy BC bytes (the digits) from Register Pair HL (51CBH) to Register Pair DE (51C6H).
5044
POP DE D1
Restore Register Pair DE from the stack: the text pointer.
5045
GOSUB to 516EH, which stores Register A as the best item's length byte (51C5H), sets 5021H and empties the line list.
5048
JUMP to 5101H to add this line to the list at 4200H.
504B
An &: GOSUB to 514BH, which moves Register Pair DE to the next byte that is not a blank, in Register A.
504E
CP 44H FE 44
Compare Register A against 44H, the letter D.
5050
If the Z FLAG is set (&D), JUMP to 4F6AH: the rest of the line is skipped.
5053
CP 4FH FE 4F
Compare Register A against 4FH, the letter O (an octal constant).
5055
If the Z FLAG is set, JUMP to 4FE1H to skip the digits.
5058
CP 48H FE 48
Compare Register A against 48H, the letter H (a hexadecimal constant).
505A
If the NZ FLAG is set (none of them), JUMP to 5070H.

SKIP HEXADECIMAL DIGITS
Register Pair DE steps over 0-9 and A-F.

505C
GOSUB to 514BH for the next byte that is not a blank, in Register A.
505F
CP 47H FE 47
Compare Register A against 47H: the NO CARRY FLAG is set above F.
5061
If the NO CARRY FLAG is set, JUMP to 5070H: the constant ends.
5063
CP 41H FE 41
Compare Register A against 41H: the NO CARRY FLAG is set for A-F.
5065
If the NO CARRY FLAG is set, LOOP back to 505CH.
5067
CP 3AH FE 3A
Compare Register A against 3AH: the NO CARRY FLAG is set for 3AH-40H.
5069
If the NO CARRY FLAG is set, JUMP to 5070H: the constant ends.
506C
CP 30H FE 30
Compare Register A against 30H: the NO CARRY FLAG is set for a digit.
506E
If the NO CARRY FLAG is set, LOOP back to 505CH.
5070
JUMP to 4F78H to look at the byte in Register A.
5073
The letter A: GOSUB to 514BH for the next byte that is not a blank, in Register A.
5076
CP 53H FE 53
Compare Register A against 53H, the letter S (the word AS).
5078
If the NZ FLAG is set, JUMP to 5094H: a name starting with A (Register C = A).
507A
LD B,A 47
Load Register B with Register A (S), the second character if this is the name AS.
507B
GOSUB to 514BH for the next byte that is not a blank, in Register A.
507E
GOSUB to 5161H: the CARRY FLAG is set if Register A is not a letter.
5081
If the CARRY FLAG is set (no letter after AS), JUMP to 509FH: the name AS.
5083
PUSH DE D5
Save Register Pair DE (the text pointer) on the stack.
5084
LD DE,0000H 11 00 00
Self-Modifying Code
Load Register Pair DE with the position of the last FIELD token; the operand 5085H (0000H in the file) is stored at 4FB4H and cleared at 4DF6H.
5087
LD HL,(4E7AH) 2A 7A 4E
Load Register Pair HL with the 16-bit value at 4E7AH, the address of this line.
508A
OR A B7
OR Register A with itself to clear the CARRY FLAG for the subtraction.
508B
SBC HL,DE ED 52
Subtract Register Pair DE (the FIELD's position) from Register Pair HL (the line's start): the CARRY FLAG is set if the FIELD lies after the line's start, in this line.
508D
POP DE D1
Restore Register Pair DE from the stack: the text pointer. POP does not change the flags.
508E
If the NO CARRY FLAG is set (no FIELD in this line), JUMP to 509FH: the name AS.
5090
LD C,A 4F
FIELD ... AS name: load Register C with Register A, the letter after AS, the name's first character.
5091
A name: GOSUB to 514BH for the next byte that is not a blank, in Register A.
5094
LD B,20H 06 20
Load Register B with 20H, a space, the second character of a one-letter name.
5096
GOSUB to 515AH: the CARRY FLAG is set if Register A is not a letter or digit.
5099
If the CARRY FLAG is set (a one-letter name), JUMP to 50A4H.
509B
LD B,A 47
Load Register B with Register A, the name's second character.

SKIP THE REST OF THE NAME
Only the first two characters count, as in the ROM.

509C
GOSUB to 514BH for the next byte that is not a blank, in Register A.
509F
GOSUB to 515AH: the CARRY FLAG is set if Register A is not a letter or digit.
50A2
If the NO CARRY FLAG is set (the name goes on), LOOP back to 509CH.
50A4
LD HL,(51C0H) 2A C0 51
Load Register Pair HL with the 16-bit value at 51C0H: Register L = the item's first character, Register H = its second.
50A7
LD A,C 79
Load Register A with Register C, the name's first character.
50A8
CP L BD
Compare Register A with Register L: the CARRY FLAG is set if the name is smaller, the Z FLAG if the first characters match.
50A9
Self-Modifying Code
JUMP to 4F78H (skip this name) under the condition set at 4DDDH: JP C (mode 0: smaller names are skipped) or JP NZ (other modes: other names are skipped).
50AC
If the NZ FLAG is set (mode 0 and larger), JUMP to 50EEH.
50AE
LD A,B 78
Load Register A with Register B, the name's second character.
50AF
CP H BC
Compare Register A with Register H, the item's second character.
50B0
If the NZ FLAG is set, JUMP to 50A9H to decide with these flags.
50B2
LD A,(4E0CH) 3A 0C 4E
The same name: load Register A with the byte at 4E0CH, the mode.
50B5
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set for mode 0.
50B6
If the Z FLAG is set (mode 0), JUMP to 50EBH: only larger names matter.
50B8
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, the character after the name (a type character or not).
50B9
LD HL,51D5H 21 D5 51
Load Register Pair HL with 51D5H, the counter for the # form.
50BC
LD IY,51B5H FD 21 B5 51
Load Index Register IY with 51B5H, the # in the type characters.
50C0
LD B,04H 06 04
Load Register B with 04H, the four type characters.

FIND THE TYPE
Index Register IY steps back through # ! % $; Register Pair HL through their counters.

50C2
CP (IY+00H) FD BE 00
Compare Register A with the byte at Index Register IY + 00H, a type character.
50C5
If the Z FLAG is set (this type), JUMP to 50CDH with Register Pair HL = its counter.
50C7
DEC HL 2B
Decrement Register Pair HL to the counter before.
50C8
DEC IY FD 2B
Decrement Index Register IY to the type character before.
50CA
Decrement Register B (the types left) and LOOP back to 50C2H.
50CC
DEC DE 1B
No type character: Register Pair HL = 51D1H, the plain counter; decrement Register Pair DE so the next byte is read again.
50CD
GOSUB to 514BH for the next byte that is not a blank, in Register A.
50D0
CP 28H FE 28
Compare Register A against 28H, an opening parenthesis: an array.
50D2
If the NZ FLAG is set (not an array), JUMP to 50D9H.
50D4
LD BC,0005H 01 05 00
Load Register Pair BC with 0005H, the distance to the array counters.
50D7
ADD HL,BC 09
Add Register Pair BC (5) to Register Pair HL: HL = the same form's array counter.
50D8
INC DE 13
Increment Register Pair DE past the parenthesis.
50D9
INC (HL) 34
Increment the byte at Register Pair HL: one more use counted in this line.
50DA
LD HL,4F6DH 21 6D 4F
Load Register Pair HL with 4F6DH, the opcode of the end-of-line jump.
50DD
LD (HL),C3H 36 C3
Self-Modifying Code
Store C3H (JP) at Register Pair HL, 4F6DH: this line is reported at its end.
50DF
LD HL,(4E7AH) 2A 7A 4E
Load Register Pair HL with the 16-bit value at 4E7AH, the address of this line.
50E2
INC HL 23
Increment Register Pair HL: 1 of 2 to the line number.
50E3
INC HL 23
Increment Register Pair HL: 2 of 2, the line number's low byte.
50E4
LD C,(HL) 4E
Load Register C with the byte at Register Pair HL, the line number's low byte.
50E5
INC HL 23
Increment Register Pair HL to the high byte of the line number.
50E6
LD B,(HL) 46
Load Register B with the byte at Register Pair HL. Register Pair BC = the line's number.
50E7
LD (4E76H),BC ED 43 76 4E
Self-Modifying Code
Store Register Pair BC (the line's number) at 4E76H, the operand of 4E75H.
50EB
JUMP to 4F78H to look at the byte in Register A.
50EE
LD HL,(51C6H) 2A C6 51
Mode 0, a name above the last item: load Register Pair HL with the 16-bit value at 51C6H: Register L = the best item's first character, Register H = its second.
50F1
LD A,C 79
Load Register A with Register C, the name's first character.
50F2
CP L BD
Compare Register A with Register L: the CARRY FLAG is set if the name is smaller than the best.
50F3
If the CARRY FLAG is set, JUMP to 50FEH: a new best.
50F5
If the NZ FLAG is set (larger), JUMP to 4F78H.
50F8
LD A,B 78
Load Register A with Register B, the name's second character.
50F9
CP H BC
Compare Register A with Register H, the best item's second character.
50FA
If the NZ FLAG is set, JUMP to 50F3H to decide with these flags.
50FC
The same name as the best: JUMP to 5101H to remember the line.
50FE
GOSUB to 5168H, which stores Register Pair BC (the name) as the best item and empties the line list.

5101H - Remember the Line

Adds this line's address to the list at 4200H-423FH (32 lines) unless the list is full or the line is already its last entry.

5101
LD HL,(4EEFH) 2A EF 4E
Load Register Pair HL with the 16-bit value at 4EEFH, the end of the list (the operand of 4EEEH).
5104
LD BC,4240H 01 40 42
Load Register Pair BC with 4240H, the end of a full list.
5107
OR A B7
OR Register A with itself to clear the CARRY FLAG for the subtraction.
5108
SBC HL,BC ED 42
Subtract Register Pair BC from Register Pair HL: the Z FLAG is set if the list is full.
510A
ADD HL,BC 09
Add Register Pair BC back: HL = the end of the list again.
510B
If the Z FLAG is set (the list is full), JUMP to 50EBH.
510D
LD BC,4200H 01 00 42
Load Register Pair BC with 4200H, the start of the list.
5110
OR A B7
OR Register A with itself to clear the CARRY FLAG for the subtraction.
5111
SBC HL,BC ED 42
Subtract Register Pair BC from Register Pair HL: the Z FLAG is set if the list is empty.
5113
ADD HL,BC 09
Add Register Pair BC back: HL = the end of the list.
5114
LD BC,(4E7AH) ED 4B 7A 4E
Load Register Pair BC with the 16-bit value at 4E7AH, this line's address. LD does not change the flags.
5118
If the Z FLAG is set (empty), JUMP to 5126H to add it.
511A
DEC HL 2B
Decrement Register Pair HL to the last entry's high byte.
511B
LD A,B 78
Load Register A with Register B, the line's high byte.
511C
CP (HL) BE
Compare Register A with the byte at Register Pair HL.
511D
If the NZ FLAG is set (another line), JUMP to 5125H.
511F
DEC HL 2B
Decrement Register Pair HL to the last entry's low byte.
5120
LD A,C 79
Load Register A with Register C, the line's low byte.
5121
CP (HL) BE
Compare Register A with the byte at Register Pair HL.
5122
INC HL 23
Increment Register Pair HL back to the high byte (the flags are not changed).
5123
If the Z FLAG is set (already the last entry), JUMP to 50EBH.
5125
INC HL 23
Increment Register Pair HL to the end of the list.
5126
LD (HL),C 71
Store Register C (the line's low byte) at Register Pair HL.
5127
INC HL 23
Increment Register Pair HL to the high byte of the new entry.
5128
LD (HL),B 70
Store Register B (the line's high byte) at Register Pair HL.
5129
INC HL 23
Increment Register Pair HL: the new end of the list.
512A
LD (4EEFH),HL 22 EF 4E
Self-Modifying Code
Store Register Pair HL at 4EEFH, the end of the list (the operand of 4EEEH).
512D
JUMP to 50EBH to go on scanning at Register Pair DE.

512FH - Text Search

Reached through JP 512FH at 4F7CH with Register A = the current byte of the line. Compares the bytes from there with the search text at 51DBH until its 00H end; a match counts in 51D1H and the scan goes on after it.

512F
LD HL,51DBH 21 DB 51
Load Register Pair HL with 51DBH, the search text.
5132
CP (HL) BE
Compare Register A (the line's byte) with the byte at Register Pair HL, the first byte of the search text.
5133
If the NZ FLAG is set (no match here), JUMP to 5148H.
5135
PUSH DE D5
Save Register Pair DE (the position in the line) on the stack.

COMPARE LOOP
Register Pair DE steps through the line, Register Pair HL through the search text.

5136
INC DE 13
Increment Register Pair DE to the line's next byte.
5137
INC HL 23
Increment Register Pair HL to the search text's next byte.
5138
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the search text's next byte.
5139
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set at the search text's 00H end.
513A
If the NZ FLAG is set (more to compare), JUMP to 5143H.
513C
POP HL E1
A match: restore Register Pair HL from the stack, discarding the saved position (Register Pair DE is past the match).
513D
LD HL,51D1H 21 D1 51
Load Register Pair HL with 51D1H, the first counter.
5140
JUMP to 50D9H to count the use and mark the line.
5143
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, the line's byte.
5144
CP (HL) BE
Compare Register A with the byte at Register Pair HL, the search text's byte.
5145
If the Z FLAG is set (it matches), LOOP back to 5136H.
5147
POP DE D1
Restore Register Pair DE from the stack: the position where the compare began.
5148
JUMP to 4F77H for the next byte of the line at Register Pair DE.

514BH - Small Helpers

514BH: the next byte of the line in Register A, skipping spaces, 09H and 0AH. 515AH: CARRY if Register A is not a letter or digit; 5161H: CARRY if it is not a letter. 5168H/516EH: store the best item's first two characters (Register Pair BC) and length byte, and empty the line list; 5171H: set 5021H for the kind of item.

514B
INC DE 13
Increment Register Pair DE to the next byte of the line.
514C
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE.
514D
CP 20H FE 20
Compare Register A (the byte of the line) against 20H, a space.
514F
If the Z FLAG is set (a space), LOOP back to 514BH.
5151
RET NC D0
If the NO CARRY FLAG is set (above a space), RETURN with it in Register A.
5152
CP 0BH FE 0B
Compare Register A against 0BH: the NO CARRY FLAG is set for 0BH-1FH.
5154
RET NC D0
If the NO CARRY FLAG is set (0BH-1FH), RETURN with it in Register A.
5155
CP 09H FE 09
Compare Register A against 09H: the CARRY FLAG is set below 09H (such as the 00H end).
5157
RET C D8
If the CARRY FLAG is set (below 09H), RETURN with it in Register A.
5158
09H or 0AH: LOOP back to 514BH to skip it and read the next byte.
515A
CP 30H FE 30
Compare Register A against 30H: the CARRY FLAG is set below the digit 0.
515C
RET C D8
If the CARRY FLAG is set, RETURN with CARRY: not a letter or digit.
515D
CP 3AH FE 3A
Compare Register A against 3AH: the CARRY FLAG is set for a digit.
515F
CCF 3F
Complement the CARRY FLAG: the NO CARRY FLAG now marks a digit.
5160
RET NC D0
If the NO CARRY FLAG is set (a digit), RETURN with NO CARRY.
5161
CP 41H FE 41
Compare Register A against 41H: the CARRY FLAG is set below the letter A.
5163
RET C D8
If the CARRY FLAG is set, RETURN with CARRY: not a letter.
5164
CP 5BH FE 5B
Compare Register A against 5BH: the CARRY FLAG is set for A-Z.
5166
CCF 3F
Complement the CARRY FLAG: the NO CARRY FLAG now marks a letter.
5167
RET C9
RETURN with the CARRY FLAG set if Register A is not a letter.
5168
LD (51C6H),BC ED 43 C6 51
Store Register Pair BC (two characters: FFFFH for none, or a name) at 51C6H, the best item's characters.
516C
LD A,01H 3E 01
Load Register A with 01H, the length byte of a two-character name.
516E
LD (51C5H),A 32 C5 51
Store Register A (the length byte) at 51C5H, the best item's length byte.
5171
LD A,(51C6H) 3A C6 51
Load Register A with the byte at 51C6H, the best item's first character.
5174
CP 41H FE 41
Compare Register A against 41H: the NO CARRY FLAG is set for a letter (a name, or FFH).
5176
LD A,18H 3E 18
Load Register A with 18H, the opcode JR. LD does not change the flags.
5178
If the NO CARRY FLAG is set (a name), JUMP to 517CH with JR.
517A
LD A,38H 3E 38
Load Register A with 38H, the opcode JR C, for a number.
517C
LD (5021H),A 32 21 50
Self-Modifying Code
Store Register A at 5021H, the opcode of the best-number test.
517F
LD HL,4200H 21 00 42
Load Register Pair HL with 4200H, the start of the line list.
5182
LD (4EEFH),HL 22 EF 4E
Self-Modifying Code
Store Register Pair HL at 4EEFH: the list's end is its start, the list is empty.
5185
LD (4EF2H),HL 22 F2 4E
Self-Modifying Code
Store Register Pair HL at 4EF2H, the list's next entry.
5188
RET C9
RETURN with the line list at 4200H empty and 5021H set for the item.

5189H - Compare Characters

Compares Register C characters at 51CCH with those at Index Register IY. The Z FLAG is set if they are all equal (or Register C is 0).

5189
LD A,C 79
Load Register A with Register C, the number of characters.
518A
OR A B7
OR Register A with itself to set the flags: the Z FLAG is set for none.
518B
LD B,A 47
Load Register B with Register A, the count. LD does not change the flags.
518C
RET Z C8
If the Z FLAG is set (nothing to compare), RETURN with Z.
518D
LD HL,51CCH 21 CC 51
Load Register Pair HL with 51CCH, the second digit of the number found.

COMPARE LOOP
Register Pair HL and Index Register IY step through the two strings; Register B counts.

5190
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, a character of the number found.
5191
CP (IY+00H) FD BE 00
Compare Register A with the byte at Index Register IY + 00H.
5194
INC HL 23
Increment Register Pair HL (the flags are not changed).
5195
RET NZ C0
If the NZ FLAG is set (they differ), RETURN with NZ and the CARRY FLAG from the compare.
5196
INC IY FD 23
Increment Index Register IY to the next character.
5198
Decrement Register B (the characters left) and LOOP back to 5190H.
519A
RET C9
RETURN with the Z FLAG set: all characters are equal.

519BH - Position the Output

519EH prints a space; if the column is 53 or more it starts a new line, and at the start of a line it indents to column 7 (past the item's name).

519B
GOSUB to BASIC 5D79H, which starts a new output line.
519E
GOSUB to BASIC 5D64H, which prints a space on the output.
51A1
LD A,(4020H) 3A 20 40
Load Register A with the byte at 4020H, the low byte of the ROM's cursor address.
51A4
AND 3FH E6 3F
AND Register A with 3FH: the cursor's column (0-63).
51A6
CP 35H FE 35
Compare Register A against 35H (53): the NO CARRY FLAG is set for column 53 or more.
51A8
If the NO CARRY FLAG is set (near the right edge), JUMP to 519BH for a new line.
51AA
SUB 07H D6 07
Subtract 07H from Register A: the column minus 7.
51AC
RET NC D0
If the NO CARRY FLAG is set (column 7 or more), RETURN.
51AD
NEG ED 44
NEG Register A: the number of spaces up to column 7.
51AF
JP 5D57H C3 57 5D
JUMP to BASIC 5D57H, which prints Register A spaces and returns.

51B2H - Type Characters and Work Areas

The rest of the file: the type characters, the TEXT END message and the work areas (all zero in the file). After the file (not loaded): 51D3H-51DAH the remaining counters and 51DBH-51EBH the search text.

51B2-51B5
DEFM "$%!#" 24 25 21 23
The type characters $ % ! #, for the counters 1-4 (51D2H-51D5H) and 6-9, read at 4ED4H and 50C2H.
51B6-51BE
DEFM "TEXT END", 0DH 54 45 58 54 20 45 4E 44 0D
The message TEXT END and a carriage return, 9 characters printed at 4E25H.
51BF
DEFB 00H 00
The length byte of the item compared (its number of characters minus 1); 00H in the file.
51C0-51C4
DEFB 00H, 00H, 00H, 00H, 00H 00 00 00 00 00
The characters of the item compared (a name has 2, a number up to 5); zero in the file.
51C5
DEFB 00H 00
The length byte of the best item found in mode 0, or of the item reported; 00H in the file.
51C6-51CA
DEFB 00H, 00H, 00H, 00H, 00H 00 00 00 00 00
The characters of that item (FFH FFH = none found); zero in the file.
51CB-51D0
DEFB 00H, 00H, 00H, 00H, 00H, 00H 00 00 00 00 00 00
The number collected from the text (up to 6 digits, written at 4FD9H); zero in the file.
51D1-51D2
DEFB 00H, 00H 00 00
The first two of the 10 reference counters (51D1H-51DAH): the name alone, then with $, %, !, #; 51D6H-51DAH the same as arrays.