home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / player / ahi / developer / lib / ahi_lib.c
Encoding:
C/C++ Source or Header  |  1996-07-12  |  1.2 KB  |  65 lines

  1. /*
  2.   These SAS/C autoopen/autoclose functions was supplied by Mattias
  3.   Karlsson. Thanks!
  4. */
  5.  
  6. #include <devices/ahi.h>
  7. #include <proto/ahi.h>
  8. #include <proto/exec.h>
  9. #include <dos.h>
  10.  
  11. extern void __regargs __autoopenfail(char *);
  12.  
  13. extern long __oslibversion;
  14.  
  15. struct Library    *AHIBase;
  16. struct MsgPort    *AHImp=NULL;
  17. struct AHIRequest *AHIio=NULL;
  18. BYTE               AHIDevice=-1;
  19.  
  20. // Autoopen rutin för ahi.
  21. int __stdargs _STI_openahi(void)
  22. {
  23.  
  24.     if(AHImp=CreateMsgPort())
  25.       {
  26.         if(AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest)))
  27.         {
  28.             AHIio->ahir_Version=2;      // Open at least version 2 of 'ahi.device'.
  29.  
  30.             if(!(AHIDevice=OpenDevice(AHINAME,AHI_NO_UNIT,(struct IORequest *)AHIio,NULL)))
  31.             {
  32.                 AHIBase=(struct Library *)AHIio->ahir_Std.io_Device;
  33.                 return 0;
  34.             }
  35.         }
  36.     }
  37.  
  38.     // Så vi får rätt version angivelse
  39.     __oslibversion=2;
  40.     __autoopenfail("ahi.device");
  41.      return 1;
  42. }
  43.  
  44. // autoclose rutin finns det oxo :)
  45. void __stdargs _STD_closeahi(void)
  46. {
  47.  
  48.     if(AHIDevice==0)
  49.     {
  50.         CloseDevice((struct IORequest *)AHIio);
  51.     }
  52.  
  53.     if(AHIio)
  54.     {
  55.       DeleteIORequest((struct IORequest *)AHIio);
  56.       AHIio=NULL;
  57.     }
  58.  
  59.     if(AHImp)
  60.     {
  61.         DeleteMsgPort(AHImp);
  62.         AHImp=NULL;
  63.     }
  64. }
  65.