1
by Zed Pobre
Import upstream version 1.8.0 |
1 |
/*
|
2 |
* kbd.c - Keyboard emulation for BeOS.
|
|
3 |
*
|
|
4 |
* Written by
|
|
5 |
* Andreas Matthies <andreas.matthies@gmx.net>
|
|
6 |
*
|
|
7 |
* This file is part of VICE, the Versatile Commodore Emulator.
|
|
8 |
* See README for copyright notice.
|
|
9 |
*
|
|
10 |
* This program is free software; you can redistribute it and/or modify
|
|
11 |
* it under the terms of the GNU General Public License as published by
|
|
12 |
* the Free Software Foundation; either version 2 of the License, or
|
|
13 |
* (at your option) any later version.
|
|
14 |
*
|
|
15 |
* This program is distributed in the hope that it will be useful,
|
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 |
* GNU General Public License for more details.
|
|
19 |
*
|
|
20 |
* You should have received a copy of the GNU General Public License
|
|
21 |
* along with this program; if not, write to the Free Software
|
|
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
23 |
* 02111-1307 USA.
|
|
24 |
*
|
|
25 |
*/
|
|
26 |
||
27 |
#include "vice.h" |
|
28 |
||
29 |
#include <stdio.h> |
|
30 |
#include <stdlib.h> |
|
31 |
||
32 |
#include "kbd.h" |
|
33 |
#include "cmdline.h" |
|
1.1.1
by Zed Pobre
Import upstream version 1.14 |
34 |
#include "joy.h" |
1
by Zed Pobre
Import upstream version 1.8.0 |
35 |
#include "keyboard.h" |
1.1.1
by Zed Pobre
Import upstream version 1.14 |
36 |
#include "lib.h" |
1
by Zed Pobre
Import upstream version 1.8.0 |
37 |
#include "resources.h" |
38 |
#include "machine.h" |
|
1.2.2
by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg |
39 |
#include "translate.h" |
1
by Zed Pobre
Import upstream version 1.8.0 |
40 |
#include "types.h" |
41 |
||
42 |
/* ------------------------------------------------------------------------ */
|
|
43 |
||
44 |
/* #define DEBUG_KBD */
|
|
45 |
||
46 |
/* Debugging stuff. */
|
|
47 |
#ifdef DEBUG_KBD
|
|
48 |
static void kbd_debug(const char *format, ...) |
|
49 |
{
|
|
50 |
}
|
|
51 |
#define KBD_DEBUG(x) kbd_debug x
|
|
52 |
#else
|
|
53 |
#define KBD_DEBUG(x)
|
|
54 |
#endif
|
|
55 |
||
56 |
/* ------------------------------------------------------------------------ */
|
|
57 |
||
1.2.2
by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg |
58 |
#ifndef COMMON_KBD
|
1
by Zed Pobre
Import upstream version 1.8.0 |
59 |
/* 40/80 column key. */
|
60 |
static key_ctrl_column4080_func_t key_ctrl_column4080_func = NULL; |
|
61 |
||
62 |
/* CAPS key. */
|
|
63 |
static key_ctrl_caps_func_t key_ctrl_caps_func = NULL; |
|
1.2.2
by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg |
64 |
#endif
|
1
by Zed Pobre
Import upstream version 1.8.0 |
65 |
|
66 |
struct _convmap { |
|
67 |
/* Conversion map. */
|
|
68 |
keyconv *map; |
|
69 |
/* Location of the virtual shift key in the keyboard matrix. */
|
|
70 |
int virtual_shift_row, virtual_shift_column; |
|
71 |
};
|
|
72 |
||
73 |
static struct _convmap *keyconvmaps; |
|
74 |
static struct _convmap *keyconv_base; |
|
75 |
static int num_keyconvmaps; |
|
76 |
||
77 |
static int keymap_index; |
|
78 |
||
79 |
/* ------------------------------------------------------------------------ */
|
|
80 |
||
81 |
int kbd_init(int num, ...) |
|
82 |
{
|
|
83 |
va_list p; |
|
84 |
int i; |
|
85 |
||
1.1.1
by Zed Pobre
Import upstream version 1.14 |
86 |
keyconvmaps=(struct _convmap*)lib_malloc(num*sizeof(struct _convmap)); |
1
by Zed Pobre
Import upstream version 1.8.0 |
87 |
num_keyconvmaps=num; |
88 |
||
89 |
va_start(p,num); |
|
90 |
for (i =0; i<num_keyconvmaps; i++) { |
|
91 |
keyconv *map; |
|
92 |
unsigned int sizeof_map; |
|
93 |
int shift_row,shift_column; |
|
94 |
shift_row=va_arg(p,int); |
|
95 |
shift_column=va_arg(p,int); |
|
96 |
map=va_arg(p,keyconv*); |
|
97 |
sizeof_map=va_arg(p,unsigned int); |
|
98 |
||
99 |
keyconvmaps[i].map = map; |
|
100 |
keyconvmaps[i].virtual_shift_row = shift_row; |
|
101 |
keyconvmaps[i].virtual_shift_column = shift_column; |
|
102 |
}
|
|
103 |
keyconv_base=&keyconvmaps[keymap_index>>1]; |
|
104 |
||
105 |
return 0; |
|
106 |
}
|
|
107 |
||
1.1.5
by Laszlo Boszormenyi (GCS)
Import upstream version 1.22 |
108 |
static int set_keymap_index(int val, void *param) |
1
by Zed Pobre
Import upstream version 1.8.0 |
109 |
{
|
1.1.5
by Laszlo Boszormenyi (GCS)
Import upstream version 1.22 |
110 |
int real_index; |
1
by Zed Pobre
Import upstream version 1.8.0 |
111 |
|
1.1.5
by Laszlo Boszormenyi (GCS)
Import upstream version 1.22 |
112 |
keymap_index=val; |
1
by Zed Pobre
Import upstream version 1.8.0 |
113 |
real_index=keymap_index>>1; |
114 |
keyconv_base=&keyconvmaps[real_index]; |
|
115 |
||
116 |
return 0; |
|
117 |
}
|
|
118 |
||
1.1.5
by Laszlo Boszormenyi (GCS)
Import upstream version 1.22 |
119 |
static const resource_int_t resources_int[] = { |
120 |
{ "KeymapIndex", 0, RES_EVENT_NO, NULL, |
|
121 |
&keymap_index, set_keymap_index, NULL }, |
|
1
by Zed Pobre
Import upstream version 1.8.0 |
122 |
{ NULL } |
123 |
};
|
|
124 |
||
125 |
int kbd_resources_init(void) |
|
126 |
{
|
|
1.1.5
by Laszlo Boszormenyi (GCS)
Import upstream version 1.22 |
127 |
return resources_register_int(resources_int); |
1
by Zed Pobre
Import upstream version 1.8.0 |
128 |
}
|
129 |
||
1.1.1
by Zed Pobre
Import upstream version 1.14 |
130 |
static const cmdline_option_t cmdline_options[] = { |
1.2.2
by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg |
131 |
{ "-keymap", SET_RESOURCE, 1, |
132 |
NULL, NULL, "KeymapIndex", NULL, |
|
133 |
USE_PARAM_STRING, USE_DESCRIPTION_STRING, |
|
134 |
IDCLS_UNUSED, IDCLS_UNUSED, |
|
1
by Zed Pobre
Import upstream version 1.8.0 |
135 |
"<number>", "Specify index of used keymap" }, |
136 |
{ NULL }, |
|
137 |
};
|
|
138 |
||
139 |
int kbd_cmdline_options_init(void) |
|
140 |
{
|
|
141 |
return cmdline_register_options(cmdline_options); |
|
142 |
}
|
|
143 |
||
144 |
/* ------------------------------------------------------------------------ */
|
|
145 |
||
146 |
int kbd_handle_keydown(int kcode) |
|
147 |
{
|
|
1.1.1
by Zed Pobre
Import upstream version 1.14 |
148 |
#ifndef COMMON_KBD
|
1
by Zed Pobre
Import upstream version 1.8.0 |
149 |
if (kcode == 8) /* F7 */ { |
150 |
if (key_ctrl_column4080_func != NULL) { |
|
151 |
key_ctrl_column4080_func(); |
|
152 |
}
|
|
153 |
}
|
|
154 |
||
155 |
if (kcode == 5) /* F4 */ { |
|
156 |
if (key_ctrl_caps_func != NULL) { |
|
157 |
key_ctrl_caps_func(); |
|
158 |
}
|
|
159 |
}
|
|
160 |
||
161 |
if (kcode == 33) /* PgUp */ { |
|
162 |
machine_set_restore_key(1); |
|
163 |
}
|
|
164 |
||
165 |
if (!joystick_handle_key(kcode, 1)) { |
|
166 |
keyboard_set_keyarr(keyconv_base->map[kcode].row, |
|
167 |
keyconv_base->map[kcode].column, 1); |
|
168 |
if (keyconv_base->map[kcode].vshift) |
|
169 |
keyboard_set_keyarr(keyconv_base->virtual_shift_row, |
|
170 |
keyconv_base->virtual_shift_column, 1); |
|
171 |
}
|
|
1.1.1
by Zed Pobre
Import upstream version 1.14 |
172 |
#else
|
173 |
if (!joystick_handle_key(kcode, 1)) |
|
174 |
keyboard_key_pressed((signed long)kcode); |
|
175 |
#endif
|
|
176 |
||
1
by Zed Pobre
Import upstream version 1.8.0 |
177 |
return 0; |
178 |
}
|
|
179 |
||
180 |
int kbd_handle_keyup(int kcode) |
|
181 |
{
|
|
1.1.1
by Zed Pobre
Import upstream version 1.14 |
182 |
#ifndef COMMON_KBD
|
1
by Zed Pobre
Import upstream version 1.8.0 |
183 |
if (kcode == 33) /* PgUp */ { |
184 |
machine_set_restore_key(0); |
|
185 |
}
|
|
186 |
||
187 |
if (!joystick_handle_key(kcode, 0)) { |
|
188 |
keyboard_set_keyarr(keyconv_base->map[kcode].row, |
|
189 |
keyconv_base->map[kcode].column, 0); |
|
190 |
if (keyconv_base->map[kcode].vshift) |
|
191 |
keyboard_set_keyarr(keyconv_base->virtual_shift_row, |
|
192 |
keyconv_base->virtual_shift_column, 0); |
|
193 |
}
|
|
1.1.1
by Zed Pobre
Import upstream version 1.14 |
194 |
#else
|
195 |
if (!joystick_handle_key(kcode, 0)) |
|
196 |
keyboard_key_released((signed long)kcode); |
|
197 |
#endif
|
|
1
by Zed Pobre
Import upstream version 1.8.0 |
198 |
|
199 |
return 0; |
|
200 |
}
|
|
201 |
||
202 |
const char *kbd_code_to_string(int kcode) |
|
203 |
{
|
|
204 |
static char *tab[256] = { |
|
205 |
"<None>", "Esc", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", |
|
206 |
"F11", "F12", "PrtScr", "Scroll Lock", "16", "^", "1", "2", "3", "4", |
|
207 |
"5", "6", "7", "8", "9", "0", "-", "=", "Backspace", "Ins", "Home", |
|
208 |
"PgUp", "Num Lock", "Numpad /", "Numpad *", "Numpad -", "Tab", "Q", "W", "E", "R", |
|
209 |
"T", "Y", "U", "I", "O", "P", "{", "}", "\\", "Del", "End", |
|
210 |
"PgDown", "Numpad 7", "Numpad 8", "Numpad 9", "Numpad +", "Caps Lock", "A", "S", "D", "F", |
|
211 |
"G", "H", "J", "K", "L", ";", "'", "Enter", "Numpad 4", "Numpad 5", "Numpad 6", |
|
212 |
"Left Shift", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", |
|
213 |
"Right Shift", "Up", "Numpad 1", "Numpad 2", "Numpad 3", "Numpad Enter", "Left Ctrl", "Left ALt", |
|
214 |
"Space", "Right Alt", "Right Ctrl", "Left", "Down", "Right", "Numpad 0", "Numpad Dot", |
|
215 |
"Left Win95", "Right Win95", "Break" |
|
216 |
};
|
|
217 |
||
218 |
return tab[(int) kcode]; |
|
219 |
}
|
|
220 |
||
221 |
/* ------------------------------------------------------------------------ */
|
|
1.1.1
by Zed Pobre
Import upstream version 1.14 |
222 |
#ifndef COMMON_KBD
|
223 |
void keyboard_register_column4080_key(key_ctrl_column4080_func_t func) |
|
1
by Zed Pobre
Import upstream version 1.8.0 |
224 |
{
|
225 |
key_ctrl_column4080_func = func; |
|
226 |
}
|
|
227 |
||
1.1.1
by Zed Pobre
Import upstream version 1.14 |
228 |
void keyboard_register_caps_key(key_ctrl_caps_func_t func) |
1
by Zed Pobre
Import upstream version 1.8.0 |
229 |
{
|
230 |
key_ctrl_caps_func = func; |
|
231 |
}
|
|
1.1.1
by Zed Pobre
Import upstream version 1.14 |
232 |
#endif
|
233 |
||
234 |
#ifdef COMMON_KBD
|
|
1.1.5
by Laszlo Boszormenyi (GCS)
Import upstream version 1.22 |
235 |
void kbd_initialize_numpad_joykeys(int* joykeys) |
236 |
{
|
|
237 |
joykeys[0] = K_RIGHTCTRL; |
|
238 |
joykeys[1] = K_KP1; |
|
239 |
joykeys[2] = K_KP2; |
|
240 |
joykeys[3] = K_KP3; |
|
241 |
joykeys[4] = K_KP4; |
|
242 |
joykeys[5] = K_KP6; |
|
243 |
joykeys[6] = K_KP7; |
|
244 |
joykeys[7] = K_KP8; |
|
245 |
joykeys[8] = K_KP9; |
|
246 |
}
|
|
247 |
||
1.1.1
by Zed Pobre
Import upstream version 1.14 |
248 |
void kbd_arch_init(void) |
249 |
{
|
|
250 |
}
|
|
251 |
||
252 |
signed long kbd_arch_keyname_to_keynum(char *keyname) |
|
253 |
{
|
|
254 |
return (signed long)atoi(keyname); |
|
255 |
}
|
|
256 |
||
257 |
const char *kbd_arch_keynum_to_keyname(signed long keynum) |
|
258 |
{
|
|
259 |
static char keyname[20]; |
|
260 |
||
261 |
memset(keyname, 0, 20); |
|
262 |
||
263 |
sprintf(keyname, "%li", keynum); |
|
264 |
||
265 |
return keyname; |
|
266 |
}
|
|
267 |
#endif
|
|
268 |
||
1
by Zed Pobre
Import upstream version 1.8.0 |
269 |