					EXPORT	RANDOM_NUMBER
					EXPORT	GET_RANDOM

RANDOM_NUMBER_RANGE	FDB		100
GET_RANDOM_IN_RANGE	PSHS	A,B
					BSR		GET_RANDOM_POSITIVE
					LDD		RANDOM_NUMBER,PCR
					STD		DIV16_NUMER,PCR
					LDD		RANDOM_NUMBER_RANGE,PCR
					ADDD	#1
					STD		DIV16_DENOM,PCR
					LBSR	DIV16
					LDD		DIV16_NUMER,PCR
					STD		RANDOM_NUMBER,PCR
					PULS	A,B,PC

GET_RANDOM_POSITIVE	PSHS	A,B
					BSR		GET_RANDOM
					LDD		RANDOM_NUMBER,PCR
					ANDA	#$7F
					STD		RANDOM_NUMBER,PCR
					PULS	A,B,PC

					; Random number (kind of)
					; Read F-BASIC ROM $8000+i, $8800+i, $9000+i, $9800+i
					; and take XOR.
					; Shadow-RAM must be in the ROM mode.
					; Return value is stored in RANDOM_NUMBER
RANDOM_NUMBER		FDB		0
GET_RANDOM			PSHS	A,B,X

					LDD		RANDOM_READOFFSET,PCR
					LDX		#$8000
					LEAX	D,X

					ADDD	#2
					ANDA	#$0F
					STD		RANDOM_READOFFSET

					LDD		,X
					LEAX	$800,X
					EORA	,X
					EORB	1,X
					LEAX	$800,X
					EORA	,X
					EORB	1,X
					LEAX	$800,X
					EORA	,X
					EORB	1,X
					STD		RANDOM_NUMBER,PCR

					PULS	A,B,X,PC


RANDOM_READOFFSET	FDB		0
