Implement mouse input on RISC OS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c
index b571d75..3dbc3d0 100644
--- a/src/video/riscos/SDL_riscosevents.c
+++ b/src/video/riscos/SDL_riscosevents.c
@@ -30,6 +30,7 @@
#include "scancodes_riscos.h"
#include <kernel.h>
+#include <swis.h>
static SDL_Scancode
SDL_RISCOS_translate_keycode(int keycode)
@@ -104,6 +105,47 @@ RISCOS_PollKeyboard(_THIS)
}
}
+static const Uint8 mouse_button_map[] = {
+ SDL_BUTTON_RIGHT,
+ SDL_BUTTON_MIDDLE,
+ SDL_BUTTON_LEFT,
+ SDL_BUTTON_X1,
+ SDL_BUTTON_X2,
+ SDL_BUTTON_X2 + 1,
+ SDL_BUTTON_X2 + 2,
+ SDL_BUTTON_X2 + 3
+};
+
+void
+RISCOS_PollMouse(_THIS)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata;
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_Rect rect;
+ _kernel_swi_regs regs;
+ int i, x, y, buttons;
+
+ if (SDL_GetDisplayBounds(0, &rect) < 0) {
+ return;
+ }
+
+ _kernel_swi(OS_Mouse, ®s, ®s);
+ x = (regs.r[0] >> 1);
+ y = rect.h - (regs.r[1] >> 1);
+ buttons = regs.r[2];
+
+ if (mouse->x != x || mouse->y != y) {
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
+ }
+
+ if (driverdata->last_mouse_buttons != buttons) {
+ for (i = 0; i < SDL_arraysize(mouse_button_map); i++) {
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, (buttons & (1 << i)) ? SDL_PRESSED : SDL_RELEASED, mouse_button_map[i]);
+ }
+ driverdata->last_mouse_buttons = buttons;
+ }
+}
+
int
RISCOS_InitEvents(_THIS)
{
@@ -126,6 +168,7 @@ RISCOS_InitEvents(_THIS)
void
RISCOS_PumpEvents(_THIS)
{
+ RISCOS_PollMouse(_this);
RISCOS_PollKeyboard(_this);
}
diff --git a/src/video/riscos/SDL_riscosmodes.c b/src/video/riscos/SDL_riscosmodes.c
index be72390..7b35c5d 100644
--- a/src/video/riscos/SDL_riscosmodes.c
+++ b/src/video/riscos/SDL_riscosmodes.c
@@ -247,6 +247,9 @@ RISCOS_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
_kernel_oswrch(disable_cursor[i]);
}
+ /* Turn the mouse pointer on */
+ _kernel_osbyte(106, 1, 0);
+
return 0;
}
diff --git a/src/video/riscos/SDL_riscosvideo.h b/src/video/riscos/SDL_riscosvideo.h
index 7be93af..a7480d8 100644
--- a/src/video/riscos/SDL_riscosvideo.h
+++ b/src/video/riscos/SDL_riscosvideo.h
@@ -29,6 +29,7 @@
typedef struct SDL_VideoData
{
+ int last_mouse_buttons;
Uint8 key_pressed[RISCOS_MAX_KEYS_PRESSED];
} SDL_VideoData;