Prev: 7928 Up: Map Next: 794A
7930: Generate Random Number
Generates a pseudo-random number using a linear decay formula. Reads the current seed from RandomSeed, computes (seed + 01) * FE then derives the new seed from the difference of the low and high bytes of the result. Returns the new value in A.
Output
A Pseudo-random value
Generate_Random_Number 7930 LD A,($7AC7) Fetch the current random seed from *RandomSeed.
7933 LD H,A Set HL to seed * 0100 and copy into DE.
7934 LD L,$00
7936 LD D,L
7937 LD E,H
7938 AND A Subtract DE twice from HL (i.e. HL = seed * FE).
7939 SBC HL,DE
793B SBC HL,DE
793D LD DE,$00FE Add FE to HL.
7940 ADD HL,DE
7941 LD A,L Subtract H from L; if no borrow occurred, decrement the result by one.
7942 SUB H
7943 JR C,Store_Random_Seed
7945 DEC A
Store_Random_Seed 7946 LD ($7AC7),A Write the new random seed to *RandomSeed.
7949 RET Return.
Prev: 7928 Up: Map Next: 794A