;	******* BEASTIE *******
;
;	THE BOUNCING BEASTIE--
;		A RANDOM WALKER FOR THE SOL
;			COMPUTER TERMINAL
;
;
;
VDM	EQU	0FEH
DISP	EQU	0CC00H
;
	ORG	0000H
;
;INITIALIZE SOL VIDEO DISPLAY
;
	LXI	SP,AR+6
	MVI	A,0
	OUT	VDM
AG:	LXI	H,DISP
ST:	MVI	M,' '
	INX	H
	MOV	A,H
	CPI	0D0H
	JNZ	ST

;
;START BEASTIE IN CENTER OF SCREEN
;
N1:	LXI	H,0CE20H
N2:	MVI	M,7
;
;DELAY ROUTINE TO SLOW DOWN ACTION
;
N4:	MOV	A,B
	ANI	3
	JZ	N5
	LXI	B,1FFFH
	JMP	N3
N5:	LXI	B,0FFFH
N3:	DCX	B
	MOV	A,B
	CPI	07H
	JNZ	N3
;LEAVE A TRAIL BEHIND
	MVI	M,'.'
	CALL	RND
;
;MOVE ROUTINE
;
	MOV	B,A
	ANI	1
	CNZ	UP
	MOV	A,B
	ANI	2
	CNZ	DN
	MOV	A,B
	ANI	40H
	CNZ	RT
	MOV	A,B
	ANI	80H
	CNZ	LF
	JMP	N2
;
;MOVE RIGHT ROUTINE
;
RT:	INX	H
	MOV	A,H
	CPI	0D0H
	RNZ
	MVI	H,0CCH
	RET
;
;MOVE LEFT ROUTINE
;
LF:	DCX	H
	MOV	A,H
	CPI	0CBH
	RNZ
	MVI	H,0CFH
	RET
;
;MOVE UP ROUTINE
;
UP:	LXI	D,0FFC0H
	DAD	D
	MOV	A,H
	ANI	0FBH
	ORI	0CH
	MOV	H,A
	RET
;
;MOVE DOWN ROUTINE
;
DN:	LXI	D,40H
	DAD	D
	MOV	A,H
	ANI	0C7H
	ORI	0CH
	MOV	H,A
	RET
;
;RANDOM NUMBER GENERATOR
;
RND:	PUSH	H
	LXI	H,SH+3
	MVI	B,8
	MOV	A,M
RTOP:	RLC
	RLC
	RLC
	XRA	M
	RAL
	RAL
	DCR	L
	DCR	L
	DCR	L
	MOV	A,M
	RAL
	MOV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