LS-DOS 6.3.1 for the Model 4 - BASIC/OV2 Disassembled
Page Customization
Page Index
BASIC/OV2
Other Navigation
Introduction/Summary
LS-DOS 6.3.1 BASIC/OV2 Disassembly (Model 4)
BASIC/OV2 holds the four program editing commands the Disk BASIC of LS-DOS 6.3.1 keeps out of BASIC/CMD: C for COPY, M for MOVE, F for FIND and S for SEARCH. It is 1376 bytes dated 21 February 1990, the only one of the three BASIC files carrying the date of the 6.3.1 release itself, and it is built from BMOVE/ASM. It is not a load module: newb.jcl assembles it with EDAS's core image switch, so the file is the bytes themselves with no load records at all, and it runs where it is read in, the DOS overlay area at 1E00H to 235FH. The enhancement package of BASIC/CMD reads it there itself rather than letting the DOS command interpreter load it, so the file is never a command a user can type.
MORC at 8234H of that package is the whole of the loading. It saves the command token, calls CLEAR 447EH, which closes every open file and throws every variable away, and NORMNUM 661EH, which walks the program and puts every line reference back into the plain number form; reads OVRLY$ 0069H and skips the load when it already holds 01H; otherwise opens BASIC/OV2 with a buffer at 1E00H and reads six whole sectors, which is B296, 160 bytes more than the file holds; and jumps to 1E00H with Register A holding the command token and Register Pair HL at INBUF 7039H. The call to NORMNUM is what makes the rest sound: MOVE's own walk writes the resolved 0DH form of a reference and reads it back, and FIND looks only for the plain 0EH form, so neither would be safe if a 0DH left by an earlier GOTO were still standing in the program text.
The entry at 1E00H stores the Stack Pointer into SAVSTK (2352H) and separates the four tokens: 05H to COPY (22C5H), 02H to MOVE (1E0EH), and everything else to DOFIND (20C0H), which keeps the token in DTYPE (21E9H) and is therefore both SEARCH, 03H, and FIND, 04H. No command returns to its caller: each of them loads Register Pair HL with an address in BASIC/CMD, puts the Stack Pointer back from SAVSTK and jumps, and the four exits at 2342H to 2354H are chained by three 0DDH prefix bytes so that one load of Register Pair HL survives the three beneath it.
MOVE (1E0EH) takes three line numbers and reads them with NXTLIN (1E4AH) and its second entry NXTLIN1 (1E56H), all three of which must name lines that exist. GOTLIN (1E64H) refuses an insert point inside the block, counts the line numbers free above it into BLANKS (1EC3H), counts the lines of the block with the walk at CNTLP (1EAFH) and refuses a block that needs more numbers than there are. The memory check at 1ED2H proves the block fits in the free memory between LOPT 71A3H and HIPT 7178H, and 1EFDH settles the direction, whose Carry Flag is then carried on the stack through the whole of the rest of the command.
Then the heart of MOVE, which is one walk of the program run twice from TIME2 (1F1DH). Pass 1 turns every reference to a line of the block into the 0DH token and the address that line will stand at once it has moved, which is what RANGE (1FBAH) works out by adding OFFSET (1FCCH); an undefined reference is reported by UNDEF (1F71H) and the walk carries on. PAS1DUN (1FD3H) then lifts the block into free memory, shuffles the lines between the hole and the insert point over it with an instruction it writes at 2023H, gives every line of the block its new link and its new number at ADJ1 (203DH), puts the block down again at ADJ2A (2074H) and adjusts the links of the shuffled lines at ADJ3 (20A5H). ADJ4 (20B9H) clears DOPASS1 (2355H) and goes back to TIME2 for pass 2, which turns every address pass 1 wrote into the number the line now carries.
FIND and SEARCH (20C0H) are one body of code and part company only at SHOW (21E8H): SEARCH goes to SHOLIN (2211H), which makes the line found the current one and hands a full stop to NOBRK@ 80F4H, the key handler of the enhancement package, and never returns; FIND goes to SHONUM (21EEH), which writes the line's number and does return, so that FIND lists every match in one line with COMSTR (220EH) between them. What is looked for is read out of the tokenized command line at LBUF+1 6EFAH and not out of INBUF, which is the one place this overlay prefers the tokenized form, and it has to: a keyword stands in the program text as one byte. The first character chooses among three searches, KEYFIND (20E7H) for a token, VARFIND (212CH) for a name and NUMFIND (221EH) for a line number, and a bare command goes to AGAIN (2265H), which picks the last search up at the line after the one it stopped at.
COPY (22C5H) copies nothing itself. It finds the line asked for, moves its tokenized text into LBUF, has UNTOKE 7A0DH turn it back into characters at INBUF, makes room for a five character line number in front of them with the LDDR at 2319H, writes the new number into that room with @HEXDEC, shows the whole line on the display and jumps to 5993H, the line entry of BASIC/CMD, so that the line is entered exactly as a typed line would be. That is why 59AFH counts COPY as the keyboard, and why a COPY to a number above 65529 gives Syntax error and not Illegal function call.
Notes
BASIC/OV2 is the only file of the release built as a core image, which is why rec.py cannot be run on it: the first byte of the file is EDH, the first half of the LD (nn),SP at 1E00H, and a record reader takes that for a record type and walks off the end. The source has the assembler check the length itself, with an IFGT that gives an error if the code reaches past 23FFH, which is the top of the DOS overlay area.
The file occupies part of LOWBUF$ 2300H, the resident system's low memory disk buffer: 2300H to 235FH is the tail of COPY and the whole of the overlay's own storage. That is the same region B296 writes over, MORC reading 1536 bytes for a file of 1376, so the 160 bytes from 2360H to 23FFH take whatever followed the file in its last sector on the diskette.
Once the overlay has been read in, OVRLY$ 0069H holds 01H and MORC skips the load, so a second extended command does not touch the disk and the file need not still be there. SVCUSR at 8078H of the enhancement package clears that cell before any supervisor call that might load a DOS overlay over the same address, which is what makes the caching safe.
KEYFIND is the only code in the whole of the Disk BASIC that uses the alternate accumulator. No row of BASIC/CMD's 21978 bytes decodes as EX AF,AF', and KEY2 (2118H) uses it twice over to hold the result of one comparison while a second is made, which is how both halves of a two byte function token are matched without a spare register.
The reference walk of MOVE takes no notice of a string literal or of REM text, where VARFIND steps carefully over both. It is safe all the same, and the reason is in the line readers of BASIC/CMD: 7E42H throws away every control character but a tab and a line feed when a line is read from a text file, and the keyboard reader does the same, so no 0DH or 0EH byte can reach a literal or a remark. VARFIND has to be careful because the characters it looks for are ordinary ones.
Three runs of this file are reached by nothing. The Illegal function call at 1EBCH cannot be taken, the end of the program standing beyond the last line of the block because 1E5CH has already found that line; the Illegal function call at 2142H cannot be taken, 20D5H and 20D9H having already proved the first character of the name is a letter, which VALID accepts; and the jump at ILLEG (2340H) is two bytes nothing needs, every one of COPY's eight error jumps being within reach of BADLIN (2346H) itself, the furthest at 79H bytes where a relative jump reaches 7FH. The call and return at 22B0H is a fourth small waste of the same kind, a jump to CKSPCL (22B6H) doing the same work in the same three bytes.
216DH to 2176H is the one part of the file the two builds differ over. BMOVE/ASM has it inside an IF on the 6.3.1 build switch, and the other branch is a jump to a patch area at the end of the source that the 6.3.1 assembly leaves out altogether. What the release's branch adds is that the apostrophe form of REM and the second byte of a two byte function token are both stepped over by VARFIND, so that neither can be taken for the beginning of a variable name.
Against the manual
The BASIC Reference Manual's Copying, Moving, and Searching section describes all four commands and the bytes agree with it almost everywhere, including the parts that are easiest to get wrong. Its example that a block moved after line 100 where line 110 follows can be no more than nine lines long is exactly what BLANKS (1EC3H) works out and 1EC9H tests: one less than the difference of the two numbers. Its rule that Num2 must be greater than or equal to Num1 is the comparison at 1E2AH, which lets the two be equal and so allows a block of one line. Its claim that these commands clear all variable values and close any open files is true by way of the CLEAR 447EH that MORC calls before the overlay is entered, not of anything in this file.
Its syntax tables give the object as optional for SEARCH and as required for FIND, and that difference is real: a bare S reaches AGAIN (2265H) and repeats the last search, and a bare F is refused at 2268H and goes back to the prompt without a word. The reason is in the two answers of SHOW: SEARCH shows one line and stops, so there is something to carry on from, and FIND writes the whole list in one go, so there is not.
Its warning that type declarations must be used and that F A would not find A$ or A() is the test at 219EH, which refuses a match when the character after the name is one VALID (229DH) accepts, and VALID accepts the four declaration characters and an opening parenthesis. Its warning that only the first ten characters of a name are significant is the collecting loop at VAR1 (2131H), which stops at ten, together with 2193H, which accepts a ten character match without looking at what follows it: a search for a name of the full ten characters matches every longer name that begins with it.
The manual says the space after the letter is mandatory when a keyword is being looked for. Nothing in this file requires it: 20CAH calls NXTCHAR, which steps over as many spaces as there are, so none, one or several make no difference here. The requirement belongs to the tokenizer and to the abbreviation test of CKABBR at 81D5H, which have to see the letter as a word of its own before the command token is ever written.
Two things the manual does not say. FIND and SEARCH of a line number name the line of that number as well as every line that refers to it, because 223DH leaves the line's own number in Register Pair DE and the first comparison of every line at 2241H is made against it, before NUMLP2 (2253H) begins looking for a reference. And the file need only be on the disk for the first of these commands in a session, the caching at OVRLY$ 0069H taking care of the rest, where the manual says the file must be present when using them.
Bugs
B350: 1EC7H skips the only limit there is on the new line numbers whenever the block is moved to after the last line of the program. 1E98H leaves BLANKS (1EC3H) at 0000H in that case, meaning that there is no following line to run into, and that jump reads the 0000H as a reason to skip the comparison entirely. ADJ1 then gives each line of the block the next number after NUM3 with the plain increment at 204AH and no ceiling of any kind, so a program whose last line is numbered near the top of the range comes back with lines numbered above 65529, which the line entry will not accept from the keyboard, and with enough lines the numbers wrap through 65535 to 0 and the program's numbers are no longer in order. FIND 5AB4H gives up as soon as a line's number stands above the one asked for, so every line past the wrap becomes unreachable to GOTO, LIST, EDIT and DELETE while still being listed.
B351: 1ECEH stores the count of lines in the block into LTM (235AH) and nothing ever reads it. That instruction is the only one in BASIC/OV2 that names 235AH, the count is used where it stands in Register Pair BC at 1EC9H and nowhere else, and no routine outside the file could read the cell to any purpose, the overlay area being written over by the next DOS overlay. Four bytes of code and two of storage with nothing behind them.
B352: 219BH keeps the length of the name where the source means to keep the character of the line. 2192H has already loaded Register A from Register C for the comparison above it, so what is saved and brought back at 21A1H is a number from one to nine, and the comparison with an opening parenthesis at 21BEH can therefore never be equal on the path from 21A2H. Nothing goes wrong, because BYV1 (21C2H) reads the same character one instruction later and tests it for the parenthesis itself, so both paths reach VARLP3 (215DH) with the search standing in the same place.
B353: the jump at 2024H reads a Carry Flag that is not the one the code took care to save. 2007H pushes the direction so that the downward path below it may spoil the flags, and DOMOV (201BH) then reads the live flags rather than popping that copy. On the upward path they are still the direction; on the downward path they are whatever the subtraction at 2013H left, which is the Carry Flag clear for every pair of addresses where the insert point stands below the block. The two readings agree only because 1E7CH refuses a move whose block already stands at the insert point, which is the one case where that subtraction would borrow and the shuffle would be taken for an upward one.
B354: 2221H leaves a FIND or a SEARCH whose number has anything after it doing nothing and saying nothing. 221EH reads the number with NUM2DE and that jump goes to EXIT (234EH) when the line has not ended, which prints the prompt and no message, where MOVE at 1E3AH and COPY at 22ECH both give Illegal function call for exactly the same fault. So F 100,200 and S 100X look as though they found nothing, and a mistyped command cannot be told from a search that matched no line.
B355: the push at 2299H is never popped. AGN1 puts the address of the stored name on the stack before it jumps to VARREP (214DH), which is what NUMREP does at 2232H because its own comparison keeps the number it is looking for there; the variable search keeps nothing on the stack and reads nothing from it. The word stays where it is until one of the four exits puts the Stack Pointer back from SAVSTK (2352H), so the only cost is two bytes of stack for the length of one search.
Variables
Memory Used by BASIC/OV2
| Address Size | Contents |
|---|---|
| 1E86H-1E87H 2 bytes | POSN3 The operand of the LD HL at 1E85H, 0000H in the file: the address of the line the block is to be put after. Written at 1E44H from FIND's answer, read at 1E85H and 1F00H. |
| 1E9CH-1E9DH 2 bytes | NUM3 The operand of the LD DE at 1E9BH, 0000H in the file: the number of that line, and then the number the last moved line was given. Written at 1E40H and stepped one at a time by ADJ1 at 204BH; read at 1E64H, 1E9BH and 2046H. |
| 1EA7H-1EA8H 2 bytes | STRTLIN The operand of the LD HL at 1EA6H, 0000H in the file: the address of the first line of the block. Written at 1E15H; read at 1EA6H, 1EE4H, 1EF5H, 1F06H, 1FDAH, 2000H, 202EH and 207DH. |
| 1EAAH-1EABH 2 bytes | ENDLIN The operand of the LD DE at 1EA9H, 0000H in the file: the address of the last line of the block. Written at 1E21H; read at 1EA9H, 1EDDH and 1FEDH. |
| 1EC3H-1EC4H 2 bytes | BLANKS The operand of the LD HL at 1EC2H, 0000H in the file: how many line numbers are free above the insert line, or 0000H for no limit at all. Written at 1E82H and 1EA3H, read at 1EC2H. The 0000H case is B350. |
| 1FCCH-1FCDH 2 bytes | OFFSET The operand of the LD HL at 1FCBH, 0000H in the file: the distance every moved line's address changes by. Written at 1F18H, read by RANGE at 1FCBH and by ADJ0 at 2039H. |
| 2023H 1 byte | DIRECT The second byte of the instruction at 2022H, B0H in the file, which makes it an LDIR; 201BH stores B8H there for a downward move, which makes it an LDDR. |
| 205AH-205BH 2 bytes | OFFSET1 The operand of the LD DE at 2059H, 0000H in the file: the distance the block's own bytes moved to reach free memory, which turns an old link into the next line's place in the copy. Written at 2035H, read at 2059H. |
| 205FH-2060H 2 bytes | ENDPT The operand of the LD HL at 205EH, 0000H in the file: the byte past the end of the block in free memory, which ADJ1 stops on. Written at 1FE7H from the LDIR's own Register Pair DE, read at 205EH. |
| 2072H-2073H 2 bytes | UPSTART The operand of the LD DE at 2071H, 0000H in the file: where an upward shuffle left room for the block. Written at 2026H from the shuffle's own Register Pair DE, read at 2071H. |
| 208CH-208DH 2 bytes | TOCNG The operand of the LD BC at 208BH, 0000H in the file: the count of bytes the shuffle moved. Written at 201EH, read at 208BH. |
| 20AFH-20B0H 2 bytes | ENDPT1 The operand of the LD HL at 20AEH, 0000H in the file: the byte past the shuffled region in its new place, which ADJ3 stops on. Written at 2091H, read at 20AEH. |
| 21E9H 1 byte | DTYPE The operand of the LD A at 21E8H, 00H in the file: the command token, 03H for SEARCH and 04H for FIND. Written at 20C0H, read by SHOW at 21E8H and by AGAIN at 2265H. |
| 21F1H 1 byte | FTIME The operand of the LD A at 21F0H, 00H in the file: 00H until FIND has written a number and 01H after, which is what puts a comma in front of every number but the first. Written at 20C4H and 21F5H, read at 21F0H. |
| 2207H-2208H 2 bytes | NXTPO The operand of the LD HL at 2206H, 0000H in the file: the address of the next line of the program. Written a byte at a time by GTPTR at 21DCH and 21E2H, read at 2206H, so that SHOW leaves the search one byte below that line. |
| 2352H-2353H 2 bytes | SAVSTK The operand of the LD SP at 2351H, 0000H in the file: the Stack Pointer as BASIC's own CLEAR left it. Written by the first instruction of the overlay at 1E00H and loaded back by every one of the four exits. |
| 2355H 1 byte | DOPASS1 Which pass of the line reference walk is running, 00H in the file: not 00H for the first and 00H for the second. Written at 1F1DH and 20BAH, read at 1F36H and 1FD3H. |
| 2356H-2357H 2 bytes | NUM1 The first line number of the block, 0000H in the file. Written at 1E11H, read at 1E76H and by RANGE at 1FC1H. |
| 2358H-2359H 2 bytes | NUM2 The last line number of the block, 0000H in the file. Written at 1E1DH, read by RANGE at 1FBAH. |
| 235AH-235BH 2 bytes | LTM The count of lines in the block, 0000H in the file. Written at 1ECEH and read by nothing at all, which is B351. |
| 235CH-235DH 2 bytes | TOMOVE The length of the block in bytes, 0000H in the file. Written at 1EEBH, read at 1EF0H, 1F11H, 1FE1H, 2077H, 2080H and 2096H. |
| 235EH-235FH 2 bytes | NEWLIN The address in the program text the block is to be moved to, 0000H in the file. Written at 1E8BH, read at 1EF8H, 1FF7H, 200EH, 2069H and 2087H. |
Memory of Other Files Used
| Address Size | Contents |
|---|---|
| 6E9EH 2 bytes | PGMBGN (BASIC/CMD) The address of the first line of the program, read at 1F20H, 20F7H, 214AH and 2228H so that each of the four walks starts at the top. |
| 6EF9H-7038H 320 bytes | LBUF (BASIC/CMD) The tokenized line buffer. DOFIND reads what is to be searched for from 6EFAH at 20C7H; COPY puts the tokenized text of the line it is copying there at 22FDH; and the colon the enhancement package keeps at 6EF9H is the byte 2304H hands to UNTOKE and 2319H drops again. |
| 7039H-7138H 256 bytes | INBUF (BASIC/CMD) The input buffer. MOVE and COPY read their line numbers from the characters standing there, 1E00H being entered with Register Pair HL on it; UNTOKE lays the copied line down from 7039H; and COPY hands 7038H to the line entry at 233AH. |
| 7145H 2 bytes | IPOS (BASIC/CMD) The place in the line to carry on from after a packed number, read at 1FAEH so that PAS2A can write the three bytes of a reference, and at 225FH so that NUMFIND can step back over one. |
| 7178H 2 bytes | HIPT (BASIC/CMD) The highest free byte of memory, read at 1ED2H as the top of the room the block may be put in. |
| 7192H 2 bytes | CURLIN (BASIC/CMD) The number of the line being run, written by SHOLIN at 2215H so that the key handler of the enhancement package lists the line the search found. |
| 71A3H 2 bytes | LOPT (BASIC/CMD) The lowest free byte of memory, read at 1ED5H, 1FDDH, 202AH and 2074H: it is the bottom of the room and the address the block is parked at while the shuffle runs. |
| 83DBH 1 byte | LSTTYP$ (BASIC/CMD, the enhancement package) The kind of the last search: 0EH a line number, 80H or above a keyword token, below that the length of a variable name, 00H none yet. Written at 20E7H, 2145H and 222DH; read by AGAIN at 226DH. |
| 83DCH-83DDH 2 bytes | LSTLIN$ (BASIC/CMD, the enhancement package) The line the last search stopped at. Written at 2105H, 2159H and 223DH; read by SHONUM at 2200H, by SHOLIN at 2211H, by 2248H and by AGAIN at 2275H. |
| 83DEH-83DFH 2 bytes | LSTNUM$ (BASIC/CMD, the enhancement package) The line number the last search looked for. Written at 2224H, read by AGAIN at 2280H. |
| 83E0H 1 byte | LSTKEY$ (BASIC/CMD, the enhancement package) The second half of a two byte keyword token, FFH when there is none. Written at 20F4H, read by AGAIN at 228DH. |
| 83E1H-83EBH 11 bytes | LSTVAR$ (BASIC/CMD, the enhancement package) The variable name the last search looked for, up to ten characters and a 00H. Collected at 2138H and ended at 213DH; read a character at a time at 2185H and named again by 215DH and 2296H. |
Routines of Other Files Called
| Address | Contents |
|---|---|
| 052DH | @DSPLY (BOOT/SYS), SVC 10: COPY shows the whole of the line it has built before it enters it (2336H). |
| 06F6H | @HEXDEC (BOOT/SYS), SVC 97: the new line number written as five characters right justified with leading spaces (2329H). |
| 3131H | The word in and a number (BASIC/CMD): the second half of the Undef. line report, naming the line the reference stands in (1F83H). |
| 3139H | NUMDSP (BASIC/CMD): a line number written as decimal digits, for the Undef. line report (1F7CH) and for every number FIND lists (2203H). |
| 41E9H | The carriage return only when one is wanted (BASIC/CMD): the Undef. line report begins on a line of its own (1F71H). |
| 46A5H | The text writer (BASIC/CMD): UNDEF$ (1F78H) and COMSTR (21FDH). |
| 5AB4H | FIND (BASIC/CMD): a line looked up by its number, at 1E5CH, 1E6EH, 1F62H, 2279H, 22D7H and 22F3H. |
| 5E93H | NXTCHAR (BASIC/CMD): the next character or token of the line, called from eighteen places in this file. |
| 5F9AH | NUM2DE (BASIC/CMD): a line number read out of the command line, at 1E37H, 1E50H, 221EH, 225CH, 22CDH and 22E9H. |
| 5FAEH | NUMPOSN (BASIC/CMD), which BMOVE/ASM itself names: the two bytes after a reference token, at 1F50H, 1F5EH and 1F9DH. |
| 7A0DH | UNTOKE (BASIC/CMD): the tokenized line COPY has moved into LBUF turned back into characters at INBUF (2305H). |
Routines of Other Files Jumped To
| Address | Contents |
|---|---|
| 425CH | OMERR (BASIC/CMD): error 7, Out of memory, the exit NOMEM (234AH) takes when the block is longer than the free memory. |
| 5920H | READY (BASIC/CMD): the prompt and command level, the exit EXIT (234EH) takes when a command is done or has nothing to say. |
| 5993H | The line entered into the program (BASIC/CMD): COPY's last act, which tokenizes the line in INBUF and puts it in the program (233DH). |
| 5F95H | FUNCERR (BASIC/CMD): error 5, Illegal function call, the exit BADLIN (2346H) takes and the only error this file reports apart from Out of memory. |
| 80F4H | NOBRK@ (BASIC/CMD, the enhancement package): the command level key handler, given a full stop so that it lists the line SEARCH found, the exit DOLINE (2342H) takes. |
Disassembly
1E00H - The Entry, the Four Commands and MOVE's Three Arguments (1E00H-1E49H)
BASIC/OV2 is not a load module and it is not loaded by the DOS: the enhancement package of BASIC/CMD reads it off the disk itself and jumps into it. MORC at 8234H of that package clears every variable with CLEAR 447EH, puts every line reference back into its plain number form with NORMNUM 661EH, reads the 1376 bytes in as six whole sectors to 1E00H, records 01H in OVRLY$ 0069H so that a second extended command skips the load, and jumps to 1E00H with Register A holding the command token and Register Pair HL pointing at INBUF 7039H, where the line as it was typed still stands. The four tokens come from ABBTBL of NEWB/ASM, which CKABBR writes over the abbreviation letter in the line buffer: 05H for C, COPY; 02H for M, MOVE; 03H for S, SEARCH; and 04H for F, FIND. This entry separates COPY and MOVE and sends the other two to DOFIND 20C0H, which tells SEARCH from FIND by the token it keeps in DTYPE 21E9H. Nothing else can arrive: ABBR at 81CAH refuses a token of 06H or more, and CKABBR writes none below 02H. The first instruction of all is the one every exit depends on, SAVSTK 2352H taking the Stack Pointer as BASIC's own CLEAR left it, because none of the four commands returns to its caller: each of them ends by loading Register Pair HL with an address in BASIC/CMD, putting that stack back and jumping. MOVE takes three line numbers, the first and last of the block to move and the line to put it after, and reads them with the one routine at 1E4AH twice over and its second half once.
1E4AH - NXTLIN and NXTLIN1: a Number Read and its Line Found (1E4AH-1E63H)
One routine with two entries, and between them they do every check MOVE makes on an argument. The first entry reads a number and demands that the line be followed by more of the command, which is right for the first and second of the three; the second entry takes a number already in Register Pair DE and only refuses zero and finds the line, which is right for the third, after which the line must end. Both of them answer with Register Pair BC addressing the line that was found and Register Pair HL back on the place in the command line, and both of them jump to BADLIN 2346H rather than return when anything is wrong, which is why the stack SAVSTK 2352H holds is what puts the depth right.
1E64H - GOTLIN: the Insert Point, the Spare Numbers and the Lines Counted (1E64H-1ED1H)
MOVE renumbers the lines it moves, and this is where it works out whether there are numbers left to give them. The block keeps its order and its contents and gets new numbers running up from one past the number it is put after, so a block of four lines put after line 300 becomes 301, 302, 303 and 304. That can only be done when the line standing after line 300 carries a number far enough above it, and the count of numbers there is room for is what BLANKS 1EC3H holds. A zero in BLANKS means unlimited, which is the answer when the insert point is the end of the program, and 1E98H is the test that gives it: the link of the line after the insert point is 0000H. Then the lines of the block are counted by walking their links from STRTLIN 1EA7H to ENDLIN 1EAAH, and the count is refused when it stands above BLANKS. Three subtractions in this part run with no OR A in front of them and all three are safe, each having a logical operation two or three instructions above it that cleared the Carry Flag: 1E92H clears it for 1E9EH, 1EAFH for 1EB1H and 1EC6H for 1EC9H. The count goes into LTM 235AH at the end of it and nothing in the file ever reads LTM again.
1ED2H - The Memory Check, the Direction of the Shuffle and the Offset (1ED2H-1F1CH)
MOVE lifts the block right out of the program, shuffles what is left over the hole, and puts the block down again, so it needs somewhere to put the block while the shuffle runs. The place it uses is the free memory between LOPT 71A3H and HIPT 7178H, which is the gap between the top of the variables and the bottom of the string space, and the block has to fit in it: MORC called CLEAR 447EH before it entered this overlay, so that gap is the whole of the memory the program is not using. TOMOVE 235CH takes the length of the block in bytes. Then the direction is settled by one subtraction, STRTLIN 1EA7H less NEWLIN 235EH, and the Carry Flag it leaves is carried on the stack through the whole of the rest of MOVE, popped and pushed again at 1FEBH, 2004H, 206DH and 208EH and read for the last time at 209AH. Last comes OFFSET 1FCCH, which is what every line reference in the program has to be moved by: the distance from where a moved line stands now to where it will stand, which for a move up is the gap between the two places less the length of the block itself, because the lines above the hole come down by that much.
1F1DH - TIME2: the Line References Marked and Written Back, Run Twice (1F1DH-1FB9H)
This is the part of MOVE that makes it more than a block copy, and it is one walk of the whole program run twice over. The problem it solves is that the lines being moved are about to be renumbered, so every GOTO, GOSUB, ON ERROR GOTO, RESTORE and THEN in the program that names one of them has to be given its new number, and the new numbers are not known until the move is done. The answer is to turn each such reference into the address of the line it names, plus OFFSET 1FCCH so that it is the address the line will have once it has moved, and then after the move to turn every address back into the number the line now carries. The interpreter already keeps a line reference in two forms and that is what makes it possible: the 0EH token with the number after it as it was typed, and the 0DH token with the line's address after it, which is what a GOTO leaves behind once it has resolved one. So pass 1 writes 0DH and an address and pass 2 writes 0EH and a number, and DOPASS1 2355H is the flag that says which pass is running, nonzero for the first and 00H for the second. The flag is read at 1F36H in the middle of the walk rather than at the top, so the two passes are one body of code with one test. Pass 1 looks for the pair A8H 89H, ON ERROR GOTO, as well as for a bare 0EH, because an ON ERROR GOTO 0 may not be touched; pass 2 looks only for the 0DH it wrote. Neither pass takes any notice of a string literal or of REM text, which VARFIND at 212CH is careful to step over: the walk is safe only because the tokenizer leaves no 0EH or 0DH byte in either, a number in a string being stored as its characters.
1FBAH - RANGE: is a Line Number Inside the Block? (1FBAH-1FD2H)
Three callers and two answers. The Carry Flag clear says the number in Register Pair DE falls inside the block that is moving, from NUM1 2356H to NUM2 2358H with both ends counted, and in that case Register Pair BC comes back with OFFSET 1FCCH added to it, so that one call both tests the reference and works out where the line it names will stand. The Carry Flag set says the number is outside and leaves Register Pair BC alone. 1E68H uses it to refuse an insert point inside the block and 1F67H to decide whether a reference needs marking. Register Pair DE must come back untouched and so must Register Pair BC on the outside answer, which is why neither is used for the comparisons and why the equality case at 1FC7H skips the CCF rather than being folded into it.
1FD3H - PAS1DUN and the Block Moved: the Shuffle, the Pointers and the Numbers (1FD3H-20BFH)
The move itself, and it is done in four steps because nothing in the program text may be left pointing at where a line used to be. First the block is lifted out whole into the free memory at LOPT 71A3H, which leaves a hole. Then the lines between the hole and the insert point are shuffled over it, an LDIR for a move up and an LDDR for a move down, and the instruction that does it is written at run time: 2022H and 2023H hold ED and B0 in the file and 201BH stores B8 over the second byte for the LDDR. Then the block is walked where it lies in free memory, every line in it getting its new link and its new number, the numbers running up from one past NUM3 1E9CH. Then it is put down in its new place and the lines of the shuffled region get their links adjusted, up by TOMOVE 235CH for a move down and down by it for a move up. Last of all ADJ4 20B9H clears DOPASS1 2355H and jumps back to TIME2 1F1DH, so that the second pass of the reference walk turns every address it marked back into the number the line now carries. The JR NC at 2024H reads a Carry Flag the downward path works out again at 2013H rather than the one 2007H put on the stack, and the two agree only because STRTLIN 1EA7H and NEWLIN 235EH can never be equal: 1E7CH refuses a move that would put the block where it already stands.
20C0H - DOFIND and KEYFIND: SEARCH, FIND and a Keyword Looked For (20C0H-212BH)
SEARCH and FIND are one piece of code and the only difference between them is what happens when a match is found. SHOW 21E8H reads DTYPE 21E9H, which this entry fills with the command token: 03H, SEARCH, shows the whole line and stops there; 04H, FIND, writes the line's number and carries on, so that FIND lists every line that matches and SEARCH walks them one at a time. What is searched for is read out of the line buffer at LBUF+1 6EFAH and not out of INBUF 7039H, which is the one place this overlay prefers the tokenized form of the command line to the characters as they were typed, and it has to: a keyword stands in the program text as one byte, so it can only be looked for as the byte the tokenizer made of it. Five cells in the enhancement package's own area remember what was looked for, so that a bare S or F picks up where the last one stopped: LSTTYP$ 83DBH, LSTLIN$ 83DCH, LSTNUM$ 83DEH, LSTKEY$ 83E0H and the eleven bytes of LSTVAR$ 83E1H. The first character settles which of the three searches runs: a quotation mark is refused outright, a letter goes to VARFIND 212CH, a digit to NUMFIND 221EH, and anything from 3AH up to a token goes to KEYFIND. KEYFIND is also the only code in the whole of the Disk BASIC that uses the alternate accumulator: no row of BASIC/CMD's 21978 bytes decodes as EX AF,AF', and KEY2 2118H uses it to hold the result of one comparison while a second is made.
212CH - VARFIND: a Variable Name Looked For (212CH-21D9H)
The longest of the three searches and the only one that has to understand what it walks past. A keyword and a line reference are each one byte in the program text and can be compared outright, but a variable name is characters, and those characters also occur inside string literals, inside REM text and inside longer names, so this search steps over all three. The name typed after the command is collected into LSTVAR$ 83E1H a character at a time while VALID 229DH says the character belongs to a name, which gives it a length from one to ten that is kept in Register C for the whole of the search and copied back into Register B at the top of every line, and that length is also what LSTTYP$ 83DBH holds, so that AGAIN at 2288H can tell a variable search from a keyword search by whether the saved type is below 80H. A match has to be the whole name and nothing more: when the last character agrees, 218EH to 21A2H decide whether what follows could make it a longer name, and a name of the full ten characters is accepted at once because no name can be longer. 216DH to 2176H is the one piece of this file that the 6.3.1 build puts in and the 6.3.0 build leaves out: BMOVE/ASM has it inside an IF on the build switch, with a jump to a patch area in the other branch, and what it adds is that the apostrophe form of REM and a two byte function token are both stepped over.
21DAH - GTPTR, SHOW and NUMFIND: the Line Named and a Line Number Looked For (21DAH-2264H)
GTPTR is the one routine all three searches share and SHOW is where SEARCH and FIND part company. GTPTR reads a line's link, keeps it in NXTPO 2207H so that SHOW can leave the walk standing one byte before the next line, and answers with the Zero Flag set when the link is 0000H and the program has ended. SHOW reads DTYPE 21E9H: 03H goes to SHOLIN 2211H, which never returns, making the line found the current line and handing a full stop to NOBRK@ 80F4H, the key handler of the enhancement package, which is what lists a line at command level; 04H goes to SHONUM 21EEH, which does return, writing the line's number with NUMDSP 3139H and a comma and a space in front of every number after the first, which is what FTIME 21F1H is for. So SEARCH stops at its first match and a bare S picks the walk up again, while FIND writes the whole list in one line and 2268H refuses to repeat it. NUMFIND is the third search, and it looks for a line number in two ways at once: the first comparison of every line is against the line's own number, so FIND of a number names that line as well as every line that refers to it, and then NUMLP2 2253H walks the line for the 0EH token and compares each referenced number. The number being looked for is kept on the stack and not in a cell, and the two EX (SP),HL of 2241H and 2247H swap it with the place in the line, which is how one pair serves both.
2265H - AGAIN and VALID: the Search Repeated and a Character of a Name (2265H-22C4H)
AGAIN is what makes a bare S useful, and the five cells of the enhancement package's own area are the whole of how it works. LSTTYP$ 83DBH says what kind of search the last one was and the three kinds are told apart by its value: 0EH is a line number, anything from 80H up is a keyword token, and anything below that is the length of a variable name, which is why the collector at 212CH stores the length there and not a kind of its own. LSTLIN$ 83DCH says which line the last search stopped at, and FIND 5AB4H is called on it so that the walk can be picked up at the line after, which is why a SEARCH shows the matches one at a time and why 227CH gives Illegal function call when that line has since been deleted. A bare F is refused outright at 2268H: FIND writes every match in one go and there is nothing left to carry on from. VALID is the test the collector and the three places that step over a name all use, and it counts an opening parenthesis as part of a name, which is why a search for a subscripted array can be typed with the parenthesis and why 218EH has a case for a name that ends in one.
22C5H - COPY: One Line Copied to a New Number (22C5H-233FH)
COPY does not copy anything itself: it builds the text of the new line in INBUF 7039H and hands it to BASIC's own line entry at 5993H as though it had been typed. That is why the new line is entered exactly as a typed line would be, with the same checks and the same errors, and why 59AFH's test of FILEX 6E98H counts COPY as the keyboard. The line asked for is read with FIND 5AB4H, its tokenized text is moved into LBUF 6EFAH, UNTOKE 7A0DH turns it back into characters at INBUF, room for a five character line number is made in front of it with an LDDR, the new number is written into that room by @HEXDEC, and the whole line is shown on the display before it is entered. Two off by one steps cancel each other exactly. 2304H gives UNTOKE a pointer one byte below the text it copied, so the first character UNTOKE writes is the colon that 840AH of the enhancement package keeps at 6EF9H; and the length 2314H works out is one short of what UNTOKE wrote, so the LDDR at 2319H copies everything except that colon. The field @HEXDEC writes is five characters right justified with leading spaces and it writes no terminator, which is why the room made is five and the clearing loop blanks six: the sixth is the space between the number and the text. COPY ends by jumping out of the overlay for good, so the three ways it can fail all go to ILLEG 2340H.
2340H - The Four Exits and the Storage (2340H-235FH)
No command of this overlay ever returns to its caller, and these twelve bytes are why. Each of the four exits loads Register Pair HL with an address in BASIC/CMD, falls into EXIT1 2351H, which puts the Stack Pointer back from SAVSTK 2352H as the first instruction of the overlay left it, and jumps through Register Pair HL. The three 0DDH bytes at 2345H, 2349H and 234DH are what makes the chain work: entered at one of the labels, the LD HL takes the address wanted and the 0DDH below it turns the next LD HL,nn into an LD IX,nn, so Register Pair HL is carried through the exits beneath it untouched. Executed from 2342H the real instruction sequence is LD HL,80F4H, LD IX,5F95H, LD IX,425CH, LD IX,5920H, which is one address taken and three thrown into a register nothing reads. The four addresses are NOBRK@ 80F4H, the key handler of the enhancement package, which lists a line; FUNCERR 5F95H, error 5, Illegal function call; OMERR 425CH, error 7, Out of memory; and READY 5920H, which simply prints the prompt. The eleven bytes of storage above them are the whole of what BASIC/OV2 keeps, and they stand at 2355H to 235FH inside what B296 writes over: MORC reads six whole sectors for a file of 1376 bytes, so 2360H to 23FFH takes 160 bytes of whatever followed the file on the diskette, and that region is also LOWBUF$ 2300H, the resident system's low memory disk buffer, whose top 160 bytes this overlay does not occupy.