Prev: DDCF Up: Map Next: DE0D
DDFC: A random step from the bits of a byte
Used by the routine at WANDER_STEP.
Two for each 0 among the low B bits of C, negative if the next bit is 0: a step of 0 to twice B either way, those near B likeliest, as the count of zeros among B random bits is.
Input
B The number of bits
C Random bits
Output
A The step
RANDOM_STEP DDFC PUSH BC A=0
DDFD XOR A
RANDOM_STEP_0 DDFE RR C Two for each 0 bit
DE00 JR C,RANDOM_STEP_1
DE02 ADD A,$02
RANDOM_STEP_1 DE04 DJNZ RANDOM_STEP_0
DE06 RR C The next bit: 1 positive, 0 negative
DE08 POP BC
DE09 RET C
DE0A NEG
DE0C RET
Prev: DDCF Up: Map Next: DE0D