Added a test for MUIA_Listview_SelectChange.
[AROS.git] / arch / all-hosted / hidd / sdl / startup.c
blob7ba111c8e3204026ec48d4a636d714077d7d9771
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <aros/debug.h>
9 #include <dos/dosextens.h>
10 #include <hidd/graphics.h>
11 #include <hidd/keyboard.h>
12 #include <hidd/mouse.h>
13 #include <hidd/hidd.h>
14 #include <graphics/gfxbase.h>
15 #include <workbench/startup.h>
16 #include <workbench/workbench.h>
17 #include <proto/dos.h>
18 #include <proto/exec.h>
19 #include <proto/graphics.h>
20 #include <proto/icon.h>
21 #include <proto/oop.h>
23 #include <string.h>
25 #include "sdl_intern.h"
27 /* SDL includes define main to SDL_main, bring it back */
28 #undef main
30 struct Library *OOPBase;
31 struct Library *UtilityBase;
33 OOP_AttrBase MetaAttrBase;
34 OOP_AttrBase HiddAttrBase;
35 OOP_AttrBase HiddPixFmtAttrBase;
36 OOP_AttrBase HiddBitMapAttrBase;
37 OOP_AttrBase HiddColorMapAttrBase;
38 OOP_AttrBase HiddSyncAttrBase;
39 OOP_AttrBase HiddGfxAttrBase;
40 OOP_AttrBase HiddSDLBitMapAttrBase;
41 OOP_AttrBase HiddMouseAB;
42 OOP_AttrBase HiddKbdAB;
44 static struct OOP_ABDescr attrbases[] = {
45 { IID_Meta, &MetaAttrBase },
46 { IID_Hidd, &HiddAttrBase },
47 { IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
48 { IID_Hidd_BitMap, &HiddBitMapAttrBase },
49 { IID_Hidd_ColorMap, &HiddColorMapAttrBase },
50 { IID_Hidd_Sync, &HiddSyncAttrBase },
51 { IID_Hidd_Gfx, &HiddGfxAttrBase },
52 { IID_Hidd_SDLBitMap, &HiddSDLBitMapAttrBase },
53 { IID_Hidd_Mouse, &HiddMouseAB },
54 { IID_Hidd_Kbd, &HiddKbdAB },
55 { NULL, NULL }
58 /* Class static data is really static now. :)
59 If the driver would be compiled as a ROM resident, this structure could
60 be allocated either on stack or using AllocMem() */
61 struct sdlhidd xsd = {NULL};
63 static int sdl_Startup(struct sdlhidd *xsd)
65 struct GfxBase *GfxBase;
66 OOP_Object *kbd, *ms = NULL;
67 OOP_Object *kbdriver = NULL;
68 OOP_Object *msdriver = NULL;
69 ULONG err;
71 GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 41);
72 if (!GfxBase)
73 return FALSE;
75 xsd->basebm = OOP_FindClass(CLID_Hidd_BitMap);
76 xsd->mousehidd = NULL;
77 D(bug("[SDL] Class initialization OK, creating objects\n"));
79 /* Add keyboard and mouse driver to the system */
80 kbd = OOP_NewObject(NULL, CLID_Hidd_Kbd, NULL);
81 if (kbd) {
82 ms = OOP_NewObject(NULL, CLID_Hidd_Mouse, NULL);
83 if (ms) {
84 kbdriver = HIDD_Kbd_AddHardwareDriver(kbd, xsd->kbdclass, NULL);
85 D(bug("[SDL] Keyboard driver object 0x%p\n", kbdriver));
86 if (kbdriver) {
87 msdriver = HIDD_Mouse_AddHardwareDriver(ms, xsd->mouseclass, NULL);
88 D(bug("[SDL] Mouse driver object 0x%p\n", msdriver));
94 /* If we got no input, we can't work, fail */
95 if (!msdriver)
97 err = -1;
99 if (kbdriver)
100 HIDD_Kbd_RemHardwareDriver(kbd, kbdriver);
102 if (ms)
103 OOP_DisposeObject(ms);
105 if (kbd)
106 OOP_DisposeObject(kbd);
108 return FALSE;
110 else
113 * Now proceed to adding display modes ..
114 * SDL is currently a singletone by design,
115 * So only one object!
117 err = AddDisplayDriverA(xsd->gfxclass, NULL, NULL);
120 CloseLibrary(&GfxBase->LibNode);
122 return err ? FALSE : TRUE;
125 extern struct WBStartup *WBenchMsg;
127 int __nocommandline = 1;
129 int main(void)
131 BPTR olddir = NULL;
132 STRPTR myname;
133 struct DiskObject *icon;
134 struct RDArgs *rdargs = NULL;
135 IPTR fullscreen = FALSE;
136 int ret = RETURN_FAIL;
138 /* Open libraries manually, otherwise they will be closed when this subroutine
139 exits. Driver needs them. */
140 OOPBase = OpenLibrary("oop.library", 42);
141 if (!OOPBase)
142 return RETURN_FAIL;
144 /* If SDLGfx class is already registered, the user attempts to run us twice.
145 Just ignore this. */
146 if (OOP_FindClass(CLID_Hidd_SDLGfx)) {
147 D(bug("[SDL] Driver already registered\n"));
148 CloseLibrary(OOPBase);
149 return RETURN_OK;
152 UtilityBase = OpenLibrary("utility.library", 36);
153 if (!UtilityBase) {
154 CloseLibrary(OOPBase);
155 return RETURN_FAIL;
158 /* We don't open dos.library and icon.library manually because only startup code
159 needs them and these libraries can be closed even upon successful exit */
160 if (WBenchMsg) {
161 olddir = CurrentDir(WBenchMsg->sm_ArgList[0].wa_Lock);
162 myname = WBenchMsg->sm_ArgList[0].wa_Name;
163 } else {
164 struct Process *me = (struct Process *)FindTask(NULL);
166 if (me->pr_CLI) {
167 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
169 myname = cli->cli_CommandName;
170 } else
171 myname = me->pr_Task.tc_Node.ln_Name;
174 icon = GetDiskObject(myname);
175 D(bug("[X11] Icon 0x%p\n", icon));
177 if (icon) {
178 STRPTR str;
180 str = FindToolType(icon->do_ToolTypes, "FULLSCREEN");
181 fullscreen = str ? TRUE : FALSE;
184 if (!WBenchMsg)
185 rdargs = ReadArgs("FULLSCREEN/S", &fullscreen, NULL);
187 xsd.use_fullscreen = fullscreen;
188 if (rdargs)
189 FreeArgs(rdargs);
190 if (icon)
191 FreeDiskObject(icon);
192 if (olddir)
193 CurrentDir(olddir);
195 /* Obtain attribute bases first */
196 if (OOP_ObtainAttrBases(attrbases)) {
197 /* Load host libraries */
198 if (sdl_hostlib_init(&xsd)) {
199 /* Create classes */
200 struct TagItem SDLGfx_tags[] = {
201 {aMeta_SuperID , (IPTR)CLID_Hidd_Gfx },
202 {aMeta_InterfaceDescr, (IPTR)SDLGfx_ifdescr },
203 {aMeta_InstSize , sizeof(struct gfxdata)},
204 {aMeta_ID , (IPTR)CLID_Hidd_SDLGfx},
205 {TAG_DONE , 0 }
208 xsd.gfxclass = OOP_NewObject(NULL, CLID_HiddMeta, SDLGfx_tags);
209 if (xsd.gfxclass) {
210 struct TagItem SDLBitMap_tags[] = {
211 {aMeta_SuperID , (IPTR)CLID_Hidd_BitMap },
212 {aMeta_InterfaceDescr, (IPTR)SDLBitMap_ifdescr},
213 {aMeta_InstSize , sizeof(struct bmdata) },
214 {TAG_DONE , 0 }
217 xsd.gfxclass->UserData = &xsd;
218 xsd.bmclass = OOP_NewObject(NULL, CLID_HiddMeta, SDLBitMap_tags);
219 if (xsd.bmclass) {
220 struct TagItem SDLMouse_tags[] = {
221 {aMeta_SuperID , (IPTR)CLID_Hidd },
222 {aMeta_InterfaceDescr, (IPTR)SDLMouse_ifdescr },
223 {aMeta_InstSize , sizeof(struct mousedata)},
224 {TAG_DONE , 0 }
227 xsd.bmclass->UserData = &xsd;
228 xsd.mouseclass = OOP_NewObject(NULL, CLID_HiddMeta, SDLMouse_tags);
229 if (xsd.mouseclass) {
230 struct TagItem SDLKbd_tags[] = {
231 {aMeta_SuperID , (IPTR)CLID_Hidd },
232 {aMeta_InterfaceDescr, (IPTR)SDLKbd_ifdescr },
233 {aMeta_InstSize , sizeof(struct kbddata)},
234 {TAG_DONE , 0 }
237 xsd.mouseclass->UserData = &xsd;
238 xsd.kbdclass = OOP_NewObject(NULL, CLID_HiddMeta, SDLKbd_tags);
239 if (xsd.kbdclass) {
240 xsd.kbdclass->UserData = &xsd;
242 /* Init internal stuff */
243 sdl_keymap_init(&xsd);
244 if (sdl_event_init(&xsd)) {
245 if (sdl_hidd_init(&xsd)) {
246 if (sdl_Startup(&xsd)) {
247 /* Register our gfx class as public, we use it as a
248 protection against double start */
249 OOP_AddClass(xsd.gfxclass);
250 /* Everything is okay, stay resident and exit */
251 struct Process *me = (struct Process *)FindTask(NULL);
253 D(bug("[SDL] Staying resident, process 0x%p\n", me));
254 if (me->pr_CLI) {
255 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
257 D(bug("[SDL] CLI 0x%p\n", cli));
258 cli->cli_Module = NULL;
259 } else
260 me->pr_SegList = NULL;
262 /* Note also that we don't close needed libraries and
263 don't free attribute bases */
264 return RETURN_OK;
266 SV(SDL_Quit);
268 sdl_event_expunge(&xsd);
270 OOP_DisposeObject((OOP_Object *)xsd.kbdclass);
272 OOP_DisposeObject((OOP_Object *)xsd.mouseclass);
274 OOP_DisposeObject((OOP_Object *)xsd.bmclass);
276 OOP_DisposeObject((OOP_Object *)xsd.gfxclass);
278 sdl_hostlib_expunge(&xsd);
279 } else
280 /* Perhaps some stupid user attempts to run this driver on
281 native system. Well, let's forgive him :) */
282 ret = RETURN_OK;
283 OOP_ReleaseAttrBases(attrbases);
286 CloseLibrary(UtilityBase);
287 CloseLibrary(OOPBase);
288 return ret;