home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / source / _fpinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  1.9 KB  |  88 lines

  1. #ifdef M881
  2. #include <dos.h>
  3. #include <constructor.h>
  4. #include <exec/execbase.h>
  5. #include <proto/dos.h>
  6. #endif
  7. #include <stdio.h>
  8. #include <proto/exec.h>
  9.  
  10. #ifdef FFP
  11. extern struct Library *MathBase;
  12. extern struct Library *MathTransBase;
  13. #else
  14. #ifdef IEEE
  15. extern struct Library *MathIeeeDoubBasBase;
  16. extern struct Library *MathIeeeDoubTransBase;
  17. #endif
  18. #endif
  19.  
  20. extern int (* far __ctors[])(void);
  21. extern void (* far __dtors[])(void);
  22.  
  23.  
  24. int __stdargs __fpinit(void)
  25. {
  26.    void * volatile p = &__ctors;  /* so GO won't eliminate tst */   
  27.    /* call all the autoinit routines */
  28.    if (p)
  29.    {
  30.        if ((*__ctors[-1])()) /* this function calls all the others */
  31.           return 20;
  32.    }
  33.  
  34.    return 0;
  35. }
  36.  
  37. #ifdef M881
  38. FP_CONSTRUCTOR(m881)
  39. {
  40.     extern struct ExecBase *SysBase;
  41.  
  42.     /* Check to see if an 881 is present */
  43.     if ((SysBase->AttnFlags & (1 << AFB_68881)) == 0)
  44.     {
  45.         struct DOSBase *DOSBase;
  46.         long fh;
  47.         int closefh = 0;
  48.         
  49.         DOSBase = (struct DOSBase *)OpenLibrary("dos.library",0);
  50.         fh = Output();
  51.         if (fh == NULL)
  52.         {
  53.             fh = Open(__stdiowin, MODE_NEWFILE);
  54.             closefh = 1;
  55.         }
  56.         
  57.         if (fh)
  58.         {
  59.             Write(fh, "This program requires a math co-processor\n", 42);
  60.             if (closefh)
  61.                Close(fh);
  62.         }
  63.         CloseLibrary((struct Library *)DOSBase);
  64.         return 1;  /* fail */
  65.     }
  66.  
  67.     __emit(0xf23c);        /* put out the instruction FMOVE.L #$00,FPCR */
  68.     __emit(0x9000);        /* This is Round toward nearest and use      */
  69.     __emit(0x0000);        /* Extended precision.                       */
  70.     __emit(0x0000);
  71.     
  72.     return 0;
  73. }
  74. #endif
  75.  
  76.  
  77.  
  78. void __stdargs __fpterm(void)
  79. {
  80.    void * volatile p = &__dtors;  /* so GO won't eliminate tst */   
  81.    /* call all the auto close routines */
  82.    if (p)
  83.    {
  84.        (*__ctors[-1])(); /* this function calls all the others */
  85.    }
  86.  
  87. }
  88.