Prev: 53171 Up: Map Next: 53309
53194: Load A with value indicating which direction room A lies relative to room in state data at IX
Direction index value in A denotes which direction (left or right), e.g. Drutt, has to travel to reach the target room:
Value Meaning
0 neither (target room cannot be reached by going left or right)
1 right
2 left
Used by the routine at 51779.
Input
A Target room index (e.g. Berk's room or worm's room)
IX Address of complex state data (current level) for Drutt
Output
A Direction index
53194 PUSH HL Store HL
53195 PUSH IX Store IX
53197 LD E,A Load E with target room index
53198 LD A,(IX+0) Load D with Drutt's current room...
53201 LD D,A ...
53202 LD HL,53159 Set first two bytes of header to 255 (start marker)...
53205 LD (HL),255 ...
53207 INC HL ...
53208 LD (HL),255 ...
53210 INC HL Set third byte of header to index of Drutt's current room...
53211 LD (HL),A ...
53212 INC HL Advance HL to first byte of first entry
53213 CALL 54542 Load B with index of room to left of Drutt's current room...
53216 JR Z,53228 ...and if there is no such room then skip ahead to 53228
53218 LD A,E If room to left of Drutt's current room is the target room...
53219 CP B ...then set zero flag
53220 LD A,2 Load A with 2 ("go left")
53222 JP Z,53336 If zero flag is set (room to left is target room) then restore registers and return
53225 CALL 53309 Add entry to pathfinding data table stating room to left of Drutt is to the left
53228 CALL 54508 Load B with index of room to right of Drutt's room...
53231 JR Z,53243 ...and if there is no such room then skip ahead to 53243
53233 LD A,E If room to right of Drutt's current room is the target room...
53234 CP B ...then set zero flag
53235 LD A,1 Load A with 1 ("go right")
53237 JP Z,53336 If zero flag is set (room to right is target room) then restore registers and return
53240 CALL 53309 Add entry to pathfinding data table stating room to right of Drutt is to the right
Now the pathfinding data table has a header and zero, one or two records, depending upon the horizontal connectivity of Drutt's current room.
53243 LD IX,53162 Load IX with address of first entry in pathfinding data table
53247 LD D,(IX+1) Load D with index of room from current entry in pathfinding data table
53250 CALL 54542 Load B with index of room to left of room D...
53253 JR Z,53271 ...and if there is no such room then skip ahead to 53271
53255 LD A,E If room to left of room D is the target room...
53256 CP B ...
53257 JP Z,53333 ...then load A with direction index for room D, restore registers and return
53260 CALL 53317 If room B already has an entry in pathfinding data table...
53263 JR Z,53271 ...then skip ahead to 53271
53265 LD A,(IX+0) Load A with current entry's direction index (room B must lie in same direction as room D)
53268 CALL 53309 Add entry to pathfinding data table for room B lying in direction A
53271 CALL 54508 Load B with index of room to right of room D...
53274 JR Z,53292 ...and if there is no such room then skip ahead to 53292
53276 LD A,E If room to right of room D is the target room...
53277 CP B ...
53278 JP Z,53333 ...then load A with direction index for room D, restore registers and return
53281 CALL 53317 If room B already has an entry in pathfinding data table...
53284 JR Z,53292 ...then skip ahead to 53292
53286 LD A,(IX+0) Load A with current entry's direction index (room B must lie in same direction as room D)
53289 CALL 53309 Add entry to pathfinding data table for room B lying in direction A
53292 INC IX Advance IX by two bytes to next entry in pathfinding data table...
53294 INC IX ...
53296 LD A,(IX+0) If byte at this location is not 255 (end marker)...
53299 CP 255 ...
53301 JP NZ,53247 ...then loop back to 53247
At this point, the search has checked all rooms and not found the target room.
53304 POP IX Restore IX
53306 POP HL Restore HL
53307 XOR A Set A to zero
53308 RET Return
Prev: 53171 Up: Map Next: 53309