arch/m68k-amiga: Add parallel.hidd class for Amiga m68k
[AROS.git] / rom / keymap / support.c
blob70fb6b430b38d49e0d2457048dc477c22ef822cc
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 /****************************************************************************************/
11 #include <devices/inputevent.h>
12 #include <string.h>
14 #include <aros/debug.h>
16 #include "keymap_intern.h"
18 /****************************************************************************************/
20 #if DEBUG
21 extern struct KeymapBase *DebugKeymapBase;
22 # undef SysBase
23 # define SysBase DebugKeymapBase->SysBase
25 #endif
27 /****************************************************************************************/
29 BOOL WriteToBuffer(struct BufInfo *bufinfo, UBYTE *string, LONG numchars)
31 if (bufinfo->CharsWritten + numchars > bufinfo->BufLength)
32 return (FALSE);
34 strncpy(bufinfo->Buffer, string, numchars);
35 bufinfo->CharsWritten += numchars;
37 return (TRUE);
40 /****************************************************************************************/
42 BOOL GetKeyInfo(struct KeyInfo *ki, UWORD code, UWORD qual, struct KeyMap *km)
44 BOOL valid = TRUE; /* valid code is default */
46 if (code & IECODE_UP_PREFIX) /* Key pressed ? */
48 valid = FALSE;
50 else if (code >= 128) /* Keymaps at the moment support only 128 keys */
52 valid = FALSE;
54 else
56 BYTE capsable;
57 BYTE repeatable;
59 ki->KCFQual = KC_NOQUAL; /* == 0 */
61 code &= ~IECODE_UP_PREFIX;
63 /* Convert from IEQUAL_xxx into KCF_xx */
64 if (qual & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
65 ki->KCFQual |= KCF_SHIFT;
67 if (qual & (IEQUALIFIER_LALT|IEQUALIFIER_RALT))
68 ki->KCFQual |= KCF_ALT;
70 if (qual & IEQUALIFIER_CONTROL)
71 ki->KCFQual |= KCF_CONTROL;
73 D(bug("mrk: KCF qual: %d\n", ki->KCFQual));
75 /* Get the type of the key */
76 if (code <= 0x3F)
78 /* Get key info from low keymap */
79 ki->Key_MapType = km->km_LoKeyMapTypes[code];
80 ki->Key_Mapping = km->km_LoKeyMap[code];
82 capsable = GetBitProperty(km->km_LoCapsable, code);
83 repeatable = GetBitProperty(km->km_LoRepeatable, code);
85 else
87 code -= 0x40; /* hex 40 is first indexed */
89 /* Get key info from high keymap */
90 ki->Key_MapType = km->km_HiKeyMapTypes[code];
91 ki->Key_Mapping = km->km_HiKeyMap[code];
92 capsable = GetBitProperty(km->km_HiCapsable, code);
93 repeatable = GetBitProperty(km->km_HiRepeatable, code);
96 D(bug("mrk: capsable=%d\n", capsable));
98 if ((qual & IEQUALIFIER_CAPSLOCK) && capsable)
99 ki->KCFQual |= KCF_SHIFT;
101 if ((qual & IEQUALIFIER_REPEAT) && (!repeatable))
103 valid = FALSE; /* Repeating not supported for key, skip keypress */
106 D(bug("mrk:repeat test passed\n"));
108 D(bug("mrk: key mapping: %04x\n", ki->Key_Mapping));
111 return (valid);
114 /****************************************************************************************/
116 WORD GetDeadKeyIndex(UWORD code, UWORD qual, struct KeyMap *km)
118 struct KeyInfo ki;
119 WORD retval = -1;
121 /* Get the key info for the key */
123 if (GetKeyInfo(&ki, code, qual, km))
125 if (ki.Key_MapType & KCF_DEAD)
127 BYTE idx;
129 /* Use keymap_str table to get idx to right key descriptor */
130 idx = keymapstr_table[ki.Key_MapType & KC_VANILLA][ki.KCFQual];
131 if (idx != -1)
133 UBYTE *dead_descr = (UBYTE *)ki.Key_Mapping;
135 if (dead_descr[idx * 2] == DPF_DEAD)
137 /* Clear first */
139 retval = dead_descr[idx * 2 + 1];
141 retval &= 0x00FF; /* Clear upper byte */
147 return (retval);
150 /****************************************************************************************/