![]() |
Routines |
| Prev: 24474 | Up: Map | Next: 24515 |
|
Used by the routines at CreateSpawnedEntity, CreateRandomCreature, UpdatePickupEntity and UpdateScreen.
Makes a pseudo-random number by mixing the byte at a moving address in the game memory into a seed. The address moves on by one byte each time and wraps within 32768-40959.
|
||||||||||
| GetRandomNumber | 24478 | LD DE,(24474) | Fetch the seed. | |||||||
| 24482 | LD HL,(24476) | Fetch the address of the byte of game memory to mix in. | ||||||||
|
Make the new low byte.
|
||||||||||
| 24485 | LD A,(HL) | Fetch the byte of game memory. | ||||||||
| 24486 | ADD A,5 | Add 5 to it. | ||||||||
| 24488 | LD B,A | Store the result in B. | ||||||||
| 24489 | LD A,(23774) | Fetch the game variable at GameVariable. | ||||||||
| 24492 | ADD A,B | Add the byte from game memory. | ||||||||
| 24493 | ADD A,E | Add the low byte of the seed. | ||||||||
| 24494 | LD E,A | Make it the new low byte of the seed. | ||||||||
|
Make the new high byte.
|
||||||||||
| 24495 | LD A,(HL) | Fetch the byte of game memory again. | ||||||||
| 24496 | CPL | Invert it. | ||||||||
| 24497 | ADD A,22 | Add 22. | ||||||||
| 24499 | ADD A,D | Add the high byte of the seed. | ||||||||
| 24500 | ADD A,L | Add the low byte of the address. | ||||||||
| 24501 | LD D,A | Make it the new high byte of the seed. | ||||||||
| 24502 | LD (24474),DE | Store the new seed. | ||||||||
|
Move the address on.
|
||||||||||
| 24506 | INC HL | Move onto the next byte of game memory. | ||||||||
| 24507 | LD A,H | Fetch the high byte of the address. | ||||||||
| 24508 | AND %10011111 | Keep the address within 32768-40959. | ||||||||
| 24510 | LD H,A | Put the high byte back. | ||||||||
| 24511 | LD (24476),HL | Store the address. | ||||||||
| 24514 | RET | Return. | ||||||||
| Prev: 24474 | Up: Map | Next: 24515 |