home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk463.lzh / LibTool / JimsExample / AWlib.c < prev   
C/C++ Source or Header  |  1991-03-09  |  3KB  |  105 lines

  1. /**************************************************************************
  2.     AWlib.c
  3.  
  4.     A set of C routines to be turned into a library called "AW.library".
  5.     We use LibTool to make our lib startup asm code (-m option) to be linked
  6.     with this module. This creates a library. We also use LibTool to create
  7.     glue code for a C application which expects to call C library functions (-c
  8.     option). Note that this module should NOT be compiled with small code/data
  9.     because we do not bother setting up and restoring a4 (which is what you
  10.     would have to do at the start and end of each callable function).
  11.  
  12.     You may wish to make the C header file at this time, as well. Use the
  13.     LibTool option -cmho.
  14.  
  15. Manx 5.0d
  16.  
  17. LibTool -cmo glue.asm AWlib.fd        ;C function code, create lib startup code
  18. as -cd -o LibStart.o AWlib.src        ;large code and data
  19. cc -mcd0b -ff AWlib.c                    ;large code, large data, no .begin, ffp
  20. ln -o libs:AW.library LibStart.o AWlib.o -lmfl -lcl    ;large, 32 bit lib 
  21.  
  22. ***************************************************************************/
  23.  
  24. #include "exec/types.h"
  25. #include "exec/tasks.h"
  26. #include "exec/memory.h"
  27. #include "libraries/dos.h"
  28. #include "libraries/dosextens.h"
  29.  
  30. #include "math.h"
  31.  
  32. #define TO_DEGREES(x) (57.29577951*(x))
  33. #define TO_RADIANS(x) (0.0174532925*(x))
  34.  
  35. extern struct LibBase; /* this library's base */
  36.  
  37. /**************************************************************************
  38.     These are the functions which perform rectangular / polar conversions.
  39.     Angle arguments / returns are specified in degrees.
  40. ***************************************************************************/
  41.  
  42. double Mag( double real, double imaj )
  43. {
  44.     return( sqrt( real*real + imaj*imaj ) );
  45. }
  46.  
  47. double Ang( double real, double imaj )
  48. {
  49.     return( TO_DEGREES( atan( imaj / real ) ) );
  50. }
  51.  
  52. double Real( double mag, double ang )
  53. {
  54.     return( mag * cos( TO_RADIANS( ang ) ) );
  55. }
  56.  
  57. double Imaj( double mag, double ang )
  58. {
  59.     return( mag * sin( TO_RADIANS( ang ) ) );
  60. }
  61.  
  62.  
  63. /*************************************************************************
  64.     Here are the special initialization and expunge routines.
  65. ***************************************************************************/
  66.  
  67. struct MathTransBase *MathTransBase = 0L;
  68. struct MathBase *MathBase = 0L;
  69.  
  70. /**************************************************************************
  71.  This is called only once when the lib is first loaded. It just opens
  72.  mathffp.library and mathtrans.library for us. If they aren't opened, we'll
  73.  say hello to Mr. GURU. This is the Init vector function (i.e. ##init in the
  74.  fd file).
  75. ***************************************************************************/
  76.  
  77. BOOL myInit()
  78. {
  79.     if( (MathBase = (struct MathBase *)OpenLibrary("mathffp.library", 0L )) == 0 )    
  80.         return( FALSE );
  81.  
  82.     if( (MathTransBase = (struct MathTransBase *)OpenLibrary("mathtrans.library", 0L )) == 0 )
  83.     {
  84.         CloseLibrary( MathBase );
  85.         MathBase = 0L;
  86.         return( FALSE );
  87.     }
  88.  
  89.     return( TRUE );
  90. }
  91.  
  92. /**************************************************************************
  93.  This is called when the lib is expunged. It just closes the mathffp.library
  94.  and mathtrans.library for us. This is the Expu vector function (i.e. ##expu
  95.  in the fd file).
  96. ***************************************************************************/
  97.  
  98. VOID myFree()
  99. {
  100.     if( MathBase )         CloseLibrary( MathBase );
  101.     if( MathTransBase )    CloseLibrary( MathTransBase );
  102.     MathBase = 0L;
  103.     MathTransBase = 0L;
  104. }
  105.