Prev: D0F0 Up: Map Next: D1BF
D1A8: Advance RNG Seed
Advances the linear congruential generator one step. The seed at RNG_Seed is updated using the recurrence seed = seed × 21 + 29 (multiply by 33, add 41), producing the next pseudo-random value. Called by Generate_Random_Byte to generate each random byte during enemy spawning.
Advance_RNG_Seed D1A8 LD HL,($C4DC) Load the current RNG seed from RNG_Seed.
D1AB PUSH BC Stash BC on the stack.
D1AC ADD HL,HL Multiply the seed by 20 by shifting left five times.
D1AD ADD HL,HL
D1AE ADD HL,HL
D1AF ADD HL,HL
D1B0 ADD HL,HL
D1B1 LD BC,($C4DC) Reload the original seed into BC and add it (total factor: 21).
D1B5 ADD HL,BC
D1B6 LD BC,$0029 Add 0029 and store the new seed back to RNG_Seed.
D1B9 ADD HL,BC
D1BA LD ($C4DC),HL
D1BD POP BC Restore BC and return.
D1BE RET
Prev: D0F0 Up: Map Next: D1BF