/* Number of iterations before an error is triggered */
#define FPCOUNT    	0x80		

#define FPCIR	    	((WORD *)(0xFFFFFA40L))
#define FPCMD	    	((WORD *)(0xFFFFFA4AL))
#define FPOP	    	((float *)(0xFFFFFA50L))

WORD fpcount, dum;

/* fperr() is user-defined */

#define FPwait() { 	fpcount = FPCOUNT; \
					while((*FPCIR & 0xBFFF) != 0x0802) \
						if(!(--fpcount)) fperr();	 }

#define FPsglset(r,v) { FPwait(); \
					  *FPCMD = (0x5400 | ((r) << 7)); \
					  while((*FPCIR & 0xFFF0) != 0x8C00) \
						if(!(--fpcount)) fperr();		\
					  *FPOP = (v); }

#define FPsglmul(r1,r2) { 	FPwait();	\
						*FPCMD = (0x0027 | ((r2) << 10) | ((r1) << 7));		\
						dum = *FPCIR + 1;	}

/* dum = FPCIR +1; forces the status register to be read
   (we assume the data's good) */

#define FPsglget(r,var) {	FPwait();	\
						*FPCMD = (0x6400 | ((r) << 7));		\
						while(*FPCIR != 0xb104)		\
							if(!(--fpcount)) fperr();		\
						var = *FPOP;		}							

/*
 * void sglmul( float *f1, float *f2 );
 *
 * Multiplies f1 by f2. Returns result in f1.
 *
 */

void
sglmul( float &f1, float &f2 )
{
	FPsglset( 0, *f1 );
	FPsglset( 1, *f2 );
	FPsglmul( 0, 1 );
	FPsglget( 0, *f1 );
}
