Google
 

Trailing-Edge - PDP-10 Archives - LCG_Integration_Tools_Clearinghouse_T20_v7_30Apr86 - tools/tape11/rfil11.mac
There are 3 other files named rfil11.mac in the archive. Click here to see a list.
	title	RFIL11 - Read a Files-11 tape end to end
	subttl	Berkley Shands @ ECL for not enough money or respect

	search	monsym,macsym		;pick up symbols and macro's
	sall

	;accumulators

	t1==	1			;jsys arg 1
	t2==	2			;jsys arg 2
	t3==	3			;jsys arg 3
	t4==	4			;jsys arg 4
	t5==	5			;jsys arg 5

	a==	10
	b==	11
	c==	12
	d==	13
	e==	14

	;flag register

	f==	0

	;stack pointer

	p==	17

	;flags

	f.crlf==	1b0			;on if <CR><LF> needed

	ftansi==	0			;[2] on if TM02/TU72 only
	subttl	Edit history and version

	;[1]	new 11/21/80 efbs
	;[2]	9/6/83 add ftansi conditional to allow for tu78/EE

entvec:
	jrst	start
	jrst	start
	exp	2
	subttl	Execution address

rfil11::
start::
	reset					;clear everything
	setzm	low				;zero impure
	move	t1,[low,,low+1]			;blt word
	blt	t1,high				;clear buffers and such
	setz	f,				;clear flags
	move	p,[iowd 200,pdlst]		;set up big stack
	tmsg	<RFIL11 Files-11 tape processor. Whole tape is read.
Output is to connected directory.
>
	;get magtape designator

	tmsg	<Enter input magtape device: >
	dmove	t1,[gj%sht!gj%msg!gj%fns	;short form, give msg, i/o tty:
		.priin,,.priou]			;i/o to tty
	GTJFN					;get magtape descripter
	 ERJMP	badmta				;whoops
	hrrzm	t1,mtajfn			;save jfn for now
	movei	a,(t1)				;keep jfn handy

	;set up magtape specs


	;open the magtape

	movei	t1,(a)				;get jfn again
	ifn	ftansi,<
	movx	t2,of%rd!<7>b5			;8 on tape, monitor
						;eats one for 7
>;end ifn ftansi
	ife	ftansi,<
	movx	t2,of%rd!<10>b5			;8 on tape, 8 incore
>;enf ife ftansi
	OPENF					;get the device
	 ERJMP	badmop				;bad mta open

	movx	t2,.morew			;rewind tape to start
	MTOPR					;try that
	 ERCAL	badrew				;could not rewind
	movei	t1,(a)				;recover jfn
	movx	t2,.mosdm			;set data mode
	ifn	ftansi,<
	movx	t3,.sjdma			;ANSI ASCII 8 bit bytes
>;end ifn ftansi
	ife	ftansi,<
	movx	t3,.sjdm8			;[2] use industry
>;enf ife ftansi
	MTOPR					;set feature
	 ERCAL	badmod				;bad device data mode
	movei	t1,(a)				;get mta jfn
	movx	t2,.mosrs			;set record size
	movei	t3,^d80				;headers are 80 chars
	MTOPR					;set block len
	 ERJMP	.+1
	Subttl	Begin processing tape

	;read volume id and ignore

	movei	t1,(a)				;get mta jfn again
	ifn	ftansi,<
	hrroi	t2,volume			;volume buffer
>;end ifn ftansi
	ife	ftansi,<
	move	t2,[point 8,volume]		;[2] use 8 bit
>;end ife ftansi
	movni	t3,^d80				;one card image
	setz	t4,				;just in case
	SINR					;read record
	 ERCAL	ERRRVL				;err reading vol label
	ife	ftansi,<
	move	t1,[^d80,,volume]		;[2] convert to 7 bit
	call	convrt				;[2] do the work
>;end ife ftansi
	tmsg	<Volume id: >
	movei	t1,.priou			;type on tty
	move	t2,[point 7,volume,27]		;start of name
	movni	t3,6				;six chars max
	SOUT
	tmsg	<
>
	;here at top of file processing loop

top:
	movx	t1,co%nrj			;reset size of file
	hrri	t1,(a)				;get jfn
	CLOSF					;kill device
	 ERJMP	.+1
	movei	t1,(a)				;restart device
	ifn	ftansi,<
	movx	t2,of%rd!<7>b5			;8 on tape, monitor
						;eats one for 7
>;end ifn ftansi
	ife	ftansi,<
	movx	t2,of%rd!<10>b5			;8 on tape, 8 incore
>;enf ife ftansi
	OPENF					;grab back
	 ERJMP	.+1
	movei	t1,(a)				;recover jfn
	movx	t2,.mosdm			;set data mode
	ifn	ftansi,<
	movx	t3,.sjdma			;ANSI ASCII 8 bit bytes
>;end ifn ftansi
	ife	ftansi,<
	movx	t3,.sjdm8			;[2] use industry
>;enf ife ftansi
	MTOPR					;set feature
	 ERCAL	badmod				;bad device data mode
	movei	t1,(a)				;get mta jfn
	movx	t2,.mosrs			;set record size
	movei	t3,^d80				;headers are 80 chars
	MTOPR					;set block len
	 ERJMP	.+1
	movei	t1,(a)				;get mta jfn
	ifn	ftansi,<
	hrroi	t2,hdr1				;header buffer
>;end ifn ftansi
	ife	ftansi,<
	move	t2,[point 8,hdr1]		;[2] use 8 bits
>;end ife ftansi
	movni	t3,^d80				;first header
	SINR					;read header
	 ERCAL	TOPEOF				;top level eof ?
	ife	ftansi,<
	move	t1,[^d80,,hdr1]         	;[2] convert to 7 bit
    	call	convrt				;[2] do the work
>;end ife ftansi

	;now do second record of header

	movei	t1,(a)				;get mta jfn
	ifn	ftansi,<
	hrroi	t2,hdr2				;header buffer
>;end ifn ftansi
	ife	ftansi,<
	move	t2,[point 8,hdr2]		;[2] use 8 bits
>;end ife ftansi
	movni	t3,^d80				;read 80 bytes
	SINR					;read record
	 ERCAL	errrh2				;err reading hdr2
	ife	ftansi,<
	move	t1,[^d80,,hdr2]  		;[2] convert to 7 bit
	call	convrt				;[2] do the work
>;end ife ftansi

	;ok, should be at tape mark
	;so skip over it

	movei	t1,(a)				;get mta jfn again
	movx	t2,.mofwf			;forward to tape mark
	MTOPR					;try to move tape
	 ERCAL	badtpm				;bad tape mark

	;ready to set stuff up for file reading
	subttl	File creation and user notify

	;start by breaking the file name out of header1

	dmove	t1,[point 7,hdr1+4,13		;addr of last char
		point	7,hdr1,27]		;addr of first char file name
	setz	t3,				;force a null
	dpb	t3,t1				;as last char
	movx	t1,gj%sht!gj%fou		;short form, output only
	GTJFN					;get handle on file
	 ERCAL	badtfn				;bad tape file name
	hrrzm	t1,filjfn			;save jfn of file
	movei	b,(t1)				;keep jfn handy

	;tell user type of file

	ldb	c,[point 7,hdr2+7,13]		;get crlf code
	cain	c," "				;force crlf ?
	txoa	f,f.crlf			;yes, give crlf
	txz	f,f.crlf			;reset flag
	hrroi	t1,[asciz/[File will have <CR><LF> appended to each record]
/]
	txne	f,f.crlf			;needed ?
	 PSOUT					;yes, type message

	tmsg	<Working on file: >
	move	t1,[point 7,hdr1,27]		;type out file name
	PSOUT					;on user tty

	move	t1,filjfn			;get jfn back
	movx	t2,of%wr!<7>b5			;seven bit bytes
	OPENF					;create the file
	 ERCAL	badofn				;bad openf file name

	;set up the new blocksize and record length

	dmove	t1,hdr2+1			;get block length and rec len
	movem	t1,blktxt			;save text of block len
	movem	t2,rectxt			;save record len text

	;convert text to numbers

	hrroi	t1,blktxt			;start with block text
	movei	t3,^d10				;decimal text
	NIN					;read the number
	 ERCAL	[movei	t2,^d512
		RET]				;default if bad
	caig	t2,0				;check again
	 movei	t2,^d512			;fix if in error
	movem	t2,blklen			;save block length

	hrroi	t1,rectxt			;do record length text
	movei	t3,^d10				;base 10
	NIN
	 ERCAL	[movei	t2,^d512
		RET]				;default
	caig	t2,0				;range check
	 movei	t2,^d512			;correct if problem
	movem	t2,reclen			;save record length

	;set new block-size for tape

	movx	t1,co%nrj			;hold this jfn
	hrri	t1,(a)				;for next open
	CLOSF
	 ERJMP	.+1
	movei	t1,(a)				;re-open file
	ifn	ftansi,<
	movx	t2,of%rd!<7>b5			;8 on tape, monitor
						;eats one for 7
>;end ifn ftansi
	ife	ftansi,<
	movx	t2,of%rd!<10>b5			;8 on tape, 8 incore
>;enf ife ftansi
	OPENF
	 ERJMP	.+1				;oh, hell!

	movei	t1,(a)				;recover jfn
	movx	t2,.mosdm			;set data mode
	ifn	ftansi,<
	movx	t3,.sjdma			;ANSI ASCII 8 bit bytes
>;end ifn ftansi
	ife	ftansi,<
	movx	t3,.sjdm8			;[2] use industry
>;enf ife ftansi
	MTOPR					;set feature
	 ERCAL	badmod				;bad device data mode
	movei	t1,(a)				;get mta jfn
	movx	t2,.mosrs			;set record size
	move	t3,blklen			;get block size
	MTOPR					;set block len
	 ERJMP	.+1
	subttl	data transfer

xfer:
	movei	t1,(a)			;i/o from mta
	ifn	ftansi,<
	hrroi	t2,recbuf			;header buffer
>;end ifn ftansi
	ife	ftansi,<
	move	t2,[point 8,recbuf]		;[2] use 8 bits
>;end ife ftansi
	movn	t3,blklen		;bytes to read
	setz	t4,			;clear char
	SINR				;read record
	 ERCAL	xfrerr			;transfer error
	ife	ftansi,<
	movs	t1,blklen		;[2] bytes in record
	hrri	t1,recbuf		;[2] addr of buffer
	call	convrt			;[2] change to 7 bits
>;end ife ftansi

	;now write the record to disk
	;format of <CR><LF> ascii file is ascii byte count, #chars, repeat

	dmove	c,[point 7,recbuf	;set up pointers for char counts
		point	7,cbuf]		;and pointer for scratch area
	ldb	t2,[point 7,recbuf,6]	;get first char of block
	cail	t2,"0"			;range check
	 caile	t2,"9"			;valid numbers only
	  jrst	xfrbig			;do whole block

xfrtry:
	move	t1,d			;get output area
	ildb	t2,c			;get a byte of data
	idpb	t2,t1			;and save for conversion
	ildb	t2,c			;get second byte of len
	idpb	t2,t1			;save in cbuf
	ildb	t2,c			;get third byte of data
	idpb	t2,t1			;save in cbuf
	ildb	t2,c			;get last char of len
	idpb	t2,t1			;save it
	hrroi	t1,cbuf			;start of text
	setz	t2,			;clear it
	movei	t3,^d10			;use base 10
	NIN				;try to read a number
	 ERJMP	xfer			;done with this record
	subi	t2,4			;decr for len of count string
	movn	t3,t2			;force reading/output of N bytes
	move	t2,c			;get current buffer pointer
	movei	t1,(b)			;output device
	setz	t4,			;no spl chars
	skipge	t3			;ignore if too small or zero
	SOUT				;output the characters
	move	c,t2			;recover new pointer
	hrroi	t2,[asciz/
/]					;a crlf
	setzb	t3,t4			;clear funny format
	txne	f,f.crlf		;a crlf ?
	 SOUT				;yes, add it
	jrst	xfrtry			;and try again

xfrbig:
	movei	t1,(b)			;out to file
	hrroi	t2,recbuf		;from input buffer
	movn	t3,blklen		;max bytes to output
	setz	t4,			;clear
	SOUT				;write to file
	jrst	xfer			;next record please

	;here on xfer error

xfrerr:
	push	p,t2
	movei	t1,.fhslf		;find error cause
	GETER				;get last error
	movei	t1,(t2)			;get error #
	pop	p,t2
	cain	t1,iox4			;<EOF> ?
	 jrst	xfreof			;yes, stop
	cain	t1,iox5			;data error ?
	 jrst	xfrder			;data error
	cain	t1,iox10		;record too long ?
	 jrst	xfrrtl			;yes

	push	p,t1			;save ac
	tmsg	<%Unknown error while reading tape file
>
	pop	p,t1
	RET				;ignore error

xfrder:
	push	p,t2
	push	p,t3
	movei	t1,(a)			;get mta status
	GDSTS				;for EOF check
	push	p,t2			;save status
	setz	t2,			;clear all bits
	SDSTS				;clear it
	 ERJMP	.+1
	pop	p,t1			;get error back
	pop	p,t3			;restore ac
	pop	p,t2			;restore ac
	txne	t1,mt%eof		;eof ?
	 jrst	xfreof			;done!
	tmsg	<%Device or data error - ignored
>
	RET

xfrrtl:
	skiple	t3			;stop early ?
	 RET				;yes, not an error
	push	p,t1
	tmsg	<%Record longer than expected
>
	pop	p,t1
	RET

xfreof:
	movei	t1,(b)			;get output jfn
	CLOSF				;drop file
	 ERJMP	.+1
	tmsg	< [Ok]
>
	;now, find next tape mark
	;and eat eof1 and eof2

	movei	t1,(a)			;i/o to mta
	movx	t2,.mofwf		;forward one file
	MTOPR				;skip a file
	 ERJMP	.+1
	pop	p,(p)			;keep stack clean
	jrst	top			;and try again
	subttl	TOPEOF error on first record

topeof:
	push	p,t2
	movei	t1,.fhslf		;get last error
	GETER				;we had
	hrrz	t1,t2			;save error
	pop	p,t2			;restore t2

	cain	t1,iox4			;eof ?
	 jrst	topdon			;yes, done
	tmsg	<%Error reading first record of file header!
>
	setzm	hdr1			;clear header 1
	move	t1,[hdr1,,hdr1+1]	;to nulls
	blt	t1,hdr1+77		;zap buffer
	RET

topdon:
	movei	t1,(a)			;mta i/o
	movx	t2,.morew		;rewind tape
	MTOPR
	 ERJMP	.+1
	reset
	HALTF
	JRST	start
	subttl	convrt convert 8 to 7 bit ascii

	;[2] all under this edit

	ife	ftansi,<
convrt:
	push	p,t2
	push	p,t3			;save acs
	push	p,t4
	hlrz	t3,t1			;copy count
	hrli	t1,(point 8,)		;input
	movsi	t2,(point 7,)		;output
	hrri	t2,(t1)			;addr of output
	ildb	t4,t1			;get a byte
	idpb	t4,t2			;save the byte
	sojg	t3,.-2			;loop
	pop	p,t4
	pop	p,t3
	pop	p,t2
	RET
>;end ife ftansi
	subttl	Random errors

badmta:
	tmsg	<%Invalid tape specs
>
	call	lsterr
	jrst	start

badmop:
	tmsg	<%OPENF failed for given device
>
	call	lsterr
	jrst	start

badrew:
	tmsg	<%Rewind failed!
>
	call	lsterr
	RET

badmod:
	tmsg	<%Could not set ANSI-ASCII (or INDUSTRY)
>
	call	lsterr
	RET

errrvl:
	tmsg	<%Error reading volume ID
>
	call	lsterr
	RET

errrh2:
	tmsg	<%Error reading HDR2
>
	call	lsterr
	setzm	hdr2
	move	t1,[hdr2,,hdr2+1]		;clear buffer
	blt	t1,hdr2+77
	RET

badtpm:
	tmsg	<%Error finding tape mark
>
	RET

badofn:
	tmsg	<%Could not open file for output, Ignoring file!
>
	movei	b,.nulio			;output to nowhere
	RET

badtfn:
	tmsg	<%Monitor rejected file name: >
	move	t1,[point 7,hdr1,27]		;type file name
	PSOUT
	tmsg	< Enter new file specs
?? >
	movx	t1,gj%sht!gj%fou!gj%fns!gj%msg	;full works
	move	t2,[.priin,,.priou]		;to tty
	GTJFN					;get it
	 ERJMP	badtfn				;nit wit!
	RET
lsterr:
	push	p,t1
	push	p,t2
	push	p,t3
	movei	t1,.priou
	hrloi	t2,.fhslf
	setz	t3,
	ERSTR
	 ERJMP	.+1
	 ERJMP	.+1
	tmsg	<
>
	pop	p,t3
	pop	p,t2
	pop	p,t1
	RET
	subttl	lits
	xlist
	lit
	list
	subttl	low segment

low:	block	1
pdlst:	block	200
hdr1:	block	100
hdr2:	block	100
volume:	block	100
recbuf:	block	10000
mtajfn:	block	1
filjfn:	block	1
rectxt:	block	2000
blktxt:	block	2000
reclen:	block	1
blklen:	block	1
cbuf:	block	1
high:	block	1
	end	<3,,entvec>