ppc-sam440: Use Write-Through caching for main memory.
[AROS.git] / test / printnativekeytable.c
blob265f96e821b480750c05d528bfc2bc5933ad8f1b
1 #include <proto/exec.h>
2 #include <proto/intuition.h>
3 #include <proto/keymap.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <exec/execbase.h>
8 #include <devices/rawkeycodes.h>
9 #include <devices/inputevent.h>
11 #define NUM_STDKEYS 89
12 #define NOKEY -1
14 struct Library *KeymapBase;
16 static WORD std_keytable[NUM_STDKEYS] =
18 NOKEY , /* 000 (0x00) */
19 RAWKEY_ESCAPE , /* 001 (0x01) K_Escape */
20 RAWKEY_1 , /* 002 (0x02) K_1 */
21 RAWKEY_2 , /* 003 (0x03) K_2 */
22 RAWKEY_3 , /* 004 (0x04) K_3 */
23 RAWKEY_4 , /* 005 (0x05) K_4 */
24 RAWKEY_5 , /* 006 (0x06) K_5 */
25 RAWKEY_6 , /* 007 (0x07) K_6 */
26 RAWKEY_7 , /* 008 (0x08) K_7 */
27 RAWKEY_8 , /* 009 (0x09) K_8 */
28 RAWKEY_9 , /* 010 (0x0A) K_9 */
29 RAWKEY_0 , /* 011 (0x0B) K_0 */
30 RAWKEY_MINUS , /* 012 (0x0C) K_Minus */
31 RAWKEY_EQUAL , /* 013 (0x0D) K_Equal */
32 RAWKEY_BACKSPACE , /* 014 (0x0E) K_Backspace */
33 RAWKEY_TAB , /* 015 (0x0F) K_Tab */
34 RAWKEY_Q , /* 016 (0x10) K_Q */
35 RAWKEY_W , /* 017 (0x11) K_W */
36 RAWKEY_E , /* 018 (0x12) K_E */
37 RAWKEY_R , /* 019 (0x13) K_R */
38 RAWKEY_T , /* 020 (0x14) K_T */
39 RAWKEY_Y , /* 021 (0x15) K_Y */
40 RAWKEY_U , /* 022 (0x16) K_U */
41 RAWKEY_I , /* 023 (0x17) K_I */
42 RAWKEY_O , /* 024 (0x18) K_O */
43 RAWKEY_P , /* 025 (0x19) K_P */
44 RAWKEY_LBRACKET , /* 026 (0x1A) K_LBracket */
45 RAWKEY_RBRACKET , /* 027 (0x1B) K_RBracket */
46 RAWKEY_RETURN , /* 028 (0x1C) K_Enter */
47 RAWKEY_LCONTROL , /* 029 (0x1D) K_LCtrl */
48 RAWKEY_A , /* 030 (0x1E) K_A */
49 RAWKEY_S , /* 031 (0x1F) K_S */
50 RAWKEY_D , /* 032 (0x20) K_D */
51 RAWKEY_F , /* 033 (0x21) K_F */
52 RAWKEY_G , /* 034 (0x22) K_G */
53 RAWKEY_H , /* 035 (0x23) K_H */
54 RAWKEY_J , /* 036 (0x24) K_J */
55 RAWKEY_K , /* 037 (0x25) K_K */
56 RAWKEY_L , /* 038 (0x26) K_L */
57 RAWKEY_SEMICOLON , /* 039 (0x27) K_Semicolon */
58 RAWKEY_QUOTE , /* 040 (0x28) K_Quote */
59 RAWKEY_TILDE , /* 041 (0x29) K_BackQuote */
60 RAWKEY_LSHIFT , /* 042 (0x2A) K_LShift */
61 RAWKEY_2B , /* 043 (0x2B) K_BackSlash */
62 RAWKEY_Z , /* 044 (0x2C) K_Z */
63 RAWKEY_X , /* 045 (0x2D) K_X */
64 RAWKEY_C , /* 046 (0x2E) K_C */
65 RAWKEY_V , /* 047 (0x2F) K_V */
66 RAWKEY_B , /* 048 (0x30) K_B */
67 RAWKEY_N , /* 049 (0x31) K_N */
68 RAWKEY_M , /* 050 (0x32) K_M */
69 RAWKEY_COMMA , /* 051 (0x33) K_Comma */
70 RAWKEY_PERIOD , /* 052 (0x34) K_Period */
71 RAWKEY_SLASH , /* 053 (0x35) K_Slash */
72 RAWKEY_RSHIFT , /* 054 (0x36) K_RShift */
73 0x5c , /* 055 (0x37) K_KP_Multiply */
74 RAWKEY_LALT , /* 056 (0x38) K_LAlt */
75 RAWKEY_SPACE , /* 057 (0x39) K_Space */
76 RAWKEY_CAPSLOCK , /* 058 (0x3A) K_CapsLock */
77 RAWKEY_F1 , /* 059 (0x3B) K_F1 */
78 RAWKEY_F2 , /* 060 (0x3C) K_F2 */
79 RAWKEY_F3 , /* 061 (0x3D) K_F3 */
80 RAWKEY_F4 , /* 062 (0x3E) K_F4 */
81 RAWKEY_F5 , /* 063 (0x3F) K_F5 */
82 RAWKEY_F6 , /* 064 (0x40) K_F6 */
83 RAWKEY_F7 , /* 065 (0x41) K_F7 */
84 RAWKEY_F8 , /* 066 (0x42) K_F8 */
85 RAWKEY_F9 , /* 067 (0x43) K_F9 */
86 RAWKEY_F10 , /* 068 (0x44) K_F10 */
87 0x5A , /* 069 (0x45) K_NumLock */
88 NOKEY , /* 070 (0x46) K_Scroll_Lock ???? */
89 RAWKEY_KP_7 , /* 071 (0x47) K_KP_7 */
90 RAWKEY_KP_8 , /* 072 (0x48) K_KP_8 */
91 RAWKEY_KP_9 , /* 073 (0x49) K_KP_9 */
92 0x5D , /* 074 (0x4A) K_KP_Sub */
93 RAWKEY_KP_4 , /* 075 (0x4B) K_KP_4 */
94 RAWKEY_KP_5 , /* 076 (0x4C) K_KP_5 */
95 RAWKEY_KP_6 , /* 077 (0x4D) K_KP_6 */
96 0x5E , /* 078 (0x4E) K_KP_Add */
97 RAWKEY_KP_1 , /* 079 (0x4F) K_KP_1 */
98 RAWKEY_KP_2 , /* 080 (0x50) K_KP_2 */
99 RAWKEY_KP_3 , /* 081 (0x51) K_KP_3 */
100 RAWKEY_KP_0 , /* 082 (0x52) K_KP_0 */
101 RAWKEY_KP_DECIMAL , /* 083 (0x53) K_KP_Decimal */
102 NOKEY , /* 084 (0x54) */
103 NOKEY , /* 085 (0x55) */
104 RAWKEY_LESSGREATER , /* 086 (0x56) K_LessGreater */
105 RAWKEY_LAMIGA , /* 087 (0x57) K_F11 - Note: we map to LAMIGA, F11 rawkey code would be 0x4B */
106 RAWKEY_RAMIGA /* 088 (0x58) K_F12 - Note: we map to RAMIGA, F12 rawkey code would be 0x6F */
110 static void dotest(void)
112 struct Window *win;
113 struct IntuiMessage *msg;
114 BOOL quitme = FALSE;
116 KeymapBase = OpenLibrary("keymap.library", 0);
117 if (!KeymapBase) return;
119 win = OpenWindowTags(NULL, WA_Left, 20,
120 WA_Top, 20,
121 WA_Width, 300,
122 WA_Height, 20,
123 WA_Activate, TRUE,
124 WA_CloseGadget, TRUE,
125 WA_DepthGadget, TRUE,
126 WA_Title, (IPTR)"IDCMP_RAWKEY Test",
127 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_RAWKEY,
128 TAG_DONE);
129 if (!win)
131 CloseLibrary(KeymapBase);
132 return;
135 while(!quitme)
137 WaitPort(win->UserPort);
138 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
140 switch(msg->Class)
142 case IDCMP_CLOSEWINDOW:
143 quitme = TRUE;
144 break;
146 case IDCMP_RAWKEY:
147 printf("RAWKEY %s: %3d (0x%02x) QUAL=0x%04x DEAD=0x%08lx ",
148 (msg->Code & IECODE_UP_PREFIX) ? "UP " : "DOWN",
149 (msg->Code & ~IECODE_UP_PREFIX),
150 (msg->Code & ~IECODE_UP_PREFIX),
151 msg->Qualifier,
152 (long)*(ULONG *)msg->IAddress);
155 struct InputEvent ie;
156 char buf[20];
157 WORD ret;
159 ie.ie_Class = IECLASS_RAWKEY;
160 ie.ie_Code = msg->Code;
161 ie.ie_Qualifier = msg->Qualifier;
162 ie.ie_EventAddress = *((ULONG **) msg->IAddress);
164 ret = MapRawKey(&ie, buf, sizeof(buf), NULL);
165 if (ret >= 0) buf[ret] = 0;
167 printf("MAPPED=%3d (%s)\n", ret, (ret == -1) ? "<NONE>" : ((ret == 0) ? "<ZERO>" : buf));
169 break;
171 ReplyMsg((struct Message *)msg);
175 CloseWindow(win);
176 CloseLibrary(KeymapBase);
179 int main(int argc, char **argv)
181 WORD *table;
182 WORD startindex = 0;
183 WORD endindex = 88;
184 WORD index;
185 WORD trashed = 0;
187 if (argc == 2)
189 if (strcmp(argv[1], "test") == 0)
191 dotest();
192 return 0;
195 index = strtol(argv[1], 0, 0);
197 if (index < 0) index = 0;
198 if (index > 88) index = 88;
200 startindex = endindex = index;
203 #if AROS_SIZEOFULONG == AROS_SIZEOFPTR
204 table = (WORD *)SysBase->ex_Reserved2[1]; /* set up in config/i386-native/Drivers/keyboard/kbdclass.c */
205 #else
206 table = NULL;
207 #endif
208 if (!table)
210 puts("Error: table points to NULL!\n");
211 return 0;
214 printf("Table address = 0x%p\n\n", table);
216 for(index = startindex; index <= endindex; index++)
218 printf("#%02d: %d (0x%x)\n", index, table[index], table[index]);
219 if (table[index] != std_keytable[index]) trashed++;
222 if (trashed)
224 printf("\n=============== Found %d trashed entries ============\n", trashed);
225 for(index = startindex; index <= endindex; index++)
227 if (table[index] != std_keytable[index])
229 printf("#%02d: %d (0x%x) should be: %d (0x%x)\n", index, table[index], table[index], std_keytable[index], std_keytable[index]);
234 return 0;