Product specifications
A point to note is that the random value contained within RND will only be auto-
updated every 1/50
th
of a second. If this is too slow for some applications then it will
do no harm to call the routine random independently of the interrupt routine using a
standard Z80 ‘CALL RANDOM’ instruction.
The assumption made is that prior to setting under the VDP interrupt routine a routine
called SETRND is called. This is listed below. It sets up a random seed within an 8
byte table RNDMEM for use by the routine RANDOM.
;
SETRND-SET UP SEED WITHIN 8 BYTE TABLE RNDMEM FOR USE
; BY ROUTINE RANDOM
; NO REGISTER SET UP REQUIRED ON ENTRY
; NONE AFFECTED ON EXIT
;
RNDMEM: DB 0,0,0,0,0,0,0,O
;
SETRND: PUSH AF ;Save Acc and flags
PUSH BC ;Save BC register pair
PUSH IY ;Save IY index register
LD B,5 ;Write five seed values into table
LD IY,RNDMEM ;RNDMEM extracted from the Z80
SETRN1: LD A,R ;refresh register
LD (IY+0),A ;Extra 3 bytes in table RNDMEM
INC IY ;used by routine RANDOM
DJNZ SETRN1
PDP IY ;Retrieve old IY index register
PDP BC ;Retrieve old BC register pair
PDP AF ;Retrieve old Acc and flags
RET ;Return to calling routine
The code for the random number routine follows
;
‘RANDOM-RETURN 8 BIT RANDOM VALUE IN VARIABLE RND
; USES TABLE RNDMEM
; NO REGISTER SET UP REQUIRED ON ENTRY
; NONE AFFECTED ON EXIT
;
RND: DB 0 ;See description above
;
RANDOM: PUSH AF ;Save Acc and flags
PUSH BC ;Save BC register pair
PUSH IY ;Save IY register pair
LD B,8 ;Loop counter = 8
LD IY,RNDMEM ;Set pointer to start of random
;seed table
RAN0: LD A,(RNDMEM+2) ;Extract seed value
SRL A ;Shuffle seed table
SRL A
SRL A
XOR (IY+4)
RR A