2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2004 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * Atari keyboard events manager, using BIOS
37 #include <mint/osbind.h>
40 #include "SDL_sysevents.h"
41 #include "SDL_events_c.h"
43 #include "SDL_atarikeys.h"
44 #include "SDL_atarievents_c.h"
45 #include "SDL_xbiosevents_c.h"
47 /* To save state of keyboard */
48 #define ATARIBIOS_MAXKEYS 128
50 static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
51 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
52 static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
54 /* Special keys state */
65 /* The translation tables from a console scancode to a SDL keysym */
66 static SDLKey keymap[ATARIBIOS_MAXKEYS];
68 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
70 static void UpdateSpecialKeys(int special_keys_state);
72 void AtariBios_InitOSKeymap(_THIS)
76 memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
77 memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
79 /* Initialize keymap */
80 for ( i=0; i<sizeof(keymap); i++ )
81 keymap[i] = SDLK_UNKNOWN;
84 for ( i = 0; i<10; i++ )
85 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
88 keymap[SCANCODE_HELP] = SDLK_HELP;
89 keymap[SCANCODE_UNDO] = SDLK_UNDO;
90 keymap[SCANCODE_INSERT] = SDLK_INSERT;
91 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
92 keymap[SCANCODE_UP] = SDLK_UP;
93 keymap[SCANCODE_DOWN] = SDLK_DOWN;
94 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
95 keymap[SCANCODE_LEFT] = SDLK_LEFT;
98 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
99 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
100 keymap[SCANCODE_TAB] = SDLK_TAB;
101 keymap[SCANCODE_ENTER] = SDLK_RETURN;
102 keymap[SCANCODE_DELETE] = SDLK_DELETE;
103 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
104 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
105 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
106 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
107 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
109 SDL_AtariXbios_InstallVectors(ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS);
112 void AtariBios_PumpEvents(_THIS)
117 /* Update pressed keys */
118 memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
120 while (Bconstat(_CON)) {
121 unsigned long key_pressed;
122 unsigned char asciicode, scancode;
124 key_pressed=Bconin(_CON);
126 asciicode = key_pressed;
127 scancode = key_pressed >> 16;
129 bios_currentkeyboard[scancode]=0xFF;
130 bios_currentascii[scancode]=asciicode;
133 /* Read special keys */
134 UpdateSpecialKeys(Kbshift(-1));
136 /* Now generate events */
137 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
139 if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
140 SDL_PrivateKeyboard(SDL_PRESSED,
141 TranslateKey(i, bios_currentascii[i], &keysym, SDL_TRUE));
143 /* Key unpressed ? */
144 if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
145 SDL_PrivateKeyboard(SDL_RELEASED,
146 TranslateKey(i, bios_currentascii[i], &keysym, SDL_FALSE));
149 SDL_AtariXbios_PostMouseEvents(this);
151 /* Will be previous table */
152 memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
155 static void UpdateSpecialKeys(int special_keys_state)
157 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
159 if (special_keys_state & (1<<(numbit))) { \
160 bios_currentkeyboard[scancode]=0xFF; \
161 bios_currentascii[scancode]=0; \
165 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
166 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
167 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
168 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
169 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
172 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
175 /* Set the keysym information */
176 keysym->scancode = scancode;
179 keysym->sym = asciicode;
181 keysym->sym = keymap[scancode];
183 keysym->mod = KMOD_NONE;
185 if (pressed && (asciicode!=0)) {
186 keysym->unicode = SDL_AtariToUnicode(asciicode);
192 void AtariBios_ShutdownEvents(void)
194 SDL_AtariXbios_RestoreVectors();