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 Gemdos
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 gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
51 static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
52 static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
54 /* Special keys state */
70 /* The translation tables from a console scancode to a SDL keysym */
71 static SDLKey keymap[ATARIBIOS_MAXKEYS];
73 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
75 static void UpdateSpecialKeys(int special_keys_state);
77 void AtariGemdos_InitOSKeymap(_THIS)
81 memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
82 memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
84 /* Initialize keymap */
85 for ( i=0; i<sizeof(keymap); i++ )
86 keymap[i] = SDLK_UNKNOWN;
89 for ( i = 0; i<10; i++ )
90 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
93 keymap[SCANCODE_HELP] = SDLK_HELP;
94 keymap[SCANCODE_UNDO] = SDLK_UNDO;
95 keymap[SCANCODE_INSERT] = SDLK_INSERT;
96 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
97 keymap[SCANCODE_UP] = SDLK_UP;
98 keymap[SCANCODE_DOWN] = SDLK_DOWN;
99 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
100 keymap[SCANCODE_LEFT] = SDLK_LEFT;
103 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
104 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
105 keymap[SCANCODE_TAB] = SDLK_TAB;
106 keymap[SCANCODE_ENTER] = SDLK_RETURN;
107 keymap[SCANCODE_DELETE] = SDLK_DELETE;
108 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
109 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
110 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
111 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
112 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
114 SDL_AtariXbios_InstallVectors(ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS);
117 void AtariGemdos_PumpEvents(_THIS)
122 /* Update pressed keys */
123 memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
125 while (Cconis()!=DEV_BUSY) {
126 unsigned long key_pressed;
127 unsigned char scancode, asciicode;
129 key_pressed=Cnecin();
131 asciicode = key_pressed;
132 scancode = key_pressed >> 16;
134 gemdos_currentkeyboard[scancode]=0xFF;
135 gemdos_currentascii[scancode]=asciicode;
138 /* Read special keys */
139 UpdateSpecialKeys(Kbshift(-1));
141 /* Now generate events */
142 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
144 if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
145 SDL_PrivateKeyboard(SDL_PRESSED,
146 TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_TRUE));
148 /* Key unpressed ? */
149 if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
150 SDL_PrivateKeyboard(SDL_RELEASED,
151 TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_FALSE));
154 SDL_AtariXbios_PostMouseEvents(this);
156 /* Will be previous table */
157 memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS);
160 static void UpdateSpecialKeys(int special_keys_state)
162 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
164 if (special_keys_state & (1<<(numbit))) { \
165 gemdos_currentkeyboard[scancode]=0xFF; \
166 gemdos_currentascii[scancode]=0; \
170 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
171 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
172 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
173 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
174 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
177 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
180 /* Set the keysym information */
181 keysym->scancode = scancode;
184 keysym->sym = asciicode;
186 keysym->sym = keymap[scancode];
188 keysym->mod = KMOD_NONE;
190 if (pressed && (asciicode!=0)) {
191 keysym->unicode = SDL_AtariToUnicode(asciicode);
197 void AtariGemdos_ShutdownEvents(void)
199 SDL_AtariXbios_RestoreVectors();