	.TITLE	WRITE 9 TRACK ASCII TO 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 # 8
/
/ COPYRIGHT 1971,1972  DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ MAGTAPE I/O HANDLER TASK          26 OCT 72    R. MCLEAN
/
/ MTWRA9 WRITES 9 TRACK EBCDIC RECORDS TO MAGTAPE (MODES 2&3)
/
/
/
/
	.GLOBL	MTWRA9,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	WRITE 9 TRACK EBCDIC
MTWRA9	0
	DZM	CNTA
	LAW	-2	/SET UP COUNTER
	DAC	COUNT
	LAC*	UNTTMP	/PICK UP THE UNIT NUMBER OF THE REQUEST
	PAX
	LAC*	MTEOTT,X /PICK UP THE END OF TAPE FLAG
	SMA		/EOT?
	JMP	ERM21	/YES SET EVENT VARIABLE TO -21
	LAC	(MTWRA9) /PICK UP THE XR ADJUSTMENT
	AND	(070000) /MASK OFF THE PAGE BITS
	TCA
	TAD*	MTNODE	/ADD IN THE ADDRESS OF THE REQUESTING NODE
	PAX
	LAC	10,X	/PICK UP THE BUFFER ADDRESS
        DAC     TEMP    /SAVE IT FOR SECOND VALIDATE AND ADJUST
        DAC*    (R3)    /SET UP FOR VALIDATE AND ADJUST
	LAC*	MTNODE
	DAC*	(R2)
        CLA!IAC        /VALIDATE ONLY 1 WORD
	DAC*	(R4)
	PXA		/SAVE XR
	DAC	TMP
	JMS*	(VAJX)	/VALADATE AND ADJUST
	JMP	ERM30	/PROTECT ERROR
	LAC*	(R3)	/PICK UP I/O ADDRESS
	IAC		/POINT TO FIRST WORD OF WORD PAIR
	DAC*	(X10)
	DAC*	(X11)
	AAC	-2
	DAC*	(X12)	/SAVE POINTER TO THE HEADER WORD PAIR
	LAC	(BUF-1)	/PICK UP THE ADDRESS OF THE INTERNAL BUFFER
	DAC*	(X13)	/SAVE IT
	DAC*	CAA	/STORE IT IN THE MAGTAPE CURRENT ADDRESS POINTER
        DAC*    MTCAA     /SAVE IT IN CASE OF AN ERROR
	LAC*	X12	/PICK UP THE HEADER TO DETERMINE THE WORD COUNT
	SWHA		/MOVE THE WORD COUNT TO THE RIGHT HALF
        AND     (177)    /MASK OFF THE WORD COUNT
	AAC	-1	/SUBTRACT 1 SINCE HEADER IS NOT TRANSFERRED
	TCA
	DAC	WDCNT	/SAVE THE WORD COUNT
	SMA		/IS IT LEGAL?
	JMP	ERM16	/NO RETURN -16 EVENT VARIABLE
	TCA
	CLL!RAL		/MULTIPLY BY 2 TO FIND WORD COUNT
        DAC*    (R4)    /SET UP FOR SECOND VALIDATE AND ADJUST
	LAC	TEMP
	DAC*	(R3)	/RESET CORE ADDRESS
        JMS*    (VAJX)   /VALIDATE AND ADJUST
	JMP	ERM30	/PROTECT ERROR
	LAC	TMP	/RESTORE XR
	PAX
	DZM	TEMP	/CLEAR OUT TEMP STORAGE
	LAC	7,X	/PICK UP THE MODE OF THE REQUEST
	SAD	(3)	/IS IT IMAGE?
	JMP	IMAG	/YES DECODE IMAGE
CONVAN	LAC*	X10	/PICK UP THE FIRST WORD PAIR
        LRS     13      /RIGHT JUSTIFY FIRST CHARACTER
	JMS	CONV	/CONVERT THE CHARACTER
	LLS	7	/CONVERT THE NEXT CHARACTER
	JMS	CONV	/CONVERT THE SECOND CHARACTER
	LLS	7	/PICK UP THE FIRST HALF OF THE 3 CHARACTER
        AND     (170)     /MASK OFF THE RELEVANT BITS
	DAC	TMP	/SAVE THE BITS
	LAC*	X10	/PICK UP THE NEXT WORD
	LRS	17	/MOVE THE USEFUL BITS TO 15-17
	AND	(7)	/MASK OFF THE BITS
	XOR	TMP	/ADD THE FIRST HALF OF THE CHARACTER
	JMS	CONV	/CONVERT THE THIRD CHARACTER
        LLS     7      /PICK UP THE 4TH WORD
	JMS	CONV	/CONVERT IT
	LLS	7	/PICK UP THE 5TH CHARACTER
	JMS	CONV	/CONVERT IT
	ISZ	WDCNT	/IS THE WORD COUNT EXHAUSTED?
	JMP	CONVAN	/NO -- GO DO THE NEXT WORD PAIR
FINIMG  CLQ            /YES LEFT JUSTIFY THE FINAL WORD
        LAC     COUNT    /IF THE COUNT 2 INDICATING 'TEMP' EMPTY?
	SAD	(-2)
	JMP	FIN	/YES GO TRANSFER THE BUFFER TO TAPE
	LAC	TEMP	/PICK UP THE LAST CHARACTER
        SZA              /SKIP IF LAST WORD EMPTY
        DAC*    X13    /STORE THE LAST WORD
FIN	LAC	CNTA	/PICK UP THE WORD COUNT
	TCA		/COMPLEMENT IT FOR MAGTAPE REGISTER
	DAC*	WCA	/STORE IN MAGTAPE WORD COUNT REGISTER
	DAC*	MTWCA	/SAVE IT IN CASE OF AN ERROR
	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	(WR!IE)	/OR IN WRITE COMMAND
	JMS*	WFMT	/REQUEST A TAPE MOTION
	LAC*	MTEVAM	/PICK UP THE STATUS OF THE TAPE REQUEST
	SMA		/WAS IT OK?
	JMP*	FINREQ	/YES -- RETURN +1 EVENT VARIABLE
	AND	(ET)	/NO -- WAS IT END OF TAPE?
	SNA
	JMP*	ERM12	/NO -- UNKNOWN ERROR
	LAC*	UNTTMP	/PICK UP THE UNIT NUMBER
	PAX
	DZM*	MTEOTT,X /CLEAR THE EOT SWITCH
	LAC	(4)	/RETURN A STATUS OF +4
	JMP*	FLSREQ
/
IMAG	LAC*	X10	/DECODE AND WRITE IMAGE
	JMS	CONV
	LAC*	X10
	JMS	CONV
	ISZ	WDCNT	/FINISHED?
	JMP	IMAG	/NO CONTINUE
	JMP	FINIMG	/YES -- STORE LAST CHARACTERS
/
/      CONV -- CONV CONVERTS 5/7 BIT ASCII
/		TO EBCDIC
/
CONV	0
	AND	(177)	/MASK OFF 7 BITS
	SAD	(177)	/IS IT A RUBOUT?
	JMP	RO	/YES -- INSERT RUBOUT CODE
	SAD	(175)	/IS IT AN ALTMODE?
	JMP	AM	/YES -- INSERT AN ALTMODE
	SAD	(137	/IS IT A BACK ARROW?
	JMP	CONVR	/YES -- INSET A BACK ARROW
        AAC     -11      /FIRST 11 CHARACTERS ARE NULL
	PAX
	SPA!CLA		/
	JMP*	CONV	/NOT LEGAL CHARACTER DELETE IT
        AAC     126     /IS THE HIGH END LEGAL?
	PAL
        CLA            /CLEAR AC IN CASE IT IS LEGAL
	AXS	0	/CHECK FOR UPPER LIMIT
	SKP		/LEGAL PICK UP FROM TABLE
	JMP*	CONV	/ILLEGAL RETURN
	LAC	TBL,X	/PICK UP THE EBCDIC CHARACTER
	SNA!CLL		/IS IT A NULL CHARACTER?
	JMP*	CONV	/YES -- IGNORE IT
CONVR	ISZ	COUNT	/2 CHARACTERS FOUND?
	JMP	CONVS	/NO SET UP FOR NEXT TIME
	XOR	TEMP
	DAC*	X13	/YES -- STORE 2 CHARACTERS
	LAW	-2	/RESET COUNTER
	DAC	COUNT
	JMP*	CONV	/RETURN TO CALLER
CONVS	ALSS	10	/MOVE OVER 8 BITS FOR NEXT TIME
	DAC	TEMP	/SAVE VALUE
	ISZ	CNTA	/UPDATE TAPE WORD COUNT
	JMP*	CONV	/RETURN TO CALLER
RO      LAC     (7)
	JMP	CONVR
AM      LAC     (47)
	JMP	CONVR
/
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
/
TEMP	0
CNTA	0
TMP	0
COUNT	0
WDCNT	0
TBL     5       /TAB
	45	/LINE FEED
        13        /VERTICAL TAB
        14      /FORM FEED
        15       /CARRIAGE RETURN
	.BLOCK	22
	100	/SPACE
        132      /!
	177	/"
	173	/#
	133	/$
	154	/%
	120	/&
	175	/'
	115	/(
	135	/)
	134	/*
	116	/+
	153	/,
	140	/-
	113	/.
	141	//
	360	/0
	361	/1
	362	/2
	363	/3
	364	/4
	365	/5
	366	/6
	367	/7
	370	/8
	371	/9
	172	/:
	136	/;
	114	/<
	176	/=
	156	/>
	157	/?
        174     /AMPERSAND
	301	/A
	302	/B
	303	/C
	304	/D
	305	/E
	306	/F
	307	/G
	310	/H
	311	/I
	321	/J
	322	/K
	323	/L
	324	/M
	325	/N
	326	/O
	327	/P
	330	/Q
	331	/R
	342	/S
	343	/T
	344	/U
	345	/V
	346	/W
	347	/X
	350	/Y
	351	/Z
	115	/[
	0
	135	/]
	0
	0
BUF	.BLOCK	500
	.END	MTWRA9
