2 Copyright 1995-2008, The AROS Development Team. All rights reserved.
5 Desc: Code that loads and initializes necessary HIDDs.
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>
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>
33 #include "devs_private.h"
35 #include <aros/asmcall.h>
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 /************************************************************************/
54 #define HIDDPREFSFILE "SYS:S/hidd.prefs"
56 /* We don't link with c library so I must implement this separately */
58 (c == '\t' || 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
;
68 UBYTE gfxname
[BUFSIZE
], kbdname
[BUFSIZE
], mousename
[BUFSIZE
];
69 BOOL def_gfx
= TRUE
, def_kbd
= TRUE
, def_mouse
= TRUE
;
70 struct BootMenuBase
*BootMenuBase
;
73 base
->sysbase
= sysBase
;
74 base
->dosbase
= dosBase
;
76 D(bug("[DOSBoot] __dosboot_InitHidds()\n"));
78 OOPBase
= OpenLibrary(AROSOOP_NAME
, 0);
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)
96 bug("[DOS] InitHidds: Failed to open graphics.hidd\n");
99 OpenLibrary("graphics.hidd", 0);
101 BootMenuBase
= (struct BootMenuBase
*)OpenResource("bootmenu.resource");
102 D(bug("[DOS] __dosboot_InitHidds: BootMenuBase = 0x%p\n", 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
);
113 D(bug("[DOS] __dosboot_InitHidds: hiddprefs file opened\n"));
114 while (FGets(fh
, buf
, BUFSIZE
))
116 STRPTR keyword
= buf
, arg
, end
;
131 D(bug("[DOS] __dosboot_InitHidds: Got line: %s\n", buf
));
134 while ((*keyword
!= 0) && isspace(*keyword
))
140 /* terminate keyword */
142 while ((*arg
!= 0) && (!isblank(*arg
)))
153 /* Find start of argument */
154 D(bug("[DOS] __dosboot_InitHidds: Find argument at %s\n", arg
));
155 while ((*arg
!= 0) && isblank(*arg
))
161 D(bug("[DOS] __dosboot_InitHidds: Terminate argument at %s\n", arg
));
162 /* terminate argument */
164 while ( (*end
!= 0) && (!isblank(*end
)))
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 */
177 else if (0 == strcmp(keyword
, "gfx"))
179 strncpy(gfxname
, arg
, BUFSIZE
- 1);
182 else if (0 == strcmp(keyword
, "mouse"))
184 strncpy(mousename
, arg
, BUFSIZE
- 1);
187 else if (0 == strcmp(keyword
, "kbd"))
189 strncpy(kbdname
, arg
, BUFSIZE
- 1);
196 BootLoaderBase
= OpenResource("bootloader.resource");
202 list
= (struct List
*)GetBootInfo(BL_Args
);
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);
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);
223 if (0 == strncmp(node
->ln_Name
,"mouse=",6))
225 strncpy(mousename
, &node
->ln_Name
[6], BUFSIZE
-1);
232 if ((!BootMenuBase
) && (def_gfx
|| def_mouse
|| def_kbd
)) {
234 kprintf("You must specify drivers for this system!\n");
240 if (!OpenLibrary(BootMenuBase
->bm_BootConfig
.defaultgfx
.libname
, 0)) {
242 kprintf("Unable to load gfx hidd %s\n",
243 BootMenuBase
->bm_BootConfig
.defaultgfx
.libname
);
247 if (def_mouse
&& mousename
[0])
249 if (!OpenLibrary(BootMenuBase
->bm_BootConfig
.defaultmouse
.libname
, 0)) {
251 kprintf("Unable to load mouse hidd %s\n",
252 BootMenuBase
->bm_BootConfig
.defaultmouse
.libname
);
256 if (def_kbd
&& kbdname
[0])
258 if (!OpenLibrary(BootMenuBase
->bm_BootConfig
.defaultkbd
.libname
, 0)) {
260 kprintf("Unable to load keyboard hidd %s\n", BootMenuBase
->bm_BootConfig
.defaultkbd
.libname
);
265 if (!__dosboot_InitGfx(gfxname
, base
))
267 kprintf("Could not init gfx hidd %s\n", gfxname
);
271 if (!__dosboot_InitDevice(kbdname
, "keyboard.device", base
))
273 kprintf("Could not init keyboard hidd %s\n", kbdname
);
277 if (!__dosboot_InitDevice(mousename
, "gameport.device", base
))
279 kprintf("Could not init mouse hidd %s\n", mousename
);
284 CloseLibrary(OOPBase
);
286 ReturnBool("__dosboot_InitHidds", success
);
290 ** __dosboot_InitGfx() **
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);
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);
320 if (LateIntuiInit(NULL
))
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
;
340 D(bug("[DOSBoot] __dosboot_InitDevice(classname='%s')\n", hiddclassname
));
342 if (!hiddclassname
[0])
344 mp
= CreateMsgPort();
347 struct IORequest
*io
;
348 io
= CreateIORequest(mp
, sizeof ( struct IOStdReq
));
350 if (0 == OpenDevice(devicename
, 0, io
, 0))
354 /* Allocate message data */
355 data
= AllocMem(BUFSIZE
, MEMF_PUBLIC
);
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 */
366 if (0 == io
->io_Error
)
371 FreeMem(data
, BUFSIZE
);
379 ReturnBool("__dosboot_InitDevice", success
);