![]() |
Routines |
| Prev: ACFC | Up: Map | Next: AD34 |
|
Returns a number from 00 up to, but not including, the limit passed in A. The Z80 Memory Refresh Register supplies the walk count: the routine counts down inside that limit once per refresh tick, wrapping to the original limit when it hits zero, then decreases the result by one more before returning. Nothing in the game calls it.
|
||||||||||||
|
Preserve BC, keep the limit, and read the refresh register for the walk count.
|
||||||||||||
| GenerateRandomNumber | AD25 | PUSH BC | Stash BC on the stack. | |||||||||
| AD26 | LD C,A | Copy the exclusive upper bound into C. | ||||||||||
| AD27 | LD A,R | Read the Memory Refresh Register into A. | ||||||||||
| AD29 | LD B,A | Use that refresh value as the walk counter in B. | ||||||||||
| AD2A | LD A,C | Restore the exclusive upper bound into A. | ||||||||||
|
Count down inside the limit; when it wraps, reload the original bound from C.
|
||||||||||||
| GenerateRandomNumber_Loop | AD2B | DEC A | Decrease the running value in A by one. | |||||||||
| AD2C | JR NZ,GenerateRandomNumber_Next | Jump to GenerateRandomNumber_Next if the running value is not zero. | ||||||||||
| AD2E | LD A,C | Reload the exclusive upper bound from C into A. | ||||||||||
| GenerateRandomNumber_Next | AD2F | DJNZ GenerateRandomNumber_Loop | Decrease the walk counter by one and loop back to GenerateRandomNumber_Loop until the refresh count is spent. | |||||||||
| AD31 | DEC A | Decrease the running value in A by one for the final result. | ||||||||||
| AD32 | POP BC | Restore BC from the stack. | ||||||||||
| AD33 | RET | Return. | ||||||||||
|
View the equivalent code in;
|
||||||||||||
| Prev: ACFC | Up: Map | Next: AD34 |