comparison src/video/riscos/SDL_riscosevents.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents d910939febfa
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
68 /* Size of array for all keys */ 68 /* Size of array for all keys */
69 #define ROKEYBD_ARRAYSIZE 125 69 #define ROKEYBD_ARRAYSIZE 125
70 70
71 static char RO_pressed[ROKEYBD_ARRAYSIZE]; 71 static char RO_pressed[ROKEYBD_ARRAYSIZE];
72 72
73 static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed); 73 static SDL_keysym *TranslateKey (int intkey, SDL_keysym * keysym,
74 74 int pressed);
75 void RISCOS_PollMouse(_THIS); 75
76 void RISCOS_PollKeyboard(); 76 void RISCOS_PollMouse (_THIS);
77 77 void RISCOS_PollKeyboard ();
78 void RISCOS_PollMouseHelper(_THIS, int fullscreen); 78
79 void RISCOS_PollMouseHelper (_THIS, int fullscreen);
79 80
80 #if SDL_THREADS_DISABLED 81 #if SDL_THREADS_DISABLED
81 extern void DRenderer_FillBuffers(); 82 extern void DRenderer_FillBuffers ();
82 83
83 /* Timer running function */ 84 /* Timer running function */
84 extern void RISCOS_CheckTimer(); 85 extern void RISCOS_CheckTimer ();
85 86
86 #endif 87 #endif
87 88
88 void FULLSCREEN_PumpEvents(_THIS) 89 void
90 FULLSCREEN_PumpEvents (_THIS)
89 { 91 {
90 /* Current implementation requires keyboard and mouse polling */ 92 /* Current implementation requires keyboard and mouse polling */
91 RISCOS_PollKeyboard(); 93 RISCOS_PollKeyboard ();
92 RISCOS_PollMouse(this); 94 RISCOS_PollMouse (this);
93 #if SDL_THREADS_DISABLED 95 #if SDL_THREADS_DISABLED
94 // DRenderer_FillBuffers(); 96 // DRenderer_FillBuffers();
95 if (SDL_timer_running) RISCOS_CheckTimer(); 97 if (SDL_timer_running)
98 RISCOS_CheckTimer ();
96 #endif 99 #endif
97 } 100 }
98 101
99 102
100 void RISCOS_InitOSKeymap(_THIS) 103 void
101 { 104 RISCOS_InitOSKeymap (_THIS)
102 int i; 105 {
103 106 int i;
104 /* Map the VK keysyms */ 107
105 for ( i=0; i<SDL_arraysize(RO_keymap); ++i ) 108 /* Map the VK keysyms */
106 RO_keymap[i] = SDLK_UNKNOWN; 109 for (i = 0; i < SDL_arraysize (RO_keymap); ++i)
107 110 RO_keymap[i] = SDLK_UNKNOWN;
108 RO_keymap[3] = SDLK_LSHIFT; 111
109 RO_keymap[4] = SDLK_LCTRL; 112 RO_keymap[3] = SDLK_LSHIFT;
110 RO_keymap[5] = SDLK_LALT; 113 RO_keymap[4] = SDLK_LCTRL;
111 RO_keymap[6] = SDLK_RSHIFT; 114 RO_keymap[5] = SDLK_LALT;
112 RO_keymap[7] = SDLK_RCTRL; 115 RO_keymap[6] = SDLK_RSHIFT;
113 RO_keymap[8] = SDLK_RALT; 116 RO_keymap[7] = SDLK_RCTRL;
114 RO_keymap[16] = SDLK_q; 117 RO_keymap[8] = SDLK_RALT;
115 RO_keymap[17] = SDLK_3; 118 RO_keymap[16] = SDLK_q;
116 RO_keymap[18] = SDLK_4; 119 RO_keymap[17] = SDLK_3;
117 RO_keymap[19] = SDLK_5; 120 RO_keymap[18] = SDLK_4;
118 RO_keymap[20] = SDLK_F4; 121 RO_keymap[19] = SDLK_5;
119 RO_keymap[21] = SDLK_8; 122 RO_keymap[20] = SDLK_F4;
120 RO_keymap[22] = SDLK_F7; 123 RO_keymap[21] = SDLK_8;
121 RO_keymap[23] = SDLK_MINUS, 124 RO_keymap[22] = SDLK_F7;
122 RO_keymap[25] = SDLK_LEFT; 125 RO_keymap[23] = SDLK_MINUS, RO_keymap[25] = SDLK_LEFT;
123 RO_keymap[26] = SDLK_KP6; 126 RO_keymap[26] = SDLK_KP6;
124 RO_keymap[27] = SDLK_KP7; 127 RO_keymap[27] = SDLK_KP7;
125 RO_keymap[28] = SDLK_F11; 128 RO_keymap[28] = SDLK_F11;
126 RO_keymap[29] = SDLK_F12; 129 RO_keymap[29] = SDLK_F12;
127 RO_keymap[30] = SDLK_F10; 130 RO_keymap[30] = SDLK_F10;
128 RO_keymap[31] = SDLK_SCROLLOCK; 131 RO_keymap[31] = SDLK_SCROLLOCK;
129 RO_keymap[32] = SDLK_PRINT; 132 RO_keymap[32] = SDLK_PRINT;
130 RO_keymap[33] = SDLK_w; 133 RO_keymap[33] = SDLK_w;
131 RO_keymap[34] = SDLK_e; 134 RO_keymap[34] = SDLK_e;
132 RO_keymap[35] = SDLK_t; 135 RO_keymap[35] = SDLK_t;
133 RO_keymap[36] = SDLK_7; 136 RO_keymap[36] = SDLK_7;
134 RO_keymap[37] = SDLK_i; 137 RO_keymap[37] = SDLK_i;
135 RO_keymap[38] = SDLK_9; 138 RO_keymap[38] = SDLK_9;
136 RO_keymap[39] = SDLK_0; 139 RO_keymap[39] = SDLK_0;
137 RO_keymap[41] = SDLK_DOWN; 140 RO_keymap[41] = SDLK_DOWN;
138 RO_keymap[42] = SDLK_KP8; 141 RO_keymap[42] = SDLK_KP8;
139 RO_keymap[43] = SDLK_KP9; 142 RO_keymap[43] = SDLK_KP9;
140 RO_keymap[44] = SDLK_BREAK; 143 RO_keymap[44] = SDLK_BREAK;
141 RO_keymap[45] = SDLK_BACKQUOTE; 144 RO_keymap[45] = SDLK_BACKQUOTE;
142 /* RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */ 145 /* RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */
143 RO_keymap[47] = SDLK_BACKSPACE; 146 RO_keymap[47] = SDLK_BACKSPACE;
144 RO_keymap[48] = SDLK_1; 147 RO_keymap[48] = SDLK_1;
145 RO_keymap[49] = SDLK_2; 148 RO_keymap[49] = SDLK_2;
146 RO_keymap[50] = SDLK_d; 149 RO_keymap[50] = SDLK_d;
147 RO_keymap[51] = SDLK_r; 150 RO_keymap[51] = SDLK_r;
148 RO_keymap[52] = SDLK_6; 151 RO_keymap[52] = SDLK_6;
149 RO_keymap[53] = SDLK_u; 152 RO_keymap[53] = SDLK_u;
150 RO_keymap[54] = SDLK_o; 153 RO_keymap[54] = SDLK_o;
151 RO_keymap[55] = SDLK_p; 154 RO_keymap[55] = SDLK_p;
152 RO_keymap[56] = SDLK_LEFTBRACKET; 155 RO_keymap[56] = SDLK_LEFTBRACKET;
153 RO_keymap[57] = SDLK_UP; 156 RO_keymap[57] = SDLK_UP;
154 RO_keymap[58] = SDLK_KP_PLUS; 157 RO_keymap[58] = SDLK_KP_PLUS;
155 RO_keymap[59] = SDLK_KP_MINUS; 158 RO_keymap[59] = SDLK_KP_MINUS;
156 RO_keymap[60] = SDLK_KP_ENTER; 159 RO_keymap[60] = SDLK_KP_ENTER;
157 RO_keymap[61] = SDLK_INSERT; 160 RO_keymap[61] = SDLK_INSERT;
158 RO_keymap[62] = SDLK_HOME; 161 RO_keymap[62] = SDLK_HOME;
159 RO_keymap[63] = SDLK_PAGEUP; 162 RO_keymap[63] = SDLK_PAGEUP;
160 RO_keymap[64] = SDLK_CAPSLOCK; 163 RO_keymap[64] = SDLK_CAPSLOCK;
161 RO_keymap[65] = SDLK_a; 164 RO_keymap[65] = SDLK_a;
162 RO_keymap[66] = SDLK_x; 165 RO_keymap[66] = SDLK_x;
163 RO_keymap[67] = SDLK_f; 166 RO_keymap[67] = SDLK_f;
164 RO_keymap[68] = SDLK_y; 167 RO_keymap[68] = SDLK_y;
165 RO_keymap[69] = SDLK_j; 168 RO_keymap[69] = SDLK_j;
166 RO_keymap[70] = SDLK_k; 169 RO_keymap[70] = SDLK_k;
167 RO_keymap[72] = SDLK_SEMICOLON; 170 RO_keymap[72] = SDLK_SEMICOLON;
168 RO_keymap[73] = SDLK_RETURN; 171 RO_keymap[73] = SDLK_RETURN;
169 RO_keymap[74] = SDLK_KP_DIVIDE; 172 RO_keymap[74] = SDLK_KP_DIVIDE;
170 RO_keymap[76] = SDLK_KP_PERIOD; 173 RO_keymap[76] = SDLK_KP_PERIOD;
171 RO_keymap[77] = SDLK_NUMLOCK; 174 RO_keymap[77] = SDLK_NUMLOCK;
172 RO_keymap[78] = SDLK_PAGEDOWN; 175 RO_keymap[78] = SDLK_PAGEDOWN;
173 RO_keymap[79] = SDLK_QUOTE; 176 RO_keymap[79] = SDLK_QUOTE;
174 RO_keymap[81] = SDLK_s; 177 RO_keymap[81] = SDLK_s;
175 RO_keymap[82] = SDLK_c; 178 RO_keymap[82] = SDLK_c;
176 RO_keymap[83] = SDLK_g; 179 RO_keymap[83] = SDLK_g;
177 RO_keymap[84] = SDLK_h; 180 RO_keymap[84] = SDLK_h;
178 RO_keymap[85] = SDLK_n; 181 RO_keymap[85] = SDLK_n;
179 RO_keymap[86] = SDLK_l; 182 RO_keymap[86] = SDLK_l;
180 RO_keymap[87] = SDLK_SEMICOLON; 183 RO_keymap[87] = SDLK_SEMICOLON;
181 RO_keymap[88] = SDLK_RIGHTBRACKET; 184 RO_keymap[88] = SDLK_RIGHTBRACKET;
182 RO_keymap[89] = SDLK_DELETE; 185 RO_keymap[89] = SDLK_DELETE;
183 RO_keymap[90] = SDLK_KP_MINUS; 186 RO_keymap[90] = SDLK_KP_MINUS;
184 RO_keymap[91] = SDLK_KP_MULTIPLY; 187 RO_keymap[91] = SDLK_KP_MULTIPLY;
185 RO_keymap[93] = SDLK_EQUALS; 188 RO_keymap[93] = SDLK_EQUALS;
186 RO_keymap[94] = SDLK_BACKSLASH; 189 RO_keymap[94] = SDLK_BACKSLASH;
187 RO_keymap[96] = SDLK_TAB; 190 RO_keymap[96] = SDLK_TAB;
188 RO_keymap[97] = SDLK_z; 191 RO_keymap[97] = SDLK_z;
189 RO_keymap[98] = SDLK_SPACE; 192 RO_keymap[98] = SDLK_SPACE;
190 RO_keymap[99] = SDLK_v; 193 RO_keymap[99] = SDLK_v;
191 RO_keymap[100] = SDLK_b; 194 RO_keymap[100] = SDLK_b;
192 RO_keymap[101] = SDLK_m; 195 RO_keymap[101] = SDLK_m;
193 RO_keymap[102] = SDLK_COMMA; 196 RO_keymap[102] = SDLK_COMMA;
194 RO_keymap[103] = SDLK_PERIOD; 197 RO_keymap[103] = SDLK_PERIOD;
195 RO_keymap[104] = SDLK_SLASH; 198 RO_keymap[104] = SDLK_SLASH;
196 RO_keymap[105] = SDLK_END; 199 RO_keymap[105] = SDLK_END;
197 RO_keymap[106] = SDLK_KP0; 200 RO_keymap[106] = SDLK_KP0;
198 RO_keymap[107] = SDLK_KP1; 201 RO_keymap[107] = SDLK_KP1;
199 RO_keymap[108] = SDLK_KP3; 202 RO_keymap[108] = SDLK_KP3;
200 RO_keymap[112] = SDLK_ESCAPE; 203 RO_keymap[112] = SDLK_ESCAPE;
201 RO_keymap[113] = SDLK_F1; 204 RO_keymap[113] = SDLK_F1;
202 RO_keymap[114] = SDLK_F2; 205 RO_keymap[114] = SDLK_F2;
203 RO_keymap[115] = SDLK_F3; 206 RO_keymap[115] = SDLK_F3;
204 RO_keymap[116] = SDLK_F5; 207 RO_keymap[116] = SDLK_F5;
205 RO_keymap[117] = SDLK_F6; 208 RO_keymap[117] = SDLK_F6;
206 RO_keymap[118] = SDLK_F8; 209 RO_keymap[118] = SDLK_F8;
207 RO_keymap[119] = SDLK_F9; 210 RO_keymap[119] = SDLK_F9;
208 RO_keymap[120] = SDLK_HASH; 211 RO_keymap[120] = SDLK_HASH;
209 RO_keymap[121] = SDLK_RIGHT; 212 RO_keymap[121] = SDLK_RIGHT;
210 RO_keymap[122] = SDLK_KP4; 213 RO_keymap[122] = SDLK_KP4;
211 RO_keymap[123] = SDLK_KP5; 214 RO_keymap[123] = SDLK_KP5;
212 RO_keymap[124] = SDLK_KP2; 215 RO_keymap[124] = SDLK_KP2;
213 216
214 SDL_memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE); 217 SDL_memset (RO_pressed, 0, ROKEYBD_ARRAYSIZE);
215 } 218 }
216 219
217 220
218 /* Variable for mouse relative processing */ 221 /* Variable for mouse relative processing */
219 int mouse_relative = 0; 222 int mouse_relative = 0;
220 223
221 /* Check to see if we need to enter or leave mouse relative mode */ 224 /* Check to see if we need to enter or leave mouse relative mode */
222 225
223 void RISCOS_CheckMouseMode(_THIS) 226 void
227 RISCOS_CheckMouseMode (_THIS)
224 { 228 {
225 /* If the mouse is hidden and input is grabbed, we use relative mode */ 229 /* If the mouse is hidden and input is grabbed, we use relative mode */
226 if ( !(SDL_cursorstate & CURSOR_VISIBLE) && 230 if (!(SDL_cursorstate & CURSOR_VISIBLE) &&
227 (this->input_grab != SDL_GRAB_OFF) ) { 231 (this->input_grab != SDL_GRAB_OFF)) {
228 mouse_relative = 1; 232 mouse_relative = 1;
229 } else { 233 } else {
230 mouse_relative = 0; 234 mouse_relative = 0;
231 } 235 }
232 } 236 }
233 237
234 238
235 void RISCOS_PollMouse(_THIS) 239 void
236 { 240 RISCOS_PollMouse (_THIS)
237 RISCOS_PollMouseHelper(this, 1); 241 {
242 RISCOS_PollMouseHelper (this, 1);
238 } 243 }
239 244
240 extern int mouseInWindow; 245 extern int mouseInWindow;
241 246
242 void WIMP_PollMouse(_THIS) 247 void
243 { 248 WIMP_PollMouse (_THIS)
244 /* Only poll when mouse is over the window */ 249 {
245 if (!mouseInWindow) return; 250 /* Only poll when mouse is over the window */
246 251 if (!mouseInWindow)
247 RISCOS_PollMouseHelper(this, 0); 252 return;
253
254 RISCOS_PollMouseHelper (this, 0);
248 } 255 }
249 256
250 /* Static variables so only changes are reported */ 257 /* Static variables so only changes are reported */
251 static Sint16 last_x = -1, last_y = -1; 258 static Sint16 last_x = -1, last_y = -1;
252 static int last_buttons = 0; 259 static int last_buttons = 0;
253 260
254 /* Share routine between WIMP and FULLSCREEN for polling mouse and 261 /* Share routine between WIMP and FULLSCREEN for polling mouse and
255 passing on events */ 262 passing on events */
256 void RISCOS_PollMouseHelper(_THIS, int fullscreen) 263 void
264 RISCOS_PollMouseHelper (_THIS, int fullscreen)
257 { 265 {
258 _kernel_swi_regs regs; 266 _kernel_swi_regs regs;
259 static int starting = 1; 267 static int starting = 1;
260 268
261 if (_kernel_swi(OS_Mouse, &regs, &regs) == NULL) 269 if (_kernel_swi (OS_Mouse, &regs, &regs) == NULL) {
262 { 270 Sint16 new_x = regs.r[0]; /* Initialy get as OS units */
263 Sint16 new_x = regs.r[0]; /* Initialy get as OS units */ 271 Sint16 new_y = regs.r[1];
264 Sint16 new_y = regs.r[1]; 272
265 273 /* Discard mouse events until they let go of the mouse after starting */
266 /* Discard mouse events until they let go of the mouse after starting */ 274 if (starting && regs.r[2] != 0)
267 if (starting && regs.r[2] != 0) 275 return;
268 return; 276 else
269 else 277 starting = 0;
270 starting = 0; 278
271 279 if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2]) {
272 if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2]) 280 /* Something changed so generate appropriate events */
273 { 281 int topLeftX, topLeftY; /* Top left OS units */
274 /* Something changed so generate appropriate events */ 282 int x, y; /* Mouse position in SDL pixels */
275 int topLeftX, topLeftY; /* Top left OS units */ 283
276 int x, y; /* Mouse position in SDL pixels */ 284 if (fullscreen) {
277 285 topLeftX = 0;
278 if (fullscreen) 286 topLeftY = (this->hidden->height << this->hidden->yeig) - 1;
279 { 287 } else {
280 topLeftX = 0; 288 int window_state[9];
281 topLeftY = (this->hidden->height << this->hidden->yeig) - 1; 289
282 } else 290 /* Get current window state */
283 { 291 window_state[0] = this->hidden->window_handle;
284 int window_state[9]; 292 regs.r[1] = (unsigned int) window_state;
285 293 _kernel_swi (Wimp_GetWindowState, &regs, &regs);
286 /* Get current window state */ 294
287 window_state[0] = this->hidden->window_handle; 295 topLeftX = window_state[1];
288 regs.r[1] = (unsigned int)window_state; 296 topLeftY = window_state[4];
289 _kernel_swi(Wimp_GetWindowState, &regs, &regs); 297 }
290 298
291 topLeftX = window_state[1]; 299 /* Convert co-ordinates to workspace */
292 topLeftY = window_state[4]; 300 x = new_x - topLeftX;
293 } 301 y = topLeftY - new_y; /* Y goes from top of window/screen */
294 302
295 /* Convert co-ordinates to workspace */ 303 /* Convert OS units to pixels */
296 x = new_x - topLeftX; 304 x >>= this->hidden->xeig;
297 y = topLeftY - new_y; /* Y goes from top of window/screen */ 305 y >>= this->hidden->yeig;
298 306
299 /* Convert OS units to pixels */ 307 if (last_x != new_x || last_y != new_y) {
300 x >>= this->hidden->xeig; 308 if (mouse_relative) {
301 y >>= this->hidden->yeig; 309 int centre_x = SDL_VideoSurface->w / 2;
302 310 int centre_y = SDL_VideoSurface->h / 2;
303 if (last_x != new_x || last_y != new_y) 311
304 { 312 if (centre_x != x || centre_y != y) {
305 if (mouse_relative) 313 if (SDL_VideoSurface)
306 { 314 SDL_PrivateMouseMotion (0, 1,
307 int centre_x = SDL_VideoSurface->w/2; 315 x - centre_x,
308 int centre_y = SDL_VideoSurface->h/2; 316 y - centre_y);
309 317 last_x = topLeftX + (centre_x << this->hidden->xeig);
310 if (centre_x != x || centre_y != y) 318 last_y = topLeftY - (centre_y << this->hidden->yeig);
311 { 319
312 if (SDL_VideoSurface) SDL_PrivateMouseMotion(0,1,x - centre_x, y - centre_y); 320 /* Re-centre the mouse pointer, so we still get relative
313 last_x = topLeftX + (centre_x << this->hidden->xeig); 321 movement when the mouse is at the edge of the window
314 last_y = topLeftY - (centre_y << this->hidden->yeig); 322 or screen.
315 323 */
316 /* Re-centre the mouse pointer, so we still get relative 324 {
317 movement when the mouse is at the edge of the window 325 unsigned char block[5];
318 or screen. 326
319 */ 327 block[0] = 3; /* OSWORD move pointer sub-reason code */
320 { 328 block[1] = last_x & 0xFF;
321 unsigned char block[5]; 329 block[2] = (last_x >> 8) & 0xFF;
322 330 block[3] = last_y & 0xFF;
323 block[0] = 3; /* OSWORD move pointer sub-reason code */ 331 block[4] = (last_y >> 8) & 0xFF;
324 block[1] = last_x & 0xFF; 332
325 block[2] = (last_x >> 8) & 0xFF; 333 regs.r[0] = 21; /* OSWORD pointer stuff code */
326 block[3] = last_y & 0xFF; 334 regs.r[1] = (int) block;
327 block[4] = (last_y >> 8) & 0xFF; 335 _kernel_swi (OS_Word, &regs, &regs);
328 336 }
329 regs.r[0] = 21; /* OSWORD pointer stuff code */ 337 }
330 regs.r[1] = (int)block; 338 } else {
331 _kernel_swi(OS_Word, &regs, &regs); 339 last_x = new_x;
332 } 340 last_y = new_y;
341 SDL_PrivateMouseMotion (0, 0, x, y);
333 } 342 }
334 } else 343 }
335 { 344
336 last_x = new_x; 345 if (last_buttons != regs.r[2]) {
337 last_y = new_y; 346 int changed = last_buttons ^ regs.r[2];
338 SDL_PrivateMouseMotion(0,0,x,y); 347 last_buttons = regs.r[2];
339 } 348 if (changed & 4)
340 } 349 SDL_PrivateMouseButton ((last_buttons & 4) ?
341 350 SDL_PRESSED : SDL_RELEASED,
342 if (last_buttons != regs.r[2]) 351 SDL_BUTTON_LEFT, 0, 0);
343 { 352 if (changed & 2)
344 int changed = last_buttons ^ regs.r[2]; 353 SDL_PrivateMouseButton ((last_buttons & 2) ?
345 last_buttons = regs.r[2]; 354 SDL_PRESSED : SDL_RELEASED,
346 if (changed & 4) SDL_PrivateMouseButton((last_buttons & 4) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); 355 SDL_BUTTON_MIDDLE, 0, 0);
347 if (changed & 2) SDL_PrivateMouseButton((last_buttons & 2) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); 356 if (changed & 1)
348 if (changed & 1) SDL_PrivateMouseButton((last_buttons & 1) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); 357 SDL_PrivateMouseButton ((last_buttons & 1) ?
349 } 358 SDL_PRESSED : SDL_RELEASED,
350 } 359 SDL_BUTTON_RIGHT, 0, 0);
360 }
361 }
351 } 362 }
352 } 363 }
353 364
354 void RISCOS_PollKeyboard() 365 void
355 { 366 RISCOS_PollKeyboard ()
356 int which_key = ROKEY_LEFT_SHIFT; 367 {
357 int j; 368 int which_key = ROKEY_LEFT_SHIFT;
358 int min_key, max_key; 369 int j;
359 SDL_keysym key; 370 int min_key, max_key;
360 371 SDL_keysym key;
361 /* Scan the keyboard to see what is pressed */ 372
362 while (which_key <= ROKEY_LAST_KEY) 373 /* Scan the keyboard to see what is pressed */
363 { 374 while (which_key <= ROKEY_LAST_KEY) {
364 which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF); 375 which_key = (_kernel_osbyte (121, which_key, 0) & 0xFF);
365 if (which_key != ROKEY_NONE) 376 if (which_key != ROKEY_NONE) {
366 { 377 switch (which_key) {
367 switch(which_key) 378 /* Skip over mouse keys */
368 { 379 case ROKEY_LEFT_MOUSE:
369 /* Skip over mouse keys */ 380 case ROKEY_CENTRE_MOUSE:
370 case ROKEY_LEFT_MOUSE: 381 case ROKEY_RIGHT_MOUSE:
371 case ROKEY_CENTRE_MOUSE: 382 which_key = ROKEY_RIGHT_MOUSE;
372 case ROKEY_RIGHT_MOUSE: 383 break;
373 which_key = ROKEY_RIGHT_MOUSE; 384
374 break; 385 /* Ignore keys that cause 2 internal number to be generated */
375 386 case 71:
376 /* Ignore keys that cause 2 internal number to be generated */ 387 case 24:
377 case 71: case 24: case 87: case 40: 388 case 87:
378 break; 389 case 40:
379 390 break;
380 /* Ignore break as it can be latched on */ 391
392 /* Ignore break as it can be latched on */
381 case 44: 393 case 44:
382 break; 394 break;
383 395
384 default: 396 default:
385 RO_pressed[which_key] += 2; 397 RO_pressed[which_key] += 2;
386 break; 398 break;
387 } 399 }
388 which_key++; 400 which_key++;
389 } 401 }
390 } 402 }
391 403
392 /* Generate key released messages */ 404 /* Generate key released messages */
393 min_key = ROKEY_LAST_KEY+1; 405 min_key = ROKEY_LAST_KEY + 1;
394 max_key = ROKEY_LEFT_SHIFT; 406 max_key = ROKEY_LEFT_SHIFT;
395 407
396 for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++) 408 for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++) {
397 { 409 if (RO_pressed[j]) {
398 if (RO_pressed[j]) 410 if (RO_pressed[j] == 1) {
399 { 411 RO_pressed[j] = 0;
400 if (RO_pressed[j] == 1) 412 SDL_PrivateKeyboard (SDL_RELEASED, TranslateKey (j, &key, 0));
401 { 413 } else {
402 RO_pressed[j] = 0; 414 if (j < min_key)
403 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j,&key,0)); 415 min_key = j;
404 } else 416 if (j > max_key)
405 { 417 max_key = j;
406 if (j < min_key) min_key = j; 418 }
407 if (j > max_key) max_key = j; 419 }
408 } 420 }
409 } 421
410 } 422 /* Generate key pressed messages */
411 423 for (j = min_key; j <= max_key; j++) {
412 /* Generate key pressed messages */ 424 if (RO_pressed[j]) {
413 for (j = min_key; j <= max_key; j++) 425 if (RO_pressed[j] == 2) {
414 { 426 SDL_PrivateKeyboard (SDL_PRESSED, TranslateKey (j, &key, 1));
415 if (RO_pressed[j]) 427 }
416 { 428 RO_pressed[j] = 1;
417 if (RO_pressed[j] == 2) 429 }
418 { 430 }
419 SDL_PrivateKeyboard(SDL_PRESSED,TranslateKey(j,&key,1)); 431 }
420 } 432
421 RO_pressed[j] = 1; 433 static SDL_keysym *
422 } 434 TranslateKey (int intkey, SDL_keysym * keysym, int pressed)
423 } 435 {
424 } 436 /* Set the keysym information */
425 437 keysym->scancode = (unsigned char) intkey;
426 static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed) 438 keysym->sym = RO_keymap[intkey];
427 { 439 keysym->mod = KMOD_NONE;
428 /* Set the keysym information */ 440 keysym->unicode = 0;
429 keysym->scancode = (unsigned char) intkey; 441 if (pressed && SDL_TranslateUNICODE) {
430 keysym->sym = RO_keymap[intkey]; 442 int state;
431 keysym->mod = KMOD_NONE; 443 int ch;
432 keysym->unicode = 0; 444
433 if ( pressed && SDL_TranslateUNICODE ) 445 state = (_kernel_osbyte (202, 0, 255) & 0xFF);
434 { 446
435 int state; 447 /*TODO: Take into account other keyboard layouts */
436 int ch; 448
437 449 ch = keysym->sym; /* This should handle most unshifted keys */
438 state = (_kernel_osbyte(202, 0, 255) & 0xFF); 450
439 451 if (intkey < 9 || ch == SDLK_UNKNOWN) {
440 /*TODO: Take into account other keyboard layouts */ 452 ch = 0;
441 453
442 ch = keysym->sym; /* This should handle most unshifted keys */ 454 } else if (state & 64) { /* Control on */
443 455 ch = ch & 31;
444 if (intkey < 9 || ch == SDLK_UNKNOWN) 456
445 { 457 } else {
446 ch = 0; 458 int topOfKey = 0;
447 459 if (state & 8) { /* Shift on */
448 } else if (state & 64) /* Control on */ 460 topOfKey = 1;
449 { 461 }
450 ch = ch & 31; 462
451 463 if ((state & 16) == 0) { /* Caps lock is on */
452 } else 464 if (ch >= SDLK_a && ch <= SDLK_z) {
453 { 465 if ((state & 128) == 0) { /* Shift Enable off */
454 int topOfKey = 0; 466 /* All letter become upper case */
455 if (state & 8) /* Shift on */ 467 topOfKey = 1;
456 { 468 } else {
457 topOfKey = 1; 469 /* Shift+Letters gives lower case */
458 } 470 topOfKey = 1 - topOfKey;
459 471 }
460 if ((state & 16) == 0) /* Caps lock is on */ 472 }
461 { 473 }
462 if (ch >= SDLK_a && ch <= SDLK_z) 474
463 { 475 if (topOfKey) {
464 if ((state & 128) == 0) /* Shift Enable off */ 476 /* Key produced with shift held down */
465 { 477
466 /* All letter become upper case */ 478 /* Letters just give upper case version */
467 topOfKey = 1; 479 if (ch >= SDLK_a && ch <= SDLK_z)
468 } else 480 ch = toupper (ch);
469 { 481 else {
470 /* Shift+Letters gives lower case */ 482 switch (ch) {
471 topOfKey = 1 - topOfKey; 483 case SDLK_HASH:
472 } 484 ch = '~';
473 } 485 break;
474 } 486 case SDLK_QUOTE:
475 487 ch = '@';
476 if (topOfKey) 488 break;
477 { 489 case SDLK_COMMA:
478 /* Key produced with shift held down */ 490 ch = '<';
479 491 break;
480 /* Letters just give upper case version */ 492 case SDLK_MINUS:
481 if (ch >= SDLK_a && ch <= SDLK_z) ch = toupper(ch); 493 ch = '_';
482 else 494 break;
483 { 495 case SDLK_PERIOD:
484 switch(ch) 496 ch = '>';
485 { 497 break;
486 case SDLK_HASH: ch = '~'; break; 498 case SDLK_SLASH:
487 case SDLK_QUOTE: ch = '@'; break; 499 ch = '?';
488 case SDLK_COMMA: ch = '<'; break; 500 break;
489 case SDLK_MINUS: ch = '_'; break; 501
490 case SDLK_PERIOD: ch = '>'; break; 502 case SDLK_0:
491 case SDLK_SLASH: ch = '?'; break; 503 ch = ')';
492 504 break;
493 case SDLK_0: ch = ')'; break; 505 case SDLK_1:
494 case SDLK_1: ch = '!'; break; 506 ch = '!';
495 case SDLK_2: ch = '"'; break; 507 break;
496 case SDLK_3: ch = '£'; break; 508 case SDLK_2:
497 case SDLK_4: ch = '$'; break; 509 ch = '"';
498 case SDLK_5: ch = '%'; break; 510 break;
499 case SDLK_6: ch = '^'; break; 511 case SDLK_3:
500 case SDLK_7: ch = '&'; break; 512 ch = '£';
501 case SDLK_8: ch = '*'; break; 513 break;
502 case SDLK_9: ch = '('; break; 514 case SDLK_4:
503 515 ch = '$';
504 case SDLK_SEMICOLON: ch = ':'; break; 516 break;
505 case SDLK_EQUALS: ch = '+'; break; 517 case SDLK_5:
506 case SDLK_LEFTBRACKET: ch = '{'; break; 518 ch = '%';
507 case SDLK_BACKSLASH: ch = '|'; break; 519 break;
508 case SDLK_RIGHTBRACKET: ch = '}'; break; 520 case SDLK_6:
509 case SDLK_BACKQUOTE: ch = '¬'; break; 521 ch = '^';
510 522 break;
511 default: 523 case SDLK_7:
512 ch = 0; /* Map to zero character if we don't understand it */ 524 ch = '&';
513 break; 525 break;
514 } 526 case SDLK_8:
515 } 527 ch = '*';
516 528 break;
517 } else if (ch > 126) 529 case SDLK_9:
518 { 530 ch = '(';
519 /* SDL key code < 126 map directly onto their Unicode equivalents */ 531 break;
520 /* Keypad 0 to 9 maps to numeric equivalent */ 532
521 if (ch >= SDLK_KP0 && ch <= SDLK_KP9) ch = ch - SDLK_KP0 + '0'; 533 case SDLK_SEMICOLON:
522 else 534 ch = ':';
523 { 535 break;
524 /* Following switch maps other keys that produce an Ascii value */ 536 case SDLK_EQUALS:
525 switch(ch) 537 ch = '+';
526 { 538 break;
527 case SDLK_KP_PERIOD: ch = '.'; break; 539 case SDLK_LEFTBRACKET:
528 case SDLK_KP_DIVIDE: ch = '/'; break; 540 ch = '{';
529 case SDLK_KP_MULTIPLY: ch = '*'; break; 541 break;
530 case SDLK_KP_MINUS: ch = '-'; break; 542 case SDLK_BACKSLASH:
531 case SDLK_KP_PLUS: ch = '+'; break; 543 ch = '|';
532 case SDLK_KP_EQUALS: ch = '='; break; 544 break;
533 545 case SDLK_RIGHTBRACKET:
534 default: 546 ch = '}';
535 /* If we don't know what it is set the Unicode to 0 */ 547 break;
536 ch = 0; 548 case SDLK_BACKQUOTE:
537 break; 549 ch = '¬';
538 } 550 break;
539 } 551
540 } 552 default:
541 } 553 ch = 0; /* Map to zero character if we don't understand it */
542 554 break;
543 keysym->unicode = ch; 555 }
544 } 556 }
545 return(keysym); 557
558 } else if (ch > 126) {
559 /* SDL key code < 126 map directly onto their Unicode equivalents */
560 /* Keypad 0 to 9 maps to numeric equivalent */
561 if (ch >= SDLK_KP0 && ch <= SDLK_KP9)
562 ch = ch - SDLK_KP0 + '0';
563 else {
564 /* Following switch maps other keys that produce an Ascii value */
565 switch (ch) {
566 case SDLK_KP_PERIOD:
567 ch = '.';
568 break;
569 case SDLK_KP_DIVIDE:
570 ch = '/';
571 break;
572 case SDLK_KP_MULTIPLY:
573 ch = '*';
574 break;
575 case SDLK_KP_MINUS:
576 ch = '-';
577 break;
578 case SDLK_KP_PLUS:
579 ch = '+';
580 break;
581 case SDLK_KP_EQUALS:
582 ch = '=';
583 break;
584
585 default:
586 /* If we don't know what it is set the Unicode to 0 */
587 ch = 0;
588 break;
589 }
590 }
591 }
592 }
593
594 keysym->unicode = ch;
595 }
596 return (keysym);
546 } 597 }
547 598
548 /* end of SDL_riscosevents.c ... */ 599 /* end of SDL_riscosevents.c ... */
549 600 /* vi: set ts=4 sw=4 expandtab: */