TRS-80 DOS - NEWDOS/80 v2.0 for the Model III - SYS18/SYS Disassembled

Page Customization

Introduction/Summary

NEWDOS/80 v2.0 SYS18/SYS Disassembly - The BASIC Command Line (Model III)

SYS18/SYS handles the Disk BASIC command line. It loads 5200H-56E7H in five load records (transfer address 5200H); the code and data end at 5535H and 5536H-56E7H are 434 bytes of 00H. It is one of the BASIC overlays that BASIC/CMD loads at 5200H through its loader at 576CH (RST 28H code 34H); BASIC/CMD loads it first, from its entry code at 66C1H. 5200H itself only returns with the Z FLAG set. There are two entries:

  • 5202H, the command line input. The ROM's line input INLIN (0361H) calls the Disk BASIC link 41AFH at 0368H; when it was called from the command loop (return 1A7EH), BASIC/CMD 575DH-5767H drops INLIN's return 036BH and runs 5202H. SYS18/SYS reads the first key itself (one-key listings, below), then the rest of the line through the ROM's line input at 05E3H, checks it at 53C5H and hands it back to INLIN at 0375H.
  • 54FAH, after tokenizing. The command loop calls the link 41B2H at 1AA1H after a typed line has been tokenized; BASIC/CMD 5756H runs 54FAH. A line that 53C5H marked (RENEW, RENUM, REF) is carried out; anything else goes back to the ROM.

The page shows every byte of the file once, in address order.

Keys and Commands

First key or commandWhat it does
@Clears the screen and lists from the current line (40ECH) as many lines as fit in 15 rows (at most 64).
colonClears the screen and lists the lines before the current line, up to it, as many as fit in 15 rows (13 lines back at most); a colon after a colon or after @ goes back from the first line listed.
down arrow, up arrowLists the line after or before the current one.
period, commaLists the current line, or edits it (ROM EDIT at 2E65H).
slash, shift-down arrowLists the last line.
semicolon, shift-up arrowLists the first line.
A, D, E, L followed by a number or a periodWritten out as AUTO, DELETE, EDIT, LIST (unless the line holds an =, an assignment).
DI n,m and DU n,mMove (DI) or copy (DU) line n (or the current line, a period) to the new number m, through the ROM's line store at 1AA7H.
RENEWBrings back a program after NEW by giving the first line a non-zero link and rebuilding the links.
RENUM, REFRun SYS13/SYS (code 4FH) and SYS12/SYS (code 2EH) with RST 28H, returning through BASIC/CMD 641EH to READY.

A line number typed alone (ENTER right after it) gives SYNTAX ERROR here. With option AB (RUN-ONLY), or when 63FAH is not 00H, no command line may be typed (ILLEGAL DIRECT). While a chain file supplies the keys, the line is read with the ROM's line input at 05D9H and the one-key listings are not used.

The listings write over the READY line when it is the row above the cursor (53A6H) and go through the ROM's LIST4 (2B33H) to READY; the colon and @ listings clear the screen first and count the rows of each expanded line (ROM 2B7EH).

Variables

ROM Addresses

Address
Size
Contents
3C00H-3FFFH
1024 bytes
Video Memory
The row above the cursor is compared with READY at 53A6H.
4020H-4021H
2 bytes
Cursor Address
Read at 5394H.
40A4H-40A5H
2 bytes
TXTTAB
The first program line (5246H, 5280H, 52E1H, 5526H).
40A7H-40A8H
2 bytes
Input Buffer
The line buffer (520FH, 5267H, 5322H, 5486H).
40ECH-40EDH
2 bytes
DOT
The current line for LIST and EDIT (527CH, 545DH).

DOS Addresses

Address
Size
Contents
4289H
1 byte
System Flags
Bit 5: a chain file supplies the keys (5207H).

BASIC/CMD Addresses

Address
Size
Contents
57B6H-57B7H
2 bytes
Work Bytes
The code of a marked command and the mark 01H (5404H, 54FBH, 5500H).
63FAH
1 byte
Run-Only Byte
The operand of BASIC/CMD's 63F9H: not 00H stops the command line (521EH).

Operands Changed at Run Time

Address
Size
Contents
5205H-5206H
2 bytes
Display Routine
Operand of 5204H: 0033H, or 6562H for BASIC/CMD's startup command.
5227H
1 byte
Previous First Key
Operand of 5226H (522FH).
5272H-5273H
2 bytes
Colon Start
Operand of 5271H: the first line of the last listing (536EH).
5373H-5374H
2 bytes
Last Line
Operand of 5372H: the last line that fits (5354H).
54A1H
1 byte
DI or DU
Operand of 54A0H: A1H DI, A0H DU (5453H).

Outside Routines

WhereAddresses
ROM0033H, 0049H, 05D9H and 05E3H (line input), 0375H (INLIN), 1997H, 1A25H, 1AA7H, 1AF8H, 1B2CH, 1B59H, 1E5AH, 1ED9H, 2831H, 2B33H, 2B7EH, 2BE4H, 2E65H; RST 10H, RST 18H, RST 28H.
BASIC/CMD57BAH (upper case), 5D0BH (digits), 5D3FH (display), 5DB8H (error 84H), 6382H (file statement flag), 641EH (end of the statement).
OverlaysSYS12/SYS (REF, code 2EH) and SYS13/SYS (RENUM, code 4FH) through RST 28H.

Disassembly

5200H - Load Entry

BASIC/CMD loads SYS18/SYS through its overlay loader at 576CH with RST 28H code 34H (function 1 of directory slot 14H) into 5200H-56E7H. The SYS0/SYS dispatcher calls the transfer address 5200H after the load, which returns at once with the Z FLAG set; BASIC/CMD's loader then RETurns into the entry it pushed from Register Pair BC: 5202H (the command line input, from 5767H) or 54FAH (a tokenized line, from 5758H).

5200
CP A BF
Compare Register A with itself: the Z FLAG is always set, which the dispatcher passes back to BASIC/CMD's loader (5779H) as a load without error.
5201
RET C9
RETURN to the SYS0/SYS dispatcher with the Z FLAG set; BASIC/CMD's loader then runs the entry in Register Pair BC.

5202H - Command Line Input

Entered from BASIC/CMD 5767H when the ROM's line input INLIN (0361H) calls the link 41AFH at 0368H for the command loop (INLIN called from 1A7BH): BASIC/CMD has dropped the return 036BH, so the stack holds only 1A7EH, INLIN's return into the command loop, and Register Pair BC = 5202H. SYS18/SYS reads the line itself. As the first key of a line, some keys list or edit at once: @ lists from the current line (40ECH) as many lines as fit in 15 screen rows; a colon lists the lines before the current one that fit (a second colon goes back further); the down and up arrows list the line after or before the current one; a period lists the current line, a comma edits it; a slash and shift-down arrow list the last line, a semicolon and shift-up arrow the first. Any other key starts an ordinary line, which is checked for SYS18/SYS's own commands at 53C5H.

5202
LD A,0EH 3E 0E
Load Register A with 0EH, the display code that turns the cursor on.
5204
Self-Modifying Code
GOSUB to the routine whose address is the operand 5205H: ROM 0033H, which displays the character in Register A, in the file. BASIC/CMD stores 6562H there at its 655CH for the first command line after a start with a command (its startup hook takes the line from there and puts 0033H back).
5207
LD A,(4289H) 3A 89 42
Load Register A with the byte at 4289H, SYS0/SYS's system flags.
520A
BIT 5,A CB 6F
Test bit 5 of Register A (4289H): set while a chain file supplies the keys.
520C
If the Z FLAG is set (no chain file), JUMP to 521AH to wait for the first key.
520E
PUSH BC C5
Chain file: save Register Pair BC (5202H) on the stack, where the ROM's INLIN keeps its caller's Register Pair BC (as its 036BH does).
520F
LD HL,(40A7H) 2A A7 40
Load Register Pair HL with the 16-bit value at 40A7H, the ROM's pointer to the input buffer.
5212
LD B,F0H 06 F0
Load Register B with F0H (240), the most characters in a line.
5214
GOSUB to ROM 05D9H, the line input, which reads up to Register B characters into the buffer at Register Pair HL (here from the chain file, through the keyboard driver) and returns the CARRY FLAG for BREAK and Register B = the characters typed.
5217
JUMP to 53C5H to check the line for SYS18/SYS's commands.
521A
GOSUB to ROM 0049H, which waits for a key and returns it in Register A.
521D
PUSH AF F5
Save Register Pair AF (Register A = the first key) on the stack.
521E
LD A,(63FAH) 3A FA 63
Load Register A with the byte at 63FAH, the operand of BASIC/CMD's OR nn at 63F9H: 00H normally, not 00H with option AB (RUN-ONLY) or as SYS19/SYS stores it at its 524EH.
5221
OR A B7
OR Register A (the byte from 63FAH) with itself to set the flags: the Z FLAG is set if it is 00H.
5222
If the NZ FLAG is set (no direct command may be typed), JUMP to ROM 2831H for ILLEGAL DIRECT.
5225
POP AF F1
Restore Register Pair AF from the stack: Register A = the first key.
5226
LD L,00H 2E 00
Self-Modifying Code
Load Register L with the first key of the line before, the operand 5227H (00H in the file; stored at 522FH).
5228
CP 60H FE 60
Compare Register A (the first key) against 60H, the code of the shifted @ key.
522A
If the NZ FLAG is set (Register A is not 60H), JUMP to 522EH.
522C
LD A,40H 3E 40
Load Register A with 40H: the shifted @ counts as @.
522E
PUSH AF F5
Save Register Pair AF (Register A = the first key) on the stack, above 1A7EH.
522F
LD (5227H),A 32 27 52
Self-Modifying Code
Store Register A (the first key) at 5227H, the operand of LD L,nn at 5226H: the key of the line before, for the next line.
5232
CP 3AH FE 3A
Compare Register A (the first key) against 3AH, a colon.
5234
If the Z FLAG is set (a colon), JUMP to 5271H.
5236
CP 0AH FE 0A
Compare Register A (the first key) against 0AH, the code of the down arrow.
5238
If the Z FLAG is set (the down arrow), JUMP to 527CH to start from the current line.
523A
CP 5BH FE 5B
Compare Register A (the first key) against 5BH, the code of the up arrow.
523C
If the Z FLAG is set (the up arrow), JUMP to 527CH to start from the current line.
523E
CP 2EH FE 2E
Compare Register A (the first key) against 2EH, a period.
5240
If the Z FLAG is set (a period), JUMP to 527CH to start from the current line.
5242
CP 2CH FE 2C
Compare Register A (the first key) against 2CH, a comma.
5244
If the Z FLAG is set (a comma), JUMP to 527CH to start from the current line.
5246
LD HL,(40A4H) 2A A4 40
Load Register Pair HL with the 16-bit value at 40A4H, the ROM's pointer to the first program line.
5249
CP 3BH FE 3B
Compare Register A (the first key) against 3BH, a semicolon.
524B
If the Z FLAG is set (a semicolon), JUMP to 524FH with the Z FLAG still set.
524D
CP 1BH FE 1B
Compare Register A (the first key) against 1BH, the code of shift-up arrow.
524F
If the Z FLAG is set (a semicolon or shift-up arrow), JUMP to 537AH to list the first line, at Register Pair HL.
5252
LD DE,FFFFH 11 FF FF
Load Register Pair DE with FFFFH (65535), a number above every line: the search stops at the last line.
5255
CP 1AH FE 1A
Compare Register A (the first key) against 1AH, the code of shift-down arrow.
5257
If the Z FLAG is set (shift-down arrow), JUMP to 5280H to find the last line.
5259
CP 2FH FE 2F
Compare Register A (the first key) against 2FH, a slash.
525B
If the Z FLAG is set (a slash), JUMP to 5280H to find the last line.
525D
CP 40H FE 40
Compare Register A (the first key) against 40H, the character @.
525F
If the Z FLAG is set (@), JUMP to 527CH to start from the current line.
5261
POP AF F1
Any other key: restore Register Pair AF from the stack, Register A = the key (the stack holds 1A7EH again).
5262
PUSH BC C5
Save Register Pair BC (5202H) on the stack, as the ROM's INLIN does with its caller's Register Pair BC at 036BH.
5263
LD HL,53C5H 21 C5 53
Load Register Pair HL with 53C5H, SYS18/SYS's check of the typed line.
5266
PUSH HL E5
Push Register Pair HL (53C5H) on the stack: the line input returns there, in place of INLIN's 0374H.
5267
LD HL,(40A7H) 2A A7 40
Load Register Pair HL with the 16-bit value at 40A7H, the ROM's pointer to the input buffer.
526A
LD B,F0H 06 F0
Load Register B with F0H (240), the most characters in a line.
526C
LD C,B 48
Load Register C with Register B (240), as the line input does at 05DFH: the buffer size.
526D
PUSH HL E5
Push Register Pair HL (the input buffer) on the stack, as the line input does at 05D9H.
526E
JUMP into ROM 05E3H, the line input just after its CALL 0049H at 05E0H, so that the key in Register A becomes the line's first character and the rest of the line is read.
5271
LD DE,0000H 11 00 00
Self-Modifying Code
A colon: load Register Pair DE with the number of the first line of the last colon or @ listing, the operand 5272H (0000H in the file; stored at 536EH).
5274
CP L BD
Compare Register A (the colon) with Register L, the first key of the line before.
5275
If the Z FLAG is set (a colon again), JUMP to 5280H to go back from that line.
5277
LD A,L 7D
Load Register A with Register L, the first key of the line before.
5278
CP 40H FE 40
Compare Register A (that key) against 40H, the character @.
527A
If the Z FLAG is set (after an @ listing), JUMP to 5280H to go back from its first line.
527C
LD DE,(40ECH) ED 5B EC 40
Load Register Pair DE with the 16-bit value at 40ECH, the ROM's current line for LIST and EDIT (its DOT).
5280
LD HL,(40A4H) 2A A4 40
Load Register Pair HL with the 16-bit value at 40A4H, the ROM's pointer to the first program line.
5283
LD BC,0000H 01 00 00
Load Register Pair BC with 0000H, the count of lines passed.
5286
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of the first line's link field.
5287
INC HL 23
Increment Register Pair HL to the high byte of the first line's link field.
5288
OR (HL) B6
OR Register A (the link's low byte) with the byte at Register Pair HL: the Z FLAG is set for 0000H, no program.
5289
DEC HL 2B
Decrement Register Pair HL back to the first line's start.
528A
If the Z FLAG is set (no program), JUMP to 537AH, which lists nothing from the end marker at Register Pair HL.

FIND THE LINE LOOP
Register Pair HL = the line being tested, Register Pair DE = the line number wanted, Register Pair BC = the lines passed.

528D
INC HL 23
Increment Register Pair HL, 1 of 3, from the line's start towards its number.
528E
INC HL 23
Increment Register Pair HL, 2 of 3, to the low byte of the line's number (52A7H loops back here with Register Pair HL one byte into the line).
528F
INC HL 23
Increment Register Pair HL, 3 of 3, to the high byte of the line's number.
5290
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the high byte of this line's number.
5291
CP D BA
Compare Register A (the high byte) with Register D, the high byte of the number wanted: the CARRY FLAG is set if this line's number is lower.
5292
DEC HL 2B
Decrement Register Pair HL to the low byte of the line's number (DEC HL does not change the flags).
5293
If the NZ FLAG is set (the high bytes differ), JUMP to 5297H with the flags of that compare.
5295
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of this line's number.
5296
CP E BB
Compare Register A (the low byte) with Register E, the low byte of the number wanted: the Z FLAG is set on an exact match, the CARRY FLAG if this line's number is lower.
5297
DEC HL 2B
Decrement Register Pair HL, 1 of 2, back towards the line's start.
5298
DEC HL 2B
Decrement Register Pair HL, 2 of 2: Register Pair HL = the line's start, its link field.
5299
If the NO CARRY FLAG is set (this line's number is not below the one wanted), JUMP to 52ADH: found.
529B
PUSH HL E5
Save Register Pair HL (this line's address) on the stack.
529C
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of this line's link.
529D
INC HL 23
Increment Register Pair HL to the high byte of this line's link.
529E
LD H,(HL) 66
Load Register H with the byte at Register Pair HL, the high byte of the link.
529F
LD L,A 6F
Load Register L with Register A, the low byte. Register Pair HL = the next line.
52A0
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of the next line's link field.
52A1
INC HL 23
Increment Register Pair HL to the high byte of the next line's link field.
52A2
OR (HL) B6
OR Register A (the low byte) with the byte at Register Pair HL: the Z FLAG is set if the next line is the end marker.
52A3
If the Z FLAG is set (this was the last line), JUMP to 52A9H.
52A5
INC BC 03
Increment Register Pair BC, the count of lines passed.
52A6
POP AF F1
Restore Register Pair AF from the stack, discarding the address saved at 529BH.
52A7
LOOP back to 528EH with Register Pair HL one byte into the next line.
52A9
POP HL E1
The last line: restore Register Pair HL from the stack, the last line's address saved at 529BH.
52AA
POP AF F1
Restore Register Pair AF from the stack: Register A = the first key, pushed at 522EH (the stack holds 1A7EH again).
52AB
JUMP to 52BFH with Register A = the key and Register Pair HL = the last line.
52AD
POP DE D1
Found: restore Register Pair DE from the stack: Register D = the first key, pushed with its flags at 522EH (the stack holds 1A7EH again). POP does not change the flags.
52AE
LD A,D 7A
Load Register A with Register D, the first key. LD does not change the flags (the Z FLAG is set if the line found has the number wanted).
52AF
If the NZ FLAG is set (the line found has a higher number: the current line does not exist), JUMP to 52B8H.
52B1
LD DE,0001H 11 01 00
Load Register Pair DE with 0001H: one line on.
52B4
CP 0AH FE 0A
Compare Register A (the first key) against 0AH, the down arrow.
52B6
If the Z FLAG is set (the down arrow), JUMP to 52CEH with Register Pair DE = +1.
52B8
LD DE,FFFFH 11 FF FF
Load Register Pair DE with FFFFH: one line back (minus 1).
52BB
CP 5BH FE 5B
Compare Register A (the first key) against 5BH, the up arrow.
52BD
If the Z FLAG is set (the up arrow), JUMP to 52CEH with Register Pair DE = minus 1.
52BF
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H: no step, the listing starts at the line found.
52C2
CP 40H FE 40
Compare Register A (the first key) against 40H, the character @.
52C4
If the Z FLAG is set (@), JUMP to 52CEH with Register Pair DE = 0.
52C6
LD DE,FFF3H 11 F3 FF
Load Register Pair DE with FFF3H: 13 lines back (minus 13).
52C9
CP 3AH FE 3A
Compare Register A (the first key) against 3AH, a colon.
52CB
If the NZ FLAG is set (a period, a comma, a slash, shift-down arrow, or the down arrow at a line that does not exist), JUMP to 5379H to list or edit the line at Register Pair HL.
52CE
PUSH AF F5
Save Register Pair AF (Register A = the first key) on the stack.
52CF
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the step (+1, minus 1, 0 or minus 13), Register Pair DE = the line found.
52D0
ADD HL,BC 09
Add Register Pair BC (the number of lines before the line found) to Register Pair HL: Register Pair HL = the index of the target line from the first line.
52D1
LD A,H 7C
Load Register A with Register H, the high byte of the target index.
52D2
CP FFH FE FF
Compare Register A (the high byte) against FFH: the Z FLAG is set if the index is below 0 (before the first line).
52D4
If the NZ FLAG is set (the index is 0 or more), JUMP to 52D9H.
52D6
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H: start at the first line instead.
52D9
PUSH BC C5
Save Register Pair BC (the index of the line found) on the stack.
52DA
LD B,H 44
Load Register B with Register H, the high byte of the target index.
52DB
LD C,L 4D
Load Register C with Register L, the low byte. Register Pair BC = the target index.
52DC
POP HL E1
Restore Register Pair HL from the stack: the index of the line found.
52DD
OR A B7
OR Register A with itself to clear the CARRY FLAG for the SBC HL,BC at 52DEH.
52DE
SBC HL,BC ED 42
Subtract Register Pair BC (the target index) from Register Pair HL (the index of the line found): the number of lines from the target to the line found.
52E0
PUSH HL E5
Save Register Pair HL (that number of lines) on the stack.
52E1
LD HL,(40A4H) 2A A4 40
Load Register Pair HL with the 16-bit value at 40A4H, the first program line.

STEP TO THE TARGET LINE
Register Pair BC counts down the lines to pass; Register Pair HL = the current line, Register Pair DE = the next.

52E4
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of this line's link field.
52E5
INC HL 23
Increment Register Pair HL to the high byte of this line's link field.
52E6
LD D,(HL) 56
Load Register D with the byte at Register Pair HL, the high byte. Register Pair DE = the next line.
52E7
DEC HL 2B
Decrement Register Pair HL back to this line's start.
52E8
LD A,B 78
Load Register A with Register B, the high byte of the lines left to pass.
52E9
OR C B1
OR Register A with Register C, the low byte: the Z FLAG is set when none are left.
52EA
DEC BC 0B
Decrement Register Pair BC, the lines left to pass (DEC BC does not change the flags).
52EB
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the next line, Register Pair DE = this line.
52EC
If the NZ FLAG is set (lines were left), LOOP back to 52E4H.
52EE
POP BC C1
Restore Register Pair BC from the stack: the number of lines from the target to the line found.
52EF
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the target line.
52F0
INC BC 03
Increment Register Pair BC: the number of lines to list, up to and including the line found.
52F1
POP AF F1
Restore Register Pair AF from the stack: Register A = the first key (the stack holds 1A7EH again).
52F2
CP 3AH FE 3A
Compare Register A (the first key) against 3AH, a colon.
52F4
LD B,A 47
Load Register B with Register A, the first key. LD does not change the flags.
52F5
If the Z FLAG is set (a colon; Register C = the lines to list), JUMP to 52FCH.
52F7
CP 40H FE 40
Compare Register A (the first key) against 40H, the character @.
52F9
If the NZ FLAG is set (an arrow), JUMP to 5379H to list the target line at Register Pair HL.
52FB
LD C,A 4F
Load Register C with Register A (40H): @ lists up to 64 lines, as many as fit.
52FC
POP AF F1
Restore Register Pair AF from the stack, discarding 1A7EH, the return into the ROM's command loop: the listing ends through LIST4 at READY.
52FD
LD A,1CH 3E 1C
Load Register A with 1CH, the display code that moves the cursor to the top left of the screen.
52FF
GOSUB to BASIC 5D3FH, which displays the character in Register A (1CH).
5302
LD A,1FH 3E 1F
Load Register A with 1FH, the display code that erases from the cursor to the end of the screen.
5304
GOSUB to BASIC 5D3FH to display it: the screen is cleared.

COUNT THE ROWS
Each line is expanded (ROM 2B7EH) and its screen rows counted; lines are added while the total stays below 15 rows. Register D = the rows so far, Register E = the lines counted, Register C = the most lines wanted, Register B = the first key.

5307
PUSH HL E5
Save Register Pair HL (the first line to list) on the stack (5352H loops back here with a later first line).
5308
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H: Register D = the screen rows used, Register E = the lines counted.
530B
PUSH HL E5
Save Register Pair HL (the line being counted) on the stack.
530C
PUSH DE D5
Save Register Pair DE (the rows and lines counted) on the stack.
530D
PUSH BC C5
Save Register Pair BC (Register B = the first key, Register C = the line limit) on the stack.
530E
INC HL 23
Increment Register Pair HL, 1 of 2, towards the line's number.
530F
INC HL 23
Increment Register Pair HL, 2 of 2, to the low byte of the line's number.
5310
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of the line's number.
5311
INC HL 23
Increment Register Pair HL to the high byte of the line's number.
5312
LD D,(HL) 56
Load Register D with the byte at Register Pair HL, the high byte. Register Pair DE = the line's number.
5313
PUSH DE D5
Save Register Pair DE (the line's number) on the stack.
5314
INC HL 23
Increment Register Pair HL to the line's text.
5315
GOSUB to ROM 2B7EH (BUFLIN), which expands the tokenized text at Register Pair HL into readable text in the input buffer (40A7H) through Register Pair BC, returned after the last character.
5318
POP DE D1
Restore Register Pair DE from the stack: the line's number.
5319
PUSH DE D5
Save Register Pair DE (the line's number) on the stack again, for 533DH.
531A
GOSUB to BASIC 5D0BH, which converts Register Pair DE to five digits at 5D2AH and returns Register E = the number of digits without leading zeros.
531D
XOR A AF
Load Register A with 00H (XOR A with itself).
531E
LD D,01H 16 01
Load Register D with 01H: the line takes at least one row.
5320
INC E 1C
Increment Register E, the number of digits: the column after the number and the space LIST puts after it.
5321
LD (BC),A 02
Store Register A (00H) at Register Pair BC, ending the expanded text in the input buffer.
5322
LD HL,(40A7H) 2A A7 40
Load Register Pair HL with the 16-bit value at 40A7H, the input buffer holding the expanded text.
5325
JUMP to 5337H to start counting at the first character at Register Pair HL.
5327
CP 0DH FE 0D
Compare Register A (the character) against 0DH, a carriage return.
5329
If the Z FLAG is set (a carriage return: a new row), JUMP to 5334H.
532B
CP 0AH FE 0A
Compare Register A (the character) against 0AH, a line feed.
532D
If the Z FLAG is set (a line feed: a new row), JUMP to 5334H.
532F
INC E 1C
Increment Register E, the column in the current screen row.
5330
BIT 6,E CB 73
Test bit 6 of Register E: set when the column reaches 64, the end of a row.
5332
If the Z FLAG is set (still inside the row), JUMP to 5337H.
5334
INC D 14
Increment Register D, the rows this line takes.
5335
LD E,00H 1E 00
Load Register E with 00H, column 0 of the new row.
5337
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, a character of the expanded text.
5338
OR A B7
OR Register A (the character) with itself to set the flags: the Z FLAG is set at the 00H end.
5339
INC HL 23
Increment Register Pair HL to the next character (INC HL does not change the flags).
533A
If the NZ FLAG is set (not the end), LOOP back to 5327H.
533C
LD A,D 7A
Load Register A with Register D, the rows this line takes.
533D
POP HL E1
Restore Register Pair HL from the stack: this line's number.
533E
POP BC C1
Restore Register Pair BC from the stack: Register B = the first key, Register C = the line limit.
533F
POP DE D1
Restore Register Pair DE from the stack: Register D = the rows so far, Register E = the lines counted.
5340
ADD A,D 82
Add Register D (the rows so far) to Register A (this line's rows).
5341
LD D,A 57
Load Register D with Register A, the rows including this line.
5342
CP 0FH FE 0F
Compare Register A (the rows) against 0FH (15): the CARRY FLAG is set if fewer than 15 rows are used.
5344
If the CARRY FLAG is set (the line fits), JUMP to 5354H.
5346
POP HL E1
Too many rows: restore Register Pair HL from the stack, discarding the line pushed at 530BH.
5347
LD A,B 78
Load Register A with Register B, the first key (a colon or @).
5348
CP 40H FE 40
Compare Register A (the first key) against 40H, the character @.
534A
If the Z FLAG is set (@), JUMP to 5367H to list the lines that fit.
534C
POP HL E1
A colon: restore Register Pair HL from the stack, the first line of the listing.
534D
DEC C 0D
Decrement Register C, the lines to list: the listing starts one line later and ends at the same line.
534E
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of the first line's link field.
534F
INC HL 23
Increment Register Pair HL to the high byte of the first line's link field.
5350
LD H,(HL) 66
Load Register H with the byte at Register Pair HL, the high byte of the link.
5351
LD L,A 6F
Load Register L with Register A, the low byte. Register Pair HL = the next line, the new first line.
5352
JUMP to 5307H to count the rows again from there.
5354
LD (5373H),HL 22 73 53
Self-Modifying Code
Store Register Pair HL (this line's number) at 5373H, the operand of LD HL,nnnn at 5372H: the last line to list so far.
5357
POP HL E1
Restore Register Pair HL from the stack: this line's address.
5358
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of this line's link field.
5359
INC HL 23
Increment Register Pair HL to the high byte of this line's link field.
535A
LD H,(HL) 66
Load Register H with the byte at Register Pair HL, the high byte of the link.
535B
LD L,A 6F
Load Register L with Register A, the low byte. Register Pair HL = the next line.
535C
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of the next line's link field.
535D
INC HL 23
Increment Register Pair HL to the high byte of the next line's link field.
535E
OR (HL) B6
OR Register A (the low byte) with the byte at Register Pair HL: the Z FLAG is set at the end marker.
535F
DEC HL 2B
Decrement Register Pair HL back to the next line's start (DEC HL does not change the flags).
5360
If the Z FLAG is set (no more lines), JUMP to 5367H to list what was counted.
5362
INC E 1C
Increment Register E, the number of lines counted.
5363
LD A,E 7B
Load Register A with Register E, the lines counted.
5364
CP C B9
Compare Register A (the lines counted) with Register C, the most lines wanted: the CARRY FLAG is set if more may follow.
5365
If the CARRY FLAG is set, LOOP back to 530BH for the next line at Register Pair HL.
5367
POP HL E1
Restore Register Pair HL from the stack: the first line of the listing.
5368
PUSH HL E5
Save Register Pair HL (the first line of the listing) on the stack again.
5369
INC HL 23
Increment Register Pair HL, 1 of 2, towards the line's number.
536A
INC HL 23
Increment Register Pair HL, 2 of 2, to the low byte of the first line's number.
536B
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of the first line's number.
536C
INC HL 23
Increment Register Pair HL to the high byte of the first line's number.
536D
LD D,(HL) 56
Load Register D with the byte at Register Pair HL, the high byte. Register Pair DE = the first line's number.
536E
LD (5272H),DE ED 53 72 52
Self-Modifying Code
Store Register Pair DE (the first listed line's number) at 5272H, the operand of LD DE,nnnn at 5271H: a colon typed next goes back from here.
5372
LD HL,0000H 21 00 00
Self-Modifying Code
Load Register Pair HL with the number of the last line to list, the operand 5373H (0000H in the file; stored at 5354H).
5375
EX (SP),HL E3
Exchange Register Pair HL with the word at the top of the stack (at the Stack Pointer SP): the last line's number goes there and Register Pair HL = the first line's address.
5376
PUSH HL E5
Push Register Pair HL (the first line's address) on the stack: LIST4 takes it with POP HL and the last number with POP DE.
5377
JUMP to 53B8H, which jumps to LIST4 with the range on the stack.
5379
PUSH AF F5
One line: save Register Pair AF (Register A = the first key) on the stack.
537A
LD A,1DH 3E 1D
Load Register A with 1DH, the display code that moves the cursor to the start of its row (524FH and 528AH enter here with the key pushed at 522EH on the stack).
537C
GOSUB to ROM 0033H, which displays the character in Register A (1DH).
537F
POP AF F1
Restore Register Pair AF from the stack: Register A = the first key (pushed at 5379H, or at 522EH on the paths from 524FH and 528AH).
5380
POP BC C1
Restore Register Pair BC from the stack, discarding 1A7EH, the return into the ROM's command loop: LIST4 and EDIT end at READY by themselves.
5381
LD B,H 44
Load Register B with Register H, the high byte of the line's address.
5382
LD C,L 4D
Load Register C with Register L, the low byte. Register Pair BC = the line's address.
5383
INC HL 23
Increment Register Pair HL, 1 of 2, towards the line's number.
5384
INC HL 23
Increment Register Pair HL, 2 of 2, to the low byte of the line's number.
5385
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of the line's number.
5386
INC HL 23
Increment Register Pair HL to the high byte of the line's number.
5387
LD D,(HL) 56
Load Register D with the byte at Register Pair HL, the high byte. Register Pair DE = the line's number.
5388
CP 2CH FE 2C
Compare Register A (the first key) against 2CH, a comma.
538A
If the Z FLAG is set (a comma), JUMP to ROM 2E65H inside EDIT, which stores Register Pair DE (the line's number) at 40ECH and edits the line at Register Pair BC.
538D
PUSH DE D5
Push Register Pair DE (the line's number) on the stack: the last line to list.
538E
PUSH BC C5
Push Register Pair BC (the line's address) on the stack: the first line to list.
538F
LD A,0FH 3E 0F
Load Register A with 0FH, the display code that turns the cursor off.
5391
GOSUB to ROM 0033H to display the character in Register A (0FH): the cursor is off while the line is listed.
5394
LD HL,(4020H) 2A 20 40
Load Register Pair HL with the 16-bit value at 4020H, the ROM's cursor address in the video memory.
5397
LD DE,FFC0H 11 C0 FF
Load Register Pair DE with FFC0H, minus 64 (one screen row).
539A
ADD HL,DE 19
Add Register Pair DE (minus 64) to Register Pair HL: Register Pair HL = the same column in the row above.
539B
LD A,H 7C
Load Register A with Register H, the high byte of that address.
539C
CP 3CH FE 3C
Compare Register A (the high byte) against 3CH: the CARRY FLAG is set if the address lies before the video memory (3C00H).
539E
If the CARRY FLAG is set (no row above), JUMP to 53B3H.
53A0
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the address in the row above.
53A1
LD B,0AH 06 0A
Load Register B with 0AH (10), the number of characters to compare.
53A3
LD HL,53BBH 21 BB 53
Load Register Pair HL with 53BBH, the text READY and five spaces as they stand on the screen.

IS THE ROW ABOVE THE READY LINE?
Register Pair DE = the screen, Register Pair HL = the text at 53BBH, Register B = the characters left.

53A6
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, a character on the screen.
53A7
INC DE 13
Increment Register Pair DE to the next screen position.
53A8
CP (HL) BE
Compare Register A (the screen character) with the byte at Register Pair HL, the character expected.
53A9
INC HL 23
Increment Register Pair HL to the next expected character (INC HL does not change the flags).
53AA
If the NZ FLAG is set (they differ), JUMP to 53B3H.
53AC
Decrement Register B, the characters left, and LOOP back to 53A6H until all 10 match.
53AE
LD A,1BH 3E 1B
The row above shows READY: load Register A with 1BH, the display code that moves the cursor up one row.
53B0
GOSUB to ROM 0033H to display it (1BH): the listing is written over the READY line.
53B3
LD A,1EH 3E 1E
Load Register A with 1EH, the display code that erases to the end of the row.
53B5
GOSUB to ROM 0033H to display the character in Register A (1EH): the rest of the row is erased before the listing.
53B8
JUMP to ROM 2B33H (LIST4, inside LIST), which takes the first line's address (POP HL) and the last line's number (POP DE), lists them and goes to READY.

53BBH - The READY Line (Data)

Compared with the row above the cursor at 53A6H-53ACH.

53BB-53C4
DEFM "READY " 52 45 41 44 59 20 20 20 20 20
READY and five spaces, the row the command loop leaves on the screen.

53C5H - Check the Typed Line

The line input returns here (pushed at 5263H, or jumped to from 5217H) with the CARRY FLAG set for BREAK, Register B = the characters typed, Register C = the buffer size and Register Pair HL = the input buffer, which ends with the carriage return 0DH. The stack holds Register Pair BC (pushed at 5262H or 520EH) and 1A7EH, as the ROM's INLIN has them before its 0374H. A line number alone is SYNTAX ERROR. A line whose first word is in the command table (54B2H) is changed: RENEW, RENUM and REF are marked for 54FAH, A, D, E and L followed by a line number or a period are written out as AUTO, DELETE, EDIT and LIST, and DI and DU (move and copy a line) are done at once. The line then goes back to INLIN at 0375H.

53C5
PUSH AF F5
Save Register Pair AF (the CARRY FLAG set for BREAK) on the stack, as the ROM's INLIN does at 0374H; its 037EH takes it back.
53C6
If the CARRY FLAG is set (BREAK was pressed), JUMP to 5450H to hand the line straight back to INLIN.
53C9
PUSH DE D5
Save Register Pair DE (the caller's value) on the stack; 544FH takes it back.
53CA
PUSH BC C5
Save Register Pair BC (Register B = the characters typed, Register C = the buffer size) on the stack.
53CB
PUSH HL E5
Save Register Pair HL (the start of the input buffer) on the stack.
53CC
DEC HL 2B
Decrement Register Pair HL, the buffer pointer, so that the RST 10H that follows reads the first character.
53CD
RST 10H D7
RST 10H: step Register Pair HL to the first character that is not a space and load it into Register A; the CARRY FLAG is set for a digit.
53CE
If the NO CARRY FLAG is set (the line does not start with a digit), JUMP to 53DAH to look for a command.
53D0
GOSUB to ROM 1E5AH (LINGET), which reads the line number at Register Pair HL into Register Pair DE and returns Register A = the character after it.
53D3
CP 0DH FE 0D
Compare Register A (the character after the number) against 0DH, the carriage return that ends the typed line.
53D5
If the NZ FLAG is set (text follows the number), JUMP to 544DH: an ordinary program line.
53D7
JUMP to ROM 1997H (SNERR) for SYNTAX ERROR: a line number alone is refused here, as is a written-out abbreviation that would not fit in the buffer (5433H).
53DA
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the first character of the line.
53DB
LD HL,54B2H 21 B2 54
Load Register Pair HL with 54B2H, the first entry of SYS18/SYS's command table.

TABLE SEARCH LOOP
Register Pair HL = the table entry, Register Pair DE = the typed text; the start of the typed word is kept on the stack.

53DE
PUSH DE D5
Save Register Pair DE (the start of the typed word) on the stack.
53DF
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, a character of the typed word.
53E0
INC DE 13
Increment Register Pair DE to the next typed character.
53E1
GOSUB to BASIC 57BAH, which changes a lower case letter in Register A to upper case.
53E4
CP (HL) BE
Compare Register A (the typed character) with the byte at Register Pair HL, the entry's character.
53E5
If the Z FLAG is set (they match), JUMP to 53F5H.
53E7
BIT 7,(HL) CB 7E
Test bit 7 of the byte at Register Pair HL: set for the attribute byte that ends an entry's name.
53E9
INC HL 23
Increment Register Pair HL (INC HL does not change the flags).
53EA
If the Z FLAG is set (still in the name), LOOP back to 53E7H until Register Pair HL is past the attribute byte.
53EC
INC HL 23
Increment Register Pair HL over the entry's first value byte.
53ED
INC HL 23
Increment Register Pair HL over the second value byte: Register Pair HL = the next entry.
53EE
POP DE D1
Restore Register Pair DE from the stack: the start of the typed word.
53EF
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the next entry's first byte.
53F0
OR A B7
OR Register A (that byte) with itself to set the flags: the Z FLAG is set at the 00H that ends the table (54E2H).
53F1
If the NZ FLAG is set (another entry), LOOP back to 53DEH.
53F3
JUMP to 544DH: the word is not one of SYS18/SYS's commands and the line goes on as typed.
53F5
INC HL 23
Increment Register Pair HL to the entry's next byte.
53F6
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the entry's next character or its attribute byte.
53F7
BIT 7,A CB 7F
Test bit 7 of Register A: set for the attribute byte, the whole name has matched.
53F9
If the Z FLAG is set (more of the name), LOOP back to 53DFH to compare the next typed character.
53FB
INC HL 23
Increment Register Pair HL to the entry's first value byte.
53FC
LD C,(HL) 4E
Load Register C with the byte at Register Pair HL, the first value byte.
53FD
INC HL 23
Increment Register Pair HL to the entry's second value byte.
53FE
LD B,(HL) 46
Load Register B with the byte at Register Pair HL, the second value byte. Register Pair BC = the entry's value.
53FF
POP HL E1
Restore Register Pair HL from the stack: the start of the command word in the buffer.
5400
BIT 6,A CB 77
Test bit 6 of Register A, the attribute byte: set for RENEW, RENUM and REF (C0H).
5402
If the Z FLAG is set (not one of them), JUMP to 5413H.
5404
LD (57B6H),BC ED 43 B6 57
Store Register Pair BC at 57B6H-57B7H in BASIC/CMD: Register C (the RST 28H code, or 01H for RENEW) at 57B6H and Register B (01H, the mark) at 57B7H, for 54FBH after the line is tokenized.
5408
LD (HL),FFH 36 FF
Store FFH at Register Pair HL, over the command word's first letter: the byte 54FAH-5504H looks for.
540A
INC HL 23
Increment Register Pair HL to the next letter of the command word.
540B
RST 18H DF
RST 18H: compare Register Pair HL with Register Pair DE (just past the matched letters). The NO CARRY FLAG is set at the end of the word.
540C
If the NO CARRY FLAG is set (the word is done), JUMP to 544DH.
540E
LD (HL),20H 36 20
Store 20H (a space) at Register Pair HL, over a letter of the command word, so that the ROM's tokenizer makes no keyword of it.
5410
INC HL 23
Increment Register Pair HL to the next letter.
5411
JUMP to 540BH to test the next letter at Register Pair HL.
5413
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the typed text after the command letters.
5414
DEC HL 2B
Decrement Register Pair HL, so that the RST 10H that follows reads that character.
5415
BIT 5,A CB 6F
Test bit 5 of Register A, the attribute byte: set for DI and DU (A1H, A0H).
5417
If the NZ FLAG is set (DI or DU), JUMP to 5453H.
5419
RST 10H D7
An abbreviation (A, D, E or L, attribute 80H): RST 10H steps Register Pair HL to the next character that is not a space, in Register A; the CARRY FLAG is set for a digit.
541A
If the CARRY FLAG is set (a line number follows the letter), JUMP to 5420H.
541C
CP 2EH FE 2E
Compare Register A (the character after the letter) against 2EH, a period (the current line).
541E
If the NZ FLAG is set (neither a number nor a period), JUMP to 544DH: the line goes on as typed.

NO = IN THE LINE
Register Pair HL steps to the carriage return; an = means the line is an assignment such as A1=5, not an abbreviation.

5420
INC HL 23
Increment Register Pair HL to the next character of the line.
5421
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the character.
5422
CP 3DH FE 3D
Compare Register A (the character) against 3DH, an =.
5424
If the Z FLAG is set (an =: an assignment), JUMP to 544DH: the line goes on as typed.
5426
CP 0DH FE 0D
Compare Register A (the character) against 0DH, the carriage return that ends the line.
5428
If the NZ FLAG is set (more of the line), LOOP back to 5420H.
542A
POP HL E1
Restore Register Pair HL from the stack: the start of the input buffer, pushed at 53CBH.
542B
POP DE D1
Restore Register Pair DE from the stack: the Register Pair BC pushed at 53CAH, so Register D = the characters typed and Register E = the buffer size.
542C
LD A,D 7A
Load Register A with Register D, the line's length.
542D
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the line's length is kept in Register A'.
542E
LD A,(BC) 0A
Load Register A with the byte at Register Pair BC, the length of the full word (Register Pair BC = the entry's value, the address of a length byte and the letters, 54E3H-54F9H).
542F
DEC A 3D
Decrement Register A: the word's length less the one letter typed, the characters to add.
5430
ADD A,D 82
Add Register D (the line's length) to Register A: the new length of the line.
5431
LD D,A 57
Load Register D with Register A, the new length.
5432
CP E BB
Compare Register A (the new length) with Register E, the buffer size: the NO CARRY FLAG is set if the line would not fit.
5433
If the NO CARRY FLAG is set (too long), JUMP to 53D7H for SYNTAX ERROR.
5435
PUSH DE D5
Save Register Pair DE (Register D = the new length, Register E = the buffer size) on the stack, in place of the Register Pair BC taken at 542BH: the counts 544EH gives back to INLIN.
5436
PUSH HL E5
Save Register Pair HL (the start of the buffer) on the stack again.
5437
LD A,(BC) 0A
Load Register A with the byte at Register Pair BC, the word's length.
5438
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': Register A = the line's old length, and the word's length goes to Register A'.
5439
INC BC 03
Increment Register Pair BC to the word's first letter.
543A
PUSH BC C5
Save Register Pair BC (the word's letters) on the stack.
543B
LD C,A 4F
Load Register C with Register A, the line's old length.
543C
LD B,00H 06 00
Load Register B with 00H, so that Register Pair BC = the old length.
543E
ADD HL,BC 09
Add Register Pair BC (the old length) to Register Pair HL (the buffer): Register Pair HL = the end of the line.
543F
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the end of the line.
5440
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': Register A = the word's length.
5441
LD H,B 60
Load Register H with Register B (00H), the high byte.
5442
LD L,A 6F
Load Register L with Register A, the word's length.
5443
DEC L 2D
Decrement Register L: Register Pair HL = the characters to add.
5444
ADD HL,DE 19
Add Register Pair DE (the end of the line) to Register Pair HL: Register Pair HL = the new end of the line.
5445
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the new end, Register Pair HL = the old end.
5446
LDDR ED B8
Move Register Pair BC bytes (the old length) from Register Pair HL (the line's carriage return) to Register Pair DE, working downward: the characters after the typed letter move up by the characters to add. Afterwards Register Pair HL = the start of the buffer (the typed letter), Register Pair DE = the place of the word's last letter and Register Pair BC = 0000H.
5448
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the start of the buffer, where the typed letter is.
5449
POP HL E1
Restore Register Pair HL from the stack: the word's letters, saved at 543AH.
544A
LD C,A 4F
Load Register C with Register A, the word's length (Register B is 00H after LDDR).
544B
LDIR ED B0
Copy Register Pair BC bytes (the word) from Register Pair HL to Register Pair DE: the word's letters replace the typed letter and fill the room made (the abbreviation is expected as the line's first character).
544D
POP HL E1
Restore Register Pair HL from the stack: the start of the input buffer.
544E
POP BC C1
Restore Register Pair BC from the stack: Register B = the line's length, Register C = the buffer size, for INLIN.
544F
POP DE D1
Restore Register Pair DE from the stack: the Register Pair DE saved at 53C9H.
5450
JUMP to ROM 0375H inside INLIN, which ends the line with 00H, takes back Register Pair AF (pushed at 53C5H) and Register Pair BC (pushed at 5262H or 520EH) and returns to 1A7EH with the CARRY FLAG set for BREAK.
5453
LD (54A1H),A 32 A1 54
Self-Modifying Code
DI or DU: store Register A (the attribute: A1H for DI, A0H for DU) at 54A1H, the operand of LD A,nn at 54A0H.
5456
RST 10H D7
RST 10H: step Register Pair HL to the next character that is not a space, in Register A; the CARRY FLAG is set for a digit.
5457
If the CARRY FLAG is set (a line number), JUMP to 5464H.
5459
CP 2EH FE 2E
Compare Register A (the character) against 2EH, a period (the current line).
545B
If the NZ FLAG is set (neither a number nor a period), JUMP to 544DH: the line goes on as typed.
545D
LD BC,(40ECH) ED 4B EC 40
Load Register Pair BC with the 16-bit value at 40ECH, the ROM's current line for LIST and EDIT: the line to move or copy.
5461
RST 10H D7
RST 10H: step Register Pair HL past the period; Register A = the next character.
5462
JUMP to 5469H with Register Pair BC = the current line's number.
5464
GOSUB to ROM 1E5AH (LINGET): Register Pair DE = the line number; Register A = the character after it.
5467
LD B,D 42
Load Register B with Register D, the high byte of the line number.
5468
LD C,E 4B
Load Register C with Register E, the low byte. Register Pair BC = the number of the line to move or copy.
5469
CP 2CH FE 2C
Compare Register A (the character after the first line number) against 2CH, a comma.
546B
If the NZ FLAG is set (no comma), JUMP to 544DH: the line goes on as typed.
546D
RST 10H D7
RST 10H: step Register Pair HL past the comma; Register A = the next character, the CARRY FLAG set for a digit.
546E
If the NO CARRY FLAG is set (no new line number), JUMP to 544DH: the line goes on as typed.
5470
GOSUB to ROM 1E5AH (LINGET): Register Pair DE = the new line number; Register A = the character after it.
5473
CP 0DH FE 0D
Compare Register A (the character after the new number) against 0DH, the carriage return.
5475
If the NZ FLAG is set (more follows), JUMP to 544DH: the line goes on as typed.
5477
POP AF F1
Restore Register Pair AF from the stack, discarding 1 of 6 words: the Register Pair HL pushed at 53CBH. DI and DU store the line themselves and go to READY.
5478
POP AF F1
Restore Register Pair AF from the stack, discarding 2 of 6: the Register Pair BC pushed at 53CAH.
5479
POP AF F1
Restore Register Pair AF from the stack, discarding 3 of 6: the Register Pair DE pushed at 53C9H.
547A
POP AF F1
Restore Register Pair AF from the stack, discarding 4 of 6: the Register Pair AF pushed at 53C5H.
547B
POP AF F1
Restore Register Pair AF from the stack, discarding 5 of 6: the Register Pair BC pushed at 5262H or 520EH.
547C
POP AF F1
Restore Register Pair AF from the stack, discarding 6 of 6: 1A7EH, INLIN's return into the ROM's command loop.
547D
PUSH DE D5
Save Register Pair DE (the new line number) on the stack.
547E
LD D,B 50
Load Register D with Register B, the high byte of the old line number.
547F
LD E,C 59
Load Register E with Register C, the low byte. Register Pair DE = the old line number.
5480
GOSUB to ROM 1B2CH (FNDLIN), which looks for the line numbered Register Pair DE: Register Pair BC returns its address and the CARRY FLAG is set if it exists.
5483
If the NO CARRY FLAG is set (no such line), JUMP to ROM 1ED9H (USERR) for UNDEFINED LINE NUMBER.
5486
LD DE,(40A7H) ED 5B A7 40
Load Register Pair DE with the 16-bit value at 40A7H, the ROM's pointer to the input buffer.
548A
LD H,B 60
Load Register H with Register B, the high byte of the old line's address.
548B
LD L,C 69
Load Register L with Register C, the low byte. Register Pair HL = the old line.
548C
DEC DE 1B
Decrement Register Pair DE, 1 of 2, below the input buffer.
548D
DEC DE 1B
Decrement Register Pair DE, 2 of 2: Register Pair DE = two bytes before the input buffer, where the line's text is copied.
548E
PUSH DE D5
Save Register Pair DE (that address) on the stack.
548F
PUSH BC C5
Save Register Pair BC (the old line's address) on the stack.
5490
LD BC,0004H 01 04 00
Load Register Pair BC with 0004H: the length count starts at 4 for the line's link and number.
5493
ADD HL,BC 09
Add Register Pair BC (4) to Register Pair HL: Register Pair HL = the old line's text.

COPY THE TEXT
Register Pair HL = the old line's text, Register Pair DE = the copy, Register Pair BC = the length counted.

5494
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, a byte of the old line's text.
5495
OR A B7
OR Register A (the byte) with itself to set the flags: the Z FLAG is set at the 00H that ends the line.
5496
LD (DE),A 12
Store Register A (the byte) at Register Pair DE, in the copy.
5497
INC HL 23
Increment Register Pair HL to the next byte of the line.
5498
INC DE 13
Increment Register Pair DE to the next byte of the copy.
5499
INC BC 03
Increment Register Pair BC, counting the byte (INC BC does not change the flags).
549A
If the NZ FLAG is set (not the end), LOOP back to 5494H.
549C
LD D,B 50
Load Register D with Register B, the high byte of the line's length (4 plus its text and the 00H).
549D
LD E,C 59
Load Register E with Register C, the low byte. Register Pair DE = the line's length.
549E
POP BC C1
Restore Register Pair BC from the stack: the old line's address.
549F
PUSH DE D5
Save Register Pair DE (the line's length) on the stack.
54A0
LD A,00H 3E 00
Self-Modifying Code
Load Register A with the attribute, the operand 54A1H (00H in the file; A1H for DI or A0H for DU, stored at 5453H).
54A2
RRCA 0F
Rotate Register A right: bit 0 goes into the CARRY FLAG, set for DI.
54A3
If the NO CARRY FLAG is set (DU, copy), JUMP to 54ABH: the old line stays.
54A5
DI: GOSUB to ROM 2BE4H inside DELETE, which moves the program down from Register Pair HL (the line after the old one, where the copy loop stopped) to Register Pair BC (the old line), taking the old line out, and sets 40F9H.
54A8
GOSUB to ROM 1AF8H (LINKER), which rebuilds every line's link field.
54AB
POP BC C1
Restore Register Pair BC from the stack: the line's length.
54AC
POP HL E1
Restore Register Pair HL from the stack: the copy of the text, two bytes before the input buffer.
54AD
POP DE D1
Restore Register Pair DE from the stack: the new line number.
54AE
DEC HL 2B
Decrement Register Pair HL, one byte before the copy, for the RST 10H at 1AADH.
54AF
JUMP to ROM 1AA7H in the command loop, which stores the text after Register Pair HL as the line numbered Register Pair DE (Register Pair BC = its length), as if it had been typed, and returns to READY.

54B2H - Command Table (Data)

Entries of a name, an attribute byte (bit 7 set) and two value bytes: bit 6 = a command run after tokenizing (54FAH), value = the RST 28H code (or 01H for RENEW) and the mark 01H; bit 5 = DI or DU, bit 0 set for DI; 80H = a one-letter abbreviation, value = the address of the full word (a length byte and its letters). A 00H ends the table.

54B2-54B9
DEFM "RENEW" / DEFB C0H, 01H, 01H 52 45 4E 45 57 C0 01 01
RENEW: attribute C0H, code 01H (handled at 5522H), mark 01H.
54BA-54C1
DEFM "RENUM" / DEFB C0H, 4FH, 01H 52 45 4E 55 4D C0 4F 01
RENUM: attribute C0H, RST 28H code 4FH (SYS13/SYS function 2), mark 01H.
54C2-54C7
DEFM "REF" / DEFB C0H, 2EH, 01H 52 45 46 C0 2E 01
REF: attribute C0H, RST 28H code 2EH (SYS12/SYS function 1), mark 01H.
54C8-54CC
DEFM "DI" / DEFB A1H, 00H, 00H 44 49 A1 00 00
DI (move a line to a new number): attribute A1H.
54CD-54D1
DEFM "DU" / DEFB A0H, 00H, 00H 44 55 A0 00 00
DU (copy a line to a new number): attribute A0H.
54D2-54D5
DEFM "A" / DEFB 80H / DEFW 54F5H 41 80 F5 54
A: the abbreviation of AUTO, whose length byte and letters are at 54F5H.
54D6-54D9
DEFM "D" / DEFB 80H / DEFW 54EEH 44 80 EE 54
D: the abbreviation of DELETE, whose length byte and letters are at 54EEH.
54DA-54DD
DEFM "E" / DEFB 80H / DEFW 54E9H 45 80 E9 54
E: the abbreviation of EDIT, whose length byte and letters are at 54E9H.
54DE-54E1
DEFM "L" / DEFB 80H / DEFW 54E3H 4C 80 E3 54
L: the abbreviation of LIST, whose length byte and letters are at 54E3H.
54E2
DEFB 00H 00
The 00H that ends the command table; the search at 53EFH-53F0H stops at it.
54E3-54E8
DEFB 04H / DEFM "LIST" / DEFB 0DH 04 4C 49 53 54 0D
The word LIST and its length 04H for L. BASIC/CMD also uses 54E4H-54E8H, LIST and a carriage return, as the command it starts with after a start with an asterisk (its 654DH).
54E9-54ED
DEFB 04H / DEFM "EDIT" 04 45 44 49 54
The word EDIT and its length byte 04H, written out for E by 542EH-544BH.
54EE-54F4
DEFB 06H / DEFM "DELETE" 06 44 45 4C 45 54 45
The word DELETE and its length byte 06H, written out for D by 542EH-544BH.
54F5-54F9
DEFB 04H / DEFM "AUTO" 04 41 55 54 4F
The word AUTO and its length byte 04H, written out for A by 542EH-544BH.

54FAH - After Tokenizing

Entered from BASIC/CMD 5756H through the link 41B2H, which the ROM's command loop calls at 1AA1H after a typed line has been tokenized (Register Pair HL = the tokenized line, the CARRY FLAG set if it has a line number). BASIC/CMD pushed the ROM's Register Pair AF and Register Pair BC above the return address 1AA4H. A line marked at 5404H-5411H (its first byte FFH and the mark at 57B7H) is one of RENEW, RENUM and REF and is carried out here; any other line goes back to the ROM.

54FA
PUSH HL E5
Save Register Pair HL (the pointer to the tokenized line) on the stack.
54FB
LD BC,(57B6H) ED 4B B6 57
Load Register Pair BC with the 16-bit value at 57B6H: Register C = the code stored at 5404H, Register B = the mark (01H when 5404H marked the line).
54FF
XOR A AF
Load Register A with 00H (XOR A with itself).
5500
LD (57B7H),A 32 B7 57
Store Register A (00H) at 57B7H, clearing the mark: it counts only for this line.
5503
RST 10H D7
RST 10H: step Register Pair HL to the first byte of the tokenized line that is not a space, in Register A.
5504
INC A 3C
Increment Register A: the Z FLAG is set if the byte was FFH, the mark of 5408H.
5505
If the Z FLAG is set (the line starts with FFH), JUMP to 5511H.
5507
POP HL E1
Restore Register Pair HL from the stack: the pointer to the tokenized line.
5508
POP BC C1
Restore Register Pair BC from the stack: the ROM's Register Pair BC, pushed at BASIC/CMD 5757H.
5509
POP AF F1
Restore Register Pair AF from the stack: the ROM's Register Pair AF, pushed at BASIC/CMD 5756H, the CARRY FLAG set if the line has a line number.
550A
RET C D8
If the CARRY FLAG is set (a program line), RETURN to the ROM at 1AA4H, which stores it.
550B
GOSUB to BASIC 6382H: when no file statement runs (6382H = 00H) it drops this return and goes back to the ROM at 1AA4H, which runs the direct statement; during a file statement (C9H) it returns here.
550E
JUMP to BASIC 5DB8H (LD A,84H) for error 84H Direct Statement In File.
5511
The FFH byte: decrement Register B (the mark from 57B7H); if it was not 01H (an FFH typed by the user), JUMP to 5507H.
5513
POP AF F1
Restore Register Pair AF from the stack, discarding 1 of 4: the pointer pushed at 54FAH.
5514
POP AF F1
Restore Register Pair AF from the stack, discarding 2 of 4: the ROM's Register Pair BC.
5515
POP AF F1
Restore Register Pair AF from the stack, discarding 3 of 4: the ROM's Register Pair AF.
5516
POP AF F1
Restore Register Pair AF from the stack, discarding 4 of 4: the ROM's return 1AA4H; the command is carried out here instead.
5517
RST 10H D7
RST 10H: step Register Pair HL past the spaces that replaced the command word, to its parameters; Register A = the first one.
5518
LD DE,1A25H 11 25 1A
Load Register Pair DE with 1A25H, the ROM's READY.
551B
PUSH DE D5
Push Register Pair DE (1A25H) on the stack: the command ends at READY.
551C
LD A,C 79
Load Register A with Register C, the code from the command table (57B6H).
551D
CP 20H FE 20
Compare Register A (the code) against 20H: the NO CARRY FLAG is set for an RST 28H code (RENUM 4FH, REF 2EH).
551F
If the NO CARRY FLAG is set, JUMP to 5531H to call the overlay.
5522
DEC A 3D
Decrement Register A (the code): the Z FLAG is set for code 01H, RENEW.
5523
If the NZ FLAG is set (an unknown code), JUMP to ROM 1997H for SYNTAX ERROR.
5526
LD HL,(40A4H) 2A A4 40
RENEW: load Register Pair HL with the 16-bit value at 40A4H, the first program line.
5529
LD (HL),FFH 36 FF
Store FFH at Register Pair HL, the low byte of the first line's link field: NEW leaves it 0000H, so the program looks empty; any other value brings it back.
552B
GOSUB to ROM 1AF8H (LINKER), which rebuilds every line's link field from the first line on and returns Register Pair HL at the end marker's second byte.
552E
JUMP to ROM 1B59H inside NEW, which steps Register Pair HL past the end marker, stores it at 40F9H as the program's end, clears the variables (1B5DH) and returns to 1A25H, READY, pushed at 551BH.
5531
LD DE,641EH 11 1E 64
Load Register Pair DE with 641EH, BASIC/CMD's end of the statement (it clears the printer switch 5D45H and bit 6 of 4289H).
5534
PUSH DE D5
Push Register Pair DE (641EH) on the stack: the overlay returns there, and from there to 1A25H.
5535
RST 28H EF
RST 28H with Register A = the code (4FH: RENUM in SYS13/SYS; 2EH: REF in SYS12/SYS) and Register Pair HL at the parameters after the command word; it does not come back here.

5536H - Unused Bytes

The rest of the file.

5536-56E7
DEFB 00H x 434 00 x 434
434 bytes of 00H to the end of the file (56E7H). Nothing in SYS18/SYS reads or writes them.