Prev: 904A Up: Map Next: 907A
904B: Generate a semi-random number.
Used by the routines at subversion_spell, TUR_DO, main_routine, TREPUT and routine08.
Stores a number with lower nibble less than 10 in RANUM, and returns value from 0 to 9 in A.
RANDY 904B PUSH HL Preserve HL.
RANDO 904C LD A,R Copy R. register to A.
904E LD HL,$5C76 Add value of SEED system variable.
9051 ADD A,(HL)
9052 OR $80 Set most significant bit.
9054 LD B,A Copy value to B register as outer loop counter.
PODER 9055 PUSH BC Preserve loop counter.
9056 LD B,$0F Set B to 15 as inner loop counter.
PODEI 9058 NOP Loop back and execute NOP for 15 iterations.
9059 DJNZ PODEI
905B POP BC Restore loop counter.
905C DJNZ PODER Loop back to PODER.
905E LD A,R Copy R register to A.
9060 AND $07 Copy lowest three bits to H.
9062 LD H,A
9063 LD A,R Copy R register to L. HL now contains a semi-random address below $0800.
9065 LD L,A
9066 LD A,R Copy R register to A then add byte at the address in HL twice.
9068 ADD A,(HL)
9069 ADD A,(HL)
906A LD HL,$5C76 Add the SEED system variable.
906D ADD A,(HL)
906E LD (RANUM),A Store result in RANUM.
9071 AND $0F If the lower nibble is greater than 9 jump back to RANDO.
9073 CP $0A
9075 JP P,RANDO
9078 POP HL Else restore HL and return.
9079 RET
Prev: 904A Up: Map Next: 907A