        .TITLE  READ 7 TRACK ASCII FROM BCD
/ 
/ 
/                   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# 7
/
/ COPYRIGHT 1971,1972,1973 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ MAGTAPE I/O HANDLER TASK       4 APR 73     R. MCLEAN
/					M. HEBENSTREIT
/
/ MTREA7 READS 7 TRACK BCD RECORDS FROM MAGTAPE (MODE 2&3)
/
/
/
/
	.GLOBL	MTREA7,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 7 TRACK BCD
MTREA7	0
        DZM     BSERFL    /CLEAR THE BUFFER SIZE ERROR FLAG
	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	(MTREA7)	/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	-323	/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	(EP)	/YES -- DEFAULT IS EVEN PARITY
	OMQ		/OR IN THE UNIT NUMBER
	LMQ		/SAVE IT IN MQ
	LAC*	FMTDEN,X /PICK UP THE DENSITY
	SNA		/IS IT DEFAULT DENSITY?
	LAC	(D8)   /YES  --  DEFAULT IS 800 BPI
	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
	SPA!RAL		/EOF?
	JMP	EOF	/YES -- GO RETURN AN END OF FILE HEADER AND AN END OF FILE EVENT VARIABLE
	RTL
	SPA
	JMP	INCRCL	/YES -- CHECK TO SEE IF RECORD TOO LONG
        LAC*    MTEVAM  /PICKUP THE STATUS AGAIN
        AND     (ET)  /IS IT END OF TAPE?
	SZA
	JMP	DECOD	/YES MUST BE OK
        JMP*    ERM12   /NO 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)
	DAC*	(X12)
	LAC	(323)	/DETERMINE ACTUAL WORDS TRANSFERRED
	TAD*	WCA
	DAC	RECFND	/SAVE THE WORD COUNT
        RCL         /COMPUTE THE RECORD 
        TAD     RECFND  /CHARACTER COUNT AT
        DAC     RECCCT  /3 CHARS/WORD.
	LAC	MODSAV	/CHECK FOR IMAGE MODE
	SAD	(3)
	JMP	IMAG	/DECODE IMAGE RECORD REQUEST
        LAC     RECCCT   /DETERMINE IF THE AREA SIZE IS OK
	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 (EXCL. HEADER)
	TAD	SIZEOT
        SPA!SNA
	JMP	INRCL	/NOT INCORRECT LENGTH
RECA	LAC	ERR	/CHECK FOR ERROR ALREADY
	SNA		/SKIP IF PARITY ERROR
	AAC	60
	DAC	ERR
        DAC     BSERFL    /SET BUFFER SIZE ERROR FLAG.
	LAC	SIZEOT	/SET UP SIZE OF TRANSFER
	JMP	.+4
INRCL	LAC	RECFND
        TCA            /SET UP WORD PAIR COUNT
	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 3 CHARACTERS / WORD
	LRSS	14	/DECODE  LEFT HALF FIRST
	JMS	STOR	/DECODE A WORD
	LAC*	X11
	LRSS	6
	JMS	STOR
	LAC*	X12
	JMS	STOR
	JMP	DECODB	/TRY AGAIN NOT FINISHED
/
IMAG    LAC     RECCCT   /COMPUTE A WORD PAIR
        IAC                 /COUNT FOR THE RECORD.
        RCR
        DAC     RECFND   /
        LAC     SIZEOT   /CHECK TO SEE IF
        RCL              /THE BUFFER SIZE IS OK
        TAD     RECCCT
        SPA!SNA
	JMP	INRCL	/SIZE OK
	JMP	RECA	/BAD SIZE ERROR
/
IMAGE   LAC     (JMP IMGCH)      /SET UP TO STORE 1 CHAR/WORD
        DAC     CHRFND
        LAC     SIZEOT    /CHANGE THE TRANSFER
        RCL               /SIZE FROM A WORD PAIR
        DAC     SIZEOT    /COUNT TO A WORD COUNT.
        LAC     BSERFL    /DID A BUFFER SIZE
        SZA               /ERROR OCCUR?
        JMP     DECODB    /YES
        LAC     RECCCT    /NO -- USE THE RECORD
        TCA               /CHARACTER COUNT TO DETERMINE
        DAC     SIZEOT    /THE TRANSFER SIZE.
	JMP	DECODB	/DECODE THE CHARACTERS
/
IMGCH	DAC*	X13	/STORE THE CHARACTER
	ISZ	SIZEOT	/LAST CHARACTER?
	JMP*	STOR	/NO RETURN
FINETC	LAC*	MTEVAM	/CHECK FOR END OF TAPE ERROR
	AND	(ET)
	SNA
	JMP*	FINREQ	/FINISHED NO EOT
        LAC*    UNTTMP   /FIND THE UNIT NUMBER
	PAX
	DZM*	MTEOTT,X /SET END OF TAPE FLAG
	LAC	(4)	/RETURN EOT FLAG
	JMP*	FLSREQ
/
/
STOR	0
        AND     (77)     /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 ASCII.
	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
/
/
/
/
/
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
RECCCT  0       /RECORD CHARACTER COUNT
BSERFL  0       /BUFFER SIZE ERROR FLAG
TBL	0	/NULL (CAN'T HAPPEN )
	61	/1
	62	/2
	63	/3
	64	/4
	65	/5
	66	/6
	67	/7
	70	/8
	71	/9
	60	/0
	75	/=
        47      /'
	72	/:
        76      />
	137	/BACK ARROW
	40	/SP
	57	//
	123	/S
	124	/T
	125	/U
	126	/V
	127	/W
	130	/X
	131	/Y
	132	/Z
	15	/CR
	54	/,
	50	/(
	11	/TAB
        177     /RO
        12      /LF
	55	/-
	112	/J
	113	/K
	114	/L
	115	/M
	116	/N
	117	/O
	120	/P
	121	/Q
	122	/R
	41	/!
	44	/$
	52	/*
	135	/]
	73	/;
	14	/FF
	53	/+
	101	/A
	102	/B
	103	/C
	104	/D
	105	/E
	106	/F
	107	/G
	110	/H
	111	/I
	77	/?
	56	/.
	51	/)
        133     /BRACKET
	74	/<
        175     /AM
BUF	.BLOCK	323
	.END	MTREA7
