***fpcexp.s
*
*	Default Expection Handler for Atari FPC
*
*	void fpcexp(error)
*	int error;
*
*	Copyright 1987,1988 Atari Corporation.
*
*	MDJohnson	2/15/88
***
FPCTL	equ	$FFFFFFA42		; control register.w

	.data
_errmg:	.dc.b	"FPC Exception: $"
	.dc.b	$0,$0,$0,$0
_errno:	.dc.b	$a,$d,$0

	.text

*
* put character to screen
*
_putc:	move.w	d0,-(sp)		; push character
	move.w	#2,-(sp)		; push routine
	trap	#1			; call bios
	addq	#4,sp			; clean up
	rts

*
* convert execption code to ascii
*
_htoa:	andi.b	#$0F,d0			; mask high nibble
	addi.b	#$30,d0			; convert to ascii
	cmpi.b	#$39,d0			; is it 0 - 9?
	ble	.1			; if so done
	addi.b	#7,d0			; if not A - Z
.1:	move.b	d0,-(a0)		; store it.
	rts

*
* default execption handling routine
*
	.extern	_exit
	.globl	_fpcexp

_fpcexp:	move.w	#2,FPCTL	; acknowledge execption
	andi.w	#$3EFF,d0		; mask unrelated bits
	move.w	d0,d1			; save in d1

	move.w	#3,d2			; 4 nibbles
	move.l	#_errno,a0		; point to execption number storage
.1:	move.b	d1,d0			; put current d1 in d0
	jsr	_htoa			; convert lsn
	ror.w	#4,d1			; move next nibble to lsn
	dbra	d2,.1			; convert next
	
	move.l	#_errmg,a0		; get message to print
.2:	move.b	(a0)+,d0		; put current byte in d0
	cmpi.b	#0,d0			; is it last byte?
	beq	.3
	move.l	a0,-(sp)		; save a0
	jsr	_putc			; print character
	move.l	(sp)+,a0		; restore a0
	bra	.2

.3:	move	#1,(sp)			; push error code
	jsr	_exit			; and exit!


