/OS8 BASIC USER FUNCTIONS, V5
/
/
/
/
/
/
/
/
/
/COPYRIGHT  (C)  1974 BY DIGITAL EQUIPMENT CORPORATION
/
/
/
/
/
/
/
/
/
/
/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 RESPONSIBILITY
/FOR ANY ERRORS THAT MAY APPEAR IN THIS MANUAL.
/
/THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FURNISHED 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 PROVIDED IN WRITING BY DIGITAL.
/
/DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY FOR THE USE
/OR RELIABILITY OF ITS SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY
/DIGITAL.
/
/
/
/
/
/
/
/
/
/
/JR	6-JUN-77	MODIFIED FOR V5

	VERSON=	5	/VERSION OF BRTS
	SUBVUF=	01	/SUBVERSION OF BASIC.UF
			/FIRST WORD OF THIS OVERLAY CONTAINS
			/BRTS VERSION IN LEFT HALF AND SUBVERSION IN RIGHT HALF

	FPP=	4000
	FADD=	FPP+2000
	FSUB=	FPP+2117
	FMPY=	FPP+1600
	FDIV=	FPP+1722
	FFNEG=	FPP+2135
	FFPUT=	FPP+2256
	FFGET=	FPP+2241
	FFNOR=	FPP+2215
	FACCLR=	0323
	UNSFIX=	1615
	PSWAP=	1262
	ARGPRE=	311

	/VC8E POINT PLOTTING DISPLAY CONTROL IOT'S

	DISD=	6052	/SKIP ON DONE FLAG
	DILX=	6053	/LOAD AC2-11 INTO X-REGISTER (DOESN'T CLEAR AC)
	DILY=	6054	/LOAD AC2-11 INTO Y-REGISTER (DOESN'T CLEAR AC)
	DIXY=	6055	/INTENSIFY

	/DK8EP PROGRAMMABLE REAL TIME CLOCK IOT'S

	CLZE=	6130	/CLEAR CLOCK ENABLE BITS PER AC
	CLSK=	6131	/SKIP ON CLOCK FLAG
	CLOE=	6132	/SET CLOCK ENABLE BITS PER AC
	CLAB=	6133	/AC TO CLOCK BUFFER
	CLSA=	6135	/READ CLOCK STATUS TO AC
			/BIT 0 SET ON OVERFLOW
			/BITS 9-11 SET ON RESPECTIVE SCHMITT TRIGGER FIRING

	/CLOCK ENABLE REGISTER BITS
	/BIT	FUNCTION
	/0	INTERRUPT ENABLE BIT
	/1-2	MODE BITS:
	/	00	RUN COUNTER, INTERRUPTING EACH 4096 TICKS
	/	01	RUN COUNTER AND RESET WITH CLOCK BUFFER ON OVERFLOW
	/	10	RUN COUNTER AND READ COUNTER WHEN EVENT OCCURS
	/	11	RUN COUNTER AND READ AND CLEAR IT ON EVENT
	/3-5	RATE SELECTION:
	/	000	STOPPED
	/	001	EXTERNAL TIME BASE
	/	010	100 HZ
	/	011	1 KHZ
	/	100	10 KHZ
	/	101	100 KHZ
	/	110	1 MHZ
	/	111	STOPPED
	/6	OVERFLOW STARTS A-D
	/7	SET TO INHIBIT CLOCK
	/8	EVENT ON CHAN 1, 2, OR 3 CAUSE INTERRUPT AND OVERFLOW
	/9-11	ENABLE EVENTS 1 THRU 3

	/AD8EA A-D CONVERTER IOT'S

	ADCL=	6530	/CLEAR A-D
	ADLM=	6531	/LOAD MULTIPLEXOR FROM AC8-11 AND CLEAR AC
	ADST=	6532	/START A-D CONVERTER
	ADRB=	6533	/READ A-D BUFFER INTO AC0-11 AND CLEAR FLAG
	ADSK=	6534	/SKIP ON A-D DONE FLAG (DOESN'T CLEAR FLAG)
	ADLE=	6536	/SKIP ON TIMING ERROR
	ADRS=	6537	/READ STATUS REGISTER

	/STATUS REGISTER FORMAT:
	/0	A-D DONE FLAG
	/1	TIMING ERROR FLAG
	/2	ENABLE INTERRUPT ON DONE FLAG
	/3	ENABLE INTERRUPT ON TIMING ERROR
	/4	ENABLE EXTERNAL START (EG CLOCK)
	/5	AUTO INCREMENT MODE
	/6-7	UNUSED
	/8-11	4 BIT CHANNEL NUMBER

	/DR8E-A DIGITAL BUFFERED I/O BASE IOT'S
	/DEVICE CODE CHANGED TO 52 TO AAVOID CONFLICT
	/WITH LQP-80 WHICH IS DEVICE CODE 50

	DBDI=	6520	/DISABLE INTERRUPTS
	DBEI=	6521	/ENABLE INTERRUPTS
	DBSK=	6522	/SKIP IF THE IN FLAG IS SET
	DBCI=	6523	/SET SELECTED BITS IN INPUT REGISTER
	DBRI=	6524	/READ INPUT REGISTER TO AC
	DBCO=	6525	/CLEAR SELECTED BITS IN OUTPUT REGISTER
	DBSO=	6526	/SET SELECTED BITS IN OUTPUT REGISTER
	DBRO=	6527	/READ OUTPUT REGISTER TO AC

	ACX=	44
	ACH=	45
	ACL=	46

	MAXPTS=	XR0
	REFRFL=	XR1
	BUFXR=	XR2
	DX=	XR3		/XR3,XR4,XR5=	TEMP FL PT LOC

	SPF=	6040	/SET TTY PRINTER FLAG
	CAF=	6007	/RESET PROCESSOR

	IA=	1465	/ENTRY POINT FOR USER FUNCTION ERROR MESSAGE
	NOPUNCH		/DUMMY SECTION FOR MISC PAGE 0 REFERENCES

	*1		/JPG 13-DEC-77 DUMMY PAGE 0 CHANGED SO THAT POINTERS
			/AND ADDRESSES MATCH UP WITH CURRENT VERSION
	JMP I	.+1
	SERVC
	*6
USECON,	0	/ENTRY #OF USER BUF IN DIM TBL
	*10
XR0,	0
XR1,	0
XR2,	0
XR3,	0
XR4,	0
XR5,	0
	*20
CDFIO,	CDF 10	/FLD OF PSEUDO DIM TBL
	0
ARSTRT,	0	/ADR-1 OF PSEUDO DIM TBL
	*56
INSAV,	0
	*124
FNORL,	FFNOR
	*126
FPUTL,	FFPUT
	*156
FIXP,	UNSFIX
FGETL,	FFGET
	*161
FCLR,	FACCLR
	*171
K0017,	17
K0200,	200
P1SWAP,	PSWAP
	*177
K0010,	10

	ENPUNCH
	*3400

/INI(N)-INITIALIZE ROUTN;CALLED BY USER BEFORE 'PLY
/	OR ADC';INITIALIZE CTRS,FLGS,ETC
/	N IS A DUMMY ARG
/
INI,	VERSON^100+SUBVUF /VERSION NUMBER OF USER FUNCTIONS
	JMS	BUFCDF
	TAD	BUFBAK	/PICK UP ADDR OF DISPLAY BUFFER
	DCA	BUFXR	/STORE IN BUFFER XR FOR PUTBUF ROUTINE
	DCA	TOTPTS	/BUF IS NOW EMPTY
	IAC
	DCA I	(STPT	/ACCES BUF AT 1ST PT
	IAC
	DCA I	(NTHY	/ACCES EVERY PT
	IAC
	DCA I	(XFLG	/BUF MAYBE DISPLAYED
	JMP I 	INI

	/ROUTINE TO GET FIELD AND ADDRESS OF USER BUFFER
	/FROM 'USECON' LOCATION

BUFCDF,	0
	TAD	USECON	/ENTRY PT OF BUF IN DIM TBL
	CLL RTL		/MULT BY 4
	TAD	ARSTRT	/ADR-1 OF STRT F DIM TBL
	DCA	XR5	/ADR-1 OF ENTRY IN DIM TBL
	TAD	CDFIO	/COPY CDF TO BRTS TABLES INLINE
	DCA	.+1
	0
	CMA
	TAD I	XR5	/ADR-1 OF BUF
	DCA	BUFBAK	/NEED FOR DISPLY ROUTN
	TAD I	XR5	/GET CDF OF BUF
	DCA	PUTCDF
	TAD	PUTCDF
	DCA	CDFBAK	/NEED FOR DISPLY ROUTN
	CDF		/RESTORE DF
	JMP I	BUFCDF
CDFBAK,	0
BUFBAK,	0
TOTPTS,	0

/PUTBUF-ENTER WITH A 12BIT VALUE IN AC;PUT VAL IN
/	USER BUFFER;CHK TO SEE IF NXT VAL WILL CROSS FLDS
/
PUTBUF,	0
PUTCDF,	0
	DCA I	BUFXR
	IAC
	TAD	BUFXR
	SZA CLA		/ABOUT TO CROSS FLDS?
	JMP	.+4	/NO
	TAD	K0010	/YES
	TAD	PUTCDF
	DCA	PUTCDF	/DF=DF+1
	CDF		/RESTORE DF
	JMP I	PUTBUF

/PLY(Y)-ENTER WITH YVAL IN FAC;CHK 0<=VAL<1.;
/	PUT LEGIT VAL IN USER BUF
/
PLY,	0
	TAD	ACH
	SPA CLA		/YVAL>=0?
	JMP I	(IA	/NO,ERR
	TAD	ACX
	SMA SZA CLA	/YVAL<1?
	JMP I	(IA	/NO, ERR
/CONV # IN FAC TO A 10BIT DISPLAYABLE VAL
/	FAC=FAC*1776+1001
/
	JMS  I	(FMPY	/YES
	FL1022		/1776(8)
	JMS  I	(FADD
	FL513		/1001(8)
	JMS I 	FIXP
	JMS	PUTBUF
	ISZ	TOTPTS	/KEEP CNT OF PTS IN BUF
	JMP I	PLY
/DLY(N)-N IS MAX # OF PTS TO BE EVENTUALLY DISPLAYED
/	CHK IF 1<=N<=1024; SET 'REFRFL' =0 FOR
/	A ONE SHOT DISPLAY.
/
DLY,	0
	JMS I 	FIXP
	SPA SNA		/1<=N?
	JMP I	(IA	/NO,ERR
/CHK IF N IS SAME AS LAST TIME &
/IF SO, NO NEED TO GO THE "SETDX" ROUT
	DCA	INI	/YES,TEMPORARY SAVE
	DCA	XR1
	TAD	INI
	CIA
	TAD	MAXPTS
	SZA CLA		/N IS STILL THE SAME?
	JMP	.+3	/NO
	JMS I	(DISPLY	/YES, DISPLY ONCE &
	JMP I	DLY	/RETURN
	TAD	INI	/GET N BACK
	DCA	MAXPTS	/ASSUME N IS VALID FOR MOMENT
	TAD	MAXPTS
	CIA
	TAD	(2000
	SPA CLA		/N<=1024?
	JMP I	(IA	/NO
	DCA	REFRFL	/ONE SHOT DISPLY
	JMS I	(SETDX	/SET DX FOR DISPLY
	JMP I	DLY
/ADC(N)-SAMPLE ADC NTH CHANNEL; RETN FL PT VAL IN FAC
/

ADC,	0
	JMS I	FIXP	/GET ARG N
	CIA
	TAD	K0017
	SPA		/N<=17(8)?
	JMP I	(IA	/NO,ERR
	CIA		/YES
	TAD	K0017
	ADLM		/LOAD MUX
	ADST		/START CONV
	ADSK
	JMP	.-1
	ADRB		/GET VAL
	DCA	ACH
	JMS I	(FFLOT
	JMP I	ADC
/CLW(N)-N IS A DUMMY ARG; WAIT UNTIL CLOCK O.F. OR
/	UNTIL A SCHMITT TRIG FIRES(DEPENDING WHICH WAS
/	SPECIFIED IN 'CLK') BEFORE RETURNING TO BASIC
/
CLW,	0
	CLSK		/STATUS REG IS ALREADY SET?
	SKP		/NO
	JMP	EARLY	/YES
	CLSK
	JMP	.-1
	CLSA		/READ STATUS
CLW1,	CLL RAL		/CHK ON O.F.
	SZL		/O.F. BIT SET IN SATUS WD?
	CIA		/YES,NEG REST OF STATUS REG
/RTN 0 IF O.F. ONLY; 1,2,...,7 IF SCHMITT ONLY;
/-1,-2,...,-7 IF BOTH
	RAR		/NO
	DCA	ACH
	JMS I	(FFLOT
	JMP I	CLW
/IF CLOCK INTERRUPTED TOO SOON TELL USER;
/-8 IF O.F. ONLY; 9 THRU 15 IF SCHMITT ONLY;
/-9 THRU -15 IF BOTH
EARLY,	CLSA
	TAD	K0010
	JMP	CLW1

	PAGE
/DIS(S,E,N,X)-DISPLY EVERY NTH PT BEGIN WITH S
/	& NOT EXCEEDING N; X=1 DISPLY NOW,
/	X=0 SETUP TO DISPLY FOR A SAM
/
DIS,	0
	JMS I	(BUFCDF	/SETUP CDF & USER BUF
	JMS I	(ARG123
	STPT-1
/FLOAT N
	TAD	NTHY
	DCA	ACH
	JMS I	(FFLOT
	JMS I	FPUTL	/IT BETTER NOT =0
	DX		/HOLD TEMPORARY
/CHK 1<=S,0<=E-S
	TAD	STPT
	SPA SNA
	JMP I	(IA	/ERROR
	CIA
	TAD	ENDPT
	SPA
	JMP I	(IA	/ERROR
/FLOAT (E-S) & GET (E-S)/N
	DCA	ACH
	JMS I	(FFLOT
	JMS I	(FDIV
	DX
/CHK (E-S)/N+1<=1024; MAXPTS=(E-S)/N+1
	JMS I 	FIXP
	IAC
	DCA	MAXPTS	/ASSUME OK FOR NOW
	TAD	MAXPTS
	CIA
	TAD	(2000	/1024(10)
	SPA CLA
	JMP I	(IA	/ERROR
/GET X ARG; DISPLY BUF(X=1); ONLY A SETUP FOR SAM (X=0)
	CLL IAC RAL	/4TH ARG DESIGNATED BY AC=2
	JMS I	(GETARG
	JMS I 	FIXP
	DCA	XFLG
	TAD	XFLG
	SZA CLA		/USER WANTS TO DISPLY?
	TAD	MAXPTS	/YES,TOTPTS=MAXPTS
DPY1,	DCA I	(TOTPTS	/NO,JUST SET UP,TOTPTS=0
	IAC		/REFRESH TILL ^N(NON INTERRUPT)
	DCA	REFRFL	/OR TILL CLK INTERRPT(INT MODE)
	JMS I	(SETDX
	JMP I	DIS
STPT,	0		/THESE 3 LOCATIONS
ENDPT,	0		/GO TOGETHER & MUST
NTHY,	0		/BE IN THIS ORDER
XFLG,	0
/DISPLY-SETUP CDF & PTR TO STARTING PT OF USER BUF;
/	SETUP 'DISCTR' FOR # OF PTS TO DISPLY THIS TIME;
/	INITIALIZE FL PT 'DXSUM'=-'DX'
/
DISPLY,0
/IF TOTPTS<=MAXPTS,DISPLY TOTPTS;OTHERWSE MAXPTS
D4,	TAD I	(TOTPTS
	SNA		/SIMPLE WAIT LOOP FOR THAT'1ST'
	JMP	.-1	/ADC TO BE SAMPLED
	CIA
	DCA	DISCTR
	TAD	DISCTR
	TAD	MAXPTS
	SMA CLA		/TOTPTS<=MAXPTS?
	JMP	.+4	/YES
	TAD	MAXPTS	/NO
	CIA
	DCA	DISCTR
/SETUP CDF & PTR TO START PT OF USER BUFFER
	TAD I	(CDFBAK	/RE-INIT CDF FOR LAST TIME YOU DISPLY
	DCA	DISCDF	/YOU MAY HAVE CROSSED FLDS
	TAD I	(BUFBAK	/ADR-1 OF BUF
	TAD	STPT
	DCA	BUFPTR
	TAD	XCRD	/INITIALIZE XCOORD
	DCA	XCOORD
D3,	TAD	XCOORD
	DILX
	TAD	DELTAX
	DCA	XCOORD	/UPDATE XCOORD BY DELTAX
DISCDF,	0
	TAD I	BUFPTR
	CDF
	DILY
	CLA CLL
	TAD	NTHY	/MOVE PTR TO NXT LOC TO BE
	TAD	BUFPTR	/ACCESSED IN BUF
	DCA	BUFPTR
	SNL		/JUST CROSSED FLDS?
	JMP	.+4	/NO
	TAD	K0010	/YES
	TAD	DISCDF
	DCA	DISCDF
	DISD
	JMP	.-1
	DIXY	/INTENSIFY
/DISPLYED ALL PTS YET?
	ISZ	DISCTR
	JMP	D3	/NO
	TAD	REFRFL	/YES,KEEP REFRESHING?
	SNA CLA
	JMP I	DISPLY	/NO
/KEYBOARD IS CHK HERE FOR ^N WHEN DSPL & NOT SAMPLING
/KEYBOARD INTERRUPTS TO THE INT ROUTN
/
	KSF		/YES
	JMP	D4
	KRB
	TLS
	TAD	(-216
	SNA CLA		/USER HIT ^N?
	JMP I	DISPLY	/YES
	JMP	D4	/NO, KEEP REFRESHING
DISCTR,	0
BUFPTR,	0
XCRD,	0
XCOORD,	0
DELTAX,	0
/FFLOT-FLOAT ANY INTEGER IN ACH(LOC 45) INTO FAC

FFLOT,	0
	DCA	ACL	/CLEAR LOW MANTISSA
	TAD	(13	/11(10) INTO EXPONENT
	DCA	ACX
	JMS I	FNORL	/NORMALIZE
	JMP I	FFLOT	/RETURN
FL513,	12;2002;0
FL1022,	12;3774;0

	PAGE
/SAM(C,N,P,T)-SETUP PARAMETERS FOR SUBSEQUENT SAMPLING
/	OF ADC'S OR OR DOING DIGITAL IO
/
	CONST=CLK
	TSAM=NCTR
SAM,	0
	JMS I	(ARG123
	CSAM-1
	TAD	PSAM
	SPA SNA		/P=0?
	JMP I	(IA	/YES,ERR
	CIA		/NO
	DCA	PCTR	/PCTR=-P(DONE CTR)
	CLL IAC RAL	/4TH ARG IS DESIGN BY AC=2
	JMS	GETARG	/GET T
	JMS I	FIXP
	DCA	TSAM
	TAD	TSAM
	SZA CLA		/SET UP TO SAMPLE ADC'S?
	JMP	DIG	/NO, DO DIGAL IO
	IAC		/YES
	DCA	SAMFLG	/SET FLG=1 FOR 'CLK'
	TAD	K0017	/15(10)
	JMP	SAM1
DIG,	CMA
	DCA	SAMFLG	/SET FLG=-1 FOR 'CLK'
	CLA CLL IAC RAL	/2
SAM1,	DCA	CONST
/CHK IF 0<=C, 1<=N, N+C-1<=2(DIG IO)OR <=17(8)(ADC'S)
/
	CMA
	TAD	NSAM
	SPA		/1<=N?
	JMP I	(IA	/NO,ERR
	TAD	CSAM
	CIA
	TAD	CONST
	SPA CLA		/N+C-1<=2 OR 17?
	JMP I	(IA	/NO,ERR
	TAD	TSAM
	SNA CLA
	JMP	SAM3
/CLEAR ALL DIGIAL INPT REGS
	JMS I	(BUFCDF	/SET UP USER BUF
	TAD	NSAM
	CIA
	DCA	NCTR	/-#OF BOARDS TO CLAR
	TAD	CSAM	/START BOARD#(0,1,2)
	CLL RTL
	RAL		/START BOARD# * 10(8)
	TAD	(DBCI
A1,	DCA	.+2
	CLA CMA
	0		/DBCI IS ISSUED
	CLA
	TAD	.-2
	TAD	K0010
	ISZ	NCTR	/MORE BOARDS TO CLEAR?
	JMP	A1	/YES
	CLA
	JMP I	SAM
/DO A CLEAR ALL; AD DONE FLG, ERR FLG, CLR MUX & EN REG.
/SET NON-AUTO INCR MODE
/
SAM3,	CAF		/CL ALL FLGS-I MAY USE ION'S
	ADCL
	TAD	K0200
	ADLE		/ENABLE EXT START OF ADC'S
	JMP I	SAM
CSAM,	0		/THESE 3 LOCATIONS MUST
NSAM,	0		/BE TOGETHER & IN THIS
PSAM,	0		/ORDER
PCTR,	0
NCTR,	0
/CLK(R,O,S)-A COMPLEX CLK ROUTN WHICH SETS UP CLOCK
/	FOR ADC SAMPLING; DIGIAL IO SMPLING;
/	& SETS UP A SIMPLE CLOCK-WAIT ROUTN
/
CLK,	0
	JMS I	(ARG123
	R-1
	CLSA		/CLEAR CLK STATUS REG 
	CLA
	TAD	R
	SPA SNA		/R>0?
	JMP	IAA	/NO,ERR
	TAD	(-6	/YES
	SMA SZA CLA	/R<=6?
	JMP	IAA	/NO
	TAD	R	/R GIVES CORRECT VAL FOR
	CLL RTL		/EXT START, .1,1,10,100,1000 KHZ RATE
	RTL
	RTL		/RATE GOES INTO BITS 3-5 OF EN REG
	TAD	(5050	/BITS 0,2,6,8 OF EN REG ALWAYS SET
	DCA	SAM	/SAVE TEMP
	TAD	O	/OVERFLOW CNT
	CIA
	CLAB		/SET BUF PRESET REG
	CLA
	TAD	S
	SZA CLA		/ANY SCHMITT TRIGS ASKED FOR?
	TAD	(27	/YES,SET BITS 7,9-11 OF EN REG
	TAD	SAM	/FINAL ENABLE VAL
	CMA
	CLZE		/CLEAR BAD BITS FROM EN REG
	CMA		/ENABLE VAL IS BACK AGAIN
	CLOE		/START CLOCK
	CLA
	TAD	SAMFLG
	SNA		/JUST SETTING UP FOR A SIMPLE TIMING DEV?
	JMP	DONE	/YES,RTN TO BASIC
	SPA CLA		/SAMPLE ADC'S?
	JMP I	(DRESET	/NO,DO DIGITAL IO
	JMP I	(SRESET	/YES
DONE,	DCA	SAMFLG	/CLR FLG
	SPF		/RESET TTY FLG FOR BASIC
	JMP I	CLK	/RTN TO BASIC
IAA,	SPF
	JMP I	(IA
R,	0		/THESE 3 LOCATIONS
O,	0		/MUST BE TOGETHER IN
S,	0		/THIS ORDER
SAMFLG,	0
FL4096,	15;2000;0
/GETARG-ENTER WITH SCALER(0=ARG2,1=ARG3,2=ARG4) IN AC;
/	CALL 'ARGPRE' & ON RTN THE D.F. OF ARG IS SET
/	& ADR OF ARG IS IN FAC
/	PUT FL PT ARG IN FAC( 44-46)

GETARG,	0
	DCA	INSAV	/ARGPRE USES THIS SCALER LOC 64
	JMS I	KARG	/GET ADR OF ARG
	JMS I	FGETL	/PUT ARG IN FAC
KARG,	ARGPRE		/USED TO ADVANTAGE
	CDF		/RESET D.F.
	JMP I	GETARG

	PAGE
/SETDX-SETUP DELTAX; CHK IF DISPL IS TO BE
/	ACTIVATED; DX IS A FL PT NO
/	SETUP DELTAX SUCH THAT IT =1,2,3,...,1023;
/	& XCOORD SO THAT DISPLY IS CENTERED
/
SETDX,	0
	CMA
	TAD	MAXPTS	/MAXPTS-1
	SNA		/IF # OF MAXPTS=1 THEN DISPLY
	IAC		/IS POSITIONED AT X=0 COORD
	DCA	ACH
	JMS  I	(FFLOT
	JMS I	FPUTL
	DX		/SAVE FL PT(MAXPTS-1) TEMP
	TAD	(1777	/1023
	DCA	ACH
	JMS I	(FFLOT
	JMS I	(FDIV
	DX		/FL PT (1023/MAXPTS-1) =DX
	JMS I	FIXP	/FIXED 'DX'
	DCA I	(DELTAX
	TAD I	(DELTAX
	DCA	ACH
	JMS I	(FFLOT
	JMS I	(FMPY
	DX		/(MAXPTS-1)*(FIX'DX')=FLOT PROD
	JMS I	FIXP	/FIX 'PROD'
	CIA
	TAD	(1777
	CLL RAR		/(1023-FIX'PROD')/2
	TAD	(1001
	DCA I	(XCRD	/XCOORD=[1001+(1023-FIX'DX')/2]
/CHK  SHOULD DISPLY NOW(XFLG=1)
/OR RTN TO BASIC DUE TO SAM SETUP(XFLG=0

	TAD I	(XFLG
	SZA CLA
	JMS I	(DISPLY
	JMP I	SETDX
/ADSAM-A CLOCK INTERRUPT FOR SAMPLING ADC'S COMES HERE
/
ADSAM1,	ADRS		/RD STATUS(GET MUX)
	IAC
	ADLM		/BMP MUX BY 1
	JMP	CLUGE
ADSAM,	CLSA		/READ STATUS REG & CLEAR IT
	SMA CLA		/CLK O.F.?
	JMP 	TION	/NO, SCHMITT TRIG SYNC
	ADSK		/CONV IS DONE?
	JMP	.-1	/NO
	ADRB		/GET VAL FR CONV BUF
	JMS I	(PUTBUF	/YES
	ISZ I	(NCTR	/SAMPLED ALL CHANS FOR THIS INTERRUPT?
	JMP	ADSAM1	/NO
	ISZ I	(PCTR	/YES,JOB IS ALL DONE?
	JMP	SRESET-1	/NO
	JMP I	(DONE	/YES,'DONE' IS IN 'CLK' ROUTN

/SRESET-USED TO RESET STCHAN & CTR FR ADC SAMPLING
/	ROUTN SETS MUX TO SAMPLE 1ST OF A SERIES OF CHANS.
/	A CTR IS SET TO -# OF CONSEC CHANS TO SAMPLE
/

	ISZ I	(TOTPTS	/#PTS /CHANNEL
SRESET,	TAD I	(NSAM
	CIA
	DCA I	(NCTR
	TAD I	(CSAM
	ADLM		/LOAD MUX WITH 1ST CHAN
TION,	ION
	JMS I	(DISPLY	/DISPLY UNTIL CLK INTERRUPT
/DRI(N) -SAMPLE DIGITAL IO BOARD N; & RTN RESULT
/	AS FL PT IN FAC

DRI,	0
	JMS	ARGN
	JMS I	(DIGIO	/GET DIGITAL VAL
	JMS	NEGCHK
	JMP I	DRI

/ARGN - GET N AND MAKE A 'DBSK' INSTRUCTION

ARGN,	0
	JMS I	FIXP	/BOARD #
/CHK 0<=N<=2
	DCA	SETDX	/SAV N TEMP
	TAD	SETDX
	CIA
	TAD	(2
	SPA CLA
	JMP I	(IA	/ERR
	TAD	SETDX	/GET N BAK
	CLL RTL
	RAL		/BOARD # = BITS 6-8
	TAD	(DBCI
	JMP I	ARGN

/DRO(M,N)- M=FL PT VAL TO OUTPUT, N=BOARD #
/	IF M=0 CLR OUTPUT REG; OTHERWISE LEAVE
/	THE BITS OF DBSO SET

	MASK=DIGIO
DRO,	0
	JMS I	FIXP
	DCA I	(MASK	/DIGITAL OUTPUT VAL
	JMS I	(GETARG
	JMS	ARGN
	TAD	(2	/65N5='DBCI+2'
	DCA	KDBCO
	IAC
	TAD	KDBCO
	DCA	KDBSO
	TAD I	(MASK	/GET FL PT VAL
	SZA		/CLR OUTPUT REG/
	JMP	KDBSO	/NO
	CMA		/YES,SET ALL BITS OF AC
KDBCO,	0	/CLR OUTPUT REG
	SKP
KDBSO,	0		/OUTPUT DIG VAL
	CLA
	JMP I	DRO
	FLGNEG=DRO
/NEGCHK- THIS ROUTINE CHKS TO SEE IF A VALUE FROM
/	'DRI' OR 'GET' IS NEGATIVE.  IF IT IS
/	THE VALUE IS CHANGED TO 4096+NEG VAL.

NEGCHK,	0
	DCA	FLGNEG	/VAL IS EITHER + R -
	TAD	FLGNEG
	DCA	ACH
	JMS I	(FFLOT
	TAD	FLGNEG
	SMA CLA		/VAL WAS NEG?
	JMP I	NEGCHK	/NO
	JMS I	(FADD	/YES
	FL4096
	JMP I	NEGCHK
CLUGE,	ADST		/START CONV
	JMP	ADSAM+3

	PAGE
/GET(M,L)- M=0, GET VAL FROM USER BUF & NO MASKING
/	M>0, GET VAL FROM USER BUF & MASK WHERE
/	M IS THE MASKING VALUE.
/	L IS THE LOCATION OF USER BUF TO ACCESS

	LHOLD=ARG123
GET,	0
	IAC
	DCA	MSKCTR
	JMS I	FIXP	/GET M
	SNA		/M=0
	CMA		/YES,SET M=7777
	CLL RAR
	SZL
	JMP	.+3
	ISZ	MSKCTR
	JMP	.-4
	RAL
	JMS COMMON	/SAME CODE FOR 'GET' & 'PUT'
	TAD	MSKCTR
	CIA
	DCA	MSKCTR
	TAD I	LHOLD
	CDF		/RESET D.F.
	CLL RAR
	ISZ	MSKCTR
	JMP	.-2
	RAL
	AND	MASK
	JMS I	(NEGCHK
	JMP I	GET
MSKCTR,	0

/PUT(M,L)- M IS THE FL PT VALU TO BE FIXED & PUT
/	IN THE USER BUF;  L IS THE LOC OF THE USER
/	BUF WHERE TO STORE THE FIXED NUMBER.

PUT,	0
	JMS I	FIXP	/GET & FIX THE FL PT VAL
	JMS COMMON
	TAD	MASK
	DCA I	LHOLD
	CDF
	JMP I	PUT

/COMMON- THIS ROUTINE IS USED BY BOTH 'GET' & 'PUT'

COMMON,	0
	DCA	MASK	/SAVE M TEMPORARILY
	JMS I	(GETARG
	JMS I	FIXP	/GET L
	CLL
	TAD I	(BUFBAK
	DCA	LHOLD
	SZL		/CROSSED FIELDS?
	TAD	K0010	/YES
	TAD I	(CDFBAK	/NO
	DCA	.+1
	0
	JMP I	COMMON
/WHEN INTERRUPT OCCURS COME HERE
/

SERVC,	CLA
	CLSK		/CLOCK INTERRUPT?
	SKP		/NO
	JMP I	(ADSAM	/YES
	KSF		/TTY INTERRUPT?
	SKP		/NO
	JMP	KKBRD	/YES
	TSF		/DUE TO LAST ECHO?
	HLT		/SPURIOUS INTERRUPT
	TCF		/YES
	JMP I	(TION
KKBRD,	KRB
	TLS		/ECHO CHAR
	TAD	(-203
	SZA CLA		/^C TYPED?
	JMP I	(TION	/NO,IGNORE CHAR
	JMS I	P1SWAP	/YES
	JMP I	(7605	/RTN TO MONITOR
/ARG123-THIS ROUTINE GETS 3 ARGUMENTS OF A FUNCTION
/	AND STORES THEIR FL PT VALUES IN
/	'ARG1,ARG2,ARG3' & STORES THEIR FIXED VALUES
/	AT 'ADR,ADR+1,ADR+2'
/		CALL: JMS ARG123
/		      ADR-1

ARG123,	0
	TAD I	ARG123	/GET(ADR-1)FOR THE THREE
	DCA	XR1	/1WD ARGS
	ISZ	ARG123
	JMS I	FIXP
	DCA I	XR1	/SINGLE PREC ARG1
	JMS I	(GETARG	/ARG2 DESIGN BY AC=0
	JMS I	FIXP
	DCA I	XR1	/SINGLE PREC ARG2
	IAC
	JMS I	(GETARG	/ARG3 DESIGN BY AC-3
	JMS I	FIXP
	DCA I	XR1	/SINGLE PREC ARG3
	JMP I	ARG123
/DRESET-USED TO RESET STARTING DIGITAL IO BOARD & CTR;
/	WAIT FOR CLK TO O.F.; SAMPLE EACH BOARD ASKED FOR.
/

DRESET,	TAD I	(NSAM
	CIA
	DCA I	(NCTR
	TAD I	(CSAM	/STARTING BOARD #
	CLL RTL
	RAL		/ST BOARD #*10(8)
	TAD	(DBCI-10
	DCA	KDBCI	/[DBCI-10(8)] FOR 1ST BOARD
/WAIT LOOP
	CLSK
	JMP	.-1
	CLSA		/READ STATUS & CLR
	CLA
/SAMPLE ALL BOARDS ASKED FOR

DIGSAM,	TAD	K0010
	TAD	KDBCI
	JMS	DIGIO	/SAMPLE BOARD
	JMS I	(PUTBUF	/PUT DIG VAL IN BUF
	ISZ I	(NCTR	/MORE BOARDS?
	JMP	DIGSAM	/YES
	ISZ I	(PCTR	/NO, JOB IS ALL DONE?
	JMP	DRESET	/NO
	JMP I	(DONE	/YES,'DONE' IS IN 'CLK' ROUTN
/DIGIO-ENTER WITH 'DBCI' SETUP FOR CORRECT BOARD; THIS RTN
/	SETS UP THE 'DBRI & DBCI' AND SAMPLES CORRECT BOARD;
/	EXIT WITH DIGITAL VAL IN AC
/

DIGIO,	0
	DCA	KDBCI
	TAD	KDBCI
	IAC
	DCA	KDBRI
KDBRI,	0
KDBCI,	0
	JMP I	DIGIO
$

