Atlas - SDL_dosmouse.c
Home / ext / SDL / src / video / dos Lines: 1 | Size: 4956 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 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_DOSVESA 24 25// https://stanislavs.org/helppc/int_33.html 26 27#include "SDL_dosmouse.h" 28#include "SDL_dosvideo.h" 29 30#include "../../events/SDL_mouse_c.h" 31#include "../../events/default_cursor.h" 32#include "../SDL_sysvideo.h" 33 34// Create a cursor from a surface 35static SDL_Cursor *DOSVESA_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) 36{ 37 SDL_CursorData *curdata; 38 SDL_Cursor *cursor; 39 40 SDL_assert(surface->format == SDL_PIXELFORMAT_ARGB8888); 41 SDL_assert(surface->pitch == surface->w * 4); 42 43 cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor)); 44 if (!cursor) { 45 return NULL; 46 } 47 curdata = (SDL_CursorData *)SDL_calloc(1, sizeof(*curdata)); 48 if (!curdata) { 49 SDL_free(cursor); 50 return NULL; 51 } 52 53 curdata->surface = SDL_DuplicateSurface(surface); 54 if (!curdata->surface) { 55 SDL_free(curdata); 56 SDL_free(cursor); 57 return NULL; 58 } 59 60 SDL_SetSurfaceBlendMode(curdata->surface, SDL_BLENDMODE_BLEND); 61 62 curdata->hot_x = hot_x; 63 curdata->hot_y = hot_y; 64 curdata->w = surface->w; 65 curdata->h = surface->h; 66 67 cursor->internal = curdata; 68 69 return cursor; 70} 71 72static SDL_Cursor *DOSVESA_CreateDefaultCursor(void) 73{ 74 return SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); 75} 76 77// Show the specified cursor, or hide if cursor is NULL 78static bool DOSVESA_ShowCursor(SDL_Cursor *cursor) 79{ 80 return true; // we handle this elsewhere. 81} 82 83// Free a window manager cursor 84static void DOSVESA_FreeCursor(SDL_Cursor *cursor) 85{ 86 SDL_CursorData *curdata; 87 88 if (cursor) { 89 curdata = cursor->internal; 90 91 if (curdata) { 92 SDL_DestroySurface(curdata->surface); 93 SDL_DestroySurface(curdata->converted_surface); 94 SDL_free(cursor->internal); 95 } 96 SDL_free(cursor); 97 } 98} 99 100static bool DOSVESA_WarpMouseGlobal(float x, float y) 101{ 102 SDL_Mouse *mouse = SDL_GetMouse(); 103 104 if (!mouse || !mouse->cur_cursor || !mouse->cur_cursor->internal) { 105 return true; 106 } 107 108 // warp mouse in the driver, so we get correct screen coordinates from it. 109 __dpmi_regs regs; 110 regs.x.ax = 0x4; 111 regs.x.cx = (Uint16)x; 112 regs.x.dx = (Uint16)y; 113 __dpmi_int(0x33, ®s); 114 115 // Update internal mouse position. 116 SDL_SendMouseMotion(0, mouse->focus, SDL_GLOBAL_MOUSE_ID, false, x, y); 117 118 return true; 119} 120 121static bool DOSVESA_WarpMouse(SDL_Window *window, float x, float y) 122{ 123 return DOSVESA_WarpMouseGlobal(x, y); 124} 125 126// This is called when a mouse motion event occurs 127static bool DOSVESA_MoveCursor(SDL_Cursor *cursor) 128{ 129 return true; // we handle this elsewhere. 130} 131 132void DOSVESA_InitMouse(SDL_VideoDevice *_this) 133{ 134 SDL_Mouse *mouse = SDL_GetMouse(); 135 mouse->internal = NULL; 136 137 __dpmi_regs regs; 138 regs.x.ax = 0; 139 __dpmi_int(0x33, ®s); 140 if (regs.x.ax == 0) { 141 return; // no mouse found, don't hook up cursor support, etc. 142 } 143 144 mouse->internal = SDL_calloc(1, 1); // just something non-NULL (and safely freeable) to say "there's a mouse available." 145 146 // Query mouse sensitivity (mickeys per pixel) via INT 33h function 0x1B 147 SDL_VideoData *data = _this->internal; 148 regs.x.ax = 0x1B; // Get Mouse Sensitivity 149 __dpmi_int(0x33, ®s); 150 data->mickeys_per_hpixel = (regs.x.bx > 0) ? (float)regs.x.bx : 8.0f; 151 data->mickeys_per_vpixel = (regs.x.cx > 0) ? (float)regs.x.cx : 16.0f; 152 153 mouse->CreateCursor = DOSVESA_CreateCursor; 154 mouse->ShowCursor = DOSVESA_ShowCursor; 155 mouse->MoveCursor = DOSVESA_MoveCursor; 156 mouse->FreeCursor = DOSVESA_FreeCursor; 157 mouse->WarpMouse = DOSVESA_WarpMouse; 158 mouse->WarpMouseGlobal = DOSVESA_WarpMouseGlobal; 159 160 SDL_SetDefaultCursor(DOSVESA_CreateDefaultCursor()); 161} 162 163void DOSVESA_QuitMouse(SDL_VideoDevice *_this) 164{ 165 SDL_Mouse *mouse = SDL_GetMouse(); 166 SDL_free(mouse->internal); 167 mouse->internal = NULL; 168} 169 170#endif // SDL_VIDEO_DRIVER_DOSVESA 171[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.