Update to lasso handling. Adjust scroll amount based on difference between mouse...
[AROS.git] / rom / dosboot / inithidds.c
blob80a048fa6e3894eacdc858d660a6f128fb212136
1 /*
2 Copyright 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Code that loads and initializes necessary HIDDs.
6 Lang: english
7 */
9 #define DEBUG 0
10 #include <aros/debug.h>
12 #include <aros/bootloader.h>
13 #include <exec/memory.h>
14 #include <exec/resident.h>
15 #include <exec/alerts.h>
16 #include <exec/io.h>
17 #include <dos/filesystem.h>
18 #include <libraries/bootmenu.h>
19 #include <utility/tagitem.h>
20 #include <utility/hooks.h>
21 #include <hidd/hidd.h>
23 #include <proto/bootloader.h>
24 #include <proto/exec.h>
25 #include <proto/oop.h>
26 #include <proto/utility.h>
27 #include <proto/dos.h>
28 #include <proto/graphics.h>
29 #include <proto/intuition.h>
30 #include <oop/oop.h>
31 #include <string.h>
33 #include "devs_private.h"
35 #include <aros/asmcall.h>
37 struct initbase
39 struct ExecBase *sysbase;
40 struct DosLibrary *dosbase;
41 struct Library *oopbase;
44 #define DOSBase (base->dosbase)
45 #define OOPBase (base->oopbase)
47 static BOOL __dosboot_InitGfx ( STRPTR gfxclassname, struct initbase *base);
48 static BOOL __dosboot_InitDevice( STRPTR hiddclassname, STRPTR devicename, struct initbase *base);
50 /************************************************************************/
52 #define BUFSIZE 100
54 #define HIDDPREFSFILE "SYS:S/hidd.prefs"
56 /* We don't link with c library so I must implement this separately */
57 #define isblank(c) \
58 (c == '\t' || c == ' ')
59 #define isspace(c) \
60 (c == '\t' || c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\v')
62 BOOL __dosboot_InitHidds(struct ExecBase *sysBase, struct DosLibrary *dosBase)
64 /* This is the initialisation code for InitHIDDs module */
65 struct initbase stack_b, *base = &stack_b;
66 BOOL success = TRUE;
67 UBYTE buf[BUFSIZE];
68 UBYTE gfxname[BUFSIZE], kbdname[BUFSIZE], mousename[BUFSIZE];
69 BOOL def_gfx = TRUE, def_kbd = TRUE, def_mouse = TRUE;
70 struct BootMenuBase *BootMenuBase;
71 APTR BootLoaderBase;
73 base->sysbase = sysBase;
74 base->dosbase = dosBase;
76 D(bug("[DOSBoot] __dosboot_InitHidds()\n"));
78 OOPBase = OpenLibrary(AROSOOP_NAME, 0);
79 if (!OOPBase)
81 success = FALSE;
83 else
85 BPTR fh;
87 D(bug("[DOSBoot] __dosboot_InitHidds: OOP opened\n"));
89 /* TODO: graphics.library is not in the kernel on Linux-hosted
90 version, so we can't do this check because we'll fail.
91 As a workaround, we load it explicitly in S:hidd.prefs.
93 if ((OpenLibrary("graphics.hidd", 0L)) == NULL)
95 success = FALSE;
96 bug("[DOS] InitHidds: Failed to open graphics.hidd\n");
97 goto end;
98 }*/
99 OpenLibrary("graphics.hidd", 0);
101 BootMenuBase = (struct BootMenuBase *)OpenResource("bootmenu.resource");
102 D(bug("[DOS] __dosboot_InitHidds: BootMenuBase = 0x%p\n", BootMenuBase));
103 if (BootMenuBase) {
104 strcpy(gfxname, BootMenuBase->bm_BootConfig.defaultgfx.hiddname);
105 strcpy(kbdname, BootMenuBase->bm_BootConfig.defaultkbd.hiddname);
106 strcpy(mousename, BootMenuBase->bm_BootConfig.defaultmouse.hiddname);
109 /* Open the hidd prefsfile */
110 fh = Open(HIDDPREFSFILE, FMF_READ);
111 if (fh)
113 D(bug("[DOS] __dosboot_InitHidds: hiddprefs file opened\n"));
114 while (FGets(fh, buf, BUFSIZE))
116 STRPTR keyword = buf, arg, end;
117 STRPTR s;
119 if (*buf == '#')
120 continue;
122 s = buf;
123 if (*s) {
124 for (; *s; s ++)
126 if (s[-1] == 10) {
127 s[-1] = 0;
131 D(bug("[DOS] __dosboot_InitHidds: Got line: %s\n", buf));
133 /* Get keyword */
134 while ((*keyword != 0) && isspace(*keyword))
135 keyword ++;
137 if (*keyword == 0)
138 continue;
140 /* terminate keyword */
141 arg = keyword;
142 while ((*arg != 0) && (!isblank(*arg)))
144 arg ++;
146 if (*arg == 0)
147 continue;
149 *arg = 0;
151 arg ++;
153 /* Find start of argument */
154 D(bug("[DOS] __dosboot_InitHidds: Find argument at %s\n", arg));
155 while ((*arg != 0) && isblank(*arg))
156 arg ++;
158 if (*arg == 0)
159 continue;
161 D(bug("[DOS] __dosboot_InitHidds: Terminate argument at %s\n", arg));
162 /* terminate argument */
163 end = arg;
164 while ( (*end != 0) && (!isblank(*end)))
165 end ++;
166 if (*end != 0)
167 *end = 0;
169 D(bug("[DOS] __dosboot_InitHidds: Got keyword \"%s\" arg \"%s\"\n", keyword, arg));
171 if (0 == strcmp(keyword, "library"))
173 D(bug("Opening library\n"));
174 /* Open a specified library */
175 OpenLibrary(arg, 0);
177 else if (0 == strcmp(keyword, "gfx"))
179 strncpy(gfxname, arg, BUFSIZE - 1);
180 def_gfx = FALSE;
182 else if (0 == strcmp(keyword, "mouse"))
184 strncpy(mousename, arg, BUFSIZE - 1);
185 def_mouse = FALSE;
187 else if (0 == strcmp(keyword, "kbd"))
189 strncpy(kbdname, arg, BUFSIZE - 1);
190 def_kbd = FALSE;
193 Close(fh);
196 BootLoaderBase = OpenResource("bootloader.resource");
197 if (BootLoaderBase)
199 struct List *list;
200 struct Node *node;
202 list = (struct List *)GetBootInfo(BL_Args);
203 if (list)
205 ForeachNode(list,node)
207 if (0 == strncmp(node->ln_Name,"gfx=",4))
209 D(bug("[DOS] __dosboot_InitHidds: Using %s as graphics driver\n",&node->ln_Name[4]));
210 strncpy(gfxname,&(node->ln_Name[4]),BUFSIZE-1);
211 def_gfx = FALSE;
213 if (0 == strncmp(node->ln_Name,"lib=",4))
215 D(bug("[DOS] __dosboot_InitHidds: Opening library %s\n",&node->ln_Name[4]));
216 OpenLibrary(&node->ln_Name[4],0L);
218 if (0 == strncmp(node->ln_Name,"kbd=",4))
220 strncpy(kbdname, &node->ln_Name[4], BUFSIZE-1);
221 def_kbd = FALSE;
223 if (0 == strncmp(node->ln_Name,"mouse=",6))
225 strncpy(mousename, &node->ln_Name[6], BUFSIZE-1);
226 def_mouse = FALSE;
232 if ((!BootMenuBase) && (def_gfx || def_mouse || def_kbd)) {
233 success = FALSE;
234 kprintf("You must specify drivers for this system!\n");
235 goto end;
238 if (def_gfx)
240 if (!OpenLibrary(BootMenuBase->bm_BootConfig.defaultgfx.libname, 0)) {
241 success = FALSE;
242 kprintf("Unable to load gfx hidd %s\n",
243 BootMenuBase->bm_BootConfig.defaultgfx.libname);
244 goto end;
247 if (def_mouse && mousename[0])
249 if (!OpenLibrary(BootMenuBase->bm_BootConfig.defaultmouse.libname, 0)) {
250 success = FALSE;
251 kprintf("Unable to load mouse hidd %s\n",
252 BootMenuBase->bm_BootConfig.defaultmouse.libname);
253 goto end;
256 if (def_kbd && kbdname[0])
258 if (!OpenLibrary(BootMenuBase->bm_BootConfig.defaultkbd.libname, 0)) {
259 success = FALSE;
260 kprintf("Unable to load keyboard hidd %s\n", BootMenuBase->bm_BootConfig.defaultkbd.libname);
261 goto end;
265 if (!__dosboot_InitGfx(gfxname, base))
267 kprintf("Could not init gfx hidd %s\n", gfxname);
268 success = FALSE;
269 goto end;
271 if (!__dosboot_InitDevice(kbdname, "keyboard.device", base))
273 kprintf("Could not init keyboard hidd %s\n", kbdname);
274 success = FALSE;
275 goto end;
277 if (!__dosboot_InitDevice(mousename, "gameport.device", base))
279 kprintf("Could not init mouse hidd %s\n", mousename);
280 success = FALSE;
281 goto end;
283 end:
284 CloseLibrary(OOPBase);
286 ReturnBool("__dosboot_InitHidds", success);
289 /*****************
290 ** __dosboot_InitGfx() **
291 *****************/
293 static BOOL __dosboot_InitGfx(STRPTR gfxclassname, struct initbase *base)
295 struct GfxBase *GfxBase;
296 BOOL success = FALSE;
298 D(bug("[DOSBoot] __dosboot_InitGfx(hiddbase='%s')\n", gfxclassname));
300 GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 37);
301 if (GfxBase)
303 D(bug("[DOS] __dosboot_InitGfx: gfx.library opened\n"));
305 /* Call private gfx.library call to init the HIDD.
306 Gfx library is responsable for closing the HIDD
307 library (although it will probably not be neccesary).
310 D(bug("[DOS] __dosboot_InitGfx: calling private gfx LateGfxInit() ...\n"));
311 if (LateGfxInit(gfxclassname))
313 struct IntuitionBase *IntuitionBase;
314 D(bug("[DOS] __dosboot_InitGfx: ... success\n"));
316 /* Now that gfx. is guaranteed to be up & working, let intuition open WB screen */
317 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
318 if (IntuitionBase)
320 if (LateIntuiInit(NULL))
322 success = TRUE;
324 CloseLibrary((struct Library *)IntuitionBase);
327 D(bug("[DOS] __dosboot_InitGfx: Closing gfx\n"));
329 CloseLibrary((struct Library *)GfxBase);
331 ReturnBool ("__dosboot_InitGfx", success);
335 static BOOL __dosboot_InitDevice( STRPTR hiddclassname, STRPTR devicename, struct initbase *base)
337 BOOL success = FALSE;
338 struct MsgPort *mp;
340 D(bug("[DOSBoot] __dosboot_InitDevice(classname='%s')\n", hiddclassname));
342 if (!hiddclassname[0])
343 return TRUE;
344 mp = CreateMsgPort();
345 if (mp)
347 struct IORequest *io;
348 io = CreateIORequest(mp, sizeof ( struct IOStdReq));
350 if (0 == OpenDevice(devicename, 0, io, 0))
352 UBYTE *data;
354 /* Allocate message data */
355 data = AllocMem(BUFSIZE, MEMF_PUBLIC);
356 if (data)
358 #define ioStd(x) ((struct IOStdReq *)x)
359 strcpy(data, hiddclassname);
360 ioStd(io)->io_Command = CMD_HIDDINIT;
361 ioStd(io)->io_Data = data;
362 ioStd(io)->io_Length = strlen(data);
364 /* Let the device init the HIDD */
365 DoIO(io);
366 if (0 == io->io_Error)
368 success = TRUE;
371 FreeMem(data, BUFSIZE);
373 CloseDevice(io);
375 DeleteIORequest(io);
377 DeleteMsgPort(mp);
379 ReturnBool("__dosboot_InitDevice", success);