revert between 56095 -> 55830 in arch
[AROS.git] / workbench / classes / datatypes / sound / library.c
blob639991832744fdac64e1a1e92013d77e19ade0bf
2 /*
3 **
4 ** sound.datatype v41
5 ** © 1998/99 by Stephan Rupprecht
6 ** All Rights reserved
7 **
8 */
10 #include <exec/resident.h>
11 #include <exec/initializers.h>
12 #include <exec/execbase.h>
13 #include <exec/libraries.h>
14 #include <datatypes/soundclass.h>
16 #ifdef __MAXON__
17 #include <pragma/exec_lib.h>
18 #include <pragma/intuition_lib.h>
19 #include <pragma/dos_lib.h>
20 #include <pragma/utility_lib.h>
21 #include <pragma/datatypes_lib.h>
22 #else
23 #include <inline/exec.h>
24 #include <inline/intuition.h>
25 #include <inline/dos.h>
26 #include <inline/utility.h>
27 #include <inline/datatypes.h>
28 #endif
30 #include "classbase.h"
32 #ifndef __MAXON__
33 #include "CompilerSpecific.h"
34 #endif
36 /****************************************************************************/
38 #define BPTR ULONG
40 #ifdef __MAXON__
41 #define REG(r, a) register __## r a
42 #define __regargs
43 #endif
45 #define VERSION 41
46 #define REVISION 11
47 #define VERSIONSTR "41.11"
48 #define DATE "11.08.00"
50 /****************************************************************************/
52 STATIC struct Library *LibInit(REG(a0, ULONG Segment), REG(d0, struct ClassBase *ClassBase), REG(a6, struct Library *) );
53 STATIC struct Library *LibOpen( REG(a6, struct ClassBase *ClassBase) );
54 STATIC ULONG LibExpunge( REG(a6, struct ClassBase *ClassBase) );
55 STATIC ULONG LibClose( REG(a6, struct ClassBase *ClassBase) );
56 STATIC LONG LibExtFunc(void);
58 BOOL __regargs L_OpenLibs(struct ClassBase *);
59 void __regargs L_CloseLibs(struct ClassBase *);
60 Class * __regargs initClass (struct ClassBase *);
61 Class * ObtainClass( REG(a6, struct ClassBase *) );
63 extern ULONG Dispatch( REG(a0, Class *), REG(a2, Object *), REG(a1, Msg) );
65 /****************************************************************************/
67 UBYTE LibName[] = "v41sound.datatype",
68 LibID[] = "v41sound.datatype "VERSIONSTR" ("DATE") © 1998-2000 by Stephan Rupprecht";
70 LONG LibVersion = VERSION,
71 LibRevision = REVISION;
73 APTR LibVectors[] =
75 (APTR) LibOpen,
76 (APTR) LibClose,
77 (APTR) LibExpunge,
78 (APTR) LibExtFunc,
79 (APTR) ObtainClass,
80 (APTR) -1L
83 ULONG LibInitTab[] =
85 (ULONG) sizeof(struct ClassBase),
86 (ULONG) LibVectors,
87 (ULONG) NULL,
88 (ULONG) LibInit
91 struct Resident ROMTag = /* do not change */
93 RTC_MATCHWORD,
94 &ROMTag,
95 &ROMTag + 1L,
96 RTF_AUTOINIT,
97 VERSION,
98 NT_LIBRARY,
100 LibName,
101 LibID,
102 (APTR) LibInitTab
105 /****************************************************************************/
107 LONG dummy(void)
109 return(-1L);
112 /****************************************************************************/
114 LONG LibExtFunc(void)
116 return(0L);
119 /****************************************************************************/
121 #ifndef __MAXON__
122 #define IntuitionBase cb->cb_IntuitionBase
123 #define GfxBase cb->cb_GfxBase
124 #define DOSBase cb->cb_DOSBase
125 #define SysBase cb->cb_SysBase
126 #define DataTypesBase cb->cb_DataTypesBase
127 #define UtilityBase cb->cb_UtilityBase
128 #define IFFParseBase cb->cb_IFFParseBase
129 #define TapeDeckBase cb->cb_TapeDeckBase
130 #else
131 struct Library *DOSBase, *SysBase, *DataTypesBase, *TapeDeckBase,
132 *IntuitionBase, *GfxBase, *UtilityBase, *IFFParseBase;
133 #endif
135 /****************************************************************************/
137 struct Library *
138 LibInit( REG(a0, ULONG Segment), REG(d0, struct ClassBase *cb), REG(a6, struct Library *ExecBase) )
140 SysBase = ExecBase;
142 InitSemaphore( &cb->cb_LibLock );
143 ObtainSemaphore( &cb->cb_LibLock );
145 cb->LibSegment = Segment;
146 cb->LibNode.lib_Revision = REVISION;
148 if( ((struct ExecBase *)ExecBase)->AttnFlags & AFF_68020 )
150 if(L_OpenLibs(cb))
152 if(cb->cb_Class = initClass(cb))
154 ReleaseSemaphore( &cb->cb_LibLock );
155 return((struct Library *)cb);
160 L_CloseLibs( cb );
162 ReleaseSemaphore( &cb->cb_LibLock );
164 FreeMem((BYTE *)cb-cb->LibNode.lib_NegSize,
165 cb->LibNode.lib_NegSize + cb->LibNode.lib_PosSize);
167 return(NULL);
170 /****************************************************************************/
172 struct Library *LibOpen( REG(a6, struct ClassBase *cb) )
174 ObtainSemaphore( &cb->cb_LibLock );
175 cb->LibNode.lib_Flags &= ~LIBF_DELEXP;
176 cb->LibNode.lib_OpenCnt++;
177 ReleaseSemaphore( &cb->cb_LibLock );
178 return((struct Library *)cb);
181 /****************************************************************************/
183 ULONG LibExpunge( REG(a6, struct ClassBase *cb) )
185 ULONG retval = 0L;
187 ObtainSemaphore( &cb->cb_LibLock );
189 if(!cb->LibNode.lib_OpenCnt)
191 if(cb->cb_Class)
193 if( ! FreeClass(cb->cb_Class) )
195 AddClass( cb->cb_Class );
196 ReleaseSemaphore( &cb->cb_LibLock );
197 return( NULL );
200 #ifdef __GNUC__
201 if( DataTypesBase->lib_Version >= 45L )
203 FreeDTMethods( cb->cb_Methods );
205 #else
206 FreeVec( cb->cb_Methods );
207 #endif
209 L_CloseLibs(cb);
211 Remove((struct Node *)cb);
213 FreeMem((BYTE *)cb-cb->LibNode.lib_NegSize,
214 cb->LibNode.lib_NegSize + cb->LibNode.lib_PosSize);
216 retval = cb->LibSegment;
218 else
220 cb->LibNode.lib_Flags |= LIBF_DELEXP;
223 ReleaseSemaphore( &cb->cb_LibLock );
225 return( retval );
228 /****************************************************************************/
230 ULONG LibClose( REG(a6, struct ClassBase *cb) )
232 ULONG retval = 0L;
234 ObtainSemaphore( &cb->cb_LibLock );
236 if( ! cb->LibNode.lib_OpenCnt || ! --cb->LibNode.lib_OpenCnt )
238 if( cb->LibNode.lib_Flags & LIBF_DELEXP )
240 retval = LibExpunge( cb );
244 ReleaseSemaphore( &cb->cb_LibLock );
246 return( retval );
249 /****************************************************************************/
251 BOOL __regargs L_OpenLibs( struct ClassBase *cb )
253 if( ( DOSBase = OpenLibrary( "dos.library", 0L ) ) &&
254 ( IntuitionBase = OpenLibrary( "intuition.library", 0L ) ) &&
255 ( GfxBase = OpenLibrary( "graphics.library", 0L ) ) &&
256 ( DataTypesBase = OpenLibrary( "datatypes.library", 0L ) ) &&
257 ( UtilityBase = OpenLibrary( "utility.library", 0L ) ) &&
258 ( IFFParseBase = OpenLibrary( "iffparse.library", 0L ) ) )
260 TapeDeckBase = OpenLibrary( "gadgets/tapedeck.gadget", 39L );
261 return TRUE;
264 return FALSE;
267 /****************************************************************************/
269 Class * __regargs initClass ( struct ClassBase *cb )
271 register Class *cl;
273 if(cl = MakeClass(LibName, DATATYPESCLASS, NULL, sizeof( struct InstanceData ), 0L))
275 cl->cl_Dispatcher.h_Entry = (HOOKFUNC) Dispatch;
276 cl->cl_UserData = (ULONG) cb;
277 AddClass(cl);
280 return (cl);
283 /****************************************************************************/
285 void __regargs L_CloseLibs( struct ClassBase *cb )
287 CloseLibrary( DOSBase );
288 CloseLibrary( IntuitionBase );
289 CloseLibrary( GfxBase );
290 CloseLibrary( DataTypesBase );
291 CloseLibrary( UtilityBase );
292 CloseLibrary( IFFParseBase );
293 CloseLibrary( TapeDeckBase );
296 /****************************************************************************/
298 Class *ObtainClass( REG(a6, struct ClassBase *cb) )
300 Class *cl;
302 ObtainSemaphoreShared( &cb->cb_LibLock );
303 cl = cb->cb_Class;
304 ReleaseSemaphore( &cb->cb_LibLock );
306 return cl;
309 /****************************************************************************/