	.TITLE RSX III PLOTTER HANDLER EDIT #12 12/18/75
/
/
/		FIRST PRINTING, DECEMBER 1974
/
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/
/
	.EJECT
/
/EDIT #01	3/4/74	SCR	PUT IT TOGETHER FROM LP.29,XYU. 031
/EDIT #02	3/4/74	SCR	MORE FASTENERS NEEDED.
/EDIT #03	4/15/74	SCR	ENTER AS .INIT
/EDIT #04	4/30/74	SCR	HINF CODE, FIX READ
/EDIT	#06	5/10/74	SCR	MAKE READ WORK FOR F4. 400000 WD.
/EDIT	#07	10/28/74	SCR	FIX 0 LENGTH ASCII;FIX POINT PLOT
/					GENERAL CLEANUP OF ORGANIAZTION
/EDIT	#08	10/29/74	SCR	FIX 32K CHARACTER BUG. CLEANUP
/EDIT	#09	11/4/74	SCR	FIX ABORT BUG.ADD MULTI LINE
/EDIT	#10	12/5/74	SCR	XY311 LEGAL CHECK OFF BY 1; ADD COPYRIGHT
/EDIT	#11	12/6/74	SCR	CHANGE BFCALC SO READ ESCAPES 0 LENGTH CHECK
/EDIT	#12	12/18/75 SCR	FIX INTERFERENCE OF 'OTHER' ABORT
/
	.DBREL
/
/CONDITIONAL ASSEMBLY PARAMETERS
/
/THESE ARE USED TO GENERATE THE PEN SELECTION CODE FOR THE
/XY311 INTERFACE AND TO GENERATE THE DEFAULT CHARACTER SIZES
/SHOWN IN THE TABLE BELOW IN TENTHS OF AN INCH AOR IN MM.
/
/		XY11	XY311
/	1/10
/      INCHES	2	1.25
/	MM	5	3
/
/PL311 DEFINED GENERATES CODE FOR THE XY311 INTERFACE
/PL311 UNDEFINED GENERATES CODE FOR THE XY11 INTERFACE
/UNITS DEFINED GENERATES CODE BASED ON METRIC UNITS
/UNITS UNDEFINED GENERATES CODE BASED ON ENGLISH UNITS
/
/WE USE THESE PARAMETERS TO DETERMINE DEFAULT CHARACTER SIZE 
/
	.DEC
	.IFDEF	PL311
	.IFDEF	UNITS
DFLCHR=100/5*3		/3 MM. IN .05 MM. STEPS
	.ENDC
	.IFUND	UNITS
DFLCHR=1000/2*1/8	/0.125 INCHES IN .002 STEPS
	.ENDC
	.ENDC
	.IFUND	PL311
	.IFDEF	UNITS
DFLCHR=100/25*5		/5 MM. IN 0.25 MM. STEPS
	.ENDC
	.IFUND	UNITS
DFLCHR=1000/10*2/10	/0.2 INCHES IN 0.01 INCH STEPS
	.ENDC
	.ENDC
REC10=104858		/2^20 DIVIDED BY 10 FOR UNIT GRID COMPUTATION
	.OCT
XYPPB=12		/10 XY PAIRS PER BUFFER TO PDP-11
/
/	DESCRIPTION
/
/  ERROR CONDITIONS ARE ENTIRELY HANDLED ON THE PDP-11 SIDE. THE
/  PDP-15 SIDE HANDLER ASSUMES THAT THE DEVICE NEVER MAKES AN
/  ERROR; SOME OPERATIONS JUST TAKE A WHILE TO COMPLETE. ERROR
/  MESSAGES ARE PLACED IN A TABLE IN THE PIREX-11 EXEC. A
/  SEPARATE TASK PRINTS OUT ANY ERROR S THAT OCCUR. THE
/  PDP-11 HANDLES TIMEOUT UNTIL DEVICE READY.
/
/	W  A  R  N  I  N  G  !  !
/
/  IN ORDER FOR THE UC15 HANDLER TO FUNCTION PROPERLY, THE
/  PDP-11 MUST BE ABLE TO ACCESS OUR INTERNAL BUFFER
/  AND TCB'S. THIS MEANS THAT THEIR ADDRESS MUST BE LESS THAN
/  28K TO THE PDP-11. THUS, IF THE PDP-11 LOCAL MEMORY IS 8K,
/  THIS HANDLER MUST RESIDE BELOW 20K IN PDP-15 CORE! THIS IS
/  EQUIVALENT TO 50000 OCTAL. SIMILARLY, IF THE LOCAL 
/  PDP-11 MEMORY IS 12K, THE HANDLER MUST RESIDE BELOW
/  40000 OCTAL.
/
/
/ THE REQUESTOR'S EVENT VARIABLE IS CLEARED (ZEROED) WHEN THE REQUEST
/ IS QUEUED BY THE "QUEUE I/O" DIRECTIVE.  IF THE REQUEST CAN BE 
/ PERFORMED, THE EVENT VARIABLE IS SET TO ONE (+1) UPON COMPLETION.
/ IF THE REQUEST CANNOT BE PERFORMED, THE EVENT VARIABLE IS SET TO ONE 
/ OF THE FOLLOWING NEGATIVE VALUES:
/
/	 -6 -- ILLEGAL REQUEST FUNCTION
/	 -7 -- ILLEGAL DATA MODE
/	-16 -- ILLEGAL OUTPUT HEADER WORD-PAIR-COUNT (<1)
/	-24 -- LUN HAS BEEN REASSIGNED WHILE REQUEST WAS IN QUEUE
/	-30 -- OUT-OF-PARTITION TRANSFER (NORMAL MODE)
/	-203 - ILLEGAL TO ATTACH OR DETACH FROM OTHER THAN TASK LEVEL
/
/  NOTE THAT THIS HANDLER HAS 3 RATHER UNUSUAL CAL'S
/
/  A READ RETURNS THE CURRENT PLOTTER STATUS ACCORDING TO THE HANDLER
/   (WARNING, IN CASE OF SPOOLING, THE PLOTTER ITSELF MAY NOT YET
/   HAVE ATTAINED THIS STATUS.)
/
/  AN ENTER SERVES AS A .INIT. IT SETS UP DEFAULT CHARACTER
/   ATTRIBUTES, ZEROES PRESENT X AND Y, AND CLEARS OUT THE BUFFER
/   FOR COLLECTING LINES. (10(10) LINE PAIRS GET SENT TO THE
/   PDP-11 AT ONCE TO MINIMIZE PROCESSOR INTERACTION LOADING.)
/
/  A CLOSE FORCES ANY COLLECTED BUT UNSENT LINES TO BE SENT TO
/   THE PDP-11 FOR PLOTTING.
/
	.EJECT
/
/	EQUATES
/
/
X12=12		/AUTO-INCREMENT REG 12
X13=13		/AUTO-INCREMENT REG 13
X17=17		/AUTO-INCREMENT REG 17 (USED TO SET REQUESTOR'S EV)
R1=101		/RE-ENTRANT REGISTER ONE
R2=102		/RE-ENTRANT REGISTER TWO
R3=103		/RE-ENTRANT REGISTER THREE
R4=104		/RE-ENTRANT REGISTER FOUR
NADD=107	/NODE ADDITION ROUTINE ENTRY POINT
SNAM=123	/NAME SCAN ROUTINE ENTRY POINT
POOL=240	/LISTHEAD FOR POOL OF EMPTY NODES
PDVL=252	/LISTHEAD FOR PHYSICAL DEVICE LIST
ALAD=325	/ATTACH LUN & DEVICE ENTRY POINT
DLAD=332	/DETACH LUN & DEVICE ENTRY POINT
DQRQ=337	/DE-QUEUE REQUEST ENTRY POINT
PICK=120	/PICK A NODE ENTRY POINT
VAJX=342	/VERIFY & ADJUST ENTRY POINT
IOCD=345	/DECLARE I/O REQUEST COMPLETE ENTRY POINT
DMTQ=361	/DETACH & EMPTY QUEUE ENTRY POINT
D.TG=10		/POSITION OF TRIGGER EVENT VARIABLE IN PDVL NODE
LUN=2		/LUN FOR NOT-READY MESSAGE.(LUN 3 NOT USED SINCE MCR OUTPUT
		/COULD BE CHANNELED THRO LUN 3)
.INH=705522	/INHIBIT INTERRUPTS
.ENB=705521	/ENABLE INTERRUPTS
/
/
/
/  EQUATES FOR UNICHANNEL PLOTTER
/
APISLT=65
APILVL=3
XYSF=APILVL*20+706101
SIOA=706001
LIOR=706006
CAPI=APILVL*20+706104
BUFSZ=104		/132(10) CHAR'S + 2 WORD HEADER
/
	.IFUND	NOSPL
DEVCOD=6		/DEVICE CODE IN PIREX IF SPOOLING ALLOWED
	.ENDC
	.IFDEF	NOSPL
DEVCOD=206		/200 BIT FORBIDS SPOOLING
	.ENDC
LBF=.			/IO BUFFER TO PDP-11 OVERLAYS INITIALIZATION
	.EJECT
/
/ HANDLER INITIALIZATION
/
START	LAC	LPDVL	/SCAN PHYSICAL DEVICE LIST FOR NODE
	DAC*	(R1)	/FOR THIS DEVICE.
	LAC	LHNAM
	DAC*	(R2)
	JMS*	LSNAM	/(R1, R2, R6, X17, XR, & AC ARE ALTERED)
			/NODE FOUND?
	CAL	(10)	/NO -- EXIT
/
	DAC	PDVNA	/SAVE PDVL NODE ADDRESS
	AAC	+D.TG	/AND
	DAC	PDVTA	/TRIGGER EVENT VARIABLE ADDRESS ADDRESS.
	AAC	-2	/MAKE POINTER TO DEQUE HEAD
	DAC	PDVDH	/USED AT DEAX TIME
	CAL	CCPB	/CONNECT INTERRUPT LINE
	LAC	EV	/CONNECT OKAY?
	SPA
	CAL	(10)	/NO -- EXIT
/
	.EJECT
/
/	INITIALIZATION ERROR, AND LITERALS
/
	LAC	LTG	/YES -- SET TRIGGER EVENT VARIABLE ADDRESS
	DAC*	PDVTA	/IN PHYSICAL DEVICE NODE
	ISZ	CCPB	/MAKE CONNECT A DISCONNECT FOR EXIT
	AND	L70000	/DETERMINE "XR-ADJ"
	TCA
	DAC	XADJ
	JMS	CLEAR	/CLEAR OUT DEVICE, WAIT FOR COMPLETE
	LAC	EV11K	/CHECK IF OUR DRIVER IN PIREX
	RTL		/PDP-11 SIGN BIT TO OURS
	SMA		/SKIP IF PROBLEM
	JMP	ENTERI	/NO PROBLEM, INITIALIZE
	CAL	MSINIT	/PROBLEM, TYPE MESSAGE
	CAL	WFMS	/WAIT FOR MESSAGE COMPLETION
	CAL	(10	/TYPED, NOW EXIT
/
WFMS	20	/WAIT FOR ERROR MESSAGE
	EV
MSINIT	2700		/TYPE ERROR MESSAGE
	EV
	LUN
	2
	INITMS
INITMS 	004002; 000000; .ASCII "*** NO XY IN PIREX"<15>
/
/
	JMP	WFTGR	/WAIT FOR TRIGGER
/
HNAM	.SIXBT "XY@@@@"	/DEVICE NAME (HANDLER TASK NAME IS "XY....")
/
/  INITIALIZATION LITERALS, TO SAVE SPACE
/
LPDVL	PDVL		/PHYSICAL DEVICE LIST HEADER ADDR.
LHNAM	HNAM		/POINT TO HANDLER NAME
LSNAM	SNAM		/SEARCH FOR NAME MATCH ROUTINE ADDR.
LTG	TG		/ADDR OF OUT TRIGGGER
L70000	70000		/LITERAL FOR XR ADJUSTMENT
/
	.LOC	LBF
	.BLOCK	BUFSZ	/BUFFER. 132 CHAR'S ?!?! + 2 WORD HEADER
	.EJECT
/
/	STORAGE AND TEMPORARIES
/
/  8 WORDS DESCRIBING THE UNIT GRID ON REAL PLOTTER
/
XDXH	2		/HIGH HALF OF X STEPS PER GRID UNIT
XDXL	0		/LOW HALF.11*11 GRID UNITS MAKE CHARACTER 'BOX'
YDYH	2		/Y STEPS PER Y GRID UNIT, HIGH
YDYL	0		/Y STEP, LOW HALF. ORDER MUST MATCH IN PDP-11
XDYH	0		/Y STEPS PER X GRID UNIT, CA OCCUR WITH TIPPED
XDYL	0		/CHARACTERS
YDXH	0
YDXL	0
/
/  FOLLOWING 7 (8 FOR XY311) WORDS ARE TRANSFERED OUT ON A .READ. THEY MUST
/  REMAIN IN ORDER
/
OTSJNK	400000		/SOME SORT OF OTS WORD;ALSO USED AS LITERAL
LASTX	0		/PRESENT X CO-ORDINATE PEN POSITION
LASTY	0		/PRESENT Y CO-ORDINATE PEN POSITION
XSZ	DFLCHR		/X SIZE OF A CHARACTER, IN INTEGER STEPS
YSZ	DFLCHR		/Y SIZE OF A CHARACTER IN STEPS
SINX	0		/200000*SIN(X), WHERE X IS TILT OF CHAR.
COSX	200000		/200000*COS(X). STRING FROM HORIZONTAL
UPDWN	0		/PEN STATUS.0=UP.100000=DOWN
	.IFDEF	PL311
NUMPEN	0		/NUMBER OF THE PEN WHICH IS ACTIVE
	.ENDC		/(XY311 INTERFACE ONLY)
/
/	VARIOUS TEMPORARIES ORIENTED TOWARD COMPUTATION
/
ABSDEL	0		/XCT LAC* X12 OR TAD* X12
IMPERR	0		/IMPOSSIBLE ERROR HOLDER
INITFL	400001		/BOTTOM BITS TELL PIREX REAL INIT
/			/FOR XY311. TOP BIT ON SAYS SKIP SEV
COUNT			/-COUNT OF X,Y PAIRS TO OUTPUT BUFFER
COUNTC			/COUNT OF INPUT WORD PAIRS
COUNTX			/CONTROL COUNT FORTRAN CHAR'S
POINT1			/POINT TO SINGLE WORD OPERAND  MX1X2
POINT2			/POINT TO DOUBLE WORD OPERAND  MX1X2
SIGN1			/MX1X2 STORE SIGN OF RESULT
/			/ALSO USED AS TEMPORARY BY WRITE
SIGN3			/MX1X2 0 OR 1 TO ADD TO LOW WORD OF RESULT
/			/ALSO USED AS TEMOORARY BY BFCALC
T1			/3 TERMPORARIES FOR MX1X2
T2
T3
BUFP	LBF+2		/POINTER TO PLACE LINES IN OUTPUT BUFFER
XSH			/KEEP THIS AND NEXT THREE IN ORDER
XSL			/HIGH AND LOW HALF X-DIR GRID CALC. TEMP.
YSH			/HIGH HALF OF Y GRID DIRECTION
YSL			/LOW HALF OF Y
/
/	DISPATCH TABLE FOR TYPE OF BINARY WRITE
/
DISTAB	JMP	OKEX	/0 JUST LIFTS PEN
	JMP	OKEX	/1 JUST LOWERS
	JMP	ABSOL	/2 ABSOLUTE LINE
	JMP	ABSOL	/3 ABSOLUTE LINE
	JMP	DELTA	/4 DELTA LINE
	JMP	DELTA	/5 DELTA LINE
	JMP	CHAR	/6 CHARACTER STRING
	JMP	SET	/7 SET HERE AS X,,Y
	JMP	ABSOL	/10 ABSOLUTE LINE
	JMP	DELTA	/11 RELATIVE LINE
	JMP	CHARST	/12 CHARACTER ATTRIBUTES
/
	.IFUND	PL311
	JMP	IOPS7	/13 ILLEGAL FOR REG. XY
	.ENDC
	.IFDEF	PL311
	JMP	PIKPEN	/13 PEN SELECT FOR 311
	.ENDC
/
/
/	VARIOUS TEMPORARIES ORIENTED TOWARD RSX
/
XYDON	0		/1 WHEN AN OPERATION FINISHED, OTHERWISE 0
POST	0		/REQUEST NODE ADDRESS WHEN WAITING FOR AN
/			/INTERRUPT; OTHERWISE 0
XADJ	0		/XR ADJUST CONSTANT FOR PAGE BITS
ACBF	0		/SAVE AC AT INTERRUPT LEVEL
EV	0		/RSX EVENT VARIABLE
STLA	0		/STL NODE ADDR OF WHO CALLED US (FOR ABORT)
RN	400000		/REQUEST NODE ADDR FOR PRESENT CAL.
GIVEEV	0		/VALUE IN THIS LOC RETURNED AS EVENT VARIABLE
SAV12	0		/SAVE X12 THRU IO
TG	0		/TRIGGER EVENT VARIABLE
PDVNA	0		/PHYSICAL DEVICE NODE ADDRESS
PDVTA	0		/INIT : ADDR OF TG ADDR IN PH DEV NODE.
/			/EXIT : ADDR OF ASSIGN INHIBIT IN PH DEV NODE
PDVDH	0		/ADDR OF DEQUEHEAD IN PH DEV NODE
/
	.EJECT
/
/	RSX CAL'S
/
WFTCPB	20		/WAIT FOR TRIGGER
	TG
/
CCPB	11		/CONNECT API TRAP CAL (ISZ TO DISCONNECT FOR EXIT)
	EV
	APISLT-40
	INT		/INTERRUPT TRAP
/
WFCLER	20		/WAIT FOR PIREX TO SET EV ON DEVICE CLEAR
	EV11K
/
/	TCB'S TO COMMUNICATE TO PDP-11
/
TCB	APISLT*400+APILVL	/SEND I/O REQ TO PDP11. HERE IS API RETURN INFO
	DEVCOD			/PIREX DEVICE CODE FOR XY
EV11	0			/PIREX EVENT VARIABLE
	0			/DUMMY HIGH ADDRESS BITS FOR BUFFER
	LBF			/PERMANENT DATA BUFFER ADDRESS
	0			/TWO WORDS NOT USED, THERE FOR COMPATIBILITY
	0			/TO UC15 LPT CALL FOR PIREX SPOOLER
/
TCBK	0			/TELL PDP-11 TO SHUT DOWN DEVICE, NO RETURN INTR.
	DEVCOD&177*400+200	/THIS IS REQUEST CODE TO SHUT DOWN XY
EV11K	0			/PIREX EVENT VARIABLE
/
TCBP	TCB			/POINTERS TO TCB'S (COULD BE LITERALS)
TCBKP	TCBK
/
	.EJECT
/
/ WAIT FOR TASK TO BE TRIGGERED BY 'QUEUE I/O' DIRECTIVE OR BY 'ABORT'
/ TO SIGNAL THAT A REQUEST HAS BEEN QUEUED. THEN DISPATCH ON CAL.
/
WFTGR	CAL	WFTCPB	/WAIT FOR TRIGGER EVENT VARIABLE TO BE SET
PQ	LAC	TG	/FIND OUT WHO WOKE US UP
	DZM	TG	/CLEAR FOR NEXT TIME AROUND
	RTL		/ABORT BIT TO AC0
	SPA!CLA!IAC	/SKIP IF NOT, SET UP 1 FOR COMPARES
	JMP	PQ1	/PICK OFF ABORT IN NORMAL MANNER
/			/IRREGARDLESS IF WAITING FOR INTERRUPT
	SAD	XYDON	/HAS INTERRRUPT COME BACK
	JMP	OPDONE	/GO CHECK IT OUT
	LAC	POST	/ARE WE WAITING FOR ONE
	SZA		/SKIP IF WE ARE
	JMP	WFTGR	/YES, DO NOTHING NOW, INTERRUPT WILL WAKE
/			/US LATER;WE ALWAYS CHECK DEQUE BEFORE 
/			/RETUNING TO SLEEP AGAIN.
PQ1	LAC	PDVNA	/DEQUE A REQUEST
	DAC*	(R1)
	JMS*	(DQRQ)	/(R1, R2, R4, R5, R6, XR, & AC ARE ALTERED)
			/WAS A REQUEST FOUND?
	JMP	WFTGR	/NO -- WAIT FOR TRIGGER
	DAC	RN	/YES -- SAVE ADDRESS OF REQUEST NODE
	TAD	XADJ	/SETUP XR TO ACCESS NODE
	PAX
/
	LAC	5,X	/FETCH CAL FUNCTION CODE
	AND	(777)
	SAD	(017)	/ABORT REQUEST?
	JMP	ABORT	/YES -- ABORT TASK I/O
	SAD	(777)	/NO -- EXIT (DEASSIGNED) REQUEST?
	JMP	DAEX	/YES -- DETACH & EXIT
	SAD	(34	/CLOSE
	JMP	CLOSE	/USE HERE AS BUFFER FLUSH
	SAD	(33	/ENTER
	JMP	ENTER	/USE HERE AS A .INIT
	SAD	(36	/HINF
	JMP	HINF	/USE NORMALLY
	CLL!RAR		/SEARCH ATTACH DETACH IN COMMON
	SAD	(12	/24/2 AND 25/2  ARE 12
	JMP	ATTACH	/GO DO EITHER
	SAD	(13	/SEARCH READ-WRITE
	JMP	RW	/27/2=13;26/2=13
ILFUNC	LAW	-6	/NO -- UNIMPLEMENTED FUNCTION -- SET
	JMP	SEV	/EVENT VARIABLE TO -6
	.EJECT
/
/	ABORT, ATTACH, DETACH PROCESSING
/
/ ABORT ALL I/O INITIATED BY THE INDICATED TASK.
/
ABORT	XOR	5,X	/ABORT IS AN ILLEGAL FUNCTION FOR ALL TASKS
	SZA		/EXCEPT 'IORD', WHO SETS THE LUN=0.
	JMP	ILFUNC
	LAC	STLA	/IS ABORT SAME TASK AS MIGHT HAVE I/O PENDING
	SAD	2,X	/COMPARE STL NODE ADDR.
	SKP		/SAME TASK, KEEP ON CHECKING
	JMP	ABO1	/DIFFERENT TASK, JUST CLEAR DEQUE
	LAW	-24	/EVENT VARIABLE FOR HANDLER ASSIGNED AWAY
	DAC	GIVEEV	/IN CASE WE FIND NODES
	LAC	POST	/ARE WE WAITING FOR INTERRRUPT
	SNA!SPA		/SKIP IF YES
	JMP	ABO1	/NO, JUST CLEAR DEQUE
	JMS	GIVBAK	/RETURN NODE, ADDR IN AC!
	JMS	CLEAR	/TELL PIREX TO FORGET ABOUT REQ.
ABO1	LAC	PDVNA	/PHYSICAL DEVICE NODE ADR
	DAC*	(R1)
	LAC	RN	/REQUEST NODE ADR
	DAC*	(R2)
	JMS*	(DMTQ)	/DETACH LUN & DEVICE, IF NECESSARY, AND THEN
			/EMPTY THE QUEUE OF ALL I/O REQUESTS MADE BY THE
			/TASK BEING ABORTED. (R1, R2, R3, R5, R6, X10,
			/X11, X12, XR & AC ARE ALTERED).
	JMP	OKEX	/DONE.
/
/
/  ATTACH TO  OR  DETACH FROM A TASK
/
ATTACH	CLA!RAL		/LINK TO AC; ATTACH-DETACH COMMON CODE
	PAX		/XR 0 FOR ATTACH, 1 FOR DETACH
	LAC	PDVNA	/LUN AND DEVICE
	DAC*	(R1)
	LAC	RN
	DAC*	(R2)
	XCT	ATTDET,X /(R3, R4, R5, R6, X10, X11, XR, & AC ARE ALTERED)
			/WAS LUN DETACHED?
	JMP	SEV	/NO -- SET REQUESTOR'S EVENT VARIABLE TO -24 OR -203
	JMP	OKEX	/OKEX TO SET +1 AND EXIT
/
/  MONITOR SUBROUTINE CALLS FOR ATTACH-DETACH
/
ATTDET	JMS*	(ALAD
	JMS*	(DLAD
	.EJECT
/
/	READ OR WRITE ENTRY, WRITE PROCESSING
/
RW	SNL		/SKIP ON WRITE
	JMP	READ	/SO GO READ
WRITE	LAC	7,X	/DATA MODE
	DAC	SIGN1	/SAVE THRU CALL TO BFCALC
	JMS	BFCALC	/SET UP BUFFER CALCULATIONS
	LAC*	X12	/XCT'ED BY BFCALC; WE ARE A WRITE, OBTAIN BUFFER HEADER
	LAC	SIGN1	/GET BACK MODE; BFCALC RETURNS HERE
	SNA!CLL!RTR	/0 IS OK, GO DO BINARY
	JMP	WRITEB
	SNA		/0 IS NOW ASCII, OTHERS ARE ERROR
	JMP	CHARI	/GO DO CHAR STRING
	JMP	IOPS7	/GO DO IOPS 7 ILLEGAL MODE
/
/
WRITEB	LAC*	X12	/FIRST WORD, ENTER HERE LINK=0
	SAD	OTSJNK	/400000 IS OTS JUNK
	LAC*	X12	/NOW GET RIGHT THING IN AC
	PAX		/CODE IN XR FOR DISPATCHING
	TAD	(-14	/CHECK FOR LEGAL CODE #
	SZL		/ILLEGAL CODE CARRIES TO LINK!
	JMP	IOPS7	/WRONG ONE, ERROR OUT
	AAC	6	/TYPES 0-5 SET THE PEN,TEST FOR THEM.
	SMA!RAR		/SKIP ON TYPES 0-5, PEN BIT NOW IN LINK
	JMP	WRITED	/NO PEN SET, JUST GO TO DISPATCH
	CLA!RAR		/ALL CLEAR EXCEPT PEN BIT 
	RTR		/PEN BIT NOW IN 100000 POSITION
	DAC	UPDWN	/SET PEN FLAG
WRITED	CLA!CLL		/DISPATCH WITH AC, LINK =0
	JMP	DISTAB,X /GO TO CORRECT FOR OF BINARY WRITE
/
	.EJECT
/
/  ABSOLUTE AND RELATIVE LINE ENTRIES SET UP EXECUTE LOCATION
/  'ABSDEL' TO CONTAIN  LAC* X12 FOR DELTA, TAD* X12 FOR ABS.
/
ABSOL	LAC	(DZM	/TAD=LAC+DZM
DELTA	TAD	XLIT	/TAD OF   LAC* X12
	DAC	ABSDEL
/
/  NOW LOOP TO TRANSFER LINES
/
WRITEL	LAC	LASTX	/SET UP THIS-LAST INCASE ABSOL
	CMA!IAC
	XCT	ABSDEL	/RESULTS IN DELTA X IN AC
	JMS	VALID	/CHECK SIZE OF MOVEMENT
	XOR	UPDWN	/NOW HAVE DX IN AC, PUT IN PEN BIT
	DAC*	BUFP	/PLACE IN OUTPUT BUFFER
	ISZ	BUFP	/AND MOVE POINTER FOR DY
	XOR	UPDWN	/TURN OFF PEN BIT FOR OUR GRID COMPUTATION
	TAD	LASTX	/UPDATE POSITION
	DAC	LASTX
	LAC	LASTY	/SAME FOR Y
	CMA!IAC
	XCT	ABSDEL
	JMS	VALID
	DAC*	BUFP	/PLACE DY FROM AC TO OUTPUT BUFFER
	ISZ	BUFP	/MOVE POINTER TO NEXT PAIR
	TAD	LASTY
	DAC	LASTY
	ISZ	COUNT	/BUFFER FULL?
	SKP		/NO, JUST KEEP GOING
	JMS	DOLINE	/PUT OUT THE BUFFER
	ISZ	COUNTC	/MORE LINES? BFCALC SET THIS UP
	JMP	WRITEL	/YES
	JMP	OKEX	/THAT'S ALL!!!
	.EJECT
/
/	CHARACTER ATTRIBUTES SETUP
/
CHARST	JMS	DOLINE	/FORCE OUT ANY ACCUMULATED LINES (X12 SAVED!)
XLIT	LAC*	X12	/GET X SIZE, ALSO THIS IS LITERAL
	DAC	XSZ
	LAC*	X12	/GET Y SIZE
	DAC	YSZ
	LAC*	X12	/GET SINE
	DAC	SINX
	LAC*	X12	/GET COSINE
	DAC	COSX
INNDCH	LAC	XSZ	/CHARST AND INIT, CALCULATE DOUBLE PRECISION
	MUL		/SIZE OF SINGLE GRID STEP AT GIVEN OVERALL
/			/GRID SIZE AND ANGLE
	REC10		/THIS DIVIDES BY 10, MULT BY 4
	DAC	XSH	/SAVE IN TEMPORARY IN BUFFER
	LACQ		/GET LOW HALF
	DAC	XSL
	LAC	YSZ	/DIVIDE Y BY 10 (10UNITS GRID PER BOX)
	MUL
	REC10
	DAC	YSH
	LACQ
	DAC	YSL
/
/  NOW SET UP TO MULT DOUBLE NUMBER IN XSH-XSL AND YSHYSL PAIRS BY
/  SIN AND COS, XR RUNS 0-8 THRU 'COMMON' AS WE FILL DATA
/
	CLX		/XR UNDISTURBED BY MX1X2, P11
	LAC	(XSH	/MAKE POINTER TO DOUBLE NUMBER
	DAC	POINT2
	LAC	COSX
	DAC	POINT1	/AND ARGUMENT TO MULTIPLIER
	JMS	MX1X2	/CALL ROUTINE, DOUBLE PRESISION MULTIPLY
/			/OF SINGLE NUMBER IN POINT1 TIME DOUBLE NUMBER
/			/AT POINT2. LEAVE DOUBLE ASNWER IN AC,MQ
	JMS	P11	/PLACE ANSWER IN BUFFER AND IN OUR STORAGE
/			/THIS GAVE XDXH AND XDXL
	JMS	MX1X2
	JMS	P11	/NOW HAVE YDYH AND YDYL
	LAC	SINX	/GET SINE FOR MULTIPLY
	DAC	POINT1
	LAC	(XSH	/POINT DOUBLE TO X PAIR
	DAC	POINT2
	JMS	MX1X2	/GET XDYH,XDYL
	JMS	P11
/
/  NOW A DIRTY, WE NEED -SIN FOR YDX
/
	LAC	SINX
	CMA!IAC
	DAC	POINT1
	JMS	MX1X2
	JMS	P11
	LAC	INITFL	/LOW BITS;FLAG FOR REAL INIT (XY311 NEEDS)
	DAC	LBF+2,X /PLACE IN BUFFER TO GO TO PDP-11
	LAC	(1422	/MODE 3, 22 BYTES
COMMON	DAC	LBF	/AS BUFFER HEADER
	JMS	DOIO	/GO PLACE TO PDP-11
	LAC	INITFL	/TOP BIT SAYS WHETHER GO TO SEV
	DZM	INITFL	/DEFAULT SETTING
	SMA		/FIRST TIME THRU -, SKIP SEV
	JMP	OKEX
	JMP	PQ
	.EJECT
/
/  CHARACTER STRING PROCESSING FOR WRITE 2 AND WRITE 0 MODE 6
/
CHAR	LAC*	X12	/GET CHAR COUNT
	SNA!SPA!CMA!IAC	/MAKE - FOR ISZ. CHECK IF >1
	JMP	IOPS7	/CONTROL COUNT 0 OR -, QUIT
CHARI	DAC	COUNTX	/CONTROL COUNT FOR FORTRAN BINARY
/			/FORTRAN ASCII ENTERS AT CHARI WITH 0 AC.
	DZM	COUNTC	/ZERO COUNTR 
	JMS	DOLINE	/FORCE OUT ANY PENDING LINE OPERATIONS
	LAC	(UNPK1	/INIT UNPACKING ROUTINE
	DAC	UNPKX
	LAC	(PACK1	/INIT PACKING ROUTINE
	DAC	PKX
CHARL	JMP*	UNPKX	/GO GET A CHARACTER (USES MQ THRU CHARC)
UNPKX	HLT		/POINTS TO CORRECT ACTION FOR THE NEXT CHAR
	AND	(177	/RETURNS HERE, CHAR IN AC, VIA JMS UNPKX  , WHICH
/			/LEAVES POINTER TO NEXT ACTION
	SAD	(15	/CR
	JMP	DN	/YES, QUIT
	SAD	(175	/ALT
	JMP	DN	/QUIT
	AAC	-40	/CHAR'S LESS THAT 40 IGNORED!
	SPA
	JMP	CHARC	/GO DO LOOP CONTROL
	AAC	-100	/CHAR'S 140 ARE GREATER ARE MAPPED BACK TO 100
	SMA
	AAC	-40	/MAP BACK, PRIMARILITY FOR LOWER CASE CHAR'S
	AAC	140	/RECREATE CHAR
	ISZ	COUNTC	/COUNT A 'REAL' CHARACTER
	JMP*	PKX	/GO PLACE CHARACTER IN PDP-11 STYLE BUFFER
PKX	HLT		/POINTS TO NEXT CORRECT ACTION (AS ABOVE)
CHARC	ISZ	COUNTX	/FORTRAN, GOT THEM ALL
	JMP	CHARL	/LOOP
/
DN	LAC	COUNTC	/HOW MANY DID WE GET
	SNA		/DID WE GET ANY REAL CHAR'S (NOT CONTROL)
	JMP	DN1	/NOPE, DON'T SEND OUT
	TAD	(1000	/FOR HEADER, MODE 2
	DAC	LBF	/THRU OUR POINTER TO DOS BUFFER
	XOR	(1000	/RESTORE ORIG. COUNT
	MUL		/TIMES 10, WE NOW COMPUTE PEN CHANGE OF STRING
	12
	LACQ
	DAC	POINT1
	LAC	(XDXH	/POINTER TO DOUBLE
	DAC	POINT2
	JMS	MX1X2	/ANSWER IN AC,MQ
	JMS	CHP	/GET MIDDLE THIRD OF ANS, OROUNDED TO AC
	TAD	LASTX
	DAC	LASTX	/UPDATED X, NOW DO Y
	LAC	(XDYH
	DAC	POINT2
	JMS	MX1X2
	JMS	CHP
	TAD	LASTY
	DAC	LASTY
	JMS	DOIO	/PUT IT OUT
DN1	JMS	RESETL	/RESET BUFP
	JMP	OKEX
/
	.EJECT
/
/	READ PROCESSING
/
/  THE READ FUNCTION IS USED TO OBTAIN PLOTTER STATUS
/
/  CAL WITH SEVEN (OR EIGHT FOR XY311) INTEGER ARGUMENTS  TO OBTAIN
/
/  400000	/WORD TO FAKE OUT FORTRAN, MACRO PEOPLE MUST THROW AWAY
/  LASTX		/PRESENT X POSITION IN INTEGER STEPS
/  LASTY		/PRESENT Y POSITION IN INTEGER STEPS
/  ISX		/X SIZE IN STEPS OF CHARACTER
/  ISY		/Y SIZE OF CHARACTER IN STEPS
/  ISIN		/INTEGER SIN (200000*SIN(X)) OF SLOPE OF CHARACTERS
/  ICOS		/INTEGER COS (200000*COS(X)) ON SLOPE OF CHARACTERS
/  IPEN		/0 IF PEN UP, 100000 IF DOWN
/  IPENUM	/# OF THE ACTIVE PEN IF XY311 INTERFACE IS INSTALLED
/
/  I.E.
/
/	READ (6) LASTX,LASTY,ISX,ISY,ISIN,ICOS,IPEN,IPENUM
/
READ	JMS	BFCALC	/CALC BUFFERS
	DAC*	X12	/XCT'ED BY BFCALC; WE ARE A READ, PLACE BUFFER HEADER
	.IFUND	PL311
	LAW	-10	/LOOP CONTROL; BFCALC RETURNS HERE
	.ENDC
	.IFDEF	PL311
	LAW	-11	/LOOP CONTROL IF XY311 FUNCTIONSET AVAILABLE
	.ENDC
	DAC	COUNTC	/GRAB COUNTER LOCATION FOR WRITE
	LAC	(OTSJNK-1 /ADDR-1 OF OUR LIST FOR AUTOX.
	DAC*	(X13	/GET WORDS FOR LOOP FROM HERE
READ1	LAC*	X13	/GET WORD
	DAC*	X12	/PUT WORD
	ISZ	COUNTC	/DONE YET
	JMP	READ1
	JMP	OKEX
	.EJECT
/
/	CLOSE, ENTER, HINF PROCESSING
/
CLOSE	JMS	DOLINE	/FORCE OUT ANY ACUMULATED LINES
	LAC	(177404	/EOF HEADER (4 BYTES FOR XY311)
	JMP	COMMON
/
/
ENTER	CLA!IAC		/INITFL TO SAY INIT, BUT GO TO SEV
	DAC	INITFL
ENTERI	JMS	RESETL	/FROM FIRST TIME CODE (INITFL ASSEM=400001)
	DZM	UPDWN	/PEN UP
	DZM	LASTX	/X=0
	DZM	LASTY	/Y=0
	LAC	(DFLCHR	/DEFAULT CHARACTER SIZE
	DAC	XSZ
	DAC	YSZ
	DZM	SINX	/HORIZONTAL
	LAC	(200000
	DAC	COSX
	JMP	INNDCH	/SEND INFOR TO PDP-11
/
/
HINF	LAC	(100026	/RETURN CODE, THAT'S ALL
	JMP	SEV
/
	.EJECT
/
/ EXIT REQUEST (FROM TASK "...REA") PROCESSING
/
DAEX	CLA!IAC		/RETURN NODE MAKING REQ
	JMS	SEVRN
	LAW	-24	/ANY OTHER NODES GET LOST HANDLER MESSAGE
	DAC	GIVEEV	/EVENT VARIABLE ARGUMENT
DAEX1	LAC	PDVDH	/SCAN DEQUE FOR OTHER NODES(IS THIS POSSIBLE?)
	DAC*	(R1	//IF NOT POSSIBLE, IT IS NOT HARMFUL TO LOOK
	JMS*	(PICK
	JMP	DAEX2	/NO MORE
	JMS	GIVBAK	/RETURN IT
	JMP	DAEX1
DAEX2	JMS	CLEAR	/CLEAR OUT PIREX IN PDP-11
	CAL	CCPB	/DISCONNECT INTERRUPT
	.INH
	DZM*	PDVTA	/CLEAR TG
	ISZ	PDVTA
	DZM*	PDVTA	/AND ASSIGN INHIBIT
	.ENB
	CAL	(10	/BACK TO SYSTEM
	.EJECT
/
/	FINISH UP CAL PROCESSING
/
ERR30	LAW	-30
/
/  COMMON TERMINATION PIOINT
/
SEV	JMS	SEVRN	/SET EVENT VARIABLE, DECALRE SIGNIFICANT
	JMP	PQ	/EVENT, RETURN NODE, PICK NEXT REQ.
/
/ SEVRN -- SUBROUTINE TO SET THE REQUESTOR'S EVENT VARIABLE TO
/ THE QUANTITY IN AC, DECLARE A SIGNIFICANT EVENT, DECREMENT I/O
/ TRANSFERS PENDING COUNT (NORMAL MODE), AND RETURN REQUEST NODE
/ TO THE POOL.
/
SEVRN	0
	DAC	GIVEEV	/SET UP TO CALL GIVBAK
	LAC	RN	/REQ NODE IN AC
	JMS	GIVBAK	/NODE IN AC, SETTING IN GIVEEV FOR GIVBAK
	JMP*	SEVRN
/
/  GIVBAK DOES REAL WORK, IT AXPECTS NODE ADDR IN AC, 
/  EVENT VARIABLE SETTING IN GIVEEV
/
GIVBAK	0
	DAC*	(R2	/PLACE NODE ADDR IN SYSTEM ARG. FOR IOCD, NADD
	TAD	XADJ	/ADJUST FOR PRESENT PAGE ADDR
	PAX		/TO UTILIZE N,X TYPE ADDRESSING
	LAC	6,X	/DID USER EXPECT EVENT VARIABLE BACK
	SNA		/IF SO, THIS VARIABLE IS RETURN ADDRESS
	JMP	NOSET	/IF NOT, VARIABLE IS ZERO; JUST GO IOCD,NADD
	TAD	XADJ	/AGAIN PREPARE FOR INDEXING BY ADJUSTING PAGE
	PAX		/THIS FOR RETURNING EVENT VARIABLE
	LAC	GIVEEV	/SETTING FOR RETURN STORED HERE
	DAC	0,X	/HE'S GOT IT
	LAC	(401000	/MAKE SURE SYSTEM WAKES UP., SO IT CAN TELL
	ISA		/THE CALLER HIS REQ. HAS BEEN DONE
NOSET	LAC	(POOL	/POOL IS DEQUEHEAD TO WHICH TO ADD NODE
	DAC*	(R1	/FOR NADD CALL; IOCD LEAVES IT ALONE
	JMS*	(IOCD	/DECREMENT IO COUNT FOR CALLER'S PARTITION
	JMS*	(NADD	/RETURN REQUEST NODE TO MT NODE POOL
	JMP*	GIVBAK
/
	.EJECT
/
/	SUBROUTINE BFCALC DOES COMMON SETUP FOR READ/WRITE
/  CALL+1 HAS LAC* X12 FOR WRITE, AND DAC* X12 FOR READ; RETURN AT CALL+2
/  THIS ROUTINE ASSUMES AUTOINCR. #12 LIVES THRU ROUTINE VAJX
/
BFCALC	0
	LAC	RN	/VERIFY & ADJUST (NORMAL MODE) THE ADDRESS
	DAC*	(R2)	/OF THE BEGINNING OF THE LINE (HEADER ADR).
	LAC	10,X
	DAC*	(R3)
	DAC	SIGN3	/(SAVE UN-ADJUSTED BASE FOR SECOND JMS)
	CLA!IAC
	DAC*	(R4)
	JMS*	(VAJX)	/(R3, R5, XR, & AC ARE ALTERED)
			/IS BEGINNING ADDRESS OKAY?
	JMP	ERR30	/NO -- SET REQUESTOR'S EVENT VARIABLE TO -30
	LAW	-1	/YES -- SETUP X12 AS SOURCE INDEX TO MOVE LINE
	TAD*	(R3)
	DAC*	(X12)
	.IFUND	PL311
	LAC	(5000	/WORD PAIR COUNT FOR READ, IN CASE IT IS  A READ
	.ENDC
	.IFDEF	PL311
	LAC	(6000	/PL311 RETURNS MORE INFO, SO PAIR COUNT DIFFERENT
	.ENDC
	XCT*	BFCALC	/FOR READ PLACE HEADER PAIR COUNT; FOR WRITE GET IT
	LRS	10
	AND	(776)
	DAC*	(R4)
	AAC	-4	/REDUCE TO # OF DATA WORDS FOR LEGAL CHECK
	SMA!CLL!RAR	/SKIP IF ILLEGAL, DIVIDE FOR PAIR COUNT
	JMP	.+3	/OK, GO MAKE UP CONTROL COUNT FOR LINE PAIRS
	LAW	-16	/EVENT VARIABLE FOR ILLEGAL BUFFER
	JMP	SEV	/JUST RETURN IT
	CMA!IAC		/NOW HAVE LINE PAIR COUNT FOR ARRAYS OF LINES
	DAC	COUNTC	/IN CASE NEEDED
	LAC	SIGN3	/VERIFY LINE SIZE (NORMAL MODE). R2 & R4 ARE
	DAC*	(R3)	/SETUP.
	JMS*	(VAJX)	/(R3, R5, XR, & AC ARE ALTERED)
			/IS LINE SIZE OKAY?
	JMP	ERR30	/NO -- SET REQUESTOR'S EVENT VARIABLE TO -30
	LAC*	X12	/BUMP POINTER TO DATA FIELD USER'S BUFFER
	ISZ	BFCALC	/MOVE RETURN ADDR TO CALL+2
	JMP*	BFCALC	/RETURN TO READ OR WRITE
	.EJECT
/
/MX1X2 SUBROUTINE
/
/   CALL WITH  SINGLE PRECISION NUMBER IN POINT1
/    CALL WITH POINTER TO DOUBLE PRECISION NUMBER IN POINT2
/  POINT2 IS INCREMENTED TWICE BY ROUTINE!!!!!!
/
/  RESULTING TRIPLE PRECISION NUMBER IS LEFT IN AC,MQ,T3
/
/  THE ROUTINE HANDLES SIGNS. IT IS ASSUMED THAT THE TOP
/  BIT OF ALL NUMBERS IS SIGN BIT, AND NUMBERS ARE IN TWO-COMPLEMENT FORM
/  NOTE, ONLY TOP BIT OF TOP WORD HAS SIGN, ALL REST DATA.
/
/ROUTINE USES TEMPORARIES T1,T2,T3,SIGN1,SIGN3
/
MX1X2	0
	LAC	POINT1	/GET SINGLE PRECISION NUMBER
	DAC	SIGN1	/SAVE
	SPA!CLL		/MAKE ABSOLUTE FOR MUL
	CMA!IAC
	DAC	MZOT1	/PLACE IN CORE FOR MUL'S
	DAC	MZOT2
	LAC*	POINT2	/GET HIGH HALF OF DOUBLE NUMBER
	XOR	SIGN1	/FIND SIGN OF ANSWER
	SPA!CLA		/SET UP 0 IF +
	CMA		/STORE 0 OR -1
	DAC	SIGN1
	CMA!IAC
	DAC	SIGN3	/0 OR 1 TO ADD TO LOW ORDER WORD
	LAC*	POINT2	/NOW MAKE DOUBLE PLUS
	SPA!CLL!CML	/LINK ON IF NUMBER +
	CLL!CMA		/TOP HALF ONLY CMA, NO IAC!
	DAC	T1	/HOLD TOP HALF HERE
	ISZ	POINT2	/GET LOW HALF OF TOP
	LAC*	POINT2
	ISZ	POINT2	/MOVE DOUBLE POINTER TO NEXT PAIR
	SNL!CLL		/SKIP IF NO NEED TO COMPLEMENT LOW HALF
	CMA!IAC		/LEAVES LINK ON IF CARRY TO UPPER HALF!
	SZL!CLL		/CHECK CARRY
	ISZ	T1	/WAS ONE
	NOP		/JUST IN CASE OF ISZ
	MUL		/MUL BY SINGLE PART
MZOT1	HLT
	DAC	T2	/SAVE PART OF LOW HALF OF ANSWER
	LACQ		/SAVE LOW PART OF LOW HALF
	DAC	T3
	LAC	T1	/NOW MULT HIGH HALF
	MUL
MZOT2	HLT
	DAC	T1	/SAVE HIGH HALF OF ANSWER
	LACQ		/PART OF LOW HALF
	CLL		/LINK ZERO TO CHECK CARRY OUT OF...
	TAD	T2	/ADD TOGHTHER OF LOW HALVES
	SZL!CLL		/NO SKIP IF CARRY
	ISZ	T1	/PICK UP CARRY
	NOP
	DAC	T2
/
/  NOW START COMPLEMENTING  THE THREE NUMBERS
/
	CLL
	LAC	T3
	XOR	SIGN1
	TAD	SIGN3
	DAC	T3
	LAC	T2
	XOR	SIGN1
	SZL!CLL
	IAC
	LMQ		/PUT LOW HALF BACK TO MQ
	LAC	T1	/GET HIGH HALF
	XOR	SIGN1	/COMPLEMENT IF NECESSARY
	SZL!CLL		/SKIP UNLESS NEED CARRY
	AAC	1	/AAC 1 NO CARRY TO LINK!!!
	JMP*	MX1X2	/THAT'S IT
/
/  P11 DOES SCALING FOR PDP-11 16 BIT WORD, STORES ANSWER
/  IN LOCAL STORE STARTING AT XDXH
/  AND IN OUTGOING BUFFER STARTING AT LBF+2
/
/  ROUTINE MUST RECEIVE DOUBLE PRECISION NUMBER IN AC,MQ
/  LINK MUST ENTER 0
/
P11	0
	DAC	LBF+2,X /INTO BUFFER FOR PDP-11
	DAC	XDXH,X	/SAVE COPY FOR HERE STAFRTING AT XDXH
	LLS	20	/TOP 16 BITS OF LOW ORDER HALF, IN POSITION FOR PDP11
	DAC	LBF+3,X	/TWO TOP PDP-15 BITS GARBAGE, BUT THAT OK
	CLL!RAL		/NOW TAKE 16 DATA BITS LEFT JUSTIFIED IN PDP-15 WORD
	CLL!RAL		/SO CALCULATIONS IN TWO MACHINES MATCH!!
	DAC	XDXH+1,X /SAVE COPY IN PDP-15
	AXR	2	/UPDATE XR FOR NEXT WORD PAIR
	JMP*	P11
/
/  ROUTINE CHP GETS MIDDLE THIRD OF ANSWER FROM MX1X2
/  AND ROUNDS UP IF HIGH BIT OF LOW THIRD IS SET
/
CHP	0
	LAC	T3	/LOWEST OF THREE WORD ANSWER (TOP WORD 0 HERE)
	RAL		/SAVE SIGN IN LINK
	LACQ		/GET MIDDLE THIRD OF ANSWER
	SZL!CLL		/SKIP IF NO CARRY
	AAC	1	/AAC KEEPS LINK 0, MAYBE NOT IMPORTANT ANY MORE
	JMP*	CHP	/ANSWER IN AC
/
/
/	CHAR UNPACKER
/
/  CHARACTER UMPACKER GETS CHAR'S IN IOPS
/  ASCII FROM THE POINTER X12. EACH CHARACTER IS RETURNED
/  RIGHT JUSTIFIED IN THE AC, WITH HIGH BITS STRIPPED.
/
/  UNPX SERVES AS A POINTER TO THE CORRECT ACTION FOR THE
/  NEXT CHARACTER, THERE BEING DIFERENT ACTION FOR
/  1,2,3,4,5, THEN 6 IS SAME AS 1.
/
/  THE JMS'S IN THE CODE SET UP POINTER IN UNPX FOR THE NEXT
/  CHAR.  THE ROUTINE MUST BE INITED BEFORE FIRST CALL BY
/  PLACING THE ADDRESS UNPK1 INTO UNPX.
/
/  W  A  R  N  I  N  G  !  THIS ROUTINE ASSUMES MQ UNDISTURBED
/
UNPK1	LAC*	X12	/GET FIRST WORD OF IOPS ASCII PAIR
	LRS	13	/PUT FIRST CHAR RIGHT JUSTIFIED IN AC, SAVE REST IN MQ
	JMS	UNPKX	/LEAVE POINTER FOR SECOND CHARACTER ACTION AND RETURN
	LLS	7	/SECOND CHARACTER ACTION
	JMS	UNPKX	/LEAVING POINTER FOR THIRD CHAR.
	LLS	4	/THESE ARE TOP FOUR BITS OF THIRD CHAR.
	DAC	UNPKX	/YES, THIS IS!! A SAFE TEMPORARY
	LAC*	X12	/GET SECOND WORD OF IOPS ASCII PAIR
	LMQ		/FEED IT OUT OF MQ JUST LIKE FIRST
	LAC	UNPKX	/THIRD CHAR NOW STRADDLES AC,,MQ
	LLS	3	/GOT IT!
	JMS	UNPKX	/LEAVING POINTER FOR FOURTH
	LLS	7
	JMS	UNPKX
	LLS	7
	JMS	UNPKX
	JMP	UNPK1	/AFTER FIFTH CHAR, GO DO FIRST OF FIVE AGAIN
	.EJECT
/
/ CHAR PACKER
/
/  THE CHARACTR PACKER RECEIVES ASCII CHARACTERS RIGHT
/  JUSTIFIED IN THE AC. THE CHARACTERS ARE PLACED VIA
/  THE POINTER BUFP.  THE CHARACTERS ARE COUNTED
/  IN THE COUNTER 'COUNT'. THE PACKING FORMAT PER WORD
/  IS FIRST CHARACTER RIGHT JUSTIFIED, SECOND CHARACTER
/  IN BITS 2-9, TOP TWO BITS UNUSED. THE POINTER BUFP
/  IS USED TO CHECK ON THE TOTAL NUMBER OF CHARACTERS.
/  IN CASE OF TOO MANY (>132), THE REMAINING CHARACTERS
/  ARE THROWN AWAY, AND CONTROL GOES TO DN.
/
/  PKX IS POINTER TO NEXT ACTION, AS IN UNPK. PKX IS INITED
/ BEFORE FIRST CALL BY PLACING ADDRESS PACK1 IN TO IT.
/
/
PACK1	DAC*	BUFP	/FIRST, JUST PLACE
	JMS	PKX
	CLL!SWHA
	RAR
	XOR*	BUFP	/SECOND IN BITS 2-9
	DAC*	BUFP
	ISZ	BUFP
	LAC	BUFP
	SAD	(LBF+BUFSZ	/CHECK OVERFLOW WITH CLCULATED END
	JMP	DN
	JMS	PKX
	JMP	PACK1
	.EJECT
/
/	MISCELLANEOUS SUBROUTINES
/
/
/  THE DOLINE ROUTINE OUTPUTS THE BUFFER OF XY PAIRS, AND THEN
/  CALLS RESETL TO SETUP COUNT AND POINTER FOR NEXT
/
DOLINE	0
	LAC	COUNT	/MAKE COUNT OF WORD PAIRS TO BE SENT
	AAC	XYPPB
	SNA!SPA!CLL	/SKIP IF ANY
	JMP*	DOLINE	/NONE, DO NOTHING
	AAC	100	/TO BE 400 HEADER CODDE FOR LINE
	RTL		/*4 TO GIVE BYTE COUNT FOR SPOOLER
	DAC	LBF	/THE HEADER
	JMS	RESETL	/RESET POINTER, COUNTER
	JMS	DOIO	/GO DO IO
	JMP*	DOLINE
/
/  THE RESETL ROUTINE RESETS COUNT AND BUFP FOR THE NEXT BUFFER
/
RESETL	0
	LAW	-XYPPB	/10(10) PAIRS FOR NOW
/			/10 IS A GUESS OF WHAT SIZE WILL PACK WELL
/			/INTO SPOOLING BUFFERS, SINCE CHARACTER
/			/STRINGS WILL BE OF RANDOM SIZES
	DAC	COUNT
	LAC	(LBF+2	/POINT TO DATA PORTION OF BUFFER
	DAC	BUFP
	JMP*	RESETL
/
/  SUBROUTINE VALID VERIFIES THAT INPUT CO-ORDINATE VALUES ARE
/  LESS THAN 2^14 STEPS IN MAGNITUDE. CALL WITH VALUE IN AC
/  AC IS DESTROYED.
/
/
/
VALID	0
	DAC	SIGN3	/SAVE INPUT
	SPA!CLL		/SKIP IF ALREADY +
	CMA!IAC		/MAKE + FOR TEST
	TAD	(740000	/ANY TOP BITS ON
	LAC	SIGN3	/RESTORE INPUT
	SNL		/IF ERROR CARRY TO LINK
	JMP*	VALID
IOPS7	LAW	-7	/SEND ERROR
	JMP	SEV
/
	.EJECT
/
/  SET ESTABLISHES THE PROVIDED CO-ORDINATES AT THE PRESENT
/  PEN POSITION
/
SET	LAC*	X12
	DAC	LASTX
	LAC*	X12
	DAC	LASTY	/AND LAST Y VALUE
OKEX	CLA!IAC		/SEND +1 AS OK OPERATION
	JMP	SEV
/
/
	.IFDEF	PL311
/
/SUBROUTINE PIKPEN ASSEMBLES THE DATA REQUIRED FOR THE TCB
/TO SELECT AS THE ACTIVE PEN, PEN NO.1,2 OR 3
/CALLED WITH (LBUF) INDEXING DATA BUFFER OF FORTRAN CALL
/
PIKPEN	JMS	DOLINE	/SEND ANY PENDING LINES
	LAC*	X12	/GET PEN TYPE
	DAC	NUMPEN	/UPDATE ACTIVE PEN NUMBER
	DAC	LBF+2	/DATA WORD FOR THIS TCB
	LAC	(2004	/THIS PUTS MODE=4 AND BYTE COUNT=4 
	JMP	COMMON
	.ENDC
/
	.EJECT
/
/	ROUTINES TO TALK TO PDP-11
/
/  SUBROUTINE DOIO SENDS A REQUEST TO THE PDP11, THEN RELEASES TO PQ.
/  ON AN INTERRUPT, TG AND XYDON ARE SET. TG WAKES UP WFTGR, WHICH
/  LOOKS AT POST, AND XYDON AND JUMPS TO OPDONE. ON OK, WE RETURN TO CALLER
/  OF DOIO. ON ERROR OUT OF NODES, WE RETRY. ON OTHER PDP-11 ERROR
/  (IMPOSSIBLE?!?!?), WE SET IMPERR AND CONTINUE AS IF OK.
/
DOIO	0
	LAC*	(X12	/SAVE AUTO INCR THRU IO
	DAC	SAV12
RETRY	LAC	RN	/SET POST, SAYS WE'RE WAITING
	DAC	POST	/ALSO SERVES TO REMEMBER NODE IF ABORTED
	SNA!SPA!IAC	/SKIP IF REAL NODE
	JMP	RETRY1	/NOT REAL, DON'T STLA
	DAC*	(X12	/REMEMBER STLA
	LAC*	X12
	DAC	STLA
RETRY1	DZM	XYDON	/CLEAR INTERRUPT HAPPENED
	LAC	TCBP	/POINTER FOR PIREX COMMAND STRING
	JMS	XYIU	/SEND IT
	JMP	WFTGR	/WAIT FOR INTERRRUPT TO WAKE US UP
/
OPDONE	LAC	POST	/(#12)BACK FROM 11;GET LAST REQ NODE
	DAC	RN	/(#12)IN CASE ANOTHER ABORT INTERVENED
	DZM	POST
	DZM	XYDON	/CLEAR FLAGS
	LAC	EV11	/PDP-11 STATUS
	AND	(177777	/TOP TWO BITS ARE NOT SENT
	SAD	(177001	/PIREX OUT OF NODES
	JMP	RETRY	/IN THIS CASE JUST TRY AGAIN
	RTL		/CHECK OTHER ERROS
	SPA!RTR		/SKIP IF OK
	DAC	IMPERR	/SAVE 'IMPOSSIBLE' EROR
	LAC	SAV12	/RESTORE X12
	DAC*	(X12
	JMP*	DOIO
/
XYIU	0		/SUBROUTINE TO SEND TO PDP-11
/			/AC COMTAINS TCB POINTER ON ENTRY
	DZM	EV11	/CLEAR RETURN VARIABLE
	DZM	EV11K	/AND THE OTHER ONE, IN CASE IT USED
	SIOA		/SKIP IF PDP-11 CAN TAKE IT
	JMP	.-1	/NOPE
	LIOR		/AC POINTS TO INSTRUCTION LIST
	JMP*	XYIU	/THAT'S ALL
/
CLEAR	0		/CLEAR POST,XYDON,PIREX
	DZM	POST
	DZM	XYDON
	LAC	TCBKP	/TELL PIREX TO CLEAR
	JMS	XYIU	/PIREX REQ SENDER
	CAL	WFCLER	/WAIT FOR PIREX COMPLETION
	JMS	RESETL	/FOR WHEN ABORT CALLS HERE.
	JMP*	CLEAR
/
/ INTERRUPT SERVICE ROUTINE
/
INT	0		/INTERRUPT ENTRY POINT
	DBA		/ENTER INDEX (PAGE) MODE
	DAC	ACBF	/SAVE AC
	CAPI		/CLEAR OUT FLAG SET BY PIREX
	LAC	POST	/WANTED OR NOT
	SNA!CLA!IAC	/SKIP IF YES;MAKE 1 FOR DAC'S
	JMP	INT11	/NOT WANTED, JUST GET OUT
	DAC	TG
	DAC	XYDON
	LAC	(401000)/DECLARE A SIGNIFICANT EVENT
	ISA
INT11	LAC	ACBF	/RESTORE AC
	DBR		/RETURN TO INTERRUPTED PROGRAM
	JMP*	INT
/
	.END	START
