	.TITLE	AD....	AD15 I/O HANDLER TASK.
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 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	017		12-4-73
/ 
/COPYRIGHT 1971,1973 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/W. A. DESIMONE
/M. HEBENSTREIT
/ 
/AD15 ANALOG SUBSYSTEM HANDLER TASK.
/
/ASSEMBLY PARAMETERS:
/ 
/LKS=N   WHERE AN N-LINK TABLE IS GENERATED AND USED FOR CONTROL
/	OF I/O PROCESSING AT INTERRUPT LEVEL.
/
/AD.NT=N  WHERE N IS THE POSITIVE NUMBER OF CLOCK TICKS DESIRED
/	  BETWEEN CLK. GENERATED SIGNIFICANT EVENTS.  IF UNDEFINED
/	  ASSUMED ONE.  (ONLY APPLIES TO NORMAL MODE TASK USE OF THIS
/	  (HANDLER TASK.)
/
/
/THIS HANDLER TASK PROVIDES AN RSX INTERFACE TO THE
/PDP-15 AD15 ANALOG SUBSYSTEM.  IT OPERATES AT HIGHEST
/PRIORITY (PRIO. 1) IN EXECUTIVE MODE AND COMMUNICATES
/WITH TASKS VIA QUEUE I/O REQUESTS.  AT ONE TIME, ONLY
/ONE TASK CAN USE THIS HANDLER TASK.
/ 
	.EJECT
/
/THE FOLLOWING QUEUE I/O REQUESTS ARE HONORED BY THIS
/HANDLER TASK:
/
/	CPB	3600		/HANDLER INFO (HINF)
/		EV
/		LUN
/
/	CPB	500		/CONNECT (ADCON).  CONNECT HANDLER
/		EV		/TASK TO THE REQUESTING TASK.  MUST
/		LUN		/BE ISSUED PRIOR TO ANY OTHER OF
/				/THE QUEUE I/O REQUESTS TO FOLLOW
/
/	CPB	100		/AD15 SEQUENTIAL DATA CHANNEL MODE
/		EV		/I/O SETUP (ADSSET).  SETS UP INTERNAL
/		LUN		/LINK TABLE THAT CONTROLS I/O INITIATED
/		CTB		/BY QUEUE I/O REQUEST ADSTRT.  ADSSET
/				/DOES NOT START I/O.
/	ADSSET	CONTROL TABLE
/	CTB	LKNO		/LINK NO. (1-LKS)
/		LKTYPE		/LINK TYPE (0,1,2,3) EXPLAINED BELOW
/		LCH		/LOWER CHANNEL NO. (LOWEST=0).
/		HCH		/HIGHER CHANNEL NO. (HIGHEST=177(8).
/		ISA		/ADDRESS OF INPUT STATUS (BIT ASSIGN BELOW).
/		DVT		/ADDRESS OF DIGITAL VALUES TABLE
/		CNT		/REPEAT COUNT
/		LKEV		/LINK EV.
/		MOEV		/MEM. OVERFLOW EV.
/
/
/	CPB	200		/AD15 RANDOM DATA CHANNEL MODE
/		EV		/I/O SETUP (ADRSET).  SETS UP INTERNAL
/		LUN		/LINK TABLE THAT CONTROLS I/O INITIATED
/		CTB		/BY QUEUE I/O REQUEST ADSTRT. ADRSET
/				/DOES NOT START I/O.
/	ADRSET CONTROL TABLE
/	CTB	LKNO		/LINK TABLE NO. (1-LKS)
/		LKTYPE		/LINK TYPE (0,1,2,3) (EXPLAINED BELOW)
/		NPTS		/NUMBER OF CONVERSIONS
/		IST		/ADDRESS OF INPUT STATUS TABLE
/		DVT		/ADDRESS OF DIGITAL VALUES TABLE
/		CNT		/REPEAT COUNT
/		LKEV		/LINK EV.
/		MOEV		/MEMORY OVERFLOW EV.
/
/
/NOTES: A MAXIMUM OF 'LKS' LINKS CAN BE ENTERED INTO THE LINK
/TABLE. THE DEFAULT VALUE OF 'LKS' IS 12 (BASE 8).
/THIS IMPLIES SUCCESSIVE ADRSET OR ADSSET QUEUE I/O REQUESTS
/CAN BE ISSUED TO SET UP A MAXIMUM OF 'LKS' LINKS.
/ONCE AN ADSTRT REQUEST IS MADE (SEE BELOW) THESE LINKS
/ARE PROCESSED FROM LINK NO. 1 THRU LINK NO. 'LKS'.  THIS PROCESSING
/CONTROLS I/O TRANSFERS WITHOUT ANY INTERVENING QUEUE I/O
/REQUESTS.  THE ONLY QUEUE I/O REQUEST ACCEPTED AFTER
/AN ADSTRT IS AN ADSTOP UNLESS I/O IS DONE.  THE LINKS ARE
/PROCESSED IN NUMERICAL ORDER WITH ADDED CONSIDERATIONS FOR
/LINK TYPE (LKTYPE):
/LKTYPE=
/	0- - - - -NULL LINK. IGNORE THIS LINK WHILE I/O PROCESSING.
/	1- - - - -CHAIN LINK.  AFTER THIS LINK IS PROCESSED,
/		  GO AND PROCESS NEXT LINK IN NUMERICAL ORDER.
/		  WRAP AROUND IF AT BOTTOM OF LINK TABLE.
/	2- - - - -END LINK.  AFTER THIS LINK IS PROCESSED,
/		 STOP I/O.
/	3- - - - -LOOP LINK AFTER THIS LINK IS PROCESSED,
/		 GO TO HEAD OF LINK TABLE AND PROCESS NEXT LINK.
/
/NOTES ON EV SETTING:
/
/CPB EV'S ARE SET AS USUAL FOR AN RSX I/O HANDLER TASK.  THE TWO
/EV'S (LKEV AND MOEV) IN THE ADSSET AND ADRSET CTB'S ARE SET DURING
/I/O INITIATION AND SERVICING AS FOLLOWS:
/
/	LKEV - THE CURRENT REPEAT COUNT PLUS ONE OR,
/	     - -73 IF MEMORY OVERFLOW  (MEM. OVFL. MUST BE ENABLED).
/
/	MOEV - ZERO IF NO MEMORY OVERFLOW.
/	     - NUMBER PLUS ONE OF CHANNEL CAUSING OVERFLOW.
/		(THE DIGITAL BEFORE THE OVERFLOW IS RECONSTRUCTED.)
/BIT ASSIGNMENTS FOR ISA FOR SEQ MODE INPUT STATUS
/ARE:
/	GAIN (00=1,01=2,10=4,11=8)	BITS 0,1
/	NOT USED			BITS 2-5
/	MEMORY OVERFLOW (1=ENABLED)	BIT 6
/	SET 1 FOR DATA CHANNEL BREAK	BIT 7
/	INTERNAL/EXTERNAL SYNC. (EXT=1) BIT 8
/	ADD-TO-MEMORY MODE (1=ENABLED)	BIT 9
/	SET TO 1 FOR SEQ. MODE		BIT 10
/	SET BY ADSSET REQUEST TO	BITS 11-17
/	LOWER CHANNEL NO.
/BIT ASSIGNMENTS FOR IST ENTRIES FOR RAN DCH MODE
/ARE:
/	GAIN (00=1,01=2,10=4,11=8)	BITS 0,1
/	NOT USED			BITS 2-5
/	MEMORY OVERFLOW (1=ENABLED)	BIT 6
/	SET 1 FOR DATA CHANNEL BREAK	BIT 7
/	INTERNAL/EXTERNAL SYNC, (EXT=1) BIT 8
/	ADD-TO-MEMORY MODE (1=ENABLED)  BIT 9
/	SET TO 0 FOR RANDOM MODE	BIT 10
/	ANALOG CHANNEL ADDRESS		BITS 11-17
/
/
/	CPB	300		/START AD15 CONVERSIONS (ADSTRT)
/		EV
/		LUN
/
/
/	CPB	400		/STOP AD15 CONVERS. (ADSTOP).
/		EV
/		LUN
/
/	CPB	600		/DISCONNECT AD15 HANDLER TASK FROM
/		EV		/THE REQUESTING TASK.(ADDIS)
/		LUN	
/
	.EJECT
/
/IF A REQUEST CANNOT BE QUEUED, THE FOLLOWING EVENT VARIABLE
/VALUES ARE RETURNED:
/
/	-101 -- INDICATED LUN DOES NOT EXIST
/	-102 -- INDICATED LUN IS NOT ASSIGNED TO PHYSICAL DEVICE
/	-103 -- HANDLER TASK IS NOT CORE RESIDENT
/	-777 -- NODE FOR REQUEST QUEUE UNAVAILABLE
/
/IF THE QUEUED I/O REQUEST CANNOT BE SUCCESSFULLY DEQUED,
/THE FOLLOWING EVENT VARIABLE VALUES ARE RETURNED
/ 
/	-6 -- UNIMPLEMENTED FUNCTION.
/	-30-- OUT OF PARTITION TRANSFER (NORMAL MODE)
/	-34-- DATA MISSED (SEQUENTIAL MODE ONLY)
/	-70-- INVALID I/O PARAMETER
/	-71-- LINK TABLE CONNECT OR DISCONNECT ERROR
/	-72-- STOP OR START I/O ERROR
/	-73--ADD-TO-MEMORY OVERFLOW.
/	-203--CAL NOT TSK ISSUED.
/
	.EJECT
/ 
/ASSEMBLY PARAMETERS: (COND. + UNCOND.)
/ 
	.IFUND	LKS
LKS=12
	.ENDC
	.IFUND	AD.NT
AD.NT=1				/NO. OF TICKS SET AS SEPARATING CLK.
	.ENDC
LKSZ=11				/LINK TABLE ENTRY SIZE
/
/REGISTER DEFINITIONS:
/ 
X10=10				/AUTO-INCR 10
X11=11				/AUTO-INCR 11.
R1=101				/RE-ENTRANT PSUEDO REGISTERS R1-R4.
R2=102
R3=103
R4=104
WX12=12				/WORKING AUTO-INCR 12
WX13=13				/WORKING AUTO-INCR 13
/
/DATA CHANNEL AD15 ADDRESSES:
/ 
DC24=24				/STATUS WORD WC.
DC25=25				/STATUS WORD CA-1.
DC26=26				/DIGITAL VALUES WC.
DC27=27				/DIGITAL VALUES CA-1.
/
/RSX RE-ENTRANT ROUTINE ENTRY POINTS:
/ 
NADD=107			/NODE ADDITION.
DQRQ=337			/DE-QUEUE REQUEST.
VAJX=342			/VERIFY AND ADJUST I/O TRANSFER PARAM.
IOCD=345			/DECREMENT TRANSFERS PENDING COUNT
DMTQ=361			/DE-QUEUE I/O REQUEST (FOR ABORTING).
SNAM=123			/NAME SCAN.
/
/SYSTEM INFORMATION
/ 
POOL=240			/LISTHEAD FOR POOL OF EMPTY NODES.
PDVL=252			/LISTHEAD FOR PHYSICAL DEVICE LIST.
NTSCSE=146			/REG. CONTAINING NO. OF TICKS
				/SEPARATING CLK. GENERATED SIGNIF.
				/EVENTS.
/ 
/TEMP.	STORAGE
/ 
CONSW	0			/CONNECT SWITCH (0-CLEARED)
ADIOD	1			/I/O DONE FLAG(1=I/O DONE).
/
/INSTRUCTION DEFINITIONS
/ 
/AD15 IOTS:
/
ADCV=701304			/CONVERT ANALOG TO DIGITAL.
ADRB=701312			/READ DATA BUFFER.
ADRS=701352			/READ AD15 STATUS REGISTER.
ADCF=701362			/CLEAR ALL AD15 FLAGS.
MSSF=701321			/SKIP ON MEMORY OVERFLOW FLAG.
/
.INH=705522			/INHIBIT INTERRUPTS.
.ENB=705521			/ENABLE INTERRUPTS.
/
/CONSTANTS
/ 
D.TG=10				/POS. OF TRIG. EV. IN PDVL NODE
/
	.EJECT
/
/DIRECTIVE CAL PARAM. BLOCKS USED BY THIS HANDLER
/ 
WFTCPB	20			/WAIT FOR TRIGGER
	TG
/
WFIOD	20			/WAIT FOR AD15 I/O DONE
	ADIOD
/ 
CCPB	11			/CONNECT AD15 TO INTERR. LINE.
	TG
	17			/LINE NO.(API TRP. ADDR.=57).
	ADINT
/
DCPB	12			/DISCONNECT AD15 FROM INT. LINE
	0
	17			/LINE NO.(API TRAP ADDR.=57)
	ADINT
/
	.EJECT
/
/HANDLER INITIALIZATION CODE (ONCE ONLY)
/
/START				/TEMP.
/LKSET1				/TEMP. FOR LKSET SUBR
/RN				/REQUEST NODE ADDRESS.
/RE				/REQUESTOR'S EV.
/LKBASE				/LINK BASE ADDRESS.
/PDVNA				/TEMP.
/RPCNT				/CURRENT REPEAT COUNT.
/PDVTA				/ADDR. OF TRIG. EV.
/TX12				/TEMP. FOR WX12 S/R.
/TX13				/TEMP. FOR WX13 S/R.
/CRN				/CONNECT REQ. NODE ADDRESS.
/DLEV				/DUMMY LINK EV.
/DMOEV				/DUMMY MEM. OVFL. EV.
/ERRCH				/MEM. OVFL. EV.
/LKTYPE				/LINK TYPE .
/ADAC				/AD15 TEMP. FOR AC SAVE.
/MISDAT				/FLAG USED TO TEST DATA MISSED
/XADJ				/XR ADJUSTMENT
/LKEP				/LINK ENTRY POINTER.
/S.NT				/SAVE REG. FOR NTSCSE
/ADXR				/TEMP. FOR SAVED XR.
/HNAM				/HANDLER NAME
/TG				/TRIGGER EVENT VAR.
/
/
/BEGINNING OF ONCE ONLY CODE -- HANDLER INITIALIZATION
/
START	LAC	(PDVL)		/SCAN PHYS. DEVICE LIST FOR DEVICE CODE
	DAC*	(R1)		/LISTHEAD TO R1
LKSET1	LAC	(HNAM)		/GET HANDLER NAME TO R2
RN	DAC*	(R2)		/SNAM ALTERS R1,R2,R6,XR,AC
RE	JMS*	(SNAM)		/NODE FOUND?
LKBASE	CAL	(10)		/NO. EXIT
PDVNA	DAC	.		/YES. PDVL NODE ADDRESS IN AC. SAVE.
RPCNT	AAC	+D.TG		/ADD TRIG. EV ADDRESS OFFSET
PDVTA	DAC	.		/SAVE ADDRESS OF TRIG. EV. VARIABLE
TX12	CAL	CCPB		/CONNECT INTERR. LINE.
TX13	LAC	TG		/CONNECT OK?
CRN	SPA
DLEV	CAL	(10)		/NO.  EXIT.
DMOEV	DZM	TG		/YES.  CLEAR TRIGGER.
ERRCH	LAC	(TG)		/SET TRIGGER EV IN PHY. DEV. NODE.
LKTYPE	DAC*	PDVTA
ADAC	AND	(70000)		/DETERM. "XR-ADJ" (TWOS COMPL. OF
MISDAT	TCA			/PAGE BITS).
XADJ	DAC	.		/STORE.
LKEP	LAC*	(NTSCSE)	/SAVE SYSTEM INFO ON CLK. GEN. S.E'S.
S.NT	DAC	.
	ADCF			/CLEAR ALL AD15 FLAGS.
ADXR	JMP	WFTGR		/WAIT FOR TRIGGER
HNAM	.SIXBT	"AD@"		/HANDLER NAME
TG	0			/TRIG. EV. VARIABLE (MUST BE 0 INIT.)
/
/END OF ONCE ONLY INIT. CODE
/ 
	.EJECT
/
/WAIT FOR TRIGGER TO BE SET.  CAN BE SET UNDER THE
/FOLLOWING CONDITIONS:
/
/ 1--	NORMAL REQUEST QUEUED	BIT 0 SET
/ 2--	ABORT REQUEST QUEUED	BIT 2 SET
/
/
WFTGR	CAL	WFTCPB		/WAIT FOR TRIGGER
	DZM	TG		/CLEAR
PQ	LAC	PDVNA		/NO. NORMAL REQUEST - DEQUEUE.
	DAC*	(R1)		/PDVL NODE ADDRESS TO R1
	JMS*	(DQRQ)		/(R1,R2,R4,R5,R6,XR,AC ALTERED)
	JMP	WFTGR		/NO REQUEST -- WAIT FOR TRIGGER
	DAC	RN		/SAVE ADDRESS OF REQUEST NODE
	TAD	XADJ		/ADJUST FOR XR.
	PAX
	DZM	MISDAT		/CLEAR THE MISSED DATA FLAG
	LAC	6,X		/SAVE REQUESTOR'S EV. IF SPEC. (NON-ZERO).
	SNA
	LAC	(RE)
	DAC	RE		/SAVE FOR SETTING.
/
	LAC	5,X		/FETCH FUNCT. CODE = DISPATCH
	AND	(777)		/FUNCT CODES (1-6) LEGAL
	SNA
	JMP	UNIMPL		/UNIMPL. FUNCTION (L.T. 1)
	AAC	-7
	SMA
	JMP	HFEX		/UNIMPL. FUNCTION (G.T. 6),HINF OR EXIT. OR ABORT.
	AAC	+7		/GET OFFSET BACK
	TAD	(JMP DISP)
	DAC	DISP
/
/ DISPATCH ROUTINE
/
DISP	XX			/ MODIFIED TO CONTAIN 'JMP DISP' + FUNCTION CODE
	JMP	ADSSET
	JMP	ADRSET
	JMP	ADSTRT
	JMP	ADSTOP
	JMP	ADCON
	JMP	ADDIS
/ 
/ HINF,EXIT,ABORT AND SOME UNIMPLEMENTED FUNCTIONS ENTER HERE
/
HFEX	AAC	+7		/NULLIFY AAC -7
	SAD	(777)		/EXIT?
	JMP	ADEXIT		/YES,
	SAD	(36)		/HINF?
	JMP	ADHINF		/YES.
	SAD	(017)		/ABORT REQUEST?
	JMP	ADABRT		/YES.
/ 
/ ALL UNIMPEMENTED FUNCTIONS ENTER HERE -- RETURN EV OF -6
/
UNIMPL	LAW	-6		/UNIMPL. FUNCT. SET EV TO -6.
	JMP	EV
/ 
	.EJECT
/ 
/SETUP FOR SEQ. DATA CHAN. MODE.
/ 
ADSSET	JMS	CONCHK		/CHECK FOR SAME TASK + CONNECT ISSUED
	JMP	EV		/HERE IF CONNECT ERROR (AC=-71)
	JMS	IOUND		/CHECK FOR I/O UNDERWAY - IF IT IS, ERROR.
	JMP	EV		/HERE IF ERROR (AC=-72)
	LAC	7,X		/O.K. ALLOW SETUP VERIFY + ADJUST
	DAC*	(R3)		/CTB ADDRESS
	JMS	SVAJX		/ALTERS XR,AC,R2,R3,R4,R5,WX12,LK.
		10		/WC
	JMP	EVM30A		/ERROR.  I/O PARAM. OUT OF PART
	JMS	LKSET		/ADJ CTB-1 IN AC. (LKSET ALTERS AC,LK,X10,X11,WX12,XR,R2-R5.)
	NOP			/FOR LKSET TO INDICATE SEQ MODE.
	SPA			/RETURN HERE.  IF AC NEG, ERROR
	JMP	EV		/EV SETTING IN AC.
	LAC	LKTYPE		/SUCCESSFUL SETUP.  SET LINK TYPE
	DAC*	LKEP		/TO WORD 0 OF LINK ENTRY.
	JMP	REQCMP		/REQUEST COMPLETE
/
/RETURN HANDLER INFORMATION IN EV.  ALWAYS ALLOWED IN (NOT TASK
/DEPENDENT)
/
ADHINF	LAC	(200020)	/BIT1=INPUT.  BITS 12-17 = DEV. #.
	JMP	EV		/SET EV.
/
/AD15 EXIT SERVICES REASSIGN REQUEST (NOT TASK DEPENDENT).
/MUST STOP ANY I/O IN PROGRESS BEFORE DOING ROUTINE CLEANUP.
/
ADEXIT	JMS	IOUND		/I/O UNDERWAY?
	JMP	STIOE		/YES.  STOP I/O.
ADEXT1	JMS	RETRN		/RET REQ. NODE TO POOL (RN=ADDR.).
	LAC	CONSW		/AD15 CONNECTED?
	SNA	
	JMP	ADEXT2		/NO.  NORMAL EXIT.
	DZM	CONSW		/DISCONNECT.
	LAC	CRN		/CONNECT REQUEST NODE ADDR.  MUST
	DAC	RN		/DECR. TRANSFERS PENDING TWICE SINCE
	JMS	DECTP		/CONNECT REQUEST DOES NOT DECRM. IT.
	JMS	DECTP
	JMS	RETRN		/RETURN CONNECT REQ. NODE TO POOL.
ADEXT2	CAL	DCPB		/DISCONNECT INTERRUPT. LINE.
	LAC	S.NT		/RESTORE CONTENTS OF SYS. REG. 146.
	DAC*	(NTSCSE)
	ISZ	PDVTA		/CLEAR ASSIGN INHIBIT FLAG.
	.INH			///INHIBIT INTERRS. TO PREVENT
	DZM*	PDVTA		/// REASSIGN CONFLICTS.
	.ENB			///ENABLE INTERRS.
	CAL	(10)		///EXIT
/
/
STIOE	.INH			/INHIB. TO PREVENT INCOMPLETE
	LAC	(JMP	STIO)	///MOD. OF AD15 INTERRUPT SERVICE
	DAC	ADPIV		///FOR STOPPING I/O AFTER NEXT TRANSF.
	.ENB			///ENABLE INTERRUPTS.
	CAL	WFIOD		///WAITFOR ADIOD(I/O DONE FLAG.).
	JMP	ADEXT1		/CONTINUE WITH CLEANUP.
/
/AD15 ABORT I/O ROUTINE.
/
ADABRT	LAC	5,X
	AND	(777000)
	SZA			/IS ABORT REQ. LUN = 0?
	JMP	UNIMPL		/NO.  ERROR.  RETRN. -6 EV.
	LAC	CONSW		/AD15 HANDLER TASK CONNECTED?
	SNA
	JMP	ABRT2		/NO.  CLEAN UP.
	SAD	2,X		/YES.  CONNECTED TO TASK REQ. ABORT?
	SKP			/YES.  RUNDOWN ANY I/O IN PROG. AND DISCON.
	JMP	ABRT2		/NO.  CLEAN UP.
	JMS	IOUND		/I/O UNDERWAY?
	SKP			/YES.  STOP I/O.
	JMP	ABRT1		/NO.  DISCONNECT.
	.INH			/INHIBIT INTERRUPTS TO ALLOW COMPLETE
	LAC	(JMP STIO)	///MOD. OF INTERR. SERVICE.  SET
	DAC	ADPIV		///INTERR. SERV. PIVOTS TO STOP
	.ENB			///I/O AFTER NEXT TRANSFER.
	CAL	WFIOD		///WAITFR I/O DONE (ADIOD).
ABRT1	DZM	CONSW		/DISCONNECT SO THAT ANOTHER TASK CAN CONNECT.
	LAC	S.NT		/RESTORE SYS. REG. 146.
	DAC*	(NTSCSE)
	JMS	CQUEUE		/CLEAR QUEUE OF REQUESTS.
	JMS	DECTP		/DECREM. T.P. COUNT FOR ABORT REQ.
	JMS	RETRN		/RETURN ABORT REQ. TO POOL.
	LAC	CRN		/CONNECT REQ. NODE ADDRESS.
	DAC	RN		/FOR DECTP, AND RETRN.
	JMS	DECTP		/DECREM. T.P. ONCE.  WILL BE DECREM.
	JMP	REQCMP		/AGAIN IN REQCMP ALONG WITH RETURNING
				/THE CONNECT REQ. NODE TO THE POOL.
ABRT2	JMS	CQUEUE		/CLEAR QUEUE OF REQUESTS.
	JMP	REQCMP
/
/SETUP FOR RAND. DATA CHANN. MODE
/
ADRSET	JMS	CONCHK		/CONNECT CHECK
	JMP	EV		/HERE IF ERROR (AC=-71)
	JMS	IOUND		/CHECK I/O UNDERWAY. ERROR IF IT IS
	JMP	EV		/ERROR  AC=-72
	LAC	7,X		/O.K. ALLOW SETUP. VAL. +ADJ. CTB ADDRESS.
	DAC*	(R3)
	JMS	SVAJX		/ALTERS XR,AC,R2,R4,R5,R3,WX12,LK
		7		/WC
	JMP	EVM30A		/ERR. I/O PARAM. OUT OF PART
	JMS	LKSET		/ADJ CTB-1 IN AC. (LKSET ALTERS AC,LK,X10,X11,WX12,XR
	JMP	LKRAN		/(R2-R5).  JMP LKRAN INDIC. RAND. MODE
	SPA			/RETURN HERE.  IF AC NEG, ERROR EV
	JMP	EV		/SETTING IN AC.
	LAC	LKTYPE		/SUCCESSFUL SETUP.  LINK TYPE TO
	DAC*	LKEP		/LINK ENTRY WORD 0.
	JMP	REQCMP		/
/
/START AD15 I/O.
/
ADSTRT	JMS	CONCHK		/CHECK FOR CONNECT
	JMP	EV		/HERE IF ERROR - AC=-71
	JMS	IOUND		/CHECK I/O UNDERWAY - ERROR IF IT IS
	JMP	EV		/AC=-72
	LAC	(LKHEAD)	/OK. START AT TOP OF LINK TABLE
LKNX	DAC	LKBASE		/AND FIND FIRST NON-ZERO LINK
	TAD	XADJ		/SET XR FOR LINK TABLE SCAN
	PAX
	LAC	0,X
	SZA
	JMP	SIO		/FOUND NON-NULL LINK - INITIATE I.O.
	LAC	LKBASE
	TAD	(LKSZ)
	SAD	(LKEND)		/AT END OF TABLE
	JMP	EVM72		/ALL NULL LINKS.  STOP/START I/O ERROR
	JMP	LKNX		/RECYCLE
/ 
/A NON-NULL LINK HAS BEEN FOUND -- PREPARE TO INITIATE I/O
/ 
SIO	LAC	1,X		/SET UP CHANNEL ADDRESSES
	DAC*	(DC26)		/DIGITAL VALUES (D.V.) WC.(-WC)
	LAC	2,X
	DAC*	(DC24)		/INPUT STATUS (I.S.) WC.(-WC-1)
	LAC	3,X
	DAC*	(DC25)		/INPUT STATUS ATABLE ADDR.(I.S.T.A)(CA-1)
	LAC	4,X
	DAC*	(DC27)		/DIGITAL VALUES TABLE ADDR (D.V.T.A.) (CA-1)
	LAC	6,X		/SET REPEAT COUNT.
	DAC	RPCNT
	DZM	ERRCH		/RESET MEM. OV. CHANNEL # TO ZERO FOR SETEV.
	LAC	(LAC 1,X)	/  ALSO INIT. INTERR. SERVICE
	DAC	ADPIV		/ROUTINE.
	JMS	SETEV		/SET EV VARIABLES AND CHECK REPEAT
	JMP	SIO1		/CNT.  RETS. HERE IF RPCNT NOT X-HAUSTED.
	LAC	(JMP ADUPDT)	/RETURNS HERE IF RPCNT EXHAUSTED.  SET INTERR. SERV. TO
	DAC	ADPIV		/LOOK FOR NXT. WHEN TRANSF. DONE.
SIO1	LAC	5,X		/INPUT STATUS (2000 IF RAND. DCH).
	ADCV			/START AD15 CONVERSION.
	.INH			/// INHIBIT INTERRS. PREVENTS I/O SERVICE
				///SETTING ADIOD BEFORE DZM.
	DZM	ADIOD		///CLR. I/O DONE FLAG TO IND. I/O IN PROG.
	.ENB			///ENABLE INTERRS.
	JMP	REQCMP		///REQUEST COMPLETE.  GO DEQUEUE NEXT REQ. INCASE AN
				/ADSTOP.  EV SETTINGS ETC. THAT RESULT
				/FROM I/O DONE ARE HANDLED AT INTERR. LEVEL.
/
/STOP AD15 AFTER NEXT TRANSF.
/
ADSTOP	JMS	CONCHK		/CONNECT CHK.
	JMP	EV		/ERROR (AC=-71)
	JMS	IOUND		/I/O UNDERWAY?
	SKP			/YES.  PROCEED TO STOP IT.
	JMP	REQCMP		/NO.  REQ. COMPLETE.
	.INH			/INHIBIT INTERRS. TO ALLOW COMPLETE
				///MOD. OF AD15 INTERRUPT SERVICE.
	LAC	(JMP STIO)	///
	DAC	ADPIV		///SET PIVOTS IN INTERR. SERVICE TO
	.ENB			///CEASE I/O AFTER TRANSFER.
	CAL	WFIOD		///WAIT FOR I/O DONE FLAG (ADIOD)
	JMP	REQCMP		/DONE.  LEAVE SET.  REQUEST COMPLETE
/
/ADI5 CONNECT --TIES AD15 HANDLER TASK TO ONE TASK.
/ 
ADCON	LAC	CONSW		/TASK CONNECTED?
				/(CONSW IS 0 IF THE AD HANDLER IS NOT
				/CONNECTED TO A TASK, OR THE ADDRESS
				/OF THE STL NODE IF THE HANDLER IS
				/CONNECTED TO A PARTICULAR TASK.)
	SZA
	JMP	EVM71		/YES.  CONNECT ERROR.
	LAC	2,X		/NO.  GET  STL NODE ADDRESS.
	SNA			/INVALID IF 0.(NOT TASK ISSUED.)
	JMP	EVM203		/RET. NEG. EV.(CAL NOT TSK. ISSUED).
	DAC	CONSW		/SAVE AS SWITCH AND IDENTITY OF TASK.
				/(IF THE TASK CONNECTED TO THE AD
				/HANDLER IS BUILT IN NRM MODE, SET
				/THE CLOCK SERVICE ROUTINE TO
				/DECLARE A SIGNIFICANT EVENT EVERY
				/'AD.NT' TICKS AND DON'T ALLOW THE
				/AD HANDLER TO DECLARE A SIGNIFICANT
				/EVENT ON AD INTERRUPTS. IF THE TASK
				/IS EXM MODE, DECLARE A SIGNIFICANT
				/EVENT ON AD INTERRUPTS AND DON'T
				/CHANGE ANY PARAMETERS IN THE CLOCK
				/SERVICE ROUTINE.)
	LAC	3,X		/TEST PART. BLK. PTR FOR EXM. TSK.
	SZA			/EXM. TSK?
	JMP	SEVT		/NO.  NORM. MODE TSK.  DISABLE SIGNIF.
				/DECLAR. AT INTERR. LEVEL.
	LAC	(ISA)		/YES.  RESTORE SIGNIF. EV. DECLR. AT
	DAC	ADPIV1		/INTERR. LEVEL.
ADCON1	LAC	RN		/SAVE CONNECT REQ. NODE ADDRESS FOR
	DAC	CRN		/CLEANUP DURING ABORT,EXIT AND CONNECT.
	LAC	RE		/REQUESTOR'S EV. ADDRESS 17 BITS.
	TAD	XADJ		/SETUP INDEX REGISTER.
	PAX
	CLA!IAC			/UNLIKE OTHER I/O REQ., THE REQ. NODE IS
	DAC	0,X		/NOT RET. TO POOL AND T.P. COUNT IS NOT
	LAC	(401000)	/DECRM.  JUST SET EV,DECLARE SIGNIF. EVENT
	ISA			/AND DEQUEUE ANOTHER REQ.
				/(THE REQUEST NODE FOR ADCON WILL BE
				/RETURNED TO THE POOL WHEN THE ADDIS
				/CAL IS ISSUED BY THE CONNECTING TASK.)
	JMP	PQ
SEVT	LAC	(AD.NT)		/SET DELTA TICKS TO AD.NT
	DAC*	(NTSCSE)	/THIS CODE ASSUMES AD15 HANDLER TSK
				/ONLY MODIFYING NTSCSE.
	LAC	(NOP)		/SUPPRESS SIG. EV. DECLR. AT INTERR. LEVEL.
	DAC	ADPIV1
	JMP	ADCON1		/CONT.
/
/AD15 DISCONNECT--FREES AD15 HANDLER TASK FOR CONNECTION TO
/ANOTHER TASK.
/ 
ADDIS	JMS	CONCHK		/CHK. FOR CONNECT.
	JMP	EV		/CONNECT ERROR(AC=-71).
	JMS	IOUND		/I/O UNDERWAY?
	JMP	EV		/I/O NOT DONE.  ERROR.(AC=-72).
	DZM	CONSW		/CONNECTED AND IO DONE.  CLEAR SWITCH.
	LAC	S.NT		/RESTORE SYS. REG. 146.
	DAC*	(NTSCSE)
	JMS	DECTP		/DECR. T.P. COUNT FOR DISCON. REQ.
	JMS	RETRN		/RET. TO POOL.
	LAC	CRN		/CONNECT REQ. NODE ADDRESS.
	DAC	RN		/TO RN FOR RETRN AND DECTP.
REQCMP	CLA!IAC			/1 TO AC.
EV	PAL			/SET USER EV. TO AC VALUE.
	LAC	RE		/REQUESTOR'S EV ADDRESS 17 BITS.
	TAD	XADJ		/SETUP XR.
	PAX
	PLA			/RETRIEVE EV VALUE.
	DAC	0,X		/SET REQ. EV.
	LAC	(401000)	/DECLARE SIGNIF. EVENT.
	ISA
	JMS	DECTP		/DECR. T.P. COUNT.
	JMS	RETRN		/RETURN REQ. NODE TO POOL.
	JMP	PQ		/  DEQUEUE AGAIN.
/
	.EJECT
/ 
/ EVENT VARIABLE SETTINGS (PARTIAL LIST)
/
EVM71	LAW	-71		/CONNECT/DISCONNECT ERROR
	JMP	EV
EVM72	LAW	-72		/STOP/START I/O ERROR
	JMP	EV
EVM203	LAW	-203		/CAL NOT TASK ISSUED
	JMP	EV
EVM30A	LAW	-30		/I/O PARAM. OUT OF PARTITION
	JMP	EV
/
	.EJECT
/
/ MISC. SUBROUTINES
/
/SUBR. TO DECR. TRANSFERS PENDING COUNT.  RN MUST BE SET TO REQ. NODE
/ADDRESS PRIOR TO CALL.
/
DECTP	0
	LAC	RN		/REQ. NODE ADDRESS.
	DAC*	(R2)
	JMS*	(IOCD)
	JMP*	DECTP
/
/SUBR. TO RETURN REQ. NODE POINTED TO BY RN TO POOL OF EMPTY NODES.
/
RETRN	0
	LAC	(POOL)
	DAC*	(R1)
	LAC	RN
	DAC*	(R2)
	JMS*	(NADD)
	JMP*	RETRN
/
/SUBR. TO REMOVE REQS. IN QUEUE OF TASK TO BE ABORTED.  RN CONTAINS THE
/ABORT REQ. NODE ADDRESS.
/
CQUEUE	0
	LAC	PDVNA		/PDVL NODE ADDRESS.
	DAC*	(R1)
	LAC	RN		/REQUEST NODE ADDRESS.
	DAC*	(R2)
	JMS*	(DMTQ)		/R1,R2,R3,R5,R6,X10,X11,X12,XR,AC ALTERED.
	JMP*	CQUEUE
/
/CONNECT/DISCONNECT CHECK.
/
/CALLING SEQUENCE:
/		JMS	CONCHK
/		NEXT INSTR.	/SUBR. RET. IF CONN. ERR.(NO CONNECT DONE OR MISMATCH)
/		NEXT INSTR.	/SUBR. RET IF CONNECT DONE TO REQ. TASK.
/	AC=-71 RETURNED ALWAYS.
/
CONCHK	0		/SUBR. ENTRY.
	LAC	CONSW	/WAS CONNECT PERFORMED(ADCON)?
	SNA
	JMP	CONERR	/NO.  CONNECT ERROR.
	SAD	2,X	/YES.  COMP. STL NODE ADDR. TO CONSW(CONTAINS CONN.
	ISZ	CONCHK	/STL NODE ADDRESS).  IF MATCH,BUMP EXIT TO IND.
			/CONNECT DONE AND NO CONNECT ERROR.
CONERR	LAW	-71	/RETURN WITH AC=-71 IN ALL CASES.
	JMP*	CONCHK
/
/AD15 I/O UNDERWAY CHECK.
/
/CALLING SEQUENCE:
/		JMS	IOUND
/		NEXT INSTR.	/RET HERE WITH AC=-72 IF I/O UNDERW.
/		NEXT INSTR.	/RET HERE IF I/O DONE!
/
IOUND	0		/SUBR. ENTRY.
	LAC	ADIOD	/I/O DONE?
	SZA
	ISZ	IOUND	/YES.  BUMP EXIT.
	LAW	-72	/NO.  BUMP BYPASSED.  AC=-72
	JMP*	IOUND
/
	.EJECT
/
/LINK TABLE - DEFAULT SIZE IS 12 (8) LINKS (11(8) WORDS/LINK).
/
/LINK ENTRY:
/	LINK TYPE (0,1,2,3) (0=NULL,1=CHAIN,2=END,3=LOOP)
/	DIGITAL VALUES WORD COUNT (-WC)
/	INPUT STATUS WORD COUNT (-WC-1) (HCH+1 FOR SEQ. MODE)
/	INPUT STATUS TABLE ADDRESS (CA-1) (0 FOR SEQ. MODE)
/	DIGITIZED VALUES TABLE ADDRESS (CA-1)
/	INPUT STATUS (2000 IF RANDOM MODE-SET BIT 7 FOR DCH MODE)
/	-REPEAT COUNT (-1 IS ASSUMED IF NO NON-ZERO VALUE SPECIFIED)
/	LINK EVENT VARIABLE ADDRESS -1 (0 IF NOT SPEC.)
/	LINK	MEM OVFL ERR ADDRESS -1 (0 IF NOT SPEC.)
/
LKTBSZ=LKS*LKSZ
/
/
/
LKHEAD=.
	.REPT	LKTBSZ
	0
LKEND=	.
/
	.EJECT
/
/LK TABLE SETUP PROCESSOR
/
/CALLING SEQUENCE:
/	JMS	LKSET		/CTB ADDRESS -1 IN AC (ALREADY VERIFIED)
/	JMP	LKRAN		/NOP IF SEQUENTIAL MODE
/	NEXT INSTRUCTION	//SUBR RETURN. AC POS OR NEG.
/THIS SUBR. ALTERS AC,LK,X10,X11,WX12,XR,R2-R5.  RETURN AC POS. IF
/NO ERRORS DETECTED. NEG EV SETTING IF ERRORS.
/RETURNS WITH ENTRY PTR. IN LKEP AND LINK TYPE IN LKTYPE.  CALLER MUST
/SET LINK TYPE IF NO ERRORS DETECTED IN THIS SUBROUTINE.
/
MLKS=-LKS			/LINK TABLE SIZE PARAMETERS.
PLKSM1=LKS-1
/
LKSET	0			/SUBR. ENTRY
				/CTB-1 TO X10
	DAC*	(X10)
	LAC*	X10		/GET LK NO.
				/CHECK BELOW WILL GO THRO IF LK. NO IS
				/L.E. LKS AND LK. NO. -1 IS G.E. 0.
	TAD	(MLKS)		/1-LKS RANGE.  IF NOT, EXIT IMMED.
	SMA!SZA			/WITH APPRO EVENT VARIABLE IN AC
	JMP	EVM70		/G.T. 12 ERROR
	TAD	(PLKSM1)		/L.E. LKS
	SPA!CLL			/G.E. 1 CLEAR LINK FOR MUL.
	JMP	EVM70		/L.T. 1 ERROR
	DAC	F1		/OK IN RANGE. LK-1 IN AC. FIND
	LAC	(LKSZ)		/LK TABLE DISPLACEMENT. LK-1 AS ONE FACTOR.
	MUL			/OTHER FACTOR IN AC. (LKSZ*(LK-1))
F1	XX
	LACQ			/GET PRODUCT (DISPLACEMENT)
	TAD	(LKHEAD)	/ADD ADDR. OF LK. TABLE HEAD.
	DAC	LKEP		/SAVE ENTRY PTR. FOR LATER SETTING .
	DAC*	(X11)		/X11 POINTS TO LK ENTRY .
	LAC*	X10		/GET THE LINK TYPE
	AAC	-3		/CHECK FOR 0-3 RANGE.
	SMA!SZA			/G.T. 3?
	JMP	EVM70		/G.T. 3 ERROR
	AAC	+3		/L.T. 0?
	SPA
	JMP	EVM70		/L.T. 0, ERROR
	DAC	LKTYPE		/G.E 0.  OK.  SAVE FOR LATER SETTING.
	XCT*	LKSET		/LKSET =   NOP IF SEQ.
/ 
/ PROCESS SEQ. MODE LINKS HERE
/
	LAC*	X10		/JMP LKRAN IF RAN. GET LOW CHANL.
	DAC	LKSET1		/AND CHECK FOR > 177(E).  STORE TEMP.
	AND	(776000)	/G.T. 177(E)?
	SZA
	JMP	EVM70		/YES ERROR
	LAC*	X10		/GOOD CHANL NO. IN LKSET1.  DIGIT. VAL.
	AAC	1		/GET HCH+1 INTO MISDAT FOR CHECK ON
	DAC	MISDAT		/MISSED DATA (SEQ. MODE ONLY)
	AAC	-1		/RESTORE THE AC
	CMA			/WC= (LCH-1)-UCH.  INPUT STATUS WC
	TAD	LKSET1		/HAS NO MEANING FOR SEQ. MODE!!
	SMA			/IF POS.,ERROR(LCH ANDHCH NOT ORDERED).
	JMP	EVM70
	DAC*	X11		/SET DIG. VAL. WC IN LK ENTRY 1.
	TCA			/TWC TO DVWCI FOR SUAJX
	DAC	DVWCI
	LAC	MISDAT		/STORE HCH+1 IN WORD 2 INCREMENTING X11
	DAC*	X11
	DZM	MISDAT
	DZM*	X11		/ZERO WORD 3 FOR MODE DETERMINATION
	LAC*	X10		/AT INT. LEVEL. NOW GET INPUT STATUS
	JMS	SVAJX		/ADDRESS AND VALIDATE.  VIA SVAJX
L1		1		/WC. AC,R2,R3,R4,R5,XR,WX12, LK ALTERED.
	JMP	EVM30		/RETURNS HERE IF ERROR (OUT OF PART).
	LAC*	WX12		/RETURNS HERE IF OK. WITH ADJUSTED
	AND	(777400)	/ADDR -1 IN WX12 AND AC.
	XOR	(200)		/INPUT STATUS MERGED WITH LKSET 1 AND
	XOR	LKSET1		/BIT 10 FORCED TO 1 FOR SEQ. DCH.
	DAC	LKSET1		/SAVE FOR LINK ENTRY 5
	LAC*	X10		/GET DIG. VALUES TABLE ADDRESS AND VAL/ADJ
	JMS	SVAJX		/AC,R2,R3,R4,R5,XR,WX12, LK ALTERED.
DVWCI	XX			/SET TO DIG VALUES WC
	JMP	EVM30		/ERROR
	DAC*	X11		/SET CA-1 TO LINK ENTRY 4.
	LAC	LKSET1		/SET INPUT STATUS TO LINK ENTRY 5
	DAC*	X11
/ 
/ COMMON CODE FOR SEQ. AND RND. MODES
/ 
LKSET2	LAC*	X10		/GET REPEAT CNT AND CHECK FOR POS.
	SPA
	JMP	EVM70		/IF NEG, ERROR.
	SNA			/IF 0, FORCED TO 1
	AAC	+1
	TCA			/-CNT TO LINK ENTRY 6.
	DAC*	X11
	LAC*	X10		/GET LINK EV.
	SNA			/ZERO IF NOT SPEC.
	JMP	BYP2		/ZERO TO LINK ENTRY.
	JMS	SVAJX		/VAL/ADJ.
		1		/WC.
	JMP	EVM30		/OUT OF PARTITION ERROR.
BYP2	DAC*	X11		/LINK EV-1 TO LINK ENTRY 7.
	LAC*	X10		/GET MEM. OVERFLOW EV. IF ZERO, DON'T
	SNA			/VAL/ADJ.
	JMP	BYP1		/SET LINK ENTRY 10 TO ZERO.
	JMS	SVAJX		/VAL/ADJ. AC,R2,R3,R4,R5,XR,WX12,LK ALTERED.
		1		/WC
	JMP	EVM30		/ERROR.
BYP1	DAC*	X11		/MEM. OVR. EV ADDR-1 IN AC. TO LINK ENTRY 10.
LKEX	ISZ	LKSET		/BUMP EXIT.
	JMP*	LKSET		/ENTRY 10. POS AC FOR RETURN
EVM30	LAW	-30		/I/O PARAMETER OUT OF PARTITION
	JMP	LKEX
EVM70	LAW	-70		/INVALID I/O PARAMETER
	JMP	LKEX
/ 
/ CODE FOR RND. MODE LINK ENTRIES
/
LKRAN	LAC*	X10		/HERE FOR RAN. DCH. MODE. GET NO.
	DAC	RDVWC1		/SET WC FOR SVAJX ON DIG. VAL. TBL.
	DAC	RSTWC1		/SET WC FOR SVAJX ON INPUT ST. TBL.
	TCA			/OF PTS TO CONVERT AND CHECK FOR
	SMA!SZA			/GREATER THAN ZERO.
	JMP	EVM70		/ERROR. NO. OF PTS INDIC. L.E. ZERO
	DAC*	X11		/-WC TO LINK ENTRY 1.
	AAC	-1		/-WC -1 TO INPUT STATUS WC. LINK ENTRY 2.
	DAC*	X11		/NEED ONE LESS SINCE DCH BUMPS STATUS WC FIRST.
	LAC*	X10		/GET INP. STAT. TABLE ADDRESS AND VAL/ADJ.
	JMS	SVAJX		/AC, R3, R2,R4,R5,XR,WX12 ALTERED.
RSTWC1	XX			/SET TO NO. OF PTS. TO CONVERT.
	JMP	EVM30		/ERROR RETURN
	DAC*	X11		/INPUT STATUS ADDR-1 IN AC. TO LINK ENTRY
	LAC*	X10		/NO. 3.
	JMS	SVAJX
RDVWC1	XX			/SET TO NO. OF PTS TO CONVERT
	JMP	EVM30		/ERROR RETURN.
	DAC*	X11		/DIG. VALUES ADDR-1 IN AC. TO LINK ENTRY 4.
	LAC	(2000)		/BIT 7 SET FOR RAND STATUS TO IND DCH MODE.
				/BIT 10=0 FOR RANDOM MODE.  ALL OTHER BITS
				/IGNORED.
	DAC*	X11		/SET LINK ENTRY 5.
	JMP	LKSET2		/ GO TO LKSET2 FOR REST OF PROC.
/
	.EJECT
/
/SVAJX - SUBR TO VERIFY AND ADJUST 15 BIT ADDRESSES TO
/17 - BIT ADDRESSES.
/
/CALLING SEQUENCE:	/XR,AC,R2,R3,R4,R5,WX12,LK ALTERED
/	JMS	SVAJX		/ADDR. TO BE ADJ. IN AC. REQ. NODE ADDR IN RN.
/		WC		/WC
/	NEXT	INSTR.		/RETURN HERE IF VAJX ERROR
/	NEXT	INSTR.		/RETURN HERE WITH ADJ ADDRESS-1 IN
/				/AC AND WX12.
SVAJX	0			/SUBR. ENTRY
	DAC*	(R3)		/ADDRESS TO R2
	LAC*	SVAJX		/GET WC AND PUT IN R4
	DAC*	(R4)
	ISZ	SVAJX		/BUMP EXIT.
	LAC	RN		/REQ. NODE ADDRESS TO R2.
	DAC*	(R2)
	JMS*	(VAJX)		/ALTERS AC,R3,R5,XR
	JMP*	SVAJX		/ERROR RETURN - EXIT IMMEDIATELY.
	LAC*	(R3)		/GET ADJ. ADDRESS.
	AAC	-1		/MAKE ADDR-1
	DAC*	(WX12)		/PUT IN X12 ALSO IN CASE IT HAS TO
	ISZ	SVAJX		/BE REFERENCE AS 17-BITS-BUMP EXIT
	JMP*	SVAJX		/RETURN WITH ADDR-1 IN AC.
/
	.EJECT
/
/AD15 INTERRUPT SERVICE
/
ADINT	0
	DBA			/DISABLE BK ADDRESSING FOR PG MODE OPER.
	DAC	ADAC		/SAVE AC
	PXA			/SAVE XR
	DAC	ADXR
	LAC	LKBASE		/GET BASE ADDRESS OF LINK TO XR.
	TAD	XADJ
	PAX
	DZM	MISDAT		/ZERO MISSED DATA FLAG
	MSSF			/MEMORY OVERFLOW?
	SKP			/NO - GO ON AS QUICKLY AS POSSIBLE
	JMP	ADMOFL		/GO HANDLE MEMORY OVERFLOW
	LAC	3,X		/IS THIS SEQ. MODE?
	SZA
	JMP	ADPIV		/NO -- DON'T CHECK MISSED DATA
	ADRS			/YES -- HAVE WE MISSED DATA?
	AND	(177
	SAD	2,X
	JMP	.+3		/NO -- ALL'S WELL
	ISZ	MISDAT		/YES -- SET THE FLAG
	JMP	ADMOFL
ADPIV	XX			/JMP ADUPDT IF LAST TRANSFER FOR LINK.
				/JMP STIO IF EXIT REQUESTED.
				/JMP STIO IF ABORT REQUESTED FOR CONN. TASK.
				/JMP STIO IF ADSTOP REQUESTED FOR CONN. TASK.
				/LAC 1,X OTHERWISE.
/
	DAC*	(DC26)		/ SET D.V. WC.
	LAC	2,X		/SET I.S WC.
	DAC*	(DC24)
	LAC	3,X
	DAC*	(DC25)		/SET I.S. TABLE ADDRESS.
	LAC	4,X
	DAC*	(DC27)		/SET D.V. TABLE ADDRESS.
	LAC	5,X		/GET INPUT STATUS (2000 IF RAND. MODE).
ADIOT	ADCV!ADCF		/AD15 CONVERT (CLEARS A/D DONE FLAG).
				/ALSO CLEAR AL OTHER AD15 FLAGS.
	JMS	SETEV		/BUMP REPEAT CNT + TEST FOR ZERO + SET EV'S.
	JMP	ADEX1		/RETURN HERE IF RPCNT NOT X-HAUST. 
	LAC	(JMP ADUPDT)	/HERE IF RPCNT X-HAUSTED. RESET ADPIV FOR LAST TRANSF.
ADEX2	DAC	ADPIV
ADEX3	LAC	(401000)	/DECLARE SIGNIF. EVENT.
ADPIV1	XX			/ISA FOR EXM. TSK.  NOP FOR NORMAL MODE TSK.
	LAC	ADXR		/RESTORE XR
	PAX
	LAC	ADAC		/RESTORE AC
	DBR
	JMP*	ADINT		/EXIT
ADEX1	LAC	(LAC 1,X)	/REINIT ADPIV
	JMP	ADEX2
/
	.EJECT
/
/RECONSTRUCT DIGITAL VALUE BEFORE
/BY TAKING OVERFLOWED VALUE AND SUBTRACTING AUGEND THAT
/CAUSED OVERFLOW.
/
ADMOFL	JMS	SAINCR		/SAVE AUTO-INCR. 12,13.
	LAC	MISDAT		/WAS DATA MISSED?
	SZA			/IF AC=0 -- NO
	JMP	ADMDAT		/YES -- PREPARE TO RETURN EV OF -34
	LAC*	(DC27)		/GET CA AND SUBTR. 1 FOR AUTO-INCR.
	AAC	-1
	DAC*	(WX12)		/SET AUTO-INCR 12 AND 13.
	DAC*	(WX13)
	ADRB			/READ DATA BUFFER (701312)
	TCA			/-AUGEND
	TAD*	WX12		/PLUS OVERFLOWED VALUE.
	DAC*	WX13		/RESET IT TO PREVIOUS VALUE.
	LAC*	(DC25)		/ST. WORD CA.  IF 0,SEQ. MODE.
	SNA			/IF NON 0, RAND. MODE. PTS. TO NEXT STATUS.
	JMP	SMOF		/SEQ. MODE.
	AAC	-2		/RAND. MODE.  BACK UP PTR.
	DAC*	(WX12)		/SETUP AUTO INCR. 12.
	LAC*	WX12		/GET OFFENDING STATUS FOR CHNL. #
	AND	(177)		/MASK.
	IAC			/ADD 1 FOR RETURN.
	JMP	ADMOF1
SMOF	ADRS			/IN SEQ. MODE, ST. INDICATES CHNL. # +1.
	AND	(177)		/MASK.
	SNA			/CHECK FOR SPECIAL CASE OF CH. # 177.
	LAC	(200)		/YES. ADD ONE. (BY RETRN. 200).
ADMOF1	DAC	ERRCH		/SAVE FOR EV SETTING.
	JMS	RAINCR		/RESTORE AUTO INCR. 12,13.
	JMP	STIO		/STOP I/O.
/ 
ADMDAT	LAW	-1		/DATA WAS MISSED
	JMP	ADMOF1
/
/ THIS ROUTINE IS ENTERED WHENEVER THE LAST TRANSFER FOR A LINK
/ HAS BEEN COMPLETED. ROUTINE FINDS NEXT LINK TO BE PROCESSED.
/
ADUPDT	LAC	(LAC 1,X)
	DAC	ADPIV		/REINIT FOR TRANSF
	LAC	0,X		/GET LK TYPE.
	SAD	(1)		/CHAIN?
	JMP	NEXTLK		/FIND NEXT NON-NULL LINK
	SAD	(2)		/END?
	JMP	STIO		/YES.  STOP I/O.
LKTBT	LAC	(LKHEAD)	/MUST BE LOOP LINK!!
LKNXT	DAC	LKBASE
	TAD	XADJ		/ADJUST
	PAX			/SET XR
	LAC	0,X
	SZA			/IF NON-ZERO, OK TO PROCESS
	JMP	ADLKPR		/GO PROCESS
NEXTLK	LAC	LKBASE		/WILL EVENTUALLY FIND NON-NULL LINK.
	TAD	(LKSZ)		/ADD LK SIZE FOR OFFSET.
	SAD	(LKEND)		/WRAP AROUND IF END OF LINK TABLE
	JMP	LKTBT		/REACHED.
	JMP	LKNXT		/CHECK AGAIN
/
/
STIO	ISZ	ADIOD		/SET AD15 I/O DONE FLAG
	ADCF			/CLEAR ALL AD15 FLAGS.
	JMS	SETEV		/SET EV'S
	JMP	ADEX3		/UNCOND. GO TO ADEX 3
	JMP	ADEX3		/
ADLKPR	LAC	6,X		/UPDATE RPCNT
	DAC	RPCNT
	JMP	ADPIV		/GO PROCESS
/
	.EJECT
/
/SUBROUTINE SETEV SETS LK. AND MEM. OVFL  EVENT VARAIBLES AND
/CHECKS RPCNT (REPEAT COUNT)
/
/CALLING SEQUENCE:
/	JMS	SETEV
/	NEXT	INST.	/RET. HERE IF MORE REPEATS(OR MEM. OVFL.)
/	NEXT	INSTR.		/RET. HERE IF RPCNT EXHAUSTED (0).
/
SETEV	0			/SUBR. ENTRY
	JMS	SAINCR		/DSAVE AUTO-INCR 12,13.
	LAC	7,X		/GET LINK EV (CURRENT)
	SNA			/IF ZERO, SET UP DUMMY EV.
	LAC	(DLEV-1)
	DAC*	(WX12)
	LAC	10,X		/GET MEM. OVFL. EV-1.  IF 0, SET UP DUMMY EV.
	SNA
	LAC	(DMOEV-1)
	DAC*	(WX13)
	LAC	ERRCH
	SAD	(-1		/WAS DATA MISSED?
	JMP	SETMIS		/YES -- SET EV TO -34
	SZA			/MEMOVERFLOW?
	JMP	SETOVF		/YES
	LAC	RPCNT		/NO. GET CURRENT REPEAT COUNT
	TCA			/WAS NEG. MAKE POS.
	AAC	+1		/FOR REPEATS PLUS ONE.
	DAC*	WX12		/SET IN LINK EV.
	LAC	ERRCH		/SET MEM OVERFLOW EV (0 IF NO ERROR)
	DAC*	WX13
	JMS	RAINCR		/RESORE AUTO-INCR. 12,13.
	ISZ	RPCNT		/BUMP RPCNT. X-HAUSTED?
	JMP*	SETEV		/NO
	ISZ	SETEV		/YES - BUMP RETURN
	JMP*	SETEV
SETOVF	DAC*	WX13		/SET MO EV. TO CHANN # + 1.
	LAC	(-73)		/SET LKEV TO -73.
SETOV1	DAC*	WX12
	JMS	RAINCR		/RESTORE AUTO-INCR. 12,13.
	JMP*	SETEV
/
SETMIS	DAC*	WX13		/SET M.O. TO CHANNEL # + 1.
	LAW	-34
	JMP	SETOV1
/
/SAVE WORKING AUTO-INCR. REGISTERS 12,13.
/
SAINCR	0
	LAC*	(WX12)
	DAC	TX12
	LAC*	(WX13)
	DAC	TX13
	JMP*	SAINCR
/
/RESTORE WORKING AUTO-INCR REG. 12,13
/
RAINCR	0
	LAC	TX12
	DAC*	(WX12)
	LAC	TX13
	DAC*	(WX13)
	JMP*	RAINCR
/
	.END	START
