rename the directory
[AROS.git] / workbench / hidds / sm502 / sm502_init.c
blob4b4f3d8050afb328e3ed6b91eeb4e0808be2e969
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: sm502 gfx Hidd for standalone i386 AROS
6 Lang: english
7 */
9 #define __OOP_NOATTRBASES__
11 #include <aros/debug.h>
13 #include <proto/exec.h>
14 #include <proto/graphics.h>
15 #include <proto/oop.h>
16 #include <exec/types.h>
17 #include <exec/lists.h>
18 #include <graphics/driver.h>
19 #include <graphics/gfxbase.h>
20 #include <hidd/graphics.h>
21 #include <oop/oop.h>
22 #include <utility/utility.h>
23 #include <aros/symbolsets.h>
25 #include "hardware.h"
26 #include "sm502gfxclass.h"
28 #include LC_LIBDEFS_FILE
31 * The following two functions are candidates for inclusion into oop.library.
32 * For slightly other implementation see incomplete Android-hosted graphics driver.
34 static void FreeAttrBases(const STRPTR *iftable, OOP_AttrBase *bases, ULONG num)
36 ULONG i;
38 for (i = 0; i < num; i++)
40 if (bases[i])
41 OOP_ReleaseAttrBase(iftable[i]);
45 static BOOL GetAttrBases(const STRPTR *iftable, OOP_AttrBase *bases, ULONG num)
47 ULONG i;
49 for (i = 0; i < num; i++)
51 bases[i] = OOP_ObtainAttrBase(iftable[i]);
52 if (!bases[i])
54 FreeAttrBases(iftable, bases, i);
55 return FALSE;
59 return TRUE;
62 /* These must stay in the same order as attrBases[] entries assignment in sm502gfx.h */
63 static const STRPTR interfaces[ATTRBASES_NUM] =
65 IID_Hidd_ChunkyBM,
66 IID_Hidd_BitMap,
67 IID_Hidd_Gfx,
68 IID_Hidd_PixFmt,
69 IID_Hidd_Sync,
70 IID_Hidd
73 static int PCSM502_Init(LIBBASETYPEPTR LIBBASE)
75 struct SM502Gfx_staticdata *xsd = &LIBBASE->vsd;
76 struct GfxBase *GfxBase;
77 ULONG err;
78 int res = FALSE;
80 if (!GetAttrBases(interfaces, xsd->attrBases, ATTRBASES_NUM))
81 return FALSE;
83 InitSemaphore(&xsd->framebufferlock);
84 InitSemaphore(&xsd->HW_acc);
86 if (!initSM502GfxHW(&xsd->data))
87 return FALSE;
89 D(bug("[SM502] Init: Everything OK, installing driver\n"));
92 * Open graphics.library ourselves because we will close it
93 * after adding the driver.
94 * Autoinit code would close it only upon driver expunge.
96 GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 41);
97 if (!GfxBase)
99 D(bug("[SM502] Failed to open graphics.library!\n"));
101 return FALSE;
104 LIBBASE->vsd.basebm = OOP_FindClass(CLID_Hidd_BitMap);
107 * It is unknown (and no way to know) what hardware part this driver uses.
108 * In order to avoid conflicts with disk-based native-mode hardware
109 * drivers it needs to be removed from the system when some other driver
110 * is installed.
111 * This is done by graphics.library if DDRV_BootMode is set to TRUE.
113 err = AddDisplayDriver(LIBBASE->vsd.sm502gfxclass, NULL, DDRV_BootMode, TRUE, TAG_DONE);
115 D(bug("[SM502] AddDisplayDriver() result: %u\n", err));
116 if (!err)
118 /* We use ourselves, and no one else does */
119 LIBBASE->library.lib_OpenCnt = 1;
120 res = TRUE;
123 CloseLibrary(&GfxBase->LibNode);
124 return res;
127 ADD2INITLIB(PCSM502_Init, 0)