Prev: AC69 Up: Map Next: AC7F
AC6C: Find Data By ID
Input
A ID of data to find
HL Pointer to data for searching
Output
HL Pointer to data correlating to the ID
If A is zero, just return instantly.
FindDataById AC6C OR A Return if A is zero.
AC6D RET Z
AC6E PUSH BC Stash BC and DE on the stack.
AC6F PUSH DE
E now holds the ID we want to find the memory location for. This is used as a "countdown".
AC70 LD E,A E=A.
All data is terminated by FF so essentially we're going to count how many terminators we find. This will give us the start address of the data ID we're interested in.
AC71 LD A,$FF A=FF.
Set the counter to 10000.
AC73 LD BC,$0000 BC=0000.
FindDataById_Loop AC76 CPIR Search for the first occurrence of FF using *HL.
Move onto the next ID, and keep looping back to FindDataById_Loop until we're on the ID we want to find the data for.
AC78 DEC E Decrease E by one.
AC79 JP NZ,FindDataById_Loop Jump to FindDataById_Loop until E is zero.
Once we're here, HL will contain the start address of the data correlating to the given ID.
AC7C POP DE Restore DE and BC from the stack.
AC7D POP BC
AC7E RET Return.
Prev: AC69 Up: Map Next: AC7F