![]() |
Routines |
| Prev: 27660 | Up: Map | Next: 27731 |
|
Used by the routines at Handler_RedBird, UpdateRedBirdMovement, Handle_Butterfly, Randomise_Butterfly_Position, Randomise_Car_Position, InitialiseCar, CheckCarEggCollision, Handler_CarType2 and Handler_CarType3.
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.
|
||||||||
| GenerateRandomNumber | 27705 | LD A,(27831) | H=*RedBirdAnimationSeed. | |||||
| 27708 | LD H,A | |||||||
| 27709 | LD L,0 | Load both L and D with 0. | ||||||
| 27711 | LD D,L | |||||||
| 27712 | LD E,H | Copy *RedBirdAnimationSeed into E. | ||||||
|
HL = seed × 256 DE = seed. Subtract DE twice.
|
||||||||
| 27713 | AND A | Clear carry. | ||||||
| 27714 | SBC HL,DE | HL-=DE. | ||||||
| 27716 | SBC HL,DE | HL-=DE. | ||||||
| 27718 | LD DE,254 | HL+=0254. | ||||||
| 27721 | ADD HL,DE | |||||||
|
Combine the high and low bytes.
|
||||||||
| 27722 | LD A,L | A=L. | ||||||
| 27723 | SUB H | A-=H. | ||||||
| 27724 | JR C,GenerateRandomNumber_Store | Jump to GenerateRandomNumber_Store if carry set. | ||||||
| 27726 | DEC A | Decrement A. | ||||||
| GenerateRandomNumber_Store | 27727 | LD (27831),A | Write the new seed to *RedBirdAnimationSeed. | |||||
| 27730 | RET | Return. | ||||||
| Prev: 27660 | Up: Map | Next: 27731 |