![]() |
Routines |
| Prev: 8566 | Up: Map | Next: 85B2 |
|
Used by the routine at SpawnCreature.
Chooses a random position along one axis of the room. A random number is reduced to less than the size of the room less 08 and then it is either added to or taken away from 60. This is used by SpawnCreature to place a new creature.
|
||||||||||||||||
| GetRandomCoordinate | 8598 | LD A,B | Fetch the size of the room along the axis. | |||||||||||||
| 8599 | SUB $08 | Take 08 off the size of the room. | ||||||||||||||
| 859B | LD B,A | Keep the result in B as the limit for the random number. | ||||||||||||||
| 859C | LD A,R | Fetch a random number (from the refresh register). | ||||||||||||||
| 859E | INC HL | Move HL on to the next byte. | ||||||||||||||
| GetRandomCoordinate_Reduce | 859F | CP B | Jump to GetRandomCoordinate_Offset if the random number is less than the limit. | |||||||||||||
| 85A0 | JR C,GetRandomCoordinate_Offset | |||||||||||||||
| 85A2 | SUB B | Subtract the limit from the random number. | ||||||||||||||
| 85A3 | JR GetRandomCoordinate_Reduce | Jump back to GetRandomCoordinate_Reduce to keep reducing the number. | ||||||||||||||
| GetRandomCoordinate_Offset | 85A5 | LD C,A | Keep the random offset in C. | |||||||||||||
| 85A6 | LD A,R | Fetch a random number (from the refresh register). | ||||||||||||||
| 85A8 | BIT 1,A | Test bit 1 of the random number, to choose which side of 60 to use. | ||||||||||||||
| 85AA | LD A,$60 | A=60. | ||||||||||||||
| 85AC | JR Z,GetRandomCoordinate_Negative | Jump to GetRandomCoordinate_Negative if bit 1 was not set. | ||||||||||||||
| 85AE | ADD A,C | Add the offset to 60. | ||||||||||||||
| 85AF | RET | Return. | ||||||||||||||
| GetRandomCoordinate_Negative | 85B0 | SUB C | Take the offset away from 60. | |||||||||||||
| 85B1 | RET | Return. | ||||||||||||||
| Prev: 8566 | Up: Map | Next: 85B2 |