2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
25 MiNT /dev/mouse driver
33 #include "../../events/SDL_events_c.h"
34 #include "SDL_ataridevmouse_c.h"
38 #define DEVICE_NAME "/dev/mouse"
42 static int handle = -1;
43 static int mouseb, prev_mouseb;
47 int SDL_AtariDevMouse_Open(void)
53 TODO: Fix the MiNT device driver, that locks mouse for other
54 applications, so this is disabled till fixed
58 /* First, try SDL_MOUSEDEV device */
59 mousedev = SDL_getenv("SDL_MOUSEDEV");
61 handle = open(mousedev, 0);
64 /* Failed, try default device */
66 handle = open(DEVICE_NAME, 0);
74 /* Set non blocking mode */
75 r = fcntl(handle, F_GETFL, 0);
84 r = fcntl(handle, F_SETFL, r);
95 void SDL_AtariDevMouse_Close(void)
103 static int atari_GetButton(int button)
108 return SDL_BUTTON_RIGHT;
110 return SDL_BUTTON_MIDDLE;
115 return SDL_BUTTON_LEFT;
118 void SDL_AtariDevMouse_PostMouseEvents(_THIS, SDL_bool buttonEvents)
120 unsigned char buffer[3];
128 while (read(handle, buffer, sizeof(buffer))==sizeof(buffer)) {
129 mouseb = buffer[0] & 7;
130 mousex += (char) buffer[1];
131 mousey += (char) buffer[2];
133 /* Mouse button events */
134 if (buttonEvents && (mouseb != prev_mouseb)) {
138 int curbutton, prevbutton;
140 curbutton = mouseb & (1<<i);
141 prevbutton = prev_mouseb & (1<<i);
143 if (curbutton && !prevbutton) {
144 SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
146 if (!curbutton && prevbutton) {
147 SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
151 prev_mouseb = mouseb;
155 /* Mouse motion event */
156 if (mousex || mousey) {
157 SDL_PrivateMouseMotion(0, 1, mousex, -mousey);