| Routines

196E: THE 'LINE-ADDR' SUBROUTINE

Used by the routines at ED_EDIT, ED_UP, MAIN_ADD, AUTO_LIST, LIST, LN_FETCH, LINE_NEW and RESTORE. For a given line number, in the HL register pair, this subroutine returns the starting address of that line or the 'first line after', in the HL register pair, and the start of the previous line in the DE register pair. If the line number is being used the zero flag will be set. However if the 'first line after' is substituted then the zero flag is returned reset.
Input
HL | Target line number
Output
DE | Start address of the line before the target
HL | Start address of the target line (if found) or the first line after
F | Zero flag set if the target line was found
LINE_ADDR | 196E | PUSH HL | Save the given line number.
| 196F | LD HL,($5C53) | Fetch the system variable PROG and transfer the address to the DE register pair.
| 1972 | LD D,H
| 1973 | LD E,L
Now enter a loop to test the line number of each line of the program against the given line number until the line number is matched or exceeded.
LINE_AD_1 | 1974 | POP BC | The given line number.
| 1975 | CALL CP_LINES | Compare the given line number against the addressed line number
| 1978 | RET NC | Return if carry reset; otherwise address the next line's number.
| 1979 | PUSH BC
| 197A | CALL NEXT_ONE
| 197D | EX DE,HL | Switch the pointers and jump back to consider the next line of the program.
| 197E | JR LINE_AD_1