| Routines

06539: THE 'FIND EACH STATEMENT' SUBROUTINE

Used by the routines at NEXT_LINE, LOOK_PROG, PASS_BY and S_FN_SBRN. This subroutine has two distinct functions. It can be used to find the Dth statement in a BASIC line - returning with the HL register pair addressing the location before the start of the statement and the zero flag set. Also the subroutine can be used to find a statement, if any, that starts with a given token code (in the E register).
Input
D | Statement number to look for (or 0 if looking for a token code)
E | Token code to look for (or 0 if looking for a statement)
HL | Address of the next character to consider
Output
HL | Address of the token code or first character in the statement (if found)
F | Carry flag reset if the token code is found
F | Zero flag set if the statement is found
EACH_STMT | 06539 | LD (23645),HL | Set CH-ADD to the current byte.
| 06542 | LD C,0 | Set a 'quotes off' flag.
Enter a loop to handle each statement in the BASIC line.
EACH_S_1 | 06544 | DEC D | Decrease D and return if the required statement has been found.
| 06545 | RET Z
| 06546 | RST 32 | Fetch the next character code and jump if it does not match the given token code.
| 06547 | CP E
| 06548 | JR NZ,EACH_S_3
| 06550 | AND A | But should it match then return with the carry and the zero flags both reset.
| 06551 | RET
Now enter another loop to consider the individual characters in the line to find where the statement ends.
EACH_S_2 | 06552 | INC HL | Update the pointer and fetch the new code.
| 06553 | LD A,(HL)
EACH_S_3 | 06554 | CALL NUMBER | Step over any number.
| 06557 | LD (23645),HL | Update CH-ADD.
| 06560 | CP "\"" | Jump forward if the character is not a '"'.
| 06562 | JR NZ,EACH_S_4
| 06564 | DEC C | Otherwise set the 'quotes flag'.
EACH_S_4 | 06565 | CP ":" | Jump forward if the character is a ':'.
| 06567 | JR Z,EACH_S_5
| 06569 | CP 203 | Jump forward unless the code is the token 'THEN'.
| 06571 | JR NZ,EACH_S_6
EACH_S_5 | 06573 | BIT 0,C | Read the 'quotes flag' and jump back at the end of each statement (including after 'THEN').
| 06575 | JR Z,EACH_S_1
EACH_S_6 | 06577 | CP 13 | Jump back unless at the end of a BASIC line.
| 06579 | JR NZ,EACH_S_2
| 06581 | DEC D | Decrease the statement counter and set the carry flag before returning.
| 06582 | SCF
| 06583 | RET