	.TITLE	WRITE 7 TRACK ASCII TO 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 # 10
/
/  COPYRIGHT 1971,1972  DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ MAGTAPE I/O HANDLER TASK         25 OCT 1972    R. MCLEAN
/
/ MTWRA7 WRITES 7 TRACK MAGTAPE BCD RECORDS IN MODES 2 AND 3
/
/
/
/
	.GLOBL	MTWRA7,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 7 TRACK BCD
MTWRA7	0
	DZM	CNTA	/CLEAR THE WORD COUNT
	LAW	-3	/SET UP CHARACTER COUNT
	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	(MTWRA7) /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 THE ADDRESS
        DAC*    (R3)    /SET UP FOR VALIDATE AND ADJUST
	LAC*	MTNODE
	DAC*	(R2)
        CLA!IAC         /1 WORD VALIDATION
	DAC*	(R4)
	PXA		/SAVE XR
	DAC	TMP
        JMS*    (VAJX)  /VALIDATE AND ADJUST
	JMP	ERM30	/PROTECT VIOLATION
	LAC*	(R3)	/BUFFER ADDRESS
	IAC
	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		/FIND WORD COUNT
        DAC*    (R4)    /SET UP TO VALIDATE AND ADJUST
	LAC	TEMP
	DAC*	(R3)
        JMS*    (VAJX)  /VALIDATE AND ADJUST
	JMP	ERM30
	LAC	TMP	/RESTORE XR
	PAX
	DZM	TEMP    /CLEAR PACKING AC FOR CONV SUBR.
	LAC	7,X	/PICK UP THE MODE OF THE REQUEST
	SAD	(3)	/IS IT IMAGE
	JMP	IMAG	/YES DECODE IT
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 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 PAIR COUNT EXHAUSTED?
	JMP	CONVAN	/NO -- GO DO THE NEXT WORD PAIR
FINIMG  CLQ             /YES LEFT JUSTIFY THE FINAL WORD
        LAC     COUNT   /IS THE COUNT 3 INDICATING 'TEMP' EMPTY?
	SAD	(-3)
	JMP	FIN	/YES GO TRANSFER THE BUFFER TO TAPE
	LAC	(202000)	/***** FILL WITH SPACES AT THE END************
	LMQ		/*****TO PREVENT EVEN PARITY ZEROES*******************
	LAC	TEMP	
	AAC	20	/*****PUT A SPACE IN THE LOW_ORDER POSITION ********
	CLL!SKP	/DON'T DO FIRST JUSTIFY
	LLS	6	/*****BRING IN SPACES
	ISZ	COUNT	/FINISHED YET?
	JMP	.-2	/NO -- NEXT TRY WILL GET IT
	SAD	(202020)	/NOTHING BUT SPACES?
	JMP	FIN	/YES DON'T UPDATE COUNT
        DAC*    X13     /STORE THE LAST WORD
	ISZ	CNTA	/UPDATE THE COUNT OF WORDS TO BE WRITTEN
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) /MASK OFF THE UNIT NUMBER
	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 DENSITY IS 800 BPI
	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 TRY AGAIN
	JMP	FINIMG	/YES -- STORE LAST CHARACTERS
/
/     CONV -- CONV CONVERTS 5/7 BIT ASCII
/		TO BCD
/
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	/BACK ARROW?
	JMP	BARR	/YES -- INSERT A BACK ARROW
	SAD	(13	/VERTICAL TAB?
	JMP*	CONV	/YES -- ILLEGAL CHARACTER
        AAC     -11     /FIRST 11 CHARACTERS ARE FULL
	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 BCD CHARACTER
	SNA!CLL		/IS IT A NULL CHARACTER?
	JMP*	CONV	/YES -- IGNORE IT
CONVR	XOR	TEMP	/NO -- OR IN LAST CONTENTS
	ISZ	COUNT	/3 CHARACTERS FOUND?
	JMP	CONVS	/NO SET UP FOR NEXT TIME
	DAC*	X13	/YES -- STORE 3 CHARACTERS
	DZM	TEMP	/CLEAR TEMPORARY STORAGE
	LAW	-3	/RESET COUNTER
	DAC	COUNT
	ISZ	CNTA	/UPDATE TAPE WORD COUNT
	JMP*	CONV	/RETURN TO CALLER
CONVS	ALSS	6	/MOVE OVER 6 BITS FOR NEXT TIME
	DAC	TEMP	/SAVE VALUE
	JMP*	CONV	/RETURN TO CALLER
RO	LAC	(36
	JMP	CONVR
AM	LAC	(77
	JMP	CONVR
BARR	LAC	(17
	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	/PROTECT VIOLATION
	JMP*	FLSREQ
TEMP	0
CNTA	0
TMP	0
COUNT	0
WDCNT	0
TBL	35	/TAB
	37	/LINE FEED
	17	/BACK ARROW
	57	/FORM FEED
        32      /CARRIAGE RETURN
	.REPT	22
	0
	20	/SPACE
	52	/!
	14	/"
	13	/#
	53	/$
	34	/%
	60	/&
	14	/'
	34	/(
	74	/)
	54	/*
	60	/+
	33	/,
	40	/-
	73	/.
	21	//
	12	/0
	01	/1
	02	/2
	03	/3
	04	/4
	05	/5
	06	/6
	07	/7
	10	/8
	11	/9
	15	/:
	56	/;
	76	/<
	13	/=
	16	/>
	72	/?
	0	/NULL
	61	/A
	62	/B
	63	/C
	64	/D
	65	/E
	66	/F
	67	/G
	70	/H
	71	/I
	41	/J
	42	/K
	43	/L
	44	/M
	45	/N
	46	/O
	47	/P
	50	/Q
	51	/R
	22	/S
	23	/T
	24	/U
	25	/V
	26	/W
	27	/X
	30	/Y
	31	/Z
	75	/[
	00
	55	/]
BUF	.BLOCK	323
	.END	MTWRA7
