Google
 

Trailing-Edge - PDP-10 Archives - AP-4178E-RM - swskit-sources/cdrsrv.mac
There are 49 other files named cdrsrv.mac in the archive. Click here to see a list.
;<MCLEAN>CDRSRV.MAC.26, 17-Apr-78 16:02:39, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.25, 15-Apr-78 16:14:36, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.24, 15-Apr-78 16:08:39, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.23, 13-Apr-78 01:08:42, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.22, 12-Apr-78 19:00:47, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.21, 11-Apr-78 00:40:36, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.20, 10-Apr-78 22:30:47, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.19, 10-Apr-78 22:29:36, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.18, 10-Apr-78 21:53:07, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.17, 10-Apr-78 18:07:25, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.16, 10-Apr-78 14:30:41, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.15,  9-Apr-78 14:07:22, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.14,  9-Apr-78 13:54:23, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.13,  9-Apr-78 13:02:41, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.12, 19-Feb-78 22:16:22, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.11, 11-Feb-78 19:19:05, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.10, 24-Jan-78 14:10:41, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.9, 11-Dec-77 22:57:53, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.8, 11-Dec-77 22:54:03, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.7, 11-Dec-77 22:29:19, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.6, 11-Dec-77 22:25:20, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.5, 11-Dec-77 22:21:35, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.4, 11-Dec-77 22:10:50, Edit by MCLEAN
;<MCLEAN>CDRSRV.MAC.3,  7-Nov-77 00:09:24, Edit by MCLEAN
;<SM10-MONITOR>CDRSRV.MAC.2,  6-Nov-77 23:36:22, Edit by MCLEAN
;BREAK UP FOR DEVICE DEPENDENT/INDEPENDENT
;<3-MONITOR>CDRSRV.MAC.94, 10-Oct-77 10:02:30, EDIT BY KIRSCHEN
;UPDATE COPYRIGHT FOR RELEASE 3
;<3-MONITOR>CDRSRV.MAC.93, 29-Jun-77 08:23:25, EDIT BY MILLER
;DONT'T GIVE ERRORS ON -11 RELOAD UNLESS IT IS THE MASTER
;<3-MONITOR>CDRSRV.MAC.92, 16-Jun-77 18:35:12, EDIT BY HURLEY
;FIX EOF TO BE GIVEN ONLY ONCE WHEN EOF BUTTON IS HIT
;<3-MONITOR>CDRSRV.MAC.91,  6-May-77 11:56:07, EDIT BY HURLEY
;ADD SET INPUT/OUTPUT AND ATTRIBUTE CHECK ENTRIES IN DISPATCH TABLE
;<3-MONITOR>CDRSRV.MAC.90, 13-Apr-77 09:43:22, EDIT BY HURLEY
;<3-MONITOR>CDRSRV.MAC.89, 13-Apr-77 08:50:46, EDIT BY HURLEY
;TCO 1779 - MAKE OFFLINE INTERRUPT COME ONLY AFTER LAST CARD READ BY USER
;<3-MONITOR>CDRSRV.MAC.88,  1-Apr-77 16:39:15, EDIT BY KIRSCHEN
;TCO 1725 - FIX CALLING SEQUENCE TO PSIRQ IN CDRCK
;<3-MONITOR>CDRSRV.MAC.87, 11-Jan-77 16:16:40, Edit by MCLEAN
;<3-MONITOR>CDRSRV.MAC.86, 27-Dec-76 17:30:14, EDIT BY HURLEY
;<2-MONITOR>CDRSRV.MAC.85, 15-Oct-76 13:37:14, EDIT BY MILLER
;TCO 1600. FIX HANDLING IF EIOF BUTTON
;<2-MONITOR>CDRSRV.MAC.84, 15-Oct-76 13:23:30, EDIT BY HURLEY
;<2-MONITOR>CDRSRV.MAC.83, 14-Oct-76 19:24:04, EDIT BY HURLEY
;TCO 1598 - ADD OF%OFL BIT TO OPENF
;<2-MONITOR>CDRSRV.MAC.82, 16-Aug-76 11:46:22, EDIT BY KIRSCHEN
;TCO 1495 - FIX DEFSTR FOR CDSST
;<2-MONITOR>CDRSRV.MAC.81, 16-Aug-76 11:45:38, EDIT BY KIRSCHEN
;TCO 1494 - SET MO%RLD IF FRONT END HAS BEEN RELOADED
;<2-MONITOR>CDRSRV.MAC.80, 28-Jun-76 17:52:24, EDIT BY MILLER
;FILL IN NULLS IN LAST WORD FOR ASCII INPUT
;<2-MONITOR>CDRSRV.MAC.79, 28-Jun-76 09:42:18, EDIT BY MILLER
;FIX COMPUTATION OF # OF BYTES AT SETUP1
;<2-MONITOR>CDRSRV.MAC.78, 27-Jun-76 10:57:07, EDIT BY MILLER
;<2-MONITOR>CDRSRV.MAC.77, 24-Jun-76 19:22:40, EDIT BY MILLER
;MORE BUFFER FIX UPS
;<2-MONITOR>CDRSRV.MAC.76, 24-Jun-76 11:47:36, EDIT BY MILLER
;<2-MONITOR>CDRSRV.MAC.75, 24-Jun-76 11:09:27, EDIT BY MILLER
;MORE BUFFER CONTROL CLEAN UP
;<2-MONITOR>CDRSRV.MAC.74, 24-Jun-76 10:50:18, EDIT BY MILLER
;CLEAN UP COMMENTS
;<2-MONITOR>CDRSRV.MAC.73, 24-Jun-76 10:24:35, EDIT BY MILLER
;REWORK BUFFER LOGIC
;<2-MONITOR>CDRSRV.MAC.2, 23-Jun-76 11:50:18, EDIT BY MILLER
;<2-MONITOR>CDRSRV.MAC.1, 23-Jun-76 11:28:12, EDIT BY MILLER
;TCO 1452. MAKE READER DOUBLE BUFFERED IN IMAGE MODE
;<1MILLER>CDRSRV.MAC.6, 23-Jun-76 11:24:08, EDIT BY MILLER
;<1MILLER>CDRSRV.MAC.5, 22-Jun-76 18:15:55, EDIT BY MILLER
;<1MILLER>CDRSRV.MAC.4, 22-Jun-76 17:48:52, EDIT BY MILLER
;<1MILLER>CDRSRV.MAC.3, 22-Jun-76 15:31:05, EDIT BY MILLER
;<1MILLER>CDRSRV.MAC.2, 22-Jun-76 15:06:10, EDIT BY MILLER
;<1MILLER>CDRSRV.MAC.1, 22-Jun-76 15:00:37, EDIT BY MILLER
;<1B-MONITOR>CDRSRV.MAC.2, 13-APR-76 11:09:33, EDIT BY KIRSCHEN
;TCO 1248 - PREVENT OPENS IF NEVER GOING TO USE PRIMARY PROTOCOL
;<1B-MONITOR>CDRSRV.MAC.1,  6-APR-76 09:21:23, EDIT BY MILLER
;TCO 1171. DELIVER PSI IN SCHEDULER INSTEAD OF AT DTE PI
;1MONITOR>CDRSRV.MAC.69, 23-MAR-76 18:19:10, EDIT BY HURLEY
;<1MONITOR>CDRSRV.MAC.68, 23-MAR-76 17:18:35, EDIT BY HURLEY
;<1MONITOR>CDRSRV.MAC.67, 23-MAR-76 17:08:44, EDIT BY HURLEY
;TCO 1216 - MAKE ALL UNSUPPORTED DISPATCH ENTRIES RETURN AN ERROR CODE
;<1MONITOR>CDRSRV.MAC.66, 19-MAR-76 13:29:43, EDIT BY MILLER
;TCO 1196. FIX GCDRST
;<1MONITOR>CDRSRV.MAC.65, 19-MAR-76 10:07:20, EDIT BY KIRSCHEN
;TCO 1194 - ADD FLAG ON .MOPSI TO SUPPRESS "PROBLEM ON DEVICE" MESSAGES
;<1MONITOR>CDRSRV.MAC.63, 12-MAR-76 12:13:09, EDIT BY KIRSCHEN
;<1MONITOR>CDRSRV.MAC.62, 11-MAR-76 14:56:03, EDIT BY MILLER
;<1MONITOR>CDRSRV.MAC.61, 11-MAR-76 10:29:26, EDIT BY KIRSCHEN
;<1MONITOR>CDRSRV.MAC.60, 11-MAR-76 10:22:35, EDIT BY KIRSCHEN
;<1MONITOR>CDRSRV.MAC.59, 11-MAR-76 08:44:06, EDIT BY KIRSCHEN
;<1MONITOR>CDRSRV.MAC.58, 10-MAR-76 12:50:20, EDIT BY KIRSCHEN
;<1MONITOR>CDRSRV.MAC.57, 10-MAR-76 12:48:33, EDIT BY KIRSCHEN
;<1MONITOR>CDRSRV.MAC.56, 10-MAR-76 12:47:34, EDIT BY KIRSCHEN
;<1MONITOR>CDRSRV.MAC.55, 10-MAR-76 12:13:42, EDIT BY KIRSCHEN
;<1MONITOR>CDRSRV.MAC.54, 10-MAR-76 11:26:18, EDIT BY KIRSCHEN
;TCO 1171 - ADD MTOPR TO ENABLE PSI CHANNEL FOR OFF-LINE TRANSITION
;<2MONITOR>CDRSRV.MAC.53, 15-FEB-76 12:00:41, EDIT BY MILLER
;TCO 1093. ADD RELOAD ENTRY TO DTE VECTOR
;<2MONITOR>CDRSRV.MAC.52, 16-JAN-76 17:40:54, EDIT BY MURPHY
;<2MONITOR>CDRSRV.MAC.51, 23-DEC-75 16:23:54, EDIT BY HURLEY

	SEARCH PROLOG

	DEFINE FNCALL (A,B),<
	LOAD A,CDRTYP
	MOVE A,CDRDVT(A)
	CALL @B(A)>

   IFE SMFLG,<

	TTITLE CDRSRV
   >
   IFN SMFLG,<
	TTITLE CDRSRV,CDRSM
   >

;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1977 BY DIGITAL EQUIPMENT CORPORATION

;SPECIAL REGISTERS USED HEREIN. SEE GTJFN AND FILE SYSTEM CODE
;FOR SPECIFICS ON THE USAGE OF THESE REGISTERS

DEFAC (U,Q1)
DEFAC (STS,P1)
DEFAC (JFN,P2)
DEFAC (DEV,P4)

; DEVICE DEPENDENT OFFSETS

RDCD=0		;READ CARD
CDCLZ=1		;CLOSE
CDRST=2		;RESTART
CDINI=3		;INIT
GCDRST=4	;GET STATUS
BUFSWP=5	;SWAP BUFFER TO CORRECT FORMAT


;DATA DEFINTIONS FOR THE CDR

DEFSTR (CDERR,CDRSTS,35,16)	;LAST ERROR CONDITION
DEFSTR (CDFRK,CDRSTS,17,18)	;OWNING FORK
DEFSTR (CDBLK,CDRSTS,18,1)	;WAITING FOR A CARD
DEFSTR (CDOL,CDRSTS,19,1)	;IF ONE, CARDS IN THE READER

;OTHER STATUS WORD

DEFSTR (CDAII,CDRST1,0,1)	;READER IS OPENED IN ASCII
DEFSTR (CDATN,CDRST1,1,1)	;CDR NEEDS ATTENTION
DEFSTR (CDMSG,CDRST1,2,1)	;SUPPRESS SYSTEM MESSAGES
DEFSTR (CDOPN,CDRST1,3,1)	;CDR IS OPENED
DEFSTR (CDER,CDRST1,4,1)	;ERROR IN THIS CDR
DEFSTR (CDCNT,CDRST1,12,8)	;COUNT OF BYTES NOW IN BUFFER
DEFSTR (CDEOF,CDRST1,13,1)	;EOF BUTTON WAS PUSHED
DEFSTR (CDBUF,CDRST1,14,1)	;BUFFER FOR PROCESS LEVEL
DEFSTR (CDPIR,CDRST1,15,1)	;PROCESS NEEDS INTERRUPT
DEFSTR (CDBFI,CDRST1,16,1)	;BUFFER FOR PI LEVEL
DEFSTR (CDDON,CDRST1,17,1)	;BIT TO SAY DOING A BUFFER BY PROCESS
DEFSTR (CDWRD,CDRST1,35,18)	;CURRENT WORD FOR INT STORAGE

; THIRD STATUS WORD

CD%SHA==1B0			;STATUS HAS ARRIVED FLAG
CD%RLD==1B2			;FRONT END WAS RELOADED

DEFSTR (CDPSI,CDRST2,17,6)	;PSI CHANNEL NUMBER FOR ON-LINE TRANSITIONS
DEFSTR (CDSST,CDRST2,35,16)	;SOFTWARE STATUS WORD STORED HERE
DEFSTR (CDSHA,CDRST2,0,1)	;STATUS HAS ARRIVED FLAG
DEFSTR (CDMWS,CDRST2,1,1)	;MTOPR IS WAITING FOR STATUS TO ARRIVE
MSKSTR (CDRLD,CDRST2,CD%RLD)	;FRONT END WAS RELOADED
DEFSTR (CDOFI,CDRST2,3,1)	;OFF-LINE INTERRUPT IS PENDING
DEFSTR (CDEFI,CDRST2,4,1)	;END OF FILE INTERRUPT WAS ALREADY GIVEN
DEFSTR (CDRTYP,CDRST2,6,2)	;TYPE OF CARD READER
DEFSTR (CDEXST,CDRST2,7,1)	;EXISTANCE OF READER 

INIPSI==77			;INITIAL PSI CHANNEL VALUE, MEANS NOT ENABLED
;CDR DTB

;PROTOCOL VECTOR

	RESCD
CDRDVT::CDVTFE			;FRONT-END
   FETYP=0			;TYPE FOR FE
	CDVTKS			;KS10
   KSTYP=1			;KS10 TYPE

	SWAPCD			;SWAPPABLE

CDRDTB::DTBBAD (GJFX32)		;Set directory
	DTBBAD (DESX9)		;NAME LOOKUP
	DTBBAD (DESX9)		;EXTENSION
	DTBBAD (DESX9)		;VERSION
	DTBBAD (DESX9)		;INSERT PROTECTION
	DTBBAD (DESX9)		;INSERT ACCOUNT
	DTBBAD (DESX9)
	IFIW!CDROPN
	IFIW!CDRSQI		;SEQUENTIAL INPUT
	DTBBAD (DESX9)		;OUTPUT
	IFIW!CDRCLZ		;CLOSE
	DTBBAD (DESX9)		;RENAME
	DTBBAD (DESX9)		;DELETE
	DTBBAD (DUMPX6)
	DTBBAD (DUMPX6)
	DTBBAD (DESX9)		;MOUNT
	DTBBAD (DESX9)		;DISMOUNT
	DTBBAD (DESX9)		;INIT DIRECTORY
	IFIW!CDRMTO		;MTOPR
	IFIW!CDRDST		;DEVICE STATUS
	DTBBAD (DESX9)		;SET STATUS
	DTBSKP			;RECORD OUT
	IFIW!RFTADN		;READ TAD
	IFIW!SFTADN		;SET TAD
	DTBDSP (BIOINP)		;SET JFN FOR INPUT
	DTBDSP (BIOOUT)		;SET JFN FOR OUTPUT
	DTBBAD (GJFX49)		;CHECK ATTRIBUTE

	DTBLEN==:.-CDRDTB	;GLOBAL LENGTH OF DISPATCH TABLE
;INITIALIZATION CODE CALLED FROM PROTOCOL HANDLER

CDRINI::MOVSI U,-CDRN		;NUMBER OF CDR'S
	SETOM CDRCNT		;COUNT OF CDR'S NOW OPENED
	SETOM CDRLCK		;INITILIZE LOCK
CDRLP1:	SETZM CDRSTS(U)		;CLEAR STATUS WORD
	SETZM CDRST1(U)
	SETZM CDRST2(U)		;THIRD STATUS WORD
	AOBJN  U,CDRLP1
	SKIPN PROFLG		;IF PROFLG NOT SET FORGET IT
	RET
	MOVEI Q2,0		;UNIT NUMBER
	MOVE A,CDRDVT		;INITALIZE CARD READERS
	CALL @CDINI(A)
	MOVE A,CDRDVT+1
	CALL @CDINI(A)
	MOVSI U,-CDRN		;NUMBER OF CDR'S
CDRLOP:	JE CDEXST,(U),CDRLP2 ;FORGET IT IF NO CDR
	HRRZ T4,Q2		;SET UNIT NUMBER
	FNCALL A,GCDRST		;GET STATUS
	MOVEI A,^D60000		;MUST LOOK AT EACH ONE ONCE A MINUTE
	ADD A,TODCLK		;FROM NOW
	MOVEM A,CDRCKT(U)	;STORE IT
CDRLP2:	AOBJN U,CDRLOP		;DO ALL OF THEM
	RET			;AND DONE

;RESTART ROUTINE

CDRRST::MOVSI U,-CDRN		;DO ALL CARD READERS
CDRRLP:	FNCALL A,CDRST		;DO DEVICE RESTART
	
	AOBJN U,CDRRLP		;DO ALL
	RET
;ROUTINE TO OPEN A CDR

CDROPN:	SKIPN PROFLG		;EVER GOING TO USE PRIMARY PROTOCOL ?
	RETBAD (OPNX18)		;NO, PREVENT OPENS SINCE LOCK NOT INITIALIZED
	HLRZ U,DEV		;GET UNIT
	LOCK CDRLCK,<CALL LCKTST> ;LOCK UP THE CDR LOCK
	JN CDOPN,(U),[	UNLOCK CDRLCK
		MOVEI A,OPNX9	;ALREADY OPENED
		RET]		;GIVE ERROR
	JE CDOL,(U),[CALL CHKOFL ;SEE IF OPENS ARE ALLOWED IF OFFLINE
		 SKIPA		;NO
		JRST .+1	;YES
		UNLOCK CDRLCK
		MOVEI A,OPNX8	;ERROR CODE
		RET]
	TQNE <READF>		;WANT READ?
	TQNE <WRTF>		;YES. AND NOT WRITE?
	JRST [	UNLOCK CDRLCK	;CAN'T OPEN IT THAT WAY
		RETBAD (OPNX13)] ;BOMB IT
	SETONE CDOPN,(U)	;SAY IS NOW OPENED
	MOVE A,FORKX		;GET FORK ID OF OPENER
	STOR A,CDFRK,(U)	;REMEMBER FOR SYSERR
	MOVX A,INIPSI		;GET INITIAL PSI CHANNEL VALUE (NOT ENABLED)
	STOR A,CDPSI,(U)	;SAVE FLAG THAT NO PSI IS ENABLED
	SETZRO CDPIR,(U)	;CLEAR INTERRUPT FLAG
	SETZRO CDOFI,(U)	;FOR BOTH ONLINE AND OFFLINE INTERRUPTS
	AOSE CDRCNT		;FIRST OPENING?
	JRST CDRSET		;NO. PAGE IS ALREADY LOCKED
	MOVEI A,CDRBUF		;GET THE ADDDRESS
	MOVES (A)		;CREATE THE PAGE
	CALL FPTA		;GET PTN.PN
	CALL MLKPG		;AND LOCK IT DOWN
CDRSET:	SETZM FILCNT(JFN)	;NO COUNT
	SETZRO <CDBUF,CDBFI>,(U) ;CLEAR BUFFER POINTERS
	SETZRO <CDDON,CDER>,(U)	;CLEAR PI ACTIVE AND ERROR
	SETOM CDRCT1(U)		;NO BUFFERS AVAILABLE YET
	SETZM FILBYT(JFN)	;AND NO BUFFER POINTER
	SETZM FILBYN(JFN)	;NO BYTE NUMBER
	SETZM FILLEN(JFN)	;NO BYTES YET
	UNLOCK CDRLCK		;CLEAR LOCK
	LDB A,[POINT 6,P5,5]	;GET OPEN SIZE
	DPB A,PBYTSZ		;SAVE IT
	SETZRO CDAII,(U)	;ASSUME NOT ASCII
	TRNE STS,17		;IS IT ASCII?
	RETSKP			;NO. RETURN NOW
	SETONE CDAII,(U)	;YES. REMEMBER THIS
	RETSKP			;AND RETURN
;CLOSE A CDR

CDRCLZ:	HLRZ U,DEV		;GET UNIT
	FNCALL A,CDCLZ
	JFCL
	LOCK CDRLCK,<CALL LCKTST> ;GO GET THE LOCK
	SETZRO CDOPN,(U)	;NOT OPENED
	SETZRO CDEOF,(U)	;CLEAR EOF ALLOWING STATUS
	SETZRO CDFRK,(U)	;NO OWNER
	SETZRO CDBLK,(U)	;NOT BLOCKED
	SETZRO CDMSG,(U)	;NO SUPPRESS MESSAGES
	SOSL CDRCNT		;LAST CLOSE?
	JRST CDRCL1		;NO. ALL DONE
	MOVEI A,CDRBUF		;YES. UNLOCK THE PAGE
	CALL FPTA		;GET PTN.PN
	CALL MULKPG		;UNLOCK IT
CDRCL1:	UNLOCK CDRLCK		;FREE THE LOCK
	RETSKP

;ROUTINE TO ARRANGE A BLOCK FOR CARD ARRIVED

WAIT:	JE CDOFI,(U),WAIT1	;SEE IF INTERRUPT NEEDED
	SETZRO CDOFI,(U)	;YES, ONLY DO IT ONCE
	MOVE B,U		;GET UNIT NUMBER
	CALL REQPSI		;AND REQUEST THE INTERRUPT
WAIT1:	TQO <BLKF>		;REQUEST THE BLOCK
	MOVEI A,0(U)		;UNIT TO LH
	HRRI A,CDRBLK		;WAIT FOR THE CARD TO ARRIVE
	RET			;AND RETURN

;ROUTINE TO CALCULATE THE STRING DATA BUFFER ADDRESS

SETBUF:	LOAD C,CDBUF,(U)	;GET BUFFER CONTROL BIT
	JRST SETBF2		;GO TO RESIDENT ROUTINE FOR COMPUTATION

	RESCD

SETBF1:	LOAD C,CDBFI,(U)	;GET INTERRUPT BUFFER CONTROL
SETBF2:	MOVEI B,0(U)		;UNIT
	IMULI B,CDRLEN		;*LENGTH OF A BUFFER
	MOVEI A,CDRBUF		;START OF ALL BUFFERS
	ADDI A,0(B)		;THE ADDRESS
	IMULI C,CDRSIZ		;SIZE OF ONE BUFFER LOAD
	ADDI A,0(C)		;THIS BUFFER
	RET
	SWAPCD
;CDR SEQUENTIAL INPUT

CDRSQI:	HLRZ U,DEV		;GET UNIT
	SETZRO CDRLD,(U)	;FORGET THAT FRONT END WAS RELOADED
CDRSQ2:	SOSL FILCNT(JFN)	;HAVE ANY BYTES?
	JRST CDRSQ1		;YES. GO GET THEM
	OPSTR <SKIPE>,CDDON,(U)	;WERE WE DOING A BUFFER?
	SOS CDRCT1(U)		;YES. WE JUST FINISHED ONE THEN
	SETZRO CDDON,(U)	;NOT DOING A BUFFER NOW
	SKIPL CDRCT1(U)		;HAVE A CARD READY TO GO?
	JRST SETUP		;YES. GO DO IT
	JN CDEOF,(U),[		;HAVE EOF AT END OF THIS CARD?
		SETZRO CDEOF,(U) ;EOF NOW CLEARED
		JN CDEFI,(U),.+1 ;IF ALREADY GIVEN INTERRUPT, DONT AGAIN
		SETONE CDEFI,(U) ;MARK THAT AN EOF WAS GIVEN
		TQO <EOFF>	;YES. RETURN THIS STATUS
		RET]		;AND DONE
	JN CDER,(U),[		;ERROR?
		TQO <ERRF>	;YES. SAY SO
		SETZRO CDER,(U)	;NO ERROR FOR THE NEXT TIME
		RET]		;AND RETURN
	JN CDBLK,(U),WAIT	;HAVE A REQUEST OUTSTANDING?
	SKIPL CDRCT1(U)		;NO. CHECK THIS AGAIN FOR THE RACE
	JRST SETUP		;HAVE A CARD AFTER ALL.
	CALL RDCARD		;NOTHING ACTIVE. GO GET A CARD
	JRST WAIT		;AND GO WAIT

;ROUTINE TO INITIALIZE THE POINTERS FOR A BUFFER

SETUP:	SETONE CDDON,(U)	;NOW WORKING ON A BUFFER
	MOVEI A,^D80		;ONE CARD OF BYTES
	MOVEM A,FILCNT(JFN)	;TO THE COUNT WORD
	CALL SETBUF		;GO FIND START OF THIS BUFFER
	HRRM A,FILBYT(JFN)	;SAVE BASE ADDRESS
	LOAD B,CDBUF,(U)	;GET BUFFER BIT
	XORI B,1		;COMPLEMENT IT
	STOR B,CDBUF,(U)	;MAKE NEXT BUFFER USED NEXT TIME
	MOVEI A,^D16		;ASSUME WE HAVE 16 BIT BYTES
	TRNE STS,17		;ASCII MODE?
	JRST [	FNCALL T2,BUFSWP	;MAKE CORRECT FORMAT BUFFER
		JRST SETUPA]
	CALL CDRAII		;YES. GO CONVERT TO ASCII
SETUPA:	JN CDEOF,(U),CDRSQ2	;IF EOF, GO DO IT NOW
	OPSTR <SKIPN>,CDBLK,(U)	;IS PI ROUTINE ACTIVE
	SKIPLE CDRCT1(U)	;NO. HAVE A PI BUFFER?
	SKIPA			;CAN'T DO READ AHEAD
	CALL RDCA