Prev: 8358 Up: Map Next: 8379
8360: Step the random number generator
Used by the routines at MOVE_ANT and NOISE.
A 32-bit shift register at RANDOM_BITS, big-endian, fed back from two bits of its first byte. The carry out is the random bit, and MOVE_ANT uses it to pick which way an ant turns. NOISE takes bit 4 of A instead, which after the rotations is bit 2 of the first byte, before the shift, XOR the carry the routine was entered with -- always clear there. (Checked in a simulator for every first byte and both carries.)
Output
A Bit 4 another random bit
F Carry the random bit
RANDOM 8360 LD HL,RANDOM_BITS The feedback bit into the carry.
8363 LD A,(HL)
8364 RLA
8365 RLA
8366 RLA
8367 XOR (HL)
8368 RLA
8369 RLA
836A LD HL,RANDOM_LOW Shift all 32 bits left, feeding it in at the bottom.
836D RL (HL)
836F DEC HL
8370 RL (HL)
8372 DEC HL
8373 RL (HL)
8375 DEC HL
8376 RL (HL)
8378 RET
Prev: 8358 Up: Map Next: 8379