	.title	rsxerr	get error text from qiosym for TED
	.ident	/4.0.01/
	.enabl	gbl
	.psect	$code

;	Brian Nelson
;	Computer Services
;	University of Toledo
;	2801 West Bancroft
;	Toledo , Ohio 43606
;
;	(419) 537-2511
;
;
;	
;	
;	Copyright (C) 1978, 1979, 1980, 1981, 1982 Brian Nelson
;	
;	
;	
;	This software is furnished under a license and may
;	be  used  and  copied  only in accordance with the
;	terms of such license and with  the  inclusion  of
;	the  above copyright notice.  This software or any
;	other copies thereof may not be provided or other-
;	wise made available to any other person.  No title
;	to and ownership of the software is hereby  trans-
;	ferred.
;	
;	The information in this  software  is  subject  to
;	change  without notice and should not be construed
;	as a commitment by the University of Toledo or  by
;	the author.
;	
;
;	Developed (of course) under RSTS 7.0 and 7.1 using
;	RSX emulation. Use of channel numbers  is done  in
;	order to retain operating system indepenence.
;	All i/o is in emulation of how things are done  on
;	RSTS, since the RSTS version was, after all,  done
;	first. Anyway, we do not use any FCS record i/o so
;	it is just as well.
;	

	.sbttl	macros used



	.mcall	fdbdf$	,fdat$a	,fdrc$a	,fdop$a	,fdbf$a	,fdbk$a
	.mcall	qiow$	,dir$	,finit$	,exit$s	,fsrsz$
	.mcall	csi$	,csi$1	,csi$2
	.mcall	opns$r	,open$w	,ofnb$r	,opnt$d	,close$
	.mcall	get$	,put$	,read$	,write$	,wait$	,fdbk$r
	.mcall	fdat$r	,fdof$l
	.mcall	alun$s

	fdof$l


	.macro	.newline
	call	$pcrlf
	global	<$pcrlf>
	.endm	.newline

	.macro	moverr	err
	mov	err	,-(sp)
	call	seterr
	.endm	moverr



inpbuf	= inbuf
bf$pnt	= bufpnt
er$sav	= errsav
by$cnt	= recount
bl$num	= blknum
io$sta	= iostat


errfil:	.word	3,10$,5,20$,12,30$
10$:	.ascii	/LB:/
	.even
20$:	.ascii	/[1,2]/
	.even
30$:	.ascii	/QIOSYM.MSG/
	.even


	.sbttl	lookup error text in qiosym


	.mcall	opns$r	,get$r	,close$
	.mcall	mrkt$s	,wtse$s
	.mcall	fdat$r	,fdrc$r	,fdbk$r	,fdop$r


	.psect	$code

prterr::mov	r0	,-(sp)		; save temps
	mov	r1	,-(sp)		; save temps
	mov	r5	,-(sp)		; save temps
	mov	#errfdb	,r5		; fdb address
	fdat$r	r5,#r.var,#fd.cr,#0	; seems to insist on this
	fdrc$r	r5,#fd.rwm		; but we are using read/write
	fdbk$r	r5,#errbuf,#1000,,#40,#errios
	fdop$r	r5,#10,#errfil,,<#fa.rd!fa.shr>
	opns$r	r5,#10,,,#errbuf,#1000,200$
	movb	<2+6>(sp),r1		; use fcs record random i/o
	bpl	5$			; ok
	neg	r1			; need a positive record number
5$:	dec	r1			; convert to 0..n-1
	blt	90$			; oops
	cmpb	<<2+6>+1>(sp),#377	; a directive error ?
	bne	6$			; no
	add	#200	,r1		; yes, correct offset in qiosym
6$:	clr	r0			; setup for divide to get the
	div	#10	,r0		; block number and offset in it
	inc	r0			; + 1
	mul	#100	,r1		; offset in block (in r0)
	calls	$getbl	,<#errbuf,#1000,#10,r0>; read the block
	iferr	210$			; oops
	add	#errbuf	,r1		; at last, get the record addr
	mov	r1	,r5		; save it please
	mov	#100	,r0		; number of bytes in record
10$:	tstb	(r1)+			; find the trailing null
	beq	20$			; go it
	sob	r0	,10$		; no, next please
20$:	sub	r5	,r1		; number of bytes to print
	calls	rputkb	,<r5,r1>	; simple
	mrkt$s	#31.,#1,#2		; take a short nap now
	wtse$s	#31.			; wait for the timeout
90$:	close$	#errfdb			; close up shop for now
100$:	mov	(sp)+	,r5
	mov	(sp)+	,r1		; pop temps
	mov	(sp)+	,r0		; pop temps
	mov	(sp)+	,(sp)		; pop parameter
	clc				; don't care if it fails
	return				; bye

200$:	tst	(sp)+
205$:	movb	errfdb+f.err,r0		; print the error code and
	.print	#215$			; a message about not finding
	.wrdec	r0			; qiosym.msg
	br	100$			; open error

210$:	.print	#220$			; read error on qiosym
	.wrdec	errsav			; print error number
	.wrdec	r0			; block number
	.newline			; a cr/lf
	br	100$			; exit

	.enabl	lc
215$:	.asciz	/?Opns$r failed for LB:[1,2]QIOSYM.MSG /
220$:	.asciz	/?Error reading QIOSYM (er,blk#) /
	.dsabl	lc
	.even
230$:	.asciz	/LB:[1,2]QIOSYM.MSG/
	.even

	.end
