home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / Recent / mus / play / mhimdev.lha / mhimdev.library / src / library.c < prev    next >
C/C++ Source or Header  |  2001-06-03  |  4KB  |  173 lines

  1. /*****************************************************************************
  2.  
  3.     mhimdev.library - MHI driver for mpeg.device
  4.     Copyright (C) 2001  Michael Henke
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20. *****************************************************************************/
  21.  
  22.  
  23. #include <proto/exec.h>
  24. #include <exec/resident.h>
  25. #include <exec/initializers.h>
  26. #include "mhimdev.h"
  27.  
  28.  
  29. /*** don't try to run this! ***/
  30. LONG
  31. returnError(void)
  32. {
  33.     return(-1);
  34. }
  35.  
  36.  
  37. static const ULONG libInitTable[4]; /* prototype */
  38.  
  39. static const struct Resident romTag = 
  40. {
  41.     RTC_MATCHWORD,
  42.     (struct Resident *)&romTag,
  43.     (struct Resident *)libInitTable,
  44.     RTF_AUTOINIT,
  45.     VERSION,
  46.     NT_LIBRARY,
  47.     0,
  48.     LIBNAME,
  49.     IDSTRING,
  50.     (APTR)libInitTable
  51. };
  52.  
  53.  
  54.  
  55. struct LibInitData
  56. {
  57.     UBYTE i_Type;     UBYTE o_Type;     UBYTE  d_Type;     UBYTE p_Type;
  58.     UBYTE i_Name;     UBYTE o_Name;     STRPTR d_Name;
  59.     UBYTE i_Flags;    UBYTE o_Flags;    UBYTE  d_Flags;    UBYTE p_Flags;
  60.     UBYTE i_Version;  UBYTE o_Version;  UWORD  d_Version;
  61.     UBYTE i_Revision; UBYTE o_Revision; UWORD  d_Revision;
  62.     UBYTE i_IdString; UBYTE o_IdString; STRPTR d_IdString;
  63.     ULONG endmark;
  64. };
  65.  
  66.  
  67.  
  68. /*** mandatory reserved library function ***/
  69. static ULONG
  70. i_libReserved(void)
  71. {
  72.     return(0);
  73. }
  74.  
  75.  
  76.  
  77. /*** called by OpenLibrary() ***/
  78. static struct Library* __asm
  79. i_libOpen(register __a6 struct mhimdevBaseP *mybase)
  80. {
  81.     mybase->libNode.lib_Flags &= ~LIBF_DELEXP;
  82.     mybase->libNode.lib_OpenCnt++;
  83.     return(&mybase->libNode);
  84. }
  85.  
  86.  
  87.  
  88. /*** remove lib from memory ***/
  89. static BPTR __asm
  90. i_libExpunge(register __a6 struct mhimdevBaseP *mybase)
  91. {
  92.     if(mybase->libNode.lib_OpenCnt==0)
  93.     {
  94.         BPTR seglist = mybase->segList;
  95.         Remove((struct Node *) mybase);
  96.         FreeMem((STRPTR)mybase-mybase->libNode.lib_NegSize, (ULONG)(mybase->libNode.lib_NegSize+mybase->libNode.lib_PosSize));
  97.         return(seglist);
  98.     }
  99.     mybase->libNode.lib_Flags |= LIBF_DELEXP;
  100.     return(NULL);
  101. }
  102.  
  103.  
  104.  
  105. /*** called by CloseLibrary() ***/
  106. static BPTR __asm
  107. i_libClose(register __a6 struct mhimdevBaseP *mybase)
  108. {
  109.     if(!(--mybase->libNode.lib_OpenCnt))
  110.     {
  111. #ifndef DEBUG
  112.         if(mybase->libNode.lib_Flags & LIBF_DELEXP)
  113. #endif
  114.             return(i_libExpunge(mybase));
  115.     }
  116.     return(0);
  117. }
  118.  
  119.  
  120.  
  121. /*** initialize library ***/
  122. static struct Library* __asm
  123. i_libInit(register __a0 BPTR seglist, register __d0 struct mhimdevBaseP *mybase, register __a6 struct ExecBase *SysBase)
  124. {
  125.     mybase->segList = seglist;
  126.     return(&mybase->libNode);   /* ok */
  127. }
  128.  
  129.  
  130.  
  131. static const APTR libVectors[] =
  132. {
  133.     (APTR) i_libOpen,
  134.     (APTR) i_libClose,
  135.     (APTR) i_libExpunge,
  136.     (APTR) i_libReserved,
  137.     (APTR) i_MHIAllocDecoder,
  138.     (APTR) i_MHIFreeDecoder,
  139.     (APTR) i_MHIQueueBuffer,
  140.     (APTR) i_MHIGetEmpty,
  141.     (APTR) i_MHIGetStatus,
  142.     (APTR) i_MHIPlay,
  143.     (APTR) i_MHIStop,
  144.     (APTR) i_MHIPause,
  145.     (APTR) i_MHIQuery,
  146.     (APTR) i_MHISetParam,
  147.     (APTR) -1
  148. };
  149.  
  150.  
  151.  
  152. static const struct LibInitData libInitData =
  153. {
  154.     0xA0, (UBYTE) OFFSET(Node,    ln_Type),      NT_LIBRARY,                   0,
  155.     0x80, (UBYTE) OFFSET(Node,    ln_Name),      LIBNAME,
  156.     0xA0, (UBYTE) OFFSET(Library, lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED,    0,
  157.     0x90, (UBYTE) OFFSET(Library, lib_Version),  VERSION,
  158.     0x90, (UBYTE) OFFSET(Library, lib_Revision), REVISION,
  159.     0x80, (UBYTE) OFFSET(Library, lib_IdString), IDSTRING,
  160.     0
  161. };
  162.  
  163.  
  164.  
  165. static const ULONG libInitTable[4] =
  166. {
  167.     (ULONG)sizeof(struct mhimdevBaseP),
  168.     (ULONG)libVectors,
  169.     (ULONG)&libInitData,
  170.     (ULONG)i_libInit
  171. };
  172.  
  173.