revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / arch / all-mingw32 / hidd / wingdi / wingdi_kbdclass.c
blobbab2ef2a00e65135dcfd44fb8305a9419e83e060
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: GDI hidd handling keypresses.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <aros/debug.h>
12 #include <aros/symbolsets.h>
13 #include <devices/inputevent.h>
14 #include <devices/rawkeycodes.h>
15 #include <oop/oop.h>
16 #include <hidd/hidd.h>
17 #include <hidd/keyboard.h>
19 #include <proto/kernel.h>
20 #include <proto/utility.h>
21 #include <proto/oop.h>
23 #include LC_LIBDEFS_FILE
24 #include "gdi.h"
26 #define NOKEY -1
28 #include "stdkeytable.h"
29 #include "e0keytable.h"
31 /****************************************************************************************/
33 static OOP_AttrBase HiddKbdAB;
35 static struct OOP_ABDescr attrbases[] =
37 { IID_Hidd_Kbd , &HiddKbdAB },
38 { NULL , NULL }
41 /****************************************************************************************/
43 static VOID KbdIntHandler(struct gdikbd_data *data, volatile struct GDI_Control *KEYBOARDDATA)
45 const WORD *keytable;
46 UBYTE numkeys;
47 WORD keycode;
48 UWORD eventcode = KEYBOARDDATA->KbdEvent;
49 UWORD rawcode = KEYBOARDDATA->KeyCode;
52 * Signal to event processing thread that we've read the event.
53 * Omit Forbid()/Permit() pair here because we are inside interrupt.
55 native_func->GDI_KbdAck();
57 if (rawcode & 0x0100)
59 keytable = e0_keytable;
60 numkeys = NUM_E0KEYS;
62 else
64 keytable = std_keytable;
65 numkeys = NUM_STDKEYS;
67 rawcode &= 0x00FF;
69 if (rawcode < numkeys)
71 keycode = keytable[rawcode];
72 if (keycode != NOKEY)
74 if (eventcode == WM_KEYUP)
75 keycode |= IECODE_UP_PREFIX;
77 data->kbd_callback(data->callbackdata, keycode);
82 /****************************************************************************************/
84 OOP_Object * GDIKbd__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
86 struct TagItem *tag, *tstate;
87 APTR callback = NULL;
88 APTR callbackdata = NULL;
90 EnterFunc(bug("GDIKbd::New()\n"));
92 if (XSD(cl)->kbdhidd)
94 /* It is illegal to create more than one object */
95 ReturnPtr("GDIKbd::New", OOP_Object *, NULL);
98 tstate = msg->attrList;
99 D(bug("attrList: 0x%p\n", tstate));
101 while ((tag = NextTagItem(&tstate)))
103 ULONG idx;
105 D(bug("Got tag %d, data %x\n", tag->ti_Tag, tag->ti_Data));
107 if (IS_HIDDKBD_ATTR(tag->ti_Tag, idx))
109 D(bug("Kbd hidd tag\n"));
110 switch (idx)
112 case aoHidd_Kbd_IrqHandler:
113 callback = (APTR)tag->ti_Data;
114 D(bug("Got callback %p\n", (APTR)tag->ti_Data));
115 break;
117 case aoHidd_Kbd_IrqHandlerData:
118 callbackdata = (APTR)tag->ti_Data;
119 D(bug("Got data %p\n", (APTR)tag->ti_Data));
120 break;
124 } /* while (tags to process) */
126 if (NULL == callback)
127 ReturnPtr("GDIKbd::New", OOP_Object *, NULL); /* Should have some error code here */
129 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
130 if (o)
132 struct gdikbd_data *data = OOP_INST_DATA(cl, o);
133 struct GDI_Control *ctl = XSD(cl)->ctl;
135 data->interrupt = KrnAddIRQHandler(ctl->KbdIrq, KbdIntHandler, data, ctl);
136 if (data->interrupt)
138 data->kbd_callback = (VOID (*)(APTR, UWORD))callback;
139 data->callbackdata = callbackdata;
141 XSD(cl)->kbdhidd = o;
143 ReturnPtr("GDIKbd::New", OOP_Object *, o);
145 OOP_MethodID disp_mid = OOP_GetMethodID(IID_Root, moRoot_Dispose);
146 OOP_CoerceMethod(cl, o, (OOP_Msg) &disp_mid);
148 return NULL;
151 /****************************************************************************************/
153 VOID GDIKbd__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
155 struct gdikbd_data *data = OOP_INST_DATA(cl, o);
157 EnterFunc(bug("[GDIKbd] Dispose()\n"));
159 KrnRemIRQHandler(data->interrupt);
160 ObtainSemaphore( &XSD(cl)->sema);
161 XSD(cl)->kbdhidd = NULL;
162 ReleaseSemaphore( &XSD(cl)->sema);
163 OOP_DoSuperMethod(cl, o, msg);
166 /****************************************************************************************/
168 static int kbd_init(LIBBASETYPEPTR LIBBASE)
170 return OOP_ObtainAttrBases(attrbases);
173 /****************************************************************************************/
175 static int kbd_expunge(LIBBASETYPEPTR LIBBASE)
177 OOP_ReleaseAttrBases(attrbases);
178 return TRUE;
181 /****************************************************************************************/
183 ADD2INITLIB(kbd_init, 0);
184 ADD2EXPUNGELIB(kbd_expunge, 0);