2 Copyright (C) 2003, The AROS Development Team.
7 This file provides the library initialization for OS4
13 #include <exec/types.h>
14 #include <proto/exec.h>
15 #include <proto/utility.h>
16 #include <proto/muimaster.h>
18 #include "muimaster_intern.h"
25 #define VSTRING "zunemaster.library 0.1 (25.02.2005)"
26 //#include "zunemaster.library_rev.h"
28 struct Library
*DataTypesBase
;
29 struct Library
*TextClibBase
;
30 struct Library
*MUIMasterBase
; /* this library */
32 struct Interface
*IGraphics
;
33 struct IntuitionIFace
*IIntuition
;
34 struct UtilityIFace
*IUtility
;
35 struct Interface
*ILayers
;
36 struct Interface
*IGadTools
;
37 struct Interface
*ICyberGfx
;
38 struct Interface
*ICommodities
;
39 struct Interface
*IIFFParse
;
40 struct Interface
*IDiskfont
;
41 struct Interface
*ITextClip
;
42 struct DOSIFace
*IDOS
;
43 struct Interface
*IAsl
;
44 struct Interface
*IKeymap
;
45 struct Interface
*IDataTypes
;
46 struct Interface
*IIcon
;
47 struct ZuneMasterIFace
*IZuneMaster
;
49 static struct SignalSemaphore OpenSemaphore
;
51 /*************************************************************************
53 *************************************************************************/
59 /*************************************************************************
60 Open a library and its interface easily
61 *************************************************************************/
62 struct Library
*OpenLibraryInterface(STRPTR name
, int version
, void *interface_ptr
)
64 struct Library
*lib
= IExec
->OpenLibrary(name
,version
);
65 struct Interface
*iface
;
66 if (!lib
) return NULL
;
68 iface
= IExec
->GetInterface(lib
,"main",1,NULL
);
71 IExec
->CloseLibrary(lib
);
74 *((struct Interface
**)interface_ptr
) = iface
;
78 /*************************************************************************
79 Close a library and its interface easily
80 *************************************************************************/
81 void CloseLibraryInterface(struct Library
*lib
, void *interface
)
83 IExec
->DropInterface(interface
);
84 IExec
->CloseLibrary(lib
);
88 /*************************************************************************
89 Deinitialize the custom library base
90 *************************************************************************/
91 static void DeinitCustomLibraryBase(struct MUIMasterBase_intern
*libBase
)
93 CloseLibraryInterface((struct Library
*)libBase
->utilitybase
,IUtility
);
94 CloseLibraryInterface((struct Library
*)libBase
->dosbase
,IDOS
);
95 CloseLibraryInterface((struct Library
*)libBase
->gfxbase
,IGraphics
);
96 CloseLibraryInterface(libBase
->aslbase
,IAsl
);
97 CloseLibraryInterface(libBase
->layersbase
,ILayers
);
98 CloseLibraryInterface((struct Library
*)libBase
->intuibase
,IIntuition
);
99 CloseLibraryInterface((struct Library
*)libBase
->cxbase
,ICommodities
);
100 CloseLibraryInterface(libBase
->gadtoolsbase
,IGadTools
);
101 CloseLibraryInterface(libBase
->keymapbase
,IKeymap
);
102 CloseLibraryInterface(DataTypesBase
,IDataTypes
);
103 CloseLibraryInterface(libBase
->iffparsebase
,IIFFParse
);
104 CloseLibraryInterface(libBase
->diskfontbase
,IDiskfont
);
105 CloseLibraryInterface(libBase
->iconbase
,IIcon
);
108 /*************************************************************************
109 Initialize the custom library base
110 *************************************************************************/
111 static int InitCustomLibraryBase(struct MUIMasterBase_intern
*libBase
)
113 MUIMB(libBase
)->sysbase
= (struct ExecBase
*)SysBase
;
114 if (!(MUIMB(libBase
)->utilitybase
= (void*)OpenLibraryInterface("utility.library",50,&IUtility
)))
116 if (!(MUIMB(libBase
)->dosbase
= (void*)OpenLibraryInterface("dos.library",50,&IDOS
)))
118 if (!(MUIMB(libBase
)->gfxbase
= (void*)OpenLibraryInterface("graphics.library",50,&IGraphics
)))
120 if (!(MUIMB(libBase
)->aslbase
= OpenLibraryInterface("asl.library",50,&IAsl
)))
122 if (!(MUIMB(libBase
)->layersbase
= OpenLibraryInterface("layers.library",50,&ILayers
)))
124 if (!(MUIMB(libBase
)->intuibase
= (void*)OpenLibraryInterface("intuition.library",50,&IIntuition
)))
126 if (!(MUIMB(libBase
)->cxbase
= OpenLibraryInterface("commodities.library",50,&ICommodities
)))
128 if (!(MUIMB(libBase
)->gadtoolsbase
= OpenLibraryInterface("gadtools.library",37,&IGadTools
)))
130 if (!(MUIMB(libBase
)->keymapbase
= OpenLibraryInterface("keymap.library",37,&IKeymap
)))
132 if (!(DataTypesBase
= OpenLibraryInterface("datatypes.library",39,&IDataTypes
)))
134 if (!(MUIMB(libBase
)->iffparsebase
= OpenLibraryInterface("iffparse.library",39,&IIFFParse
)))
136 if (!(MUIMB(libBase
)->diskfontbase
= OpenLibraryInterface("diskfont.library",39,&IDiskfont
)))
138 if (!(MUIMB(libBase
)->iconbase
= OpenLibraryInterface("icon.library",39,&IIcon
)))
141 /* continue even if cybergraphics.library is not available */
142 MUIMB(libBase
)->cybergfxbase
= OpenLibraryInterface("cybergraphics.library",39,&ICyberGfx
);
144 #ifdef HAVE_COOLIMAGES
145 MUIMB(libbase
)->coolimagesbase
= OpenLibraryInterface("coolimages.library",0,&ICoolImages
);
148 IExec
->InitSemaphore(&MUIMB(libBase
)->ZuneSemaphore
);
150 IExec
->NewMinList(&MUIMB(libBase
)->BuiltinClasses
);
151 IExec
->NewMinList(&MUIMB(libBase
)->Applications
);
154 DeinitCustomLibraryBase(libBase
);
158 /****************************************************************************/
160 struct Library
*libOpen(struct LibraryManagerInterface
*Self
, ULONG version
)
162 struct Library
*libBase
= (struct Library
*)Self
->Data
.LibBase
;
164 /* Add any specific open code here
165 * Return 0 before incrementing OpenCnt to fail opening */
166 IExec
->ObtainSemaphore(&OpenSemaphore
);
168 if (libBase
->lib_OpenCnt
== 0)
169 IZuneMaster
= (struct ZuneMasterIFace
*)IExec
->GetInterface(libBase
,"main",1,NULL
);
171 /* Add up the open count */
173 libBase
->lib_OpenCnt
++;
176 IExec
->ReleaseSemaphore(&OpenSemaphore
);
181 /* Close the library */
182 APTR
libClose(struct LibraryManagerInterface
*Self
)
184 struct Library
*libBase
= (struct Library
*)Self
->Data
.LibBase
;
185 /* Make sure to undo what open did */
186 IExec
->ObtainSemaphore(&OpenSemaphore
);
187 /* Make the close count */
188 libBase
->lib_OpenCnt
--;
189 if (libBase
->lib_OpenCnt
== 0)
191 IExec
->DropInterface((struct Interface
*)IZuneMaster
);
194 IExec
->ReleaseSemaphore(&OpenSemaphore
);
198 /* Expunge the library */
199 APTR
libExpunge(struct LibraryManagerInterface
*Self
)
201 /* If your library cannot be expunged, return 0 */
202 struct ExecIFace
*IExec
= (struct ExecIFace
*)(*(struct ExecBase
**)4)->MainInterface
;
203 APTR result
= (APTR
)0;
204 struct Library
*libBase
= (struct Library
*)Self
->Data
.LibBase
;
206 if (libBase
->lib_OpenCnt
== 0)
208 result
= (APTR
)MUIMB(libBase
)->seglist
;
210 DeinitCustomLibraryBase(MUIMB(libBase
));
212 IExec
->Remove((struct Node
*)libBase
);
213 IExec
->DeleteLibrary(libBase
);
218 libBase
->lib_Flags
|= LIBF_DELEXP
;
223 /* The ROMTAG Init Function */
224 struct Library
*libInit(struct Library
*libBase
, APTR seglist
, struct Interface
*exec
)
226 IExec
= (struct ExecIFace
*)exec
;
227 SysBase
= exec
->Data
.LibBase
;
229 if ((SysBase
->lib_Version
< 51) || (SysBase
->lib_Version
== 51 && SysBase
->lib_Revision
< 19))
232 libBase
->lib_Node
.ln_Type
= NT_LIBRARY
;
233 libBase
->lib_Node
.ln_Pri
= 0;
234 libBase
->lib_Node
.ln_Name
= "zunemaster.library";
235 libBase
->lib_Flags
= LIBF_SUMUSED
|LIBF_CHANGED
;
236 libBase
->lib_Version
= VERSION
;
237 libBase
->lib_Revision
= REVISION
;
238 libBase
->lib_IdString
= VSTRING
;
241 MUIMB(libBase
)->seglist
= (BPTR
)seglist
;
243 IExec
->InitSemaphore(&OpenSemaphore
);
245 if (!InitCustomLibraryBase(MUIMB(libBase
)))
248 /* Store the libraries base */
249 MUIMasterBase
= libBase
;
253 DeinitCustomLibraryBase(MUIMB(libBase
));
257 /* ----------- Implementation of main Interface ----------------- */
258 ASM APTR
LIB_MUI_AddClipping(REG(a0
, struct MUI_RenderInfo
*mri
), REG(d0
, WORD left
), REG(d1
, WORD top
), REG(d2
, WORD width
), REG(d3
, WORD height
));
259 ASM APTR
LIB_MUI_AddClipRegion(REG(a0
,struct MUI_RenderInfo
*mri
), REG(a1
, struct Region
*r
));
260 ASM APTR
LIB_MUI_AllocAslRequest(REG(d0
,unsigned long reqType
), REG(a0
,struct TagItem
*tagList
));
261 ASM BOOL
LIB_MUI_AslRequest(REG(a0
, APTR requester
), REG(a1
, struct TagItem
*tagList
));
262 ASM BOOL
LIB_MUI_BeginRefresh(REG(a0
, struct MUI_RenderInfo
*mri
), REG(d0
, ULONG flags
));
263 ASM
struct MUI_CustomClass
*LIB_MUI_CreateCustomClass(REG(a0
, struct Library
*base
), REG(a1
, char *supername
), REG(a2
, struct MUI_CustomClass
*supermcc
), REG(d0
,int datasize
), REG(a3
, APTR dispatcher
));
264 ASM BOOL
LIB_MUI_DeleteCustomClass(REG(a0
,struct MUI_CustomClass
*mcc
));
265 ASM VOID
LIB_MUI_DisposeObject(REG(a0
,Object
*obj
));
266 ASM VOID
LIB_MUI_EndRefresh(REG(a0
, struct MUI_RenderInfo
*mri
), REG(d0
, ULONG flags
));
267 ASM LONG
LIB_MUI_Error(VOID
);
268 ASM VOID
LIB_MUI_FreeAslRequest(REG(a0
, APTR requester
));
269 ASM VOID
LIB_MUI_FreeClass(REG(a0
, struct IClass
*classptr
));
270 ASM
struct IClass
*LIB_MUI_GetClass(REG(a0
,char *classname
));
271 ASM BOOL
LIB_MUI_Layout(REG(a0
,Object
*obj
), REG(d0
, LONG left
), REG(d1
,LONG top
), REG(d2
,LONG width
), REG(d3
,LONG height
), REG(d4
, ULONG flags
));
272 ASM Object
*LIB_MUI_MakeObjectA(REG(d0
, LONG type
), REG(a0
, ULONG
*params
));
273 ASM Object
*LIB_MUI_NewObjectA(REG(a0
, char *classname
), REG(a1
, struct TagItem
*tags
));
274 ASM LONG
LIB_MUI_ObtainPen(REG(a0
, struct MUI_RenderInfo
*mri
), REG(a1
, struct MUI_PenSpec
*spec
), REG(d0
, ULONG flags
));
275 ASM VOID
LIB_MUI_Redraw(REG(a0
, Object
*obj
), REG(d0
, ULONG flags
));
276 ASM VOID
LIB_MUI_RejectIDCMP(REG(a0
, Object
*obj
), REG(d0
, ULONG flags
));
277 ASM VOID
LIB_MUI_ReleasePen(REG(a0
, struct MUI_RenderInfo
*mri
), REG(d0
, LONG pen
));
278 ASM VOID
LIB_MUI_RemoveClipping(REG(a0
, struct MUI_RenderInfo
*mri
), REG(a1
,APTR handle
));
279 ASM VOID
LIB_MUI_RemoveClipRegion(REG(a0
, struct MUI_RenderInfo
*mri
), REG(a1
, APTR handle
));
280 ASM LONG
LIB_MUI_RequestA(REG(d0
, APTR app
), REG(d1
, APTR win
), REG(d2
, LONGBITS flags
), REG(a0
, CONST_STRPTR title
), REG(a1
, CONST_STRPTR gadgets
), REG(a2
, CONST_STRPTR format
), REG(a3
, APTR params
));
281 ASM VOID
LIB_MUI_RequestIDCMP(REG(a0
, Object
*obj
), REG(d0
, ULONG flags
));
282 ASM LONG
LIB_MUI_SetError(REG(d0
,LONG num
));
284 ULONG VARARGS68K
_ZuneMaster_Obtain(struct ZuneMasterIFace
*Self
)
286 return Self
->Data
.RefCount
++;
289 ULONG VARARGS68K
_ZuneMaster_Release(struct ZuneMasterIFace
*Self
)
291 return Self
->Data
.RefCount
++;
294 Object
*VARARGS68K
_ZuneMaster_MUI_NewObjectA(struct ZuneMasterIFace
*iface
, CONST_STRPTR classname
, struct TagItem
* tags
)
296 return LIB_MUI_NewObjectA((STRPTR
)classname
, tags
);
299 Object
*VARARGS68K
_ZuneMaster_MUI_NewObject(struct ZuneMasterIFace
*Self
, CONST_STRPTR classname
, ...)
303 struct TagItem
*tags
;
305 va_startlinear(ap
, classname
);
306 tags
= va_getlinearva(ap
, struct TagItem
*);
307 obj
= Self
->MUI_NewObjectA(classname
, tags
);
312 VOID VARARGS68K
_ZuneMaster_MUI_DisposeObject(struct ZuneMasterIFace
*iface
, Object
* obj
)
314 LIB_MUI_DisposeObject(obj
);
317 LONG VARARGS68K
_ZuneMaster_MUI_RequestA(struct ZuneMasterIFace
*iface
, APTR app
, APTR win
, ULONG flags
, CONST_STRPTR title
, CONST_STRPTR gadgets
, CONST_STRPTR format
, APTR params
)
319 return LIB_MUI_RequestA(app
, win
, flags
, title
, gadgets
, format
, params
);
322 LONG VARARGS68K
_ZuneMaster_MUI_Request(struct ZuneMasterIFace
*Self
, APTR app
, APTR win
, ULONG flags
, CONST_STRPTR title
, CONST_STRPTR gadgets
, CONST_STRPTR format
, ...)
328 va_startlinear(ap
, format
);
329 params
= va_getlinearva(ap
, APTR
);
330 res
= Self
->MUI_RequestA(app
,win
,flags
,title
,gadgets
,format
,params
);
335 APTR VARARGS68K
_ZuneMaster_MUI_AllocAslRequest(struct ZuneMasterIFace
*iface
, ULONG reqType
, struct TagItem
* tagList
)
337 return LIB_MUI_AllocAslRequest(reqType
,tagList
);
340 APTR VARARGS68K
_ZuneMaster_MUI_AllocAslRequestTags(struct ZuneMasterIFace
*Self
, ULONG reqType
, ...)
344 struct TagItem
*tags
;
346 va_startlinear(ap
, reqType
);
347 tags
= va_getlinearva(ap
, struct TagItem
*);
348 res
= Self
->MUI_AllocAslRequest(reqType
, tags
);
353 BOOL VARARGS68K
_ZuneMaster_MUI_AslRequest(struct ZuneMasterIFace
*iface
, APTR requester
, struct TagItem
* tagList
)
355 return LIB_MUI_AslRequest(requester
, tagList
);
358 BOOL VARARGS68K
_ZuneMaster_MUI_AslRequestTags(struct ZuneMasterIFace
*Self
, APTR requester
, ...)
362 struct TagItem
*tags
;
364 va_startlinear(ap
, requester
);
365 tags
= va_getlinearva(ap
, struct TagItem
*);
366 res
= Self
->MUI_AslRequest(requester
, tags
);
371 VOID VARARGS68K
_ZuneMaster_MUI_FreeAslRequest(struct ZuneMasterIFace
*iface
, APTR requester
)
373 LIB_MUI_FreeAslRequest(requester
);
376 LONG VARARGS68K
_ZuneMaster_MUI_Error(struct ZuneMasterIFace
*iface
)
378 return LIB_MUI_Error();
381 LONG VARARGS68K
_ZuneMaster_MUI_SetError(struct ZuneMasterIFace
*iface
, LONG num
)
383 return LIB_MUI_SetError(num
);
386 struct IClass
*VARARGS68K
_ZuneMaster_MUI_GetClass(struct ZuneMasterIFace
*iface
, CONST_STRPTR classname
)
388 return LIB_MUI_GetClass((STRPTR
)classname
);
391 VOID VARARGS68K
_ZuneMaster_MUI_FreeClass(struct ZuneMasterIFace
*iface
, struct IClass
* classptr
)
393 LIB_MUI_FreeClass(classptr
);
396 VOID VARARGS68K
_ZuneMaster_MUI_RequestIDCMP(struct ZuneMasterIFace
*iface
, Object
* obj
, ULONG flags
)
398 LIB_MUI_RequestIDCMP(obj
,flags
);
401 VOID VARARGS68K
_ZuneMaster_MUI_RejectIDCMP(struct ZuneMasterIFace
*iface
, Object
* obj
, ULONG flags
)
403 LIB_MUI_RejectIDCMP(obj
,flags
);
406 VOID VARARGS68K
_ZuneMaster_MUI_Redraw(struct ZuneMasterIFace
*iface
, Object
* obj
, ULONG flags
)
408 LIB_MUI_Redraw(obj
,flags
);
411 struct MUI_CustomClass
*VARARGS68K
_ZuneMaster_MUI_CreateCustomClass(struct ZuneMasterIFace
*iface
, struct Library
* base
, CONST_STRPTR supername
, struct MUI_CustomClass
* supermcc
, LONG datasize
, APTR dispatcher
)
413 return LIB_MUI_CreateCustomClass(base
,(STRPTR
)supername
,supermcc
,datasize
,dispatcher
);
416 BOOL VARARGS68K
_ZuneMaster_MUI_DeleteCustomClass(struct ZuneMasterIFace
*iface
, struct MUI_CustomClass
* mcc
)
418 return LIB_MUI_DeleteCustomClass(mcc
);
421 Object
*VARARGS68K
_ZuneMaster_MUI_MakeObjectA(struct ZuneMasterIFace
*iface
, LONG type
, ULONG
* params
)
423 return LIB_MUI_MakeObjectA(type
,params
);
426 Object
*VARARGS68K
_ZuneMaster_MUI_MakeObject(struct ZuneMasterIFace
*Self
, LONG type
, ...)
432 va_startlinear(ap
, type
);
433 params
= va_getlinearva(ap
, ULONG
*);
434 res
= Self
->MUI_MakeObjectA(type
,params
);
440 BOOL VARARGS68K
_ZuneMaster_MUI_Layout(struct ZuneMasterIFace
*iface
, Object
* obj
, LONG left
, LONG top
, LONG width
, LONG height
, ULONG flags
)
442 return LIB_MUI_Layout(obj
,left
,top
,width
,height
,flags
);
445 LONG VARARGS68K
_ZuneMaster_MUI_ObtainPen(struct ZuneMasterIFace
*iface
, struct MUI_RenderInfo
* mri
, struct MUI_PenSpec
* spec
, ULONG flags
)
447 return LIB_MUI_ObtainPen(mri
,spec
,flags
);
450 VOID VARARGS68K
_ZuneMaster_MUI_ReleasePen(struct ZuneMasterIFace
*iface
, struct MUI_RenderInfo
* mri
, LONG pen
)
452 LIB_MUI_ReleasePen(mri
,pen
);
455 APTR VARARGS68K
_ZuneMaster_MUI_AddClipping(struct ZuneMasterIFace
*iface
, struct MUI_RenderInfo
* mri
, WORD left
, WORD top
, WORD width
, WORD height
)
457 return LIB_MUI_AddClipping(mri
,left
,top
,width
,height
);
460 VOID VARARGS68K
_ZuneMaster_MUI_RemoveClipping(struct ZuneMasterIFace
*iface
, struct MUI_RenderInfo
* mri
, APTR handle
)
462 LIB_MUI_RemoveClipping(mri
,handle
);
465 APTR VARARGS68K
_ZuneMaster_MUI_AddClipRegion(struct ZuneMasterIFace
*iface
, struct MUI_RenderInfo
* mri
, struct Region
* r
)
467 return LIB_MUI_AddClipRegion(mri
,r
);
470 VOID VARARGS68K
_ZuneMaster_MUI_RemoveClipRegion(struct ZuneMasterIFace
*iface
, struct MUI_RenderInfo
* mri
, APTR handle
)
472 LIB_MUI_RemoveClipRegion(mri
,handle
);
475 BOOL VARARGS68K
_ZuneMaster_MUI_BeginRefresh(struct ZuneMasterIFace
*iface
, struct MUI_RenderInfo
* mri
, ULONG flags
)
477 return LIB_MUI_BeginRefresh(mri
,flags
);
480 VOID VARARGS68K
_ZuneMaster_MUI_EndRefresh(struct ZuneMasterIFace
*iface
, struct MUI_RenderInfo
* mri
, ULONG flags
)
482 LIB_MUI_EndRefresh(mri
,flags
);
485 /* ------------------- Manager Interface ------------------------ */
486 /* These are generic. Replace if you need more fancy stuff */
487 static LONG
_manager_Obtain(struct LibraryManagerInterface
*Self
)
489 return Self
->Data
.RefCount
++;
492 static ULONG
_manager_Release(struct LibraryManagerInterface
*Self
)
494 return Self
->Data
.RefCount
--;
497 /* Manager interface vectors */
498 static CONST
void *lib_manager_vectors
[] =
500 (void *)_manager_Obtain
,
501 (void *)_manager_Release
,
511 /* "__library" interface tag list */
512 static CONST
struct TagItem lib_managerTags
[] =
514 {MIT_Name
, (ULONG
)"__library"},
515 {MIT_VectorTable
, (ULONG
)lib_manager_vectors
},
520 /* ------------------- Library Interface(s) ------------------------ */
522 #include "zunemaster_vectors.c"
524 /* Uncomment this line (and see below) if your library has a 68k jump table */
525 extern ULONG VecTable68K
;
527 static CONST
struct TagItem mainTags
[] =
529 {MIT_Name
, (uint32
)"main"},
530 {MIT_VectorTable
, (uint32
)main_vectors
},
535 static CONST uint32 libInterfaces
[] =
537 (uint32
)lib_managerTags
,
542 static CONST
struct TagItem libCreateTags
[] =
544 {CLT_DataSize
, (uint32
)(sizeof(struct MUIMasterBase_intern
))},
545 {CLT_InitFunc
, (uint32
)libInit
},
546 {CLT_Interfaces
, (uint32
)libInterfaces
},
547 {CLT_Vector68K
, (uint32
)&VecTable68K
},
552 /* ------------------- ROM Tag ------------------------ */
553 static const __attribute__((used
)) struct Resident lib_res
=
556 (struct Resident
*)&lib_res
,
558 RTF_NATIVE
|RTF_AUTOINIT
,
562 "zunemaster.library",
563 &"\0$VER: "VSTRING
[7],