;
	IF	0
; original from CPMUG029
VDMPORT	EQU	0C8H
RDA	EQU	80H
INDAT	EQU	1
INSTAT	EQU	0
	ELSE
; modified for Sol, jtb 11/13/01
VDMPORT	EQU	0FEH		; SOL specific
RDA	EQU	01H		; SOL keyboard status bit
INDAT	EQU	0FCH		; SOL keyboard data port
INSTAT	EQU	0FAH		; SOL status port
	ENDIF
;
	ORG	100H
RESTART	MVI	A,0
	OUT	VDMPORT
	LXI	SP,JUMPS
	CALL	SETUP
;
;
;
MAINLP	LXI	H,VTABL
	INX	H
	MOV	A,M
	CPI	DEAD
	JZ	MP1
	PUSH	H
	CALL	ADDSCR
	LDA	SCRFLG
	ORA	A
	CP	VMOVE
	POP	H
MP1	CALL	USER
	CALL	BIGCTR
	CALL	NEWFISH
	LXI	H,VTABL
	MVI	B,MAXFISH+1
FISHES	PUSH	B
	PUSH	H
	CALL	FISHY
	POP	H
	CALL	BUMP6
	POP	B
	DCR	B
	JNZ	FISHES
	JMP	MAINLP
;
;
;
SETPHA	LXI	H,ETV-LENL+6
	MOV	C,A
	LXI	D,PHAMSG
	MVI	B,0AH
MOVPHA	LDAX	D
	ORI	BIAS
	MOV	M,A
	INX	D
	INX	H
	DCR	B
	JNZ	MOVPHA
	MOV	A,C
	ADI	ZERO
	STA	ETV-LENL+16
	SUI	ZERO
	RLC
	RLC
	RLC
	MVI	D,0
	MOV	E,A
	LHLD	CTLPTR
	DAD	D
	LXI	D,LNEWF
	MVI	B,8
TRPHA	MOV	A,M
	STAX	D
	INX	H
	INX	D
	DCR	B
	JNZ	TRPHA
	MVI	A,0
	STA	BIGTWO
	RET
;
;
;
BMTPHA	LDA	PHASE
	CPI	9
	RZ
	INR	A
	STA	PHASE
	CALL	SETPHA
	RET
;
;
;
STOP	POP	H
GETPHA	CALL	INPUT
	CPI	'0'
	RC
	CPI	'9'
	RNC
	SUI	'0'
	STA	PHASE
	CALL	SETPHA
	RET
;
;
;
ADDSCR	LDA	PHASE
	INR	A
	MOV	B,A
	LXI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,SCRMSG
PTRSCR	LDAX	D
	ORI	BIAS
	MOV	M,A
	INX	D
	INX	H
	DCR	B
	JNZ	PTRSCR
	MVI	A,0FFH
	STA	SCRFLG
	MVI	A,0
	STA	PHASE
	CALL	SETPHA
	CALL	GETPHA
	RET
;
;
;
BUMP6	INX	H
	INX	H
BUMP4	INX	H
BUMP3	INX	H
	INX	H
	INX	H
	RET
;
;
;
DEC5	DCX	H
DEC4	DCX	H
DEC3	DCX	H
	DCX	H
	DCX	H
	RET
;
;
;
NBTB1	DB	1
NBTB2	DB	SUBL,1,2
	DB	SUBL+1,2,4
	DB	1,4,8
	DB	LENL+1,8,10H
	DB	LENL,10H,20H
	DB	LENL-1,20H,40H
	DB	0FFH,40H,80H
	DB	SUBL-1,80H
LCTR	DB	8
COUNT	DB	0
RPTR	DB	0,0
BIGONE	DB	0
BIGTWO	DB	0,0,0
SCRMSG	DB	'SCORE '
	DB	'      00      '
PHAMSG	DB	'PHASE      '
SCRFLG	DB	0FFH
GOODCAL	DB	WIDTH-2
PHASE	DB	0
LNEWF	DB	100
LSIDE	DB	1
LMINS	DB	20
LSRNG	DB	80
LTIME	DB	28H
LTRACK	DB	1
LSTRK	DB	1
LBONUS	DB	0
CTLPTR	DW	CONTROL
	DB	22
;
;
;
CONTROL	DB	40H,1,2,60H,30H,10,1,50
	DB	48H,1,26H,5CH,30H,20,4,75
	DB	50H,1,24H,58H,2CH,30,7,100
	DB	58H,1,22H,54H,2CH,40,10,125
	DB	60H,2,20H,50H,28H,50,13,150
	DB	68H,2,1EH,4CH,28H,60,16,175
	DB	70H,2,1CH,48H,24H,70,19,200
	DB	78H,2,1AH,44H,24H,80,22,225
	DB	80H,4,18H,40H,20H,90,25,250
	DB	88H,4,16H,3CH,20H,100,28,255
;
;
;
MARKED	EQU	58H
FRATE	EQU	4
MRATE	EQU	1
FTRK	EQU	49H
MONIT	EQU	0		; cold start CP/M
NOTRK	EQU	41H
VMAXS	EQU	17H
VFAST	EQU	7
VICTIM	EQU	50H
LENL	EQU	64
WIDTH	EQU	64
SCORSP	EQU	20H
SUBL	EQU	0C0H
BIAS	EQU	0
BLANK	EQU	' '+BIAS
ZERO	EQU	'0'+BIAS
BIN0	EQU	0
ONE	EQU	1
VSYM	EQU	7+BIAS
DEAD	EQU	4FH
BOOM	EQU	'+'+BIAS
FISH	EQU	'*'+BIAS
BORDER	EQU	0A0H
DTV	EQU	0CC00H
NLINES	EQU	16
ETV	EQU	DTV+LENL*NLINES
STV	EQU	ETV-LENL+WIDTH
MAXFISH	EQU	(NLINES+WIDTH)/3
;
;
;
	ORG	800H
JUMPS	DW	MONIT
	DW	ESC
	DW	RESTART
	DW	UP
	DW	DOWN
	DW	LEFT
	DW	RIGHT
	DW	UL
	DW	UR
	DW	LL
	DW	LR
	DW	HALT
	DW	STOP
	DW	AUTO
	DW	RETURN
CHARS	DB	0FFH,01H
	DB	1BH,1BH
CHARGO	DB	'S',0DH
	DB	'U','8'
	DB	'J','2'
	DB	'H','4'
	DB	'K','6'
	DB	'Y','7'
	DB	'I','9'
	DB	'N','1'
	DB	',','3'
	DB	' ','5'
	DB	'P','.'
	DB	'A','0'
ENDCH	DB	0FFH
CHARL	EQU	ENDCH-CHARS
STRING	DB	' ENTER NEW VALUES FOR: GO-'
	DB	'U-'
	DB	'D-'
	DB	'L-'
	DB	'R-'
	DB	'UL-'
	DB	'UR-'
	DB	'LL-'
	DB	'LR-'
	DB	'H-'
	DB	'P-'
	DB	'A-'
	DB	0FFH
VTABL	DB	VMAXS
	DB	VICTIM
VSPEED	DB	VMAXS
VDIREC	DB	0
VPOS	DW	DTV+LENL*(NLINES-1)/2
FTABL	DS	MAXFISH*6
	END

