comparison src/video/ataricommon/SDL_biosevents.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 2405517b5eab
children d20f4510c718
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
46 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS]; 46 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
47 static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS]; 47 static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
48 static SDL_bool use_dev_mouse = SDL_FALSE; 48 static SDL_bool use_dev_mouse = SDL_FALSE;
49 49
50 /* Special keys state */ 50 /* Special keys state */
51 enum { 51 enum
52 K_RSHIFT=0, 52 {
53 K_LSHIFT, 53 K_RSHIFT = 0,
54 K_CTRL, 54 K_LSHIFT,
55 K_ALT, 55 K_CTRL,
56 K_CAPSLOCK, 56 K_ALT,
57 K_CLRHOME, 57 K_CAPSLOCK,
58 K_INSERT 58 K_CLRHOME,
59 K_INSERT
59 }; 60 };
60 61
61 /* The translation tables from a console scancode to a SDL keysym */ 62 /* The translation tables from a console scancode to a SDL keysym */
62 static SDLKey keymap[ATARIBIOS_MAXKEYS]; 63 static SDLKey keymap[ATARIBIOS_MAXKEYS];
63 64
64 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym, 65 static SDL_keysym *TranslateKey(int scancode, int asciicode,
65 SDL_bool pressed); 66 SDL_keysym * keysym, SDL_bool pressed);
66 static void UpdateSpecialKeys(int special_keys_state); 67 static void UpdateSpecialKeys(int special_keys_state);
67 68
68 void AtariBios_InitOSKeymap(_THIS) 69 void
69 { 70 AtariBios_InitOSKeymap(_THIS)
70 int i, vectors_mask; 71 {
71 unsigned long dummy; 72 int i, vectors_mask;
72 73 unsigned long dummy;
73 SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard)); 74
74 SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard)); 75 SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
75 76 SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
76 /* Initialize keymap */ 77
77 for ( i=0; i<sizeof(keymap); i++ ) 78 /* Initialize keymap */
78 keymap[i] = SDLK_UNKNOWN; 79 for (i = 0; i < sizeof(keymap); i++)
79 80 keymap[i] = SDLK_UNKNOWN;
80 /* Functions keys */ 81
81 for ( i = 0; i<10; i++ ) 82 /* Functions keys */
82 keymap[SCANCODE_F1 + i] = SDLK_F1+i; 83 for (i = 0; i < 10; i++)
83 84 keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
84 /* Cursor keypad */ 85
85 keymap[SCANCODE_HELP] = SDLK_HELP; 86 /* Cursor keypad */
86 keymap[SCANCODE_UNDO] = SDLK_UNDO; 87 keymap[SCANCODE_HELP] = SDLK_HELP;
87 keymap[SCANCODE_INSERT] = SDLK_INSERT; 88 keymap[SCANCODE_UNDO] = SDLK_UNDO;
88 keymap[SCANCODE_CLRHOME] = SDLK_HOME; 89 keymap[SCANCODE_INSERT] = SDLK_INSERT;
89 keymap[SCANCODE_UP] = SDLK_UP; 90 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
90 keymap[SCANCODE_DOWN] = SDLK_DOWN; 91 keymap[SCANCODE_UP] = SDLK_UP;
91 keymap[SCANCODE_RIGHT] = SDLK_RIGHT; 92 keymap[SCANCODE_DOWN] = SDLK_DOWN;
92 keymap[SCANCODE_LEFT] = SDLK_LEFT; 93 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
93 94 keymap[SCANCODE_LEFT] = SDLK_LEFT;
94 /* Special keys */ 95
95 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; 96 /* Special keys */
96 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; 97 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
97 keymap[SCANCODE_TAB] = SDLK_TAB; 98 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
98 keymap[SCANCODE_ENTER] = SDLK_RETURN; 99 keymap[SCANCODE_TAB] = SDLK_TAB;
99 keymap[SCANCODE_DELETE] = SDLK_DELETE; 100 keymap[SCANCODE_ENTER] = SDLK_RETURN;
100 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; 101 keymap[SCANCODE_DELETE] = SDLK_DELETE;
101 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; 102 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
102 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; 103 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
103 keymap[SCANCODE_LEFTALT] = SDLK_LALT; 104 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
104 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; 105 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
105 106 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
106 use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE; 107
107 108 use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
108 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */ 109
109 if (!use_dev_mouse) { 110 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */
110 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */ 111 if (!use_dev_mouse) {
111 } 112 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */
112 if (Getcookie(C_MiNT, &dummy)==C_FOUND) { 113 }
113 vectors_mask = 0; 114 if (Getcookie(C_MiNT, &dummy) == C_FOUND) {
114 } 115 vectors_mask = 0;
115 116 }
116 SDL_AtariXbios_InstallVectors(vectors_mask); 117
117 } 118 SDL_AtariXbios_InstallVectors(vectors_mask);
118 119 }
119 void AtariBios_PumpEvents(_THIS) 120
120 { 121 void
121 int i; 122 AtariBios_PumpEvents(_THIS)
122 SDL_keysym keysym; 123 {
123 124 int i;
124 /* Update pressed keys */ 125 SDL_keysym keysym;
125 SDL_memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS); 126
126 127 /* Update pressed keys */
127 while (Bconstat(_CON)) { 128 SDL_memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
128 unsigned long key_pressed; 129
129 unsigned char asciicode, scancode; 130 while (Bconstat(_CON)) {
130 131 unsigned long key_pressed;
131 key_pressed=Bconin(_CON); 132 unsigned char asciicode, scancode;
132 133
133 asciicode = key_pressed; 134 key_pressed = Bconin(_CON);
134 scancode = key_pressed >> 16; 135
135 136 asciicode = key_pressed;
136 bios_currentkeyboard[scancode]=0xFF; 137 scancode = key_pressed >> 16;
137 bios_currentascii[scancode]=asciicode; 138
138 } 139 bios_currentkeyboard[scancode] = 0xFF;
139 140 bios_currentascii[scancode] = asciicode;
140 /* Read special keys */ 141 }
141 UpdateSpecialKeys(Kbshift(-1)); 142
142 143 /* Read special keys */
143 /* Now generate events */ 144 UpdateSpecialKeys(Kbshift(-1));
144 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 145
145 /* Key pressed ? */ 146 /* Now generate events */
146 if (bios_currentkeyboard[i] && !bios_previouskeyboard[i]) 147 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
147 SDL_PrivateKeyboard(SDL_PRESSED, 148 /* Key pressed ? */
148 TranslateKey(i, bios_currentascii[i], &keysym, SDL_TRUE)); 149 if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
149 150 SDL_PrivateKeyboard(SDL_PRESSED,
150 /* Key unpressed ? */ 151 TranslateKey(i, bios_currentascii[i],
151 if (bios_previouskeyboard[i] && !bios_currentkeyboard[i]) 152 &keysym, SDL_TRUE));
152 SDL_PrivateKeyboard(SDL_RELEASED, 153
153 TranslateKey(i, bios_currentascii[i], &keysym, SDL_FALSE)); 154 /* Key unpressed ? */
154 } 155 if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
155 156 SDL_PrivateKeyboard(SDL_RELEASED,
156 if (use_dev_mouse) { 157 TranslateKey(i, bios_currentascii[i],
157 SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE); 158 &keysym, SDL_FALSE));
158 } else { 159 }
159 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE); 160
160 } 161 if (use_dev_mouse) {
161 162 SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
162 /* Will be previous table */ 163 } else {
163 SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS); 164 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
164 } 165 }
165 166
166 static void UpdateSpecialKeys(int special_keys_state) 167 /* Will be previous table */
168 SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard,
169 ATARIBIOS_MAXKEYS);
170 }
171
172 static void
173 UpdateSpecialKeys(int special_keys_state)
167 { 174 {
168 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \ 175 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
169 { \ 176 { \
170 if (special_keys_state & (1<<(numbit))) { \ 177 if (special_keys_state & (1<<(numbit))) { \
171 bios_currentkeyboard[scancode]=0xFF; \ 178 bios_currentkeyboard[scancode]=0xFF; \
172 bios_currentascii[scancode]=0; \ 179 bios_currentascii[scancode]=0; \
173 } \ 180 } \
174 } 181 }
175 182
176 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT); 183 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
177 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT); 184 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
178 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL); 185 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
179 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT); 186 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
180 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK); 187 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
181 } 188 }
182 189
183 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym, 190 static SDL_keysym *
184 SDL_bool pressed) 191 TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
185 { 192 SDL_bool pressed)
186 /* Set the keysym information */ 193 {
187 keysym->scancode = scancode; 194 /* Set the keysym information */
188 195 keysym->scancode = scancode;
189 if (asciicode) 196
190 keysym->sym = asciicode; 197 if (asciicode)
191 else 198 keysym->sym = asciicode;
192 keysym->sym = keymap[scancode]; 199 else
193 200 keysym->sym = keymap[scancode];
194 keysym->mod = KMOD_NONE; 201
195 keysym->unicode = 0; 202 keysym->mod = KMOD_NONE;
196 if (SDL_TranslateUNICODE && pressed) { 203 keysym->unicode = 0;
197 keysym->unicode = SDL_AtariToUnicodeTable[asciicode]; 204 if (SDL_TranslateUNICODE && pressed) {
198 } 205 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
199 206 }
200 return(keysym); 207
201 } 208 return (keysym);
202 209 }
203 void AtariBios_ShutdownEvents(void) 210
204 { 211 void
205 SDL_AtariXbios_RestoreVectors(); 212 AtariBios_ShutdownEvents(void)
206 if (use_dev_mouse) { 213 {
207 SDL_AtariDevMouse_Close(); 214 SDL_AtariXbios_RestoreVectors();
208 } 215 if (use_dev_mouse) {
209 } 216 SDL_AtariDevMouse_Close();
217 }
218 }
219
220 /* vi: set ts=4 sw=4 expandtab: */