	.TITLE	READ 9 TRACK ASCII FROM EBCDIC
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ 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 RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED 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 PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/
/       EDIT # 10
/
/ COPYRIGHT 1971,1972,1973 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ MAGTAPE I/O HANDLER TASK            4 APR. 1973   R. MCLEAN
/					M. HEBENSTREIT
/
/ MTREA9 READS 9 TRACK EBCDIC RECORDS FROM MAGTAPE (MODE 2&3)
/
/
/
/
	.GLOBL	MTREA9,FINREQ,FLSREQ,WFMT,MTNODE,MTCAA,MTWCA,FMTDEN,FMTPAR
	.GLOBL	UNTTMP,MTEOTT,ERM12,MTEVAM
/
/
WCA	32
CAA	33	/WORD COUNT ADDRESS
	.TITLE	PARAMETER DEFINITIONS
/
/
/
/
/
/	PARAMETER DEFINITIONS
/
R1=101
R2=102
R3=103
R4=104
R5=105
POOL=240	/POOL DEQUE LIST HEAD
PICK=120	/PICK A NODE
PDVL=252	/PHYSICAL DEVICE DEQUE LIST HEAD
NADD=107	/NODE ADD
SNAM=123	/SEARCH FOR A NAME
DQRQ=337	/DE-QUEUE A NODE FROM PDVL NODE
ALAD=325	/ATTACH LUN AND DEVICE
DLAD=332	/DETACH LUN AND DEVICE
VAJX=342        /VALIDATE AND ADJUST
X10=10
X11=11
X12=12
X13=13
/
.INH=705522
.ENB=705521
ECLA=641000
/
MTSF=707341	/SKIP ON ERROR FLAG OR MAGTAPE FLAG
MTCR=707321	/SKIP ON TAPE CONTROL READY
MTTR=707301	/SKIP ON TAPE TRANSPORT READY
MTAF=707322	/CLEAR THE STATUS AND COMMAND REGISTERS, EF AND MTF
                /IF TAPE CONTROL READY. IF NOT READY CLEAR EF AND MTF ONLY
MTVM=707302	/OR COMMAND REGISTER INTO AC 0-11
MTCM=707324	/OR AC 0-5,9-11 INTO COMMAND REGISTER LOAD 6-8
		/INTO COMMAND REGISTER
MTLC=707326	/LOAD AC 0-11 INTO COMMAND REGISTER
MTVS=707342	/INCLUSIVELY OR STATUS REGISTER INTO AC 0-11
MTRS=707352	/READ THE CONTENTS OF STATUS REGISTER INTO AC 0-11
MTRC=707312	/READ THE CONTENTS OF COMMAND REGISTER INTO AC 0-11
MTGO=707304	/EXECUTE THE COMMAND REGISTER
/
EF=400000	/ERROR FLAG
RW=200000	/TAPE REWINDING
BT=100000	/BEGINNING OF TAPE
IC=040000	/ILLEGAL COMMAND
PE=020000	/PARITY ERROR
FI=010000	/EOF
ET=004000	/EOT
RE=002000	/READ-COMPARE ERROR
IL=001000	/RECORD LENGTH INCORRECT
DL=000400	/DATA REQUEST LATE
TB=000200	/BAD TAPE
EP=000000+1	/EVEN PARITY
OP=040000+1	/ODD PARITY
CD=020000+1	/CORE DUMP MODE
IG=010000	/INTER - RECORD GAP
NP=000000	/MT NOP
RI=001000	/REWIND
RD=002000	/READ
RC=003000	/READ - COMPARE
WR=004000	/WRITE
WF=005000	/WRITE END OF FILE
SF=006000	/SPACE FORWARD
SR=007000	/SPACE REVERSE
IE=000400	/INTERRUPT ENABLE
ID=000000	/INTERRUPT DISABLE
D2=000000+1	/DENSITY 200 BPI
D5=000100+1	/DENSITY 556 BPI
D8=000200+1	/DENSITY 800 BPI
D9=000300+1	/DENSITY 800 BPI 9 TRACK
	.TITLE	READ 9 TRACK EBCDIC
MTREA9	0
	LAC*	UNTTMP	/CHECK FOR END OF TAPE ERROR
	PAX
	LAC*	MTEOTT,X	/PICK UP EOT FLAGS
	SMA		/EOT?
	JMP	ERM21	/YES ERROR
	DZM	ERR	/CLEAR THE ERROR FLAGS
	LAC	(TBLPTR-1) /SET UP POINTERS FOR CHARACTER DECODING
	DAC	WDPTR
	LAC	(ISZ	WDPTR)	/SET UP FOR 5/7 ASCII
	DAC	CHRFND
	LAC	(MTREA9)	/CALCULATE THE XR ADJUSTMENT
	AND	(070000)
	TCA
	DAC	XADJ
	TAD*	MTNODE	/PICK UP THE REQUESTOR'S NODE ADDRESS
	PAX		/SET UP TO PICK UP THE PARAMETERS
	LAC	7,X	/SAVE THE MODE
	DAC	MODSAV
	LAC	10,X	/PICK UP THE I/O ADDRESS
        DAC*    (R3)     /SET UP FOR VALIDATE AND ADJUST
	LAC*	MTNODE
	DAC*	(R2)
        LAC     11,X    /BUFFER SIZE
        DAC*    (R4)
	AAC	-2
	SPA!SNA		/CHECK BUFFER SIZE
	JMP	ERM16
	CLL!RAR		/MAKE IT A WORD PAIR COUNT
	TCA
	DAC	SIZEOT	/SAVE SIZE OF TRANSFER  EXCLUDING HEADER
        AAC     -2
        JMS*    (VAJX)   /VALIDATE AND ADJUST THE INPUT PARAMETERS
	JMP	ERM30	/PROTECT VIOLATION
	LAC*	(R3)	/PICK UP THE I/O ADDRESS (ADJUSTED)
	DAC	BUFADR	/SAVE IT FOR FUTURE USE
	LAW	-500	/SET UP THE WORD COUNT TO READ INTO THE BUFFER
	DAC*	WCA	/STORE IN MAGTAPE WORD COUNT REGISTER
	DAC*	MTWCA	/SAVE IT IN CASE OF AN ERROR
	LAC	(BUF-1)	/SET UP THE CURRENT ADDRESS POINTER
	DAC*	CAA
	DAC*	MTCAA
	LAC*	UNTTMP	/PICK UP THE UNIT NUMBER
	PAX		/SAVE IT IN XR
	ALS	17	/PUT IT IN BITS 0-2 FOR THE MAGTAPE UNIT NUMBER
	AND	(700000)	/MASKOFF UNIT
	LMQ		/SAVE IT IN MQ TO FIND DENSITY AND PARITY
	LAC*	FMTPAR,X /FIND THE PARITY
	SNA		/IS IT DEFAULT PARITY?
        LAC     (OP)    /YES -- DEFAULT IS ODD PARITY
	OMQ		/OR IN THE UNIT NUMBER
	LMQ		/SAVE IT IN MQ
	LAC*	FMTDEN,X /PICK UP THE DENSITY
	OMQ		/OR IN UNIT NUMBER AND PARITY
	XOR	(RD!IE)	/OR IN READ COMMAND
	JMS*	WFMT	/REQUEST A TAPE MOTION
	LAC	BUFADR  /SET UP POINTER TO USER'S BUFFER
	AAC	-1
	DAC*	(X13)
	LAC*	MTEVAM	/PICK UP THE STATUS OF THE TAPE REQUEST
	SMA		/WAS IT OK?
        JMP     DECOD   /YES -- DECODE THE INFO
	LLS	4	/LOOK AT THE ERROR STATUS
	SPA!RAL		/WAS IT AN END OF FILE?
	JMP	PARERR	/PARITY ERROR SET'S ERROR BITS
        SPA             /WAS THERE AN EOF?
	JMP	EOF	/YES -- GO RETURN AN END OF FILE HEADER AND AN END OF FILE EVENT VARIABLE
	LLS	3	/LOOK FOR INCORRECT RECORD LENGTH
	SPA
	JMP	INCRCL	/YES -- CHECK TO SEE IF RECORD TOO LONG
	LAC*	MTEVAM	/ONLY OTHER LEGAL ERROR IS EOT
	AND	(ET)
	SZA
	JMP	DECOD	/DECODE THE TAPE
	JMP*	ERM12	/YES RETURN -12
/
/	EOF -- END OF FILE REACHED RETURN HEADER WORD PAIR OF
/              1005,-1005  AND AN EVENT VARIABLE OF +2 TO INDICATE
/		TO THE USER THAT AN END OF FILE HAS BEEN FOUND
/
EOF	LAC	(1005)	/SET UP EOF INDICATOR
	DAC*	X13	/SET IN BUFFER
	TCA		/COMPLEMENT
	DAC*	X13	/STORE IN USER'S CHECKSUM
	LAC*	MTEVAM	/PICK UP THE STATUS OF THE READ
	AND	(ET)	/WAS IT AN EOT?
	SZA
	JMP	EOT	/YES REPORT EOT AND SET TABLE
	AAC	3	/RETURN EVENT VARIABLE OF +3
	JMP*	FLSREQ	/RETURN TO USER
/
/      EOT -- FOUND DURING A READ OR WRITE
/              SET EOT FLAGS IN TABLE AND RETURN EV +3
/
EOT	LAC*	UNTTMP	/FIND THE UNIT NUMBER TO SET UP THE
	PAX		//EOT TABLE
        DZM*    MTEOTT,X  /INDICATE EOT FOUND NO FORWARD MOTIONS ACCEPTED
	LAC	(4)	/RETURN +4 IN USER'S EVENT VARIABLE
	JMP*	FLSREQ
/
/	INCRCL -- INCORRECT RECORD LENGTH ERROR NOT AN ERROR IF
/		BUFFER TOO LONG ONLY IF BUFFER IS TOO SHORT
/
INCRCL	LAC*	WCA	/CHECK THE WORD COUNT
			/TO DETERMINE IF RECORD SHORT
	SZA
	JMP	DECOD	/HARDWARE READ OK GO DECODE
	LAC	(60)	/SET UP INCORRECT RECORD LENGTH ERROR
	DAC	ERR
	JMP	DECOD	/DECODE THE TEXT
/
PARERR	LAC	(20)	/ON PARITY ERROR SET PARITY ERROR BITS
	DAC	ERR	/SET UP HEADER FLAGS
/
DECOD	LAC	(BUF-1)	/BUFFER POINTER
	DAC*	(X10)
	DAC*	(X11)
	LAC	(500)	/DETERMINE ACTUAL WORDS TRANSFERRED
	TAD*	WCA
	DAC	RECFND	/SAVE THE WORD COUNT
	LAC	MODSAV	/CHECK FOR IMAGE MODE
	SAD	(3)
	JMP	IMAG	/DECODE IMAGE RECORD REQUEST
	LAC	RECFND	/DETERMINE IF THE AREA SIZE IS OK
        CLL!RAL          /MULTIPLY BY 2
        CLL             /NOW HAVE CHARACTER COUNT
	IDIV		/FIND WORD PAIR COUNT
	5
	SNA!CLL		/AC=REMAINDER
	STL		/NO REMAINDER
	LACQ		/WORD PAIR COUNT MINUS LAST WORD PAIR
	SNL
	IAC		/ADD IN REMAINDER (1 WORD PAIR)
        DAC     RECFND     /SAVE WORD PAIR COUNT
IMAG    LAC     RECFND     /CHECK TO SEE IF BUFFER IS LARGE ENOUGH
	TAD	SIZEOT
        SPA!SNA
	JMP	INRCL	/NOT INCORRECT LENGTH
RECA	LAC	ERR
	SNA
	AAC	60	/SET INCORRECT RECORD LENGTH
	DAC	ERR
	LAC	SIZEOT	/SET UP SIZE OF TRANSFER
	JMP	.+4
INRCL	LAC	RECFND
        TCA             /SET UP THE WORD PAIR COUND (EXCL. HEADER)
	DAC	SIZEOT
	TCA!CLL		/SET UP HEADER
	IAC		/ADD 1 TO INCLUDE HEADER
	SWHA		/SET UP WORD PAIR COUNT
	XOR	ERR	/SET IN THE ERROR BITS
	XOR	MODSAV	/AND THE MODE BITS
	DAC*	X13	/SET IN THE USER'S BUFFER
	DZM*	X13	/ZERO CHECKSUM WORD
	CLL
	LAC	MODSAV	/CHECK FOR IMAGE
	SAD	(3)
	JMP	IMAGE	/GO DECODE IN IMAGE MODE
DECODB	LAC*	X10	/DECODE THE 2 CHARACTERS / WORD
	LRSS	10	/DECODE  LEFT HALF FIRST
	JMS	STOR	/DECODE A WORD
	LAC*	X11
	JMS	STOR
	JMP	DECODB	/TRY AGAIN NOT FINISHED
/
IMAGE   LAC     (JMP IMGCH)       /SET UP TO STORE 1 CHAR/WORD
        DAC     CHRFND
        LAC     SIZEOT    /CONVERT THE TRANSFER SIZE
        RCL               /FROM A WORD PAIR COUNT TO
        DAC     SIZEOT    /A WORD COUNT.
	JMP	DECODB	/DECODE THE CHARACTERS
/
IMGCH	DAC*	X13	/STORE THE CHARACTER
	ISZ	SIZEOT	/LAST CHARACTER?
	JMP*	STOR	/NO RETURN
FINETC	LAC*	MTEVAM
	AND	(ET)	/END OF TAPE?
	SNA
	JMP*	FINREQ	/FINISHED REQUEST
	LAC*	UNTTMP	/FIND THE UNIT NUMBER
	PAX
	DZM*	MTEOTT,X /SET THE EOT FLAG
	LAC	(4)
	JMP*	FLSREQ	/RETURN +4 EOT FLAG
/
/
STOR	0
	CLL		/CLEAR LINK FOR SHIFT OPERATIONS
	AND	(177)	/MASK TO 7 BITS
        SAD     (7)     /RO?
	JMP	RO	/YES
        SAD     (47)    /ALTMODE?
	JMP	AM	/YES
        SAD     (5)     /IS IT A TAB?
	JMP	TAB	/YES
	SAD	(45)	/IS IT A LF?
	JMP	LF	/YES
        SAD     (13)    /IS IT A VT?
        JMP     CHRFND  /YES
        SAD     (14)    /IS IT A FF?
        JMP     CHRFND
        SAD     (15)    /IS IT A CR?
	JMP	CR
	AND	(77)	/NONE OF ABOVE LOOK UP IN TABLE
	PAX
	LAC	TBL,X	/FIND CHARACTER
CHRFND  XX         /MODIFIED INSTRUCTION. 'ISZ WDPTR' FOR IOPS 
                   /ASCII MODE TO UPDATE THE CHARACTER
                   /POINTER. 'JMP IMGCH' IF IMAGE MODE.
	XCT*	WDPTR	/GO STORE THE WORD
/
CHR1	ALSS	7	/MOVE OVER FOR CHARACTER 2
	DAC	TEMP	/SAVE IT
	JMP*	STOR	/RETURN
/
CHR2	XOR	TEMP	/ADD IN CHARACTER 1
	ALSS	4	/SET UP FOR CHARACTER 3
	DAC	TEMP
	JMP*	STOR	/RETURN
/
CHR3	LRSS	3	/SAVE 3 BITS OF THIS CHARACTER FOR NEXT WORD
	XOR	TEMP	/ADD IN FIRST 2 CHARACTERS
	DAC*	X13	/STORE THE WORD
        LLS     12      /SET UP FOR SECOND WORD
	AND	(1600)	/MASK OFF GARBAGE
	DAC	TEMP
	JMP*	STOR	/RETURN
/
CHR4	XOR	TEMP	/ADD IN 4TH CHARACTER
	ALSS	7	/SET UP FOR 5TH CHARACTER
	DAC	TEMP
	JMP*	STOR	/RETURN
/
CHR5	XOR	TEMP	/LAST CHARACTER RESET AND STORE
	RAL!CLL		/BIT 17 ZERO
	DAC*	X13
	LAC	(TBLPTR-1)
	DAC	WDPTR	/RESET
	ISZ	SIZEOT	/CHECK TO SEE IF LAST WORD PAIR WANTED
	JMP*	STOR	/NO TRY AGAIN
	JMP	FINETC	/YES EXIT
/
TBLPTR	JMP	CHR1
	JMP	CHR2
	JMP	CHR3
	JMP	CHR4
	JMP	CHR5
AM      JMS     CRAM    /STORE ALTMODE; NO RETURN
        LAC     (175)   /ARG. TO CALL: ALTMODE.
CR      JMS     CRAM    /STORE CA. RET.; NO RETURN
        LAC     (15)    /ARG. TO CALL: CAR. RET.
/  
CRAM    0               /SUBR. CALLED BY AM AND CR.
        XCT*    CRAM    /GET CHARACTER.
        XCT     CHRFND  /IF IOPS ASCII: ISZ WDPTR.
                        /IF IMAGE ASCII: JMP IMGCH.
        LAW     -1      /SET COUNTER TO TERMINATE.
        DAC     SIZEOT
        LAC     (STORTN)  /SET UP TO FAKE OUT
        DAC     STOR     /STOR AND TO FILL IN
                         /REMAINDER OF WORD
                         /PAIR WITH NULLS.
        XCT*    CRAM     /GET CHARACTER.
/
	XCT*	WDPTR	/GO STORE CHARACTER
STORTN	CLA		/SET UP TO CLEAR REST OF WORD PAIR
	JMS	STOR
	JMP	.-2
TAB	LAC	(11)	/RETURN TAB
	JMP	CHRFND
/
LF	LAC	(12)	/RETURN LINE FEED
	JMP	CHRFND
RO	LAC	(177)	/RETURN RUBOUT
	JMP	CHRFND
/
/
/
/
ERM16	LAW	-16	/ILLEGAL BUFFER SIZE
	JMP*	FLSREQ	/RETURN -16 TO USER
/
ERM21	LAW	-21	/END OF TAPE REQUEST NOT HONORED
	JMP*	FLSREQ	/RETURN -21 TO USER
ERM30	LAW	-30
	JMP*	FLSREQ
/
BUFADR	0	/ADDRESS OF USER'S BUFFER
MODSAV	0	/MODE OF REQUEST
SIZEOT	0	/SIZE OF REQUESTED TRANSFER
XADJ	0	/XR ADJUSTMENT
TEMP	0	/TEMPORARY SAVE AREA FOR DECODING
WDPTR	0	/CHARACTER POINTER
ERR	0	/ERROR BITS FOR PARITY ETC.
RECFND	0	/INTERMEDIATE RECORD SIZE
TBL	40	/SP
	101	/A
	102	/B
	103	/C
	104	/D
	105	/E
	106	/F
	107	/G
	110	/H
	111	/I
        0       /UNDEF
	56	/.
	74	/<
	50	/(
	53	/+
	0	/UNDEF
	46	/&
	112	/J
	113	/K
	114	/L
	115	/M
	116	/N
	117	/O
	120	/P
	121	/Q
	122	/R
        41      /!
	44	/$
	52	/*
	51	/)
	73	/;
	137	/_
	55	/-
	57	//
	123	/S
	124	/T
	125	/U
	126	/V
	127	/W
	130	/X
	131	/Y
	132	/Z
        0      /UNDEF
	54	/,
	45	/%
	0	/UNDEF
	76	/>
	77	/?
	60	/0
	61	/1
	62	/2
	63	/3
	64	/4
	65	/5
	66	/6
	67	/7
	70	/8
	71	/9
	72	/:
	43	/#
        100     /AMPERSAND
	47	/'
	75	/=
	42	/"
BUF	.BLOCK	500
	.END	MTREA9
