	.TITLE	ERROR
	.IDENT	"V1.8"
;
;   Author:	D. Mischler	10-JUN-87
;
;   This module contains the error handling routines
;   and all error message definitions.
;

;
;   Macro to define an error code and message.
;
	.MACRO	ERRDEF	NAME,MESSAG
NAME::	.ASCIZ	\MESSAG\
	.ENDM	ERRDEF
	.PAGE
	.PSECT	CODE,I,RO
;
;   Subroutine to display an ASCIZ error message pointed to by R1.
;   The appearance of a percent sign in the message indicates
;   that the string pointed to by R0 should be inserted.
;
ERROR::
	CALL	$SAVAL		; Save all registers.
	MOV	SP,R5		; Remember current stack position.
	MOV	R1,R3		; Copy error message address.
;   See if the message contains a percent sign.
	CLR	R4		; Indicate no percent sign (yet).
10$:	CMPB	#'%,(R3)	; Found a percent sign?
	BNE	20$		; No, check for end of string.
	MOV	R0,R4		; Indicate a percent sign was found.
20$:	TSTB	(R3)+		; Hit end of string yet?
	BNE	10$		; No, keep looking.
	TST	R4		; Did the message contain a percent sign?
	BEQ	70$		; No, take the easy way out.
;   Build the actual error message for display on the stack.
30$:	CALL	U$FTRM		; Find end of inserted string.
	SUB	R4,R0		; Get length of inserted item.
	SUB	R1,R3		; Get length of message text.
	ADD	R0,R3		; Get composite length.
	BIC	#1,R3		; Make sure length is even.
	SUB	R3,SP		; Allocate a buffer.
;   Copy the message onto the stack.
	MOV	SP,R2		; Produce a destination pointer.
40$:	CMPB	#'%,(R1)	; Found percent sign?
	BNE	60$		; No, copy character into place.
;   Insert the string pointed to by R4.
	TST	R0		; String copy already complete?
	BEQ	55$		; Yes, do not buffer percent sign.
50$:	MOVB	(R4)+,(R2)+	; Buffer a character.
	SOB	R0,50$		; Do 'em all.
55$:	INC	R1		; Skip over percent sign.
;   Buffer character.
60$:	MOVB	(R1)+,(R2)+	; Buffer character, terminator?
	BNE	40$		; No, keep copying.
	MOV	SP,R1		; Point to resulting message.
;   Output the message.
70$:	CALL	LINOUT		; Output error message line.
	MOV	R5,SP		; Restore incoming stack pointer.
	RETURN
	.PAGE
	.PSECT	STRING,D,RO
;
;   Error message definitions.
;
	ERRDEF	E.AMBG,<Ambiguous keyword "%">
	ERRDEF	E.AROV,<Address range overlap>
	ERRDEF	E.AWMF,<Address window management failure>
	ERRDEF	E.BAR,<Illegal address range>
	ERRDEF	E.BCF,<Illegal compression factor>
	ERRDEF	E.BONF,<Unknown operator "%">
	ERRDEF	E.CMDF,<Command file I/O or nesting error>
	ERRDEF	E.DAFU,<Unexpected DBGAID packet, debug with %>
	ERRDEF	E.DBZA,<Divide by zero attempted>
	ERRDEF	E.DFER,<Indirect addressing error>
	ERRDEF	E.EQMS,<Missing '='>
	ERRDEF	E.HPWF,<Halt point write failure>
	ERRDEF	E.ICCF,<Internal consistency check failure>
	ERRDEF	E.ILOP,<Illegal opcode "%">
	ERRDEF	E.ILRN,<Illegal or missing register "%">
	ERRDEF	E.IOMO,<Illegal or missing operand "%">
	ERRDEF	E.IOT,<IOT instruction>
	ERRDEF	E.KWNF,<Unknown keyword "%">
	ERRDEF	E.LOPN,<Log file open error>
	ERRDEF	E.MFUL,<Memory full>
	ERRDEF	E.MSBX,<Missing subexpression "%">
	ERRDEF	E.MWF,<Memory write failure>
	ERRDEF	E.NACT,<Target task is not active - exiting>
	ERRDEF	E.QCBR,<Quotient cannot be represented>
	ERRDEF	E.RAMS,<Required argument missing>
	ERRDEF	E.RMBC,<Range too large - compress>
	ERRDEF	E.SNRQ,<Symbol name required>
	ERRDEF	E.SOPN,<Symbol file open error>
	ERRDEF	E.SYNF,<Unknown symbol "%">
	ERRDEF	E.TSKN,<Bad task name>
	ERRDEF	E.UMSI,<Unmatched angle brackets>
	ERRDEF	E.2FAR,<Too far to branch "%">
	.END
