Prev: 44137 Up: Map Next: 44159
44140: 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 44140 OR A Return if A is zero.
44141 RET Z
44142 PUSH BC Stash BC and DE on the stack.
44143 PUSH DE
E now holds the ID we want to find the memory location for. This is used as a "countdown".
44144 LD E,A E=A.
All data is terminated by 255 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.
44145 LD A,255 A=255.
Set the counter to 65536.
44147 LD BC,0 BC=0000.
FindDataById_Loop 44150 CPIR Search for the first occurrence of 255 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.
44152 DEC E Decrease E by one.
44153 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.
44156 POP DE Restore DE and BC from the stack.
44157 POP BC
44158 RET Return.
Prev: 44137 Up: Map Next: 44159