revert between 56095 -> 55830 in arch
[AROS.git] / rom / devs / input / input.c
blobf951fddcf8ad729a7388a2229ee9a3ee8c0c0cf7
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Input device
6 Lang: english
7 */
9 #include <devices/inputevent.h>
10 #include <devices/input.h>
11 #include <devices/newstyle.h>
12 #include <proto/exec.h>
13 #include <proto/input.h>
14 #include <exec/memory.h>
15 #include <exec/errors.h>
16 #include <exec/initializers.h>
17 #include <aros/symbolsets.h>
19 #include LC_LIBDEFS_FILE
21 #include "input_intern.h"
23 #define DEBUG 0
24 #include <aros/debug.h>
26 #define NEWSTYLE_DEVICE 1
28 #if NEWSTYLE_DEVICE
30 #include <devices/newstyle.h>
32 static const UWORD SupportedCommands[] =
34 IND_ADDHANDLER,
35 IND_REMHANDLER,
36 IND_WRITEEVENT,
37 IND_ADDEVENT,
38 IND_SETTHRESH,
39 IND_SETPERIOD,
40 NSCMD_DEVICEQUERY,
44 #endif
47 static int GM_UNIQUENAME(Init) (LIBBASETYPEPTR InputDevice)
49 NEWLIST(&(InputDevice->HandlerList));
52 These defaults are in terms of 50 Hz ticks. The real VBlank frequency
53 does not affect them.
55 InputDevice->KeyRepeatThreshold.tv_secs =
56 DEFAULT_KEY_REPEAT_THRESHOLD / 50;
57 InputDevice->KeyRepeatThreshold.tv_micro =
58 (DEFAULT_KEY_REPEAT_THRESHOLD % 50) * 1000000 / 50;
60 InputDevice->KeyRepeatInterval.tv_secs =
61 DEFAULT_KEY_REPEAT_INTERVAL / 50;
62 InputDevice->KeyRepeatInterval.tv_micro =
63 (DEFAULT_KEY_REPEAT_INTERVAL % 50) * 1000000 / 50;
65 D(bug("[InputDev] Starting up task, inputbase 0x%P\n", InputDevice));
67 InputDevice->InputTask = NewCreateTask(TASKTAG_NAME, "input.device",
68 TASKTAG_PRI, IDTASK_PRIORITY,
69 TASKTAG_STACKSIZE, IDTASK_STACKSIZE,
70 TASKTAG_TASKMSGPORT, &InputDevice->CommandPort,
71 TASKTAG_PC, ProcessEvents, TASKTAG_ARG1, InputDevice, TAG_DONE);
73 if (InputDevice->InputTask)
75 D(bug("[InputDev] Done\n"));
76 return TRUE;
79 return FALSE;
83 static int GM_UNIQUENAME(Open)
84 (LIBBASETYPEPTR InputDevice,
85 struct IORequest *ioreq, ULONG unitnum, ULONG flags)
87 D(bug("id: open()\n"));
88 #ifndef __mc68000
89 /* Too many AOS programs do not initialize mn_Length. AOS input.device
90 does not care. */
91 if (ioreq->io_Message.mn_Length < sizeof(struct IOStdReq))
93 bug("[InputDev] Open: IORequest structure passed to OpenDevice is"
94 " too small\n");
95 ioreq->io_Error = IOERR_OPENFAIL;
96 return FALSE;
98 #endif
99 return TRUE;
102 ADD2INITLIB(GM_UNIQUENAME(Init), 0)
103 ADD2OPENDEV(GM_UNIQUENAME(Open), 0)
105 #define ioStd(x) ((struct IOStdReq *)x)
108 AROS_LH1(void, beginio,
109 AROS_LHA(struct IOStdReq *, ioreq, A1),
110 struct inputbase *, InputDevice, 5, Input)
112 AROS_LIBFUNC_INIT
114 LONG error = 0;
115 BOOL done_quick = TRUE;
117 D(bug("id: beginio(ioreq=%p)\n", ioreq));
119 /* WaitIO will look into this */
120 ioreq->io_Message.mn_Node.ln_Type = NT_MESSAGE;
122 switch (ioreq->io_Command)
124 #if NEWSTYLE_DEVICE
125 case NSCMD_DEVICEQUERY:
126 if (ioStd(ioreq)->io_Length < ((LONG) OFFSET(NSDeviceQueryResult,
127 SupportedCommands)) + sizeof(UWORD *))
129 ioreq->io_Error = IOERR_BADLENGTH;
131 else
133 struct NSDeviceQueryResult *d;
135 d = (struct NSDeviceQueryResult *)ioStd(ioreq)->io_Data;
137 d->DevQueryFormat = 0;
138 d->SizeAvailable = sizeof(struct NSDeviceQueryResult);
139 d->DeviceType = NSDEVTYPE_INPUT;
140 d->DeviceSubType = 0;
141 d->SupportedCommands = (UWORD *) SupportedCommands;
143 ioStd(ioreq)->io_Actual = sizeof(struct NSDeviceQueryResult);
145 break;
146 #endif
148 case IND_ADDHANDLER:
149 case IND_REMHANDLER:
150 case IND_WRITEEVENT:
151 case IND_ADDEVENT:
152 case IND_SETTHRESH:
153 case IND_SETPERIOD:
154 done_quick = FALSE;
155 break;
157 default:
158 error = IOERR_NOCMD;
159 break;
162 if (!done_quick)
164 /* Mark IO request to be done non-quick */
165 ioreq->io_Flags &= ~IOF_QUICK;
166 /* Send to input device task */
167 PutMsg(InputDevice->CommandPort, &ioreq->io_Message);
169 else
172 /* If the quick bit is not set but the IO request was done quick,
173 * reply the message to tell we're through
175 ioreq->io_Error = error;
176 if (!(ioreq->io_Flags & IOF_QUICK))
177 ReplyMsg(&ioreq->io_Message);
180 D(bug("id: Return from BeginIO()\n"));
182 AROS_LIBFUNC_EXIT
186 AROS_LH1(LONG, abortio,
187 AROS_LHA(struct IORequest *, ioreq, A1),
188 struct inputbase *, InputDevice, 6, Input)
190 AROS_LIBFUNC_INIT
192 /* Everything already done. */
193 return 0;
195 AROS_LIBFUNC_EXIT