Prev: 198B Up: Map Next: 19DD
19B8: THE 'NEXT-ONE' SUBROUTINE
Used by the routines at ME_CONTRL, ME_ENTER, MAIN_ADD, AUTO_LIST, LINE_ADDR, LOOK_VARS and DIM.
This subroutine can be used to find the 'next line' in the program area or the 'next variable' in the variables area. The subroutine caters for the six different types of variable that are used in the Spectrum system.
Input
HL Start address of the current line or variable
Output
BC Length of the current line or variable
DE Start address of the next line or variable
HL Start address of the current line or variable (as on entry)
NEXT_ONE 19B8 PUSH HL Save the address of the current line or variable.
19B9 LD A,(HL) Fetch the first byte.
19BA CP $40 Jump forward if searching for a 'next line'.
19BC JR C,NEXT_O_3
19BE BIT 5,A Jump forward if searching for the next string or array variable.
19C0 JR Z,NEXT_O_4
19C2 ADD A,A Jump forward with simple numeric and FOR-NEXT variables.
19C3 JP M,NEXT_O_1
19C6 CCF Long name numeric variables only.
NEXT_O_1 19C7 LD BC,$0005 A numeric variable will occupy five locations but a FOR-NEXT control variable will need eighteen locations.
19CA JR NC,NEXT_O_2
19CC LD C,$12
NEXT_O_2 19CE RLA The carry flag becomes reset for long named variables only, until the final character of the long name is reached.
19CF INC HL Increment the pointer and fetch the new code.
19D0 LD A,(HL)
19D1 JR NC,NEXT_O_2 Jump back unless the previous code was the last code of the variable's name.
19D3 JR NEXT_O_5 Now jump forward (BC=+0005 or +0012).
NEXT_O_3 19D5 INC HL Step past the low byte of the line number.
NEXT_O_4 19D6 INC HL Now point to the low byte of the length.
19D7 LD C,(HL) Fetch the length into the BC register pair.
19D8 INC HL
19D9 LD B,(HL)
19DA INC HL Allow for the inclusive byte.
In all cases the address of the 'next' line or variable is found.
NEXT_O_5 19DB ADD HL,BC Point to the first byte of the 'next' line or variable.
19DC POP DE Fetch the address of the previous one and continue into DIFFER.
Prev: 198B Up: Map Next: 19DD