Google
 

Trailing-Edge - PDP-10 Archives - decus_20tap5_198111 - decus/20-0138/tapout.mac
There are 2 other files named tapout.mac in the archive. Click here to see a list.
	TITLE	TAPOUT
	SUBTTL	MAGTAPE TRANSLATION AND BLOCKING PROGRAM

COMMENT @

Written by:

Paul Alciere
U. S. Department of Transportation
Transportation Systems Center
Kendall Square
Cambridge, Massachusetts 02142
U. S. A.

with acknowledgement for many suggestions and good ideas from Henrik Lind
of Kentron International, Inc.
@

	SEARCH	MACTEN,UUOSYM
	SALL
	TWOSEG

VMAJOR==1
VMINOR==3
VEDIT==12
VWHO==0
.JBVER==137

LOC .JBVER
BYTE (3)VWHO(9)VMAJOR(6)VMINOR(18)VEDIT
	SUBTTL	REVISION HISTORY

;001	THE FIRST ATTEMPT

;VERSION 1A

;002	ADD IMAGE BINARY, SIXBIT SUPPORT
;003	ADD OPTIONS TO PUT CARRIAGE RETURN, LINE FEED INTO OUTPUT STREAM,
;	SET 8TH BIT OF 8-BIT ASCII TO EITHER 1 OR 0.
;004	Type "[Copying.]" to reassure the user.
;005	FIX SOME BUGS

;VERSION 1B

;006	ASK "HOW MANY FILES?" IF INPUT IS MAGTAPE. ALSO, ASSUME SAME
;	INPUT AFTER "MORE? Y".
;007	REPORT INFORMATION CONCERNING OUTPUT MAGTAPE
;	ALSO FIX BUG IN ERROR COUNT REPORTING

;VERSION 1C

;010	Support Systems Concepts, Inc. SA-10 MAGtape controller.
;011	WRITE PROPER SIXBIT TAPE LABELS
;012	WRITE PDP-11 RSX-11 FILES-11 LABELED TAPES
	SUBTTL	ACCUMULATORS, ETC.

RELOC 400000

PDLSIZ=20	;PUSHDOWN LIST SIZE


;AC'S:

	DEFINE	AC($A),<
	ZZ==ZZ+1
	$A==ZZ>
	ZZ==-1

AC(SW)		;SWITCH REGISTER
AC(T1)		;TEMPORARY AC'S:
AC(T2)
AC(REC)		;COUNTS CHARACTERS/RECORD FOR BLOCKING
AC(BLK)		;COUNTS RECORDS/BLOCK FOR BLOCKING
AC(LEFT)	;2 CONSECUTIVE AC'S USED FOR MULTIPLYING, DIVIDING
AC(RIGHT)	;2 CONSECUTIVE AC'S USED FOR MULTIPLYING, DIVIDING
AC(PNT)		;HOLDS A BYTE POINTER FOR CERTAIN SUBROUTINES
AC(BP)		;BYTE POINTER FOR TAPE OUTPUT BUFFER
AC(CH)		;HOLDS ONE CHARACTER
AC(SP)		;HOLDS A SPACE IN OUTPUT CODE
AC(CR)		;HOLDS A CARRIAGE RETURN
AC(LF)		;HOLDS A LINE FEED
AC(BITS)	;HOLDS STATUS BITS
AC(INST)	;HOLDS INSTRUCTION FOR XCT
AC(P)		;PUSH-DOWN LIST POINTER

;BITS IN SWITCH REGISTER:

MAG==1		;OUTPUT DEVICE IS A MAGTAPE
MAG7==2		;OUTPUT DEVICE IS A 7-TRACK MAGTAPE
CRLF==4		;CARRIAGE RETURN, LINE FEED IN ASCII OUTPUT
SIX==10		;SIXBIT OUTPUT
FILL==20	;FILLING LAST BUFFER FOR SIXBIT OUTPUT
SA10==40	;SA-10 CONTROLLER, 7-TRACK, EVEN PARITY
RSX11==100	;RSX-11 FILES-11 OUTPUT


;CHANNELS:

TTY==1
INN==2
OUT==3

;MACROS:

	DEFINE	TESTAT(B,M)<
	TRNE	BITS,B			;;TEST BIT
	OUTSTR	M			;;TYPE OUT MESSAGE>
	SUBTTL	COMBINED ASCII TO BCD/EBCDIC LOOKUP TABLE

;LEFT HALFWORD CONTAINS BCD EQUIVALENT OF ASCII CHARACTER
;RIGHT HALFWORD OF EVERY WORD CONTAINS ASCII EQUIVALENT OF EBCDIC CHARACTER
;ILLEGAL CHARACTERS TRANSLATE TO ASTERISK (*).

TABLE:	REPEAT 40,<XWD 54,134>	;ALL CONTROL CHARACTERS GO TO *
	XWD	20,100	;SPACE
	XWD	77,132	;! (BCD %)
	XWD	35,177	;"
	XWD	36,173	;#
	XWD	53,133	;$
	XWD	37,154	;_
	XWD	57,120	;@
	XWD	14,175	;'
	XWD	34,115	;(
	XWD	74,135	;)
	XWD	54,134	;*
	XWD	60,116	;+
	XWD	33,153	;;
	XWD	40,140	;-
	XWD	73,113	;.
	XWD	21,141	;/
	XWD	12,360	;0
	XWD	1,361	;1
	XWD	2,362	;2
	XWD	3,363	;3
	XWD	4,364	;4
	XWD	5,365	;5
	XWD	6,366	;6
	XWD	7,367	;7
	XWD	10,370	;8
	XWD	11,371	;9
	XWD	52,172	;: (BCD -0)
	XWD	32,136	;; (BCD ?)
	XWD	76,114	;<
	XWD	13,176	;=
	XWD	56,156	;> (BCD ;)
	XWD	72,157	;? (BCD +0)
	XWD	14,174	;@
	XWD	61,301	;A
	XWD	62,302	;B
	XWD	63,303	;C
	XWD	64,304	;D
	XWD	65,305	;E
	XWD	66,306	;F
	XWD	67,307	;G
	XWD	70,310	;H
	XWD	71,311	;I
	XWD	41,321	;J
	XWD	42,322	;K
	XWD	43,323	;L
	XWD	44,324	;M
	XWD	45,325	;N
	XWD	46,326	;O
	XWD	47,327	;P
	XWD	50,330	;Q
	XWD	51,331	;R
	XWD	22,342	;S
	XWD	23,343	;T
	XWD	24,344	;U
	XWD	25,345	;V
	XWD	26,346	;W
	XWD	27,347	;X
	XWD	30,350	;Y
	XWD	31,351	;Z
	XWD	55,115	;[ (BCD ])
	XWD	17,141	;\ (BCD ")
	XWD	52,135	;] (BCD -0)
	XWD	15,137	;^ (BCD :)
	XWD	12,155	;_ (BCD 0)
	XWD	14,175	;' (BCD ')
	XWD	61,201	;a
	XWD	62,202	;b
	XWD	63,203	;c
	XWD	64,204	;d
	XWD	65,205	;e
	XWD	66,206	;f
	XWD	67,207	;g
	XWD	70,210	;h
	XWD	71,211	;i
	XWD	41,221	;j
	XWD	42,222	;k
	XWD	43,223	;l
	XWD	44,224	;m
	XWD	45,225	;n
	XWD	46,226	;o
	XWD	47,227	;p
	XWD	50,230	;q
	XWD	51,231	;r
	XWD	22,242	;s
	XWD	23,243	;t
	XWD	24,244	;u
	XWD	25,245	;v
	XWD	26,246	;w
	XWD	27,247	;x
	XWD	30,250	;y
	XWD	31,251	;z
	XWD	34,134	;{
	XWD	77,117	;|
	XWD	74,134	;}
	XWD	54,134	;~
	XWD	54,134	;rubout
	SUBTTL	MODE SWITCHES

	LALL

	DEFINE	MODES(CHARS)<
TABLE3:	IRPC CHARS,<	EXP "CHARS">
TBLLEN==.-TABLE3

TABLE4:	IRPC CHARS,<	EXP WAS'CHARS>>

	MODES (ABEIRS)
	SUBTTL	INITIALIZATION:

START:	JFCL
	RESET
	MOVEI	T1,EOF
	MOVEM	T1,.JBREN		;SET UP REENTRY ADDRESS FOR HUNG DEVICE
	MOVE	P,[XWD -PDLSIZ,STACK]
	SETZB	SW,RECNO#
	SETZM	LOWZRO			;ZERO BUFFERS, ETC.
	MOVE	T1,[XWD LOWZRO,LOWZRO+1]
	BLT	T1,LOWTOP
	AOS	VOL			;START VOLUME NUMBERS AT 1
	SKIPE	T1,SVJBFF#		;RESTORE .JBFF FOR RESTART
	MOVEM	T1,.JBFF##
	MOVE	T1,.JBFF
	MOVEM	T1,SVJBFF
	OPEN	TTY,TTYBLK
	  HALT

;SET UP LOGICAL NAME OF OUTPUT MAGTAPE

ASKOUT:	OUTSTR	[ASCIZ"
Output device:	"]
	INPUT	TTY,			;READ NAME OF MAGTAPE
	MOVE	PNT,[POINT 6,OUTBLK+1]
	PUSHJ	P,SIXIN
	MOVE	T1,OUTBLK+1
	MOVEM	T1,LOC			;SET UP DEVICE NAME FOR MTCHR.
	DEVCHR	T1,
	TLNN	T1,(DV.MTA)		;TEST FOR MAGTAPE
	JRST	NOTMTA			;NOT A MAGTAPE

;OPEN OUTPUT MAGTAPE

OPNOUT:	MOVEI	T1,.IODMP
	MOVEM	T1,OUTBLK
	OPEN	OUT,OUTBLK
	  JRST	[OUTSTR	[ASCIZ/
?Cannot open a device by that name./]
		JRST	ASKOUT]

;REPORT OUTPUT MAGTAPE INFO

	OUTSTR	[ASCIZ/[Output MAGtape /]
	MOVE	T1,[XWD 12,LOC]		;GET OUTPUT TAPE CHARACTERISTICS
	MTCHR.	T1,
	  HALT
	TRZE	T1,MT.7TR		;TEST FOR 7-TRACK
	TRO	SW,MAG7			;SET PERMANENT FLAG
	TRNE	SW,MAG7			;TEST AGAIN
	OUTSTR	[ASCIZ/7-track, /]
	TRZE	T1,MT.WLK		;TEST FOR WRITE-LOCK
	OUTSTR	[ASCIZ/write-locked, /]
	ANDI	T1,7			;TEST DENSITY
	OUTSTR	[ASCIZ/density: /]
	MOVE	LEFT,[DEC 0,200,556,800,1600,6250](T1);LOOK UP DENSITY
	PUSHJ	P,DECOUT
	OUTSTR	[ASCIZ/, reel ID: /]
	MOVE	T1,LOC+1		;REEL ID
	MOVEM	T1,VOLNAM		;SAVE FOR RSX-11TAPE LABELS
	PUSHJ	P,SIXOUT
	OUTSTR	[ASCIZ/]
/]

	MOVE	T1,LOC+.MTSWE		;SAVE INITIAL ERROR COUNTS
	MOVEM	T1,OLDSWE
	MOVE	T1,LOC+.MTHWE
	MOVEM	T1,OLDHWE#
	TRNE	SW,MAG7			;SKIP IF 9-TRACK
	JRST	ASK7			;IT WAS 7-TRACK
	MTIND.	OUT,			;IT WAS 9-TRACK. SET INDUSTRY-COMPATIBLE MODE
	JRST	ASKCOD			;ASK WHAT TRANSLATION CODE TO USE

;ASK 7-TRACK QUESTIONS

ASK7:	OUTSTR	[ASCIZ"Parity:		"]
	MOVEI	T1,.IODMP
	PUSHJ	P,TTYIN			;PICK UP O/E
	CAIL	CH,140			;TEST FOR UPPER CASE
	SUBI	CH,40			;IF SO, CONVERT TO LOWER CASE
	CAIE	CH,"E"
	JRST	ASKCOD			;ODD PARITY
	IORI	T1,IO.PAR		;SET EVEN PARITY BIT IF "E"
	SETSTS	OUT,(T1)		;MODIFY STATUS BITS OF OPENED OUTPUT FILE
	MOVE	T1,[XWD 2,[EXP .TFKTP,OUT]];TEST KONTROLLER TYPE
	TAPOP.	T1,
	  HALT
	CAIE	T1,7			;SA-10?
	JRST	ASKCOD			;NO
	TRO	SW,SA10			;YES
	MOVE	T1,[XWD 3,[EXP .TFMOD+1000,OUT,.TFM8B]]
	TAPOP.	T1,			;SET INDUSTRY-COMPATIBLE MODE
	  HALT

;ASK WHICH CODE TO USE:

ASKCOD: OUTSTR	[ASCIZ/Code:		/]
	PUSHJ	P,TTYIN			;GET A/B/E/I/N/R/S/V/11
	MOVSI	T1,-TBLLEN
LOOP:	CAMN	CH,TABLE3(T1)
	JRST	@TABLE4(T1)
	AOBJN	T1,LOOP
	JRST	ASKCOD

WASA:	TRNE	SW,MAG7			;8-BIT ASCII
	JRST	[OUTSTR	[ASCIZ/
? This program does not support 8-bit ASCII output to 7-track tape.
/]
		EXIT]
	MOVEI	SP," "
	MOVEI	CR,15
	MOVEI	LF,12
	MOVSI	INST,(JFCL)		;SET UP NO-OP FOR XCT INSTRUCTION
	TRNE	SW,RSX11
	JRST	NOTONE
	OUTSTR	[ASCIZ/Bit 8=1 or 0?	/]
	PUSHJ	P,DECIN
	JUMPE	T1,NOTONE
	TRO	SP,200
	TRO	CR,200
	TRO	LF,200
NOTONE:	MOVE	INST,[TRO CH,200]	;SET UP XCT INSTRUCTION
	MOVSI	BP,(POINT 8)		;SET UP OUTPUT BYTE SIZE
	HLLM	BP,LBLPNT		;MAKE BYTE POINTER TO LABEL AREA
	MOVEI	T1,4
	MOVEM	T1,BPERW#		;SET UP BYTES-PER-WORD
	TRNE	SW,RSX11
	JRST	ASKIN
	OUTSTR	[ASCIZ/CRLF in output?	/]
	PUSHJ	P,TTYIN
	CAIN	CH,"Y"
	TRO	SW,CRLF
	JRST	ASKLEN

WASB:	MOVEI	SP,20			;BCD
	MOVEI	T1,6
	TRNE	SW,SA10			;SPECIAL SA-10 CASE
	MOVEI	T1,4			;4 BYTES PER WORD
	MOVEM	T1,BPERW
	MOVSI	BP,(POINT 6)
	TRNE	SW,SA10			;SPECIAL SA-10 CASE
	MOVSI	BP,(POINT 8)		;8-BIT BYTE
	MOVE	INST,[HLRZ CH,TABLE(CH)]
	TRNN	SW,MAG7
	OUTSTR	[ASCIZ/
% BCD is unusual on a 9-track tape.
/]
	JRST	ASKLEN

WASE:	MOVEI	SP,100			;EBCDIC
	MOVSI	BP,(POINT 8)
	MOVE	INST,[HRRZ CH,TABLE(CH)]
	MOVEI	T1,4
	MOVEM	T1,BPERW
	TRNE	SW,MAG7
	JRST	[OUTSTR	[ASCIZ/
? This program does not support 7-track EBCDIC.
/]
		EXIT]
	JRST	ASKLEN

WASI:	MOVEI	T1,.IOIBN		;IMAGE BINARY MODE
	MOVEM	T1,INNBLK
	MOVSI	BP,(POINT 36)
	JRST	ASKLEN

WASR:	MTREW.	OUT,			;REWIND AND WRITE VOLUME LABEL
	MOVSI	T1,-^D20
	HLLM	T1,LBLCHN		;SET UP LABEL CHANNEL COMMAND
	TRO	SW,RSX11		;SET RSX-11 FLAG
	JRST	WASA			;OTHERWISE LIKE ASCII

WASS:	MOVEI	SP,' '			;SIXBIT
	TRO	SW,SIX
	MOVSI	T1,-^D13
	HLLM	T1,LBLCHN		;SET UP LABEL CHANNEL COMMAND
	MOVEI	T1,6
	MOVEM	T1,BPERW
	MOVSI	BP,(POINT 6)
	HLLM	BP,LBLPNT		;MAKE BYTE POINTER TO LABEL AREA
	MOVE	INST,[PUSHJ P,SIXCNV]
	MTDEC.	OUT,			;DEC-COMPATIBLE MODE

;ASK LOGICAL RECORD LENGTH:

ASKLEN:	OUTSTR	[ASCIZ/Record length:	/]
	PUSHJ	P,DECIN			;INPUT A DECIMAL NUMBER
	MOVEM	T1,RECLEN#
	OUTSTR	[ASCIZ/Blocking:	/]
	PUSHJ	P,DECIN
	SKIPG	T1
	MOVEI	T1,1			;DEFAULT TO 1
	MOVEM	T1,BLKFAC#

;ASK INPUT QUESTIONS

ASKIN:	OUTSTR	[ASCIZ/Input device:	/]
	INPUT	TTY,
	MOVE	PNT,[POINT 6,INNBLK+1]
	PUSHJ	P,SIXIN
	MOVE	T1,INNBLK+1		;GET NAME OF OUTPUT DEVICE
	DEVCHR	T1,			;GET ITS CHARACTERISTICS
	TLNN	T1,(DV.MTA)		;IS IT A MAGTAPE?
	JRST	OPNINN
	TRO	SW,MAG			;YES.  SET FLAG

;OPEN INPUT DEVICE

OPNINN:	OPEN	INN,INNBLK
	JRST	[OUTSTR	[ASCIZ/
?Cannot	open a device by that name.
/]
		JRST	ASKIN]
	INBUF	INN,
	MOVEI	T1,INN
	DEVTYP	T1,			;GET DEVICE TYPE
	  HALT
	TRNN	T1,.TYMTA		;MAGTAPE?
	JRST	MORE			;NO

;REPORT INPUT MAGTAPE INFO

	MOVE	T1,[XWD INNBLK,DVSZBL]	;MOVE INPUT OPEN BLOCK INFO
	BLT	T1,DVSZBL+1		;TO DEVSIZ BLOCK
	MOVEI	LEFT,DVSZBL
	DEVSIZ	LEFT,			;GET BLOCKSIZE
	  HALT
	OUTSTR	[ASCIZ/[Input blocksize: /]
	HRRZS	LEFT			;BLOCKSIZE IS IN RIGHT HALFWORD
	SUBI	LEFT,3			;3 EXTRA WORDS DON'T COUNT
	PUSHJ	P,DECOUT		;TYPE IT OUT
	MOVE	T1,INNBLK+1		;GET DEVICE NAME
	MOVEM	T1,LOC			;FOR MTCHR
	MOVE	T1,[XWD 12,LOC]		;GET INPUT TAPE CHARACTERISTICS
	MTCHR.	T1,
	  HALT
	TRZE	T1,MT.7TR		;TEST FOR 7-TRACK
	OUTSTR	[ASCIZ/, 7-track /]
	TRZE	T1,MT.WLK		;TEST FOR WRITE-LOCK
	OUTSTR	[ASCIZ/, write-locked /]
	ANDI	T1,7			;TEST DENSITY
	OUTSTR	[ASCIZ/, density: /]
	MOVE	LEFT,[DEC 0,200,556,800,1600,6250](T1);LOOK UP DENSITY
	PUSHJ	P,DECOUT
	OUTSTR	[ASCIZ/, reel ID: /]
	MOVE	T1,LOC+1		;REEL ID
	PUSHJ	P,SIXOUT
	OUTSTR	[ASCIZ/]
/]
	OUTSTR	[ASCIZ/How many files? /]
	PUSHJ	P,DECIN
	MOVEM	T1,FILES#
	JRST	MORMAG

MORE:	MOVEI	T1,INN			;TEST WHETHER DIRECTORY DEVICE
	DEVCHR	T1,
	TLNN	T1,(DV.DIR)		;SKIP IF DIRECTORY DEVICE
	JRST	MORMAG			;ELSE JUMP

;ASK FILENAME.EXT IF DIRECTORY DEVICE

ASKFIL:	OUTSTR	[ASCIZ/Filename.ext:	/]
	INPUT	TTY,
	MOVE	PNT,[POINT 6,INNAM]
	PUSHJ	P,SIXIN
	MOVE	PNT,[POINT 6,INNAM+1]
	PUSHJ	P,SIXIN
	SETZM	INNAM+2
	SETZM	INNAM+3
	LOOKUP	INN,INNAM
	  JRST	[OUTSTR	[ASCIZ/? Cannot find a file by that name.
/]
		JRST	ASKFIL]
	TRNN	SW,RSX11		;RSX-11?
	JRST	ASKFL1			;NO
	LDB	T1,[POINT 4,INNAM+2,12]	;YES. TEST FILE MODE
	CAILE	T1,1			;ASCII/ASCII LINE MODE?
	OUTSTR	[ASCIZ/
% Not an ASCII file!
/]
ASKFL1:	TRNE	SW,SIX			;SIXBIT?
	PUSHJ	P,HDR1			;WRITE HDR1 FILE LABEL


MORMAG:	HRR	BP,.JBFF
	MOVEM	BP,BPXX#
	MOVN	REC,RECLEN
	HRLZS	REC
	MOVEM	REC,AOBCTR#		;BYTE PER RECORD COUNTER
	MOVE	BLK,BLKFAC
	MOVE	T1,RECLEN

;COMPUTE BLOCK LENGTH

	TRNN	SW,SIX			;SIXBIT OUTPUT?
	JRST	BL1			;NO
	IDIVI	T1,6			;YES. DIVIDE BY 6
	SKIPE	T2			;IS THERE A REMAINDER?
	AOS	T1			;YES. ROUND UP
	AOS	T1			;ADD ONE FOR FLAG WORD
	IMUL	T1,BLK			;MULTIPLY BY BLOCKING FACTOR
	JRST	BL2			;REJOIN COMMON PATH

BL1:	TRNE	SW,CRLF			;CRLF?
	ADDI	T1,2			;ADD 2 FOR THEM
	IMUL	T1,BLK
	IDIV	T1,BPERW
	SKIPE	T2			;IF THERE IS A REMAINDER
	AOS	T1			;ROUND UP
BL2:	TRNE	SW,RSX11
	MOVEI	T1,200			;FIXED BLOCK SIZE FOR RSX-11
	MOVEM	T1,BLKLEN#
	TRNE	SW,RSX11
	MOVEI	T1,400
	ADD	T1,.JBFF
	CAMLE	T1,.JBREL##		;SEE IF WE HAVE CORE FOR OUTPUT BLOCK
	PUSHJ	P,GETCOR		;NO. GET IT.
	MOVN	T1,BLKLEN		;MAKE I/O LIST
	HRLZS	T1
	HRR	T1,.JBFF
	SOJ	T1,
	MOVEM	T1,IOLIST
	AOJ	T1,			;COMPUTE ADDRESSES FOR BLT
	HRLS	T1
	AOJ	T1,
	MOVEM	T1,BLTADR#		;BLT ADDRESS FOR CLEARING BUFFER
	HLRZS	T1
	ADD	T1,BLKLEN
	SOJ	T1,
	MOVEM	T1,BLTEND#		;ENDING ADDRESS FOR BLT
	SETZM	@.JBFF			;CLEAR BUFFER
	MOVE	T1,BLTADR
	BLT	T1,@BLTEND
	OUTSTR	[ASCIZ/
[Copying.]

/]
	SUBTTL	PROCESS

	TRNE	SW,RSX11		;RSX-11?
	JRST	RSX			;YES. SPECIAL PROCESS CODE
	MOVE	T1,INNBLK
	CAIN	T1,.IOIBN		;TEST FOR IMAGE BINARY MODE
	JRST	COPY			;USES SIMPLER PROCESS LOOP

NEWREC:	TRNN	SW,SIX			;IF SIXBIT OUTPUT,
	JRST	PROCESS
	HRRZ	T1,RECLEN		;MAKE FLAG WORD
	HRL	T1,RECS
	MOVEM	T1,(BP)			;AND STORE IN BUFFER
	AOS	BP
	TRNN	SW,FILL
	JRST	PROCESS
FILLUP:	IDPB	SP,BP			;FILL LAST SIXBIT BUFFER WITH SPACES
	AOBJN	REC,FILLUP
	JRST	ENDLIN

PROCESS:SOSG	IBUF+2			;CHECK BUFFER COUNTER
	PUSHJ	P,GETBUF		;BUFFER FULL. OUTPUT AND START NEXT ONE
	ILDB	CH,IBUF+1		;PICK UP AN ASCII CHARACTER
	JUMPE	CH,PROCESS		;IGNORE NULLS
	CAIGE	CH,40			;TEST FOR CONTROL CHARACTER
	JRST	CTLCHR			;WAS ONE
EXECUTE:XCT	INST			;DO CHARACTER TRANSLATION
	IDPB	CH,BP			;PUT TRANSLATED BYTE IN OUTPUT BUFFER
	AOBJN	REC,PROCESS		;COUNT BYTES PER LOGICAL RECORD
GOBBLE:	SOSGE	IBUF+2			;GOBBLE SUPERFLUOUS CHARACTERS
	PUSHJ	P,GETBUF
	ILDB	CH,IBUF+1
	CAIG	CH,14			;TILL YOU GET LF/VT/FF
	CAIGE	CH,12
	JRST	GOBBLE
ENDLIN:	TRNN	SW,SIX			;SIXBIT?
	JRST	EL1			;NO
	AOS	BP			;YES. ADJUST BYTE POINTER
	HRLI	BP,(POINT 6)
EL1:	TRNN	SW,CRLF			;CRLF WANTED?
	JRST	NOCRLF
	IDPB	CR,BP			;INSERT CARRIAGE RETURN
	IDPB	LF,BP			;INSERT LINE FEED
NOCRLF:	AOS	RECS			;END OF LOGICAL RECORD
	MOVE	REC,AOBCTR
	SOJG	BLK,NEWREC		;COUNT LOGICAL RECORDS PER BLOCK
	MOVE	BLK,BLKFAC
	PUSHJ	P,WRITE			;WRITE OUT THE BLOCK
	TRZE	SW,FILL			;FILLING LAST SIXBIT BUFFER?
	JRST	EOF			;YES. EOF.
	JRST	NEWREC			;NO. CONTINUE

GETBUF:	INPUT	INN,			;GET A BUFFER FROM MONITOR
	STATO	INN,IO.EOF		;TEST FOR END OF FILE
	POPJ	P,			;NOT YET
	POP	P,T1			;FORGET WHERE YOU CAME FROM
	TRNE	SW,RSX11		;RSX-11?
	JRST	RSXEOF			;SPECIAL EOF CODE
	TRNN	SW,SIX			;SIXBIT?
	JRST	GB1			;NO
	CAMN	BLK,BLKFAC		;YES. WAS A BUFFER IN PROGRESS?
	JRST	EOF			;NO. WE ARE FINISHED.
	TRO	SW,FILL			;YES. FINISH FILLING IT WITH SPACES.
	JRST	LFVTFF			;GO BACK AND FILL LAST BUFFER

GB1:	HRRZ	T1,.JBFF
	HRRZ	T2,BP
	SUB	T1,T2
	SOS	T1
	HRLM	T1,IOLIST
	CAME	BP,BPXX			;DON'T OUTPUT IF LENGTH = 0
	PUSHJ	P,WRITE			;DON'T FORGET THE LAST OUTPUT BUFFER
	JRST	EOF			;GO REPORT ERRORS

CTLCHR:	CAIN	CH,15			;TEST FOR CARRIAGE RETURN
	JRST	PROCESS			;IGNORE CARRIAGE RETURN
	CAIN	CH,11			;TEST FOR HORIZONTAL TAB
	JRST	TABOUT
	CAIG	CH,14			;TEST FOR LF/VT/FF
	CAIGE	CH,12
	JRST	EXECUTE			;ALL OTHER CTL CHARS BECOME *
LFVTFF:	IDPB	SP,BP			;FILL OUT LOGICAL REC WITH SPACES
	AOBJN	REC,.-1
	JRST	ENDLIN

TABOUT:	IDPB	SP,BP			;TAB OUT TO NEXT COL THAT IS MULTIPLE OF 8
	AOBJP	REC,ENDLIN		;UNLESS YOU GET TO END OF LINE FIRST
	TRNE	REC,7			;MULTIPLE OF 8 HAS 0 IN LAST 3 BITS
	JRST	TABOUT			;NOT THERE YET
	JRST	PROCESS

;RSX-11 PROCESS CODE

RSX:	PUSHJ	P,VOL1			;OUTPUT THE VOLUME LABEL
RSXFIL:	PUSHJ	P,HDR1			;WRITE HDR1 LABEL
RSXFUL:	MOVE	BP,BPXX			;SET UP NEW OUTPUT BUFFER
	MOVEI	BLK,^D512		;COUNT BYTES/BUFFER
RSXREC:	MOVEM	BP,PNT			;HERE FOR NEW LOGICAL RECORD
	AOJ	BP,			;ADVANCE BYTE POINTER BY ONE WORD
	MOVEI	LEFT,4			;COUNT BYTES/REC, INCLUDING COUNT
	SUBI	BLK,4			;MAKE SURE THERE IS ROOM FOR BYTE COUNT
	JUMPLE	RSXOUT			;OOPS, NO.
RSXCHR:	SOSG	IBUF+2			;CHECK BUFFER COUNTER
	PUSHJ	P,GETBUF		;BUFFER DEPLETED. READ IN ANOTHER ONE
	ILDB	CH,IBUF+1		;PICK UP AN ASCII CHARACTER
	CAIGE	CH,40			;CONTROL CHARACTER?
	JRST	RSXCTL			;YES.
RSXOK:	IDPB	CH,BP			;CHARACTER IS OK TO OUTPUT
	AOJ	LEFT,			;COUNT IT
	SOJG	BLK,RSXCHR		;TEST FOR FULL OUTPUT BUFFER

;HERE WHEN THE BUFFER IS FULL

RSXOUT:	MOVEI	BITS,"^"
	MOVE	BP,BPXX
	ADDI	BP,200			;SET BP TO ADDRESS OF SECOND BUFFER
	CAIL	LEFT,1000	;TEST FOR LOGICAL RECORD LONGER THAN BUFFER
	JRST	RSXBIG		;BREAK IT OFF IF IT IS
	MOVEI	T1,4
	IDPB	BITS,PNT		;STORE "^" OVER BYTE POINTER
	SOJG	T1,.-1

	CAIG	LEFT,4			;TEST FOR BLANK LINE
	JRST	RSXBL			;INSERT ONE SPACE
	MOVEI	T1,-4(LEFT)
RSXOU1:	ILDB	CH,PNT			;SAVE PARTIAL RECORD
	DPB	BITS,PNT		;REPLACING IT WITH "^"
	IDPB	CH,BP
	SOJG	T1,RSXOU1

	PUSHJ	P,WRITE			;WRITE OUT THE BUFFER

	MOVE	BP,BPXX			;MOVE PARTIAL RECORD BACK INTO BUFFER
	MOVE	PNT,BP
	AOJ	BP,
	ADDI	PNT,200

	MOVEI	T1,-4(LEFT)
	MOVEI	BLK,774
	SUB	BLK,T1
RSXOU2:	ILDB	CH,PNT
	IDPB	CH,BP
	SOJG	T1,RSXOU2

	MOVE	PNT,BPXX
	JRST	RSXCHR

RSXCTL:	JUMPE	CH,RSXCHR		;IGNORE NULLS
	CAIN	CH,15
	JRST	RSXCHR			;IGNORE CARRIAGE RETURN
	CAIG	CH,14			;TEST FOR LF/VT/FF
	CAIGE	CH,12
	JRST	RSXOK			;PASS ALL OTHER CONTROL CHARACTERS
	MOVEI	T1,4
	PUSHJ	P,DECLBL		;OUTPUT RECSIZ
	AOS	RECS			;COUNT THE RECORD
	JRST	RSXREC			;START NEW REC

RSXBL:	IDPB	SP,BP			;BLANK LINE NEEDS ONE SPACE
	MOVEI	LEFT,5
	MOVEI T1,4
	PUSHJ	P,DECLBL		;OUTPUT THE BYTE COUNT
	AOS RECS			;COUNT THE LOGICAL RECORD
	SOJLE	BLK,RSXOUT		;SEE IF THE BUFFER IS FULL
	JRST	RSXREC			;DO THE NEXT RECORD

RSXBIG:	MOVEI	T1,4			;BREAK OFF LONG RECORD
	PUSHJ	P,DECLBL
	AOS	RECS
	PUSHJ	P,WRITE
	JRST	RSXFUL

;SIMPLE COPY LOOP FOR IMAGE BINARY DATA

COPY:	SOSG	IBUF+2			;SEE IF BUFFER IS EMPTY
	PUSHJ	P,GETBUF		;IF SO, GET ANOTHER
	ILDB	CH,IBUF+1		;PICK UP A WORD OF DATA
	IDPB	CH,BP			;PUT IT INTO THE OUTPUT BUFFER
	AOBJN	REC,COPY		;COUNT WORDS/RECORD
	AOS	RECS			;COUNT RECORDS
	MOVE	REC,AOBCTR		;RESET COUNTER
	SOJG	BLK,COPY		;COUNT LOGICAL RECORDS/BLOCK
	MOVE	BLK,BLKFAC		;RESET REC/BLK COUNTER
	PUSHJ	P,WRITE
	JRST	COPY

;HERE FOR SPECIAL RSX-11 END-OF-FILE PROCESSING

RSXEOF:	MOVEI	CH,"^"			;FILL OUT BUFFER WITH "^"
	ADDI	BLK,4
	IDPB	CH,PNT
	SOJG	BLK,.-1
	PUSHJ	P,WRITE			;WRITE OUT THE LAST BUFFER

;HERE ON END-OF-FILE READING INPUT FILE

EOF:	TRNE	SW,SIX!RSX11		;SIXBIT/RSX-11?
	PUSHJ	P,EOF1			;WRITE EOF1 LABEL
	TRNE	SW,RSX11
	PUSHJ	P,EOF2
	OUTSTR	[ASCIZ/[End of file. /]
	MOVE	LEFT,RECS#
	PUSHJ	P,DECOUT
	OUTSTR	[ASCIZ/ logical records, /]
	MOVE	LEFT,BLKNO
	PUSHJ	P,DECOUT
	OUTSTR	[ASCIZ/ blocks written.]
[/]
	MOVE	T1,OUTBLK+1		;NAME OF OUTPUT DEVICE
	MOVEM	T1,LOC
	MOVE	T1,[XWD 12,LOC]
	MTCHR.	T1,
	  HALT
	MOVE	LEFT,LOC+.MTSWE		;SOFT WRITE ERRORS
	SUB	LEFT,OLDSWE#
	PUSHJ	P,DECOUT
	OUTSTR	[ASCIZ/ soft write errors, /]
	MOVE	LEFT,LOC+.MTHWE		;HARD WRITE ERRORS
	SUB	LEFT,OLDHWE
	PUSHJ	P,DECOUT
	OUTSTR	[ASCIZ/ hard write errors.]
/]
	SETZM	BLKNO
	SETZM	RECS
	CLOSE	INN,
	CLOSE	OUT,
	SOSLE	FILES			;COUNT FILES
	JRST	MORMAG			;DO ANOTHER ONE
	OUTSTR	[ASCIZ/
More? /]
	PUSHJ	P,TTYIN
	CAIN	CH,"N"
	EXIT
	JRST	MORE
	SUBTTL	SUBROUTINES

SIXCNV:	CAIL	CH,140			;CONVERT ASCII TO SIXBIT
	SUBI	CH,40
	SUBI	CH,40
	POPJ	P,

WRITE:	OUTPUT	OUT,IOLIST
	SETZM	@.JBFF			;CLEAR BUFFER AFTER WRITING
	MOVE	T1,BLTADR
	BLT	T1,@BLTEND
	MOVE	BP,BPXX			;RESET OUTPUT POINTER
	AOS	BLKNO#
	GETSTS	OUT,BITS		;GET MAGTAPE STATUS
	TRZ	BITS,IO.EOF		;SUPPRESS SPURIOUS EOF
	TRNE	BITS,IO.ERR!IO.EOT
	PUSHJ	P,MTSTAT
	TRNN	BITS,IO.EOT
	POPJ	P,

;END-OF-REEL PROCEDURE:

	MTEOF.	OUT,			;WRITE TAPE MARK
	MTUNL.	OUT,			;UNLOAD TAPE
	OUTSTR	NXTAPE			;TELL USER WHAT TO DO
	EXIT	1,			;WAIT FOR HIM (HER) TO DO IT
	AOS	VOL			;INCREMENT VOLUME NUMBER
	POPJ	P,

NXTAPE:	ASCIZ	/
Wrote EOF and unloaded.
Use SEND OPR: command to ask operator to mount next reel.
Then give CONTINUE command.
/

;INTERPRET MAGTAPE STATUS BITS

MTSTAT:	TESTAT	IO.IMP,IMPMSG
	TESTAT	IO.DER,DERMSG
	TESTAT	IO.DTE,DTEMSG
	TESTAT	IO.ACT,ACTMSG
	TESTAT	IO.BOT,BOTMSG
	TESTAT	IO.EOT,EOTMSG
	TRNN	BITS,IO.PAR	;TEST BIT
	OUTSTR	ODDMSG
	TRNE	BITS,IO.PAR
	OUTSTR	EVNMSG
	TESTAT	IO.NRC,NRCMSG

	PUSHJ	P,BLKOUT
	OUTSTR	[ASCIZ/
/]
	POPJ	P,

IMPMSG:	ASCIZ	/
[Tried to write while write-locked, or other illegal operation.]/
DERMSG:	ASCIZ	/
[Data was missed, tape is bad, or transport is hung.]/
DTEMSG:	ASCIZ	/
[Parity error.]/
ACTMSG:	ASCIZ	/
[Device was active.]/
BOTMSG:	ASCIZ	/
[Unit is at beginning of tape.]/
EOTMSG:	ASCIZ	/
[Unit is at end of tape.]/
EVNMSG:	ASCIZ	/
[Even parity is set.]/
ODDMSG:	ASCIZ	/
[Odd parity is set.]/
NRCMSG:	ASCIZ	/
[Automatic error correction is suppressed.]/

;GET A CHARACTER FROM TTY

TTYIN:	INPUT	TTY,
TTYIN1:	ILDB	CH,TINP+1		;GET THE CHARACTER
	JUMPE	CH,TTYIN1		;IGNORE NULL
	CAIN	CH," "			;TEST FOR SPACE
	JRST	TTYIN1			;IGNORE SPACE
	CAIL	CH,140			;TEST FOR LOWER CASE
	SUBI	CH,40			;CONVERT TO UPPER CASE
	POPJ	P,

;GET MORE CORE

GETCOR:	IORI	T1,777
	CORE	T1,
	  JRST	[OUTSTR	[ASCIZ/
? Could not get enough core to write tape block.
/]
		EXIT]
	OUTSTR	[ASCIZ/
[/]
	MOVE	LEFT,.JBREL
	ADDI	LEFT,1001		;ALLOW FOR WORD 0 AND UPMP
	ASH	LEFT,-^D9
	PUSHJ	P,DECOUT		;TYPE OUT LOSEG SIZE
	OUTCHR	["+"]
	MOVEI	LEFT,HITOP
	TRZ	LEFT,400000
	ASH	LEFT,-^D9
	SKIPE	RIGHT
	AOJ	LEFT,			;ROUND UP
	PUSHJ	P,DECOUT		;TYPE OUT HISEG SIZE
	OUTSTR	[ASCIZ/P Core.]
/]
	POPJ	P,

;INPUT FROM TTY AND CONVERT TO SIXBIT

SIXIN:	SETZM	(PNT)			;CLEAR DESTINATION WORD INITIALLY
	MOVEI	T2,6			;MAX. 6 CHARACTERS IN DEVICE NAME
GET:	ILDB	T1,TINP+1		;PICK UP A LETTER
	CAILE	T1,140			;TEST FOR LOWER-CASE
	SUBI	T1,40			;IF SO, CONVERT TO UPPER-CASE
	CAIN	T1,":"			;QUIT ON COLON
	POPJ	P,
	CAIN	T1,"."			;TEST FOR PERIOD
	JRST	DOT			;IGNORE PERIOD IF FIRST CHARACTER
	SUBI	T1,40			;CONVERT TO SIXBIT
	JUMPLE	T1,GOT			;QUIT ON ANY CONTROL CHARACTER OR BLANK
	IDPB	T1,PNT			;PUT SIXBIT CHARACTER INTO DEVICE NAME
SKIP:	SOJG	T2,GET			;LOOP
GOT:	POPJ	P,

DOT:	CAIL	T2,6			;SEE IF IT WAS THE FIRST CHARACTER
	JRST	SKIP			;YES. IGNORE IT
	POPJ	P,			;NO. GO HOME

;CONVERT SIXBIT TO ASCII AND OUTPUT TO TTY

SIXOUT:	MOVEI	T2,6			;COUNT 6 CHARACTERS
	MOVE	PNT,[POINT 6,T1]	;GET A BYTE POINTER
SIXX:	ILDB	CH,PNT			;PICK UP A SIXBIT CHARACTER
	ADDI	CH,40			;CONVERT TO ASCII
	OUTCHR	CH			;TYPE OUT ON THE TTY
	SOJG	T2,SIXX			;LOOP
	POPJ	P,			;RETURN

;DECIMAL TYPOUT ROUTINE FROM SYSTEM REFERENCE MANUAL:

DECOUT:	IDIVI	LEFT,^D10		;DIVIDE BY 10
	HRLM	RIGHT,(P)		;SAVE REMAINDER
	SKIPE	LEFT			;ALL DIGITS FORMED?
	PUSHJ	P,DECOUT		;NO. CALL SELF RECURSIVELY

	HLRZ	LEFT,(P)		;YES. TAKE OUT IN OPPOSITE ORDER
	ADDI	LEFT,"0"		;CONVERT TO ASCII
	OUTCHR	LEFT			;TYPE OUT ONE DIGIT
	POPJ	P,

NOTMTA:	OUTSTR	[ASCIZ/
? Not a MAGtape.
/]
	JRST	ASKOUT

;INPUT A DECIMAL NUMBER FROM THE TTY INTO AC T1

DECIN:	SETZB	T1,DIGIT#		;CLEAR NUMBER AND DIGIT FLAG
	INPUT	TTY,			;READ A LINE FROM THE TTY
DIN1:	ILDB	CH,TINP+1		;READ A CHARACTER
	CAIN	CH,15
	POPJ	P,			;QUIT ON CARRIAGE RETURN
	SUBI	CH,"0"
	JUMPL	CH,NONDIG		;CHARACTER LESS THAN "0"
	CAILE	CH,^D9
	JRST	NONDIG			;CHARACTER GREATER THAN "9"
	IMULI	T1,^D10			;MULTIPLY WHAT YOU HAVE BY 10
	ADD	T1,CH			;ADD THE NEXT DIGIT
	JRST	DIN1			;LOOK FOR MORE

NONDIG:	SKIPN	DIGIT			;HAVE WE SEEN ANY DIGITS YET?
	JRST	DIN1			;NO. KEEP LOOKING.
	POPJ	P,			;YES. NOW ANY NON-NUMERIC IS A TERMINATOR

;TYPE OUT THE CURRENT BLOCK NUMBER

BLKOUT:	OUTSTR	[ASCIZ/
[Block number /]
	MOVE	LEFT,BLKNO
	PUSHJ	P,DECOUT
	OUTSTR	[ASCIZ/]
/]
	POPJ	P,
	SUBTTL	WRITE MAGTAPE FILE LABELS

;VOL1 LABEL (RSX-11 ONLY)

VOL1:	MOVE	T1,[XWD 2,[EXP .TFSTS,OUT]];GET OUTPUT TAPE UNIT STATUS
	TAPOP.	T1,
	  HALT
	TRNN	T1,TF.BOT		;AT BEGINNING-OF-TAPE?
	POPJ	P,			;NO.  DO NOT WRITE VOL1 LABEL
	MOVE	PNT,LBLPNT		;OUTPUT BYTE POINTER
	MOVE	T1,[POINT 6,[SIXBIT/VOL1/]]
	MOVEI	T2,4
	PUSHJ	P,SIXTAP

	MOVE	T1,[POINT 6,VOLNAM]
	MOVEI	T2,6
	PUSHJ	P,SIXTAP

	MOVEI	T1,^D27
	PUSHJ	P,SPACES

	MOVE	T1,[POINT 6,[SIXBIT/D%B4444001001/]]
	MOVEI	T2,^D13
	PUSHJ	P,SIXTAP

	MOVEI	T1,^D29
	PUSHJ	P,SPACES

	MOVEI	T1,"1"
	IDPB	T1,PNT

	OUTPUT	OUT,LBLCHN
	POPJ	P,

;HDR1 LABELS (SIXBIT AND RSX-11)

HDR1:	MOVE	T1,[POINT 6,[SIXBIT/HDR1/]]
	MOVEI	T2,4
	MOVE	PNT,LBLPNT		;BYTE POINTER TO LABEL AREA
	PUSHJ	P,SIXTAP		;MOVE 4 SIXBIT CHARACTERS

	MOVE	T1,[POINT 6,INNAM]	;OUTPUT THE FILE NAME
	MOVEI	T2,6
	PUSHJ	P,SIXTAP

	MOVEI	T1,"."
	TRNE	SW,RSX11
	IDPB	T1,PNT

	MOVE	T1,[POINT 6,INNAM+1]	;OUTPUT THE EXTENSION
	MOVEI	T2,3
	PUSHJ	P,SIXTAP

	TRNE	SW,RSX11
	JRST	[MOVEI	T1,7
		PUSHJ	P,SPACES
		MOVE	T1,[POINT 6,VOLNAM]
		MOVEI	T2,6
		PUSHJ	P,SIXTAP
		JRST	HDR1A]
	MOVEI	T1,^D14			;14 SPACES
	PUSHJ	P,SPACES

HDR1A:	MOVE	LEFT,VOL		;VOLUME NUMBER
	MOVEI	T1,4
	PUSHJ	P,DECLBL

	AOS	LEFT,FILE		;FILE NUMBER
	MOVEI	T1,4
	PUSHJ	P,DECLBL

	TRNE	SW,RSX11
	JRST	[MOVE	T1,[POINT 6,[SIXBIT/000100 /]]
		MOVEI	T2,7
		PUSHJ	P,SIXTAP
		JRST	HDR1B]

	MOVEI	T1,6			;6 SPACES
	PUSHJ	P,SPACES

HDR1B:	DATE	LEFT,			;GET DATE
	IDIVI	LEFT,^D31
	AOJ	RIGHT,
	MOVEM	RIGHT,DAY#		;STORE DAY
	IDIVI	LEFT,^D12
	TRNN	SW,RSX11		;USE MONTH-1 FOR RSX-11
	AOJ	RIGHT,
	MOVEM	RIGHT,MONTH#		;STORE MONTH
	ADDI	LEFT,^D1964		;ADD BASE YEAR
	MOVEM	LEFT,YEAR#		;STORE YEAR
	MOVEI	T1,2
	PUSHJ	P,DECLBL		;OUTPUT YEAR

	TRNE	SW,RSX11
	JRST	RSXDAT

	MOVE	LEFT,MONTH		;GET MONTH
	MOVEI	T1,2
	PUSHJ	P,DECLBL		;OUTPUT MONTH
	MOVE	LEFT,DAY		;GET DAY
	MOVEI	T1,2
	PUSHJ	P,DECLBL		;OUTPUT DAY

	MOVEI	T1,^D13			;13 SPACES
	PUSHJ	P,SPACES

	MOVE	T1,[POINT 6,[SIXBIT/PDP10/]]	;SYSTEM ID
	MOVEI	T2,5
	PUSHJ	P,SIXTAP

	MOVEI	T1,^D15			;15 SPACES
	PUSHJ	P,SPACES

	OUTPUT	OUT,LBLCHN		;WRITE LABEL RECORD
	POPJ	P,

;RSX-11 DIFFERS FROM SIXBIT FROM DATE ON

RSXDAT:	MOVEI	T1,^D28
	MOVEM	T1,FEBRUARY
	MOVE	LEFT,YEAR		;LEAP YEAR TEST
	IDIVI	LEFT,4
	SKIPN	RIGHT
	AOS	FEBRUARY
	MOVN	RIGHT,MONTH		;NEGATIVE OF MONTH
	HRLZS	RIGHT			;TO LEFT HALFWORD
	SETZ	LEFT,			;CLEAR LEFT
	ADD	LEFT,JANUARY(RIGHT)	;ADD UP DAYS IN EACH MONTH
	AOBJN	RIGHT,.-1
	ADDB	LEFT,DAY		;ADD DAY OF MONTH
	MOVEI	T1,3
	PUSHJ	P,DECLBL		;OUTPUT DAY OF YEAR
	IDPB	SP,PNT			;AND A SPACE
	AOS	LEFT,YEAR		;EXPIRATION DATE ONE YEAR LATER
	MOVEI	T1,2
	PUSHJ	P,DECLBL

	MOVE	LEFT,DAY
	MOVEI	T1,3
	PUSHJ	P,DECLBL

	MOVE	T1,[POINT 6,[SIXBIT/ 000000DECFILE11A/]]
	MOVEI	T2,^D17
	PUSHJ	P,SIXTAP

	MOVEI	T1,^D10			;10 SPACES
	PUSHJ	P,SPACES

	OUTPUT	OUT,LBLCHN		;WRITE HDR1 RECORD

;WRITE HDR2 RECORD

	MOVE	PNT,LBLPNT
	HRRI	PNT,LABEL2
	MOVE	T1,[POINT 6,[SIXBIT/HDR2D0051200512/]]
	MOVEI	T2,^D15
	PUSHJ	P,SIXTAP

	MOVEI	T1,^D35
	PUSHJ	P,SPACES
	MOVE	T1,[POINT 6,[SIXBIT/00/]]
	MOVEI	T2,2
	PUSHJ	P,SIXTAP

	MOVEI	T1,^D28
	PUSHJ	P,SPACES

	OUTPUT	OUT,LB2CHN
	MTEOF.	OUT,			;WRITE EOF
	POPJ	P,

;EOF1 TRAILER LABELS

EOF1:	MTEOF.	OUT,			;WRITE EOF

	MOVE	PNT,LBLPNT		;CHANGE HDR1 LABEL INTO EOF1
	MOVE	T1,[POINT 6,[SIXBIT/EOF/]]
	MOVEI	T2,3
	PUSHJ	P,SIXTAP

	OUTPUT	OUT,LBLCHN		;WRITE EOF1 LABEL
	POPJ	P,

;EOF2 TRAILER LABEL

EOF2:	MOVE	PNT,LBLPNT
	HRRI	PNT,LABEL2
	MOVE	T1,[POINT 6,[SIXBIT/EOF/]]
	MOVEI	T2,3
	PUSHJ	P,SIXTAP
	OUTPUT	OUT,LB2CHN
	POPJ	P,

;SUBROUTINE TO MOVE SIXBIT CHARACTERS TO TAPE LABEL OUTPUT AREA

SIXTAP:	ILDB	CH,T1			;GET A SIXBIT CHARACTER
	TRNE	SW,RSX11		;IF RSX-11,
	ADDI	CH,40			;CONVERT SIXBIT TO ASCII
	IDPB	CH,PNT			;PUT IT IN THE OUTPUT AREA
	SOJG	T2,SIXTAP
	POPJ	P,

;SUBROUTINE TO MOVE SPACES TO TAPE OUTPUT AREA

SPACES:	IDPB	SP,PNT
	SOJG	T1,.-1
	POPJ	P,

;SUBROUTINE TO OUTPUT A DECIMAL NUMBER TO THE TAPE OUTPUT AREA

DECLBL:	IDIVI	LEFT,^D10
	HRLM	RIGHT,(P)
	SOSLE	T1
	PUSHJ	P,DECLBL

	HLRZ	CH,(P)
	ADDI	CH,20(SP)
	IDPB	CH,PNT
	POPJ	P,

	XLIST			;DON'T LIST LITERALS
	LIT
	LIST
	SUBTTL	STORAGE

HITOP==.-1			;HIGHEST ADDRESS IN HIGH SEGMENT

;LOW SEGMENT:
	RELOC

;NON-ZEROED LOW CORE:

;TABLE OF DAYS PER MONTH

JANUARY:DEC	31
FEBRUARY:DEC	28		;MODIFIED ON LEAP YEAR
MARCH:	DEC	31
APRIL:	DEC	30
MAY:	DEC	31
JUNE:	DEC	30
JULY:	DEC	31
AUGUST:	DEC	31
SEPTEMBER:DEC	30
OCTOBER:DEC	31
NOVEMBER:DEC	31
DECEMBER:DEC	31

TTYBLK:	0
	SIXBIT/TTY/
	XWD TOUT,TINP
OUTBLK:	OCT 17,0,0
INNBLK:	0
	SIXBIT/DSK/
	XWD 0,IBUF

LBLCHN:	EXP	LABEL-1,0
LB2CHN:	IOWD	^D20,LABEL2
	0
LBLPNT:	LABEL			;BYTE POINTER TO LABEL AREA

;ZEROED LOW CORE:

LOWZRO==.

VOLNAM:	0			;VOLUME NAME FOR MAGTAPE LABELS
VOL:	0			;VOLUME NUMBER FOR MAGTAPE LABELS
FILE:	0			;FILE NUMBER FOR MAGTAPE LABELS
LABEL:	BLOCK	^D20		;STORAGE FOR MAGTAPE LABEL
LABEL2:	BLOCK	^D20		;STORAGE FOR SECOND MAGTAPE LABEL

DVSZBL:	BLOCK	3		;DEVSIZ BLOCK
INNAM:	BLOCK 4
IOLIST:	BLOCK	2		;I/O LIST

LOC:	BLOCK 12

TINP:	BLOCK 3
TOUT:	BLOCK 3
IBUF:	BLOCK 3

STACK:	BLOCK	PDLSIZ		;PUSHDOWN LIST
	LIT
LOWTOP==.

	END START