.nlist
*
* FPMACRO: macro header for all fp modules.
*
* The macro fpidle waits for the chip to be idle.  If it isn't idle
* within $80 loops, we go to the exception handler.
*
* ckcir just reads the status once.  This is always sufficient when
* you waited for the chip to be idle before beginning the dialog.
*
* fpinit is always the first part of a function.  It begins with
* an entry point which is actually above the entry to the function;
* then the entry to the function, and the fpexists flag is checked.
* If negative, _X\name is used; if zero, the pre-fn entry point
* is jumped to, which will check for the existence of the chip.
* If the flag was positive, this will fall through, and the next
* thing in the function (usually fpidle) is hit.
*

FPCIR	equ	$FFFFFA40		; status register.w
FPCTL	equ	$FFFFFA42		; control register.w
FPSAV	equ	$FFFFFA44		; save register (unused here).w
FPREST	equ	$FFFFFA46		; restore register (unused here).w
FPOPR	equ	$FFFFFA48		; operation word register (?).w
FPCMD	equ	$FFFFFA4A		; command register.w
FPRES	equ	$FFFFFA4C		; reserved.w
FPCCR	equ	$FFFFFA4E		; condition code register.w
FPOP	equ	$FFFFFA50		; operand register.l

	.text

	.extern	_fpcexp

	.macro	fpidle			; wait for FP to be idle
	.nlist
	moveq	#$7F,d2			; timeout into d2
.I\~:	move.w	FPCIR,d0		; get response
	and.w	#$BFFF,d0		; mask PC
	cmp.w	#$0802,d0		; compare to expected
	dbeq	d2,.I\~			; pass or loop?
	beq.s	.IX\~			; succeed
	bsr	_fpcexp			; else out because of timeout.
.IX\~:
	.list
	.endm

	.macro	ckcir	value
	moveq	#$7F,d2			; timeout into d2
.\~:	move.w	FPCIR,d0		; get response
	andi.w	#$BFFF,d0		; mask PC
	cmpi.w	\value,d0		; compare to expected
	dbeq	d2,.\~			; pass or loop?
	beq.s	.1\~			; why are we out?
	bsr	_fpcexp			; jump to execption handler
.1\~:
	.endm

*	.macro	ckcir arg
*	move.w	FPCIR,d0		; don't care about the value
*	.endm

	.macro	fpinit	name

	.globl	fpcheck, fpexists, _X\name, _\name
mustcheck:
	bsr	fpcheck			; .. and fall through to test flag.

_\name:
	tst.w	fpexists		; test flag
	bmi	_X\name			; minus means use SW,
	beq.s	mustcheck		; zero means must check,
					; else fall through to hw code
	.endm
.list
