e_array:	cl	-(sp)	 ;	bra	error
e_range:	mov	#0x1,-(sp) ;	bra	error
e_set:		mov	#0x2,-(sp) ;	bra	error
e_iovfl:	mov	#0x3,-(sp) ;	bra	error
e_fovfl:	mov	#0x4,-(sp) ;	bra	error
e_funfl:	mov	#0x5,-(sp) ;	bra	error
e_idivz:	mov	#0x6,-(sp) ;	bra	error
e_fdivz:	mov	#0x7,-(sp) ;	bra	error
e_iund:		mov	#0x8,-(sp) ;	bra	error
e_fund:		mov	#0x9,-(sp) ;	bra	error
e_conv:		mov	#0xA,-(sp) ;	bra	error
e_stack:	mov	#0x10,-(sp) ;	bra	fatal
e_heap:		mov	#0x11,-(sp) ;	bra	fatal
e_illins:	mov	#0x12,-(sp) ;	bra	fatal
e_oddz:		mov	#0x13,-(sp) ;	bra	fatal
e_case:		mov	#0x11,-(sp) ;	bra	fatal
e_memflt:	mov	#0x15,-(sp) ;	bra	fatal
e_badptr:	mov	#0x16,-(sp) ;	bra	fatal
e_badpc:	mov	#0x17,-(sp) ;	bra	fatal
e_badlae:	mov	#0x18,-(sp) ;	bra	error
e_badmon:	mov	#0x19,-(sp) ;	bra	error
e_badlin:	mov	#0x1A,-(sp) ;	bra 	error
e_badgto:	mov	#0x1B,-(sp) ;	bra	error

flnim:		mov	#0xB,-(sp) ;	bra	error
no8bar:		mov	#0xC,-(sp) ;	bra	error
	.define e_memflt
!---------------------------------------------------------------------------
!		ERRORS AND TRAPS
!----------------------------------------------------------------------------
fatal:		clr.l	-(sp)			!dummy return address
		pea	hlt_z			!RETURN FROM FATAL HALTS
		mov	8(sp),-(sp)

error:		movem.l	d0/d1/d2/d3/d4/d5/d6/d7/a0/a1/a2/a3/a4/a5/a6,-(sp)
		mov	60(sp),d0		!ERROR NUMBER IN d0
		lea	retsize,a5
		move.l	#16,d1
1:		move.w	-(a5),-(sp)
		dbra	d1,1b
		cmp.w	#0xB,d0
		bge	0f		!FATAL ERROR , START ERROR HANDLING
		move.l	#0x1,d1
		asl.l	d0,d1
		move.w	ignmask,d2
		not.w	d2
		and.w	d2,d1
		bne	0f
		move.l	#16,d1
		lea	retsize,a5
1:		move.w	(sp)+,(a5)+
		dbra	d1,1b
		movem.l	(sp)+,d0/d1/d2/d3/d4/d5/d6/d7/a0/a1/a2/a3/a4/a5/a6

		add.l	wrd,sp		!REMOVE ERROR NUMBER
		rts

0:		move.l	uerrorp,a0
		cmp.l	#-1,a0
		beq	notrap
		mov	d0,-(sp)
		move.l	uerrorp,-(sp)
		move.l	#-1,uerrorp		!USER MUST SET TRAP AGAIN
		bra	cai_z

!-----------------------------------------------------------------------------
rtt_z:		move.l	a2,sp
		add.l	#0x10,sp		!REMOVE RETURN STATUS BLOCK
		add.l	wrd,sp			!REMOVE  ERROR NUMBER
		move.l	#16,d0
		lea	retsize,a5
1:		move.w	(sp)+,(a5)+
		dbra	d0,1b
		movem.l	(sp)+,d0/d1/d2/d3/d4/d5/d6/d7/a0/a1/a2/a3/a4/a5/a6
		add.l	wrd,sp
		rts

trp_z:		sub.l	#4,sp
		mov	4(sp),(sp)		!COPY ERROR NUMBER
		move.l	a4,word(sp)		!RETURN ADDRESS TO MAIN LOOP
		bra	error

sig_z:		move.l	(sp),d0
		move.l	uerrorp,(sp)
		move.l	d0,uerrorp
		jmp	(a4)

	.data
uerrorp:	.long	0x-1
	.text

!-----------------------------------------------------------------------------
!FIRST INFORMATION ABOUT THE KIND OF THE ERROR
notrap:		add.l	#38,sp
		movem.l	(sp)+,d1/d2/d3/d4/d5/d6/d7/a0/a1/a2/a3/a4/a5/a6
notrap1:	comp	#28,d0			!ERROR NUMBER STILL IN d0
!still to make a routine that prints the number of a user set error
1:		mulu	#21,d0
		lea	emerr,a0
		move.l	#20,-(sp)
		pea	0(a0,d0)
		mov	#2,-(sp)		!STANDARD ERROR
		bsr	_write
		add.l	wrd+4,sp
!NEXT INFORMATION ABOUT THE LINE NUMBER
		move.l	(a6),d1
		lea	emess+14,a0
		bsr	itoa
		move.l	#30,-(sp)
		pea	emess
		mov	#2,-(sp)
		bsr	_write
		add.l	wrd+4,sp
!NOW INFORMATION ABOUT THE FILES
2:		move.l	4(a6),a0
		cmp.l	#0,a0
		beq	5f
		move.l	a0,a5
		sub.l	#4,sp
		move.l	a5,-(sp)
		move.l	#-1,d0
1:		add.l	#1,d0
		tst.b	(a5)+
		bne	1b
		move.l	d0,4(sp)
		mov	#2,-(sp)
		bsr	_write
		add.l	wrd+4,sp
5:		move.w	#0x0A,-(sp)
		move.l	#2,-(sp)
		pea	4(sp)
		mov	#2,-(sp)
		bsr	_write
		add.l	wrd+6,sp
		comp	#0xB,(sp)
		beq	1f

		move.l	#-1,argc
		clr.l	-(sp)		!dummy return address
		bra	hlt_z

1:		add.l	wrd,sp
		jmp	(a4)

!---------------------------------------------------------------------------
!		EXIT HANDLING
!--------------------------------------------------------------------------
hlt_z:		add.l	#4,sp		!remove return address
#if	prof
	.data
emprof:	.asciz	"em_profile\0"
	.align 2
	.bss
profile: .space 4
ltime:	.space 4
profsiz: .space	4
	.text
		mov	#0x1B6,-(sp)
		pea	emprof
		bsr	_creat
		testen	(sp)+
		mov	(sp)+,d0
		move.l	profsiz,-(sp)
		move.l	ltime,-(sp)		!LTIME IS POINTER AT TABLE
		mov	d0,-(sp)
		bsr	_write
		add.l	wrd+4,sp
#endif
#if flow
		mov	#0x1B6,-(sp)
		pea	emflow
		bsr	_creat
		testen	(sp)+
		mov	(sp)+,d0
		move.l	flowsiz,-(sp)
		move.l	lflow,-(sp)
		mov	d0,-(sp)
		bsr	_write
		add.l	wrd+4,sp
	.data
emflow:	.asciz	"em_flow\0"
	.align 2
	.bss
lflow:	.space 4
flowsiz: .space 4
	.text
#endif
#if	count
		mov	#0x1B6,-(sp)
		pea	emcount
		bsr	_creat
		testen	(sp)+
		mov	(sp)+,d0
		move.l	countsiz,-(sp)
		move.l	lcount,-(sp)
		mov	d0,-(sp)
		bsr	_write
		add.l	wrd+4,sp
	.data
emcount: .asciz	"em_count\0"
	.align 2
	.bss
lcount: .space 4
countsiz: .space 4
#endif
#if opfreq
	.data
emopf:	.asciz	"em_opfreq\0"
	.align
	.bss
counttab:  .space	1884
	.text
		mov	#0x1B6,-(sp)
		pea	emopf
		bsr	_creat
		testen	(sp)+
		mov	(sp)+,d0
		move.l	#1884,-(sp)
		pea	counttab
		mov	d0,-(sp)
		bsr	_write
		add.l	wrd+4,sp
#endif
#if count+flow+prof
	.bss
countfld: .space 4			!COUNT NUMBER - NUMBER OF LINE 1 OF PROC
countptr: .space 4			!COUNT NUMBER OF CURRENT LINE
#endif
#if	last
	.text
		mov	#0x1B6,-(sp)
		pea	emlast
		bsr	_creat
		testen	(sp)+
		mov	(sp)+,d6	!d6 contains file descriptor
		cmp.l	#-1,linused-4	!test if buffer is fully used
		beq	0f
		bsr	nexttab
		bra	1f
0:		lea	lasttable,a5
1:		tst.l	(a5)
		bne	2f		!exists entry in table
		move.l	#22,-(sp)	!here case no lines processed
		pea	mess1
		mov	d6,-(sp)
		bsr	_write
		add.l	wrd+4,sp
		bra	9f
2:		move.l	#7,-(sp)	!announce new file name
		pea	mess2
		mov	d6,-(sp)
		bsr	_write
		add.l	wrd+4,sp
		move.l	(a5),d7
		move.l	d7,a0		!keep file pointer in d7
		clr.l	(a5)+		!this will stop the printing
		move.l	#-1,d1		!d1 will contain length of file name
3:		add.l	#1,d1
		tst.b	(a0)+
		bne	3b
		move.l	d1,-(sp)
		move.l	d7,-(sp)
		mov	d6,-(sp)
		bsr	_write
		add.l	wrd+4,sp
4:		move.l	(a5),d1		!next print line numbers
		lea	mess3,a0
		bsr	itoa
		move.l	#12,-(sp)
		pea	mess3
		mov	d6,-(sp)
		bsr	_write
		add.l	wrd+4,sp
		bsr	nexttab
		tst.l	(a5)		!in case 0 no more lines
		beq	9f
		cmp.l	(a5),d7
		bne	2b		!new file name
		clr.l	(a5)+		!skip file name
		bra	4b		!only new line
9:
	.data
emlast:	.asciz	"em_last"
mess1:	.asciz	"no line processed yet\n"
mess2:	.asciz	"\nfile :"
mess3:	.asciz	"           \n"
	.align 2
	.bss
lasttable:  .space  128
linused:    .space  4
#endif
	.text
halt:		bsr	_exit

	.data
emerr:
.asciz	"ARRAY BOUND ERROR  \n"
.asciz	"RANGE BOUND ERROR  \n"
.asciz	"SET BOUND ERROR    \n"
.asciz	"INTEGER OVERFLOW   \n"
.asciz	"FLOATING OVERFLOW  \n"
.asciz	"FLOATING UNDERFLOW \n"
.asciz	"INT. DIV. BY ZERO  \n"
.asciz	"DIVIDE BY 0.0      \n"
.asciz	"UNDEFINED INTEGER  \n"
.asciz	"UNDEFINED FLOAT    \n"
.asciz	"CONVERSION ERROR   \n"
.asciz	"NO FLOATING POINT  \n"
.asciz	"NO 8 BYTE ARITH.   \n"
.asciz	"NO LOAD FILE       \n"
.asciz	"LOAD FILE ERROR    \n"
.asciz	"PROGRAM TOO LARGE  \n"
.asciz	"STACK OVERFLOW     \n"
.asciz	"HEAP OVERFLOW      \n"
.asciz	"ILLEGAL INSTRUCTION\n"
.asciz	"ILLEGAL SIZE ARG.  \n"
.asciz	"CASE  ERROR        \n"
.asciz	"ADDRESS NON EX. MEM\n"
.asciz	"BAD POINTER USED   \n"
.asciz	"PR COUNT. OUT RANGE\n"
.asciz	"BAD ARG. OF LAE    \n"
.asciz	"BAD MONITOR CALL   \n"
.asciz	"ARG OF LIN TOO HIGH\n"
.asciz	"GTO DESCR. ERROR   \n"
.asciz	"BAD RETURN SIZE    \n"
emess:
.asciz	"ON SOURCE LINE             OF\n"
.align 2
!-----------------------------------------------------------------------------
!	SUBROUTINES FOR THE INTERPRETOR
!------------------------------------------------------------------------------
	.text
#if	last
nexttab:	move.l  linused,a5
		add.l	#8,a5
		cmp.l	#linused,a5	!top of buffer reached?
		bne	1f		!if so back to bottom
		sub.l	#128,a5
1:		move.l	a5,linused
		rts
#endif