* FUNCTION LIGHT_PEN : BOOLEAN ; EXTERNAL;

* READS THE PORT WHICH ADDRESSES THE LIGHT PEN.IF THE PEN IS 
* SWITCHED ON THEN THE FUNCTION LIGHT_PEN ITSELF RETURNS TRUE.
* IF THE PEN IS ACTIVATED ( E.G. BY THE LIGHT OF THE CURSOR )
* THEN THE BOOLEAN VARIABLE CORRESPONDING TO "ON" RETURNS TRUE.

LOBYTE	EQU 02H		; ACCESS TO ADDRESS FOR 
HIBYTE	EQU 03H 	; RETURN VALUE OF FUNCTION.
VBYTES	EQU 00H		; NO. OF BYTES ON THE STACK.
PORT	EQU 60H
FALSE	EQU 00H
TRUE	EQU NOT FALSE
ON1	EQU 0C0H	; PEN SIGNAL = ON AND ACTIVATED.
ON2	EQU 0C1H	;  "    "       "  "     "

	NAME	LIGHT_PEN
	ENTRY	LIGHT_PEN
	EXT	HEXOUT
	INCLUDE MACRO.SRC

LIGHT_PEN:
	ENTR D,2,VBYTES
	JMP START

MSG1:	DB 'INPUT  BYTE  = $'
CRLF:	DB 0DH,0AH,'$'

START:
	IN PORT
	PUSH PSW
	CPI ON1			; IF BYTE = 0C0H  
	JZ YEP1			; OR 0C1H THEN PEN
	CPI ON2			; WAS ON & TRIGGERED BY CURSOR.
	JNZ NOPE
YEP1:	MVI A,TRUE
	JMP YEP
NOPE:	MVI A,FALSE
YEP:	MOV LOBYTE(IX),A
	MOV HIBYTE(IX),A
	POP PSW
	PRINT CRLF
	CURSOR 24,40
	PRINT MSG1
	CALL HEXOUT
	PRINT CRLF
	EXIT D,VBYTES
	END LIGHT_PEN
