Prev: 6B12 Up: Map Next: 6B42
6B2B: 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 * 0100 shifted right by a fixed number of bits. ScaleValue multiplies by 40 ScaleValue_DivideByEight multiplies by 20 (used for the X position of a map point) and ScaleValue_DivideBySixteen multiplies by 10 (used for the Y position of a map point).
Input
D Value to scale
Output
DE Scaled value
ScaleValue 6B2B PUSH BC Stash BC on the stack.
6B2C LD B,$02 Set the shift counter to 02.
6B2E JR ScaleValue_Shift Jump to ScaleValue_Shift.
This entry point is used by the routines at CollisionCup, DrawObjects, FindFirstObject and UpdateCurrentObject.
Multiply by 20.
ScaleValue_DivideByEight 6B30 PUSH BC Stash BC on the stack.
6B31 LD B,$03 Set the shift counter to 03.
ScaleValue_Shift 6B33 LD E,$00 Clear the low byte of the scaled value.
ScaleValue_Loop 6B35 SRL D Shift D right, moving bit 0 into the carry flag.
6B37 RR E Rotate the carry flag into E.
6B39 DJNZ ScaleValue_Loop Decrease the shift counter by one and loop back to ScaleValue_Loop until all of the shifts have been done.
6B3B POP BC Restore BC from the stack.
6B3C RET Return.
This entry point is used by the routine at DrawObjects.
Multiply by 10.
ScaleValue_DivideBySixteen 6B3D PUSH BC Stash BC on the stack.
6B3E LD B,$04 Set the shift counter to 04.
6B40 JR ScaleValue_Shift Jump to ScaleValue_Shift.
Prev: 6B12 Up: Map Next: 6B42