-
Notifications
You must be signed in to change notification settings - Fork 49
/
ksvgab.c
339 lines (289 loc) · 8.61 KB
/
ksvgab.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
* This file is part of the Advance project.
*
* Copyright (C) 2001, 2002, 2003 Andrea Mazzoleni
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* In addition, as a special exception, Andrea Mazzoleni
* gives permission to link the code of this program with
* the MAME library (or with modified versions of MAME that use the
* same license as MAME), and distribute linked combinations including
* the two. You must obey the GNU General Public License in all
* respects for all of the code used other than MAME. If you modify
* this file, you may extend this exception to your version of the
* file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*/
#include "portable.h"
#include "ksvgab.h"
#include "log.h"
#include "error.h"
#include "oslinux.h"
#include <vgakeyboard.h>
#define LOW_INVALID ((unsigned)0xFFFFFFFF)
struct keyb_svgalib_context {
unsigned map_up_to_low[KEYB_MAX];
adv_bool disable_special_flag;
};
static struct keyb_pair {
unsigned up_code;
unsigned low_code;
} KEYS[] = {
{ KEYB_A, SCANCODE_A },
{ KEYB_B, SCANCODE_B },
{ KEYB_C, SCANCODE_C },
{ KEYB_D, SCANCODE_D },
{ KEYB_E, SCANCODE_E },
{ KEYB_F, SCANCODE_F },
{ KEYB_G, SCANCODE_G },
{ KEYB_H, SCANCODE_H },
{ KEYB_I, SCANCODE_I },
{ KEYB_J, SCANCODE_J },
{ KEYB_K, SCANCODE_K },
{ KEYB_L, SCANCODE_L },
{ KEYB_M, SCANCODE_M },
{ KEYB_N, SCANCODE_N },
{ KEYB_O, SCANCODE_O },
{ KEYB_P, SCANCODE_P },
{ KEYB_Q, SCANCODE_Q },
{ KEYB_R, SCANCODE_R },
{ KEYB_S, SCANCODE_S },
{ KEYB_T, SCANCODE_T },
{ KEYB_U, SCANCODE_U },
{ KEYB_V, SCANCODE_V },
{ KEYB_W, SCANCODE_W },
{ KEYB_X, SCANCODE_X },
{ KEYB_Y, SCANCODE_Y },
{ KEYB_Z, SCANCODE_Z },
{ KEYB_0, SCANCODE_0 },
{ KEYB_1, SCANCODE_1 },
{ KEYB_2, SCANCODE_2 },
{ KEYB_3, SCANCODE_3 },
{ KEYB_4, SCANCODE_4 },
{ KEYB_5, SCANCODE_5 },
{ KEYB_6, SCANCODE_6 },
{ KEYB_7, SCANCODE_7 },
{ KEYB_8, SCANCODE_8 },
{ KEYB_9, SCANCODE_9 },
{ KEYB_0_PAD, SCANCODE_KEYPAD0 },
{ KEYB_1_PAD, SCANCODE_KEYPAD1 },
{ KEYB_2_PAD, SCANCODE_KEYPAD2 },
{ KEYB_3_PAD, SCANCODE_KEYPAD3 },
{ KEYB_4_PAD, SCANCODE_KEYPAD4 },
{ KEYB_5_PAD, SCANCODE_KEYPAD5 },
{ KEYB_6_PAD, SCANCODE_KEYPAD6 },
{ KEYB_7_PAD, SCANCODE_KEYPAD7 },
{ KEYB_8_PAD, SCANCODE_KEYPAD8 },
{ KEYB_9_PAD, SCANCODE_KEYPAD9 },
{ KEYB_F1, SCANCODE_F1 },
{ KEYB_F2, SCANCODE_F2 },
{ KEYB_F3, SCANCODE_F3 },
{ KEYB_F4, SCANCODE_F4 },
{ KEYB_F5, SCANCODE_F5 },
{ KEYB_F6, SCANCODE_F6 },
{ KEYB_F7, SCANCODE_F7 },
{ KEYB_F8, SCANCODE_F8 },
{ KEYB_F9, SCANCODE_F9 },
{ KEYB_F10, SCANCODE_F10 },
{ KEYB_F11, SCANCODE_F11 },
{ KEYB_F12, SCANCODE_F12 },
{ KEYB_ESC, SCANCODE_ESCAPE },
{ KEYB_BACKQUOTE, SCANCODE_GRAVE },
{ KEYB_MINUS, SCANCODE_MINUS },
{ KEYB_EQUALS, SCANCODE_EQUAL },
{ KEYB_BACKSPACE, SCANCODE_BACKSPACE },
{ KEYB_TAB, SCANCODE_TAB },
{ KEYB_OPENBRACE, SCANCODE_BRACKET_LEFT },
{ KEYB_CLOSEBRACE, SCANCODE_BRACKET_RIGHT },
{ KEYB_ENTER, SCANCODE_ENTER },
{ KEYB_SEMICOLON, SCANCODE_SEMICOLON },
{ KEYB_QUOTE, SCANCODE_APOSTROPHE },
{ KEYB_BACKSLASH, SCANCODE_BACKSLASH },
{ KEYB_LESS, SCANCODE_LESS },
{ KEYB_COMMA, SCANCODE_COMMA },
{ KEYB_PERIOD, SCANCODE_PERIOD },
{ KEYB_SLASH, SCANCODE_SLASH },
{ KEYB_SPACE, SCANCODE_SPACE },
{ KEYB_INSERT, SCANCODE_INSERT },
{ KEYB_DEL, SCANCODE_REMOVE },
{ KEYB_HOME, SCANCODE_HOME },
{ KEYB_END, SCANCODE_END },
{ KEYB_PGUP, SCANCODE_PAGEUP },
{ KEYB_PGDN, SCANCODE_PAGEDOWN },
{ KEYB_LEFT, SCANCODE_CURSORBLOCKLEFT },
{ KEYB_RIGHT, SCANCODE_CURSORBLOCKRIGHT },
{ KEYB_UP, SCANCODE_CURSORBLOCKUP },
{ KEYB_DOWN, SCANCODE_CURSORBLOCKDOWN },
{ KEYB_SLASH_PAD, SCANCODE_KEYPADDIVIDE },
{ KEYB_ASTERISK, SCANCODE_KEYPADMULTIPLY },
{ KEYB_MINUS_PAD, SCANCODE_KEYPADMINUS },
{ KEYB_PLUS_PAD, SCANCODE_KEYPADPLUS },
{ KEYB_PERIOD_PAD, SCANCODE_KEYPADPERIOD },
{ KEYB_ENTER_PAD, SCANCODE_KEYPADENTER },
{ KEYB_PRTSCR, SCANCODE_PRINTSCREEN },
{ KEYB_PAUSE, SCANCODE_BREAK },
{ KEYB_LSHIFT, SCANCODE_LEFTSHIFT },
{ KEYB_RSHIFT, SCANCODE_RIGHTSHIFT },
{ KEYB_LCONTROL, SCANCODE_LEFTCONTROL },
{ KEYB_RCONTROL, SCANCODE_RIGHTCONTROL },
{ KEYB_ALT, SCANCODE_LEFTALT },
{ KEYB_ALTGR, SCANCODE_RIGHTALT },
{ KEYB_LWIN, SCANCODE_LEFTWIN },
{ KEYB_RWIN, SCANCODE_RIGHTWIN },
{ KEYB_MENU, 127 /* Not defined by SVGALIB */ },
{ KEYB_SCRLOCK, SCANCODE_SCROLLLOCK },
{ KEYB_NUMLOCK, SCANCODE_NUMLOCK },
{ KEYB_CAPSLOCK, SCANCODE_CAPSLOCK },
{ KEYB_MAX, 0 }
};
static struct keyb_svgalib_context svgalib_state;
static adv_device DEVICE[] = {
{ "auto", -1, "SVGALIB keyboard" },
{ 0, 0, 0 }
};
adv_error keyb_svgalib_init(int keyb_id, adv_bool disable_special)
{
struct keyb_pair* i;
unsigned j;
log_std(("keyb:svgalib: keyb_svgalib_init(id:%d, disable_special:%d)\n", keyb_id, (int)disable_special));
if (target_wm()) {
error_set("Unsupported in X.\n");
return -1;
}
if (!os_internal_svgalib_get()) {
error_set("Not supported without the svgalib library.\n");
return -1;
}
for (j = 0; j < KEYB_MAX; ++j) {
svgalib_state.map_up_to_low[j] = LOW_INVALID;
}
for (i = KEYS; i->up_code != KEYB_MAX; ++i) {
svgalib_state.map_up_to_low[i->up_code] = i->low_code;
}
svgalib_state.disable_special_flag = disable_special;
return 0;
}
void keyb_svgalib_done(void)
{
log_std(("keyb:svgalib: keyb_svgalib_done()\n"));
}
adv_error keyb_svgalib_enable(adv_bool graphics)
{
log_std(("keyb:svgalib: keyb_svgalib_enable(graphics:%d)\n", (int)graphics));
if (target_wm()) {
error_set("Unsupported in X.\n");
return -1;
}
#if defined(USE_VIDEO_SDL)
if (os_internal_sdl_is_video_active()) {
error_set("The svgalib keyboard driver cannot be used with the SDL video driver.\n");
return -1;
}
#endif
if (keyboard_init() != 0) {
error_set("Error enabling the svgalib keyboard driver. Function keyboard_init() failed.\n");
return -1;
}
if (svgalib_state.disable_special_flag) {
keyboard_translatekeys(DONT_CATCH_CTRLC);
}
keyboard_clearstate();
return 0;
}
void keyb_svgalib_disable(void)
{
log_std(("keyb:svgalib: keyb_svgalib_disable()\n"));
keyboard_close();
}
unsigned keyb_svgalib_count_get(void)
{
log_debug(("keyb:svgalib: keyb_svgalib_count_get(void)\n"));
return 1;
}
adv_bool keyb_svgalib_has(unsigned keyboard, unsigned code)
{
log_debug(("keyb:svgalib: keyb_svgalib_has()\n"));
return svgalib_state.map_up_to_low[code] != LOW_INVALID;
}
unsigned keyb_svgalib_get(unsigned keyboard, unsigned code)
{
unsigned low_code;
log_debug(("keyb:svgalib: keyb_svgalib_get(keyboard:%d,code:%d)\n", keyboard, code));
/* disable the pause key */
if (code == KEYB_PAUSE)
return 0;
low_code = svgalib_state.map_up_to_low[code];
if (low_code == LOW_INVALID)
return 0;
return keyboard_keypressed(low_code) != KEY_NOTPRESSED;
}
void keyb_svgalib_all_get(unsigned keyboard, unsigned char* code_map)
{
unsigned i;
const char* state;
log_debug(("keyb:svgalib: keyb_svgalib_all_get(keyboard:%d)\n", keyboard));
state = keyboard_getstate();
for (i = 0; i < KEYB_MAX; ++i) {
unsigned low_code = svgalib_state.map_up_to_low[i];
if (low_code == LOW_INVALID)
code_map[i] = 0;
else
code_map[i] = state[low_code] != KEY_NOTPRESSED;
}
/* disable the pause key */
code_map[KEYB_PAUSE] = 0;
}
void keyb_svgalib_led_set(unsigned keyboard, unsigned led_mask)
{
log_debug(("keyb:svgalib: keyb_svgalib_led_set(keyboard:%d,mask:%d)\n", keyboard, led_mask));
/* TODO led support */
}
int keyb_svgalib_poll(void)
{
log_debug(("keyb:svgalib: keyb_svgalib_poll()\n"));
keyboard_update();
return 0;
}
unsigned keyb_svgalib_flags(void)
{
return 0;
}
adv_error keyb_svgalib_load(adv_conf* context)
{
return 0;
}
void keyb_svgalib_reg(adv_conf* context)
{
}
/***************************************************************************/
/* Driver */
keyb_driver keyb_svgalib_driver = {
"svgalib",
DEVICE,
keyb_svgalib_load,
keyb_svgalib_reg,
keyb_svgalib_init,
keyb_svgalib_done,
keyb_svgalib_enable,
keyb_svgalib_disable,
keyb_svgalib_flags,
keyb_svgalib_count_get,
keyb_svgalib_has,
keyb_svgalib_get,
keyb_svgalib_all_get,
keyb_svgalib_led_set,
keyb_svgalib_poll
};