Prev: 06539 Up: Map Next: 06621
06584: 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 06584 PUSH HL Save the address of the current line or variable.
06585 LD A,(HL) Fetch the first byte.
06586 CP 64 Jump forward if searching for a 'next line'.
06588 JR C,NEXT_O_3
06590 BIT 5,A Jump forward if searching for the next string or array variable.
06592 JR Z,NEXT_O_4
06594 ADD A,A Jump forward with simple numeric and FOR-NEXT variables.
06595 JP M,NEXT_O_1
06598 CCF Long name numeric variables only.
NEXT_O_1 06599 LD BC,5 A numeric variable will occupy five locations but a FOR-NEXT control variable will need eighteen locations.
06602 JR NC,NEXT_O_2
06604 LD C,18
NEXT_O_2 06606 RLA The carry flag becomes reset for long named variables only, until the final character of the long name is reached.
06607 INC HL Increment the pointer and fetch the new code.
06608 LD A,(HL)
06609 JR NC,NEXT_O_2 Jump back unless the previous code was the last code of the variable's name.
06611 JR NEXT_O_5 Now jump forward (BC=5 or 18).
NEXT_O_3 06613 INC HL Step past the low byte of the line number.
NEXT_O_4 06614 INC HL Now point to the low byte of the length.
06615 LD C,(HL) Fetch the length into the BC register pair.
06616 INC HL
06617 LD B,(HL)
06618 INC HL Allow for the inclusive byte.
In all cases the address of the 'next' line or variable is found.
NEXT_O_5 06619 ADD HL,BC Point to the first byte of the 'next' line or variable.
06620 POP DE Fetch the address of the previous one and continue into DIFFER.
Prev: 06539 Up: Map Next: 06621