Prev: 27410 Up: Map Next: 27458
27435: Scale Value
Used by the routine at CollisionCup.
Converts a map position held in a single byte into map units, by shifting D right through E so that DE is D * 256 shifted right by a fixed number of bits. ScaleValue multiplies by 64 ScaleValue_DivideByEight multiplies by 32 (used for the X position of a map point) and ScaleValue_DivideBySixteen multiplies by 16 (used for the Y position of a map point).
Input
D Value to scale
Output
DE Scaled value
ScaleValue 27435 PUSH BC Stash BC on the stack.
27436 LD B,2 Set the shift counter to 2.
27438 JR ScaleValue_Shift Jump to ScaleValue_Shift.
This entry point is used by the routines at CollisionCup, DrawObjects, FindFirstObject and UpdateCurrentObject.
Multiply by 32.
ScaleValue_DivideByEight 27440 PUSH BC Stash BC on the stack.
27441 LD B,3 Set the shift counter to 3.
ScaleValue_Shift 27443 LD E,0 Clear the low byte of the scaled value.
ScaleValue_Loop 27445 SRL D Shift D right, moving bit 0 into the carry flag.
27447 RR E Rotate the carry flag into E.
27449 DJNZ ScaleValue_Loop Decrease the shift counter by one and loop back to ScaleValue_Loop until all of the shifts have been done.
27451 POP BC Restore BC from the stack.
27452 RET Return.
This entry point is used by the routine at DrawObjects.
Multiply by 16.
ScaleValue_DivideBySixteen 27453 PUSH BC Stash BC on the stack.
27454 LD B,4 Set the shift counter to 4.
27456 JR ScaleValue_Shift Jump to ScaleValue_Shift.
Prev: 27410 Up: Map Next: 27458