comparison src/video/ataricommon/SDL_gemdosevents.c @ 281:c5010ab8ba35

Added initial support for Atari (thanks Patrice!)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 17 Feb 2002 19:54:28 +0000
parents
children d8b7eae78652
comparison
equal deleted inserted replaced
280:0ddcea45d829 281:c5010ab8ba35
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
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.
9
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.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
27
28 /*
29 * Atari keyboard events manager, using Gemdos
30 *
31 * Patrice Mandin
32 */
33
34 #include <string.h>
35
36 /* Mint includes */
37 #include <mint/osbind.h>
38
39 #include "SDL.h"
40 #include "SDL_sysevents.h"
41 #include "SDL_events_c.h"
42
43 #include "SDL_atarikeys.h"
44 #include "SDL_xbiosmouseevents_c.h"
45
46 /* To save state of keyboard */
47 #define ATARIBIOS_MAXKEYS 128
48
49 static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
50 static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
51 static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
52
53 /* Special keys state */
54 enum {
55 K_RSHIFT=0,
56 K_LSHIFT,
57 K_CTRL,
58 K_ALT,
59 K_CAPSLOCK,
60 K_CLRHOME,
61 K_INSERT
62 };
63
64 enum {
65 DEV_BUSY=0,
66 DEV_READY
67 };
68
69 /* The translation tables from a console scancode to a SDL keysym */
70 static SDLKey keymap[ATARIBIOS_MAXKEYS];
71
72 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
73 static void UpdateSpecialKeys(int special_keys_state);
74
75 void AtariGemdos_InitOSKeymap(_THIS)
76 {
77 int i;
78
79 memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
80 memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
81
82 /* Initialize keymap */
83 for ( i=0; i<sizeof(keymap); i++ )
84 keymap[i] = SDLK_UNKNOWN;
85
86 /* Functions keys */
87 for ( i = 0; i<10; i++ )
88 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
89
90 /* Cursor keypad */
91 keymap[SCANCODE_HELP] = SDLK_HELP;
92 keymap[SCANCODE_UNDO] = SDLK_UNDO;
93 keymap[SCANCODE_INSERT] = SDLK_INSERT;
94 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
95 keymap[SCANCODE_UP] = SDLK_UP;
96 keymap[SCANCODE_DOWN] = SDLK_DOWN;
97 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
98 keymap[SCANCODE_LEFT] = SDLK_LEFT;
99
100 /* Special keys */
101 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
102 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
103 keymap[SCANCODE_TAB] = SDLK_TAB;
104 keymap[SCANCODE_ENTER] = SDLK_RETURN;
105 keymap[SCANCODE_DELETE] = SDLK_DELETE;
106 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
107 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
108 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
109 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
110 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
111
112 AtariXbios_InstallMouseVector();
113 }
114
115 void AtariGemdos_PumpEvents(_THIS)
116 {
117 int i;
118 SDL_keysym keysym;
119
120 /* Update pressed keys */
121 memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
122
123 while (Cconis()!=DEV_BUSY) {
124 unsigned long key_pressed;
125 unsigned char scancode, asciicode;
126
127 key_pressed=Cnecin();
128
129 asciicode = key_pressed;
130 scancode = key_pressed >> 16;
131
132 gemdos_currentkeyboard[scancode]=0xFF;
133 gemdos_currentascii[scancode]=asciicode;
134 }
135
136 /* Read special keys */
137 UpdateSpecialKeys(Kbshift(-1));
138
139 /* Now generate events */
140 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
141 /* Key pressed ? */
142 if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
143 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gemdos_currentascii[i], &keysym));
144
145 /* Key unpressed ? */
146 if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
147 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, 0, &keysym));
148 }
149
150 AtariXbios_PostMouseEvents(this);
151
152 /* Will be previous table */
153 memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS);
154 }
155
156 static void UpdateSpecialKeys(int special_keys_state)
157 {
158 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
159 { \
160 if (special_keys_state & (1<<(numbit))) { \
161 gemdos_currentkeyboard[scancode]=0xFF; \
162 gemdos_currentascii[scancode]=0; \
163 } \
164 }
165
166 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
167 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
168 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
169 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
170 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
171 }
172
173 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym)
174 {
175 /* Set the keysym information */
176 keysym->scancode = scancode;
177
178 if (asciicode)
179 keysym->sym = asciicode;
180 else
181 keysym->sym = keymap[scancode];
182
183 keysym->mod = KMOD_NONE;
184 keysym->unicode = 0;
185
186 return(keysym);
187 }
188
189 void AtariGemdos_ShutdownEvents(void)
190 {
191 AtariXbios_RestoreMouseVector();
192 }