Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
599 lines (520 loc) · 18.1 KB

SDL_riscosevents.c

File metadata and controls

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