DOSPLUS 3.5 for the Model III - LABEL/CMD Disassembled

Page Customization

Introduction/Summary

DOSPLUS 3.5 LABEL/CMD Disassembly - The BASIC Label Resolver (Model III)

LABEL/CMD turns a BASIC program that uses labels into one that uses only line numbers, run from the DOS command level as LABEL filespec1 filespec2; its heading reads LABEL - DOSPLUS Label resolver - 3.50. It is a load module of 4 blocks, 998 bytes, at 5700H-5AE5H with the transfer address 5700H, after the two comment records (the name LABEL and the copyright notice). LABEL/CMD is on the Model III master only, and its manual is the addendum, which describes labels with the BASIC keyword NAME.

LABEL works on the program file as BASIC saves it in the tokenized form: the byte FFH, then each line as a link, a line number and the tokens and characters ended by 00H, and a link of 0000H at the end. The file control blocks and buffers of the source and the destination, and the table of labels, lie above the load module at 5AE6H on.

The Parts of LABEL/CMD

AddressContents
5700H-576DHThe heading, the two file specifications or the prompts, OPEN@ and the FFH test (5700H, 571AH, 574EH).
576EH-5802HThe first pass: the table of labels (576EH).
5803H-5871HThe second pass: INIT@, the links and line numbers (5803H).
5872H-5920HThe bytes of a line, NAME, the keywords and their lists, a label (5872H, 58A1H, 58E5H).
5921H-59EDHThe look up, the prompt, reading and writing a byte, a number in decimal, Out of memory and the errors (5921H, 5972H, 5993H, 59D6H).
59EEH-5AE5HThe texts, the keywords, the line number (59EEH).

How LABEL Works

The two file specifications come from the command line; a missing one is asked for with Source filespec : or Destination filespec : (up to 25 characters; BREAK returns to the DOS; a bad reply is Improper file name and the prompt again, 571AH). The source is opened, and its first byte must be FFH, else Invalid file type! (574EH). Every error later shows its message and starts again at the prompts; the files are not closed then.

The first pass (Scanning -) reads each line and shows Line #: and its number over the one before (576EH). A line whose first statement, after any spaces, is NAME gives an entry to the table at 5E26H: the label up to a space, a colon or the end of the line, a 00H, and the line number. The source is then read again (REW@) for the second pass (Resolving -), and the destination is made by INIT@ (5803H). The FFH, each link and each line number are copied unchanged: BASIC makes the links again when it loads the program, so the shorter lines do no harm.

In the second pass each byte of a line is tested (5872H). NAME and everything after it up to a colon or the end of the line is left out, the colon too, wherever NAME stands. A keyword of the table at 5ADBH (GOTO, GOSUB, EDIT, RESUME, LIST, LLIST, DELETE, AUTO) is written and starts a list (58A1H): an item starting with a digit is copied, any other item is a label, taken up to a space, a comma, an apostrophe, a colon or the end of the line and looked up (58E5H, 5921H). A label in the table is replaced by its line number in decimal; one that is not is written unchanged and Undefined Label: and the label are shown beside the Line #: of the line. The end link closes the destination and LABEL returns to the DOS.

Differences from the Manual

The addendum says that LABEL replaces all label references. The bytes resolve only labels after the eight keywords of the table: a label after THEN, ELSE, RUN or RESTORE is written unchanged and no message is shown for it. A label must match a table entry in full, and NAME is looked for in the first pass only at the start of a line, while the second pass leaves out a NAME statement wherever it stands. Strings and remarks are not passed over: a byte equal to NAME or to a keyword of the table inside them is taken as that keyword.

The test for Out of memory (59D6H) compares the end of the table with Register Pair DE, which the first pass loads with HMEM$ (5777H) but replaces with the line number of each line (5793H). The table is never stopped at HMEM$; Out of memory comes only when the end of the table happens to equal the number of the line being scanned.

Variables

LABEL/CMD Variables

Address
Size
Contents
5AE4H-5AE5H
2 bytes
Line number
The line of the first pass (578DH).
5AE6H-5BE5H
256 bytes
Buffer
Replies, digits and the label looked up (5975H, 58E5H).
5BE6H-5C05H
32 bytes
Source FCB
The source program (5708H).
5C06H-5D05H
256 bytes
Source buffer
(5751H).
5D06H-5D25H
32 bytes
Destination FCB
The program written (5710H).
5D26H-5E25H
256 bytes
Destination buffer
(5814H).
5E26H
to the top
Labels
The table of labels: label, 00H, line number (5774H).

Memory Outside LABEL/CMD

Address
Size
Contents
4411H-4412H
2 bytes
HMEM$
Loaded as the limit of the table (5777H).

Outside Routines

AddressContents
4467HSYS0/SYS: DSPLY@ (5704H, 5972H).
441CHSYS0/SYS: FSPEC@ (570BH).
4424HSYS0/SYS: OPEN@ (5756H).
4420HSYS0/SYS: INIT@ (5819H).
443FHSYS0/SYS: REW@ (5808H).
4428HSYS0/SYS: CLOSE@ (583AH).
4409HSYS0/SYS: ERROR@ (572FH, 59E8H).
0013HROM: input a byte from a control block (597FH).
001BHROM: output a byte to a control block (598BH).
0033HROM: display a character (57A9H).
0040HROM: line input (5978H).

Disassembly

5700H - LABEL

LABEL/CMD's transfer address, entered from the DOS command level with Register Pair HL at the command line after the word LABEL: LABEL filespec1 filespec2. LABEL is the label resolver of the addendum: it reads a BASIC program saved in the tokenized form (first byte FFH) that uses labels (NAME label at the start of a line, and labels in place of line numbers after GOTO and the other keywords of its table), makes a table of the labels and their line numbers in a first pass, and writes in a second pass a copy without the NAME statements, each label reference replaced by its line number. LABEL loads at 5700H, above the buffers it does not use.

5700
PUSH HL E5
Save Register Pair HL, the command line pointer after LABEL, to the top of the stack while the heading is shown.
5701
LD HL,59EEH 21 EE 59
Point Register Pair HL to 59EEH, LABEL's heading (LABEL - DOSPLUS Label resolver - 3.50) and the copyright line.
5704
GOSUB to 4467H, DSPLY@, to display the text at Register Pair HL up to and with the 0DH after the copyright line.
5707
POP HL E1
Restore Register Pair HL, the command line pointer, from the top of the stack.
5708
LD DE,5BE6H 11 E6 5B
Point Register Pair DE to 5BE6H, the file control block of the source program.
570B
GOSUB to 441CH, FSPEC@, to move the first file specification at Register Pair HL into the file control block at Register Pair DE.
570E
If the NZ FLAG is set (no valid source specification), JUMP to 571AH to prompt for both files.
5710
LD DE,5D06H 11 06 5D
Point Register Pair DE to 5D06H, the file control block of the destination program.
5713
GOSUB to 441CH, FSPEC@, to move the second file specification at Register Pair HL into the file control block at Register Pair DE.
5716
If the NZ FLAG is set (no valid destination specification), JUMP to 5734H to prompt for the destination.
5718
JUMP to 574EH to open the source with both specifications taken.

571AH - The Prompts

Source filespec : and Destination filespec : take up to 25 characters each into 5AE6H; BREAK returns to the DOS, and a reply FSPEC@ refuses is the error 13H, Improper file name, and the same prompt again. Every error of LABEL comes back here.

571A
LD HL,5A46H 21 46 5A
Point Register Pair HL to 5A46H, the prompt Source filespec : for the source program.
571D
LD B,19H 06 19
Load Register B with 19H, the most characters of the reply: 25.
571F
GOSUB to 5972H to display the prompt at Register Pair HL and take a reply into 5AE6H; the C FLAG for BREAK.
5722
RET C D8
If the C FLAG is set (BREAK), RETurn to the DOS, which called LABEL from the command level.
5723
LD DE,5BE6H 11 E6 5B
Point Register Pair DE to 5BE6H, the file control block of the source program.
5726
GOSUB to 441CH, FSPEC@, to move the reply at Register Pair HL into the file control block at Register Pair DE.
5729
If the Z FLAG is set (a valid specification), JUMP to 5734H for the destination.
572B
LD A,13H 3E 13
Load Register A with 13H, the error code of Improper file name.
572D
OR C0H F6 C0
OR Register A with C0H, setting bits 7 and 6: ERROR@ returns, and shows the message without the frame of asterisks.
572F
GOSUB to 4409H, ERROR@, to show the message of the error code in Register A.
5732
JUMP to 571AH to prompt for the source again.
5734
LD HL,5A5EH 21 5E 5A
Point Register Pair HL to 5A5EH, the prompt Destination filespec : for the program to write.
5737
LD B,19H 06 19
Load Register B with 19H, the most characters of the reply: 25.
5739
GOSUB to 5972H to display the prompt at Register Pair HL and take a reply into 5AE6H; the C FLAG for BREAK.
573C
RET C D8
If the C FLAG is set (BREAK), RETurn to the DOS, which called LABEL from the command level.
573D
LD DE,5D06H 11 06 5D
Point Register Pair DE to 5D06H, the file control block of the destination program.
5740
GOSUB to 441CH, FSPEC@, to move the reply at Register Pair HL into the file control block at Register Pair DE.
5743
If the Z FLAG is set (a valid specification), JUMP to 574EH to open the source.
5745
LD A,13H 3E 13
Load Register A with 13H, the error code of Improper file name.
5747
OR C0H F6 C0
OR Register A with C0H, setting bits 7 and 6: ERROR@ returns, and shows the message without the frame of asterisks.
5749
GOSUB to 4409H, ERROR@, to show the message of the error code in Register A.
574C
JUMP to 5734H to prompt for the destination again.

574EH - Open the Source

OPEN@ of the source with 256 byte records and the buffer 5C06H; its first byte must be FFH, the mark of a BASIC program in the tokenized form, else Invalid file type! and the prompts again.

574E
LD DE,5BE6H 11 E6 5B
Point Register Pair DE to 5BE6H, the file control block of the source program.
5751
LD HL,5C06H 21 06 5C
Point Register Pair HL to 5C06H, the 256 byte buffer of the source program.
5754
LD B,00H 06 00
Load Register B with 00H, the logical record length for OPEN@: 256 byte records.
5756
GOSUB to 4424H, OPEN@, to open the source program of the file control block at Register Pair DE.
5759
If the NZ FLAG is set (OPEN@ failed, its error code in Register A), JUMP to 59E6H to post the error.
575C
GOSUB to 597BH to read the first byte of the source into Register A.
575F
If the NZ FLAG is set, JUMP to 59E6H to post the error (597BH has already gone there for a read error).
5762
CP FFH FE FF
Compare Register A against FFH, the first byte of a BASIC program saved in the tokenized form.
5764
If the Z FLAG is set (a BASIC program), JUMP to 576EH for the first pass.
5766
LD HL,5A76H 21 76 5A
Point Register Pair HL to 5A76H, the message Invalid file type!.
5769
GOSUB to 4467H, DSPLY@, to display the message at Register Pair HL.
576C
JUMP to 571AH for the prompts for the source and the destination.

576EH - The First Pass

Scanning -. For each line: the link (0000H ends the program), the line number (kept in 5AE4H and shown as Line #: n over itself), then the first byte after the spaces. NAME (A9H) followed by a label adds the entry label, 00H, line number to the table at 5E26H; the rest of the line is passed over.

576E
LD HL,5A97H 21 97 5A
Point Register Pair HL to 5A97H, the message Scanning - of the first pass.
5771
GOSUB to 4467H, DSPLY@, to display the message at Register Pair HL.
5774
LD HL,5E26H 21 26 5E
Point Register Pair HL to 5E26H, the start of the table of labels, which grows upwards.
5777
LD DE,(4411H) ED 5B 11 44
Load Register Pair DE with HMEM$ from 4411H-4412H, meant as the limit of the table for 59D6H.
577B
GOSUB to 597BH to read the low byte of the line's link from the source into Register A.
577E
LD B,A 47
Load Register B with Register A, the low byte of the link.
577F
GOSUB to 597BH to read the high byte of the line's link into Register A.
5782
OR B B0
OR Register A with Register B: the Z FLAG for the link 0000H that ends the program.
5783
If the Z FLAG is set (the end of the program), JUMP to 5803H for the second pass.
5785
GOSUB to 597BH to read the low byte of the line number into Register A.
5788
LD C,A 4F
Load Register C with Register A, the low byte of the line number.
5789
GOSUB to 597BH to read the high byte of the line number into Register A.
578C
LD B,A 47
Load Register B with Register A: Register Pair BC = the line number.
578D
LD (5AE4H),BC ED 43 E4 5A
Store Register Pair BC, the line number, into 5AE4H-5AE5H for an entry of the table.
5791
PUSH HL E5
Save Register Pair HL, the end of the table, to the top of the stack while the line number is shown.
5792
PUSH BC C5
Save Register Pair BC, the line number, to the top of the stack.
5793
POP DE D1
Restore Register Pair DE from the top of the stack: Register Pair DE = the line number, in place of HMEM$.
5794
LD HL,5AE6H 21 E6 5A
Point Register Pair HL to 5AE6H, the buffer for the digits of the line number.
5797
GOSUB to 5993H to write Register Pair DE in decimal at Register Pair HL; Register Pair HL returns at its first digit.
579A
PUSH HL E5
Save Register Pair HL, the first digit, to the top of the stack while the text is shown.
579B
LD HL,5AB0H 21 B0 5A
Point Register Pair HL to 5AB0H, the text Line #: before the line number.
579E
GOSUB to 4467H, DSPLY@, to display the text at Register Pair HL up to its 03H.
57A1
POP HL E1
Restore Register Pair HL, the first digit of the line number, from the top of the stack.
57A2
LD A,(HL) 7E
Load Register A with the next digit of the line number at Register Pair HL.
57A3
INC HL 23
INCrement Register Pair HL by 1, to the next digit.
57A4
OR A B7
OR Register A with itself: the Z FLAG for the 00H after the last digit.
57A5
If the NZ FLAG is set (a digit), JUMP to 57B3H to display it.
57A7
LD A,0DH 3E 0D
Load Register A with 0DH, a carriage return after the line number.
57A9
GOSUB to 0033H, the ROM's display of the character in Register A, the carriage return.
57AC
LD A,1BH 3E 1B
Load Register A with 1BH, the code that moves the cursor up one line, so the next line number is shown over this one.
57AE
GOSUB to 0033H, the ROM's display of the character in Register A, the cursor up.
57B1
JUMP to 57B8H for the line's text after the line number shown.
57B3
GOSUB to 0033H, the ROM's display of the digit in Register A.
57B6
JUMP to 57A2H for the next digit of the line number shown.
57B8
POP HL E1
Restore Register Pair HL, the end of the table, from the top of the stack.
57B9
GOSUB to 597BH to read the next byte of the line into Register A.
57BC
CP 20H FE 20
Compare Register A against 20H, a space before the first statement.
57BE
If the Z FLAG is set (a space), JUMP to 57B9H for the next byte.
57C0
CP A9H FE A9
Compare Register A against A9H, the token of NAME, which gives the line a label.
57C2
If the NZ FLAG is set (no NAME at the start of the line), JUMP to 57F9H to pass over the line.
57C4
GOSUB to 597BH to read the next byte of the line into Register A.
57C7
CP 20H FE 20
Compare Register A against 20H, a space between NAME and the label.
57C9
If the Z FLAG is set (a space), JUMP to 57C4H for the next byte.
57CB
CP 00H FE 00
Compare Register A against 00H, the end of the line, which ends the label.
57CD
If the Z FLAG is set (the end of the line), JUMP to 57E1H to end the entry.
57CF
CP 20H FE 20
Compare Register A against 20H, a space, which ends the label.
57D1
If the Z FLAG is set (a space), JUMP to 57E1H to end the entry.
57D3
CP 3AH FE 3A
Compare Register A against 3AH, the colon, which ends the label and the statement.
57D5
If the Z FLAG is set (a colon), JUMP to 57E1H to end the entry.
57D7
LD (HL),A 77
Store Register A, a character of the label, into the table at Register Pair HL.
57D8
INC HL 23
INCrement Register Pair HL by 1, to the next byte of the table.
57D9
GOSUB to 59D6H to test Register Pair HL against Register Pair DE for Out of memory.
57DC
GOSUB to 597BH to read the next byte of the line into Register A.
57DF
JUMP to 57CBH for the test of the end of the label.
57E1
PUSH AF F5
Save Register Pair AF, the byte that ended the label, to the top of the stack.
57E2
LD (HL),00H 36 00
Store 00H, the end of the label, into the table at Register Pair HL.
57E4
INC HL 23
INCrement Register Pair HL by 1, to the next byte of the table.
57E5
GOSUB to 59D6H to test Register Pair HL against Register Pair DE for Out of memory.
57E8
LD A,(5AE4H) 3A E4 5A
Load Register A with the low byte of the line number from 5AE4H.
57EB
LD (HL),A 77
Store Register A, the low byte of the line number, into the table at Register Pair HL.
57EC
INC HL 23
INCrement Register Pair HL by 1, to the next byte of the table.
57ED
GOSUB to 59D6H to test Register Pair HL against Register Pair DE for Out of memory.
57F0
LD A,(5AE5H) 3A E5 5A
Load Register A with the high byte of the line number from 5AE5H.
57F3
LD (HL),A 77
Store Register A, the high byte of the line number, into the table at Register Pair HL.
57F4
INC HL 23
INCrement Register Pair HL by 1, to the next entry of the table.
57F5
GOSUB to 59D6H to test Register Pair HL against Register Pair DE for Out of memory.
57F8
POP AF F1
Restore Register Pair AF, the byte that ended the label, from the top of the stack.
57F9
CP 00H FE 00
Compare Register A against 00H, the end of the line.
57FB
If the Z FLAG is set (the end of the line), JUMP to 577BH for the next line.
57FE
GOSUB to 597BH to read the next byte of the line into Register A, which is passed over.
5801
JUMP to 57F9H for the test of the end of the line.

5803H - The Second Pass

An empty label (00H) ends the table; the source is read again from its start; Resolving -; the destination is made by INIT@ with the buffer 5D26H, and the FFH mark and each line's link are copied unchanged. The end link 0000H closes the destination and LABEL returns to the DOS.

5803
LD DE,5BE6H 11 E6 5B
Point Register Pair DE to 5BE6H, the file control block of the source program.
5806
LD (HL),00H 36 00
Store 00H into the table at Register Pair HL: an empty label, the end of the table.
5808
GOSUB to 443FH, REW@, to set the source at Register Pair DE back to its start.
580B
LD HL,5AA2H 21 A2 5A
Point Register Pair HL to 5AA2H, the message Resolving - of the second pass, after the cursor up and the clear to the end of the screen.
580E
GOSUB to 4467H, DSPLY@, to display the message at Register Pair HL.
5811
LD DE,5D06H 11 06 5D
Point Register Pair DE to 5D06H, the file control block of the destination program.
5814
LD HL,5D26H 21 26 5D
Point Register Pair HL to 5D26H, the 256 byte buffer of the destination program.
5817
LD B,00H 06 00
Load Register B with 00H, the logical record length for INIT@: 256 byte records.
5819
GOSUB to 4420H, INIT@, to open the destination of the file control block at Register Pair DE, making it when it is not there.
581C
If the NZ FLAG is set (INIT@ failed, its error code in Register A), JUMP to 59E6H to post the error.
581F
GOSUB to 597BH to read the first byte of the source into Register A, the FFH mark.
5822
GOSUB to 5987H to write the byte in Register A to the destination.
5825
GOSUB to 597BH to read the low byte of the line's link from the source into Register A.
5828
LD B,A 47
Load Register B with Register A, the low byte of the link.
5829
GOSUB to 5987H to write the low byte of the link to the destination unchanged.
582C
GOSUB to 597BH to read the high byte of the line's link into Register A.
582F
LD C,A 4F
Load Register C with Register A, the high byte of the link.
5830
GOSUB to 5987H to write the high byte of the link to the destination unchanged.
5833
LD A,B 78
Load Register A with Register B, the low byte of the link.
5834
OR C B1
OR Register A with Register C: the Z FLAG for the link 0000H that ends the program.
5835
If the NZ FLAG is set (another line), JUMP to 583EH for its line number.
5837
LD DE,5D06H 11 06 5D
Point Register Pair DE to 5D06H, the file control block of the destination program.
583A
GOSUB to 4428H, CLOSE@, to close the destination of the file control block at Register Pair DE.
583D
RET C9
RETurn to the DOS, which called LABEL from the command level.
583E
RES 0,B CB 80
Reset bit 0 of Register B, the flag of a list of line numbers after a keyword of the table: none at the start of the line.
5840
GOSUB to 597BH to read the low byte of the line number into Register A.
5843
LD E,A 5F
Load Register E with Register A, the low byte of the line number.
5844
GOSUB to 5987H to write the low byte of the line number to the destination.
5847
GOSUB to 597BH to read the high byte of the line number into Register A.
584A
LD D,A 57
Load Register D with Register A: Register Pair DE = the line number.
584B
GOSUB to 5987H to write the high byte of the line number to the destination.
584E
LD HL,5AE6H 21 E6 5A
Point Register Pair HL to 5AE6H, the buffer for the digits of the line number.
5851
GOSUB to 5993H to write Register Pair DE in decimal at Register Pair HL; Register Pair HL returns at its first digit.
5854
PUSH HL E5
Save Register Pair HL, the first digit, to the top of the stack while the text is shown.
5855
LD HL,5AB0H 21 B0 5A
Point Register Pair HL to 5AB0H, the text Line #: before the line number.
5858
GOSUB to 4467H, DSPLY@, to display the text at Register Pair HL up to its 03H.
585B
POP HL E1
Restore Register Pair HL, the first digit of the line number, from the top of the stack.
585C
LD A,(HL) 7E
Load Register A with the next digit of the line number at Register Pair HL.
585D
INC HL 23
INCrement Register Pair HL by 1, to the next digit.
585E
OR A B7
OR Register A with itself: the Z FLAG for the 00H after the last digit.
585F
If the NZ FLAG is set (a digit), JUMP to 586DH to display it.
5861
LD A,0DH 3E 0D
Load Register A with 0DH, a carriage return after the line number.
5863
GOSUB to 0033H, the ROM's display of the character in Register A, the carriage return.
5866
LD A,1BH 3E 1B
Load Register A with 1BH, the code that moves the cursor up one line, so the next line number is shown over this one.
5868
GOSUB to 0033H, the ROM's display of the character in Register A, the cursor up.
586B
JUMP to 5872H for the line's text after the line number shown.
586D
GOSUB to 0033H, the ROM's display of the digit in Register A.
5870
JUMP to 585CH for the next digit of the line number shown.

5872H - A Byte of the Line

Outside a list of line numbers each byte is read and tested: NAME (A9H) drops itself and the bytes after it up to a colon (dropped too) or the end of the line; a keyword of the table at 5ADBH (GOTO, GOSUB, EDIT, RESUME, LIST, LLIST, DELETE, AUTO) is written and starts a list (bit 0 of Register B); any other byte is written. Strings and remarks are not passed over.

5872
BIT 0,B CB 40
Test bit 0 of Register B, set inside a list of line numbers or labels after a keyword of the table.
5874
If the NZ FLAG is set (inside a list), JUMP to 58A1H for the next item of the list after the comma.
5876
GOSUB to 597BH to read the next byte of the line into Register A.
5879
CP A9H FE A9
Compare Register A against A9H, the token of NAME.
587B
If the NZ FLAG is set (not NAME), JUMP to 588BH to test for a keyword of the table.
587D
GOSUB to 597BH to read the next byte after NAME into Register A, which is dropped.
5880
CP 00H FE 00
Compare Register A against 00H, the end of the line.
5882
If the Z FLAG is set (the end of the line), JUMP to 5916H to write the 00H that ends the line.
5885
CP 3AH FE 3A
Compare Register A against 3AH, the colon after the label.
5887
If the Z FLAG is set (the colon), JUMP to 5872H for the next statement; the colon is not written.
5889
JUMP to 587DH to drop the next byte of the label.
588B
BIT 7,A CB 7F
Test bit 7 of Register A, set for a keyword token.
588D
If the Z FLAG is set (not a token), JUMP to 5916H to write the byte.
5890
LD HL,5ADBH 21 DB 5A
Point Register Pair HL to 5ADBH, the table of the keywords that take line numbers.
5893
INC (HL) 34
INCrement the byte at Register Pair HL by 1, the first half of a test of the table's byte for zero.
5894
DEC (HL) 35
DECrement the byte at Register Pair HL by 1, back to the token: the Z FLAG for the 00H that ends the table.
5895
If the Z FLAG is set (not in the table), JUMP to 5916H to write the token.
5898
CP (HL) BE
Compare Register A against the token of the table at Register Pair HL.
5899
INC HL 23
INCrement Register Pair HL by 1, to the next token of the table.
589A
If the NZ FLAG is set (another token), JUMP to 5893H for the next entry.
589C
GOSUB to 5987H to write the keyword token in Register A to the destination.
589F
SET 0,B CB C0
Set bit 0 of Register B: a list of line numbers or labels follows.

58A1H - An Item of a List

Spaces are written; a colon, an apostrophe (27H) or the end of the line ends the list; an item starting with a digit is a line number, written as it is; any other item is a label, looked up and replaced (58E5H). A comma goes on with the list.

58A1
GOSUB to 597BH to read the next byte of the line into Register A.
58A4
CP 20H FE 20
Compare Register A against 20H, a space in the list.
58A6
If the NZ FLAG is set (not a space), JUMP to 58ADH.
58A8
GOSUB to 5987H to write the space in Register A to the destination.
58AB
JUMP to 58A1H for the next byte of the list after the space.
58AD
CP 00H FE 00
Compare Register A against 00H, the end of the line.
58AF
If the Z FLAG is set (the end of the line), JUMP to 58B9H to end the list.
58B1
CP 3AH FE 3A
Compare Register A against 3AH, the colon at the end of a statement.
58B3
If the Z FLAG is set (a colon), JUMP to 58B9H to end the list.
58B5
CP 27H FE 27
Compare Register A against 27H, the apostrophe.
58B7
If the NZ FLAG is set (another byte), JUMP to 58BEH to look at the item.
58B9
RES 0,B CB 80
Reset bit 0 of Register B: the list has ended.
58BB
JUMP to 5916H to write the byte that ended the list.
58BE
CP 30H FE 30
Compare Register A against 30H, the digit 0: the C FLAG below it.
58C0
If the C FLAG is set (not a digit), JUMP to 58E5H to take a label.
58C2
CP 3AH FE 3A
Compare Register A against 3AH, the character after 9: the NC FLAG from it on.
58C4
If the NC FLAG is set (not a digit), JUMP to 58E5H to take a label.
58C6
GOSUB to 5987H to write the character of the line number in Register A to the destination.
58C9
GOSUB to 597BH to read the next byte of the line into Register A.
58CC
CP 2CH FE 2C
Compare Register A against 2CH, the comma before the next item.
58CE
If the NZ FLAG is set (not a comma), JUMP to 58D5H.
58D0
GOSUB to 5987H to write the comma in Register A to the destination.
58D3
JUMP to 58A1H for the next item of the list after the comma.
58D5
CP 00H FE 00
Compare Register A against 00H, the end of the line.
58D7
If the Z FLAG is set (the end of the line), JUMP to 58E1H to end the list.
58D9
CP 27H FE 27
Compare Register A against 27H, the apostrophe.
58DB
If the Z FLAG is set (an apostrophe), JUMP to 58E1H to end the list.
58DD
CP 3AH FE 3A
Compare Register A against 3AH, the colon at the end of a statement.
58DF
If the NZ FLAG is set (another character of the item), JUMP to 58C6H to write it.
58E1
RES 0,B CB 80
Reset bit 0 of Register B: the list has ended.
58E3
JUMP to 5916H to write the byte that ended the list.

58E5H - A Label in a List

The label's characters up to the end of the line, a space, an apostrophe, a comma or a colon go into 5AE6H (Register C keeps the byte that ended it); 5921H writes the line number of the label, or the label itself when it is not in the table. The end of the line, an apostrophe or a colon ends the list.

58E5
LD HL,5AE6H 21 E6 5A
Point Register Pair HL to 5AE6H, the buffer for the label.
58E8
LD (HL),A 77
Store Register A, a character of the label, into the buffer at Register Pair HL.
58E9
INC HL 23
INCrement Register Pair HL by 1, to the next byte of the buffer.
58EA
GOSUB to 597BH to read the next byte of the line into Register A.
58ED
LD C,A 4F
Load Register C with Register A, kept as the byte that may end the label.
58EE
CP 00H FE 00
Compare Register A against 00H, the end of the line.
58F0
If the Z FLAG is set (the end of the line), JUMP to 5902H to look up the label.
58F2
CP 20H FE 20
Compare Register A against 20H, a space after the label.
58F4
If the Z FLAG is set (a space), JUMP to 5902H to look up the label.
58F6
CP 27H FE 27
Compare Register A against 27H, the apostrophe.
58F8
If the Z FLAG is set (an apostrophe), JUMP to 5902H to look up the label.
58FA
CP 2CH FE 2C
Compare Register A against 2CH, the comma before the next item.
58FC
If the Z FLAG is set (a comma), JUMP to 5902H to look up the label.
58FE
CP 3AH FE 3A
Compare Register A against 3AH, the colon at the end of a statement.
5900
If the NZ FLAG is set (another character of the label), JUMP to 58E8H to keep it.
5902
LD (HL),00H 36 00
Store 00H, the end of the label, into the buffer at Register Pair HL.
5904
GOSUB to 5921H to write the line number of the label at 5AE6H, or the label when it is not defined.
5907
LD A,C 79
Load Register A with Register C, the byte that ended the label.
5908
CP 00H FE 00
Compare Register A against 00H, the end of the line.
590A
If the Z FLAG is set (the end of the line), JUMP to 5914H to end the list.
590C
CP 27H FE 27
Compare Register A against 27H, the apostrophe.
590E
If the Z FLAG is set (an apostrophe), JUMP to 5914H to end the list.
5910
CP 3AH FE 3A
Compare Register A against 3AH, the colon at the end of a statement.
5912
If the NZ FLAG is set (a space or a comma), JUMP to 5916H; the list goes on.
5914
RES 0,B CB 80
Reset bit 0 of Register B: the list has ended.
5916
GOSUB to 5987H to write the byte in Register A to the destination.
5919
CP 00H FE 00
Compare Register A against 00H, the end of the line.
591B
If the Z FLAG is set (the end of the line), JUMP to 5825H for the next line.
591E
JUMP to 5872H for the next byte of the line of the source.

5921H - Look Up a Label

Compares the label at 5AE6H with each label of the table at 5E26H (each ended by 00H and followed by its line number); the whole label must match. Found: the line number is written in decimal. Not found: the label is written unchanged and Undefined Label: and the label are shown beside the Line #: of the line.

5921
LD DE,5E26H 11 26 5E
Point Register Pair DE to 5E26H, the first entry of the table of labels.
5924
LD HL,5AE6H 21 E6 5A
Point Register Pair HL to 5AE6H, the label looked up.
5927
LD A,(DE) 1A
Load Register A with the first character of the entry's label at Register Pair DE.
5928
OR A B7
OR Register A with itself: the Z FLAG for the empty label that ends the table.
5929
If the NZ FLAG is set (an entry), JUMP to 5947H to compare it.
592B
LD HL,5AB9H 21 B9 5A
Point Register Pair HL to 5AB9H, 16 cursor moves to the right and the text Undefined Label:.
592E
GOSUB to 4467H, DSPLY@, to display the text at Register Pair HL up to its 03H.
5931
LD HL,5AE6H 21 E6 5A
Point Register Pair HL to 5AE6H, the label that is not in the table.
5934
LD A,(HL) 7E
Load Register A with the next character of the label at Register Pair HL.
5935
INC HL 23
INCrement Register Pair HL by 1, to the next character.
5936
OR A B7
OR Register A with itself: the Z FLAG for the 00H after the label.
5937
If the NZ FLAG is set (a character), JUMP to 593FH to write and show it.
5939
LD A,0DH 3E 0D
Load Register A with 0DH, a carriage return after the label shown.
593B
GOSUB to 0033H, the ROM's display of the character in Register A, the carriage return.
593E
RET C9
RETurn to the caller with the label written unchanged.
593F
GOSUB to 5987H to write the character of the label in Register A to the destination.
5942
GOSUB to 0033H, the ROM's display of the character in Register A.
5945
JUMP to 5934H for the next character of the label.
5947
LD A,(DE) 1A
Load Register A with the next character of the entry's label at Register Pair DE.
5948
CP (HL) BE
Compare Register A against the character of the label looked up at Register Pair HL.
5949
If the NZ FLAG is set (they differ), JUMP to 5952H for the next entry.
594B
INC HL 23
INCrement Register Pair HL by 1, to the next character of the label looked up.
594C
INC DE 13
INCrement Register Pair DE by 1, to the next character of the entry.
594D
OR A B7
OR Register A with itself: the Z FLAG when the equal characters were the 00H at the end.
594E
If the Z FLAG is set (the whole label matches), JUMP to 595BH for the line number.
5950
JUMP to 5947H for the next character of the two labels.
5952
LD A,(DE) 1A
Load Register A with the next byte of the entry's label at Register Pair DE.
5953
INC DE 13
INCrement Register Pair DE by 1, to the byte after it.
5954
OR A B7
OR Register A with itself: the Z FLAG for the 00H at the end of the entry's label.
5955
If the NZ FLAG is set (not yet the end), JUMP to 5952H for the next byte.
5957
INC DE 13
INCrement Register Pair DE by 1, past the low byte of the entry's line number.
5958
INC DE 13
INCrement Register Pair DE by 1, past the high byte: Register Pair DE = the next entry.
5959
JUMP to 5924H to compare the next entry of the table of labels.
595B
LD A,(DE) 1A
Load Register A with the low byte of the entry's line number at Register Pair DE.
595C
LD L,A 6F
Load Register L with Register A, the low byte of the line number.
595D
INC DE 13
INCrement Register Pair DE by 1, to the high byte of the line number.
595E
LD A,(DE) 1A
Load Register A with the high byte of the entry's line number at Register Pair DE.
595F
LD H,A 67
Load Register H with Register A: Register Pair HL = the line number of the label.
5960
LD DE,5AE6H 11 E6 5A
Point Register Pair DE to 5AE6H, the buffer for its digits.
5963
EX DE,HL EB
Exchange Register Pair DE and Register Pair HL: Register Pair DE = the line number, Register Pair HL = 5AE6H.
5964
GOSUB to 5993H to write Register Pair DE in decimal at Register Pair HL; Register Pair HL returns at its first digit.
5967
LD A,(HL) 7E
Load Register A with the next digit of the line number at Register Pair HL.
5968
INC HL 23
INCrement Register Pair HL by 1, to the next digit.
5969
OR A B7
OR Register A with itself: the Z FLAG for the 00H after the last digit.
596A
If the NZ FLAG is set (a digit), JUMP to 596DH to write it.
596C
RET C9
RETurn to the caller with the line number written in place of the label.
596D
GOSUB to 5987H to write the digit in Register A to the destination.
5970
JUMP to 5967H for the next digit of the line number written.

5972H - Prompt, Read a Byte, Write a Byte

5972H shows the prompt and takes a reply of up to Register B characters into 5AE6H by the ROM's 0040H. 597BH reads a byte of the source by 0013H and 5987H writes one to the destination by 001BH; on an error each drops its own return address and goes to 59E6H.

5972
GOSUB to 4467H, DSPLY@, to display the prompt at Register Pair HL up to its 03H.
5975
LD HL,5AE6H 21 E6 5A
Point Register Pair HL to 5AE6H, the buffer for the reply.
5978
JUMP to 0040H, the ROM's line input of up to Register B characters into the buffer at Register Pair HL, which returns to the caller.
597B
PUSH DE D5
Save Register Pair DE to the top of the stack while the byte is read.
597C
LD DE,5BE6H 11 E6 5B
Point Register Pair DE to 5BE6H, the file control block of the source program.
597F
GOSUB to 0013H, the ROM's input of a byte from the control block at Register Pair DE: Register A = the byte.
5982
POP DE D1
Restore Register Pair DE from the top of the stack.
5983
RET Z C8
If the Z FLAG is set (the byte was read), RETurn to the caller with the byte in Register A.
5984
POP DE D1
Restore Register Pair DE from the top of the stack: the return address is dropped.
5985
JUMP to 59E6H to post the error in Register A.
5987
PUSH DE D5
Save Register Pair DE to the top of the stack while the byte is written.
5988
LD DE,5D06H 11 06 5D
Point Register Pair DE to 5D06H, the file control block of the destination program.
598B
GOSUB to 001BH, the ROM's output of the byte in Register A to the control block at Register Pair DE.
598E
POP DE D1
Restore Register Pair DE from the top of the stack.
598F
RET Z C8
If the Z FLAG is set (the byte was written), RETurn to the caller.
5990
POP DE D1
Restore Register Pair DE from the top of the stack: the return address is dropped.
5991
JUMP to 59E6H to post the error in Register A.

5993H - A Number in Decimal

Register Pair DE = the number, Register Pair HL = the buffer: five digits by subtracting the powers of ten of the table at 59CAH, then 00H; Register Pair HL returns past up to four leading zeros. Register Pair BC and Index Register IX are saved.

5993
PUSH BC C5
Save Register Pair BC to the top of the stack.
5994
PUSH IX DD E5
Save Index Register IX to the top of the stack.
5996
PUSH HL E5
Save Register Pair HL, the buffer, to the top of the stack for the leading zeros.
5997
EX DE,HL EB
Exchange Register Pair DE and Register Pair HL: Register Pair HL = the number, Register Pair DE = the buffer.
5998
LD IX,59CAH DD 21 CA 59
Point Index Register IX to 59CAH, the table of the powers of ten.
599C
LD B,(IX+01H) DD 46 01
Load Register B with the high byte of the power at Index Register IX+01H.
599F
LD C,(IX+00H) DD 4E 00
Load Register C with the low byte at Index Register IX+00H: Register Pair BC = the power of ten.
59A2
LD A,B 78
Load Register A with Register B, the high byte of the power.
59A3
OR C B1
OR Register A with Register C: the Z FLAG for the 0000H that ends the table.
59A4
If the NZ FLAG is set (a power), JUMP to 59B6H for its digit.
59A6
LD (DE),A 12
Store Register A (00H) into the buffer at Register Pair DE, after the fifth digit.
59A7
POP HL E1
Restore Register Pair HL, the buffer, from the top of the stack.
59A8
LD B,04H 06 04
Load Register B with 04H, the most leading zeros passed over: the last digit stays.
59AA
LD A,(HL) 7E
Load Register A with the digit at Register Pair HL.
59AB
CP 30H FE 30
Compare Register A against 30H, the digit 0, a leading zero.
59AD
If the NZ FLAG is set (a significant digit), JUMP to 59B2H.
59AF
INC HL 23
INCrement Register Pair HL by 1, past the leading zero.
59B0
DECrement Register B and, while it is not zero, LOOP BACK to 59AAH for the next digit (DJNZ).
59B2
POP IX DD E1
Restore Index Register IX from the top of the stack.
59B4
POP BC C1
Restore Register Pair BC from the top of the stack.
59B5
RET C9
RETurn to the caller with Register Pair HL at the first significant digit.
59B6
XOR A AF
Set Register A to 00H (XOR A), the count of the digit.
59B7
OR A B7
OR Register A with itself, to clear the C FLAG for the SBC below.
59B8
SBC HL,BC ED 42
SUBtract Register Pair BC, the power, from Register Pair HL with the C FLAG: the C FLAG when the number is smaller.
59BA
If the C FLAG is set (too far), JUMP to 59BFH.
59BC
INC A 3C
INCrement Register A by 1, the digit up by one.
59BD
JUMP to 59B7H to subtract the power of ten in Register Pair BC again.
59BF
ADD HL,BC 09
ADD Register Pair BC, the power, back to Register Pair HL.
59C0
OR 30H F6 30
OR Register A with 30H, making the digit a character 0-9.
59C2
LD (DE),A 12
Store Register A, the digit, into the buffer at Register Pair DE.
59C3
INC DE 13
INCrement Register Pair DE by 1, to the next place of the buffer.
59C4
INC IX DD 23
INCrement Index Register IX by 1, the first of two to the next power.
59C6
INC IX DD 23
INCrement Index Register IX by 1, the second: Index Register IX = the next power of ten.
59C8
JUMP to 599CH for the next digit, with the next power of ten.
59CA-59D5
DEFW 2710H,03E8H,0064H,000AH,0001H,0000H 10 27 E8 03 64 00 0A 00 01 00 00 00
The powers of ten for 5993H: 10000, 1000, 100, 10 and 1, ended by 0000H.

59D6H - Out of Memory and the Errors

59D6H returns when Register Pair HL is not Register Pair DE; when they are equal it drops its return address and shows Out of memory, then the prompts. 59E6H posts the error in Register A with bits 7 and 6 set (ERROR@ returns, no frame) and goes to the prompts.

59D6
PUSH HL E5
Save Register Pair HL, the end of the table, to the top of the stack.
59D7
OR A B7
OR Register A with itself, to clear the C FLAG for the SBC below.
59D8
SBC HL,DE ED 52
SUBtract Register Pair DE from Register Pair HL with the C FLAG: the Z FLAG when they are equal.
59DA
POP HL E1
Restore Register Pair HL, the end of the table, from the top of the stack.
59DB
RET NZ C0
If the NZ FLAG is set (not equal), RETurn to the caller.
59DC
POP HL E1
Restore Register Pair HL from the top of the stack: the return address is dropped.
59DD
LD HL,5A89H 21 89 5A
Point Register Pair HL to 5A89H, the message Out of memory.
59E0
GOSUB to 4467H, DSPLY@, to display the message at Register Pair HL.
59E3
JUMP to 571AH for the prompts for the source and the destination.
59E6
OR C0H F6 C0
OR Register A with C0H, setting bits 7 and 6: ERROR@ returns, and shows the message without the frame of asterisks.
59E8
GOSUB to 4409H, ERROR@, to show the message of the error code in Register A.
59EB
JUMP to 571AH for the prompts for the source and the destination.

59EEH - The Texts and the Variables

Data: the heading, the prompts and messages (ended by 03H or 0DH), the table of the keywords that take line numbers, and the line number of the first pass. 5AE6H on is not loaded: the buffer, the two file control blocks and buffers, and the table of labels.

59EE
DEFB 0AH 0A
A line feed (0AH) before the heading of LABEL.
59EF-5A14
DEFM "LABEL - DOSPLUS Label resolver - 3.50" / DEFB 0AH 4C 41 42 45 4C 20 2D 20 44 4F 53 50 4C 55 53 20 4C 61 62 65 6C 20 72 65 73 6F 6C 76 65 72 20 2D 20 33 2E 35 30 0A
The heading (5701H): LABEL - DOSPLUS Label resolver - 3.50 and a line feed.
5A15-5A45
DEFM "(c) Copyright 1983, Micro-Systems Software Inc." / DEFB 0AH,0DH 28 63 29 20 43 6F 70 79 72 69 67 68 74 20 31 39 38 33 2C 20 4D 69 63 72 6F 2D 53 79 73 74 65 6D 73 20 53 6F 66 74 77 61 72 65 20 49 6E 63 2E 0A 0D
The copyright line, a line feed and the 0DH at which DSPLY@ stops.
5A46-5A5D
DEFM "Source filespec : " / DEFB 03H 53 6F 75 72 63 65 20 66 69 6C 65 73 70 65 63 20 20 20 20 20 20 3A 20 03
The prompt for the source program (571AH), ended by 03H.
5A5E-5A75
DEFM "Destination filespec : " / DEFB 03H 44 65 73 74 69 6E 61 74 69 6F 6E 20 66 69 6C 65 73 70 65 63 20 3A 20 03
The prompt for the destination program (5734H), ended by 03H.
5A76-5A88
DEFM "Invalid file type!" / DEFB 0DH 49 6E 76 61 6C 69 64 20 66 69 6C 65 20 74 79 70 65 21 0D
The message for a source whose first byte is not FFH (5766H).
5A89-5A96
DEFM "Out of memory" / DEFB 0DH 4F 75 74 20 6F 66 20 6D 65 6D 6F 72 79 0D
The message of 59DDH, when the table of labels reaches Register Pair DE.
5A97-5AA1
DEFM "Scanning -" / DEFB 0DH 53 63 61 6E 6E 69 6E 67 20 2D 0D
The message shown at the start of the first pass (576EH).
5AA2-5AAF
DEFB 1BH,1FH / DEFM "Resolving -" / DEFB 0DH 1B 1F 52 65 73 6F 6C 76 69 6E 67 20 2D 0D
The message of the second pass (580BH), after the cursor up (1BH) and the clear to the end of the screen (1FH).
5AB0-5AB8
DEFM "Line #: " / DEFB 03H 4C 69 6E 65 20 23 3A 20 03
The text before the line number in both passes (579BH, 5855H).
5AB9-5AC8
DEFB 19H,19H,19H,19H,19H,19H,19H,19H,19H,19H,19H,19H,19H,19H,19H,19H 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19
Sixteen cursor moves to the right (19H), past the Line #: of the line (592BH).
5AC9-5ADA
DEFM "Undefined Label: " / DEFB 03H 55 6E 64 65 66 69 6E 65 64 20 4C 61 62 65 6C 3A 20 03
The text before a label that is not in the table, ended by 03H.
5ADB-5AE2
DEFB 8DH,91H,9DH,9FH,B4H,B5H,B6H,B7H 8D 91 9D 9F B4 B5 B6 B7
The keywords that take line numbers (5890H): GOTO, GOSUB, EDIT, RESUME, LIST, LLIST, DELETE and AUTO.
5AE3
DEFB 00H 00
The 00H that ends the table of the keywords taking line numbers.
5AE4-5AE5
DEFW 0000H 00 00
The line number of the line of the first pass (578DH), put into its entry of the table (57E8H).
5AE6-5BE5
DEFS 256
The buffer of the replies to the prompts (5975H), the digits of a line number (5794H) and the label looked up (58E5H).
5BE6-5C05
DEFS 32
The file control block of the source program (5708H).
5C06-5D05
DEFS 256
The 256 byte buffer of the source program (5751H).
5D06-5D25
DEFS 32
The file control block of the destination program (5710H).
5D26-5E25
DEFS 256
The buffer of the destination program (5814H).
5E26
DEFS 1
The start of the table of labels (5774H, 5921H): each entry the label, 00H and the line number, the table ended by 00H; it grows upwards.