Added 'Resident' field to ensure that the handler is included in the
[AROS.git] / rom / devs / input / input.c
blob71e612862f21e2b1c5c8516253d3cd25623bd552
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Input device
6 Lang: english
7 */
9 /****************************************************************************************/
11 #include <devices/inputevent.h>
12 #include <devices/input.h>
13 #include <devices/newstyle.h>
14 #include <proto/exec.h>
15 #include <proto/input.h>
16 #include <exec/memory.h>
17 #include <exec/errors.h>
18 #include <exec/initializers.h>
19 #include <aros/symbolsets.h>
21 #include LC_LIBDEFS_FILE
23 #include "input_intern.h"
25 #define DEBUG 0
26 #include <aros/debug.h>
28 /****************************************************************************************/
30 #define NEWSTYLE_DEVICE 1
32 /****************************************************************************************/
34 #if NEWSTYLE_DEVICE
36 #include <devices/newstyle.h>
37 static const UWORD SupportedCommands[] =
39 IND_ADDHANDLER,
40 IND_REMHANDLER,
41 IND_WRITEEVENT,
42 IND_ADDEVENT,
43 IND_SETTHRESH,
44 IND_SETPERIOD,
45 NSCMD_DEVICEQUERY,
49 #endif
51 /****************************************************************************************/
53 static int GM_UNIQUENAME(Init)(LIBBASETYPEPTR InputDevice)
55 NEWLIST( &(InputDevice->HandlerList) );
58 These defaults are in terms of 50 Hz ticks. The real VBlank frequency
59 does not effect them.
61 InputDevice->KeyRepeatThreshold.tv_secs = DEFAULT_KEY_REPEAT_THRESHOLD / 50;
62 InputDevice->KeyRepeatThreshold.tv_micro
63 = (DEFAULT_KEY_REPEAT_THRESHOLD % 50) * 1000000 / 50;
65 InputDevice->KeyRepeatInterval.tv_secs = DEFAULT_KEY_REPEAT_INTERVAL / 50;
66 InputDevice->KeyRepeatInterval.tv_micro
67 = (DEFAULT_KEY_REPEAT_INTERVAL % 50) * 1000000 / 50;
69 D(bug("[InputDev] Starting up task, inputbase 0x%P\n", InputDevice));
71 InputDevice->InputTask = NewCreateTask(TASKTAG_NAME , "input.device",
72 TASKTAG_PRI , IDTASK_PRIORITY,
73 TASKTAG_STACKSIZE , IDTASK_STACKSIZE,
74 TASKTAG_TASKMSGPORT, &InputDevice->CommandPort,
75 TASKTAG_PC , ProcessEvents,
76 TASKTAG_ARG1 , InputDevice,
77 TAG_DONE);
79 if(InputDevice->InputTask)
81 D(bug("[InputDev] Done\n"));
82 return TRUE;
85 return FALSE;
88 /****************************************************************************************/
90 static int GM_UNIQUENAME(Open)
92 LIBBASETYPEPTR InputDevice,
93 struct IORequest *ioreq,
94 ULONG unitnum,
95 ULONG flags
98 D(bug("id: open()\n"));
99 #ifndef __mc68000
100 /* Too many AOS programs do not initialize mn_Length. AOS input.device does not care. */
101 if (ioreq->io_Message.mn_Length < sizeof(struct IOStdReq))
103 bug("[InputDev] Open: IORequest structure passed to OpenDevice is too small\n");
104 ioreq->io_Error = IOERR_OPENFAIL;
105 return FALSE;
107 #endif
108 return TRUE;
111 ADD2INITLIB(GM_UNIQUENAME(Init),0)
112 ADD2OPENDEV(GM_UNIQUENAME(Open),0)
114 /****************************************************************************************/
116 #define ioStd(x) ((struct IOStdReq *)x)
117 AROS_LH1(void, beginio,
118 AROS_LHA(struct IOStdReq *, ioreq, A1),
119 struct inputbase *, InputDevice, 5, Input)
121 AROS_LIBFUNC_INIT
123 LONG error=0;
124 BOOL done_quick = TRUE;
126 D(bug("id: beginio(ioreq=%p)\n", ioreq));
128 /* WaitIO will look into this */
129 ioreq->io_Message.mn_Node.ln_Type=NT_MESSAGE;
131 switch (ioreq->io_Command)
133 #if NEWSTYLE_DEVICE
134 case NSCMD_DEVICEQUERY:
135 if(ioStd(ioreq)->io_Length < ((LONG)OFFSET(NSDeviceQueryResult, SupportedCommands)) + sizeof(UWORD *))
137 ioreq->io_Error = IOERR_BADLENGTH;
139 else
141 struct NSDeviceQueryResult *d;
143 d = (struct NSDeviceQueryResult *)ioStd(ioreq)->io_Data;
145 d->DevQueryFormat = 0;
146 d->SizeAvailable = sizeof(struct NSDeviceQueryResult);
147 d->DeviceType = NSDEVTYPE_INPUT;
148 d->DeviceSubType = 0;
149 d->SupportedCommands = (UWORD *)SupportedCommands;
151 ioStd(ioreq)->io_Actual = sizeof(struct NSDeviceQueryResult);
153 break;
154 #endif
156 case IND_ADDHANDLER:
157 case IND_REMHANDLER:
158 case IND_WRITEEVENT:
159 case IND_ADDEVENT:
160 case IND_SETTHRESH:
161 case IND_SETPERIOD:
162 done_quick = FALSE;
163 break;
165 default:
166 error = IOERR_NOCMD;
167 break;
170 if (!done_quick)
172 /* Mark IO request to be done non-quick */
173 ioreq->io_Flags &= ~IOF_QUICK;
174 /* Send to input device task */
175 PutMsg(InputDevice->CommandPort, &ioreq->io_Message);
177 else
180 /* If the quick bit is not set but the IO request was done quick,
181 ** reply the message to tell we're throgh
183 ioreq->io_Error = error;
184 if (!(ioreq->io_Flags & IOF_QUICK))
185 ReplyMsg (&ioreq->io_Message);
188 D(bug("id: Return from BeginIO()\n"));
190 AROS_LIBFUNC_EXIT
193 /****************************************************************************************/
195 AROS_LH1(LONG, abortio,
196 AROS_LHA(struct IORequest *, ioreq, A1),
197 struct inputbase *, InputDevice, 6, Input)
199 AROS_LIBFUNC_INIT
201 /* Everything already done. */
202 return 0;
204 AROS_LIBFUNC_EXIT
207 /****************************************************************************************/
209 static const char end=0;
211 /****************************************************************************************/