Prev: BF41 Up: Map Next: BF55
BF45: Generate Random Number
Return a number between 00 and the limit passed in.
Output
A A random number derived from *FRAMES
GenerateRandomNumber BF45 PUSH BC Save the limit and take the low byte of *FRAMES as the scramble.
BF46 LD C,A
BF47 LD A,($5C78)
BF4A LD B,A
BF4B LD A,C
GenerateRandomNumber_Loop BF4C DEC A Step the result down, wrapping to the limit when it passes zero.
BF4D JR NZ,GenerateRandomNumber_Repeat
BF4F LD A,C
GenerateRandomNumber_Repeat BF50 DJNZ GenerateRandomNumber_Loop Repeat that step once for each frame count.
BF52 DEC A Step the result down once more, so the range starts at zero.
BF53 POP BC Restore the saved limit from the stack.
BF54 RET Return.
Prev: BF41 Up: Map Next: BF55