Prev: 56783 Up: Map Next: 56845
56828: Choose Velocity
Used by the routine at ChooseRandomVelocity.
Makes a random velocity from a random number. The velocity is two for each of the bits that are not set in the lowest bits of the number, and it is negative if the next bit is not set.
Input
B Number of bits to use
C Random number
Output
A Velocity
ChooseVelocity 56828 PUSH BC Keep the registers, and start with a velocity of zero.
56829 XOR A
ChooseVelocity_Loop 56830 RR C Test the next bit of the random number, and jump to ChooseVelocity_Next if it is set.
56832 JR C,ChooseVelocity_Next
56834 ADD A,2 Add two to the velocity.
ChooseVelocity_Next 56836 DJNZ ChooseVelocity_Loop Loop back until all the bits have been used.
56838 RR C Test the next bit for the sign, restore the registers and return if it is set.
56840 POP BC
56841 RET C
56842 NEG Make the velocity negative and return.
56844 RET
Prev: 56783 Up: Map Next: 56845