5200H - The Start: the Banner
The transfer address. BASIC/CMD runs this file with @RUN for CMD"N text" (its 547CH): the file loads over BASIC/CMD at 5200H and is entered with Register Pair HL at the text after the N, which BASIC/CMD copied to 4226H with a 0DH after it. The spaces before the parameters are passed over, the banner is shown and then Checking for errors.
5200
LD A,(HL) 7E
Load Register A with the character at Register Pair HL, the command line after the N.
5201
CP 20H FE 20
Compare Register A against 20H, a space: the Z FLAG for a space.
5203
If the NZ FLAG is set (not a space), JUMP to 5208H with Register Pair HL at the first character of the parameters.
5205
INC HL 23
INCrement Register Pair HL past the space to the next character of the command line.
5206
LOOP BACK to 5200H for the next character of the command line.
5208
PUSH HL E5
Save Register Pair HL (the start of the parameters) to the stack, for 521DH.
5209
LD HL,55D2H 21 D2 55
Point Register Pair HL to 55D2H, the banner: 1CH (cursor home), 1FH (clear to the end of the screen) and the name and copyright lines, ended by 0DH at 5636H.
520C
GOSUB to 4467H, @DSPLY, to display the text at Register Pair HL up to its 0DH.
520F
LD HL,5637H 21 37 56
Point Register Pair HL to 5637H, the text Checking for errors and 0DH. It is shown whether or not the ! option is given.
5212
GOSUB to 553BH to display the text at Register Pair HL with @DSPLY, keeping Register Pair DE and Index Register IY.
5215H - A Program Numbered from 0
The number of the first line of the program must not be 0, else Error in line 0. A line numbered 0 keeping its number would have 0000H in its link bytes during the passes, the end mark to 559EH.
5215
LD HL,(40A4H) 2A A4 40
Load Register Pair HL with 40A4H-40A5H, the ROM's pointer to the start of the BASIC program text: the first line, its link at +00H-+01H and its number at +02H-+03H.
5218
INC HL 23
INCrement Register Pair HL to +01H, the high byte of the first line's link.
5219
INC HL 23
INCrement Register Pair HL to +02H, the low byte of the first line's number.
521A
LD A,(HL) 7E
Load Register A with the low byte of the first line's number at Register Pair HL.
521B
INC HL 23
INCrement Register Pair HL to +03H, the high byte of the first line's number.
521C
OR (HL) B6
OR Register A (the low byte) with the high byte at Register Pair HL: the Z FLAG when the first line's number is 0.
521D
POP DE D1
Restore Register Pair DE from the stack: the start of the parameters, saved at 5208H. POP does not change the flags.
521E
If the Z FLAG is set (the first line is numbered 0), JUMP to 5545H to show Error in line 0 and go back to BASIC with nothing changed.
5221H - The Stack and the ! Option
The stack is moved to HIGH$, above the program text. An exclamation mark first on the line sets 56A7H to 01H: the references are then changed in one pass with no check for errors before it.
5221
LD HL,(4411H) 2A 11 44
Load Register Pair HL with HIGH$ from 4411H-4412H, the highest address free for programs.
5224
LD SP,HL F9
Load the Stack Pointer with Register Pair HL (HIGH$): the stack lies above the program text and the line buffer at 5700H. This file never returns; it ends by running BASIC/CMD (5551H).
5225
EX DE,HL EB
Exchange Register Pair DE (the start of the parameters) with Register Pair HL, so Register Pair HL points at the parameters.
5226
XOR A AF
Load Register A with 00H (XOR A), for the pass flag.
5227
LD (56A7H),A 32 A7 56
Store Register A (00H) at 56A7H, the pass flag: 00H for a pass that only checks the references, 01H for the pass that changes them.
522A
LD A,(HL) 7E
Load Register A with the first character of the parameters at Register Pair HL.
522B
CP 21H FE 21
Compare Register A against 21H, an exclamation mark: the Z FLAG for the ! option.
522D
If the NZ FLAG is set (no ! option), JUMP to 5237H with the pass flag 00H.
522F
LD A,01H 3E 01
Load Register A with 01H, the pass flag of the pass that changes the references.
5231
LD (56A7H),A 32 A7 56
Store Register A (01H) at 56A7H, the pass flag: with the ! option the check pass is left out.
5234
GOSUB to 55BEH to step Register Pair HL past the exclamation mark and the spaces after it.
5237H - The Four Parameters
CMD"N first,new,increment,last": the first line to renumber (569BH, 1 in the file), the new number of that line (569DH, 20), the increment (569FH, 20) and the last line to renumber (56A1H, 65529). Each is a decimal number; a comma alone keeps the value in the file. A number above 65535 or any other character than a comma after a number gives Bad parameters. A value of 0 is not stored and the slot is not passed, so the next number goes into it. Text after a fourth comma is not read.
5237
LD B,04H 06 04
Load Register B with 04H, the count of the parameters.
5239
LD IX,569BH DD 21 9B 56
Point Index Register IX to 569BH, the cell of the first parameter; the four 2 byte cells follow one another.
523D
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
523E
CP 0DH FE 0D
Compare Register A against 0DH, the end of the command line.
5240
If the Z FLAG is set (no parameters), JUMP to 527BH with every cell as it is in the file.
5242
LD E,(IX+00H) DD 5E 00
Load Register E with the low byte of the parameter's cell at Index Register IX +00H, its value so far.
5245
LD D,(IX+01H) DD 56 01
Load Register D with the high byte of the parameter's cell at Index Register IX +01H: Register Pair DE = the value so far.
5248
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
5249
CP 2CH FE 2C
Compare Register A against 2CH, a comma: the Z FLAG when this parameter is left out.
524B
If the Z FLAG is set (a comma), JUMP to 525DH to store the value so far (Register Pair DE) and go to the next cell.
524D
PUSH BC C5
Save Register Pair BC (Register B = the count of the parameters left) to the stack: 5506H changes Register B.
524E
PUSH IX DD E5
Save Index Register IX (the cell of the parameter) to the stack.
5250
GOSUB to 54EFH to read the decimal number at Register Pair HL into Register Pair DE: the CARRY FLAG when it is above 65535, Register Pair HL after the digits.
5253
POP IX DD E1
Restore Index Register IX (the cell of the parameter) from the stack.
5255
POP BC C1
Restore Register Pair BC (Register B = the count of the parameters left) from the stack.
5256
If the CARRY FLAG is set (the number is above 65535), JUMP to 54C1H to show Bad parameters.
5259
LD A,D 7A
Load Register A with Register D, the high byte of the number.
525A
OR E B3
OR Register A with Register E, the low byte of the number: the Z FLAG for 0, or for no digits at all.
525B
If the Z FLAG is set (0), JUMP to 5267H: nothing is stored and Index Register IX stays at this cell.
525D
LD (IX+00H),E DD 73 00
Store Register E (the low byte of the value) at Index Register IX +00H, the low byte of the parameter's cell.
5260
INC IX DD 23
INCrement Index Register IX to the high byte of the cell.
5262
LD (IX+00H),D DD 72 00
Store Register D (the high byte of the value) at Index Register IX +00H, the high byte of the parameter's cell.
5265
INC IX DD 23
INCrement Index Register IX to the next parameter's cell.
5267
LD A,(HL) 7E
Load Register A with the character at Register Pair HL, after the number.
5268
CP 0DH FE 0D
Compare Register A against 0DH, the end of the command line.
526A
If the Z FLAG is set (the end), JUMP to 527BH: the cells not reached keep their values.
526C
CP 2CH FE 2C
Compare Register A against 2CH, a comma, the only character allowed after a number.
526E
If the NZ FLAG is set (not a comma), JUMP to 54C1H to show Bad parameters.
5271
GOSUB to 55BEH to step Register Pair HL past the comma and the spaces after it.
5274
LD A,(HL) 7E
Load Register A with the character at Register Pair HL, after the comma.
5275
CP 0DH FE 0D
Compare Register A against 0DH, the end of the command line.
5277
If the Z FLAG is set (the line ends after a comma), JUMP to 527BH.
5279
DECrement Register B (the count of the parameters left) and LOOP BACK to 5242H while it is not 0; after the fourth the rest of the line is not read.
527BH - The Bound of the New Numbers
When the last line to renumber is a line of the program, 56A1H becomes the number of the line after it less 1, or 65529 (FFF9H) when it is the last line of the program. The renumbered lines are then those up to it, and their new numbers must stay below the lines that follow. When the last line is not a line of the program, its number stays in 56A1H as both limits. Above 65530 gives Bad parameters.
527B
LD DE,(56A1H) ED 5B A1 56
Load Register Pair DE with the last line to renumber from 56A1H-56A2H.
527F
GOSUB to 1B2CH, the ROM's FNDLIN, to search the program for the line whose number is in Register Pair DE (kept): the CARRY FLAG when it is found, Register Pair HL then at the line after it.
5282
If the NO CARRY FLAG is set (no such line), JUMP to 5295H with the number in Register Pair DE as it is.
5284
LD A,(HL) 7E
Load Register A with the low byte of the link at Register Pair HL, the start of the line after the last line.
5285
INC HL 23
INCrement Register Pair HL to the high byte of that link.
5286
OR (HL) B6
OR Register A with the high byte of the link at Register Pair HL: the Z FLAG for 0000H, the end of the program.
5287
LD DE,FFF9H 11 F9 FF
Load Register Pair DE with FFF9H, 65529, the bound when no line follows. LD does not change the flags.
528A
If the Z FLAG is set (the last line is the last of the program), JUMP to 5291H to store 65529.
528C
INC HL 23
INCrement Register Pair HL to +02H of the line after the last line, the low byte of its number.
528D
LD E,(HL) 5E
Load Register E with the low byte of that line's number at Register Pair HL.
528E
INC HL 23
INCrement Register Pair HL to +03H, the high byte of that line's number.
528F
LD D,(HL) 56
Load Register D with the high byte of that line's number at Register Pair HL: Register Pair DE = the number of the next line.
5290
DEC DE 1B
DECrement Register Pair DE: the highest number the renumbered lines may take.
5291
LD (56A1H),DE ED 53 A1 56
Store Register Pair DE (the bound) at 56A1H-56A2H, the last line cell.
5295
LD HL,FFFAH 21 FA FF
Load Register Pair HL with FFFAH, 65530, the limit of a line number here.
5298
RST 18H DF
RST 18H, the ROM's compare of Register Pair HL (65530) with Register Pair DE (the bound): the CARRY FLAG when Register Pair DE is above 65530.
5299
If the CARRY FLAG is set (above 65530), JUMP to 54C1H to show Bad parameters.
529CH - The First Pass: the New Number of Every Line
Every line is given its new number in its link bytes (+00H-+01H), its own number staying at +02H-+03H: a line below the first line to renumber keeps its number, which must be below the new number of the first line; the lines from the first to the bound (56A1H) are numbered from 569DH by 569FH, each new number not above the bound and the next one below 65530; the lines after them keep their numbers. Any other case gives Bad parameters. The links are rebuilt from the text at the end (54C7H).
529C
LD HL,(569DH) 2A 9D 56
Load Register Pair HL with the new number of the first line from 569DH-569EH.
529F
LD (56A5H),HL 22 A5 56
Store Register Pair HL (the new number of the first line) at 56A5H-56A6H, to be put back at 5313H.
52A2
LD IX,(40A4H) DD 2A A4 40
Load Index Register IX with 40A4H-40A5H, the start of the program text: the first line.
52A6
GOSUB to 559EH to test the link of the line at Index Register IX: the Z FLAG for 0000H, the end of the program.
52A9
If the Z FLAG is set (every line is below the first line to renumber), JUMP to 5479H to put the numbers in place.
52AC
LD L,(IX+02H) DD 6E 02
Load Register L with the low byte of the line's number at Index Register IX +02H.
52AF
LD H,(IX+03H) DD 66 03
Load Register H with the high byte of the line's number at Index Register IX +03H: Register Pair HL = the line's number.
52B2
LD DE,(569BH) ED 5B 9B 56
Load Register Pair DE with the first line to renumber from 569BH-569CH.
52B6
RST 18H DF
RST 18H, the ROM's compare of Register Pair HL (the line's number) with Register Pair DE (the first line to renumber): the CARRY FLAG when the line is below it.
52B7
If the NO CARRY FLAG is set (the line is the first to renumber or above), JUMP to 52CCH.
52B9
LD (IX+01H),H DD 74 01
Store Register H (the high byte of the line's number) at Index Register IX +01H, the high byte of the link: the line keeps its number.
52BC
LD (IX+00H),L DD 75 00
Store Register L (the low byte of the line's number) at Index Register IX +00H, the low byte of the link.
52BF
LD DE,(569DH) ED 5B 9D 56
Load Register Pair DE with the new number of the first line from 569DH-569EH.
52C3
RST 18H DF
RST 18H, the ROM's compare of Register Pair HL (the line's number) with Register Pair DE (the new number of the first line): the CARRY FLAG when the line is below it.
52C4
If the NO CARRY FLAG is set (a line before the range would not be below the renumbered lines), JUMP to 54C1H to show Bad parameters.
52C7
GOSUB to 558EH to move Index Register IX to the next line by its text.
52CA
LOOP BACK to 52A6H for the next line of the program, still below the first line to renumber.
52CC
LD DE,(569DH) ED 5B 9D 56
Load Register Pair DE with the new number for this line from 569DH-569EH.
52D0
LD HL,(56A1H) 2A A1 56
Load Register Pair HL with the bound from 56A1H-56A2H.
52D3
RST 18H DF
RST 18H, the ROM's compare of Register Pair HL (the bound) with Register Pair DE (the new number): the CARRY FLAG when the new number is above the bound.
52D4
If the CARRY FLAG is set (the new number is above the bound), JUMP to 54C1H to show Bad parameters.
52D7
LD (IX+01H),D DD 72 01
Store Register D (the high byte of the new number) at Index Register IX +01H, the high byte of the link.
52DA
LD (IX+00H),E DD 73 00
Store Register E (the low byte of the new number) at Index Register IX +00H, the low byte of the link.
52DD
LD HL,(569FH) 2A 9F 56
Load Register Pair HL with the increment from 569FH-56A0H.
52E0
ADD HL,DE 19
ADD Register Pair DE (the new number) to Register Pair HL (the increment): the number for the next line, the CARRY FLAG above 65535.
52E1
If the CARRY FLAG is set (above 65535), JUMP to 54C1H to show Bad parameters.
52E4
LD DE,FFFAH 11 FA FF
Load Register Pair DE with FFFAH, 65530, the limit of the number for the next line.
52E7
RST 18H DF
RST 18H, the ROM's compare of Register Pair HL (the next number) with Register Pair DE (65530): the CARRY FLAG when it is below 65530.
52E8
If the NO CARRY FLAG is set (65530 or more), JUMP to 54C1H to show Bad parameters, also when no line is left to take it.
52EB
LD (569DH),HL 22 9D 56
Store Register Pair HL (the next number) at 569DH-569EH.
52EE
GOSUB to 558EH to move Index Register IX to the next line by its text: the Z FLAG at the end of the program.
52F1
If the Z FLAG is set (the end), JUMP to 5313H.
52F3
LD H,(IX+03H) DD 66 03
Load Register H with the high byte of the line's number at Index Register IX +03H.
52F6
LD L,(IX+02H) DD 6E 02
Load Register L with the low byte of the line's number at Index Register IX +02H: Register Pair HL = the line's number.
52F9
LD DE,(56A1H) ED 5B A1 56
Load Register Pair DE with the bound from 56A1H-56A2H.
52FD
RST 18H DF
RST 18H, the ROM's compare of Register Pair HL (the line's number) with Register Pair DE (the bound): the Z FLAG when equal, the CARRY FLAG when below.
52FE
If the Z FLAG is set (the line is the bound), JUMP to 52CCH to renumber it.
5300
If the CARRY FLAG is set (the line is below the bound), JUMP to 52CCH to renumber it.
5302
LD A,(IX+02H) DD 7E 02
Load Register A with the low byte of the line's number at Index Register IX +02H: a line after the range keeps its number.
5305
LD (IX+00H),A DD 77 00
Store Register A (the low byte) at Index Register IX +00H, the low byte of the link.
5308
LD A,(IX+03H) DD 7E 03
Load Register A with the high byte of the line's number at Index Register IX +03H.
530B
LD (IX+01H),A DD 77 01
Store Register A (the high byte) at Index Register IX +01H, the high byte of the link.
530E
GOSUB to 558EH to move Index Register IX to the next line by its text: the Z FLAG at the end of the program.
5311
If the NZ FLAG is set (another line), LOOP BACK to 5302H.
5313H - Which Pass Comes First
Without the ! option the references are first only checked (56A7H = 00H); when that pass ends with no error, No errors is shown, 56A7H becomes 01H and the same pass is run again to change them. With the ! option No errors is shown at once and only the pass that changes them is run. At the end of the changing pass the new numbers are put in place (5479H).
5313
LD HL,(56A5H) 2A A5 56
Load Register Pair HL with the new number of the first line, kept at 56A5H-56A6H by 529FH.
5316
LD (569DH),HL 22 9D 56
Store Register Pair HL at 569DH-569EH: the cell gets back its value before the first pass; no code reads it afterwards.
5319
LD A,(56A7H) 3A A7 56
Load Register A with the pass flag from 56A7H: 01H with the ! option.
531C
OR A B7
OR Register A with itself: the Z FLAG for 00H, no ! option.
531D
If the Z FLAG is set (no ! option), JUMP to 5333H for the pass that only checks the references.
531F
JUMP to 532DH to show No errors and run the pass that changes the references.
5321
LD A,(56A7H) 3A A7 56
Load Register A with the pass flag from 56A7H: 5333H's pass ends here at the end of the program.
5324
OR A B7
OR Register A with itself: the NZ FLAG after the pass that changed the references.
5325
If the NZ FLAG is set (the references are changed), JUMP to 5479H to put the new numbers in place.
5328
LD A,01H 3E 01
Load Register A with 01H, the pass flag of the pass that changes the references.
532A
LD (56A7H),A 32 A7 56
Store Register A (01H) at 56A7H, the pass flag.
532D
LD HL,567EH 21 7E 56
Point Register Pair HL to 567EH, the text No errors and 0DH.
5330
GOSUB to 553BH to display the text at Register Pair HL with @DSPLY, keeping Register Pair DE and Index Register IY.
5333H - The Reference Pass: Copying a Line
Each line's text (from +04H) is copied to the buffer at 5700H, a byte at a time, with the count in the alternate Register A; 255 bytes give Buffer overflow. Outside quotes the tokens THEN, ELSE, RESUME, GOTO, GOSUB, RUN and ERL (55A8H) are followed by line numbers (53FBH). 56A5H is set when a number of the line is changed. In the pass that only checks, the buffer is not used further; in the pass that changes the references a changed line is written back (538AH).
5333
LD IX,(40A4H) DD 2A A4 40
Load Index Register IX with 40A4H-40A5H, the start of the program text: the first line.
5337
XOR A AF
Load Register A with 00H (XOR A), for the quote flag.
5338
LD (56A9H),A 32 A9 56
Store Register A (00H) at 56A9H, the quote flag: 00H outside quotes, 01H inside.
533B
GOSUB to 559EH to test the link of the line at Index Register IX: the Z FLAG for 0000H, the end of the program (the links hold the new numbers now, never 0000H).
533E
If the Z FLAG is set (the end of the program), JUMP to 5321H: the pass is done.
5340
PUSH IX DD E5
Save Index Register IX (the start of the line) to the stack.
5342
POP IY FD E1
Restore Index Register IY from the stack: Index Register IY = the start of the line, the pointer that moves through its text.
5344
LD HL,(56A3H) 2A A3 56
Load Register Pair HL with the address of the line buffer from 56A3H-56A4H: 5700H.
5347
LD A,00H 3E 00
Load Register A with 00H, the count of the bytes in the buffer.
5349
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF: the count is kept in the alternate Register A.
534A
XOR A AF
Load Register A with 00H (XOR A), for the changed flag.
534B
LD (56A5H),A 32 A5 56
Store Register A (00H) at 56A5H, the changed flag: 01H once a line number in this line is changed (5466H).
534E
LD A,(IY+04H) FD 7E 04
Load Register A with the byte of the text at Index Register IY +04H; the text of a line starts after its link and its number.
5351
LD (HL),A 77
Store Register A (the byte) at Register Pair HL in the buffer.
5352
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF: Register A = the count of the bytes.
5353
INC A 3C
INCrement Register A, the count of the bytes in the buffer.
5354
CP FFH FE FF
Compare Register A against FFH: the Z FLAG at the 255th byte.
5356
If the Z FLAG is set (255 bytes), JUMP to 5493H to show Buffer overflow.
5359
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF: Register A = the byte again, the count kept.
535A
OR A B7
OR Register A (the byte) with itself: the Z FLAG for 00H, the end of the line.
535B
If the Z FLAG is set (the end of the line), JUMP to 5379H.
535D
LD (HL),A 77
Store Register A (the byte) at Register Pair HL in the buffer once more.
535E
CP 22H FE 22
Compare Register A against 22H, a quote: the Z FLAG for a quote. The two LD below do not change the flags.
5360
LD A,(56A9H) 3A A9 56
Load Register A with the quote flag from 56A9H.
5363
If the NZ FLAG is set (not a quote), JUMP to 5367H with the quote flag as it is.
5365
XOR 01H EE 01
Flip bit 0 of Register A (the quote flag): a quote opens or closes a string.
5367
LD (56A9H),A 32 A9 56
Store Register A (the quote flag, flipped at a quote) at 56A9H for the next byte.
536A
OR A B7
OR Register A (the quote flag) with itself: the NZ FLAG inside quotes.
536B
If the NZ FLAG is set (inside quotes), JUMP to 5374H: no token is looked for.
536D
LD A,(HL) 7E
Load Register A with the byte from the buffer at Register Pair HL.
536E
GOSUB to 55A8H to test Register A for a token followed by line numbers: the Z FLAG for THEN, ELSE, RESUME, GOTO, GOSUB, RUN or ERL.
5371
If the Z FLAG is set (such a token), JUMP to 53FBH to read the line numbers after it.
5374
INC IY FD 23
INCrement Index Register IY to the next byte of the text.
5376
INC HL 23
INCrement Register Pair HL to the next byte of the buffer.
5377
LOOP BACK to 534EH for the next byte of the line.
5379H - The End of a Line
A line with no changed number, or any line of the pass that only checks, is passed over. In the pass that changes the references, a changed line is written back: the rest of the program (to the second byte of the end mark) is moved down or up by the difference in length, then the text in the buffer is copied over the old text. The program is moved up with no test for room.
5379
LD A,(56A5H) 3A A5 56
Load Register A with the changed flag from 56A5H.
537C
OR A B7
OR Register A with itself: the Z FLAG when no number of the line was changed (or 00H from 53F8H after a line is written back).
537D
If the NZ FLAG is set (a number was changed), JUMP to 5384H.
537F
GOSUB to 558EH to move Index Register IX to the next line by its text.
5382
LOOP BACK to 5337H for the next line, with the quote flag cleared.
5384
LD A,(56A7H) 3A A7 56
Load Register A with the pass flag from 56A7H.
5387
OR A B7
OR Register A with itself: the Z FLAG in the pass that only checks the references.
5388
If the Z FLAG is set (the check pass), JUMP to 537FH: the line is not written back.
538A
PUSH IX DD E5
Save Index Register IX (the start of the line) to the stack.
538C
GOSUB to 558EH to move Index Register IX to the next line: the Z FLAG when it is the end mark.
538F
PUSH IX DD E5
Save Index Register IX (the next line) to the stack.
5391
If the Z FLAG is set (the next line is the end mark), JUMP to 5398H.
5393
GOSUB to 558EH to move Index Register IX to the next line: the Z FLAG at the end mark.
5396
If the NZ FLAG is set (not the end), LOOP BACK to 5393H: Index Register IX ends at the end mark of the program.
5398
PUSH IX DD E5
Save Index Register IX (the end mark) to the stack.
539A
POP HL E1
Restore Register Pair HL from the stack: Register Pair HL = the end mark, the 0000H link after the last line.
539B
INC HL 23
INCrement Register Pair HL to the second byte of the end mark, the last byte of the program text.
539C
POP DE D1
Restore Register Pair DE from the stack: the start of the next line (538FH).
539D
POP IX DD E1
Restore Index Register IX from the stack: the start of this line (538AH).
539F
PUSH IX DD E5
Save Index Register IX (the start of this line) to the stack again, for 53E6H.
53A1
PUSH HL E5
Save Register Pair HL (the last byte of the program text) to the stack.
53A2
PUSH DE D5
Save Register Pair DE (the next line) to the stack.
53A3
INC HL 23
INCrement Register Pair HL to the byte after the program text.
53A4
SBC HL,DE ED 52
SUBtract Register Pair DE (the next line) from Register Pair HL with the CARRY FLAG (cleared by the OR in 559EH): Register Pair HL = the bytes from the next line to the end mark's second byte.
53A6
PUSH HL E5
Save Register Pair HL (the count of the bytes to move) to the stack.
53A7
POP BC C1
Restore Register Pair BC from the stack: Register Pair BC = the count of the bytes to move.
53A8
POP DE D1
Restore Register Pair DE from the stack: the next line.
53A9
POP HL E1
Restore Register Pair HL from the stack: the last byte of the program text.
53AA
LD IY,(56A3H) FD 2A A3 56
Load Index Register IY with the address of the line buffer from 56A3H-56A4H: 5700H.
53AE
LD A,(IX+04H) DD 7E 04
Load Register A with the byte of the old text at Index Register IX +04H.
53B1
OR A B7
OR Register A with itself: the Z FLAG at the 00H ending the old text.
53B2
If the Z FLAG is set (the old text is no longer), JUMP to 53D1H.
53B4
LD A,(IY+00H) FD 7E 00
Load Register A with the byte of the new text at Index Register IY +00H.
53B7
OR A B7
OR Register A with itself: the Z FLAG at the 00H ending the new text.
53B8
If the Z FLAG is set (the new text is shorter), JUMP to 53C0H.
53BA
INC IX DD 23
INCrement Index Register IX to the next byte of the old text.
53BC
INC IY FD 23
INCrement Index Register IY to the next byte of the new text.
53BE
LOOP BACK to 53AEH while both texts go on, Index Registers IX and IY side by side.
53C0
PUSH DE D5
Save Register Pair DE (the next line) to the stack.
53C1
POP HL E1
Restore Register Pair HL from the stack: Register Pair HL = the next line, the start of the bytes to move down.
53C2
LD A,(IX+04H) DD 7E 04
Load Register A with the byte of the old text at Index Register IX +04H.
53C5
OR A B7
OR Register A with itself: the Z FLAG at the 00H ending the old text.
53C6
If the Z FLAG is set (the end of the old text), JUMP to 53CDH.
53C8
DEC DE 1B
DECrement Register Pair DE: the destination moves down one byte for each byte the old text is longer.
53C9
INC IX DD 23
INCrement Index Register IX to the next byte of the old text.
53CB
LOOP BACK to 53C2H for the next byte of the old text past the length of the new text.
53CD
LDIR ED B0
Copy Register Pair BC bytes from Register Pair HL (the next line) to Register Pair DE (lower by the difference), first byte first: the rest of the program moves down.
53CF
JUMP to 53E6H to copy the new text from the buffer over the old one.
53D1
LD A,(IY+00H) FD 7E 00
Load Register A with the byte of the new text at Index Register IY +00H.
53D4
OR A B7
OR Register A with itself: the Z FLAG when the new text ends with the old.
53D5
If the Z FLAG is set (the same length), JUMP to 53E6H: nothing is moved.
53D7
PUSH HL E5
Save Register Pair HL (the last byte of the program text) to the stack.
53D8
POP DE D1
Restore Register Pair DE from the stack: Register Pair DE = the last byte of the program text.
53D9
LD A,(IY+00H) FD 7E 00
Load Register A with the byte of the new text at Index Register IY +00H.
53DC
OR A B7
OR Register A with itself: the Z FLAG at the 00H ending the new text.
53DD
If the Z FLAG is set (the end of the new text), JUMP to 53E4H.
53DF
INC DE 13
INCrement Register Pair DE: the destination moves up one byte for each byte the new text is longer.
53E0
INC IY FD 23
INCrement Index Register IY to the next byte of the new text.
53E2
LOOP BACK to 53D9H for the next byte of the new text past the length of the old text.
53E4
LDDR ED B8
Copy Register Pair BC bytes from Register Pair HL (the last byte of the program text) to Register Pair DE (higher by the difference), last byte first: the rest of the program moves up.
53E6
POP IX DD E1
Restore Index Register IX from the stack: the start of the line (539FH).
53E8
LD DE,(56A3H) ED 5B A3 56
Load Register Pair DE with the address of the line buffer from 56A3H-56A4H: 5700H.
53EC
LD A,(DE) 1A
Load Register A with the byte of the new text at Register Pair DE.
53ED
LD (IX+04H),A DD 77 04
Store Register A (the byte) at Index Register IX +04H, the text of the line.
53F0
OR A B7
OR Register A with itself: the Z FLAG for the 00H ending the line.
53F1
If the Z FLAG is set (the end of the line), JUMP to 53F8H.
53F3
INC IX DD 23
INCrement Index Register IX to the next byte of the line.
53F5
INC DE 13
INCrement Register Pair DE to the next byte of the buffer.
53F6
LOOP BACK to 53ECH for the next byte of the new text in the buffer.
53F8
XOR A AF
Load Register A with 00H (XOR A): 537CH then goes on to the next line.
53F9
JUMP to 537CH with Register A = 00H and Index Register IX at the end of the line written back.
53FBH - The Line Numbers after a Token
After the token, spaces and control characters, commas (the list of ON n GOTO), the = token (D5H, as in ERL=n) and the digit 0 are copied as they are; 0 starts no number, so GOTO 0 and RESUME 0 are left alone, and digits after a 0 are read as a number of their own. A number of other digits is read into Register Pair DE without copying it, the line with that number is searched for by its old number (+02H-+03H), and the text of its new number (from its link bytes) is put in the buffer. Any other character ends the numbers and is handled by the copy loop (5351H). A line not found, or a number above 65535 (shown as line 0), gives Can not find line.
53FB
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H, the number being read. LD does not change the flags.
53FE
LD (HL),A 77
Store Register A (the byte: the token, or a character that may come between the numbers) at Register Pair HL in the buffer.
53FF
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF: Register A = the count of the bytes.
5400
INC A 3C
INCrement Register A, the count of the bytes in the buffer.
5401
CP FFH FE FF
Compare Register A against FFH: the Z FLAG at the 255th byte.
5403
If the Z FLAG is set (255 bytes), JUMP to 5493H to show Buffer overflow.
5406
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF: the count kept again.
5407
INC HL 23
INCrement Register Pair HL to the next byte of the buffer.
5408
INC IY FD 23
INCrement Index Register IY to the next byte of the text.
540A
LD A,(IY+04H) FD 7E 04
Load Register A with the byte of the text at Index Register IY +04H.
540D
OR A B7
OR Register A with itself: the Z FLAG for the 00H ending the line.
540E
If the Z FLAG is set (the end of the line), JUMP to 5351H to store the 00H and end the line.
5411
CP 21H FE 21
Compare Register A against 21H: the CARRY FLAG for a space or a control character.
5413
If the CARRY FLAG is set (a space), JUMP to 53FBH to copy it.
5415
CP 2CH FE 2C
Compare Register A against 2CH, a comma, between the numbers of ON n GOTO.
5417
If the Z FLAG is set (a comma), JUMP to 53FBH to copy it.
5419
CP D5H FE D5
Compare Register A against D5H, the token of =, as in ERL=n.
541B
If the Z FLAG is set (the = token), JUMP to 53FBH to copy it.
541D
CP 30H FE 30
Compare Register A against 30H, the digit 0, which does not start a line number here.
541F
If the Z FLAG is set (the digit 0), JUMP to 53FBH to copy it: no number is read.
5421
GOSUB to 54FFH to test Register A for a digit: the CARRY FLAG when it is not one.
5424
If the CARRY FLAG is set (not a digit), JUMP to 5351H: the numbers end and the copy loop takes the byte in Register A.
5427
GOSUB to 5506H to multiply Register Pair DE (the number so far) by 10 and add the digit in Register A: the CARRY FLAG above 65535.
542A
If the NO CARRY FLAG is set (no overflow), JUMP to 5431H.
542C
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H: a number above 65535 is reported as line 0.
542F
JUMP to 54A0H to show Can not find line with Register Pair DE = 0000H.
5431
INC IY FD 23
INCrement Index Register IY to the next byte of the text.
5433
LD A,(IY+04H) FD 7E 04
Load Register A with the byte of the text at Index Register IY +04H.
5436
GOSUB to 54FFH to test Register A for a digit: the NO CARRY FLAG for a digit.
5439
If the NO CARRY FLAG is set (a digit), LOOP BACK to 5427H to add it to Register Pair DE.
543B
PUSH IX DD E5
Save Index Register IX (the line being copied) to the stack.
543D
LD IX,(40A4H) DD 2A A4 40
Load Index Register IX with 40A4H-40A5H, the start of the program text, to search for the line numbered Register Pair DE.
5441
GOSUB to 559EH to test the link of the line at Index Register IX: the Z FLAG at the end of the program.
5444
JUMP to 5449H with the flags of 559EH, to test for the end before the first comparison.
5446
GOSUB to 558EH to move Index Register IX to the next line by its text: the Z FLAG at the end of the program.
5449
If the Z FLAG is set (no line has the number), JUMP to 549EH to show Can not find line.
544B
LD A,(IX+02H) DD 7E 02
Load Register A with the low byte of the line's old number at Index Register IX +02H.
544E
CP E BB
Compare Register A against Register E, the low byte of the number read.
544F
If the NZ FLAG is set (different), JUMP to 5446H for the next line.
5451
LD A,(IX+03H) DD 7E 03
Load Register A with the high byte of the line's old number at Index Register IX +03H.
5454
CP D BA
Compare Register A against Register D, the high byte of the number read.
5455
If the NZ FLAG is set (different), JUMP to 5446H for the next line.
5457
PUSH HL E5
Save Register Pair HL (the place in the buffer) to the stack.
5458
LD L,(IX+00H) DD 6E 00
Load Register L with the low byte of the line's new number from its link at Index Register IX +00H.
545B
LD H,(IX+01H) DD 66 01
Load Register H with the high byte of the line's new number at Index Register IX +01H: Register Pair HL = the new number.
545E
GOSUB to 557EH to turn Register Pair HL into decimal text: Register Pair DE returns at its first digit, the text ended by 00H.
5461
POP HL E1
Restore Register Pair HL (the place in the buffer) from the stack.
5462
POP IX DD E1
Restore Index Register IX (the line being copied) from the stack.
5464
LD A,01H 3E 01
Load Register A with 01H, for the changed flag.
5466
LD (56A5H),A 32 A5 56
Store Register A (01H) at 56A5H, the changed flag: the line has a reference to write back.
5469
LD A,(DE) 1A
Load Register A with the next digit of the new number at Register Pair DE.
546A
OR A B7
OR Register A with itself: the Z FLAG for the 00H ending the text.
546B
If the Z FLAG is set (all digits copied), JUMP to 540AH for the byte after the old number, at Index Register IY +04H.
546D
LD (HL),A 77
Store Register A (the digit) at Register Pair HL in the buffer.
546E
INC DE 13
INCrement Register Pair DE to the next digit.
546F
INC HL 23
INCrement Register Pair HL to the next byte of the buffer.
5470
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF: Register A = the count of the bytes.
5471
INC A 3C
INCrement Register A, the count of the bytes in the buffer.
5472
CP FFH FE FF
Compare Register A against FFH: the Z FLAG at the 255th byte.
5474
If the Z FLAG is set (255 bytes), JUMP to 5493H to show Buffer overflow.
5476
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF: the count kept again.
5477
LOOP BACK to 5469H for the next digit of the new number at Register Pair DE.
5479H - The New Numbers Put in Place
After the pass that changed the references, the new number of each line is copied from its link bytes (+00H-+01H) to its number (+02H-+03H). The links are rebuilt next (54C7H).
5479
LD IX,(40A4H) DD 2A A4 40
Load Index Register IX with 40A4H-40A5H, the start of the program text: the first line.
547D
GOSUB to 559EH to test the link of the line at Index Register IX: the Z FLAG at the end of the program.
5480
If the Z FLAG is set (the end), JUMP to 54C7H to rebuild the links.
5482
LD A,(IX+00H) DD 7E 00
Load Register A with the low byte of the new number from the link at Index Register IX +00H.
5485
LD (IX+02H),A DD 77 02
Store Register A at Index Register IX +02H, the low byte of the line's number.
5488
LD A,(IX+01H) DD 7E 01
Load Register A with the high byte of the new number from the link at Index Register IX +01H.
548B
LD (IX+03H),A DD 77 03
Store Register A at Index Register IX +03H, the high byte of the line's number.
548E
GOSUB to 558EH to move Index Register IX to the next line by its text.
5491
LOOP BACK to 547DH for the next line of the program at Index Register IX.
5493H - The Errors
Buffer overflow and Can not find line follow Error in line n. (5520H), n the old number of the line being copied; Bad parameters stands alone. Then the links are rebuilt and BASIC/CMD run again (54C7H). An error in the pass that only checks leaves the program as it was; in the pass that changes the references (the ! option) the lines before the error are already changed, but no line gets its new number.
5493
GOSUB to 5520H to display Error in line, the old number of the line at Index Register IX and a period.
5496
LD HL,565AH 21 5A 56
Point Register Pair HL to 565AH, the text Buffer overflow, 0AH and 0DH.
5499
GOSUB to 553BH to display the text at Register Pair HL with @DSPLY, keeping Register Pair DE and Index Register IY.
549C
JUMP to 54C7H to rebuild the links and go back to BASIC.
549E
POP IX DD E1
Restore Index Register IX from the stack: the line being copied (543BH), whose reference was not found.
54A0
PUSH DE D5
Save Register Pair DE (the line number not found) to the stack.
54A1
GOSUB to 5520H to display Error in line, the old number of the line at Index Register IX and a period.
54A4
LD HL,566BH 21 6B 56
Point Register Pair HL to 566BH, the text Can not find line and a space, ended by 03H.
54A7
GOSUB to 553BH to display the text at Register Pair HL with @DSPLY, keeping Register Pair DE and Index Register IY.
54AA
POP HL E1
Restore Register Pair HL from the stack: the line number not found.
54AB
GOSUB to 0FAFH, the ROM's LINPRT, to display the number in Register Pair HL in decimal.
54AE
LD HL,5697H 21 97 56
Point Register Pair HL to 5697H, the text of a period and two spaces, ended by 03H.
54B1
GOSUB to 553BH to display the text at Register Pair HL with @DSPLY, keeping Register Pair DE and Index Register IY.
54B4
GOSUB to 5538H to display 0DH, the end of the line on the screen.
54B7
JUMP to 54C7H to rebuild the links and go back to BASIC.
54B9
LD HL,(40A4H) 2A A4 40
Load Register Pair HL with 40A4H-40A5H, the start of the program text. No code jumps or calls to 54B9H.
54BC
LD A,01H 3E 01
Load Register A with 01H, for the byte at Register Pair HL. Not reached: nothing enters 54B9H.
54BE
LD (HL),A 77
Store Register A (01H) at Register Pair HL, the low byte of the first line's link. Not reached.
54BF
JUMP to 54C7H to rebuild the links and go back to BASIC. Not reached.
54C1
LD HL,564BH 21 4B 56
Point Register Pair HL to 564BH, the text Bad parameters and 0DH.
54C4
GOSUB to 553BH to display the text at Register Pair HL with @DSPLY, keeping Register Pair DE and Index Register IY.
54C7H - The Links Rebuilt, Back to BASIC
Every line's link is set again to the start of the next line, found by its text; the ROM's pointers to the variables, the arrays and the end of the arrays are set just after the end mark, so the variables are gone. Then BASIC/CMD is run (5551H).
54C7
LD IX,(40A4H) DD 2A A4 40
Load Index Register IX with 40A4H-40A5H, the start of the program text: the first line.
54CB
GOSUB to 559EH to test the link of the line at Index Register IX: the Z FLAG at the end mark (0000H), the only link that was never changed.
54CE
If the Z FLAG is set (the end mark), JUMP to 54DEH.
54D0
PUSH IX DD E5
Save Index Register IX (the line) to the stack.
54D2
POP HL E1
Restore Register Pair HL from the stack: Register Pair HL = the line, its link at +00H.
54D3
GOSUB to 558EH to move Index Register IX to the next line by its text.
54D6
PUSH IX DD E5
Save Index Register IX (the next line) to the stack.
54D8
POP DE D1
Restore Register Pair DE from the stack: Register Pair DE = the next line.
54D9
LD (HL),E 73
Store Register E (the low byte of the next line's address) at Register Pair HL, the low byte of the link.
54DA
INC HL 23
INCrement Register Pair HL to the high byte of the link.
54DB
LD (HL),D 72
Store Register D (the high byte of the next line's address) at Register Pair HL, the high byte of the link.
54DC
LOOP BACK to 54CBH for the next line of the program at Index Register IX.
54DE
PUSH IX DD E5
Save Index Register IX (the end mark) to the stack.
54E0
POP HL E1
Restore Register Pair HL from the stack: Register Pair HL = the end mark.
54E1
INC HL 23
INCrement Register Pair HL to the second byte of the end mark.
54E2
INC HL 23
INCrement Register Pair HL to the byte after the program text.
54E3
LD (40F9H),HL 22 F9 40
Store Register Pair HL at 40F9H-40FAH, the ROM's start of the simple variables.
54E6
LD (40FBH),HL 22 FB 40
Store Register Pair HL at 40FBH-40FCH, the ROM's start of the arrays.
54E9
LD (40FDH),HL 22 FD 40
Store Register Pair HL at 40FDH-40FEH, the ROM's end of the arrays: no variables are left.
54EC
JUMP to 5551H to run BASIC/CMD again with the program in memory.
54EFH - A Decimal Number
Reads the digits at Register Pair HL into Register Pair DE. Returns the NO CARRY FLAG with Register Pair HL at the first character that is not a digit (Register Pair DE = 0000H when there is none), or the CARRY FLAG when the number goes above 65535. Register B is changed (5506H).
54EF
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H, the number being read.
54F2
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
54F3
GOSUB to 54FFH to test Register A for a digit: the CARRY FLAG when it is not one.
54F6
CCF 3F
Complement the CARRY FLAG: the CARRY FLAG now set for a digit.
54F7
RET NC D0
If the NO CARRY FLAG is set (not a digit), RETURN with Register Pair DE = the number and Register Pair HL at the character.
54F8
GOSUB to 5506H to multiply Register Pair DE by 10 and add the digit in Register A: the CARRY FLAG above 65535.
54FB
INC HL 23
INCrement Register Pair HL to the next character. INC of a register pair does not change the flags.
54FC
RET C D8
If the CARRY FLAG is set (above 65535), RETURN with the CARRY FLAG.
54FD
LOOP BACK to 54F2H for the next character at Register Pair HL.
54FFH - A Digit
Tests Register A: the NO CARRY FLAG for a digit 0-9 (30H-39H), the CARRY FLAG for any other byte. Register A is not changed.
54FF
CP 30H FE 30
Compare Register A against 30H, the digit 0: the CARRY FLAG below it.
5501
RET C D8
If the CARRY FLAG is set (below 0), RETURN with the CARRY FLAG: not a digit.
5502
CP 3AH FE 3A
Compare Register A against 3AH, the byte after the digit 9: the CARRY FLAG for a digit.
5504
CCF 3F
Complement the CARRY FLAG: the NO CARRY FLAG for a digit, the CARRY FLAG above 9.
5505
RET C9
RETURN to the caller with the CARRY FLAG for a byte that is not a digit.
5506H - Times Ten Plus a Digit
Register Pair DE = Register Pair DE x 10 + the digit whose character is in Register A. The CARRY FLAG on return when the result is above 65535: Register Pair DE is then as it was when the overflow comes in the times ten, or the low 16 bits of the sum when it comes in adding the digit; the callers do not use Register Pair DE then. Register Pair HL is kept and Register B is changed; on the normal return Register A holds the digit's value.
5506
PUSH HL E5
Save Register Pair HL to the stack, to be kept.
5507
PUSH AF F5
Save Register Pair AF (Register A = the digit character) to the stack.
5508
PUSH DE D5
Save Register Pair DE (the number so far) to the stack.
5509
POP HL E1
Restore Register Pair HL from the stack: Register Pair HL = the number so far.
550A
LD B,09H 06 09
Load Register B with 09H: nine more additions of the number give ten times it.
550C
ADD HL,DE 19
ADD Register Pair DE (the number) to Register Pair HL: the CARRY FLAG above 65535.
550D
If the NO CARRY FLAG is set (no overflow), JUMP to 5513H.
550F
POP AF F1
Restore Register Pair AF (the digit character) from the stack.
5510
POP HL E1
Restore Register Pair HL from the stack, as it was on entry.
5511
SCF 37
Set the CARRY FLAG: the number is above 65535.
5512
RET C9
RETURN to the caller with the CARRY FLAG and Register Pair DE as it was.
5513
DECrement Register B and LOOP BACK to 550CH until Register Pair HL = the number x 10.
5515
POP AF F1
Restore Register Pair AF (the digit character) from the stack.
5516
SUB 30H D6 30
SUBtract 30H from Register A: the value of the digit, 0-9.
5518
LD E,A 5F
Copy Register A (the digit's value) into Register E.
5519
LD D,00H 16 00
Load Register D with 00H: Register Pair DE = the digit's value.
551B
ADC HL,DE ED 5A
ADD Register Pair DE (the digit's value) to Register Pair HL (the number x 10) with the CARRY FLAG (cleared by the SUB 30H at 5516H): the CARRY FLAG above 65535.
551D
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair DE = the new number.
551E
POP HL E1
Restore Register Pair HL from the stack, as it was on entry.
551F
RET C9
RETURN to the caller with the CARRY FLAG set for a number above 65535.
5520H - Error in line n.
Displays Error in line, then the old number (+02H-+03H) of the line at Index Register IX in decimal, then a period and two spaces. Index Register IX is kept.
5520
PUSH IX DD E5
Save Index Register IX (the line in error) to the stack.
5522
LD HL,5688H 21 88 56
Point Register Pair HL to 5688H, the text Error in line and a space, ended by 03H.
5525
GOSUB to 553BH to display the text at Register Pair HL with @DSPLY, keeping Register Pair DE and Index Register IY.
5528
POP IX DD E1
Restore Index Register IX (the line in error) from the stack.
552A
LD L,(IX+02H) DD 6E 02
Load Register L with the low byte of the line's number at Index Register IX +02H.
552D
LD H,(IX+03H) DD 66 03
Load Register H with the high byte of the line's number at Index Register IX +03H: Register Pair HL = the old number.
5530
GOSUB to 0FAFH, the ROM's LINPRT, to display the number in Register Pair HL in decimal.
5533
LD HL,5697H 21 97 56
Point Register Pair HL to 5697H, the text of a period and two spaces, ended by 03H.
5536
JUMP to 553BH to display it and return to the caller.
5538H - Showing a Text
5538H displays the 0DH at 5659H, the end of a line. 553BH displays the text at Register Pair HL with @DSPLY up to 03H (not shown) or 0DH (shown) and keeps Register Pair DE and Index Register IY.
5538
LD HL,5659H 21 59 56
Point Register Pair HL to 5659H, the 0DH after Bad parameters, to end the line on the screen.
553B
PUSH IY FD E5
Save Index Register IY to the stack, to be kept.
553D
PUSH DE D5
Save Register Pair DE to the stack, to be kept.
553E
GOSUB to 4467H, @DSPLY, to display the text at Register Pair HL.
5541
POP DE D1
Restore Register Pair DE from the stack, as it was before @DSPLY.
5542
POP IY FD E1
Restore Index Register IY from the stack, as it was before @DSPLY.
5544
RET C9
RETURN to the caller with Register Pair DE and Index Register IY as they were.
5545H - A Line Numbered 0
From 521EH: 30H 0DH are written over 5696H-5697H, so the text at 5688H becomes Error in line 0 and a new line. Nothing in the program is changed.
5545
LD HL,0D30H 21 30 0D
Load Register Pair HL with 0D30H: 30H (the digit 0) for 5696H and 0DH for 5697H.
5548
LD (5696H),HL 22 96 56
Store Register Pair HL at 5696H-5697H: the 03H ending Error in line becomes the digit 0, and the period after it becomes 0DH.
554B
LD HL,5688H 21 88 56
Point Register Pair HL to 5688H, the text Error in line 0 and 0DH.
554E
GOSUB to 553BH to display the text at Register Pair HL with @DSPLY, keeping Register Pair DE and Index Register IY.
5551H - Running BASIC/CMD Again
The name BASIC/CMD is put in the control block at 4485H and 2AH (an asterisk) over the first byte of the command line at 4225H, then @RUN loads BASIC/CMD and runs it with Register Pair HL at 4225H: BASIC with an asterisk goes back to the program in memory, and BASIC/CMD does not read the rest of that line on that path.
5551
LD HL,55C8H 21 C8 55
Point Register Pair HL to 55C8H, the text BASIC/CMD and 03H.
5554
LD DE,4485H 11 85 44
Point Register Pair DE to 4485H, CFCB$, the control block for the file to run.
5557
PUSH DE D5
Save Register Pair DE (4485H) to the stack, for @RUN.
5558
LD BC,000BH 01 0B 00
Load Register Pair BC with 000BH, the 11 bytes 55C8H-55D2H: the name, its 03H and the 1CH after it.
555B
LDIR ED B0
Copy Register Pair BC bytes from Register Pair HL (55C8H) to Register Pair DE (4485H): CFCB$ holds BASIC/CMD and 03H.
555D
POP DE D1
Restore Register Pair DE (4485H, the control block) from the stack.
555E
LD HL,4225H 21 25 42
Point Register Pair HL to 4225H, INBUF$, the command line buffer.
5561
LD (HL),2AH 36 2A
Store 2AH, an asterisk, at Register Pair HL (4225H): the command line of BASIC/CMD starts with it.
5563
JUMP to 4433H, @RUN, to load the file named at Register Pair DE (BASIC/CMD) and run it with Register Pair HL (4225H) as its command line.
5566H - Upper Case (Not Used)
Turns the lower case letters (61H-7AH) of the text at Register Pair HL into upper case, up to the first control character; Register Pair AF and Register Pair HL are kept. No code calls 5566H.
5566
PUSH AF F5
Save Register Pair AF to the stack, to be kept. Not reached: nothing calls 5566H.
5567
PUSH HL E5
Save Register Pair HL (the start of the text) to the stack, to be kept.
5568
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
5569
CP 20H FE 20
Compare Register A against 20H: the CARRY FLAG for a control character, the end of the text.
556B
If the CARRY FLAG is set (the end), JUMP to 557BH.
556D
CP 61H FE 61
Compare Register A against 61H, the letter a: the CARRY FLAG below it.
556F
If the CARRY FLAG is set (below a), JUMP to 5578H: the character is kept.
5571
CP 7BH FE 7B
Compare Register A against 7BH, the byte after the letter z: the NO CARRY FLAG above z.
5573
If the NO CARRY FLAG is set (above z), JUMP to 5578H: the character is kept.
5575
SUB 20H D6 20
SUBtract 20H from Register A: the lower case letter becomes upper case.
5577
LD (HL),A 77
Store Register A (the upper case letter) at Register Pair HL.
5578
INC HL 23
INCrement Register Pair HL to the next character.
5579
LOOP BACK to 5568H for the next character of the text at Register Pair HL.
557B
POP HL E1
Restore Register Pair HL (the start of the text) from the stack.
557C
POP AF F1
Restore Register Pair AF from the stack, as it was on entry.
557D
RET C9
RETURN to the caller with Register Pair AF and Register Pair HL as they were.
557EH - A Line Number as Text
The ROM's LINPRT (0FAFH) without its display: Register Pair HL goes to the ROM's number buffer as text (at 4130H, a space for the sign first, ended by 00H). Returns Register Pair DE at the first digit (4131H); Register Pair HL is kept.
557E
PUSH HL E5
Save Register Pair HL (the number) to the stack.
557F
GOSUB to 0A9AH, the ROM: Register Pair HL to 4121H-4122H as an integer, the type at 40AFH = 2.
5582
XOR A AF
Load Register A with 00H (XOR A): no format for the number.
5583
GOSUB to 1034H, the ROM: 40D8H = Register A (00H) and a space at 4130H, the sign of the number in the buffer; Register Pair HL returns 4130H.
5586
OR (HL) B6
OR Register A with the byte at Register Pair HL (the space at 4130H), as the ROM does at 0FB6H before 0FD9H.
5587
GOSUB to 0FD9H, the ROM's turning of the number into text from 4131H, ended by 00H; Register Pair HL returns 4130H.
558A
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair DE = 4130H, the sign of the text.
558B
INC DE 13
INCrement Register Pair DE to 4131H, the first digit.
558C
POP HL E1
Restore Register Pair HL (the number) from the stack.
558D
RET C9
RETURN to the caller with Register Pair DE at the digits.
558EH - The Next Line by Its Text
Moves Index Register IX past the link and the number (4 bytes) and past the text to the 00H after it: Index Register IX = the next line. The links cannot be followed, since the passes put the new numbers in them. Then 559EH: the Z FLAG when the link of the line at Index Register IX is 0000H, the end mark of the program.
558E
INC IX DD 23
INCrement Index Register IX past the low byte of the link.
5590
INC IX DD 23
INCrement Index Register IX past the high byte of the link.
5592
INC IX DD 23
INCrement Index Register IX past the low byte of the line's number.
5594
INC IX DD 23
INCrement Index Register IX past the high byte of the line's number, to the text.
5596
LD A,(IX+00H) DD 7E 00
Load Register A with the byte of the text at Index Register IX +00H.
5599
INC IX DD 23
INCrement Index Register IX to the next byte; the OR below tests the byte loaded into Register A.
559B
OR A B7
OR Register A with itself: the Z FLAG for the 00H ending the line.
559C
If the NZ FLAG is set (not the end), LOOP BACK to 5596H: Index Register IX ends at the next line.
559E
LD A,(IX+00H) DD 7E 00
Load Register A with the low byte of the link at Index Register IX +00H.
55A1
OR A B7
OR Register A with itself: the NZ FLAG when the low byte is not 00H.
55A2
RET NZ C0
If the NZ FLAG is set (a line), RETURN with the NZ FLAG.
55A3
LD A,(IX+01H) DD 7E 01
Load Register A with the high byte of the link at Index Register IX +01H.
55A6
OR A B7
OR Register A with itself: the Z FLAG when the link is 0000H; the CARRY FLAG is cleared.
55A7
RET C9
RETURN to the caller with the Z FLAG at the end of the program.
55A8H - Tokens Followed by Line Numbers
Returns the Z FLAG when Register A holds the token of THEN (CAH), ELSE (95H), RESUME (9FH), GOTO (8DH), GOSUB (91H), RUN (8EH) or ERL (C2H). Other line numbers, such as those of RESTORE, LIST, EDIT and DELETE, are not looked for.
55A8
CP CAH FE CA
Compare Register A against CAH, the token of THEN.
55AA
RET Z C8
If the Z FLAG is set (THEN), RETURN with the Z FLAG.
55AB
CP 95H FE 95
Compare Register A against 95H, the token of ELSE.
55AD
RET Z C8
If the Z FLAG is set (ELSE), RETURN with the Z FLAG.
55AE
CP 9FH FE 9F
Compare Register A against 9FH, the token of RESUME.
55B0
RET Z C8
If the Z FLAG is set (RESUME), RETURN with the Z FLAG.
55B1
CP 8DH FE 8D
Compare Register A against 8DH, the token of GOTO.
55B3
RET Z C8
If the Z FLAG is set (GOTO), RETURN with the Z FLAG.
55B4
CP 91H FE 91
Compare Register A against 91H, the token of GOSUB.
55B6
RET Z C8
If the Z FLAG is set (GOSUB), RETURN with the Z FLAG.
55B7
CP 8EH FE 8E
Compare Register A against 8EH, the token of RUN.
55B9
RET Z C8
If the Z FLAG is set (RUN), RETURN with the Z FLAG.
55BA
CP C2H FE C2
Compare Register A against C2H, the token of ERL.
55BC
RET Z C8
If the Z FLAG is set (ERL), RETURN with the Z FLAG.
55BD
RET C9
RETURN to the caller with the NZ FLAG: Register A is none of the seven tokens.
55BEH - Past a Character and the Spaces
Steps Register Pair HL past the character at it and the spaces after it; Register Pair AF is kept.
55BE
PUSH AF F5
Save Register Pair AF to the stack, to be kept.
55BF
INC HL 23
INCrement Register Pair HL to the next character.
55C0
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
55C1
CP 20H FE 20
Compare Register A against 20H, a space: the Z FLAG for another space.
55C3
If the Z FLAG is set (a space), LOOP BACK to 55BFH.
55C5
POP AF F1
Restore Register Pair AF from the stack, as it was on entry.
55C6
RET C9
RETURN to the caller with Register Pair HL at the first character after the spaces.
55C7H - The Texts and the Parameters
The name BASIC/CMD for 5551H, the banner and the messages (each ended by 0DH, shown, or 03H, not shown), the four parameters and the address of the line buffer. The cells 56A5H-56A9H and the buffer 5700H-57FEH are not in the file.
55C7
DEFM "L" 4C
55C7H: 4CH, the letter L before the name; 5551H copies from 55C8H, so no code reads it.
55C8-55D0
DEFM "BASIC/CMD" 42 41 53 49 43 2F 43 4D 44
55C8H-55D0H: the name of the file 5551H runs, copied to CFCB$ (4485H).
55D1
DEFB 03H 03
55D1H: 03H, the end of the name in the control block.
55D2-55D3
DEFB 1CH,1FH 1C 1F
55D2H-55D3H: the start of the banner (5209H): 1CH puts the cursor home, 1FH clears the screen from there; 55D2H is also the eleventh byte 5551H copies to 448FH.
55D4-5603
DEFM "BASIC Line Renumbering Utility - Version 2.21" / DEFB 0AH 42 41 53 49 43 20 4C 69 6E 65 20 52 65 6E 75 6D 62 65 72 69 6E 67 20 55 74 69 6C 69 74 79 20 20 2D 20 20 56 65 72 73 69 6F 6E 20 32 2E 32 31 0A
55D4H-5603H: the first line of the banner and 0AH, a line feed.
5604-5636
DEFM "Copyright 1987 MISOSYS, Inc., All rights reserved" / DEFB 0AH,0DH 43 6F 70 79 72 69 67 68 74 20 31 39 38 37 20 4D 49 53 4F 53 59 53 2C 20 49 6E 63 2E 2C 20 41 6C 6C 20 72 69 67 68 74 73 20 72 65 73 65 72 76 65 64 0A 0D
5604H-5636H: the second line of the banner, 0AH and 0DH, the end of the banner.
5637-564A
DEFM "Checking for errors" / DEFB 0DH 43 68 65 63 6B 69 6E 67 20 66 6F 72 20 65 72 72 6F 72 73 0D
5637H-564AH: shown at 520FH before the parameters are read.
564B-5658
DEFM "Bad parameters" 42 61 64 20 70 61 72 61 6D 65 74 65 72 73
564BH-5658H: the text of 54C1H; its 0DH follows at 5659H.
5659
DEFB 0DH 0D
5659H: 0DH, the end of Bad parameters, shown alone by 5538H to end a line.
565A-566A
DEFM "Buffer overflow" / DEFB 0AH,0DH 42 75 66 66 65 72 20 6F 76 65 72 66 6C 6F 77 0A 0D
565AH-566AH: the text of 5496H after Error in line n., with 0AH and 0DH.
566B-567D
DEFM "Can not find line " / DEFB 03H 43 61 6E 20 6E 6F 74 20 66 69 6E 64 20 6C 69 6E 65 20 03
566BH-567DH: the text of 54A4H, the number shown after it by LINPRT.
567E-5687
DEFM "No errors" / DEFB 0DH 4E 6F 20 65 72 72 6F 72 73 0D
567EH-5687H: shown at 532DH before the pass that changes the references.
5688-5695
DEFM "Error in line " 45 72 72 6F 72 20 69 6E 20 6C 69 6E 65 20
5688H-5695H: the text of 5522H and 554BH before the number of the line.
5696
DEFB 03H 03
5696H: 03H, the end of Error in line; 5548H writes 30H here (the digit 0) for Error in line 0.
5697-569A
DEFM ". " / DEFB 03H 2E 20 20 03
5697H-569AH: a period and two spaces after a line number (5533H, 54AEH), ended by 03H; 5548H writes 0DH at 5697H.
569B-569C
DEFW 0001H 01 00
569BH-569CH: the first line to renumber, 1 unless given (5239H); read at 52B2H.
569D-569E
DEFW 0014H 14 00
569DH-569EH: the new number of the first line, 20 unless given; then the number for the next line in the first pass (52EBH); put back at 5316H.
569F-56A0
DEFW 0014H 14 00
569FH-56A0H: the increment, 20 unless given; read at 52DDH.
56A1-56A2
DEFW FFF9H F9 FF
56A1H-56A2H: the last line to renumber, 65529 unless given; then the bound of the new numbers (5291H), read at 52D0H and 52F9H.
56A3-56A4
DEFW 5700H 00 57
56A3H-56A4H: the address of the line buffer, 5700H, read at 5344H, 53AAH and 53E8H.
56A5-56A6
DEFS 2
56A5H-56A6H: not in the file. The new number of the first line kept by 529FH for 5313H; then 56A5H is the changed flag of a line (534BH, 5466H, read at 5379H).
56A7
DEFS 1
56A7H: not in the file. The pass flag: 00H for the pass that only checks the references, 01H for the pass that changes them (5227H, 5231H, 532AH; read at 5319H, 5321H and 5384H).
56A9
DEFS 1
56A9H: not in the file. The quote flag: 01H inside quotes, where no token is looked for (5338H, 5367H).
5700-57FE
DEFS 255
5700H-57FEH: not in the file. The line buffer: the text of a line with its new numbers, ended by 00H; the 255th byte stored gives Buffer overflow.