Prev: 38233 Up: Map Next: 38295
38234: Load A with a pseudo-random number between 0 and the higher of 2 and A (input)
Used by the routines at 39514, 39563, 39631, 39741, 39823, 43054, 51598, 52144, 52179, 53252, 53943 and 55039.
Input
A Range
Output
A Generated random number
38234 CP 2 If range is less than 2 then set it to 2.
38236 JP NC,38241
38239 LD A,2
38241 LD (38233),A
38244 PUSH HL
38245 PUSH DE
38246 PUSH BC
38247 LD DE,(38231)
38251 LD H,E
38252 LD L,253
38254 LD A,D
38255 OR A
38256 SBC HL,DE
38258 SBC A,0
38260 SBC HL,DE
38262 SBC A,0
38264 LD E,A
38265 LD D,0
38267 SBC HL,DE
38269 JP NC,38273
38272 INC HL
38273 LD (38231),HL
38276 PUSH HL
38277 POP DE
38278 LD A,(38233)
38281 DEC A
38282 LD B,A
38283 XOR A Set A to 0.
38284 ADD HL,DE Add DE to HL.
38285 JP NC,38289 If DE has not crossed the 65535 - 0000 boundary then skip ahead to 38289.
38288 INC A Increase A (count of number of times DE rolls over from 65535 to 0000).
38289 DJNZ 38284 Decrease B and loop back to 38284.
38291 POP BC Restore BC, DE and HL from the stack.
38292 POP DE
38293 POP HL
38294 RET Return.
Prev: 38233 Up: Map Next: 38295