/ 
/ 
/                   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 #10
/
/ COPYRIGHT 1971, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ RSX AFC-15 HANDLER TASK     12 JAN 72        H. KREJCI, W.A DESIMONE
/
/ THIS HANDLER TASK IS TO PROVIDE AN RSX INTERFACE TO THE
/ PDP-15 FLYING CAPACITOR ANALOG INPUT (AFC-15) FRONT END
/ DEVICE.
/
/ THE SYMBOL "FMAD" MUST BE DEFINED CONTAINING THE ADDRESS
/ OF THE FIRST AFC MODULE IN BITS 0-7, AND THE SYMBOL "NMOD"
/ MUST BE DEFINED AS THE NUMBER OF AFC MODULES.  THE MODULES 
/ ARE ASSUMED TO BE IN CONTIGUOUS SLOTS.  (FOR HARDWARE 
/ PURPOSES, MODULE ADDRESSES ARE CONSIDERED TO CONSIST OF
/ THREE PARTS: X, BITS 0-2; Y, BITS 3-5; & WD BITS 6-7).
/
/ "FMAD" & "NMOD" ARE DEFINED VIA CONDITIONAL ASSEMBLY
/ PARAMETERS.
/
/
	.IFUND	FMAD
	.END -- "FMAD" MUST BE DEFINED
	.ENDC
	.IFUND	NMOD
	.END -- "NMOD" MUST BE DEFINED
	.ENDC
NCHN=10*NMOD	/NUMBER OF ANALOG CHANNELS
/
/ THE FOLLOWING CAL PARAMETER BLOCKS ARE USED TO QUEUE REQ-
/ UESTS FOR AFC SERVICE.
/
/   HANDLER INFORMATION (3 WORDS)
/
/	(0)  3600 (OCTAL FUNCTION CODES)
/	(1)  EVENT VARIABLE ADDRESS
/	(2)  LOGICAL UNIT NUMBER
/
/   ATTACH AFC (3 WORDS)
/
/	(0)  2400 (OCTAL FUNCTION CODES)
/	(1)  EVENT VARIABLE ADDRESS
/	(2)  LOGICAL UNIT NUMBER
/
/   DETACH AFC (3 WORDS)
/
/	(0)  2500 (OCTAL FUNCTION CODES)
/	(1)  EVENT VARIABLE ADDRESS
/	(2)  LOGICAL UNIT NUMBER
/
/   "GET" SEQUENTIAL ANALOG CHANNELS (4 WORDS)
/
/	(0)  3000 (OCTAL FUNCTION CODES)
/	(1)  EVENT VARIABLE ADDRESS
/	(2)  LOGICAL UNIT NUMBER
/	(3)  CONTROL TABLE ADDRESS
/
/	"GET" CONTROL TABLE (4 WORDS)
/
/	(0)  FIRST CHANNEL NUMBER ***
/	(1)  LAST CHANNEL NUMBER ***
/	(2)  ADDRESS OF GAIN TABLE
/	(3)  ADDRESS OF DIGITAL VALUE VALUES TABLE
/
/		*** CHANNEL ARE NUMBERED FROM ZERO
/
/ IF A REQUEST CANNOT BE QUEUED, THE EVENT VARIABLE, IF
/ SPECIFIED, IS SET TO ONE OF THE FOLLOWING NEGATIVE VALUES
/ TO INDICATE REJECTION AND THE REASON:
/
/	-101 -- LUN DOES NOT EXIST,
/	-102 -- LUN IS NOT ASSIGNED TO A PHYSICAL DEVICE-UNIT,
/	-103 -- HANDLER TASK IS NOT RESIDENT,
/	-777 -- NODE FOR REQUEST IS UNAVAILABLE (EMPTY POOL).
/
/ IF A REQUEST IS QUEUED, THE EVENT VARIABLE, IF SPECIFIED,
/ IS CLEARED (BY THE QUEUE I/O DIRECTIVE) AND LEFT FOR THE
/ HANDLER TASK TO SET NON-ZERO.  IF THE REQUEST IS PERFORMED,
/ THE EVENT VARIABLE (IF SPECIFIED) IS SET POSITIVE UPON
/ SUCCESSFUL COMPLETION.  IF A REQUEST CANNOT BE PERFORMED,
/ THE EVENT VARIABLE (IF SPECIFIED) IS SET TO ONE OF THE
/ FOLLOWING NEGATIVE VALUES TO INDICATE FAILURE AND THE CAUSE:
/
/	  -6 -- ILLEGAL REQUEST FUNCTION,
/	 -24 -- LUN HAS BEEN REASSIGNED WHILE REQUEST WAS IN QUEUE,
/	 -30 -- OUT-OF-PARTITION TRANSFER (NORMAL MODE),
/	 -70 -- CONTROL TABLE PARAMETER ERROR.
/
X10=10		/AUTO-INCREMENT REG 10
X11=11		/AUTO-INCREMENT REG 11
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
VAJX=342	/VERIFY & ADJUST ENTRY POINT
IOCD=345	/DECLARE I/O REQUEST COMPLETE ENTRY POINT
D.TG=10		/POSITION OF TRIGGER EVENT VARIABLE IN PDVL NODE
DMTQ=361	/REM. PENDING REQ. FROM QUEUE ROUT. ENTRY PT. (FOR ABORT).
SADIX=SAD!30000	/SAD INDIRECT & INDEXED
DACIX=DAC!30000	/DAC INDIRECT & INDEXED
.INH=705522	/INHIBIT INTERRUPTS
.ENB=705521	/ENABLE INTERRUPTS
FCMOD=701021	/SELECT ACF MODE
FCLAG=702024	/* LOAD ADDRESS & GAIN
FCEI=702004	/* ENABLE AFC INTERRUPT
FCRB=702032	/* READ A-D BUFFER
		/"*" INDICATES MODE SELECTION IS REQUIRED, AND
		/THE SYMBOL "/*/" FLAGS INSTRUCTIONS THAT
		/MUST BE ADJACENT TO EACH OTHER.
/
/ HANDLER INITIALIZATION
/
START	LAC	(PDVL)	/SCAN PHYSICAL DEVICE LIST FOR FOR NODE
	DAC*	(R1)	/FOR THIS DEVICE.
	LAC	(DNAM)
	DAC*	(R2)
	JMS*	(SNAM)	/(R1, R2, R6, X17, XR, & AC ARE ALTERED)
			/NODE FOUND?
	CAL	(10)	/NO -- EXIT
	DAC	PDVNA	/SAVE PDVL NODE ADDRESS
	AAC	+D.TG	/AND TRIGGER EVENT VARIABLE ADDRESS
	DAC	PDVTA	/TRIGGER EVENT VARIABLE ADDRESS ADDRESS.
	CAL	CCPB	/CONNECT INTERRUPT LINE
	LAC	TG	/CONNECT OKAY?
	SPA
	CAL	(10)	/NO -- EXIT
	DZM	TG	/YES -- CLEAR TRIGGER EVENT VARIABLE AND
	LAC	(TG)	/SET TRIGGER EVENT VARIABLE ADDRESS IN
	DAC*	PDVTA	/PHYSICAL DEVICE NODE
	AND	(070000)/DETERMINE "XR-ADJ"
	TCA
	DAC	XADJ
/
	LAC	(NOP)	/INITIALIZE 'DLYSW' & 'PCHN'.
	DAC	DLYSW
	LAC	3777
	DAC	PCHN
/
	JMP	WFTGR	/WAIT FOR TRIGGER
/
DNAM	.SIXBT "AF@@@@"	/DEVICE NAME (HANDLER TASK NAME IS "AF....")
/
/ WAIT FOR TASK TO BE TRIGGERED (BY 'QUEUE I/O' DIRECTIVE)
/ TO SIGNAL THAT A REQUEST HAS BEEN QUEUED.
/
WFTGR	CAL	WFTCPB	/WAIT FOR TRIGGER EVENT VARIABLE TO BE SET
/
/ THE TASK HAS BEEN TRIGGERED -- PICK A REQUEST FROM QUEUE (IF ANY)
/
	DZM	TG	/CLEAR TRIGGER
/
PQ	LAC	PDVNA	/DE-QUEUE 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	RNA	/YES -- SAVE ADDRESS OF REQUEST NODE
	TAD	XADJ	/SETUP XR TO ACCESS NODE
	PAX
	LAC	6,X	/SAVE [REQUESTOR'S] EVENT VARIABLE ADDRESS (17-BITS)
	SNA		/(IF NONE SPECIFIED USE POINTER AS EVENT VARIABLE)
	LAC	(EVA)
	DAC	EVA
/
	LAC	5,X	/FETCH CAL FUNCTION CODE
	AND	(777)
	SAD	(030)	/GET REQUEST?
	JMP	GET	/YES -- READ SEQUENTIAL CHANNELS
	SAD	(024)	/NO -- ATTACH REQUEST?
	JMP	ATTACH	/YES -- ATTACH TO A TASK
	SAD	(025)	/NO -- DETACH REQUEST?
	JMP	DETACH	/YES -- DETACH FROM TASK
	SAD	(036)	/NO -- HANDLER INFO REQUEST?
	JMP	HINF	/YES -- RETURN INFO IN EVENT VARIABLE
	SAD	(777)	/NO -- EXIT (DEASSIGNED) REQUEST?
	JMP	DAEX	/YES -- DEATTACH & EXIT
	SAD	(017)	/ABORT REQ.?
	JMP	AFABRT	/YES
ERR6	LAW	-6	/NO -- UNIMPLIMENTED FUNCTION -- SET
	JMP	FINIS	/EVENT VARIABLE TO -6
/
/ ATTACH TO A TASK
/
ATTACH	LAC	PDVNA	/ATTACH LUN & DEVICE
	DAC*	(R1)
	LAC	RNA
	DAC*	(R2)
	JMS*	(ALAD)	/(R3, R4, R5, R6, X10, X11, XR, & AC ARE ALTERED)
			/WAS LUN ATTACHED?
	JMP	FINIS	/NO -- SET REQUESTOR'S EVENT VARIABLE TO -24
	JMP	SET1	/YES -- SET REQUESTOR'S EVENT VARIABLE TO +1
/
/ DETACH FROM A TASK
/
DETACH	LAC	PDVNA	/DETACH LUN & DEVICE
	DAC*	(R1)
	LAC	RNA
	DAC*	(R2)
	JMS*	(DLAD)	/(R3, R4, R5, R6, X10, X11, XR, & AC ARE ALTERED)
			/WAS LUN DETACHED?
	JMP	FINIS	/NO -- SET REQUESTOR'S EVENT VARIABLE TO -24
	JMP	SET1	/YES -- SET REQUESTOR'S EVENT VARIABLE TO +1
/
	.EJECT
/
/AF15 ABORT REQ. PROCESSING.  REM. PENDING REQS. FROM QUEUE OF
/TASK TO BE ABORTED.
/
AFABRT	LAC	5,X	/ABORT REQ. NODE LUN=0?
	AND	(777000)
	SZA
	JMP	ERR6	/NO.  ERROR.  SET EV TO -6
	LAC	PDVNA	/YES.  PDVL NODE ADDRESS.
	DAC*	(R1)
	LAC	RNA
	DAC*	(R2)	/REQ. NODE ADDRESS.
	JMS*	(DMTQ)	/CLEAN UP QUEUE.
			/R1,R2,R3,R5,R6,X10,X11,X12,XR,AC ALTERED.
/
	.EJECT
/
/ RETURN HANDLER INFORMATION IN EVENT VARIABLE
/
HINF	LAC	(200016)
	JMP	FINIS
/
/ GET -- READ SEQUENTIAL ANALOG CHANNELS
/
/	SETUP FOR READ LOOP
/
GET	LAC	RNA	/ADJUST CONTROL TABLE ADDRESS TO 17-BITS AND CHECK
	DAC*	(R2)	/FOR TABLE OUT-OF-PARTITION (NORMAL MODE)
	LAC	7,X
	DAC*	(R3)
	LAC	(4)
	DAC*	(R4)
	JMS*	(VAJX)	/(R3, R5, XR, & AC ARE ALTERED)
			/RANGE OKAY?
	JMP	ERR30	/NO -- SET EVENT VARIABLE TO -30
	LAW	-1	/YES -- SETUP X11 TO ACCESS CONTROL TABLE
	TAD*	(R3)
	DAC*	(X11)
/
	LAC*	X11	/FETCH 'CHNL' & 'LCHN' AND SET R4 TO NUMBER
	SPA		/OF CHANNELS.  SET EVENT VARIABLE TO -70
	JMP	ERR70	/IF EITHER VALUE IS <0, OR IF FCH>LCH, OR
	DAC	CHNL	/LCH DOESN'T EXITS.
	TCA
	DAC*	(R4)
	LAC*	X11
	SPA
	JMP	ERR70
	DAC	LCHN
	TAD*	(R4)
	SPA
	JMP	ERR70
	IAC
	DAC*	(R4)
	TAD	(-NCHN-1)
	SMA
	JMP	ERR70
/
	LAC*	X11	/ADJUST GAIN TABLE ADDRESS TO 17-BITS AND CHECK
	DAC*	(R3)	/FOR TABLE OUT-OF-PARTITION (NORMAL MODE)
			/(R2 & R4 ARE SETUP FOR VAJX)
	JMS*	(VAJX)	/(R3, R5, XR, & AC ARE ALTERED)
	JMP	ERR30	/NO -- SET EVENT VARIABLE TO -30
	LAC*	(R3)	/YES -- SAVE 17-BIT GAIN-FACTOR-TABLE ADDRESS
	DAC	GFTA
/
	LAC*	X11	/ADJUST DIGITAL VALUE TABLE ADDRESS TO 17-BITS AND CHECK
	DAC*	(R3)	/FOR TABLE OUT-OF-PARTITION (NORMAL MODE)
			/R2 & R4 ARE SETUP FOR VAJX)
	JMS*	(VAJX)	/(R3, R5, XR, & AC ARE ALTERED)
			/RANGE OKAY?
	JMP	ERR30	/NO -- SET EVENT VARIABLE TO -30
	LAC*	(R3)	/YES -- SAVE 17-BIT DECIMAL-VALUE-TABLE ADDRESS
	DAC	DVTA
/
	DZM	INDX	/CLEAR BUFFER'S INDEX
/
	LAC	CHNL	/IS A DELAY NECESSARY?
	TCA		/(NO IF CHNL>PCHN)
	TAD	PCHN
	SPA
	JMP	READ	/NO -- READ REQUESTED SEQUENCE
	AAC	-12	/MAYBE -- (NO IF CHNL+10<PCHN)
	SMA
	JMP	READ	/NO -- READ REQUESTED SEQUENCE
	LAC	LCHN	/MAYBE -- (NO IF LCHN<PCHN)
	TCA
	TAD	PCHN
	SMA!SZA
	JMP	READ	/NO -- READ REQUESTED SEQUENCE
	LAC	(SKP)	/YES -- MAKE A 50 MS. CONVERSION, AND
	DAC	DLYSW	/READ REQUESTED SEQUENCE.
	DZM	AFCEV
	LAC	(777602)
	FCMOD		/*/
	FCLAG		/*/
	FCEI		/*/
	CAL	WFAFC
	LAC	(NOP)
	DAC	DLYSW
/
/ 	READ LOOP
/
READ	LAC	GFTA	/SETUP XR TO ACCESS GAIN TABLE ENTRY FOR CHANNEL
	PAX
	LAC	(GCT-1)	/CONVERT GAIN FACTOR PER 'GCT'
	DAC*	(X10)
GC1	LAC*	X10
	SADIX	INDX
	JMP	GC2
	LAC*	X10
	SZA
	JMP	GC1
	SKP
GC2	LAC*	X10
/
	CLQ		/FORM GAIN & ADDRESS WORD
	LRS	3
	LAC	CHNL
	LLS	7
	TAD	(FMAD)
/
	DZM	AFCEV	/CLEAR EVENT VARIABLE
	FCMOD		/*/SELECT AFC MODE
	FCLAG		/*/LOAD ADDRESS & GAIN REGISTER
	FCEI		/*/ENABLE AFC INTERRUPT
/
	CAL	WFAFC	/WAIT FOR AFC INTERRUPT
/
	LAC	CHNL	/LAST CHANNEL READ?
	SAD	LCHN
	JMP	RPVC	/YES -- RECORD 'PCHN'
	ISZ	CHNL	/NO -- READ NEXT CHANNEL
	ISZ	INDX
	JMP	READ
/
ERR30	LAW	-30	/SET EVENT VARIABLE TO -30
	JMP	FINIS
/
ERR70	LAW	-70	/SET EVENT VARIABLE TO -70
	JMP	FINIS
/
RPVC	DAC	PCHN	/RECORD PREVIOUS CHANNEL FOR NEXT REQUEST,
			/AND SET EVENT VARIABLE TO ONE ('SET1' MUST
			/FOLLOW).
/
/ SET1 -- SET EVENT VARIABLE TO ONE (+1) AND FINISH REQUEST
/
SET1	LAC	(+1)	/SET EVENT VARIABLE TO +1 ('FINIS' MUST FOLLOW)
/
/ FINIS -- FINISH REQUEST BY SETTING THE EVENT VARIABLE (IF SPECIFIED) TO
/ THE CONTENTS OF AC, DECLARING A SIGNIFICANT EVENT, RETURNING
/ THE REQUEST NODE TO THE POOL, AND DECLARING 'I/O COMPLETED'.
/
FINIS	PAL		/SET EVENT VARIABLE (IF SPCECIFIED) TO
	LAC	EVA	/CONTENTS OF AC
	TAD	XADJ
	PAX
	PLA
	DAC	0,X
/
	LAC	(401000)/DECLARE A SIGNIFICANT EVENT
	ISA
/
	LAC	RNA	/DECLARE REQUEST COMPLETED (DECREMENT
	DAC*	(R2)	/TRANSFERS PENDING COUNT FOR NORMAL
	JMS*	(IOCD)	/(R5, XR, & AC ARE ALTERED)
/
	LAC	(POOL)	/RETURN REQUEST NODE TO POOL
	DAC*	(R1)	/R2 IS ALREADY SETUP
	JMS*	(NADD)
/
	JMP	PQ	/PICK NEXT REQUEST (IF ANY)
/
/ DAEX -- DISCONNECT & EXIT
/
DAEX	LAC	(POOL)	/RETURN REQUEST NODE TO POOL
	DAC*	(R1)
	LAC	RNA
	DAC*	(R2)
	JMS*	(NADD)
/
	CAL	DCPB	/DISCONNECT INTERRUPT LINE
/
	ISZ	PDVTA	/CLEAR ASSIGN INHIBIT FLAG & EXIT
	.INH		///
	DZM*	PDVTA	///
	.ENB		///
	CAL	(10)	///
/
XADJ	0	/XR ADJUST FOR CURRENT PAGE
PDVNA	0	/PHYSICAL DEVICE LIST NODE ADDRESS
PDVTA	0	/ADR OF TRIGGER EVENT VARIABLE ADR IN PDVL NODE
RNA	0	/REQUEST NODE ADDRESS
EVA	0	/EVENT VARIABLE ADDRESS
/
CHNL	0	/ANALOG CHANNEL NUMBER
LCHN	0	/LAST CHANNEL OF CURRENT REQUEST
PCHN	3777	/LAST CHANNEL OF PREVIOUS REQUEST
INDX	0	/BUFFERS INDEX (CURRENT CHANNEL MINUS FIRST CHANNEL)
GFTA	0	/GAIN FACTOR TABLE ADDRESS
DVTA	0	/DIGITAL VALUE TABLE ADDRESS
/
	.DEC		/GAIN CONVERSION TABLE
GCT	1000;	7
	200;	6
	100;	5
	50;	4
	20;	2	/(YES, 4-2-3-1 IS THE CORRECT SEQUENCE)
	10;	3
	2;	1
	1;	0
	.OCT
/
CCPB	11	/CONNECT CPB
	TG
	32
	AFCINT
/
DCPB	12	/DISCONNECT CPB
	0
	32
	AFCINT
/
WFTCPB	20	/WAIT FOR TRIGGER CPB
	TG
/
TG	0	/TRIGGER EVENT VARIABLE
/
WFAFC	20	/WAIT FOR AFC INTERRUPT CPB
	AFCEV
/
AFCEV	0	/AFC INTERRUPT EVENT VARIABLE
/
/ AFC INTERRUPT SERVICE ROUTINE
/
AFCINT	0		/AFC INTERRUPT SERVICE ROUTINE
	DBA		/ENTER INDEX MODE
	DAC	ACBUF	/SAVE CONTENTS OF AC & XR
	PXA
	DAC	XRBUF
/
	LAC	DVTA	/SETUP XR TO ACCESS DECIMAL VALUE TABLE
	PAX
/
	FCMOD		/*/SELECT AFC MODE, READ A/D BUFFER, AND
	FCRB		/*/STORE DIGITIZED VALUE IN DIGITAL VALUE
	XCT	DLYSW	/TABLE ENTRY FOR CHANNEL, UNLESS DUMMY
	DACIX	INDX	/CONVERSION FOR DELAY.
/
	ISZ	AFCEV	/SET EVENT VARIABLE AND
	LAC	(401000)/DECLARE A SIGNIFICANT EVENT
	ISA
/
	LAC	XRBUF	/RESTORE CONTENTS OF XR & AC, AND RETURN TO
	PAX		/INTERRUPTED PROGRAM
	LAC	ACBUF
	DBR
	JMP*	AFCINT
/
ACBUF	0	/AC BUFFER
XRBUF	0	/XR BUFFER
DLYSW	NOP	/DELAY SWITCH  (SKP:SET::NOP:RESET)
/
	.END
