Prev: C579 Up: Map Next: C592
C582: Generate Random Number
Returns a number from 00 up to, but not including, A.
The frame counter chooses how far to walk around that range.
Input
A Exclusive upper bound
Output
A The generated number
Mix the frame counter into a number below the limit in A.
GenerateRandomNumber C582 PUSH BC Stash BC on the stack.
C583 LD C,A Store the exclusive upper bound in C.
C584 CALL FetchFrames Call FetchFrames to read *FRAMES.
C587 LD B,A Use the frame counter as the loop count in B.
C588 LD A,C Restore the exclusive upper bound into A.
GenerateRandomNumber_Loop C589 DEC A Decrease the walking value by one.
C58A JR NZ,GenerateRandomNumber_Next Jump to GenerateRandomNumber_Next if it has not wrapped past zero.
C58C LD A,C Wrap back to the exclusive upper bound.
GenerateRandomNumber_Next C58D DJNZ GenerateRandomNumber_Loop Decrease the frame-count loop by one and loop back to GenerateRandomNumber_Loop until the count is zero.
C58F DEC A Decrease the result by one so the range starts at 00.
C590 POP BC Restore BC from the stack.
C591 RET Return.
Prev: C579 Up: Map Next: C592