Prev: 8A80 Up: Map Next: 8AB6
8A91: The direction from one cell towards another
Used by the routines at MOVE_ANT and FOLLOW_PLAYER.
Straight along the axis if they share a row or column; otherwise one of the two directions that close the gap, chosen by the signs.
Input
HL From
DE Towards
Output
A A direction for STEP (only the low two bits count)
DIRECTION_TO 8A91 LD A,H
8A92 SUB D
8A93 JR Z,DIRECTION_TO_1
8A95 RLCA
8A96 AND $01
8A98 LD B,A
8A99 LD A,L
8A9A SUB E
8A9B JR Z,DIRECTION_TO_0
8A9D RLCA
8A9E AND $01
8AA0 XOR B
8AA1 RLC B
8AA3 OR B
8AA4 CPL
8AA5 RET
DIRECTION_TO_0 8AA6 LD A,B
8AA7 RLCA
8AA8 XOR $02
8AAA RET
DIRECTION_TO_1 8AAB LD A,L
8AAC SUB E
8AAD JP P,DIRECTION_TO_2
8AB0 LD A,$01
8AB2 RET
DIRECTION_TO_2 8AB3 LD A,$03
8AB5 RET
Prev: 8A80 Up: Map Next: 8AB6