Prev: 6C0C Up: Map Next: 6C53
6C39: Generate Random Number
Generates a pseudo-random number using the seed stored at *RedBirdAnimationSeed. The algorithm scrambles the seed value through a series of arithmetic operations and stores the result back as the new seed. Returns the random value in A.
Output
A Pseudo-random value
GenerateRandomNumber 6C39 LD A,($6CB7) H=*RedBirdAnimationSeed.
6C3C LD H,A
6C3D LD L,$00 Load both L and D with 00.
6C3F LD D,L
6C40 LD E,H Copy *RedBirdAnimationSeed into E.
HL = seed × 0100 DE = seed. Subtract DE twice.
6C41 AND A Clear carry.
6C42 SBC HL,DE HL-=DE.
6C44 SBC HL,DE HL-=DE.
6C46 LD DE,$00FE HL+=00FE.
6C49 ADD HL,DE
Combine the high and low bytes.
6C4A LD A,L A=L.
6C4B SUB H A-=H.
6C4C JR C,GenerateRandomNumber_Store Jump to GenerateRandomNumber_Store if carry set.
6C4E DEC A Decrement A.
GenerateRandomNumber_Store 6C4F LD ($6CB7),A Write the new seed to *RedBirdAnimationSeed.
6C52 RET Return.
Prev: 6C0C Up: Map Next: 6C53