/339 DISPLAY - FORTRAN CALLABLE SUBPROGRAM PACKAGE
/LIGHT PEN AND PUSHPUTTON INTERRUPT HANDLER.	H.SPENCER, 9/68
/COPYRIGHT 1968, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/TO DETERMINE WHETHER A LIGHT PEN INTERRUPT HAS OCCURRED:
/	JMS	LTPN
/	JMP	.+5
/	.DSA	Y		/Y COORDINATE OF LIGHT PEN HIT.
/	.DSA	X		/X COORDINATE ...
/	.DSA	CNAME		/MAIN FILE DISPLAY ENTRY HIT.
/	.DSA	PB		/12-WORD ARRAY FOR PUSH-BUTTON SETTINGS
/
/TO DETERMINE WHETHER A PUSHBUTTON OR MANUAL INTERRUPT HAS OCCURRED:
/	JMS	PBTN
/	JMP	.+2
/	.DSA	PB	/ARRAY OF PUSHBUTTON VALUES.
/
/ON RETURN FROM THIS ROUTINE, THE AC CONTAINS .T. (-1) IF THE
/QUERIED INTERRUPT HAS OCCURRED, IN WHICH CASE VALUES OF THE ARGUMENTS
/ARE SUPPLIED. IF THE APPROPRIATE INTERRUPT HAS NOT OCCURRED,THE AC
/CONTAINS .F. (0) AND THE INPUT ARGUMENTS ARE NOT ALTERED.
	.GLOBL	LTPN,PBTN,MF.100,.SS
DAT339=10
LTPN	0			/LIGHT PEN ENTRY.
	DZM	LPCSW		/TURN ON SWITCH TO COLLECT LP HITS.
TRUE	LAW	-1
	DAC	ISW		/THIS IS A LIGHT PEN CALL.
LTPN10	LAC	LPSW		/IS THERE ANY LIGHT PEN DATA?
	SZA
	JMP	WAITR		/NO,GO .WAITR FOR 339 INTERRUPT.
	ISZ	LPSW		/CLEAR LP DATA SWITCH.
/PASS LIGHT PEN DATA TO USER'S ARGUMENTS.
	LAC	LTPN		/SET UP POINTER
	DAC	ARGP		/TO CALLER ARGUMENTS.
	LAC	(ARGS+1		/SET UP POINTER TO
	DAC	ARGS		/LOCAL ARGUMENT STORAGE.
	LAW	-4		/4 ARGUMENTS
	DAC	CNT		/INTO COUNTER.
LTPN30	ISZ	ARGP		/NEXT.
	LAC*	ARGP		/GET ITS VALUE.
	SMA			/INDIRECT IF MINUS.
	JMP	LTPN32
	DAC	TEMP		/GET ACTUAL VALUE.
	LAC*	TEMP
LTPN32	DAC*	ARGS		/INSERT IN LOCAL STORAGE
	ISZ	ARGS		/NEXT.
	ISZ	CNT		/INCREMENT AND TEST COUNTER.
	JMP	LTPN30		/RECYCLE.
/GET VALUES OF ARGUMENTS INTO USERS HANDS
	LAC	X		/X REGISTER
	DAC*	ARGS+2
	LAC	Y		/Y REGISTER
	DAC*	ARGS+1
/GET 15-BIT ADDRESS IN MAINFL FROM DAC IF NO PJMP'S HAVE OCCURRED, 
/OR FROM FIRST ENTRY IN PUSH-DOWN LIST IF ANY PJMP HAS OCCURRED.
	LAC*	MF.100		/GET START OF PUSH DOWN LIST
	DAC	PDPL
	SAD	PDP		/DOES PDP POINT TO START OF LIST 
	JMP	LTPN50		/YES, GO USE DAC.
	LAC*	PDPL		/GET 1ST ENTRY IN PUSHDOWN LIST.
	RAL; RTL			/MOVE BITS 6-8 TO 3-5 AND
	AND	(70000		/SAVE BREAK FIELD.
	DAC	TEMP		/PUT ASIDE FOR A MO.
	ISZ	PDPL		/POINT TO 12-BIT ADDRESS IN 1ST ENTRY.
	LAC*	PDPL		/GET IT.
	AND	(7777		/SAVE THE GOOD 12 BITS.
	TAD	TEMP		/15-BIT ADDRESS IN AC.
	JMP	LTPN55
LTPN50	LAC	S1		/STATUS REGISTER 1 BITS 15-17 = BREAK FIELD.
	RTR; RTR; RTR; RAR		/MOVE TO 3-5 AND
	AND	(70000		/SAVE BREAK FIELD.
	TAD	DAR		/ADD IN 12 BIT DAC TO GET 15 BIT ADDR.
/NOW POINTING AT A LOCATION IN MAINFL, FIND THE BEGINNING OF THIS BLOCK.
LTPN55	TAD	MINUS1		/MOVE UP ONE IN MAINFL
	DAC	TEMP
	LAC*	TEMP		/GET THE WORD OUT OF MAINFL.
	AND	(770000		/SAVE HIGH BITS.
	SZA			/NOT 0 = BEGINNING BLOCK
	JMP	LTPN57
	LAC	TEMP		/RECYCLE.
	JMP	LTPN55
LTPN57	LAC	TEMP		/GIVE THIS POINTER (=CNAME)
	DAC*	ARGS+3		/TO USER.
/GET FIRST LOCATION OF PUSHBUTTON LOGICAL ARRAY
	LAC	PB		/GET PB REGISTER.
	DAC	TEMP		/SAVE FOR GETTING ARRARY ELEMTS.
	LAC	ARGS+4		/ARRAY DESCRIPTOR POINTER
LTPN60	DAC	.+2
	JMS*	.SS		/FORTRAN SUBSCRIPT CALCULATOR.
	XX
	LAC	(1		/FIRST ELEMENT
	DAC	ARGS+4		/ADDRESS IN AC.
	LAW	-14
	DAC	CNT		/COUNTER FOR 12 PB WORDS
	LAC	TEMP		/PB REGISTER
	RTL			/LEFT SHIFT 6
	RTL
	RTL
LTPN40	RCL			/1ST BIT INTO L.
	DAC	TEMP		/SAVE THE REST.
	LAC	TRUE		/FORTRAN .T.
	SNL			/IF L IS ON
	LAC	FALSE		/ELSE FORTRAN .F.
	DAC*	ARGS+4		/INTO USER'S ARRAY.
	ISZ	ARGS+4		/NEXT ARRAY ELEMENT.
	LAC	TEMP		/GET REST OF PB BITS.
	ISZ	CNT		/CHECK FOR 12
	JMP	LTPN40		/RECYCLE.
	LAC	TRUE		/.T. INTO AC,
	JMP*	LTPN		/RETURN TO USER.
/
PBTN	0			/PUSHBUTTON ENTRY.
	DZM	PBCSW		/TURN ON SWITCH TO COLLECT PB HITS.
	LAC	PBTN		/SET UP COMMON EXIT.
	DAC	LTPN
	DZM	ISW		/THIS IS A PUSH BUTTON CALL.
PBTN10	LAC	PBSW		/IS THERE ANY PB DATA?
	SZA
	JMP	WAITR		/NO, GO .WAITR FOR 339 INTERRUPT.
	ISZ	PBSW		/CLEAR PB DATA SWITCH.
/PASS PUSHBUTTON DATA INTO USER'S ARGUMENT.
/GET ARGUMENT - POINTER TO LOGICAL ARRAY OF PB VALUES
PBTN20	LAC	PBBUF		/GET PB REGISTER FROM PB INTERRUPT.
	DAC	TEMP		/FOR COMMON PROCESSING OF PB REG.
	LAC	LTPN		/SET UP ARGUMENT POINTER.
	DAC	ARGP
	ISZ	ARGP
	LAC*	ARGP		/GET ARGUMENT
	SMA			/INDIRECT IF MINUS
	JMP	LTPN60
	DAC	CNT
	LAC*	CNT		/GET ACTUAL.
	JMP	LTPN60		/GO GET PB VALUES AND RETURN.
/RETURN TO USER WITH .F. IN AC.
F.RTRN	LAC	FALSE		/.F. IN AC.
	JMP*	LTPN		/RETURN.
WAITR	.WAITR	DAT339,F.RTRN	/GO TO F.RTRN IF NO HIT.
/DISPLAY NOT BUSY, SEE IF LP OR PB HIT HAS OCCURRED.
	LAC	TVBUF		/FIND OUT WHICH HIT OCCURRED.
	SNA
	JMP	READTV		/NO HIT, GO .READ FOR ONE.
	DZM	TVBUF		/GOT ONE,CLEAR INDICATOR FOR NEXT TIME.
	SPA			/BIT 0 ON = LP HIT.
	JMP	LTPN20		/GO PROCESS LP HIT.
	RTL
	SMA!SML		/BIT 1 ON = MANUAL,2 = PB INTERRUPT.
	JMP	READTV		/GO .READ 339 AGAIN.
/PROCESS BUTTON HIT
	LAC	PBCSW		/ARE PB HITS IN SEASON?
	SZA
	JMP	READTV		/NO, DO ANOTHER .READ
	DAC	PBSW		/SET PB DATA SWITCH.
	LAC	TVBUF+6		/GET PB REGISTER FROM 339.
	DAC	PBBUF		/SAVE FOR PB CALLS.
	JMP	READTV		/GO DO ANOTHER .READ
/PROCESS LP HITS.
LTPN20	LAC	LPCSW		/ARE LP HITS IN SEASON?
	SZA
	JMP	READTV		/NO, GO DO ANOTHER .READ
	DZM	LPSW		/SET LP DATA FLAG.
/MOVE DATA FROM READ BUFFER TO LP SAVE BUFFER.
	LAC	TVBUF+1
	DAC	LPBUF
	LAC	TVBUF+2
	DAC	LPBUF+1
	LAC	TVBUF+3
	DAC	LPBUF+2
	LAC	TVBUF+4
	DAC	LPBUF+3
	LAC	TVBUF+5
	DAC	LPBUF+4
	LAC	TVBUF+6
	DAC	LPBUF+5
/	JMP	READTV		/GO DO ANOTHER .READ
READTV	.READ	DAT339,7,TVBUF,1	/READ
	707640			/LP,MI,PB;PDP,X,Y,DAR,S1,PB
	LAC	ISW		/WHICH KIND OF CALL WAS THIS?
	SZA
	JMP	LTPN10		/LIGHT PEN.
	JMP	PBTN10		/PUSH BUTTON.
/CONSTANTS AND STORAGE.
TVBUF	0			/BUFFER FOR DISPLAY READS.
	.BLOCK	7
LPBUF	.BLOCK	6		/LP HIT DATA SAVE AREA.
PBBUF	.BLOCK	1		/PB HIT ...
ISW=PBTN			/SWITCH TO DETERMINE LP OR PB ASKED FOR.
LPSW	1		/ON (0) IF LP INTERRUPT OCCURRED.
PBSW	1			/ON IF PB INTERRUPT OCCURRED.
ARGS	.BLOCK	5		/LOCAL ARGUMENT POINTER
ARGP				/USER'S ARGUMENT POINTER
CNT				/COUNTER
FALSE	0			/FORTRAN .F.
TEMP				/TEMPORARY STORE
PDPL				/START OF PUSH DOWN LIST
S1=LPBUF+4			/STATUS REGISTER 1
PDP=LPBUF				/PUSH DOWN POINTER
X=LPBUF+1				/X VALUE OF FIRST LP HIT
Y=LPBUF+2				/Y VALUE OF FIRST LP HIT
DAR=LPBUF+3			/DISPLAY ADDRESS REGISTER
PB=LPBUF+5			/PUSH BUTTON REGISTER
LPCSW	1			/ON (0) IF LP HITS ARE BEING SAVED.
PBCSW	1			/ON IF PB HITS . . .
MINUS1=TRUE
	.END
