	.TITLE	A2D
/
/  21 JUN 74 (PDH) PROPERLY CORRECT CASE OF +10V, EVEN FOR WATRAN
/  14 DEC 73 (PDH) CORRECT CASE OF +10V (400000)
/  18 JUL 73 - CORRECT FLAG SETTING FOR CRBC, GENERAL WORKING OVER,
/		CONDITIONALIZE FOR WATRAN & DEC FORTRAN
/   5 JUL 73 - FIX UP ARRAY ADDRESS IN 'CRBC'
/   7 MAR 72 - MOD BY P. HENDERSON
/
/	.TITLE	ANALOG TO DIGITAL CONVERSION SUBROUTINE
/
/  R. WORKMAN
/
	.GLOBL	MUXR,CRAC,CRPC,CRBC
/
/ READ MULTIPLEXER ADDRESS
/ CALLING SEQUENCE:  MUXR(DUMMY)
/   DUMMY: ANY DUMMY ARGUMENT (NEVER REFERENCED)
/ EXIT: AC=MULTIPLEXER CHANNEL ADDRESS
/
	INTACC		/DECLARE SOFTWARE INTEGER AC GLOBAL
/
MUXR	XX
	ADRM		/READ MPX ADDRESS
	.IFDEF	WATRAN
	DZM*	MOSTI		/SINGLE INTEGER RESULT ONLY
	DAC*	LEASTI
	DZM*	.MODEA	/INDICATE INTEGER MODE
	.ENDC
	JMP*	MUXR
ADRM=701212
	.EJECT
/
/ CONVERT AND READ A-D CHANNEL
/ CALLING SEQUENCE:  CALL CRAC(CHANEL,VALUE,ERROR)
/	CHANEL :8-63 CHANNEL ADDRESS
/	VALUE  :INTEGER VALUE OF CHANNEL
/	ERROR=0:NO ERROR
/	     =1:ILLEGAL CHANNEL REQUEST-NO CONVERSION
/	     =6:ADC MULTIPLEXER FAILED TO SET DESIRED CHANNEL
/
CRAC	XX
	.ARG	CRAC
	DAC	CHANEL	/CHANNEL LOCATION
	JMS	ADINIT
	.ARG
	DAC	VALUE	/VALUE LOCATION
	.ARG
	DAC	ERROR	/ERROR LOCATION
	DZM*	ERROR		/ASSUME ERROR = 0
	LAC*	CHANEL
	TAD	(-10
	SPA
	JMP	ERR1A	/CHANNEL < 8
	TAD	(-70
	SMA
	JMP	ERR1A	/CHANNEL > 63
	TAD	(100	/LOAD MPX ADDRESS
	DAC	IOUND		/SET I/O UNDERWAY FLAG
	ADSM		/SELECT ADC CHANNEL AND CONVERT
	ADRM		/READ MPX ADDRESS
	SAD*	CHANEL
	JMP	MATCH1		/THEY MATCH
	LAC	(6
	JMP	ERR6A
MATCH1	LAC	IOUND
	SZA
	JMP	MATCH1	/WAIT FOR INTERRUPT
	LAC	STORE
	DAC*	VALUE
	JMP*	CRAC
ERR1A	LAC	(1
ERR6A	DAC*	ERROR
	JMP*	CRAC
ADSM=701103
ADRM=701212
	.EJECT
/
/ CONVERT AND READ PREVIOUS A-D CHANNEL
/ CALLING SEQUENCE:  CALL CRPC(VALUE,ERROR)
/	VALUE  :INTEGER VALUE OF CURRENT ADC MPX CHANNEL
/	ERROR=0:NO ERROR
/
CRPC	XX
	.ARG	CRPC
	DAC	VALUE	/VALUE LOCATION
	JMS	ADINIT
	.ARG
	DAC	ERROR	/ERROR LOCATION
	DZM*	ERROR		/SET ERROR = 0
	DAC	IOUND	/SET I/O UNDERWAY FLAG
	ADSC		/ADC CONVERT
	LAC	IOUND
	SZA
	JMP	.-2	/WAIT FOR INTERRUPT
	LAC	STORE
	DAC*	VALUE
	JMP*	CRPC
ADSC=701304
	.EJECT
/
/ CONVERT AND READ BANK OF A-D CHANNELS
/ CALLING SEQUENCE:  CALL CRBC(FIRST,LAST,VALUES(1),ERROR)
/	FIRST: 8-63 ADDRESS OF FIRST CHANNEL IN BLOCK
/	LAST: 8-63 ADDRESS OF LAST CHANNEL IN BLOCK
/	VALUES: INTEGER ARRAY DIMENSIONED 1-64
/	        VALUES(I)=VALUE OF ADC CHANNEL I-1
/	ERROR=0: NO ERROR
/	     =1: ILLEGAL CHANNEL REQUEST (FIRST OR LAST)
/	     =6: ADC MPX FAILED TO SET CORRECT CHANNEL
/
CRBC	XX
	.ARG	CRBC
	DAC	FIRST	/FIRST LOCATION
	JMS	ADINIT
	.ARG
	DAC	LAST	/LAST LOCATION
	.ARG
	DAC	VALUES	/ARRAY POINTER
	.ARG
	DAC	ERROR	/ERROR LOCATION
	DZM*	ERROR		/SET ERROR = 0
	LAC*	FIRST
	TAD	(-10
	SPA
	JMP	ERR1B	/FIRST < 8
	TAD	(10
	DAC	FIRST	/SAVE FIRST CHANNEL
	TAD	(-100
	SMA
	JMP	ERR1B	/FIRST > 63
	LAC*	LAST
	TAD	(-10
	SPA
	JMP	ERR1B	/LAST < 8
	TAD	(10
	DAC	LAST	/SAVE LAST CHANNEL
	TAD	(-100
	SMA
	JMP	ERR1B	/LAST > 63
	LAC	FIRST	/FIRST CHANNEL
LOOPL	DAC	IOUND		/SET I/O UNDERWAY FLAG
	ADSM		/SELECT ADC CHANNEL AND CONVERT
	TAD	VALUES
	DAC	BANK	/BANK POINTER=VALUES(FIRST+1)
LOOP	ADRM		/READ MPX ADDRESS
	SAD	FIRST
	JMP	MATCH2		/MPX ADDRESS OK
	LAC	(6	/MPX ADDRESS WRONG
	JMP	ERR6B
MATCH2	LAC	IOUND
	SZA
	JMP	MATCH2	/WAIT FOR INTERRUPT
	LAC	STORE	/PLACE STORE
	DAC*	BANK	/IN BANK
	LAC	FIRST
	SAD	LAST	/LAST CHANNEL?
	JMP*	CRBC	/YES
	ISZ	BANK	/NO
	ISZ	FIRST
	LAC	FIRST
	TAD	(-100
	SPA!CLC
	JMP	NOWRAP
	LAC	(10
	DAC	FIRST	/WRAP AROUND
	JMP	LOOPL
NOWRAP	DAC	IOUND		/SET I/O UNDERWAY FLAG
	ADIM		/INCREMENT MPX ADDRESS AND CONVERT
	JMP	LOOP
ERR1B	LAC	(1
ERR6B	DAC*	ERROR
	JMP*	CRBC
ADSM=701103
ADRM=701212
ADIM=701201
	.EJECT
/
/ INTERRUPT ROUTINE
/
A2DINT	XX
	DAC	A2DAC	/SAVE AC
	LAC	IOUND	/I/O UNDERWAY
	DZM	IOUND		/CLEAR I/O UNDERWAY INDICATOR
	SNA!STL
	CLL
	ADRB		/READ
	SNL!CMA
	JMP	NOIO
	SAD	(377777		/+10V?
	SKP			/YES. DO NOT CONVERT TO -0 OR -131072
	TAD	(1
	DAC	STORE
NOIO	LAC	A2DAC	/RESTORE AC
	DBR
	XCT	.+1
	JMP*	A2DINT
ADRB=701312
/
ADINIT	XX
REPLCE	CAL	57
STORE	16
A2DAC	ADSF
BANK	A2DINT
ERROR	DBK
	LAC	.+2
LAST	DAC	REPLCE
VALUES	JMP*	ADINIT
ADSF=701301
/
FIRST;CHANEL;VALUE
IOUND
/
	.END
