Hash :
98353533
Author :
Date :
2022-02-23T18:54:31
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 95 96 97 98 99 100 101 102 103 104 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 144 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
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_RISCOS
#include "../../events/SDL_events_c.h"
#include "SDL_log.h"
#include "SDL_riscosvideo.h"
#include "SDL_riscosevents_c.h"
#include "scancodes_riscos.h"
#include <kernel.h>
#include <swis.h>
static SDL_Scancode
SDL_RISCOS_translate_keycode(int keycode)
{
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
if (keycode < SDL_arraysize(riscos_scancode_table)) {
scancode = riscos_scancode_table[keycode];
if (scancode == SDL_SCANCODE_UNKNOWN) {
SDL_Log("The key you just pressed is not recognized by SDL: %d", keycode);
}
}
return scancode;
}
void
RISCOS_PollKeyboard(_THIS)
{
SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata;
Uint8 key = 2;
int i;
/* Check for key releases */
for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) {
if (driverdata->key_pressed[i] != 255) {
if ((_kernel_osbyte(129, driverdata->key_pressed[i] ^ 0xff, 0xff) & 0xff) != 255) {
SDL_SendKeyboardKey(SDL_RELEASED, SDL_RISCOS_translate_keycode(driverdata->key_pressed[i]));
driverdata->key_pressed[i] = 255;
}
}
}
/* Check for key presses */
while (key < 0xff) {
key = _kernel_osbyte(121, key + 1, 0) & 0xff;
switch (key) {
case 255:
/* Ignore mouse keys */
case 9:
case 10:
case 11:
/* Ignore keys with multiple INKEY codes */
case 24:
case 40:
case 71:
case 87:
break;
default:
SDL_SendKeyboardKey(SDL_PRESSED, SDL_RISCOS_translate_keycode(key));
/* Record the press so we can detect release later. */
for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) {
if (driverdata->key_pressed[i] == key) {
break;
}
if (driverdata->key_pressed[i] == 255) {
driverdata->key_pressed[i] = key;
break;
}
}
}
}
}
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)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
int i, status;
for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++)
driverdata->key_pressed[i] = 255;
status = (_kernel_osbyte(202, 0, 255) & 0xFF);
SDL_ToggleModState(KMOD_NUM, (status & (1 << 2)) == 0);
SDL_ToggleModState(KMOD_CAPS, (status & (1 << 4)) == 0);
SDL_ToggleModState(KMOD_SCROLL, (status & (1 << 1)) != 0);
/* Disable escape. */
_kernel_osbyte(229, 1, 0);
return 0;
}
void
RISCOS_PumpEvents(_THIS)
{
RISCOS_PollMouse(_this);
RISCOS_PollKeyboard(_this);
}
void
RISCOS_QuitEvents(_THIS)
{
/* Re-enable escape. */
_kernel_osbyte(229, 0, 0);
}
#endif /* SDL_VIDEO_DRIVER_RISCOS */
/* vi: set ts=4 sw=4 expandtab: */