Prev: B081 Up: Map Next: B09A
B08A: Generate Random Number
Used by the routines at Event_Roman and Event_Fomorian.
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 B08A PUSH BC Stash BC on the stack.
B08B LD C,A Store the exclusive upper bound in C.
B08C CALL FetchFrames Call FetchFrames to read *FRAMES.
B08F LD B,A Use the frame counter as the loop count in B.
B090 LD A,C Restore the exclusive upper bound into A.
GenerateRandomNumber_Loop B091 DEC A Decrease the walking value by one.
B092 JR NZ,GenerateRandomNumber_Next Jump to GenerateRandomNumber_Next if it has not wrapped past zero.
B094 LD A,C Wrap back to the exclusive upper bound.
GenerateRandomNumber_Next B095 DJNZ GenerateRandomNumber_Loop Decrease the frame-count loop by one and loop back to GenerateRandomNumber_Loop until the count is zero.
B097 DEC A Decrease the result by one so the range starts at 00.
B098 POP BC Restore BC from the stack.
B099 RET Return.
Prev: B081 Up: Map Next: B09A