;	******* TARGET *******
;
;A VIDEO TARGET SHOOTING GAME USING THE SOL VIDEO TERMINAL
;
;
;
	ORG	0000H
;
GLOC	EQU	0CDC0H		;LOCATION OF GUN SYMBOL
TLOC	EQU	0CFFFH		;INITIAL TARGET LOCATION
VDM	EQU	0FEH		;VDM SETUP PORT
WIN	EQU	0CFCDH
LOSE	EQU	0CFC4H
UPSYM	EQU	5EH
MLOC	EQU	0CDC1H		;MISSLE LOCATION
MSYM	EQU	2DH		;MISSILE SYMBOL
TARGET	EQU	5EH		;TARGET SYMBOL
;
;
INIT:	LXI	SP,0CBFFH
	CALL	SINT
	LXI	H,GLOC
	MVI	M,05H		;GUN SYMBOL
	LXI	H,TLOC		;INITIAL TARGET POSITION
	MVI	M,TARGET		;TARGET UP ARROW
	XCHG
	LXI	B,8000H
	XRA	A
	OUT	VDM
	LXI	H,3030H		;ASCII ZERO
	SHLD	WIN
	SHLD	LOSE
;
;
LOOP1:	CALL	INDEL
RAR
	JC	TSTEM
;
;
INCTME:	INR	C
	MOV	A,C
	CPI	24		;MOVE TARGET EVERY 24TH TIME
	JNZ	TSTMIS
	MVI	C,0
	LDAX	D
	CPI	UPSYM
	MVI	A,20H
	STAX	D
	JNZ	DOWN
;
;
UP:	MOV	A,E
	SUI	64
	MOV	E,A
	MOV	A,D
	SBI	0
	MOV	D,A
	CPI	0CCH
	JNZ	STUP
	MOV	A,E
	CPI	3FH
	JNZ	STUP
;
;
STDOWN:	MVI	A,0BH		;DOWN SYMBOL
	STAX	D
	JMP	TSTMIS
;
;
DOWN:	MOV	A,E
	ADI	64
	MOV	E,A
	MOV	A,D
	ACI	0
	MOV	D,A
	CPI	0CFH
	JNZ	STDOWN
	MOV	A,E
	CPI	0FFH
	JNZ	STDOWN
;
;
STUP:	MVI	A,UPSYM
	STAX	D
TSTMIS:	MOV	A,B
	RLC
	JC	LOOP1
	MVI	M,' '
	INX	H
	MOV	A,L
	CPI	0FFH
	JZ	TSTHIT
	MVI	M,2DH
	JMP	LOO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