1 /* This file is included by ibmpc.c, i386.c, and os2.c. It provides a
2 * mapping from the scan code/shift state to an escape sequence.
3 */
4 /* Copyright (c) 1992, 1998 John E. Davis
5 * This file is part of JED editor library source.
6 *
7 * You may distribute this file under the terms the GNU General Public
8 * License. See the file COPYING for more information.
9 */
10 #define RSHIFT_MASK 0x1
11 #define LSHIFT_MASK 0x2
12 #define CTRL_KEY_MASK 0x4
13 #define ALT_KEY_MASK 0x8
14 #define SHIFT_MASK (RSHIFT_MASK|LSHIFT_MASK)
15
16 static unsigned char F_Keys[4][12] =
17 {
18 { 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 133, 134 },
19 { 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 135, 136 },
20 { 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 137, 138 },
21 { 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 139, 140 }
22 };
23
24 static unsigned char Small_Keypad_Keys[4][13] =
25 {
26 { 'G', 'H', 'I', 0, 'K', 0, 'M', 0, 'O', 'P', 'Q', 'R', 'S' }, /* normal */
27 { '0', '1', '2', 0, '3', 0, '4', 0, '5', '6', '7', '8', '9' }, /* shift */
28 { 'w', 141, 132, 0, 's', 0, 't', 0, 'u', 145, 'v', 146, 147 }, /* ctrl */
29 { 151, 152, 153, 0, 155, 0, 157, 0, 159, 160, 161, 162, 163 } /* alt */
30 };
31
32 static unsigned char Num_Keypad_Keys[4][13] =
33 {
34 { 'w', 'x', 'y', 0, 't', 'u', 'v', 0, 'q', 'r', 's', 'p', 'n' },
35 { '0', '1', '2', 0, '3', 0 , '4', 0, '5', '6', '7', '8', '9' },
36 { 'w', 141, 132, 0, 's', 143, 't', 0, 'u', 145, 'v', 146, 147 },
37 { 'w', 'x', 'y', 0, 't', 'u', 'v', 0, 'q', 'r', 's', 'p', 'n' }
38 };
39
40 static char *Alt_Map = "!@#$%^&*()-=\t*\0177QWERTYUIOP[]\r*ASDFGHJKL;'`*\\ZXCVBNM<>/";
41
default_scan_to_key(unsigned int scan,unsigned int shift,unsigned char * chp)42 static unsigned int default_scan_to_key (unsigned int scan, unsigned int shift,
43 unsigned char *chp)
44 {
45 unsigned char ch;
46
47 ch = (scan & 0xFF);
48 chp[0] = ch;
49
50 if (ch != 0)
51 return 1;
52
53 ch = (scan >> 8);
54
55 if ((PC_Alt_Char == 0) || (shift != ALT_KEY_MASK))
56 {
57 chp[1] = ch;
58 return 2;
59 }
60
61 if ((ch >= 14) && (ch <= 53))
62 ch = (unsigned char) Alt_Map[ch];
63 else if ((ch >= 120) && (ch <= 131))
64 ch = (unsigned char) Alt_Map[ch - 120];
65 else if (ch == 165) /* tab */
66 ch = (unsigned char) Alt_Map[12];
67
68 chp[0] = PC_Alt_Char;
69 chp[1] = ch;
70
71 return 2;
72 }
73
jed_scan_to_key(unsigned int scan,unsigned int shift,unsigned char * chbuf)74 static unsigned int jed_scan_to_key (unsigned int scan, unsigned int shift,
75 unsigned char *chbuf)
76 {
77 unsigned int i;
78 unsigned int state;
79 int c1;
80
81 switch (scan)
82 {
83 case 0x0E08: /* backspace */
84 *chbuf = 127;
85 return 1;
86
87 case 0xE02F: /* KEYPAD SLASH */
88 c1 = 'Q';
89 break;
90
91 case 0x372A: /* KEYPAD STAR */
92 c1 = 'R';
93 break;
94
95 case 0x4A2D: /* KEYPAD MINUS */
96 c1 = 'S';
97 break;
98
99 case 0x4E2B: /* KEYPAD PLUS */
100 c1 = 'm';
101 break;
102
103 case 0xE00D: /* KEYPAD ENTER */
104 c1 = 'M';
105 break;
106
107 case 0x4700: /* KEYPAD HOME */
108 case 0x4800: /* KEYPAD UP */
109 case 0x4900: /* KEYPAD PGUP */
110 case 0x4B00: /* KEYPAD LEFT */
111 case 0x4C00: /* KEYPAD 5 */
112 case 0x4D00: /* KEYPAD RIGHT */
113 case 0x4F00: /* KEYPAD END */
114 case 0x5000: /* KEYPAD DOWN */
115 case 0x5100: /* KEYPAD PGDN */
116 case 0x5300: /* KEYPAD DEL */
117 case 0x5200: /* KEYPAD INSERT */
118 state = 0;
119 if (shift & SHIFT_MASK) state = 1;
120 if (shift & CTRL_KEY_MASK) state = 2;
121 if (shift & ALT_KEY_MASK) state = 3;
122
123 i = (scan >> 8);
124 c1 = Num_Keypad_Keys[state][i - 0x47];
125 if (shift & (CTRL_KEY_MASK | ALT_KEY_MASK))
126 {
127 chbuf[0] = 0;
128 chbuf[1] = c1;
129 return 2;
130 }
131 break;
132
133 case 0x47E0: /* home */
134 case 0x48E0: /* UP */
135 case 0x49E0: /* PGUP */
136 case 0x4BE0: /* LEFT */
137 case 0x4DE0: /* RIGHT */
138 case 0x4FE0: /* END */
139 case 0x50E0: /* DOWN */
140 case 0x51E0: /* PGDN */
141 case 0x53E0: /* DEL */
142 case 0x52E0: /* INSERT */
143
144 chbuf[0] = 0;
145 state = 0;
146 i = (scan >> 8) - 0x47;
147 if (shift & SHIFT_MASK) state = 1;
148 if (shift & CTRL_KEY_MASK) state = 2;
149 if (shift & ALT_KEY_MASK)
150 {
151 chbuf[0] = 0;
152 state = 3;
153 }
154
155 chbuf[1] = Small_Keypad_Keys[state][i];
156 return 2;
157
158 case 0x8500: /* F11 */
159 case 0x8600: /* F12 */
160 scan = 0x4500 + (scan - 0x8500);
161 /* Drop */
162
163 case 0x3b00: /* F1 */
164 case 0x3c00:
165 case 0x3d00:
166 case 0x3e00:
167 case 0x3f00:
168 case 0x4000:
169 case 0x4100:
170 case 0x4200:
171 case 0x4300:
172 case 0x4400: /* F10 */
173 i = scan >> 8;
174 i = i - 0x3b;
175
176 state = 0;
177 if (shift & SHIFT_MASK) state = 1;
178 if (shift & CTRL_KEY_MASK) state = 2;
179 if (shift & ALT_KEY_MASK) state = 3;
180
181 chbuf[0] = 0;
182 chbuf[1] = F_Keys[state][i];
183 return 2;
184
185 case 0x1C0A: /* Ctrl-RETURN */
186 return default_scan_to_key (0x1C0D, shift, chbuf);
187
188 case 0x3920: /* space */
189 if (shift & CTRL_KEY_MASK)
190 scan = 0x0300;
191 /* drop */
192
193 default:
194 return default_scan_to_key (scan, shift, chbuf);
195 }
196
197 chbuf[0] = 27;
198 chbuf[1] = 'O';
199 chbuf[2] = c1;
200 return 3;
201 }
202