![]() |
Routines |
| Prev: 65D2 | Up: Map | Next: 65E6 |
|
Used by the routines at GameLoop and ActionKill.
Returns a number from 00 up to, but not including, A.
The frame counter chooses how far to walk around that range.
|
||||||||||||
|
Mix the frame counter into a number below the limit in A.
|
||||||||||||
| GenerateRandomNumber | 65D6 | PUSH BC | Stash BC on the stack. | |||||||||
| 65D7 | LD C,A | Store the exclusive upper bound in C. | ||||||||||
| 65D8 | LD A,($5C78) | Load *FRAMES into B as the loop count. | ||||||||||
| 65DB | LD B,A | |||||||||||
| 65DC | LD A,C | Restore the exclusive upper bound into A. | ||||||||||
| GenerateRandomNumber_Loop | 65DD | DEC A | Decrease the walking value by one. | |||||||||
| 65DE | JR NZ,GenerateRandomNumber_Next | Jump to GenerateRandomNumber_Next if it has not wrapped past zero. | ||||||||||
| 65E0 | LD A,C | Wrap back to the exclusive upper bound. | ||||||||||
| GenerateRandomNumber_Next | 65E1 | DJNZ GenerateRandomNumber_Loop | Decrease the frame-count loop by one and loop back to GenerateRandomNumber_Loop until the count is zero. | |||||||||
| 65E3 | DEC A | Decrease the result by one so the range starts at 00. | ||||||||||
| 65E4 | POP BC | Restore BC from the stack. | ||||||||||
| 65E5 | RET | Return. | ||||||||||
|
View the equivalent code in;
|
||||||||||||
| Prev: 65D2 | Up: Map | Next: 65E6 |