Prev: 27693 Up: Map Next: 27798
27778: Get Map Distance
Used by the routine at UpdateCurrentObject.
Finds the distance between the first co-ordinate of the player's map position at PlayerMapPosition and the value in DE. The carry flag is set when the distance is less than 96.
Input
DE Map position
Output
HL Distance
F The carry flag is set when the distance is less than 96
GetMapDistance 27778 LD HL,(24069) Fetch the player's X position on the map (PlayerMapPosition).
27781 AND A HL=HL - DE.
27782 SBC HL,DE
27784 JR NC,GetMapDistance_Compare Jump to GetMapDistance_Compare if there was no carry.
27786 CALL NegateHL Call NegateHL.
GetMapDistance_Compare 27789 PUSH HL Stash HL on the stack.
27790 LD DE,96 Set the furthest distance in view, 0096.
27793 AND A Compare the distance with the furthest distance in view.
27794 SBC HL,DE
27796 POP HL Restore HL from the stack.
27797 RET Return.
Prev: 27693 Up: Map Next: 27798