Compucolor.org – Virtual Media

Listing of file='FIREK.MAC;0A' on disk='vmedia/laser_gun_keyboard-sector.ccvf'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	FIRCTL - FIRE CONTROL ROUTINE
;
;	   DOES ALL THE SHOOTING AT THE SHIPS. KEEPS SCORE
;	   AND RECORDS NUMBER OF SHOTS FIRED. THESE ARE
;	   PUBLIC, AS ARE THE MESSSAGES THAT PRINT THEM.
;	   MAKES SOUNDS FOR SHOTS AND HITS.
;
;	*** KEYBOARD VERSION - USES NUMERIC KEYPAD ***
;
	TITLE	FIRCTL

	ENTRY	FIRCTL

	PUBLIC	FIRCNT,HITCNT,FIRMSG,HITMSG,DBCNT
	PUBLIC	X,Y

;
;	VALUES ON ENTRY:
;	   IRRELEVANT
;
;	RETURNS:
;	   NOTHING - NUMBER OF HITS AND SHOTS FIRED ARE PUBLIC
;
;	DESTROYS:
;	   ALL REGISTERS
;
;
;	EXTERNALS :- REQUIRED SUBROUTINES
;
	EXTRN	CHKSHP	;CHECK FOR A HIT ON A SHIP
	EXTRN	DECOUT	;CONVERT A BYTE TO ASCII DECIMAL NUMBER
	EXTRN	DELAY	;WASTE TIME
	EXTRN	SOUND,PITCH,DURN,NSTEPS,STEP1,STEP2
			;SOUNDWARE ROUTINE AND PUBLICS
	EXTRN	SCNDIG	;*** FOR KEYBOARD VERSION ONLY ***
			;SCANS KEYBOARD FOR DEPRESSED KEYS

	EXTRN	OSTR	;OUTPUT A STRING

	EXTRN	SCT,HLSCT,BMPSCT,NSHIP	;IN MAIN PROGRAM

;
;	EQUATES :-
;
;	PROGRAM PARAMETERS
;

ADJDEL	EQU	50	;DELAY TO ADJUST TIMING FOR WHEN A SHOT
			;  IS NOT FIRED. SHOULD BALANCE OUT THE
			;  TIME TAKEN IF A SHOT IS FIRED.

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

FIRCTL:	LDA	DEBNCE	;DEBOUNCE THE KEYBOARD
	ORA	A
	JZ	BUTTON
	DCR	A
	STA	DEBNCE
	JMP	BUTT50	;ADJUST TIMING
BUTTON:	CALL	SCNDIG	;SEE IF KEY DEPRESSED
	JNC	BUTT50	;SKIP IF NOT, AND ADJUST TIMING
	ORA	A
	JZ	BUTT50	;IGNORE 0 AND 5 KEYS
	CPI	5
	JZ	BUTT50
BUTT10:	LXI	H,DIRTBL	;INDEX INTO THE DIRECTION TABLE
	MOV	E,A
	XRA	A
	MOV	D,A
	DAD	D
	DAD	D	;(ENTRIES ARE 2 BYTES LONG)
BUTT20:	MOV	E,M	;PICK UP X,Y COORDS
	INX	H
	MOV	D,M
	XCHG
	SHLD	X	;AND STORE IN BEAM COORDS
	LXI	H,WHITE	;SET COLOR
	CALL	OSTR
	LXI	H,BEAM	;DRAW THE LASER BEAM
	CALL	OSTR
	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	LASER	;MAKE A LASER SOUND
	LXI	H,SCT
	LDA	NSHIP	;GET NUMBER OF SHIPS
	DCR	A	;LEAVE ONE ALONE
	MOV	B,A
	JNZ	BUTT30
	INR	B	;MAKE SURE AT LEAST ONE
BUTT30:	PUSH	B
	SHLD	HLSCT
	CALL	CHKSHP	;SCAN EACH SHIP FOR A HIT
	JNZ	BUTT35
	LXI	H,HITCNT	;INCREMENT SCORE IF A HIT
	INR	M
	MOV	A,M
	LXI	H,HITS		;AND DISPLAY THE HIT COUNT
	CALL	DECOUT
	LXI	H,HITMSG
	CALL	OSTR
	CALL	BOOM	;MAKE EXPLOSION SOUND
	JMP	BUTT40
BUTT35:	MVI	A,ADJDEL	;ADJUST TIMING IF NO HIT
	CALL	DELAY
BUTT40:	LHLD	HLSCT
	CALL	BMPSCT	;STEP THROUGH SHIP CONTROL TABLE
	POP	B
	DCR	B
	JNZ	BUTT30
	LXI	H,BLACK	;SET COLOR TO BLACK
	CALL	OSTR
	LXI	H,BEAM	;AND ERASE THE LASER BEAM
	CALL	OSTR
	LDA	DBCNT	;RESTORE THE DEBOUNCE COUNT
	STA	DEBNCE
	RET
BUTT50:	LDA	NSHIP	;GET NUMBER OF TIMES THRU MAIN LOOP
	MOV	B,A
BUTT60:	MVI	A,ADJDEL	;ADJUST TIMING IF NO SHOT FIRED
	CALL	DELAY
	DCR	B
	JNZ	BUTT60
	RET

;
;	MAKE "EXPLOSION" SOUND
;

BOOM:	LXI	H,800
	SHLD	PITCH
	LXI	H,4
	SHLD	DURN
	MVI	A,5
	STA	NSTEPS
	MVI	A,129
	STA	STEP1
	MVI	A,127
	STA	STEP2
	CALL	SOUND
	RET

;
;	MAKE LASER SOUND
;

LASER:	LXI	H,15
	SHLD	PITCH
	LXI	H,10
	SHLD	DURN
	MVI	A,15
	STA	NSTEPS
	MVI	A,1
	STA	STEP1
	XRA	A
	STA	STEP2
	CALL	SOUND
	RET

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

DBCNT:	DB	2
DEBNCE:	DB	2	;DEBOUNCE COUNTER
FIRCNT:	DB	0	;COUNT OF SHOTS FIRED
HITCNT:	DB	0	;COUNT OF HITS

;
;	TABLE OF DIRECTIONS FOR THE KEYS 0-9
;
;	*** KEYBOARD VERSION ONLY ***
;

DIRTBL:	DB	64,64	;0 DOES NOTHING
	DB	0,0	;1 = DOWN LEFT
	DB	64,0	;2 = DOWN
	DB	127,0	;3 = DOWN RIGHT
	DB	0,64	;4 = LEFT
	DB	64,64	;5 DOES NOTHING
	DB	127,64	;6 = RIGHT
	DB	0,127	;7 = UP LEFT
	DB	64,127	;8 = UP
	DB	127,127	;9 = UP RIGHT

;
;	MESSAGES
;

FIRMSG:	DB	15,3,10,30,6,2,'FIRED',10,26,26,26,26
FIRED:	DB	'000',239	;SHOTS FIRED

HITMSG:	DB	15,3,50,30,6,2,'HITS',10,26,26,26,26
HITS:	DB	'000',239	;NUMBER OF HITS

WHITE:	DB	6,7,239		;COLOR CHANGES
BLACK:	DB	6,0,239
BEAM:	DB	2,64,64,242	;LASER BEAM (PLOTTED VECTOR)
X:	DB	64
Y:	DB	64
	DB	255,239

	END