3 * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
5 * Copyright (C) 2002 Florian Schulze - crow@icculus.org
7 * This file is part of Jump'n'Bump.
9 * Jump'n'Bump is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Jump'n'Bump is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 volatile char keyb
[256];
32 volatile char last_keys
[50];
34 unsigned char scancode2ascii
[256] = {
35 0, 0, 49, 50, 51, 52, 53, 54, 55, 56, /* 0-9 */
36 57, 48, 45, 0, 0, 0, 113, 119, 101, 114, /* 10-19 */
37 116, 121, 117, 105, 111, 112, 0, 0, 0, 0, /* 20-29 */
38 97, 115, 100, 102, 103, 104, 106, 107, 108, 0, /* 30-39 */
39 0, 0, 0, 0, 122, 120, 99, 118, 98, 110, /* 40-49 */
40 109, 44, 46, 47, 0, 0, 0, 32, 0, 0, /* 50-59 */
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 _go32_dpmi_seginfo old_keyb_handler_seginfo
, new_keyb_handler_seginfo
;
78 if ((key
& 0x80) == 0) {
80 for (c1
= 48; c1
> 0; c1
--)
81 last_keys
[c1
] = last_keys
[c1
- 1];
82 last_keys
[0] = scancode2ascii
[key
& 0x7f];
86 if ((key
& 0x80) == 0) {
87 keyb
[(key
& 0x7f) + 0x80] = 1;
88 for (c1
= 48; c1
> 0; c1
--)
89 last_keys
[c1
] = last_keys
[c1
- 1];
90 last_keys
[0] = scancode2ascii
[(key
& 0x7f) + 0x80];
92 keyb
[(key
& 0x7f) + 0x80] = 0;
102 void keyb_handler_end()
107 char hook_keyb_handler(void)
110 if (keyb_handler_info
.enabled
== 0) {
111 _go32_dpmi_lock_data((char *) &keyb
, sizeof(keyb
));
112 _go32_dpmi_lock_code(keyb_handler
, (unsigned long) keyb_handler_end
- (unsigned long) keyb_handler
);
113 _go32_dpmi_get_protected_mode_interrupt_vector(9, &old_keyb_handler_seginfo
);
114 new_keyb_handler_seginfo
.pm_offset
= (int) keyb_handler
;
115 if (_go32_dpmi_allocate_iret_wrapper(&new_keyb_handler_seginfo
) != 0)
117 if (_go32_dpmi_set_protected_mode_interrupt_vector(9, &new_keyb_handler_seginfo
) != 0) {
118 _go32_dpmi_free_iret_wrapper(&new_keyb_handler_seginfo
);
121 keyb_handler_info
.enabled
= 1;
122 memset(last_keys
, 0, sizeof(last_keys
));
130 void remove_keyb_handler(void)
133 if (keyb_handler_info
.enabled
== 1) {
134 _go32_dpmi_set_protected_mode_interrupt_vector(9, &old_keyb_handler_seginfo
);
135 _go32_dpmi_free_iret_wrapper(&new_keyb_handler_seginfo
);
136 keyb_handler_info
.enabled
= 0;
142 char key_pressed(unsigned char key
)