Compucolor.org – Virtual Media

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	JOYSTICK UTILITY ROUTINES
;
	TITLE	JOYUTL
;
;	APPLICABLE TO BOTH ROUTINES:
;
;	VALUES ON ENTRY:
;	   A REG - NUMBER OF JOYSTICK (0-3)
;
;	*** NOTE: AN OUT OF RANGE NO. WILL PRODUCE GARBAGE
;
;	DESTROYS:
;	   A REG ONLY
;

PBR	EQU	28H
XREG	EQU	20H
YREG	EQU	21H

;
;	READ THE JOYSTICK POSITION
;
;	RETURNS:
;	   BC - X AND Y COORDS RESPECTIVELY
;

	ENTRY	JOYSTK

JOYSTK:	RLC		;SET UP PORT NUMBERS
	ADI	XREG
	STA	XSTRT
	STA	XINP
	INR	A
	STA	YSTRT
	STA	YINP

JOY10:	MVI	C,100	;TIME-OUT COUNT
	DB	0D3H
XSTRT:	DB	XREG
	NOP		;NOTE THE NOP'S - ESSENTIAL
	NOP
JOY20:	DCR	C	;SEE IF A/D HAS TIMED OUT
	JZ	JOY10	;   AND TRY AGAIN IF NECESSARY
	IN	PBR	;CHECK FOR END-OF-CONVERSION
	ANI	80H
	JZ	JOY20	;LOOP UNTIL EOC
	DB	0DBH	;READ X-REGISTER
XINP:	DB	XREG
	MOV	B,A	;SAVE IN B

JOY30:	MVI	C,100	;REPEAT FOR Y-REGISTER
	DB	0D3H
YSTRT:	DB	YREG
	NOP
	NOP
JOY40:	DCR	C
	JZ	JOY30
	IN	PBR
	ANI	80H
	JZ	JOY40
	DB	0DBH
YINP:	DB	YREG
	MOV	C,A	;SAVE IN C
	RET

;
;	CHECK A PUSH BUTTON
;
;	RETURNS:
;	   FLAGS SET AS FOLLOWS: <Z>  BUTTON IS DEPRESSED
;	                         <NZ> BUTTON NOT DEPRESSED
;

	ENTRY	PSHBUT

PSHBUT:	PUSH	B	;SAVE BC
	MOV	B,A
	MVI	A,4
PSHB10:	RLC		;GENERATE CORRECT MASK
	DCR	B
	JP	PSHB10
	MOV	B,A
	IN	PBR	;READ PUSH-BUTTON REGISTER
	ANA	B	;SEE IF BUTTON DEPRESSED
	POP	B	;RESTORE BC
	RET

	END