Prev: DDCF Up: Map Next: DE0D
DDFC: 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 DDFC PUSH BC Keep the registers, and start with a velocity of zero.
DDFD XOR A
ChooseVelocity_Loop DDFE RR C Test the next bit of the random number, and jump to ChooseVelocity_Next if it is set.
DE00 JR C,ChooseVelocity_Next
DE02 ADD A,$02 Add two to the velocity.
ChooseVelocity_Next DE04 DJNZ ChooseVelocity_Loop Loop back until all the bits have been used.
DE06 RR C Test the next bit for the sign, restore the registers and return if it is set.
DE08 POP BC
DE09 RET C
DE0A NEG Make the velocity negative and return.
DE0C RET
Prev: DDCF Up: Map Next: DE0D