Prev: 59080 Up: Map Next: 59155
59116: Generate Random Number
Used by the routine at Game_Initialisation.
Output
BC The generated random number
GenerateRandomNumber 59116 PUSH HL Stash HL on the stack.
59117 LD HL,(58053) HL=*RandomNumberSeed.
59120 LD A,(HL) Fetch a byte from *HL and store it in A.
59121 RLCA Multiply A by 16.
59122 RLCA
59123 RLCA
59124 PUSH AF Stash the result on the stack.
59125 LD A,R A=the contents of the Memory Refresh Register.
59127 AND %00011111 Ensure the number is between 0-31.
59129 LD H,A Store the result in H.
59130 INC L Increment L by one.
59131 LD (58053),HL Write HL to *RandomNumberSeed.
59134 POP AF Restore AF from the stack.
59135 LD (58053),HL Write HL to *RandomNumberSeed.
59138 LD HL,55333 HL=55333.
59141 SRL A Divide A by 2.
HalveRandomNumber 59143 SRL A Divide A by 2.
59145 CP (HL) Jump to HalveRandomNumber if A is greater than or equal to *HL.
59146 JP P,HalveRandomNumber
59149 INC A Increment A by one.
59150 LD B,0 Store the result in BC.
59152 LD C,A
59153 POP HL Restore HL from the stack.
59154 RET Return.
Prev: 59080 Up: Map Next: 59155