![]() |
Routines |
| Prev: 31016 | Up: Map | Next: 31050 |
|
Used by the routines at Handler_Helicopter, Randomise_Position_Loop, Animate_Stunned_Hazard, Handler_UFO and Handler_Balloon.
Generates a pseudo-random number using a linear decay formula. Reads the current seed from RandomSeed, computes (seed + 1) * 254 then derives the new seed from the difference of the low and high bytes of the result. Returns the new value in A.
|
||||||||
| Generate_Random_Number | 31024 | LD A,(31431) | Fetch the current random seed from *RandomSeed. | |||||
| 31027 | LD H,A | Set HL to seed * 256 and copy into DE. | ||||||
| 31028 | LD L,0 | |||||||
| 31030 | LD D,L | |||||||
| 31031 | LD E,H | |||||||
| 31032 | AND A | Subtract DE twice from HL (i.e. HL = seed * 254). | ||||||
| 31033 | SBC HL,DE | |||||||
| 31035 | SBC HL,DE | |||||||
| 31037 | LD DE,254 | Add 254 to HL. | ||||||
| 31040 | ADD HL,DE | |||||||
| 31041 | LD A,L | Subtract H from L; if no borrow occurred, decrement the result by one. | ||||||
| 31042 | SUB H | |||||||
| 31043 | JR C,Store_Random_Seed | |||||||
| 31045 | DEC A | |||||||
| Store_Random_Seed | 31046 | LD (31431),A | Write the new random seed to *RandomSeed. | |||||
| 31049 | RET | Return. | ||||||
| Prev: 31016 | Up: Map | Next: 31050 |