;
;  PROGRAM:  SYSTEST5
;  AUTHOR:  Richard Conn
;  PURPOSE:  This program obtains a seed value and then generates
;		10 random numbers
;

;
;  Externals
;
	ext	cin	; char in
	ext	cout	; char out
	ext	print	; print string
	ext	rndinit	; init random number generator by keypress
	ext	rnd	; return random number
	ext	rndseed	; init random number generator by user seed
	ext	crlf	; new line
	ext	padc	; print A as up to 3 decimal digits
	ext	caps	; capitalize char
	ext	bbline	; get line from user
	ext	eval	; evaulate string

;
;  Constants
;
cr	equ	0dh
lf	equ	0ah

	call	print
	db	'SYSTEST5 - Random Number Demo',0

;
;  Start of main loop, which generates 10 random numbers each time it is
;  executed.
;
start:

;
;  Prompt user to see if he wants to select his own seed
;
	call	print
	db	cr,lf,'Do you want to pick your own seed (Y/N)? ',0
	call	cin	; get single-char response from user
	call	caps
	call	cout
	cpi	'N'
	jz	rseed

;
;  Input a seed value from the user.
;
	call	print
	db	cr,lf,'What is your seed value? ',0
	xra	a	; no caps
	call	bbline	; get string
	call	eval	; evaluate string and return value in HL and A=L
	call	rndseed	; set seed from 8-bit value in A
	call	print	; print seed stored
	db	cr,lf,'Your seed is: ',0
	call	padc
	jmp	rseed1

;
;  Prompt user and wait for keypress to set seed.
;
rseed:
	call	print
	db	cr,lf,'Wait a little and then press a key to set the seed - ',0
	call	rndinit

;
;  Generate 10 random numbers
;
rseed1:
	call	print
	db	cr,lf,'10 Random Numbers follow --',cr,lf,0
	mvi	b,10	; 10 numbers
loop:
	call	rnd	; get number
	call	padc	; print it as decimal
	mvi	a,' '	; print <SP>
	call	cout
	dcr	b	; count down
	jnz	loop

;
;  Prompt user to continue
;
	call	print
	db	cr,lf,'Do you want to run this test again (Y/N)? ',0
	call	cin	; get response
	call	caps
	call	cout
	cpi	'N'
	jnz	start
	ret		; return to OS if done

	end
