home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug134.arc
/
RANDOM.MAC
< prev
next >
Wrap
Text File
|
1979-12-31
|
896b
|
64 lines
; random number generator
.z80
;
;... Calling this subroutine seeds random geerator from real time clock
;
seed:
ld a,4 ; HOURS
out (04h),a
in a,(07h)
ld h,a
rlca
ld l,a
ld (rand2),hl
ld a,2 ; MINUTES
out (04h),a
in a,(07h)
ld l,a
ld a,0 ; SECONDS
out (04h),a
in a,(07h)
ld h,a
ld (rand1),hl
ret
;
;... calling this subroutine returns 16-bit random number in HL
; 8-bit random number in A
;
random:
push de
ld hl,(rand2)
push hl
ld a,h
ld h,l
ld l,a
dec hl
ld (rand2),hl
ld hl,(rand1)
srl h
rr l
jr nc,$+4
set 7,h
pop de
ld a,h
rlca
xor l
xor e
ld h,a
ld a,l
rrca
xor h
xor d
ld l,a
ld (rand1),hl
pop de
ret
rand1:
ds 2 ; seed for next iteration
rand2:
ds 2 ; counter (NOT random)
end