Prev: 51400 Up: Map Next: 51472
51447: Add Speed To Position
Used by the routine at HandleBag.
Adds a signed speed to a position. The speed is multiplied by 16 so the high byte of the position is the pixel and the low byte is a fraction of a pixel.
Input
E The speed
HL The position
Output
HL The new position
Sign-extend the speed into DE.
AddSpeedToPosition 51447 XOR A Clear A.
51448 BIT 7,E Jump to AddSpeedToPosition_Multiply if the speed is not negative.
51450 JR Z,AddSpeedToPosition_Multiply
51452 CPL Set A to 255.
Multiply the speed by 16 and add it.
AddSpeedToPosition_Multiply 51453 LD D,A Put the high byte in D.
51454 SLA E Multiply the speed by 16.
51456 RL D
51458 SLA E
51460 RL D
51462 SLA E
51464 RL D
51466 SLA E
51468 RL D
51470 ADD HL,DE Add it to the position and return.
51471 RET
Prev: 51400 Up: Map Next: 51472