*** modf.s
* 	Double Precision Modulo
*	for Alcyon C
*
*	double modf(d,*ptr)
*	double d, *ptr;
*
*	Copyright Atari Corp. 1987,1988
*
*	MDJohnson       2/15/88
***

	.include fpmacro

; modf(x,*y)
	fpinit	modf
	fpidle				; wait for idle state
;
; This procedure stores intrz(x) in *y and returns x-intrz(x).
;
; It's actually computed as follows:
;	fp0 = intrz(x);
;	*y = fp0;
;	x *= -1;		(change mantissa sign bit)
;	fp0 += x;
;	return fp0;
;
; It's done the way it is so we use only FP register 0.
;

	move.w	#$5403,FPCMD		; intrz(x) -> fp0
	ckcir	#$9608			; ready for double
	move.l	4(sp),FPOP		; write first half
	move.l	8(sp),FPOP		; write second half

	fpidle				; wait for idle state
	move.w	#$7400,FPCMD		; fp0 -> double
	move.l	12(sp),a0		; get pointer
	ckcir	#$B208			; ready for double
	move.l	FPOP,(a0)+		; get double
	move.l	FPOP,(a0)

	fpidle				; wait for idle state
	bchg.b	#7,$4(sp)		; negate argument
	move.w	#$5422,FPCMD		; fp0 += #data
	ckcir	#$9608
	move.l	4(sp),FPOP
	move.l	8(sp),FPOP

	fpidle				; wait for idle state
	move.w	#$7400,FPCMD		; fp0 -> double
	ckcir	#$B208			; ready for double
	move.l	FPOP,d0			; get double
	move.l	FPOP,d1
	rts
