2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: Code that loads and initializes necessary HIDDs.
9 #include <exec/memory.h>
10 #include <exec/resident.h>
11 #include <exec/alerts.h>
13 #include <dos/filesystem.h>
14 #include <utility/tagitem.h>
15 #include <utility/hooks.h>
16 #include <hidd/hidd.h>
18 #include <proto/exec.h>
19 #include <proto/oop.h>
20 #include <proto/utility.h>
21 #include <proto/dos.h>
22 #include <proto/intuition.h>
26 #include "devs_private.h"
29 #include <aros/asmcall.h>
34 #include <aros/debug.h>
36 #warning This is just a temporary and hackish way to get the HIDDs up and working
40 struct ExecBase
*sysbase
;
41 struct DosLibrary
*dosbase
;
42 struct Library
*oopbase
;
45 #define DOSBase (base->dosbase)
46 #define OOPBase (base->oopbase)
49 static BOOL
init_gfx ( STRPTR gfxclassname
, struct initbase
*base
);
50 static BOOL
init_device( STRPTR hiddclassname
, STRPTR devicename
, struct initbase
*base
);
52 /************************************************************************/
56 #define HIDDPREFSFILE "SYS:S/hidd.prefs"
58 /* We don't link with c library so I must implement this separately */
60 (c == '\t' || c == ' ')
62 (c == '\t' || c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\v')
65 #include <proto/graphics.h>
67 BOOL
init_hidds(struct ExecBase
*sysBase
, struct DosLibrary
*dosBase
)
69 /* This is the initialisation code for InitHIDDs module */
72 struct initbase stack_b
, *base
= &stack_b
;
75 UBYTE gfxname
[BUFSIZE
], kbdname
[BUFSIZE
], mousename
[BUFSIZE
];
76 BOOL got_gfx
= FALSE
, got_kbd
= FALSE
, got_mouse
= FALSE
, got_library
= TRUE
;
79 base
->sysbase
= sysBase
;
80 base
->dosbase
= dosBase
;
82 EnterFunc(bug("init_hidds\n"));
84 OOPBase
= OpenLibrary(AROSOOP_NAME
, 0);
93 D(bug("OOP opened\n"));
95 /* Open the hidd prefsfile */
97 fh
= Open(HIDDPREFSFILE
, FMF_READ
);
104 STRPTR libname
= NULL
;
106 D(bug("hiddprefs file opened\n"));
107 while (FGets(fh
, buf
, BUFSIZE
))
109 STRPTR keyword
= buf
, arg
, end
;
123 D(bug("Got line\n"));
124 D(bug("Line: %s\n", buf
));
127 while ((*keyword
!= 0) && isspace(*keyword
))
133 /* terminate keyword */
135 while ((*arg
!= 0) && (!isblank(*arg
)))
146 /* Find start of argument */
147 D(bug("Find argument at %s\n", arg
));
148 while ((*arg
!= 0) && isblank(*arg
))
154 D(bug("Terminate argument at %s\n", arg
));
155 /* terminate argument */
157 while ( (*end
!= 0) && (!isblank(*end
)))
162 D(bug("Got keyword \"%s\"\n", keyword
));
163 D(bug("Got arg \"%s\"\n", arg
));
165 if (0 == strcmp(keyword
, "library"))
167 D(bug("Opening library\n"));
168 /* Open a specified library */
170 if (NULL
== OpenLibrary(libname
, 0))
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);
199 kprintf("Could not open library %s\n", libname
);
206 kprintf("No configuration for gfx hidd\n");
213 kprintf("No configuration for mouse hidd\n");
220 kprintf("No configuration for keyboard hidd\n");
224 if (!init_gfx(gfxname
, base
))
226 kprintf("Could not init gfx hidd %s\n", gfxname
);
231 if (!init_device(kbdname
, "keyboard.device", base
))
233 kprintf("Could not init keyboard hidd %s\n", kbdname
);
238 if (!init_device(mousename
, "gameport.device", base
))
240 kprintf("Could not init mouse hidd %s\n", mousename
);
246 CloseLibrary(OOPBase
);
249 ReturnBool("init_hidds", success
);
256 static BOOL
init_gfx(STRPTR gfxclassname
, struct initbase
*base
)
258 struct GfxBase
*GfxBase
;
259 BOOL success
= FALSE
;
261 EnterFunc(bug("init_gfx(hiddbase=%s)\n", gfxclassname
));
263 GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 37);
266 D(bug("gfx.library opened\n"));
268 /* Call private gfx.library call to init the HIDD.
269 Gfx library is responsable for closing the HIDD
270 library (although it will probably not be neccesary).
273 D(bug("calling private gfx LateGfxInit()\n"));
274 if (LateGfxInit(gfxclassname
))
276 struct IntuitionBase
*IntuitionBase
;
279 /* Now that gfx. is guaranteed to be up & working, let intuition open WB screen */
280 IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 37);
283 if (LateIntuiInit(NULL
))
287 CloseLibrary((struct Library
*)IntuitionBase
);
290 D(bug("Closing gfx\n"));
292 CloseLibrary((struct Library
*)GfxBase
);
294 ReturnBool ("init_gfxhidd", success
);
298 static BOOL
init_device( STRPTR hiddclassname
, STRPTR devicename
, struct initbase
*base
)
300 BOOL success
= FALSE
;
304 EnterFunc(bug("init_device(classname=%s)\n", hiddclassname
));
306 mp
= CreateMsgPort();
309 struct IORequest
*io
;
310 io
= CreateIORequest(mp
, sizeof ( struct IOStdReq
));
312 if (0 == OpenDevice(devicename
, 0, io
, 0))
316 /* Allocate message data */
317 data
= AllocMem(BUFSIZE
, MEMF_PUBLIC
);
320 #define ioStd(x) ((struct IOStdReq *)x)
321 strcpy(data
, hiddclassname
);
322 ioStd(io
)->io_Command
= CMD_HIDDINIT
;
323 ioStd(io
)->io_Data
= data
;
324 ioStd(io
)->io_Length
= strlen(data
);
326 /* Let the device init the HIDD */
328 if (0 == io
->io_Error
)
333 FreeMem(data
, BUFSIZE
);
346 ReturnBool("init_device", success
);