	.title	errmsg
	.ident	/v01/

;       Author:
;              William L. Kyle
;              E.I. duPont de Nemoures & Co.
;              Engineering Department
;              P.O. Box 6090
;              Newark, DE 19714-6090
;
;========================================================================;
;                          Copyright (C) 1987                            ;
;                     E.I. duPont de Nemoures & Co.                      ;
;                         All rights reserved.                           ;
;        This software is furnished through the DECUS Library and may    ;
;        NOT be sold.  It may be copied only with the inclusion of       ;
;        this copyright notice.                                          ;
;                                                                        ;
;        DuPont assumes no responsibility for the use or reliability     ;
;        of this software.                                               ;
;========================================================================;
	.enable	lc
;
;	calling sequence:
;	call errmsg
;	 r1	- address of message string
;	 r2	- address of status value stack
;		  first word = number of arguments
;		  argument list
;		- if r2 odd do not print task name
;	 r3	- lun
;
;	message format:
;	 msg1:	.asciz	/%2R -- OPEN error %1P on input file/
;	 msg2:	.asciz	/%2R -- Files: %D, pages: %D, lines: %T/
;
;	output:
;	 cc	- success
;	 cs	- error
;

	.mcall	qiow$s,gtsk$s

; program sections
	.psect	$code,	i, ro, con, rel, lcl
	.psect	$$buf,	d, rw, ovr, rel, gbl

	.psect	$code
; local equates
	flag	= 13.			; event flag for QIOW

; local buffer
	.save
	.psect	$$buf
;
; NOTE:	This buffer can be made larger by declaring the PSECT $$BUF
;	with a larger size in the calling program or durring linking
;	with an EXTSCT option.
;
outbuf:	.blkb	80.			; output buffer
	.even
	.restore
.page

errmsg::mov	r0,-(sp)		; save r0
	mov	r4,-(sp)		; save r4
	mov	r5,-(sp)		; save r5
	clr	-(sp)			; clear a flag word
	mov	sp,r5			; save stack pointer, and point to flag
	bit	#1,r2			; is r2 odd?
	beq	10$			; if eq, no - then print task name
	bic	#1,r2			; even up address
	inc	(r5)			; flag not to print task name
10$:	mov	(r2)+,r4		; get # of arguments, point to first
	beq	30$			; if eq, none
20$:	mov	(r2)+,-(sp)		; put data, sign extended, on stack
	sob	r4,20$			; count off this argument
30$:	tst	(r5)			; print task name?
	bne	40$			; if ne, no
	gtsk$s	#outbuf			; get the task name
	bcs	100$			; if cs, error
	mov	outbuf+2,-(sp)		; 2nd half of name
	mov	outbuf,-(sp)		; 1st half
40$:	mov	sp,r2			; and locate it for edmsg
	mov	#outbuf,r0		; and its destination
	call	$edmsg			; format it
	qiow$s	#io.wlb,r3,#flag,,,,<#outbuf,r1,#40>
100$:	mov	r5,sp			; clean off stack
	tst	(sp)+			; clean flag off stack
	mov	(sp)+,r5		; restore r5
	mov	(sp)+,r4		; restore r4
	mov	(sp)+,r0		; restore r0
	return				; and exit

	.end
