	.TITLE	ERROR
	.IDENT	/hah013/
 
;
; VERSION 00
;
; TOM GETZINGER  24-FEB-80
;
; Modified:	03-Aug-85	hah012
;		Improve error messages, and define some new ones.
;		11-Aug-85	hah013
;		Add support for /ID switch to identify ourselves.
;
; THIS ROUTINE PRINTS ERROR MESSAGES
;
; LOCAL MACROS
;
 
	.macro	err	name, msg, fatal				;hah012
	.PSECT	ERRTXT
...ADR=	.
	.ASCII	MSG
...LEN=	.-...ADR
	.PSECT	RODATA
NAME	==	<.-ERRTBL>/2
	.if nb	fatal							;hah012
name = name!200								;hah012
	.endc								;hah012
	.WORD	...ADR,...LEN
	.ENDM
 
;
; LOCAL DATA
;
 
	.PSECT	ERRTXT,RO,D
wrning:	.ascii	<15><12><12>/%/						;hah012
wrnlen = .-wrning							;hah012
fatal:	.ascii	<15><12><12>/?/						;hah012
ftllen = .-fatal							;hah012
errhdr:	.ascii	/DOB -- /						;hah012
ERHDLN=	.-ERRHDR
	.even

	.PSECT	RODATA,RO,D
ERRTBL:
	err	id,	<<15><12>"DOB "> 	;Should always be first	;hah012
	ERR	CMDIOR, <"Command I/O error">
	ERR	SYNTAX, <"Command syntax error">
	ERR	INIOER, <"I/O error on input file">, fatal
	ERR	OBJFMT, <"Object file format error">, fatal
	ERR	NOMEM,  <"Insufficient dynamic memory">, fatal
	ERR	TMPERR, <"I/O error on temporary file">, fatal
	err	lmtrel, <"2nd word of .LIMIT is already relocated">, fatal
	err	lmt2nd, <"No second word for .LIMIT">, fatal
	err	relrel, <"Can't relocate a relocated location">, fatal
	err	wrdrel, <"Trying to do a word location @ an odd address">, fatal
	err	rellen, <"Byte reloc. of word, or word reloc. of byte">, fatal
	err	reltxt, <"Can't find text record offset to relocate">, fatal
	err	moddef, <"More rel. ents after loc. counter mod or def">, fatal
	err	relsiz, <"Bad RLD record length">, fatal
	err	misopr, <"Missing operand in complex relocation entry">, fatal
	err	toomny, <"Too many operands in complex relocation entry">, fatal
	err	isdlen, <"Bad ISD record length">, fatal
	err	lbrior, <"Library file read error">
	err	notfnd, <"Module name or global symbol not found">
	err	nofile, <"Can't find file, or error opening file">
	err	notemp, <"Error opening work file">
	err	noout,  <"Error opening output file">
	.even
	.iif ne, id,	.error		;IDENT should be 0		;hah013

	.PSECT	CODE,RO
 
	.MCALL	EXIT$S	QIOW$S
 
ERROR::
	mov	r0,-(sp)	;Save in case not fatal			;hah012
	mov	2(sp),r0	;Get error number			;hah012
	beq	30$		;Want version number, not error		;hah013
	bit	#400,r0		;Fatal error?				;hah012
	bne	10$		;Yes					;hah012
	qiow$s	#io.wlb,#lunerr,#lunerr,,,,<#wrning,#wrnlen>		;hah012
	br	20$		;Contine				;hah012
10$:				
					;hah012
	qiow$s	#io.wlb,#lunerr,#lunerr,,,,<#fatal,#ftllen>		;hah012
	bic	#-400,r0	;Clear error flag			;hah012
20$:									;hah012
	QIOW$S	#IO.WLB,#LUNERR,#LUNERR,,,,<#ERRHDR,#ERHDLN>
30$:									;hah013
	QIOW$S	#IO.WLB,#LUNERR,#LUNERR,,,,<ERRTBL(R0),ERRTBL+2(R0)>
	mov	2(sp),r0	;Get error number again			;hah012
	bne	40$		;Continue on 				;hah013
;									;hah013
; Print rest of id as saved from TKB on startup.			;hah013
;									;hah013
	mov	r1,-(sp)	;Save registers				;hah013
	mov	r2,-(sp)						;hah013
	sub	#10,sp		;Need some work space			;hah013
	mov	sp,r0		;Point to work buffer			;hah013
	mov	savid,r1	;Get first word				;hah013
	call	$c5ta		;Convert back to ASCII			;hah013
	mov	savid+2,r1	;Get second word			;hah013
	call	$c5ta		;Convert it				;hah013
	mov	sp,r0		;Point to buffer again			;hah013
	mov	#<<12*400>+15>,6(r0) ;Put in <CR><LF>			;hah013
	qiow$s	#io.wlb,#lunerr,#lunerr,,,,<r0,#10>			;hah013
	add	#10,sp		;Done with work space			;hah013
	mov	(sp)+,r2	;Restore registers			;hah013
	mov	(sp)+,r1						;hah013
	mov	2(sp),r0	;Get it back again			;hah013
40$:									;hah013
	bit	#400,r0		;Fatal?					;hah012
	bne	60$		;Yes, exit.				;hah012
	mov	(sp)+,r0	;Restore R0				;hah012
	tst	(sp)+		;Throw away value			;hah012
	rti								;hah012
60$:									;hah012
	EXIT$S			; EXIT THE PROGRAM
 
	.END

