/339 DISPLAY - FORTRAN CALLABLE SUBPROGRAM PACKAGE
/LIGHT PEN TRACKING SUBROUTINE		H.SPENCER	10/68
/
/COPYRIGHT 1970, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/CALL:	JMS	TRACK
/	JMP	.+5
/	.DSA	Y		/Y COORDINATE OF TRACK POSITION
/	.DSA	X		/X COORDINATE OF TRACK POSITION
/	.DSA	CNAME		/MAINFILE PJMP TO THE TRACKING ROUTINE
/	.DSA	PB		/12-WORD ARRAY OF PUSHBUTTON VALUES
/
/THE ENTRY VALUES OF THE COORDINATES DETERMINE WHERE THE TRACKING PATTERN
/FIRST APPEARS. THE EXIT VALUES INDICATE THE CURRENT POSITION OF THE
/PATTERN (ACTUALLY, THE POINTER SPOT). IF AN ENTRY VALUE WAS NEGATIVE, THE
/SPOT IS CONSTRAINED AT THAT (+) VALUE OF THAT COORDINATE, WHICH REMAINS
/NEGATIVE ON EXIT.
/IF THE ENTRY VALUE OF CNAME IS 0, A NEW PJMP TO THE TRACKING
/ROUTINE IS ADDED TO THE MAINFILE, THE LOCATION OF WHICH IS ENTERED IN
/CNAME. IF IT POINTS TO A PJMP TRCK, NO CHANGE IS MADE TO THE MAIN FILE.
/OTHERWISE THE RESULT IS RETURNING TO THE USER WITH .F. IN THE AC.
/IN ALL SUCCESSFUL CASES, ENTRY TO THIS ROUTINE ACTIVATES (MAKES MOVABLE)
/THE TRACKING PATTERN. THE TRACKING PATTERN REMAINS DISPLAYED, WHETHER
/OR NOT ACTIVE, UNTIL DELETED BY THE USER. IT REMAINS ACTIVE UNTIL A
/PB OR MANUAL INTERRUPT IS RECEIVED, AT WHICH TIME THE ROUTINE GIVES
/ARGUMENTS TO THE USER AND RELINQUISHES CONTROL, WITH .T. IN THE AC.
DAT339=10
/DISPLAY CODE AND CONTROLS
OFF=0				/DON'T INTENSIFY
ON=4000				/INTENSIFY
MINY=2000			/MINUS BIT FOR Y IN SVEC MODE
MINX=20				/MINUS X
ESC=ON				/ESCAPE TO CONTROL STATE BIT
SVESC=40			/ESCAPE FROM SHORT VECTOR MODE
MINUS=MINY			/MINUS BIT IN VEC MODE
Y=0
X=0
LPON=60				/LIGHT PEN ON.
SC2=500				/SCALE 2
INT=10				/INTENSITY
POINT=1104			/POINT MODE,CLEAR SECTOR BITS
EDS=1001				/ENTER DATA STATE
STOP=1400				/INTERNAL STOP
VEC=1120				/VECTOR MODE
SVEC=1140				/SHORT VECTOR MODE
POP=3000				/SUBROUTINE RETURN
STEP=2				/TRACKING PATTERN MOVE, RASTER UNITS
	.GLOBL	TRACK,TRCK,.SS,MF.101,MF.102
TRACK	0
	JMP	TRBUF		/1-TIME CODE TO SET UP POINTERS.
/GET ARGUMENTS
	LAC	(USERY		/SET UP POINTER TO INTERNAL
	DAC	ARGPI		/ARGUMENT STORAGE.
	LAC	TRACK		/SET UP POINTER TO
	DAC	ARGPO		/USERS ARGUMENTS.
	LAW	-4		/4 ARGUMENTS, ALL REQUIRED,
	DAC	CNT		/INTO COUNTER.
TRCK10	ISZ	ARGPO		/NEXT ARGUMENT.
	LAC*	ARGPO		/GET IT.
	SMA			/INDIRECT IF MINUS.
	JMP	TRCK15
	DAC	TEMP		/GET
	LAC*	TEMP		/ACTUAL ARGUMENT.
TRCK15	DAC*	ARGPI		/PLACE IN  INTERNAL STORE.
	ISZ	ARGPI		/NEXT.
	ISZ	CNT		/CHECK COUNTER.
	JMP	TRCK10		/RECYCLE.
/SET UP STARTING LOCATION OF TRACK AND X & Y CONSTRAINTS
	LAC*	USERY		/GET VALUE OF Y COORDINATE.
	DAC	YLOC		/Y CONSTRAINT FLAG.
	JMS	CONVT		/CONVERT TO SIGN-MAGNITUDE.
TRCK20	AND	(1777		/LOSE SIGN BIT.
	XOR	(ON		/DISPLAY THIS POINT.
	DAC	Y.IN		/Y COORDINATE OF POINTER SPOT.
	LAC*	USERX		/DO THE SAME FOR X
	DAC	XLOC
	JMS	CONVT
TRCK25	AND	(1777
	XOR	(ESC		/ESCAPE TO CONTROL STATE AFTER THIS PT.
	DAC	X.IN
/GET FIRST LOCATION OF PB ARRAY
	LAC	PB		/ARRAY DESCRIPTOR POINTER
	DAC	.+2		/INTO .SS CALL.
	JMS*	.SS		/SUBSCRIPT CALCULATOR.
	XX
	LAC	(1		/FIRST ELEMENT.
	DAC	PB
/TAKE APPROPRIATE ACTION TO GET TRCK INTO MAINFL DEPENDING ON CNAME
	LAC*	CNAME		/GET VALUE OF POINTER INTO MAINFILE.
	SZA			/IF 0, PLOT TRCK.
	JMP	TRCK35
	.INIT	DAT339,0,1	/CLEAR PENDING ACTIVITY.
	.READ	DAT339,5,TRBUF,1	/SET UP FOR STOP INTERRUPT.
	LAC*	MF.102		/GET CURRENT POSITION IN MAINFL.
	DAC	MFPTR1
	DAC*	CNAME		/GIVE IT TO THE USER.
	TAD	(5		/POINT TO NEW LOCATION
	DAC	MFPTR2		/OF JUMP START IN MAINFL.
	DAC*	MF.102		/RETURN NEW CURRENT POSITION.
	LAC*	MFPTR1		/MOVE JUMP IN MAIN FILE
	DAC*	MFPTR2		/TO NEW LOCATION.
	LAC	(STOP		/STOP DISPLAY TO INSERT TRCK.
	DAC*	MFPTR1
	LAC*	MF.101		/INCREMENT FIRST LOC OF MAINFL
	DAC	TEMP
	LAC*	TEMP
	TAD	(5		/TO SHOW NEW FILE LENGTH.
	DAC*	TEMP
TRCK30	.WAIT	DAT339		/WAIT FOR STOP INTERRUPT.
	LAC	PJUMP		/INSERT PJMP TO TRCK.
	DAC*	MFPTR1
	ISZ	MFPTR1		/MOVE DOWN ONE.
	ISZ	MFPTR2
	LAC*	MFPTR1		/MOVE START ADDR DOWN FOR JUMP.
	DAC*	MFPTR2
	LAC	TR12		/INSERT 12-BIT ADDR OF TRCK FOR PJMP.
	DAC*	MFPTR1
	LAC	(POINT!EDS	/INSERT COMMANDS TO RETURN BEAM.
	ISZ	MFPTR1
	DAC*	MFPTR1
	LAC	YP		/Y POSITION.
	ISZ	MFPTR1
	DAC*	MFPTR1
	LAC	XP		/X POSITION.
	XOR	(ESC		/ESCAPE BIT.
	ISZ	MFPTR1
	DAC*	MFPTR1
	DZM	TRBUF		/CLEAR READ INDICATOR.
	.WRITE	DAT339,0,0,0	/RESTART DISPLAY.
	JMP	TRCK38		/GO TRACK.
TRCK35	DAC	TEMP		/SEE WHAT CNAME POINTS AT.
	ISZ	TEMP
	LAC*	TEMP
	SAD	TR12		/DOES THE NEXT WORD POINT AT TRCK ?
	JMP	TRCK38		/YES, GO TRACK.
	LAC	FALSE		/.F. INTO AC
	JMP	F.RTRN		/RETURN
TRCK38	LAC	(POINT!EDS!STOP	/SET UP TO STOP DISPLAY.
	DAC	MFPTR2
/ISSUE READ TO DISPLAY AND SET UP FOR TRACKING.
TRCK40	.READ	DAT339,7,TRBUF,1
	727440			/LP,MI,PB,ISTOP;PDP,X,Y,DAR,PB
	LAC	MFPTR2		/SET APPROP EDS WORD IN TRCK
	DAC	TRCK1
TRCK43	.WAIT	DAT339		/WAIT FOR FIRST INTERRUPT.
	LAC	TRBUF		/GET INTERRUPT INDICATOR
	SPA!RTL			/BIT 0 ON SAYS LIGHT PEN
	JMP	LPI
	SPA!SZL			/BIT 1 ON = MI,2 = PB.
	JMP	PBI
/INTERNAL STOP INTERRUPT, SAVE X,Y OF CURRENT BEAM
TRCK50	LAC	PDP		/CURRENT PUSH-DOWN.
	TAD	MINUS1
	DAC	PDP		/POINTS TO LOW-ORDER 12 BITS,
	TAD	MINUS1		/OF RETURN LOC IN MAIN FILE.
	DAC	TEMP		/POINTS TO HIGH 3 BITS.
	LAC*	PDP
	AND	(7777
	DAC	PDP		/LOW-ORDER 12 BITS.
	LAC*	TEMP
	RTL; RAL
	AND	(70000		/HIGH 3 BITS.
	TAD	PDP		/LOC OF POINT!EDS IN AC.
	TAD	(1
	DAC	Y.OUT		/Y POSITION LOC.
	TAD	(1
	DAC	X.OUT		/X POSITION LOC.
	LAC	XP		/CURRENT VALUE OF X
	XOR	(ESC		/INSERT ESCAPE BIT.
	DAC*	X.OUT		/WHERE TRCK RESTORES X.
	LAC	YP		/INSERT Y
	DAC*	Y.OUT		/WHERE TRCK RESTORES Y
	LAC	(POINT!EDS
	DAC	MFPTR2
	DAC	TRCK1
	.WRITE	DAT339,1,0,0	/RESUME AFTER ISTOP
	JMP	TRCK40		/GO READ AGAIN.
/LIGHT PEN INTERRUPT, TRACK
LPI	LAC	DAR		/DISPLAY ADDRESS REGISTER
	SAD	PS1		/FIND OUT WHICH SIDE WAS HIT
	JMP	MOVEUP		/TOP
	SAD	PS2
	JMP	MOVERT		/RIGHT SIDE
	SAD	PS3
	JMP	MOVEDN		/BOTTOM
	SAD	PS4
	JMP	MOVELT		/LEFT SIDE
	JMP	TRCK40		/NOT ON TRACK, GO WAIT FOR NEXT INTERRUPT
MOVEUP	LAC	(STEP		/+ MOVE THE BOX
	SKP
MOVEDN	LAC	(-STEP		/ - MOVE THE BOX
	DAC	TEMP		/SAVE INCREMENT.
	LAC	YLOC		/GET CONSTRAINT SWITCH.
	SPA
	JMP	LPI10		/GO MOVE BOX.
	LAC	Y.IN		/GET SET TO MOVE POINT.
	JMS	CKLIM		/MAKE SURE ITS ON THE SCREEN.
	DAC	Y.IN		/INSERT NEW LOCATION.
	JMP	TRCK40
LPI10	LAC	DELTAY		/GET SET TO MOVE BOX.
	TAD	TEMP		/ADD INCREMENT.
	DAC	DELTAY		/SAVE FOR NEXT TIME.
	JMS	CONVT		/CONVERT TO SIGN-MAGNITUDE.
	DAC	DELY		/PUT IN DISPLAY FILE.
	JMP	TRCK40
MOVERT	LAC	(STEP		/+ MOVE
	SKP
MOVELT	LAC	(-STEP		/- MOVE
	DAC	TEMP		/SAVE INCREMENT.
	LAC	XLOC		/GET X CONSTRAINT SWITCH.
	SPA
	JMP	LPI15		/GO MOVE BOX.
	LAC	X.IN		/GET SET TO MOVE POINT.
	JMS	CKLIM		/MAKE SURE ITS ON THE SCREEN.
	DAC	X.IN		/INSERT NEW LOACTION.
	JMP	TRCK40
LPI15	LAC	DELTAX		/GET SET TO MOVE BOX.
	TAD	TEMP		/ADD INCREMENT.
	DAC	DELTAX		/SAVE FOR NEXT TIME.
	JMS	CONVT		/CONVERT TO SIGN-MAGNITUDE.
	XOR	(ESC		/INSERT ESCAPE BIT.
	DAC	DELX		/PUT IN DISPLAY FILE.
	JMP	TRCK40
/PUSH BUTTON OR MANUAL INTERRUPT, GIVE USER HIS ARGUMENTS AND RETURN.
PBI	LAC	XLOC		/X CONSTRAINT ON?
	SPA
	JMP	PBI10		/YES, DON'T ALTER USER'S X.
	LAC	X.IN		/GET X POSITION FROM TRCK.
	XOR	(ON		/CLEAR INTENSIFY BIT.
	DAC*	USERX		/GIVE TO USER.
PBI10	LAC	YLOC		/Y CONSTRAINT ON ?
	SPA
	JMP	PBI20		/YES, DON'T ALTER USER'S Y
	LAC	Y.IN		/GET Y POSITION FROM TRCK
	XOR	(ESC		/CLEAR ESCAPE BIT
	DAC*	USERY		/GIVE TO USER.
PBI20	LAW	-14		/12 PUSHBUTTONS
	DAC	CNT		/INTO COUNTER.
	LAC	PB1		/PB REGISTER FROM 339.
	RTL; RTL; RTL; 		/LEFT SHIFT 6.
PBI22	RCL			/PUT A PB BIT INTO L
	DAC	TEMP		/SAVE REMAINDER
	LAC	TRUE		/FORTRAN .T.
	SNL			/IF L IS ON
	LAC	FALSE		/ELSE .F.
	DAC*	PB		/INTO USER'S PB ARRAY
	ISZ	PB		/NEXT ARRAY ELEMENT.
	LAC	TEMP		/GET REST OF PB BITS.
	ISZ	CNT		/CHECK COUNTER.
	JMP	PBI22		/RECYCLE.
T.RTRN	LAC	TRUE		/GET FORTRAN .T. INTO AC
F.RTRN	JMP*	TRACK		/RETURN.
/CONVERT 2'S COMPLEMENT TO SIGN-MAGNITUDE
CONVT	0
	SMA
	JMP*	CONVT		/DONE IF POSITIVE.
	CMA
	TAD	(1		/CHANGE TO POSITIVE MAGNITUDE.
	XOR	(MINUS		/INSERT MINUS SIGN BIT.
	JMP*	CONVT		/RETURN.
/CHECK TO SEE THAT THE GIVEN POINT IS WITHIN THE LIMITS OF THE SCREEN.
CKLIM	0
	XOR	(ESC		/CLEAR BIT.
	TAD	TEMP		/ADD INCREMENT TO POSITION.
	SMA
	JMP	CKLM10		/GO CHECK HIGH LIMIT.
	TAD	(STEP		/RESTORE TO OLD VALUE.
	JMP	CKLM20		/RETURN.
CKLM10	TAD	(-1777		/IS IT LESS THAN HIGH END?
	SMA
	TAD	(-STEP		/RESTORE TO OLD VALUE.
	TAD	(1777
CKLM20	XOR	(ESC		/RESET BIT.
	JMP*	CKLIM		/RETURN.
	.EJECT
/CONSTANTS AND  STORAGE
TRBUF				/339 READ BUFFER
PDP
XP
YP
DAR
PB1
TRBUF2
PDP2
XP2
YP2
DAR2
PB2
USERY			/LOCAL STORE FOR USER ARGUMENTS.
USERX
CNAME
PB
MFPTR1			/POINTERS INTO THE DISPLAY FILE.
MFPTR2
ARGPI			/INTERNAL ARGUMENT POINTER.
ARGPO			/OUT-TERNAL ARGUMENT POINTER.
TEMP
XLOC			/POINTS TO VARIABLE X IN TRCK.
YLOC			/... VARIABLE Y ...
CNT			/COUNTER
TR12			/12-BIT POINTER TO TRCK.
PS1			/12-BIT POINTERS TO SIDES OF BOX.
PS2
PS3	TRCK+2
PS4	SIDE1+1
Y.OUT			/POINTS TO BEAM-RESTORING Y IN MAINFL.
X.OUT			/... X IN MAINFL.
DELTAY	10			/2'S COMP Y FROM POINT TO BOX.
DELTAX	-10			/2'S COMP X ...
PJUMP	052010			/DISPLAY PJMP, 5 WORDS.
TRUE	-1			/FORTRAN .T.
FALSE	0			/FORTRAN .F.
MINUS1=TRUE
	.EJECT
/TRACKING PATTERN DISPLAY FILE.
TRCK	SIDE4+1-.			/LENGTH OF THIS FILE.
	0
	LPON!SC2!INT 7
TRCK1	POINT!EDS			/ENTER POINT MODE.
Y.IN	XX			/COORDINATES OF POINTER SPOT
X.IN	XX
	VEC!EDS
DELY	OFF 10			/DISTANCE FROM SPOT TO TOP LEFT
DELX	ESC!MINUS 10		/CORNER OF BOX
	SVEC!EDS			/THE BOX
SIDE1	ON!Y!0!X!17
SIDE2	ON!MINY!1700!X!0
SIDE3	ON!Y!0!MINX!17
SIDE4	SVESC!ON!Y!1700!X!0
	POP			/RETURN TO MAIN FILE.
	.EJECT
/1-TIME CODE TO SET UP DISPLAY JUMP AND 12-BIT POINTERS.
	.LOC	TRBUF
	LAC	PS3		/POINTER TO TRCK.
	AND	(7777		/KEEP 12 BITS.
	DAC	TR12
	XOR	PS3		/GET HIGH-ORDER 3 BITS.
	RCL			/MOVE THEM TO 15-17.
	RTL
	RTL
	RTL
	TAD	PJUMP		/ADD PJMP.
	DAC	PJUMP		/APPROPRIATE FOR THIS CORE BANK.
	LAC	PS4		/POINTS TO SIDE1 OF BOX.
	AND	(7777		/KEEP 12 BITS.
	DAC	PS1
	TAD	(1		/NEXT SIDE.
	DAC	PS2
	TAD	(1
	DAC	PS3
	TAD	(1
	DAC	PS4
	LAC	.+2		/BY-PASS THIS CODE IN FUTURE.
	DAC	TRACK+1
	JMP	TRACK+2		/GO TO NORMAL PROCESSING.
	.END
