Prev: DAF9 Up: Map Next: DB1F
DB06: Generate pseudo-random number using ROM address values
Used by the routines at C8DC, CBA8, CDD7, CED4, D651, D71C, DF33 and E16A.
Generates a constantly changing value in the A register, using random addresses and bytes from ROM.
HL gets gradually incremented from 0. The ROM address and the byte stored there is returned in the A register to deliver a pseudo-random value.
DB06 LD ($DB1D),HL Preserve HL register pair
DB09 LD HL,($DB1B) Retrieve address pointer
DB0C INC HL Increment pointer to next address in ROM
DB0D LD A,H Ensure high byte of pointer doesn't exceed 31 (keeps ROM address capped at 8191)
DB0E AND $1F
DB10 LD H,A
DB11 LD A,(HL) Pick a byte from this ROM address
DB12 ADD A,H Add both high & low byte address values
DB13 ADD A,L This gives the value variation if the ROM contains a lot of the same consecutive values
DB14 LD ($DB1B),HL Store the ROM address pointer for next time
DB17 LD HL,($DB1D) Retrieve HL register pair
DB1A RET
Store for registers used in the above routine
DB1B DEFW $0000 Store for incrementing ROM address pointer. Starts at 0
DB1D DEFW $0000 Temp store for HL register pair during the routine
Prev: DAF9 Up: Map Next: DB1F