Prev: 9E1F Up: Map Next: 9E6E
9E51: Find a usable exit in a direction
Searches the exits of the actor's room for one in direction A that has a destination. Returns the direction in A, or $FF (Z set) if there is none.
9E51 PUSH BC Save the caller's BC and IY
9E52 PUSH IY
9E54 LD B,A B = the direction we are looking for
9E55 CALL $9DDE IX = the start of the actor's room's exits
9E58 CALL $9AEE Look at the next exit; A = its direction, Z set once there are no more
9E5B JR Z,$9E6A No more exits: give up (A is left holding $FF)
9E5D LD A,(IX+$02) Does this exit actually lead anywhere?
9E60 AND A
9E61 JR Z,$9E58 No destination (a dead end): skip it and keep looking
9E63 LD A,(IX+$00) A = this exit's direction
9E66 CP B Is it the one we want?
9E67 JP NZ,$9E58 No: try the next exit
9E6A POP IY Found it (or ran out): restore the caller's IY and BC
9E6C POP BC
9E6D RET
Prev: 9E1F Up: Map Next: 9E6E