grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / muimaster / zunemaster_init-aos4.c
blob322eb7a4ffeda2d8910fc21842422f3ed64bb99b
1 /*
2 Copyright (C) 2003, The AROS Development Team.
3 All rights reserved.
5 $Id$
7 This file provides the library initialization for OS4
8 */
10 #undef __USE_INLINE__
12 #include <stdarg.h>
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"
20 #undef SysBase
22 /* Version Tag */
23 #define VERSION 0
24 #define REVISION 1
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 /*************************************************************************
52 The start function
53 *************************************************************************/
54 LONG _start(void)
56 return 20;
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);
69 if (!iface)
71 IExec->CloseLibrary(lib);
72 return NULL;
74 *((struct Interface**)interface_ptr) = iface;
75 return lib;
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)))
115 goto out;
116 if (!(MUIMB(libBase)->dosbase = (void*)OpenLibraryInterface("dos.library",50,&IDOS)))
117 goto out;
118 if (!(MUIMB(libBase)->gfxbase = (void*)OpenLibraryInterface("graphics.library",50,&IGraphics)))
119 goto out;
120 if (!(MUIMB(libBase)->aslbase = OpenLibraryInterface("asl.library",50,&IAsl)))
121 goto out;
122 if (!(MUIMB(libBase)->layersbase = OpenLibraryInterface("layers.library",50,&ILayers)))
123 goto out;
124 if (!(MUIMB(libBase)->intuibase = (void*)OpenLibraryInterface("intuition.library",50,&IIntuition)))
125 goto out;
126 if (!(MUIMB(libBase)->cxbase = OpenLibraryInterface("commodities.library",50,&ICommodities)))
127 goto out;
128 if (!(MUIMB(libBase)->gadtoolsbase = OpenLibraryInterface("gadtools.library",37,&IGadTools)))
129 goto out;
130 if (!(MUIMB(libBase)->keymapbase = OpenLibraryInterface("keymap.library",37,&IKeymap)))
131 goto out;
132 if (!(DataTypesBase = OpenLibraryInterface("datatypes.library",39,&IDataTypes)))
133 goto out;
134 if (!(MUIMB(libBase)->iffparsebase = OpenLibraryInterface("iffparse.library",39,&IIFFParse)))
135 goto out;
136 if (!(MUIMB(libBase)->diskfontbase = OpenLibraryInterface("diskfont.library",39,&IDiskfont)))
137 goto out;
138 if (!(MUIMB(libBase)->iconbase = OpenLibraryInterface("icon.library",39,&IIcon)))
139 goto out;
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);
146 #endif
148 IExec->InitSemaphore(&MUIMB(libBase)->ZuneSemaphore);
150 IExec->NewMinList(&MUIMB(libBase)->BuiltinClasses);
151 IExec->NewMinList(&MUIMB(libBase)->Applications);
152 return 1;
153 out:
154 DeinitCustomLibraryBase(libBase);
155 return 0;
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 */
172 if (IZuneMaster)
173 libBase->lib_OpenCnt++;
174 else libBase = NULL;
176 IExec->ReleaseSemaphore(&OpenSemaphore);
178 return libBase;
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);
192 IZuneMaster = NULL;
194 IExec->ReleaseSemaphore(&OpenSemaphore);
195 return 0;
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);
215 else
217 result = (APTR)0;
218 libBase->lib_Flags |= LIBF_DELEXP;
220 return result;
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))
230 return NULL;
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;
240 /* Store seg list */
241 MUIMB(libBase)->seglist = (BPTR)seglist;
243 IExec->InitSemaphore(&OpenSemaphore);
245 if (!InitCustomLibraryBase(MUIMB(libBase)))
246 goto out;
248 /* Store the libraries base */
249 MUIMasterBase = libBase;
251 return libBase;
252 out:
253 DeinitCustomLibraryBase(MUIMB(libBase));
254 return NULL;
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, ...)
301 Object *obj;
302 va_list ap;
303 struct TagItem *tags;
305 va_startlinear(ap, classname);
306 tags = va_getlinearva(ap, struct TagItem *);
307 obj = Self->MUI_NewObjectA(classname, tags);
308 va_end(ap);
309 return obj;
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, ...)
324 LONG res;
325 va_list ap;
326 APTR params;
328 va_startlinear(ap, format);
329 params = va_getlinearva(ap, APTR);
330 res = Self->MUI_RequestA(app,win,flags,title,gadgets,format,params);
331 va_end(ap);
332 return res;
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, ...)
342 APTR res;
343 va_list ap;
344 struct TagItem *tags;
346 va_startlinear(ap, reqType);
347 tags = va_getlinearva(ap, struct TagItem *);
348 res = Self->MUI_AllocAslRequest(reqType, tags);
349 va_end(ap);
350 return res;
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, ...)
360 BOOL res;
361 va_list ap;
362 struct TagItem *tags;
364 va_startlinear(ap, requester);
365 tags = va_getlinearva(ap, struct TagItem *);
366 res = Self->MUI_AslRequest(requester, tags);
367 va_end(ap);
368 return res;
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, ...)
428 Object *res;
429 va_list ap;
430 ULONG *params;
432 va_startlinear(ap, type);
433 params = va_getlinearva(ap, ULONG *);
434 res = Self->MUI_MakeObjectA(type,params);
435 va_end(ap);
436 return res;
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,
502 (void *)0,
503 (void *)0,
504 (void *)libOpen,
505 (void *)libClose,
506 (void *)libExpunge,
507 (void *)0,
508 (void *)-1,
511 /* "__library" interface tag list */
512 static CONST struct TagItem lib_managerTags[] =
514 {MIT_Name, (ULONG)"__library"},
515 {MIT_VectorTable, (ULONG)lib_manager_vectors},
516 {MIT_Version, 1},
517 {TAG_DONE, 0}
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},
531 {MIT_Version, 1},
532 {TAG_DONE, 0}
535 static CONST uint32 libInterfaces[] =
537 (uint32)lib_managerTags,
538 (uint32)mainTags,
539 (uint32)0
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},
548 {TAG_DONE, 0}
552 /* ------------------- ROM Tag ------------------------ */
553 static const __attribute__((used)) struct Resident lib_res =
555 RTC_MATCHWORD,
556 (struct Resident *)&lib_res,
557 (APTR)&lib_res+1,
558 RTF_NATIVE|RTF_AUTOINIT,
559 VERSION,
560 NT_LIBRARY,
561 0, /* PRI */
562 "zunemaster.library",
563 &"\0$VER: "VSTRING[7],
564 (APTR)libCreateTags