	.TITLE DRC.
/	9-20-68
/COPYRIGHT 1970, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/DRUM ADAPTATION 6-25-68
/M. SIFNAS   10-21-67 (.WAITR 3-25-68) (IOPS 23 5-8-68)
/(56 FILES 5-15-68)
/DRC.=IOPS DRUM/DECTAPE HANDLER - READ ONLY, IOPS MODES
/1-256 WD. BUF.
/1 FILE ACTIVE AT ANY GIVEN TIME
/LIMITED FUNCTIONS
/CALLING SEQUENCE
/CAL+.DAT SLOT (9-17)+I(8)/.INIT
/UNIT (0-2)+1
/RESTART ADDRESS (ONLY MEANINGFUL FOR TTY HANDLER)
/BUF SIZE (255)
/CAL+.DAT SLOT (9-17)   /.OPER (ILL. FILE COMMAND)
/UNIT (0-2)+2
/DIR. TYPE (0-2)+CORE ADDR. (3-17)
/CAL+.DAT SLOT (9-17)  /.SEEK
/UNIT (0-2)+3
/USER DIRECTORY ENTRY POINTER
/SAME AS .SEEK (FUNCTION=4) /.ENTER (ILL. FILE COMMAND)
/CAL+.DAT SLOT (9-17)  /.CLEAR (ILL. FILE COMMAND)
/UNIT(0-2)+5
/CAL+.DAT SLOT(9-17)  /.CLOSE
/UNIT(0-2)+6
/CAL+SUBFUNCTION(5-8)+.DAT SLOT /.MTAPE (0=REWIND) (ILL. FILE COMMAND)
/UNIT(0-2)+7			(2=BACKSPACE RECORD)
/CAL+D.M.(6-8)+.DATSLOT(9-17)  /.READ
/UNIT (0-2)+10
/LINE BUF ADDR
/-WC OF L.B. (2'S COMP)
/SAME AS .READ (FUNCTION=11) /.WRITE (ILL. FILE COMMAND)
/CAL+.DAT SLOT(9-17)	/.WAIT,.WAITR
/UNIT(0-2)+12
/CAL+1000+.DAT SLOT(9-17)		/.WAITR
/UNIT(0-2)+12
/15 BIT BUSY ADDR
/CAL+X(8)+.DAT SLOT (9-17)  /.TRAN (X=0=READ) (ILL. FILE COMMAND)
/UNIT (0-2)+13		(X=1=WRITE)
/BLOCK#
/CORE ADDRESS
/-WC
/
	.EJECT
	.GLOBL	DRC.
.SCOM=100
.MED=3
/IOT ASSIGNMENTS
DRSF=706101	/SKIP ON DONE FLAG
DRNEF=706201	/SKIP ON NOT ERROR
DRCE=706202	/CLEAR DATA ERROR
DRCF=706102	/CLEAR DONE AND ERROR FLAGS
DRLD=706106	/CLEAR FLAGS, LOAD DRUM ADDR. ,
		/BEGIN TRANSFER
DRRD=706006	/LOAD CORE ADDR. AND SET TO READ
DRWR=706046	/LOAD CORE ADDR. AND SET TO WRITE
DTBUF=DTDIR
DRC.	DAC	DTCALP		/CAL POINTER
	DAC	DTARGP		/ARG. POINTER
	ISZ	DTARGP		/INDEX TO FUNCTION (AND UNIT#)
	LAC*	DTARGP
	AND	DTUMSK		/MASK OFF UNIT CODE.
	DAC	DTUNIT		/SAVE UNIT#
	LAC*	DTARGP		/FUNCTION (3-17)=1-13
	ISZ	DTARGP		/INDEX TO ARG.3
	AND	L377		/MASK OFF FUNCTION CODE.
	TAD	(JMP DTTABL
	DAC	DTTABL
LITCLA	CLA
DTTABL	XX
	JMP	DTIN		/1=.INIT
	JMP	DTER6		/2=.OPER (ILL.)
	JMP	DTSEEK		/3=.SEEK
	JMP	DTER6		/4=ENTER (ILL.)
	JMP	DTER6		/5=.CLEAR (ILL.)
DJSTOP	JMP	DTSTOP		/6=.CLOSE
	JMP	DTER6		/7=.MTAPE (ILL.)
	JMP	DTREAD		/10=.READ
	JMP	DTER6		/11=.WRITE (ILL.)
	JMP	DTWAIT		/12=.WAIT
	JMP	DTER6		/13=.TRAN (ILL.)
/
/I/O UNDERWAY CHECK SUBR.
DTIOU	0
	LAC	DTUND		/I/O UNDERWAY
LITSNA	SNA			/YES
	JMP*	DTIOU		/OK-EXIT
DTBUSY	LAC	DTCALP		/BUSY-DTA I/O GOING ON
	DAC	DTARGP		/RETURN TO USER CAL
	JMP	DTDBK
/
	.EJECT
/DTA-DISK-INTERRUPT SERVICE
DTPIC	DAC	DTAC		/SAVE AC
	LAC*	(0
	DAC	DOUT		/SAVE PC, LINK, EXT. MODE, MEM. PTCT.
	LAC	(ION
	JMP	DTSTON
DTINT	JMP	DTPIC		/PIC ENTRY
	DAC	DTAC		/API ENTRY, SAVE AC
	LAC	DTINT		/SAVE PC, ETC.
	DAC	DOUT
	IORS			/CHECK PIC STATUS
	SMA!CLA			/FOR RESTORATION AT DISMISSAL
	LAW 17740		/PIC OFF, BUILD IOF
	TAD	(ION		/PIC ON, BUILD ION
DTSTON	DAC	DTDVSW
	DRNEF		/SKIP ON NOT ERROR
	JMP DRER
/DONE FLAG MUST HAVE COME UP
	LAC DRDWAT	/DONE FLAG WAIT CONDITION?
	SZA		/NO, TRANSFER DONE OK
	JMP DRPREV	/CHECK ON EARLER ERROR CONDITION
	DRCF		/CLEAR DONE AND ERROR FLAGS
	DZM DTUND	/CLEAR I/O UNDERWAY
	JMP DTDISM
/ERROR FLAG ROUTINE
DRER	DRCE		/CLEAR DATA ERROR
			/CLEARS ONLY IF TIMING ERRROR
	LAC LITSNA	/CONTINUE TRYING IF TIMING ERROR
	DRNEF
	LAC LITCLA	/PARITY: TRY N (DTERCT) TIMES ONLY
	DAC DRDWAT	/SET DONE FLAG WAIT COND.
/COME HERE ON DONE FLAG TO CHECK FOR EARLIER ERROR STATE
DRPREV	DAC DRXCT	/DRDWAT IN AC
	DRSF		/SKIP ON DONE
	JMP DTDISM
	DRCF		/CLEAR DONE AND ERROR ONLY ON DONE SKIP
	DZM DRDWAT	/CLEAR DONE FLAG WAIT COND.
DRXCT	XX		/CLA IF PARITY;SNA (TO SKIP NEXT CELL) IF TIMING
DPARIT	ISZ DTERCT	/INDEX RETRY COUNT
	SKP		/RETRY
	JMP DTDISM-2
DRETRY	LAC DTCCA	/CORE ADDR
	DRRD		/LOAD AND SET TO READ AGAIN
	LAC DTSAFE	/DRUM ADDR
	DRLD		/CLEAR FLAGS,LOAD DRUM ADDR AND TRANSFER
DNRET	LAC DTERCT	/0 IF TRY COUNT OVERFLOWS
	DAC DTUND	/I/O UNDERWAY SW/
DTDISM	LAC	(JMP DTPIC	/RESTORE PIC INTERR. ENTRY
	DAC	DTINT
	LAC	DTAC
DTDVSW	XX		/ION IF PIC, LAC DTAC IF API
	DBR
	XCT .+1
	JMP*	DOUT		/INTERR. EXIT
	.EJECT
/INIT DTA ROUTINE - MAINSTREAM
DTIN	ISZ	DTARGP		/INDEX TO BUF. SIZE ARG.
	LAC	L377		/RETURN 255 AS BUF. SIZE
	DAC*	DTARGP
	ISZ	DTARGP		/INDEX TO NORM. EXIT
DTONCE	CAL	46		/API CORE ADDR.-MODIFIED OR JMP DTSTOP
DTAC	16			/.SETUP
DOUT	DRSF			/DONE DONE AND ERROR FLAG
	DTINT			/DRUM INT. SERV. ADDR.
	CAL 46
/DTONCE+1 UP TO DTSTOP USED FOR TEMP. STOR. AFTER 1ST INIT
DTERCT	16
DTSAFE	DRNEF		/SKIP ON NOT ERROR
DTCCA	DTINT
DRDWAT	LAC* (.SCOM+4	/15-17= DRUM SIZE
DTEOF	AND (7
DTCLSS	SNA
DTBFCT	JMP DTER35	/IOPS 35: DRUM SIZE NOT IN .SCOM+4
DTHPT	TAD DRLIM	/LAC DRSTAB 1SR TIME THRU
DTWC	DAC DRLIM
DRLIM	LAC DRSTAB	/LAC DRSTAB,LACDRSTAB+5, OR -(DRUM SIZE)
DTCKSM	CMA
	DAC DRLIM
DTNXBK	LAC DJSTOP	/SKIP ONCE ONLY CODE HEREAFTER
DTUND	DAC	DTONCE
DRSTAB=.
	JMP DTSTOP
	177		/32K=1/4 DECTAPE=128 BLKS (.SCOM+4,15-17=1)
L377	377		/65K 1/2         256                     2
L777	777		/131K 1          512                        3
	1777		/262K 2           1024                   4
	3777		/524K 4           2048                   5
DTER35	LAW 35		/IOPS 35: DRUM SIZE NOT SET IN .SCOM+4
	JMP* (.MED+1
/STOP DTA ROUTINE
DTSTOP	DZM	DTUND		/CLEAR I/O UNDERWAY
	DZM DRDWAT	/CLEAR DONE WAIT FLAG
	DZM	DTEOF		/CLEAR EOF SWITCH
	DZM	DTCLSS		/SET .CLOSE SWITCH
	JMP DTDBK-1
/WAIT DTA ROUTINE
DTWAIT	LAW 7000
	AND* DTCALP	/BIT 8=0 IF .WAIT
	SNA		/BIT 8=1 IF .WAITR
	JMP DTDBK-1
	LAC (700000	/GET LINK, ETC
	AND DTCALP
	DAC DTCALP
	LAC* DTARGP	/15 BIT BUSY ADDR
	AND (77777
	XOR DTCALP
	ISZ DTARGP
	DAC DTCALP
	JMS	DTIOU		/CHECK I/O UNDERWAY
	.EJECT
DTDBK	DBR
	XCT .+1
	JMP*	DTARGP		/NORM. EXIT
/SET UP CA,WC SUBR AND BEGIN READ
DTWCS	0
	DAC	DTCCA		/TRANSFER ADDR.-1
	DRRD		/LOAD CORE ADDR AND SET TO READ
	LAW	-10
	DAC	DTERCT		/PARITY ERROR RETRY COUNT
	DAC	DTUND		/SET I/O UNDERWAY
	LAC DTUNIT	/UNIT # MUST BE:
			/0 IF 32,65 OR 131K DRUM
			/1 OR LESS IF 262K
			/3 OR LESS IF 524K
	CLL!RAR
	RAR
	RTR
	RTR
	DAC DTSAFE	/UNIT IN BITS 7,8
	TAD DRLIM	/CHECK UNIT #
	SMA		/OK
	JMP DTER26	/IOPS 26: ILL. DRUM UNIT #
	LAW -1000	/SECTOR ADDR = 777 OR LESS
	TAD DTNXBK	/BLK #
	SMA!CLC
	JMP DTER25	/IOPS 25: ILL. SECTOR ADDR
	LAC DTNXBK	/CHECK UNIT+SECTOR AGAINST MAX DRUM SIZE
	TAD DTSAFE
	DAC DTSAFE
	TAD DRLIM		/-(MAX SIZE FOR THIS PDP-9)
	SMA!CLC
	JMP DTER25	/IOPS 25: ILL SECTOR ADDR
	LAC DTSAFE	/DRUM ADDR
	DRLD		/LOAD DRUM ADDR AND START TRANSFER
	JMP*	DTWCS		/EXIT SUBR
/DTA SEEK FILE SUBR
DTSEEK	LAC	DTCLSS		/PREVIOUS FILE CLOSED
	SZA!CLA
	JMP	DTER10		/NO-FILE STILL ACTIVE
	LAC	(100		/BL# TO TRANSFER
	SAD	DTNXBK		/ALREADY SELECTED
	JMP	DTSEK1
	DAC	DTNXBK
	LAC	DLTDIR		/(DTDIR
	JMS	DTWCS		/SET UP WC, CA AND START I/O
DTSEK1	JMS	DTIOU		/WAIT FOR DIRECTORY
	.EJECT
DTUDRP=DTCKSM
DTCTS=DTCCA
DTCT1S=DTWC
DTDES=DTWCS
DTUWC=DTCCA
DTWPC=DTWC
/DIRECTORY SEARCH SUBR.
DTSK2	CLC		/SYSTEM TAPE?
	XOR* DLTSYS	/WD 3 OF SYS BIT MAP
	SNA!CLA		/NO, 56 FILES
	LAW -30		/YES, 24 FILES
	SMA
	LAW -70
	DAC	DTBFCT
	LAC	DLTD40		/DTDIR+40
	DAC	DTDES		/ENTRY SECTION POINTER
/NEXT FILE NAME ENTRY
DTSK3	LAC*	DTARGP		/USER DIR. ENTRY POINTER
	DAC	DTUDRP
	LAW	-4
	DAC	DTCT1S		/MATCH COUNT
	DAC	DTCTS		/COUNT OF ENTRY WDS TO COUNT
	ISZ	DTCTS
/NEXT WORD OF CURRENT ENTRY
DTSK5	LAC*	DTDES		/DTA DIR. ENTRY (D.E.)
	SAD*	DTUDRP		/USER D.E.
	ISZ	DTCT1S		/WD N OF ENTRY MATCHES
	ISZ	DTDES		/NEXT WD OF DTA ENTRY
	ISZ	DTUDRP		/NEXT WD OF USER ENTRY
	ISZ	DTCTS		/ENTRY WD COUNT
	JMP	DTSK5		/CONT. MATCH CHECK
	ISZ	DTCT1S		/MATCH
	JMP	DTSK6		/NO
	XCT	DTSK5		/GET 4TH WD
	SPA			/INCOMPLETE FILE
	JMP	DTSEK2		/YES-1ST BL# IN AC
DTSK6	ISZ	DTDES		/INDEX TO NEXT ENTRY
	ISZ	DTBFCT		/INDEX FILE ENTRY CT.
	JMP	DTSK3		/NEXT ENTRY
DTER13	TAD	(1		/FILE NOT FOUND
DTER12	TAD	(2		/IRREC. DTA ERR. MK. TK, EOT DURING TRANSFER
				/.SEEK NOT EXECUTED (DTER11)
DTER10	TAD	(2		/FILE STILL ACTIVE
				/ILL. DATA MODE (DTER7)
DTER6	TAD	(6		/ILL. HANDLER FUNCTION
	JMP*	(.MED+1		/KM-9 ERR. LOC.
DTER26	CLA		/IOPS 26: ILL. DRUM UNIT
DTER25	TAD (13		/IOPS 25: ILL SECTOR ADDR
	JMP DTER13
DTSEK2	DAC	DTCLSS		/SET CLOSE SWITCH
	XOR	(400000		/CLEAR SIGN BIT
	JMP	DTRNX1		/TRANSFER 1ST BLOCK
	.EJECT
/.READ IOPS ASCII OR BIN ROUTINE
DTREAD	LAC	DTCLSS		/SEEK EXECUTED
	SNA!CLA!CMA
	JMP	DTER12		/NO
	LAC	DTEOF		/EOF SWITCH SET
	SZA
	JMP	DTEFX		/YES - IGNORE CALL
	JMS	DTIOU		/I/O UNDERWAY CHECK
	LAC*	DTARGP		/USER L.B. POINTER
DTUDP=DTIOU
DTUHP=DTTABL
	DAC	DTUHP
	DAC	DTUDP
	LAC*	DTHPT
	RTR			/SHIFT W.P.C. TO FORM W.C.
	RTR
	RTR
	RTR
	AND	(776
	DAC	DTWPC
	SNA
	JMP DTER23	/0 WPC
	AND (400
	SNA!CLA		/WPC GREATER THAN 177
	JMP	DTATOK
DTER23	LAC DTNXBK	/DISPLAY BLK# WITH IOPS ERROR
	DAC* (.MED
	LAW 23		/IOPS 23: ILL. WPC (0 OR GREATER THAN 177)
	JMP*	(.MED+1		/IOPS 23
DTATOK	ISZ	DTARGP
	LAC*	DTARGP		/USER-W.C.
	DAC	DTUWC
	LAW	7000		/DATA MODE
	AND*	DTCALP
	SAD	(2000		/IOPS ASCII
	CLA			/O.K.
	SZA!CLC			/IOPS BIN-O.K.
	JMP	DTER10		/ILL. DATA MODE
	TAD	DTWPC
	TAD	DTUWC
	DZM	DTDVS		/CLEAR SHORT LINE FLAG.
	SMA!CLC
	DAC	DTDVS		/SET SHORT LINE FLAG.
	TAD	DTWPC
	CMA			/2'S COMP HEADER WORD COUNT
	DAC	DTWPC
	DZM	DTCKSM
/TRANSFER LINE TO USER L.B.
DTWT2	LAC*	DTHPT		/DTA BUF. POINTER.
	DAC*	DTUDP		/USER L.B. POINTER.
	JMS	CALCHK		/ADD TO CHECKSUM.
	ISZ	DTUDP
	ISZ	DTUWC		/DONE
	JMP	DTWT2		/NO
	.EJECT
DTWT3	LAC*	DTHPT		/BYPASS EXCESS
	JMS	CALCHK		/DATA.
	JMP	DTWT3
CALCHK	0
	TAD	DTCKSM		/ADD TO CHECKSUM.
	DAC	DTCKSM
	ISZ	DTHPT		/INDEX DTA BUF. POINTER.
	ISZ	DTBFCT		/INDEX BUF. SIZE COUNT
	ISZ	DTWPC
	JMP*	CALCHK
DTRDE	LAC*	DTUHP		/HEADER WD0-IOPS
	AND	(7
	SAD	(5		/EOF?
	JMP	DTREOF		/YES
	ISZ	DTDVS
	JMP	DTRDE1
	LAC	(60		/SHORT LINE.
	JMS	DTDVS
DTRDE1	LAC	DTERCT		/PARITY RETRY COUNT
	SMA!CLA
	JMP	DTRDP		/SET D.V. BITS=PARITY
	LAC	DTCKSM
	SNA
	JMP	DTRDN		/SET D.V. BITS=CKSUM ERROR
DTRDC	LAC	(20		/CKSUM ERR. IN LINE
DTRDP	TAD	(20		/PARITY ERROR IN DTA BLOCK,12,13=01
	JMS	DTDVS		/12,13=10
DTRDN	LAC*	DTHPT
DTRDN1	SNA!CLC
	JMP	DTRNEX		/NO MORE DATA-GET NEXT BL.
	ISZ	DTBFCT		/DATA BUF. CT = GET NEXT BL.
	JMP	DTRNOR		/NORM EXIT WITH AC=-0 TO DECR. DTBFCT
DTRNEX	SAD	DTBUF+377		/DATA LINK=-0?
	JMP	DTREOF		/LAST BLOCK -SET EOF SWITCH
	LAC	DTBUF+377
DTRNX1	DAC	DTNXBK		/DATA LINK INTO NEXT BLOCK
	LAC	DLTDIR		/INIT DTA BUF. (DTBUF
	DAC	DTHPT		/POINTER
DTUMSK	LAW	-400		/BUF. SIZE
	DAC	DTBFCT
DTCOUB	LAC	DLTDIR		/TRANSFER (DTBUF
	JMS	DTWCS		/SET UP WC,CA AND BEGIN TRANSFER
DTAPE1	ISZ	DTARGP		/INDEX TO NORM .EXIT
	JMP	DTDBK
	.EJECT
DTDVSM=DTCALP
/
/SUBR. TO SET DATA VALIDITY BITS
DTDVS	0
	DAC	DTDVSM		/SAVE MASK
	LAW	17717		/MASK ALL BUT BITS 12,13
	AND*	DTUHP
	XOR	DTDVSM
	DAC*	DTUHP
	JMP*	DTDVS
DTEFX	ISZ	DTARGP		/EXECUTE NEXT 3 LINES ONLY TO GET TO DTAPE1
DTREOF	DAC	DTEOF		/SET EOF SWITCH (-0) ONLY IF ENTERED FROM DTRDN1+3
DTRNOR	TAD	DTBFCT		/DECR. (BY 1) DTFCT
	DAC	DTBFCT
	JMP	DTAPE1		/NORM EXIT
/
DTDIR	0			/DTA DIRECTORY AND DTA BUF.
	.LOC	DTDIR+400		
DLTDIR	DTDIR			/DIRECTORY POINTER
DLTSYS	DTDIR+203			/WD 3 OF SYS BIT MAP
DLTD40	DTDIR+40			/DIRECTORY ENTRY SECTION POINTER
DTARGP	0			/ENTRANCE ARG. POINTER
/DTCCA	0			/CURRENT ADDR. POINTER FOR TRANSFER
DTCALP	0			/USER CAL POINTER
/DTEOF	0			/EOF SWITCH, -0=EOF
/DTHPT	0			/DTA BUF. LINE HEADER POINTER (INDEXED)
/DTUND	0			/I/O UNDERWAY SWITCH, 0=NOT BUSY, NOT EQUAL 0=BUSY
DTUNIT	0			/(0-2)=DTA UNIT FOR TRANSFER
/DTWC	0			/2'S COMP TRANSFER WORD COUNT
/DTCKSM	0			/LINE CHECKSUM (2'S COMP)
/DTCLSS	0			/FILE OPEN CLOSE SWITCH (NON 0=OPEN, 0=CLOSED)
/DTBFCT	0			/DTA BUF. COUNT (INIT=-377)
/DTSAFE	0			/SAFE STOR. FOR TRACK, SECTOR ADDR.
	.END
