Prev: 49910 Up: Map Next: 49967
49945: Get Facing Direction
Used by the routines at HandleTurning and SetPlayerSpeed.
Works out the direction that an object is facing from the horizontal flip flag and bit 2 of the sprite number: bit 6 of the flags of the object is made into bit 1 of the direction, and bit 2 of the sprite number into bit 0. The direction is 0 west, 1 east, 2 north and 3 south.
Input
IX The address of the object
Output
A The direction
Bit 6 of the flags to bit 1.
GetFacingDirection 49945 PUSH HL Stash HL on the stack.
49946 LD A,(IX+7) Fetch the flags of the object.
49949 RRCA Rotate bit 6 into bit 3.
49950 RRCA
49951 RRCA
49952 AND %00001000 Keep only bit 3.
49954 LD L,A Copy it to L.
Bit 2 of the sprite to bit 0.
49955 LD A,(IX+0) Fetch the sprite number of the object.
49958 AND %00000100 Keep only bit 2.
49960 OR L Merge L.
49961 RRCA Rotate the two bits into place.
49962 RRCA
49963 AND %00000011 Keep only bits 0 and 1.
49965 POP HL Restore HL from the stack.
49966 RET Return.
View the equivalent code in;
Prev: 49910 Up: Map Next: 49967