More header massaging... works great on Windows. ;-)
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 * Atari keyboard events manager, using BIOS
30 #include <mint/osbind.h>
31 #include <mint/cookie.h>
33 #include "SDL_sysevents.h"
34 #include "SDL_events_c.h"
36 #include "SDL_atarikeys.h"
37 #include "SDL_atarievents_c.h"
38 #include "SDL_xbiosevents_c.h"
40 /* To save state of keyboard */
41 #define ATARIBIOS_MAXKEYS 128
43 static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
44 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
45 static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
47 /* Special keys state */
58 /* The translation tables from a console scancode to a SDL keysym */
59 static SDLKey keymap[ATARIBIOS_MAXKEYS];
61 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
63 static void UpdateSpecialKeys(int special_keys_state);
65 void AtariBios_InitOSKeymap(_THIS)
70 SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
71 SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
73 /* Initialize keymap */
74 for ( i=0; i<sizeof(keymap); i++ )
75 keymap[i] = SDLK_UNKNOWN;
78 for ( i = 0; i<10; i++ )
79 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
82 keymap[SCANCODE_HELP] = SDLK_HELP;
83 keymap[SCANCODE_UNDO] = SDLK_UNDO;
84 keymap[SCANCODE_INSERT] = SDLK_INSERT;
85 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
86 keymap[SCANCODE_UP] = SDLK_UP;
87 keymap[SCANCODE_DOWN] = SDLK_DOWN;
88 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
89 keymap[SCANCODE_LEFT] = SDLK_LEFT;
92 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
93 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
94 keymap[SCANCODE_TAB] = SDLK_TAB;
95 keymap[SCANCODE_ENTER] = SDLK_RETURN;
96 keymap[SCANCODE_DELETE] = SDLK_DELETE;
97 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
98 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
99 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
100 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
101 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
103 vectors_mask = ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS;
104 if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
108 SDL_AtariXbios_InstallVectors(vectors_mask);
111 void AtariBios_PumpEvents(_THIS)
116 /* Update pressed keys */
117 SDL_memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
119 while (Bconstat(_CON)) {
120 unsigned long key_pressed;
121 unsigned char asciicode, scancode;
123 key_pressed=Bconin(_CON);
125 asciicode = key_pressed;
126 scancode = key_pressed >> 16;
128 bios_currentkeyboard[scancode]=0xFF;
129 bios_currentascii[scancode]=asciicode;
132 /* Read special keys */
133 UpdateSpecialKeys(Kbshift(-1));
135 /* Now generate events */
136 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
138 if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
139 SDL_PrivateKeyboard(SDL_PRESSED,
140 TranslateKey(i, bios_currentascii[i], &keysym, SDL_TRUE));
142 /* Key unpressed ? */
143 if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
144 SDL_PrivateKeyboard(SDL_RELEASED,
145 TranslateKey(i, bios_currentascii[i], &keysym, SDL_FALSE));
148 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
150 /* Will be previous table */
151 SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
154 static void UpdateSpecialKeys(int special_keys_state)
156 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
158 if (special_keys_state & (1<<(numbit))) { \
159 bios_currentkeyboard[scancode]=0xFF; \
160 bios_currentascii[scancode]=0; \
164 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
165 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
166 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
167 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
168 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
171 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
174 /* Set the keysym information */
175 keysym->scancode = scancode;
178 keysym->sym = asciicode;
180 keysym->sym = keymap[scancode];
182 keysym->mod = KMOD_NONE;
184 if (SDL_TranslateUNICODE && pressed) {
185 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
191 void AtariBios_ShutdownEvents(void)
193 SDL_AtariXbios_RestoreVectors();