Compucolor.org – Virtual Media

Listing of file='ASTJSA.SRC;01' on disk='vmedia/asteriods_source-sector.ccvf'


;	ASTEROIDS	WRITTEN 1980 BY TOM HUDSON

ENDCRT1	EQU	32769
ENDCRT2	EQU	32771

START:	ORG	829AH
	JMP	START0
OLDTAB:
SUBHD:	JMP	3459H
MULHD:	JMP	3562H
ADHLA:	JMP	3518H
DIVHD:	JMP	3581H
OS:	JMP	33F4H
LO:	JMP	3392H

LENTAB	EQU	$-OLDTAB

NEWTAB:
	JMP	188FH
	JMP	1998H
	JMP	194EH
	JMP	19B7H
	JMP	182AH
	JMP	17C8H


START0:	LDA	092AH
	CPI	1FH
	JNZ	START1
	LXI	H,OLDTAB
	LXI	D,NEWTAB
	LXI	B,LENTAB
OVRLAY:	LDAX	D
	MOV	M,A
	INX	H
	INX	D
	DCX	B
	MOV	A,B
	ORA	C
	JNZ	OVRLAY

START1:	DI
	LXI	H,TPAGE
	CALL	MYOS
	CALL	DELAY3
	CALL	DELAY3
	CALL	DELAY3
	MVI	A,255
	OUT	8
	MVI	A,247
	OUT	8
	MVI	A,1
	STA	STFLAG
	MVI	A,7
	STA	DIFF
	STA	ENDCRT1
	STA	ENDCRT2
RESTART:LXI	H,0
	SHLD	SCORE
	SHLD	SCORE2
	LXI	H,SCOBUF
	MVI	M,48
	INX	H
	MVI	M,48
	INX	H
	MVI	M,48
	INX	H
	MVI	M,48
	INX	H
	MVI	M,48
	MVI	A,0
	STA	KILLS
	STA	ENDFL
	STA	RESTRT
	MVI	A,'3'
	STA	SHIPCNT
	MVI	D,0
	LXI	H,MISCNT
CLLOOP:	MVI	M,0
	INR	D
	INX	H
	MOV	A,D
	CPI	33
	JM	CLLOOP
	CALL	DELAY3
	CALL	DELAY3
CLREST:	MVI	A,4
	STA	THRUST
	MVI	A,0
	STA	GOING
	MVI	A,1
	STA	DCOUNT
	MVI	A,64
	STA	SHIPX
	STA	SHIPY
	LXI	H,0
	SHLD	SINC
	SHLD	WINC
	MVI	A,0
	STA	FIRST
	LXI	H,CLRCRT
	CALL	MYOS
	LDA	RESTRT
	CPI	1		;IS THIS A RESTART?
	JZ	BIG		;YES, DON'T RANDOMIZE!
	MVI	A,1
	STA	RESTRT		;SET RESTART FLAG TO 1
RERND:	LXI	H,CLRCRT
	CALL	MYOS
	MVI	A,0
	STA	FIRST
	LXI	H,BIGNO
	LDA	DIFF
	MOV	M,A
	LXI	H,SMLNO
	MVI	M,0		;INITIALIZE #SMALL
	CALL	RNDAST		;RANDOMIZE ASTEROIDS
BIG:	LDA	SOUND
	CPI	0		;IS SOUND GOING?
	JZ	CHKSTRT		;NO, SEE IF NORMAL RUNNING
	MVI	A,0
	STA	SOUND
	CALL	SOUND1		;YES, MAKE BOOM SOUND
CHKSTRT:LDA	STFLAG		;GET START FLAG
	CPI	0		;IS THIS START?
	JZ	CHKEND		;NO, GO CHECK FOR END
	LDA	RNDINC
	ADI	1		;HELPS RANDOMIZE
	STA	RNDINC
	MVI	A,0
	STA	GOING		;NOT GOING YET!
	STA	DIFF
	LXI	H,STRTMSG
	CALL	OS
	CALL	DIFFCUL		;GET DIFFICULTY
	LDA	DIFF
	CPI	0
	JZ	GO
	MVI	A,0
	STA	STFLAG		;NOT START ANYMORE!
	JMP	RESTART
CHKEND:	LDA	ENDFL
	CPI	1		;GAME OVER?
	JNZ	CHKGO		;NO, SEE IF GOING
	LXI	H,ENDMSG
	CALL	OS
	LXI	H,STRTMSG
	CALL	OS
	CALL	SHOSCOR
	MVI	A,0
	STA	GOING		;TELL REST OF PROGRAM END HERE
	STA	DIFF
	CALL	DIFFCUL
	LDA	DIFF
	CPI	0
	JNZ	RESTART
	JMP	GO
CHKGO:	LDA	GOING		;NORMAL RUNNING?
	CPI	1
	JZ	GO		;YES, PROCEED
	MVI	A,7
	OUT	7
	IN	1
	CPI	239
	JNZ	GETCNT
	MVI	A,1
	STA	GOING
	JMP	GO
GETCNT:	LDA	DCOUNT		;NO, GET COUNT TO NEXT CHECK
	SUI	1
	STA	DCOUNT
	CPI	0		;READY TO CHECK?
	CZ	CHKOK		;YES! GO CHECK 12 IN ADVANCE
GO:	LDA	BIGNO		;#BIG ASTS
	CPI	0		;ANY BIG?
	JZ	SMALL		;NO, PROCESS SMALL
	MOV	B,A
	LXI	H,BIGTBL
	SHLD	HOLD1
	MVI	A,1
	STA	ATYPE		;STORE TYPE 1 (BIG)
LOOP1:	CALL	GETIT
	LHLD	HPOS
	MVI	C,3
CLOOP1:	CALL	CLRCHK		;CHECK FOR SHIP/MISSLE
	INX	H
	MVI	M,4
	INX	H
	CALL	CLRCHK
	INX	H
	MVI	M,4
	INX	H
	CALL	CLRCHK
	INX	H
	MVI	M,4
	DCR	C
	JZ	LOOPX1		;NO MORE SECTIONS
	MVI	A,123
	ADD	L		;ADD INDEX FOR NEXT SECTION
	MOV	L,A
	JNC	CLOOP1
	INR	H
	MOV	A,H
	CPI	80H
	JM	CLOOP1		;AST STILL ON SCREEN, CONTINUE
	LXI	D,1000H		;AST OFF SCREEN!
	CALL	SUBHD		;PUT IT BACK
	JMP	CLOOP1		;BACK TO PROCESS IT
LOOPX1:	CALL	INCAST		;INCREMENT AST
	SHLD	HPOS
	MVI	C,3
	LXI	D,BAIMAG-1	;BIG AST IMAGE TABLE
CLOOP2:	INX	D
	CALL	BACCHK	;CHECK FOR SHIP/MISSLE & PUT TO CRT
	INX	H
	MVI	M,4	;COLOR BLUE
	INX	H
	INX	D
	CALL	BACCHK
	INX	H
	MVI	M,4
	INX	H
	INX	D
	CALL	BACCHK
	INX	H
	MVI	M,4
	DCR	C
	JZ	LOOPX2
	MVI	A,123
	ADD	L
	MOV	L,A
	JNC	CLOOP2
	INR	H
	MOV	A,H
	CPI	80H
	JM	CLOOP2
	PUSH	D
	LXI	D,1000H
	CALL	SUBHD
	POP	D
	JMP	CLOOP2
LOOPX2:	LHLD	HOLD1
	CALL	PUTIT
	DCR	B
	JZ	SMALL
	LHLD	HOLD1
	LXI	D,4
	DAD	D
	SHLD	HOLD1
	JMP	LOOP1
SMALL:	LDA	SMLNO		;GET # SMALL AST
	CPI	0		;ARE THERE ANY?
	JZ	MOVCHK		;NO GO MOVE SHIP
	MOV	B,A
	LXI	H,SMLTBL
	SHLD	HOLD1
	MVI	A,2		;TYPE 2 AST (SMALL)
	STA	ATYPE
LOOP3:	CALL	GETIT
	LHLD	HPOS
CLOOP3:	CALL	CLRCHK		;CLEAR OLD POSITION
	INX	H
	MVI	M,4
	INX	H
	CALL	CLRCHK
	INX	H
	MVI	M,4
	CALL	INCAST
	SHLD	HPOS
	LXI	D,SAIMAG-1	;SMALL AST IMAGE
CLOOP4:	INX	D
	CALL	BACCHK		;PUT AST BACK TO CRT
	INX	H
	MVI	M,4
	INX	H
	INX	D
	CALL	BACCHK
	INX	H
	MVI	M,4
	LHLD	HOLD1
	CALL	PUTIT
	DCR	B
	JZ	MOVCHK
	LHLD	HOLD1
	LXI	D,4
	DAD	D
	SHLD	HOLD1
	JMP	LOOP3
MOVCHK:	CALL	DELAY
	LDA	GOING
	CPI	1		;GOING?
	JNZ	CHKMSL		;NO, GO PROCESS MISSLES
	MVI	A,7
	OUT	07
	IN	01
	CPI	0FEH		;IS STK FORWRD?
	JNZ	MOVSHP		;NO, GO MOVE SHIP IF NECESSARY
	LDA	THRUST
	ADI	1
	STA	THRUST
	CPI	5
	JNZ	MOVSHP
	MVI	A,0
	STA	THRUST
	LHLD	SINC
	XCHG
	LHLD	WINC
	MOV	A,H
	ADD	D
	MOV	H,A
	MOV	A,L
	ADD	E
	MOV	L,A
	SHLD	WINC
MOVSHP:	LDA	FIRST
	CPI	0
	JZ	NOERAS
	LDA	LAST
	LXI	H,PSTART1
	MVI	M,29
	CALL	PSHIP
	LDA	LAST
	LXI	H,PSTART1
	MVI	M,30
	CALL	PSHIP		;ERASE OLD SHIP
	CALL	SHOSCOR
	MVI	A,0DH
	OUT	07
	IN	01
	CPI	0FEH		;HYPERSPACE?
	JNZ	GETPDL		;NO, GET 'PADDLE' (SHIP ROT)
	CALL	RANNUM		;YES, GET RANDOM X & Y LOC
	ANI	127
	STA	SHIPX
	CALL	RANNUM
	ANI	127
	STA	SHIPY
	LDA	RNDINC
	ADI	1		;HELP RANDOMIZE
	STA	RNDINC
	JMP	GETPDL
SHOSCOR:LXI	H,28726		;POINT TO SCREEN SCORE AREA
	LXI	D,SCOPRT
	MVI	B,12		;12 CHAR TO OUTPUT
SCOLOOP:LDAX	D
	MOV	M,A		;MOVE CHAR TO CRT
	INX	H
	MVI	M,1
	DCR	B		;LAST SCORE CHAR?
	JZ	SHOSHIP		;YES, GO GET PADDLE INFO
	INX	H		;NO, POINT TO NEXT CRT POS.
	INX	D		;& POINT TO NEXT SCORE CHAR
	JMP	SCOLOOP
SHOSHIP:LXI	H,32702
	LDA	SHIPCNT
	MOV	M,A
	INX	H
	MVI	M,2
	RET
NOERAS:	MVI	A,1
	STA	FIRST
GETPDL:	LDA	HROT
	MOV	E,A
	MVI	D,0
	MVI	A,9
	OUT	07
	IN	01
	CPI	0FEH
	JNZ	NOCL		;NO CWISE ROT
	INR	E
	INR	E
	INR	E
	MOV	A,E
	STA	HROT
	JMP	NOINC
NOCL:	LDA	HROT
	MOV	E,A
	MVI	D,0
	MVI	A,0BH
	OUT	07
	IN	01
	CPI	0FEH
	JNZ	NOINC		;NO CNTR-CW INC
	DCR	E
	DCR	E
	DCR	E
	MOV	A,E
	STA	HROT
NOINC:	LHLD	WINC
	LDA	SHIPX
	ADD	H
	ANI	127
	STA	SHIPX
	LDA	SHIPY
	ADD	L
	ANI	127
	STA	SHIPY
	MOV	A,E
	LXI	H,PSTART1
	MVI	M,29
	CALL	PSHIP
CKFIRE:	MVI	A,0AH
	OUT	07
	IN	01
	CPI	0FEH		;IS 'FB' PRESSED?
	JNZ	CHKMSL		;NOT FIRING MISSLE,
				;SEE IF ANY MISSLES TO ADVANCE
	LDA	MCHECK		;GET COUNT OF # OF TIMES THE
				;BUTTON HAS BEEN PUSHED
	ADI	1		;ADD 1 TO IT
	CPI	3		;HAS IT BEEN ON 3 COUNTS?
	JP	OKFIRE		;YES! FIRE A MISSLE!
	STA	MCHECK
	JMP	CHKMSL		;NO, CHECK TO ADVANCE OTHER
				;MISSLES
OKFIRE:	MVI	A,0
	STA	MCHECK		;RESET CHECK BYTE

;
;AT THIS POINT, YOU ARE FIRING A MISSLE!
;
	LDA	MISCNT		;GET CURRENT # MISSLES
	CPI	5		;IS IT MAXIMUM?
	JP	CHKMSL		;YES!
	ADI	1
	STA	MISCNT		;INCREMENT & STORE # MISSLES
	LXI	H,MISTBL	;POINT TO MISSLE TABLE
FIND0:	MOV	A,M
	CPI	0
	JZ	GOT0		;OK, FOUND A PLACE
	LXI	D,6
	DAD	D
	JMP	FIND0
GOT0:	MVI	M,1
	SHLD	HOLD3
	INX	H
	LDA	SHIPX
	MOV	M,A
	INX	H
	LDA	SHIPY
	MOV	M,A
	LHLD	WINC
	XCHG
	LHLD	SINC
	MOV	A,H
	ADD	D
	MOV	D,A
	MOV	A,L
	ADD	E
	MOV	E,A
	LHLD	HOLD3
	INX	H
	INX	H
	INX	H
	MOV	M,D
	INX	H
	MOV	M,E
	INX	H
	MVI	M,20		;MISSILE LIFE
	LDA	SHIPX
	STA	MISLX
	LDA	SHIPY
	STA	MISLY
	LXI	H,PMISSL
	CALL	MYOS		;PLOT MISSLE 1ST TIME
CHKMSL:	LDA	MISCNT
	CPI	0
	JZ	BIG		;NO MISSLES, LOOP AGAIN
	LXI	H,MISTBL
	MVI	A,1
MLOOP:	CPI	6
	JP	BIG		;DONE W/MISSLES
	STA	MTEST
	SHLD	HOLD3
	MOV	A,M
	CPI	1
	JNZ	NEXMIS		;NO DATA, GET NEXT MISSLE
	INX	H
	MOV	A,M
	STA	MX
	INX	H
	MOV	A,M
	STA	MY
	INX	H
	MOV	A,M
	STA	MXI
	INX	H
	MOV	A,M
	STA	MYI
	INX	H
	MOV	A,M
	STA	MC		;GET #TIMES MISSLE
	LDA	MX
	STA	ERASX
	STA	ERASX2
	LDA	MY
	STA	ERASY
	STA	ERASY2
	LXI	H,MERAS
	CALL	MYOS		;ERASE OLD MISSLE
	LXI	H,MERAS2
	CALL	MYOS		;FINISH ERASING
	LDA	MC
	SUI	1
	CPI	0
	JZ	MDEAD		;MISSLE DEAD, CLEAR IT!
	STA	MC
	LDA	MX
	MOV	C,A
	LDA	MXI
	ADD	A
	ADD	C
	ANI	127
	STA	MX
	LDA	MY
	MOV	C,A
	LDA	MYI
	ADD	A
	ADD	C
	ANI	127
	STA	MY
	LDA	MX
	STA	MISLX
	LDA	MY
	STA	MISLY
	LXI	H,PMISSL
	CALL	MYOS		;PLOT NEW MISSLE
	LHLD	HOLD3
	INX	H
	LDA	MX
	MOV	M,A
	INX	H
	LDA	MY
	MOV	M,A
	INX	H
	LDA	MXI
	MOV	M,A
	INX	H
	LDA	MYI
	MOV	M,A
	INX	H
	LDA	MC
	MOV	M,A
NEXMIS:	LDA	MTEST
	ADI	1
	LHLD	HOLD3
	LXI	D,6
	DAD	D
	JMP	MLOOP

;
;	THIS ROUTINE IS USED WHEN A MISSLE HAS GONE AS FAR
;	AS IT IS ALLOWED.  IT DELETES THE MISSLE FROM THE
;	MISSLE TABLE AND DECREMENTS THE MISSLE COUNT.
;
MDEAD:	LHLD	HOLD3
	MVI	M,0		;RESET 'ON' FLAG
	LDA	MISCNT		;GET # MISSLES AND...
	SUI	1		;SUBTRACT 1 FROM IT,
	STA	MISCNT		;STORE IT BACK!
	JMP	NEXMIS
;
;THE FOLLOWING ROUTINE CHECKS TO SEE IF IT'S OK TO PLACE THE
;SHIP IN THE ASTEROID FIELD.

CHKOK:	LDA	BIGNO
	CPI	0		;ANY BIG?
	JZ	CHKOK2		;NO, GO CHECK SMALL
	LXI	H,30262		;THIS SECTION SETS UP INFO IN
	MVI	M,32
	INX	H
	MVI	M,70		;SCREEN RAM TO CHECK FOR THE
	INX	H		;COLLISION OF THE SHIP WITH
	MVI	M,32		;AN ASTEROID
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	LXI	D,115
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	MOV	B,A		;GET # BIG IN B
	LXI	H,BIGTBL	;POINT TO BIG AST TABLE
GETNXT:	SHLD	HOLD1
	CALL	GETIT
	MVI	C,20		;SCAN 20 TIMES IN ADVANCE
	LHLD	HPOS
NEXTP1:	INX	H
	MOV	A,M
	CPI	70
	JZ	COLL		;AST WILL HIT SHIP!
	DCR	C
	JZ	NXTCK1
	CALL	INCAST
	SHLD	HPOS
	JMP	NEXTP1
NXTCK1:	DCR	B		;ANY MORE BIG?
	JZ	CHKOK2		;NO, CHECK SMALL
	LHLD	HOLD1
	LXI	D,4
	DAD	D
	JMP	GETNXT		;DO NEXT AST
CHKOK2:	LDA	SMLNO		;GET # SMALL
	CPI	0		;ANY SMALL?
	JZ	AOK		;NO, COAST IS CLEAR!
	LXI	H,30262
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	LXI	D,115
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	DAD	D
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	INX	H
	MVI	M,32
	INX	H
	MVI	M,70
	MOV	B,A
	LXI	H,SMLTBL
GETNXT2:SHLD	HOLD1
	CALL	GETIT
	MVI	C,20
	LHLD	HPOS
NEXTP2:	INX	H
	MOV	A,M
	CPI	70
	JZ	COLL		;AST WILL HIT SHIP!
	DCR	C
	JZ	NXTCK2		;DONE W/20 CHECKS
	CALL	INCAST		;NEXT POS
	SHLD	HPOS
	JMP	NEXTP2
NXTCK2:	DCR	B		;ANY MORE SMALL?
	JZ	AOK		;NO, COAST IS CLEAR!
	LHLD	HOLD1
	LXI	D,4
	DAD	D		;POINT TO NEXT AST
	JMP	GETNXT2
AOK:	MVI	A,1
	STA	GOING		;WE'RE GOING NOW!
	STA	DCOUNT
	RET
COLL:	MVI	A,21		;GET # TIMES TO CYCLE BEFORE
	SUB	C		;NEXT CHECK
	STA	DCOUNT
	RET
BOOM1:	LDA	LAST
	CALL	PSHIP
	LDA	SHIPX
	STA	BOOMX
	LDA	SHIPY
	STA	BOOMY
	LXI	H,PBOOM
	CALL	MYOS
	LXI	H,PBOOM
	CALL	MYOS
	CALL	SOUND2
	CALL	DELAY3
	CALL	DELAY2
	LDA	SHIPCNT
	SUI	1
	STA	SHIPCNT
	LDA	KILLS
	ADI	1
	STA	KILLS
	CPI	3
	JM	CLREST
	MVI	A,1
	STA	ENDFL
	JMP	BIG
BOOM2:	MVI	M,4		;CLEAR CRT POS. AT COLL.
	DCX	H
	MVI	M,32
	SHLD	HBOOM		;STORE AST CRT POS.
	LDA	MISCNT		;GET # MISSLES
	CPI	0		;ANY MISSLES?
	JZ	BERROR		;OOOPS!
	STA	TMPMIS
	LXI	H,MISTBL	;POINT TO MISSLE TABLE
;
;	THIS ROUTINE FINDS OUT WHICH MISSLE HIT THE ASTEROID
;
FINDIT:	MOV	A,M		;GET MISSLE FLAG
	CPI	1		;IS IT A 'LIVE' MISSLE?
	JZ	GOTIT		;YES!
	LXI	D,6		;NO,...
	DAD	D		;INCREMENT TO NEXT MISSLE
	JMP	FINDIT
GOTIT:	INX	H
	PUSH	H		;SAVE ADDR OF MISSLE IN TBL
	MOV	A,M		;GET MISSLE X CO-ORD...
	ANI	254		;MAKE IT EVEN...
	MOV	L,A		;SET UP HL WITH X...
	MVI	H,0		;FOR LATER
	SHLD	XWORK		;STORE IT!
	POP	H		;GET ADDR BACK,
	INX	H		;INCREMENT TO MISSLE Y
	PUSH	H		;SAVE AGAIN!
	MOV	E,M		;GET Y CO-ORD
	MVI	D,0		;FOR DIVIDE
	LXI	H,4		;BY 4...
	CALL	DIVHD		;DIVIDE IT!
	XCHG			;SWAP DE & HL FOR SUB.
	LXI	H,31		;SET UP HL FOR SUBTRACT...
	CALL	SUBHD		;SUBTRACT AMT. FROM 31
	LXI	D,128		;SET UP FOR MULTIPLY...
	CALL	MULHD		;MULTIPLY IT!
	XCHG
	LHLD	XWORK		;GET EARLIER COMPUTATION
	DAD	D		;ADD TO IT FOR DISPLACEMENT
	LXI	D,28672		;GET BASE (LOW CRT MEM)
	DAD	D		;ADD TO DISPLACEMENT - TA-DA!!
	XCHG
	LHLD	HBOOM		;GET ADDR OF COLLISION
	CALL	SUBHD		;GET DIFF. BET. MISSLE & COLL.,
				;IF ZERO, THIS IS THE MISSLE!
	MOV	A,H
	CPI	0		;IS THIS IT?
	JNZ	NOTIT		;NO!
	MOV	A,L		;COULD BE...
	CPI	0		;IS THIS IT?
	JZ	BCLEAR		;YES!!!
NOTIT:	LDA	TMPMIS		;NO, TRY NEXT MISSLE
	SUI	1		;ANY MORE MISSLES?
	JZ	BERROR		;OOPS! THERE SHOULD BE!
	STA	TMPMIS
	POP	H		;GET POINTER TO MISSLE TABLE
	LXI	D,4
	DAD	D		;INCREMENT TO NEXT MISSLE
	JMP	FINDIT
BERROR:	POP	H		;DISCARD
	LXI	H,ERR2
	CALL	MYOS		;PRINT ERROR MSG
FOREVR:	JMP	FOREVR			;SUSPEND PROGRAM
BCLEAR:	POP	H
	DCX	H
	DCX	H
	MVI	M,0		;BACK UP, CLEAR MISSLE FLAG
	MVI	A,1		;SET UP...
	STA	SOUND		;...FOR SOUND CLICK
	LDA	MISCNT
	SUI	1		;1 LESS MISSLE
	STA	MISCNT
	LDA	ATYPE		;WHAT TYPE ASTEROID?
	CPI	1		;BIG?
	JZ	CLRBIG		;YES, GET RID OF IT!
;
;	CLEAR SMALL ASTEROID
;
	LHLD	SCORE2
	LXI	D,100
	DAD	D
	SHLD	SCORE2
	LHLD	SCORE
	DAD	D
	SHLD	SCORE
	CALL	PSCORE
	LHLD	HPOS		;GET AST CRT POS.
	MVI	M,32		;CLEAR BYTE 1
	INX	H
	MVI	M,4		;COLOR BYTE
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	CALL	REPACK		;REPACK ASTEROID TABLE
	LDA	SMLNO
	SUI	1		;1 LESS SMALL AST
	STA	SMLNO
	DCR	B
	MOV	D,A		;MOVE COUNT TO D
	LDA	BIGNO		;GET # BIG ASTS
	ADD	D		;ADD 'EM
	JZ	RERND		;NO ASTS LEFT, RE-RANDOMIZE
	MOV	A,B
	CPI	0		;ANY SMALL?
	JZ	MOVCHK		;NO, MOVE SHIP
	LHLD	HOLD1		;YES, GET TABLE POINTER...
	JMP	LOOP3		;AND DO THE NEXT ONE!
CLRBIG:	LHLD	SCORE2
	LXI	D,50
	DAD	D
	SHLD	SCORE2
	LHLD	SCORE
	DAD	D
	SHLD	SCORE
	CALL	PSCORE		;UPDATE SCORE
	LHLD	HPOS		;GET CRT POS.
	MVI	C,3		;SET UP COUNTER
CLRB1:	MVI	M,32		;CLEAR OLD CRT IMAGE
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	INX	H
	MVI	M,32
	INX	H
	MVI	M,4
	DCR	C		;SUB 1 --- DONE?
	JZ	REPAK2		;YES, REPACK TABLE!
	MVI	A,123
	CALL	ADHLA		;INCREMENT HL TO NEXT SECTION
	MOV	A,H
	CPI	80H
	JM	CLRB1	;NOT OFF SCREEN, DO IT AGAIN!
	LXI	D,1000H
	CALL	SUBHD
	JMP	CLRB1
REPAK2:	CALL	REPACK		;REPACK BIG TABLE
	LDA	BIGNO
	SUI	1
	STA	BIGNO
	DCR	B		;DECREMENT COUNTER
	PUSH	B		;SAVE COUNTER
	LDA	SMLNO
	MOV	B,A
	LXI	H,SMLTBL
FOPEN:	MOV	A,B
	CPI	0
	JZ	MOVEIN		;DONE CLEARING
	LXI	D,4
	DAD	D
	DCR	B
	JMP	FOPEN		;CHECK AGAIN
MOVEIN:	MVI	B,4		;WE WANT 4 ASTEROIDS
	SHLD	SMLPTR		;SAVE TABLE INDEX
	CALL	RNDLOOP
	LHLD	HBOOM
	XCHG
	LHLD	SMLPTR
	MVI	A,0
NEXT2:	MOV	M,E		;THIS SECTION REPLACES
	INX	H		;RANDOM LOCATIONS IN
	MOV	M,D		;THE ASTEROID TABLE
	INX	H		;WITH ORDERLY LOCATIONS
	INX	H		;DERIVED FROM THE CRT
	INX	H		;LOCATION OF THE DESTROYED
	INX	D		;BIG ASTEROID.
	INX	D		;THIS SECTION IS PERFORMED
	MOV	M,E		;TWICE, ONCE FOR EACH
	INX	H		;ROW OF NEW ASTEROIDS.
	MOV	M,D		;THUS:
	CPI	1
	JZ	DUNSML
	INX	H		; ###      ## ##
	INX	H		; # #  =
	INX	H		; ###      ## ##
	PUSH	H
	XCHG
	MVI	A,122
	CALL	ADHLA
	MOV	A,H
	CPI	80H
	JNZ	SMALLOK
	PUSH	D
	LXI	D,1000H
	CALL	SUBHD
	POP	D
SMALLOK:XCHG
	POP	H
	MVI	A,1		;SET 'A' FOR AN EXIT NEXT TIME
	JMP	NEXT2
DUNSML:	LDA	SMLNO
	ADI	4		;INCREMENT # SMALL
	STA	SMLNO
	POP	B		;RESTORE LOOP COUNTER
	LDA	BIGNO
	CPI	0
	JZ	SMALL		;NO BIG ASTEROIDS LEFT
	MOV	A,B
	CPI	0
	JZ	SMALL		;NONE LEFT, DO SMALL
	LHLD	HOLD1
	JMP	LOOP1		;MORE TO GO, DO THEM
REPACK:	LHLD	HOLD1
	MOV	A,B
	CPI	0
	RZ
	STA	RPKHLD
REPAK1:	SHLD	REPAK
	LXI	D,4
	DAD	D
	CALL	GETIT
	LHLD	REPAK
	CALL	PUTIT
	LDA	RPKHLD
	SUI	1
	RZ
	STA	RPKHLD
	LHLD	REPAK
	DAD	D
	JMP	REPAK1
CLRCHK:	MOV	A,M
	CPI	0
	JZ	OKCLR1
	INX	H
	MOV	A,M
	CPI	128
	JP	CKBOOM
	DCX	H
OKCLR1:	MVI	M,32
	RET
CKBOOM:	POP	D
	CPI	135
	JZ	BOOM1
	CPI	131
	JZ	BOOM2
	PUSH	D
	DCX	H
	JMP	OKCLR1
BACCHK:	MOV	A,M
	CPI	0
	JZ	OKBAC1
	INX	H
	MOV	A,M
	CPI	128
	JP	CKBOOM1
	DCX	H
OKBAC1:	LDAX	D
	MOV	M,A
	RET
CKBOOM1:INX	SP
	INX	SP		;DISCARD TOP OF STACK
	CPI	135		;WHITE?
	JZ	BOOM1		;YES, DESTROY SHIP
	CPI	131		;YELLOW?
	JZ	BOOM2		;YES, MISSLE HIT!
	DCX	SP		;NO HIT, PUT TOP OF
	DCX	SP		;STACK BACK
	DCX	H		;POINT BACK TO CHAR BYTE
	JMP	OKBAC1		;NOW IT'S OK!
INCAST:	LHLD	HPOS
	LDA	HSIGN
	CPI	0
	JZ	ADDINC		;POSITIVE INC., ADD IT
	MVI	D,0
	LDA	HINC
	MOV	E,A
	CALL	SUBHD
	LXI	D,6FFFH
	MOV	A,H
	CMP	D
	JNZ	ENDCMP
	MOV	A,L
	CMP	E
ENDCMP:	RP
	MOV	A,H
	ADI	10H
	MOV	H,A
	RET
ADDINC:	LDA	HINC
	ADD	L
	MOV	L,A
	RNC
	INR	H
	MOV	A,H
	CPI	80H		;OFF CRT?
	RM			;NO, RETURN
	LXI	D,1000H		;YES, DROP IT BACK 1000H
	CALL	SUBHD		;SUBTRACT
	RET
DELAY:	PUSH	D
	PUSH	H
	LXI	H,02H
	MVI	D,20
	MVI	E,0
DL1:	DCX	H
	MOV	A,L
	CPI	0
	JZ	ENDELAY
DL2:	DCX	D
	MOV	A,D
	CPI	0
	JZ	DL1
	JMP	DL2
ENDELAY:POP	H
	POP	D
	RET
DELAY2:	PUSH	D
	PUSH	H
	LXI	H,10H
	LXI	D,2000H
	JMP	DL1
DELAY3:	PUSH	D
	PUSH	H
	LXI	H,0FFFFH
	LXI	D,0FFFFH
	JMP	DL1
SOUND2:	LX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STA	HPOS2
R3:	CALL	GETINC
	STA	HINC
	CALL	RANNUM
	ANI	1
	STA	HSIGN
	LHLD	RHOLD
	CALL	PUTIT
	DCR	B
	RZ
	LHLD	RHOLD
	LXI	D,4
	DAD	D
	JMP	RNDLOOP
RANNUM:	LXI	H,RNDVAL
	MOV	A,M
	RLC
	XRA	M
	RRC
	INR	L
	INR	M
	ADD	M
	JPE	RSKIP
	INR	M
RSKIP:	DCR	L
	MOV	M,A
	RET
GETINC:	CALL	RANNUM
	CPI	0
	JZ	GETINC
	ANI	7
	CPI	1
	JP	CR2
	MVI	A,2
	JMP	SAVEIT
CR2:	CPI	2
	JP	CR3
	MVI	A,4
	JMP	SAVEIT
CR3:	CPI	3
	JP	CR4
	MVI	A,124
	JMP	SAVEIT
CR4:	CPI	4
	JP	CR5
	MVI	A,126
	JMP	SAVEIT
CR5:	CPI	5
	JP	CR6
	MVI	A,128
	JMP	SAVEIT
CR6:	CPI	6
	JP	CR7
	MVI	A,130
	JMP	SAVEIT
CR7:	MVI	A,132
SAVEIT:	RET
PSCORE:	PUSH	B
	PUSH	H
	LXI	H,SCOBUF
	MVI	M,48
	INX	H
	MVI	M,48
	INX	H
	MVI	M,48
	INX	H
	MVI	M,48
	INX	H
	MVI	M,48
	POP	H
	LXI	B,SCOBUF+4
PSCLOOP:LXI	D,10
	XCHG
	CALL	DIVHD
	MOV	A,E
	ADI	48
	STAX	B
	DCX	B
	XRA	A
	CMP	L
	JNZ	PSCLOOP
	CMP	H
	JNZ	PSCLOOP
	POP	B
	LHLD	SCORE2
	MOV	A,H
	CPI	27H
	RM
	MOV	A,L
	CPI	10H
	RM
	LXI	D,10000
	CALL	SUBHD
	SHLD	SCORE2
	LDA	SHIPCNT
	ADI	1
	STA	SHIPCNT
	LDA	KILLS
	SUI	1
	STA	KILLS
	RET

;************************ DATA AREAS *************************

SCORE:	DS	2
SCORE2:	DS	2
SCOPRT:	DB	'SCORE: '
SCOBUF:	DB	48,48,48,48,48
RESTRT:	DB	0
GOING:	DS	1
DCOUNT:	DS	1
PMISSL:	DB	30,6,3,2
MISLX:	DS	1
MISLY:	DS	1
	DB	255,254
RNDVAL:	DB	12
RNDINC:	DB	2
HPOS:	DS	1
HPOS2:	DS	1
HINC:	DS	1
THRUST:	DS	1
SINC:	DS	2
WINC:	DS	2
SMLPTR:	DS	2
HSIGN:	DS	1
HOLD1:	DS	2
HOLD2:	DS	2
FIRST:	DS	1
LAST:	DS	1
HROT:	DB	0
BIGNO:	DB	0
RHOLD:	DS	2
ERR2:	DB	6,1,'MISSILE NOT FOUND!',254
ATYPE:	DS	1
BAIMAG:	DB	20,5,28,1,32,2,28,31,23
SAIMAG:	DB	3,4
SMLNO:	DB	0
DIFTBL1:DB	14,13,12,11,10,9,8,7,6
DIFTBL2:DB	1,2,3,4,5,6,7,8,9
DIFF:	DS	1
TMPMIS:	DS	1
XWORK:	DS	2
HBOOM:	DS	2
KILLS:	DS	1
SHIPCNT:DS	1
SOUND:	DB	1
SOUNDWK:DB	8
REPAK:	DS	2
RPKHLD:	DS	1
SHIPX:	DB	64
SHIPY:	DB	64
PSTART1:DB	29,6,7,2
PLOTX:	DS	1
PLOTY:	DS	1
	DB	251,254
PR1:	DB	2,34,162,144,17,17,255,254
PR2:	DB	42,42,161,129,21,1,255,254
PR3:	DB	170,136,17,85,255,254
PR4:	DB	136,145,85,4,255,254
PR5:	DB	136,153,85,68,255,254
PR6:	DB	137,145,84,4,255,254
PR7:	DB	153,17,68,102,255,254
PR8:	DB	25,17,82,70,38,2,255,254
PR9:	DB	17,21,1,96,34,34,255,254
PR10:	DB	21,21,82,66,42,2,255,254
PR11:	DB	85,68,34,170,255,254
PR12:	DB	68,98,170,8,255,254
PR13:	DB	68,102,170,136,255,254
PR14:	DB	70,98,168,8,255,254
PR15:	DB	102,34,136,153,255,254
PR16:	DB	38,34,161,137,25,1,255,254
CLRCRT:	DB	30,6,4,12,254
SNDTBL:	DB	50,18,40,24,52,20,41,26,54,22,43,29
	DB	58,28,46,33,64,34,50,42,70,44,60,50
	DB	76,52,65,56,82,62,74,65,100,100,105,120
	DB	130,152,140,160,230,240,0,0
PBOOM:	DB	30,6,1,2
BOOMX:	DS	1
BOOMY:	DB	1
	DB	251,40,17,68,34,10,128,8,16,1,16,1
	DB	64,4,64,4,32,2,32,2,160,8,128,128
	DB	8,16,16,1,16,16,1,64,64,4,64,64,4
	DB	32,32,2,32,32,2,160,128,8
	DB	128,128,128,8,16,16,16,1,16,16,16,1
	DB	64,64,64,4,64,64,64,4,32,32,32,2
	DB	32,32,32,2,160,128,128,8,144,144
	DB	144,144,9,80,80,80,80,5,96,96,96,96,6
	DB	96,2,160,160,160,2,128,128,128,128
	DB	128,8,144,144,144,1,16,16,16,16,1
	DB	80,80,80,4,64,64,64,64,4,96,96,96,2
	DB	255,254
TPAGE:	DB	6,39,12,14,3,29,15,'ASTEROIDS',2,56,60,242
	DB	56,75,77,75,77,60,56,60,255,15,3,24,18
	DB	6,35,'1980 BY TOM HUDSON',254
ENDMSG:	DB	3,128,23,27,65,'*** GAME OVER ***',27,27,239
ENDFL:	DS	1
STFLAG:	DS	1
STRTMSG:DB	3,128,16,15,3,'ENTER NUMBER OF ASTEROIDS (1-9)'
	DB	27,27,239
MX:	DS	1
MY:	DS	1
MXI:	DS	1
MYI:	DS	1
MC:	DS	1
MCHECK:	DB	0
MTEST:	DB	0
MERAS:	DB	29,6,0,2
ERASX:	DS	1
ERASY:	DS	1
	DB	255,254
MERAS2:	DB	30,6,0,2
ERASX2:	DS	1
ERASY2:	DS	1
	DB	255,254
MISCNT:	DB	0
HOLD3:	DS	2
MISTBL:	DS	35
BIGTBL:	DS	40
SMLTBL:	DS	150
	END	START