Prev: DA1D Up: Map Next: DA3D
DA28: Random Number
Output
A Random number
RandomNumber DA28 LD DE,($D21A) DE=*Game_Clock.
DA2C INC DE Increment DE by one.
The max value is 2800 so test the higher order byte to check if this limit has been hit.
DA2D LD A,D If D is 28 then jump to ResetSeed.
DA2E CP $28
DA30 JR Z,ResetSeed
Update the "clock" value.
WriteSeed DA32 LD ($D21A),DE Write DE back to *Game_Clock.
The "random number" is actually a byte from the Spectrum ROM. The "clock" is used as a pointer to return a value from between memory locations 0000-27FF.
DA36 LD A,(DE) A=*DE.
DA37 RET Return.
Reset the "clock" back to 0000.
ResetSeed DA38 LD D,$00 D=00.
DA3A JP WriteSeed Jump to WriteSeed.
Prev: DA1D Up: Map Next: DA3D