	.TITLE DKC.
/5-27-70	EDIT #1	FOR 15/20 KM V5A
/	1-30-70
/COPYRIGHT 1970, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/DISK ADAPTATION 6-25-68
/M. SIFNAS   10-21-67 (.WAITR 3-25-68) (IOPS 23 5-8-68)
/(56 FILES 5-15-68)
/DKC.=IOPS DISK/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	DKC.
.MED=3
/IOT ASSIGNMENTS
DSLW=707124
DSLM=707142
DSLD=707104
DSCS=707141
DSLS=707144
DSSF=707121
DSRS=707132
DTBUF=DTDIR
DKC.	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	(377		/MASK OFF FUNCTION CODE.
	TAD	(JMP DTTABL
	DAC	DTTABL
	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
	SNA			/YES
	JMP*	DTIOU		/OK-EXIT
DTBUSY	LAC	DTCALP		/BUSY-DTA I/O GOING ON
	DAC	DTARGP		/RETURN TO USER CAL
	JMP	DTDBK
/DTA-DISK-INTERRUPT SERVICE
DTPIC	DAC	DTAC		/SAVE AC
	LAC*	(0
	DAC	DOUT		/SAVE PC, LINK, EXT. MODE, MEM. PTCT.
	LAC	DTION
	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	DTION		/PIC ON, BUILD ION
DTSTON	DAC	DTDVSW
	DSRS			/READ DISK STATUS
	DSCS			/CLEAR DISK STATUS
DTION	ION			/ION TO ALLOW OTHER INTERRUPTS
	DAC	DTBLC		/TEMP
	SPA!RTL
	JMP	DTERT		/ERR. FLAG
	DZM	DTUND		/CLEAR I/O UNDERWAY
	JMP	DTDISM		/DATA OK, DISMISS
DTERT	SZL!SPA
	JMP	DPART		/PARITY OR ILL. DISK ADDR.
	RTL
	SMA			/NOT READY, DISK FAILURE
	JMP	DRETRY		/TIMING ERROR
	LAC	DTBLC		/DISK STATUS
	DAC*	(.MED		/IN .MED INSTEAD OF CAL ADDR
	LAW 20			/DISK FAILURE
	JMP*	(.MED+1
DPART	SMA			/ILL. DISK ADDR.
	JMP	DPARIT
	LAW 21			/ILL. DISK ADDR.
	JMP*	(.MED+1
DPARIT	ISZ	DTERCT		/IF OVERFLOW, TAKE DATA ANYWAY
	SKP
	JMP DNRET
DRETRY	IOF
	JMS	DKSET		/REISSUE DISK READ
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	(377		/RETURN 255 AS BUF. SIZE
	DAC*	DTARGP
	ISZ	DTARGP		/INDEX TO NORM. EXIT
DTONCE	JMP	BNKBTS		/API CORE ADDR.-MODIFIED OR JMP DTSTOP
DTAC	16			/.SETUP
DOUT	DSSF			/DISK DONE AND ERROR FLAG
DTT2	DTINT			/DISK INT. SERV. ADDR.
DTBCA	JMP	DTNXBK
/
/DTONCE+1 TO 11 USED FOR TEMP. STOR. AFTER 1ST INIT
DTERCT	0
DTBLC	0
DTBLNC	0
DTNXBK	LAC	DJSTOP
DTDTR	DAC	DTONCE
/STOP DTA ROUTINE
DTSTOP	DZM	DTUND		/CLEAR I/O UNDERWAY
	DZM	DTEOF		/CLEAR EOF SWITCH
	DZM	DTCLSS		/SET .CLOSE SWITCH
	JMP DTDBK
/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
DTDBK	DBR
	XCT .+1
	XCT .+1
	JMP*	DTARGP		/NORM. EXIT
	.EJECT
/SET UP CA,WC SUBR AND BEGIN READ
DTWCS	0
	DAC	DTCCA		/TRANSFER ADDR.-1
	LAW	-10
	DAC	DTERCT		/PARITY ERROR RETRY COUNT
	DAC	DTUND		/SET I/O UNDERWAY
	CLA!STL			/CONVERT UNIT TO TRACK,
	RTR
	DAC	DTBLC		/INIT TO DISK SIDE 2
	LAC	DTUNIT
	SAD	(300000		/UNIT 3 ILL.
	JMP	DTER27
	SAD	(700000		/UNIT 7 ILL
	JMP	DTER27
	SMA!RTL			/UNIT 4-6 (SIDE 2)
	DZM	DTBLC		/UNIT 0-3 (SIDE 1)
	SNL!RAL			/UNIT 2 OR 6
	SZL!CLA!STL		/UNIT 0 OR 4
	LAC	(30000		/2,6
	SNL			/0,4
	TAD	(30000
	TAD	DTBLC		/SIDE
	DAC	DTUNIT		/CONVERTED UNIT
	LAC	DTNXBK		/LOGICAL BL. #
TRACK=DTBLC
	DZM	TRACK
	AND	(3777		/LOGICAL BLOCK
FINDT	TAD	(-24		/20 BLOCKS PER TRACK
	SPA!STL
	JMP	FINDS		/TRACK FOUND
	ISZ	TRACK
	JMP	FINDT		/STILL LOOKING
FINDS	TAD	(24
	RTL
	JMS	.TOBCD
SECTOR=DTDTR
	DAC	SECTOR
	LAC	TRACK
	JMS	.TOBCD
	RTL
	RTL
	RTL
	RTL
	XOR	SECTOR
	TAD	DTUNIT
	DAC	DTSAFE		/SAVE
	JMS	DKSET		/SET UP DISK I/O + EXECUTE IOT'S
	JMP*	DTWCS		/EXIT SUBR
	.EJECT
/OCTAL TOBCD CONV.
.TOBCD	0
	DZM	HOD		/HIGH ORDER DIGIT
	SKP
NXT	ISZ	HOD
	DAC OCTN		/REMAINDER
	TAD (-12
	SMA!CLL
	JMP	NXT
	LAC	HOD		/COMBINE DIGITS
	RTL
	RTL
	XOR OCTN
	JMP*	.TOBCD
HOD	0
OCTN	0
/SUBR TO SET UP DISK I/O AND EXECUTE IOT'S
DKSET	0
	LAC	DTCCA
	DSLM			/CORE ADDR.
	LAW	-400
	DSLW			/W.C.
	LAC	DTSAFE
	DSLD			/TRACK, SECTOR ADDR.
	LAC	(6000		/LOAD STATUS: READ, GO, INIT. ENABLED
	DSCS!DSLS		/CLEAR AND LOAD STATUS
	JMP*	DKSET
/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
	DZM	DTDTR		/DIRECTION=FORWARD
	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
	.EJECT
/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	LAC	(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.
DTER27	LAW	27		/ILLEGAL DISK UNIT
	JMP*	(.MED+1		/4
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	LAW	23		/ILL. WPC
	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	DTNXBK
	CMA
	TAD	DTBUF+377
	SPA!CLA			/READ FORW
	CLC			/READ REV.
	DAC	DTDTR		/TRANSF. DIRECTION 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	60000			/DTA DIRECTORY AND DTA BUF.
L47	CAL	47
BNKBTS	JMS	.		/BANK BIT INITIALIZATION
	LAC	BNKBTS
	XOR	DTT2
	AND	DTDIR
	XOR	DTT2
	DAC	DTT2
	XOR	DLTDIR
	AND	DTDIR
	XOR	DLTDIR
	DAC	DLTDIR
	TAD	DLTD40
	DAC	DLTD40
	TAD	DLTSYS
	DAC	DLTSYS
	LAC	L47
	DAC	DTONCE
	JMP	DTONCE
	.LOC	DTDIR+400		
DLTDIR	DTDIR			/DIRECTORY POINTER
DLTSYS	203-40			/WD 3 OF SYS BIT MAP
DLTD40	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)
DTEOTS	0			/END ZONE (EOT) ENTERED SWITCH (-=EOT)(0=NO EOT)
DTEOTZ	0			/DOUBLE END ZONE SWITCH (0=SET,-0=CLEAR)
DTSAFE	0			/SAFE STOR. FOR TRACK, SECTOR ADDR.
	.END
