Compucolor.org – Virtual Media

Listing of file='FIREJ.MAC;22' on disk='vmedia/dogfight-sector.ccvf'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	FIRCTL - FIRE CONTROL ROUTINE
;
;	   DOES ALL THE SHOOTING AT SHIPS. INTERNAL HIT
;	   AND SHOT COUNTERS ARE PUBLIC, AS ARE THE
;	   MESSAGES THAT PRINT THEM. MAKES SOUNDS FOR THE
;	   SHOT AND EXPLOSIONS (HITS). THE COUNT TO BE USED
;	   IN DEBOUNCING THE PUSH-BUTTON IS PUBLIC.
;
;		*** JOYSTICK VERSION ***
;
;	(USES JOYSTICK FOR BOTH DISTANCE AND DIRECTION)
;
	TITLE	FIRCTL

	ENTRY	FIRCTL

	PUBLIC	FIRCNT,HITCNT,FIRMSG,HITMSG,DBCNT

;
;	VALUES ON ENTRY:
;	   IRRELEVANT
;
;	RETURNS:
;	   NOTHING - HITS AND SHOTS FIRED ARE PUBLIC
;
;	DESTROYS:
;	   ALL REGISTERS
;
;
;	EXTERNALS - REQUIRED SUBROUTINES
;
	EXTRN	DECOUT	;CONVERTS A BYTE TO ASCII DECIMAL NO.
	EXTRN	DELAY	;WASTE TIME
	EXTRN	RANDOM	;RANDOM NUMBER GENERATOR
	EXTRN	GENSND,FINFLG
			;SOUNDWARE ROUTINE AND PUBLICS
	EXTRN	BOOM

	EXTRN	OSTR	;OUTPUT A STRING
	EXTRN	JOYSTK,PSHBUT	;JOYSTICK ROUTINES

;
;	THE FOLLOWING ARE IN THE MAIN PROGRAM:
;

	EXTRN	SCT,HLSCT,GRPTR,XPOS,YPOS
	EXTRN	XPLCNT,EXPLDE
	EXTRN	XSPD,XDIRN,YSPD,YDIRN

;
;	PROGRAM PARAMETERS
;

SHPHGT	EQU	3
SHPWID	EQU	14
ADJDEL	EQU	30	;DELAY TO ADJUST TIMING FOR WHEN A SHOT
			;  IS NOT FIRED. SHOULD BALANCE OUT THE
			;  TIME TAKEN IF A SHOT IS FIRED.

;..............................................................

FIRCTL:	LDA	SHOT2
	ORA	A
	JZ	FIRC10
	LXI	H,SH2MSG
	CALL	OSTR
	XRA	A
	STA	SHOT2
	LDA	XPOS
	ADI	SHPWID/4
	CPI	31
	JC	FIRC10
	CPI	34
	JNC	FIRC10
	LDA	YPOS
	ADI	SHPHGT/2
	CPI	14
	JC	FIRC10
	CPI	17
	JNC	FIRC10
	MVI	A,30
	CALL	BOOM
	LDA	XPLCNT
	ORA	A
	JNZ	FIRC20
	LXI	H,HITCNT	;EXPLOSION
	INR	M
	MOV	A,M
	LXI	H,HITS
	CALL	DECOUT
	LXI	H,HITMSG
	CALL	OSTR
	MVI	A,SHPWID/2
	CALL	RANDOM
	RLC
	MOV	E,A
	XRA	A
	MOV	D,A
	LXI	H,EXPLDE
	DAD	D
	SHLD	GRPTR
	MVI	A,10
	CALL	RANDOM
	ADI	2
	STA	XPLCNT
	JMP	FIRC20
FIRC10:	MVI	A,ADJDEL
	CALL	DELAY
FIRC20:	LXI	H,SH3MSG
	CALL	OSTR
FIRC30:	LDA	SHOT1
	ORA	A
	JZ	FIRC35
	LXI	H,SH1MSG
	CALL	OSTR
	MVI	A,0FFH
	STA	SHOT2
	XRA	A
	STA	SHOT1
	JMP	FIRC40
FIRC35:	MVI	A,ADJDEL/2
	CALL	DELAY

FIRC40:	LDA	DEBNCE	;DEBOUNCE THE PUSH-BUTTON
	ORA	A
	JZ	MOVE
	DCR	A
	STA	DEBNCE
	JMP	BUTT50
MOVE:	XRA	A	;SET JOYSTICK NO. ZERO
	CALL	JOYSTK	;READ POSITION
	PUSH	B	;SAVE X-Y COORDS
	MOV	A,B
	CALL	ACCEL
	STA	XSPD	;SAVE IT
	MOV	A,C
	STA	XDIRN

	POP	B	;GET BACK Y-COORD
	MOV	A,C
	CALL	ACCEL
	STA	YSPD
	MOV	A,C
	STA	YDIRN

	XRA	A	;NO. ZERO
	CALL	PSHBUT	;CHECK PUSH-BUTTON
	JNZ	BUTT40
	LXI	H,FIRCNT	;INCREMENT COUNT OF SHOTS FIRED
	INR	M
	MOV	A,M
	LXI	H,FIRED		;AND PRINT MESSAGE
	CALL	DECOUT
	LXI	H,FIRMSG
	CALL	OSTR
	CALL	MCHGUN	;MAKE A MACHINE-GUN SOUND
BUTT40:	LDA	DBCNT	;RESTORE THE DEBOUNCE COUNT
	STA	DEBNCE
	RET

BUTT50:	MVI	A,ADJDEL*2	;ADJUST TIMING IF NO SHOT FIRED
	CALL	DELAY
	RET

;
;	"ACCELERATOR" ROUTINE
;

ACCEL:	MVI	B,3	;DIVIDE BY 8
	SUI	128
	JM	ACC20
ACC10:	RRC
	ANI	7FH
	DCR	B
	JNZ	ACC10
	MOV	B,A
	ORA	A
	JZ	ACC40
	MVI	A,10H
	SUB	B
	MVI	C,1
	RET
ACC20:	CMA
	ADI	1
	CPI	128
	JNZ	ACC30
	MVI	A,127
ACC30:	RRC
	ANI	7FH
	DCR	B
	JNZ	ACC30
	MOV	B,A
	ORA	A
	JZ	ACC40
	MVI	A,10H
	SUB	B
	MVI	C,-1
	RET
ACC40:	MVI	A,10
	MVI	C,0
	RET
;
;	MAKE MACHINE-GUN SOUND AND FIRE BULLETS
;

MCHGUN:	DI		;SETUP FOR NOISE ON THE SOUND
	MVI	A,7
	OUT	30H
	MVI	A,36H
	OUT	31H
	MVI	A,6
	OUT	30H
	XRA	A
	OUT	31H
	EI

	MVI	A,0FFH
	STA	SHOT1
	LXI	H,GUNMSG
	CALL	OSTR
	LXI	H,WHITE
	CALL	OSTR
	MVI	A,5
	LXI	H,BULT1
	LXI	D,LENBUL

MCG10:	PUSH	PSW
	PUSH	D
	PUSH	H
	LXI	H,40
	MVI	D,1
	MVI	E,1
	MVI	B,4
	MVI	C,0
	MVI	A,20
	CALL	GENSND

MCG20:	LDA	FINFLG
	ORA	A
	JZ	MCG20
	POP	H
	POP	D
	DAD	D
	PUSH	H
	CALL	OSTR
	POP	H
	POP	PSW
	DCR	A
	JNZ	MCG10
	LXI	H,NOGNMG
	CALL	OSTR
	RET

;..............................................................
;
;	DATA AREA
;

DBCNT:	DB	1	;COUNT FOR DEBOUNCING
DEBNCE:	DB	1	;DEBOUNCE COUNTER
FIRCNT:	DB	0	;COUNT OF SHOTS FIRED
HITCNT:	DB	0	;COUNT OF HITS

SHOT1:	DB	0	;FLAGS FOR BULLETS IN FLIGHT
SHOT2:	DB	0

;
;	MESSAGES
;

FIRMSG:	DB	15,3,100,10,30,2,'FIRED',3,100,11,31,2
FIRED:	DB	'000',239	;SHOTS FIRED

HITMSG:	DB	15,3,100,50,30,2,'HITS',3,100,51,31,2
HITS:	DB	'000',239	;NUMBER OF HITS

WHITE:	DB	6,7,239
BLACK:	DB	6,0,239

GUNMSG:	DB	6,41H,3,16,31,64H,3,48,31,64H,239

NOGNMG:	DB	6,0,3,16,31,20H,3,48,31,20H,239

;
;	PLOTTED POINTS FOR THE BULLETS
;

BULT1:	DB	2,96,4,33,4,255,239

LENBUL	EQU	$-BULT1

BULT2:	DB	2,90,14,39,14,255,239
BULT3:	DB	2,85,24,44,24,255,239
BULT4:	DB	2,81,32,48,32,255,239
BULT5:	DB	2,77,40,52,40,255,239

SH1MSG:	DB	6,0,2,96,4,33,4,255
	DB	6,7
BULT6:	DB	2,74,46,55,46,255
	DB	6,0,2,90,14,39,14,255
	DB	6,7
BULT7:	DB	2,72,50,57,50,255
	DB	6,0,2,85,24,44,24,255
	DB	6,7
BULT8:	DB	2,70,54,59,54,255
	DB	6,0,2,81,32,48,32,255
	DB	6,7
BULT9:	DB	2,68,58,61,58,255
	DB	6,0,2,77,40,52,40,255
	DB	6,7
BULT10:	DB	2,67,60,62,60,255,239

SH2MSG:	DB	6,0,2,74,46,55,46,255
	DB	6,7
BULT11:	DB	2,66,62,63,62,255
	DB	6,0,2,72,50,57,50,255
	DB	6,7
BULT12:	DB	2,65,64,64,64,255
	DB	6,0,2,70,54,59,54,255
	DB	6,7
BULT13:	DB	2,65,65,64,65,255
	DB	6,0,2,68,58,61,58,255
	DB	6,7
BULT14:	DB	2,65,66,64,66,255
	DB	6,0,2,67,60,62,60,255
	DB	6,7
BULT15:	DB	2,65,67,64,67,255,239

SH3MSG:	DB	6,0,2
	DB	66,62,63,62
	DB	65,64,64,64
	DB	65,65,64,65
	DB	65,66,64,66
	DB	65,67,64,67
	DB	255,239

	END