added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / dos / inithidds.c
blob20322d794e8c78b62f3b7732944222f33905273f
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Code that loads and initializes necessary HIDDs.
6 Lang: english
7 */
9 #include <exec/memory.h>
10 #include <exec/resident.h>
11 #include <exec/alerts.h>
12 #include <exec/io.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>
23 #include <oop/oop.h>
24 #include <string.h>
26 #include "devs_private.h"
28 #ifdef __AROS__
29 #include <aros/asmcall.h>
30 #endif /* __AROS__ */
32 #define SDEBUG 0
33 #define DEBUG 0
34 #include <aros/debug.h>
36 #warning This is just a temporary and hackish way to get the HIDDs up and working
38 struct initbase
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 /************************************************************************/
54 #define BUFSIZE 100
56 #define HIDDPREFSFILE "SYS:S/hidd.prefs"
58 /* We don't link with c library so I must implement this separately */
59 #define isblank(c) \
60 (c == '\t' || c == ' ')
61 #define isspace(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;
73 BOOL success = TRUE;
74 UBYTE buf[BUFSIZE];
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);
85 if (!OOPBase)
87 success = FALSE;
89 else
91 BPTR fh;
93 D(bug("OOP opened\n"));
95 /* Open the hidd prefsfile */
97 fh = Open(HIDDPREFSFILE, FMF_READ);
98 if (!fh)
100 success = FALSE;
102 else
104 STRPTR libname = NULL;
106 D(bug("hiddprefs file opened\n"));
107 while (FGets(fh, buf, BUFSIZE))
109 STRPTR keyword = buf, arg, end;
110 STRPTR s;
112 s = buf;
113 if (*s) {
114 for (; *s; s ++)
116 if (s[-1] == 10) {
117 s[-1] = 0;
123 D(bug("Got line\n"));
124 D(bug("Line: %s\n", buf));
126 /* Get keyword */
127 while ((*keyword != 0) && isspace(*keyword))
128 keyword ++;
130 if (*keyword == 0)
131 continue;
133 /* terminate keyword */
134 arg = keyword;
135 while ((*arg != 0) && (!isblank(*arg)))
137 arg ++;
139 if (*arg == 0)
140 continue;
142 *arg = 0;
144 arg ++;
146 /* Find start of argument */
147 D(bug("Find argument at %s\n", arg));
148 while ((*arg != 0) && isblank(*arg))
149 arg ++;
151 if (*arg == 0)
152 continue;
154 D(bug("Terminate argument at %s\n", arg));
155 /* terminate argument */
156 end = arg;
157 while ( (*end != 0) && (!isblank(*end)))
158 end ++;
159 if (*end != 0)
160 *end = 0;
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 */
169 libname = arg;
170 if (NULL == OpenLibrary(libname, 0))
172 success = FALSE;
173 got_library = FALSE;
174 break;
177 else if (0 == strcmp(keyword, "gfx"))
179 strncpy(gfxname, arg, BUFSIZE - 1);
180 got_gfx = TRUE;
182 else if (0 == strcmp(keyword, "mouse"))
184 strncpy(mousename, arg, BUFSIZE - 1);
185 got_mouse = TRUE;
187 else if (0 == strcmp(keyword, "kbd"))
189 strncpy(kbdname, arg, BUFSIZE - 1);
190 got_kbd = TRUE;
194 Close(fh);
196 if (!got_library)
198 success = FALSE;
199 kprintf("Could not open library %s\n", libname);
200 goto end;
203 if (!got_gfx)
205 success = FALSE;
206 kprintf("No configuration for gfx hidd\n");
207 goto end;
210 if (!got_mouse)
212 success = FALSE;
213 kprintf("No configuration for mouse hidd\n");
214 goto end;
217 if (!got_kbd)
219 success = FALSE;
220 kprintf("No configuration for keyboard hidd\n");
221 goto end;
224 if (!init_gfx(gfxname, base))
226 kprintf("Could not init gfx hidd %s\n", gfxname);
227 success = FALSE;
228 goto end;
231 if (!init_device(kbdname, "keyboard.device", base))
233 kprintf("Could not init keyboard hidd %s\n", kbdname);
234 success = FALSE;
235 goto end;
238 if (!init_device(mousename, "gameport.device", base))
240 kprintf("Could not init mouse hidd %s\n", mousename);
241 success = FALSE;
242 goto end;
245 end:
246 CloseLibrary(OOPBase);
249 ReturnBool("init_hidds", success);
252 /*****************
253 ** init_gfx() **
254 *****************/
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);
264 if (GfxBase)
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;
277 D(bug("success\n"));
279 /* Now that gfx. is guaranteed to be up & working, let intuition open WB screen */
280 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
281 if (IntuitionBase)
283 if (LateIntuiInit(NULL))
285 success = TRUE;
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;
301 struct MsgPort *mp;
304 EnterFunc(bug("init_device(classname=%s)\n", hiddclassname));
306 mp = CreateMsgPort();
307 if (mp)
309 struct IORequest *io;
310 io = CreateIORequest(mp, sizeof ( struct IOStdReq));
312 if (0 == OpenDevice(devicename, 0, io, 0))
314 UBYTE *data;
316 /* Allocate message data */
317 data = AllocMem(BUFSIZE, MEMF_PUBLIC);
318 if (data)
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 */
327 DoIO(io);
328 if (0 == io->io_Error)
330 success = TRUE;
333 FreeMem(data, BUFSIZE);
335 CloseDevice(io);
338 DeleteIORequest(io);
342 DeleteMsgPort(mp);
346 ReturnBool("init_device", success);