Magic Cap Developer Resources

Using Magic Cap's FPU


Last Revised: 5/16/1996

What's here

You may have noticed that certain math functions are notably "missing" from Magic Cap, e.g. sin(), cos(), etc. That's because Magic Cap has a 68881 FPU emulator built-in that you can take advantage of. This page tells you how to do it.


What math functions do I get with the FPU?

Here's a list of functions that have direct 68881 instruction counterparts, excepted from the Metrowerks math.h file:

  • cos(x)
  • sin(x)
  • tan(x)
  • acos(x)
  • asin(x)
  • atan(x)
  • cosh(x)
  • sinh(x)
  • tanh(x)
  • exp(x)
  • ldexp(x,n)
  • log(x)
  • log10(x)
  • fabs(x)
  • sqrt(x)
  • fmod(x,y)

How do I use these functions in Magic Cap?

The trick that enables you to use these functions is making the Metrowerks C compiler generate inline FPU calls instead of math library calls. You'll notice from the Metrowerks math.h file that two preprocessor items must be defined for the compiler to generate FPU instructions: _INLINE_FPU_CALLS_ and __MC68881__.

__MC68881__ is defined by the Magic Cap {MagicCOptions} variable in your make file, so you don't have to worry about this one. Now you just have to define _INLINE_FPU_CALLS_. You can do this by either putting a #define at the start of all of your .c files, or by defining it in your make file. The latter option is the easiest, and it applies to all of your .c files, so that's the one we'll use as an example.

Setting up the make file

First, open your <package name here>.make file. This is the file that MPW uses when it needs to answer the question "how do I build this package?" Second, look for the following code in the file:
##### Default Rules #####
.c.o f .c
    {C} {DepDir}{Default}.c -o {Targ} {COptions} {ExtraCOptions}
Now add "-d _INLINE_FPU_CALLS" to this line along with the options. The resulting make file code should look like this:
##### Default Rules #####
.c.o f .c
	{C} {DepDir}{Default}.c -o {Targ} -d _INLINE_FPU_CALLS_ {COptions} {ExtraCOptions}
Now you should be able to use the standard math functions in the 68881 instruction set. For an example of using this functionality, see the fixed Calculator sample from the "Random Code" folder. The above archive is approximately 40K in size (stuffed and binhexed).


Tech Docs Magic Cap in Depth