Atlas - SDL_riscosevents.c

Home / ext / SDL / src / video / riscos Lines: 1 | Size: 5141 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifdef SDL_VIDEO_DRIVER_RISCOS 24 25#include "../../events/SDL_events_c.h" 26 27#include "SDL_riscosvideo.h" 28#include "SDL_riscosevents_c.h" 29#include "scancodes_riscos.h" 30 31#include <kernel.h> 32#include <swis.h> 33 34static SDL_Scancode SDL_RISCOS_translate_keycode(int keycode) 35{ 36 SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN; 37 38 if (keycode < SDL_arraysize(riscos_scancode_table)) { 39 scancode = riscos_scancode_table[keycode]; 40 41#ifdef DEBUG_SCANCODES 42 if (scancode == SDL_SCANCODE_UNKNOWN) { 43 SDL_Log("The key you just pressed is not recognized by SDL: %d", keycode); 44 } 45#endif 46 } 47 48 return scancode; 49} 50 51void RISCOS_PollKeyboard(SDL_VideoDevice *_this) 52{ 53 SDL_VideoData *internal = _this->internal; 54 Uint8 key = 2; 55 int i; 56 57 // Check for key releases 58 for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) { 59 if (internal->key_pressed[i] != 255) { 60 if ((_kernel_osbyte(129, internal->key_pressed[i] ^ 0xff, 0xff) & 0xff) != 255) { 61 SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, internal->key_pressed[i], SDL_RISCOS_translate_keycode(internal->key_pressed[i]), false); 62 internal->key_pressed[i] = 255; 63 } 64 } 65 } 66 67 // Check for key presses 68 while (key < 0xff) { 69 key = _kernel_osbyte(121, key + 1, 0) & 0xff; 70 switch (key) { 71 case 255: 72 // Ignore mouse keys 73 case 9: 74 case 10: 75 case 11: 76 // Ignore keys with multiple INKEY codes 77 case 24: 78 case 40: 79 case 71: 80 case 87: 81 break; 82 83 default: 84 SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, key, SDL_RISCOS_translate_keycode(key), true); 85 86 // Record the press so we can detect release later. 87 for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) { 88 if (internal->key_pressed[i] == key) { 89 break; 90 } 91 if (internal->key_pressed[i] == 255) { 92 internal->key_pressed[i] = key; 93 break; 94 } 95 } 96 } 97 } 98} 99 100static const Uint8 mouse_button_map[] = { 101 SDL_BUTTON_RIGHT, 102 SDL_BUTTON_MIDDLE, 103 SDL_BUTTON_LEFT, 104 SDL_BUTTON_X1, 105 SDL_BUTTON_X2, 106 SDL_BUTTON_X2 + 1, 107 SDL_BUTTON_X2 + 2, 108 SDL_BUTTON_X2 + 3 109}; 110 111void RISCOS_PollMouse(SDL_VideoDevice *_this) 112{ 113 SDL_VideoData *internal = _this->internal; 114 SDL_Mouse *mouse = SDL_GetMouse(); 115 SDL_Rect rect; 116 _kernel_swi_regs regs; 117 int i, x, y, buttons; 118 119 if (!SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &rect)) { 120 return; 121 } 122 123 _kernel_swi(OS_Mouse, &regs, &regs); 124 x = (regs.r[0] >> 1); 125 y = rect.h - (regs.r[1] >> 1); 126 buttons = regs.r[2]; 127 128 if (mouse->x != x || mouse->y != y) { 129 SDL_SendMouseMotion(0, mouse->focus, SDL_DEFAULT_MOUSE_ID, false, (float)x, (float)y); 130 } 131 132 if (internal->last_mouse_buttons != buttons) { 133 for (i = 0; i < SDL_arraysize(mouse_button_map); i++) { 134 bool down = ((buttons & (1 << i)) != 0); 135 SDL_SendMouseButton(0, mouse->focus, SDL_DEFAULT_MOUSE_ID, mouse_button_map[i], down); 136 } 137 internal->last_mouse_buttons = buttons; 138 } 139} 140 141bool RISCOS_InitEvents(SDL_VideoDevice *_this) 142{ 143 SDL_VideoData *internal = _this->internal; 144 _kernel_swi_regs regs; 145 int i, status; 146 147 for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) { 148 internal->key_pressed[i] = 255; 149 } 150 151 status = (_kernel_osbyte(202, 0, 255) & 0xFF); 152 SDL_ToggleModState(SDL_KMOD_NUM, (status & (1 << 2)) ? false : true); 153 SDL_ToggleModState(SDL_KMOD_CAPS, (status & (1 << 4)) ? false : true); 154 SDL_ToggleModState(SDL_KMOD_SCROLL, (status & (1 << 1)) ? true : false); 155 156 _kernel_swi(OS_Mouse, &regs, &regs); 157 internal->last_mouse_buttons = regs.r[2]; 158 159 // Disable escape. 160 _kernel_osbyte(229, 1, 0); 161 162 return true; 163} 164 165void RISCOS_PumpEvents(SDL_VideoDevice *_this) 166{ 167 RISCOS_PollMouse(_this); 168 RISCOS_PollKeyboard(_this); 169} 170 171void RISCOS_QuitEvents(SDL_VideoDevice *_this) 172{ 173 // Re-enable escape. 174 _kernel_osbyte(229, 0, 0); 175} 176 177#endif // SDL_VIDEO_DRIVER_RISCOS 178
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.