Added preliminary support for MiNT /dev/mouse driver (disabled atm)
authorPatrice Mandin <patmandin@gmail.com>
Thu, 23 Feb 2006 21:51:10 +0000
changeset 14202405517b5eab
parent 1419 36a5068bf7df
child 1421 638da75f9ab8
Added preliminary support for MiNT /dev/mouse driver (disabled atm)
README.MiNT
src/video/ataricommon/SDL_ataridevmouse.c
src/video/ataricommon/SDL_ataridevmouse_c.h
src/video/ataricommon/SDL_biosevents.c
src/video/ataricommon/SDL_gemdosevents.c
src/video/gem/SDL_gemevents.c
src/video/gem/SDL_gemvideo.c
src/video/gem/SDL_gemvideo.h
     1.1 --- a/README.MiNT	Thu Feb 23 04:16:08 2006 +0000
     1.2 +++ b/README.MiNT	Thu Feb 23 21:51:10 2006 +0000
     1.3 @@ -55,7 +55,7 @@
     1.4  IV.  What is supported:
     1.5  
     1.6  Keyboard (GEMDOS, BIOS, GEM, Ikbd)
     1.7 -Mouse (XBIOS, GEM, Ikbd)
     1.8 +Mouse (XBIOS, GEM, Ikbd, /dev/mouse (non working atm, disabled))
     1.9  Video (XBIOS (Fullscreen), GEM (Windowed and Fullscreen))
    1.10  Timer (VBL vector, GNU pth library)
    1.11  Joysticks and joypads (Ikbd, Hardware)
    1.12 @@ -88,6 +88,8 @@
    1.13  
    1.14  (1) GEM does not report relative mouse motion, so xbios mouse driver is used
    1.15  to report this type event. Under MiNT, using XBIOS mouse driver is not possible.
    1.16 +A preliminary driver for /dev/mouse device driver is present, but is disabled
    1.17 +till it can be used with other applications simultaneously.
    1.18  
    1.19  (2) If you build SDL with threads using the GNU pth library, timers are
    1.20  supported via the pth library.
    1.21 @@ -246,4 +248,4 @@
    1.22  
    1.23  -- 
    1.24  Patrice Mandin <pmandin@caramail.com>
    1.25 -http://membres.lycos.fr/pmandin/
    1.26 +http://pmandin.atari.org/
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/video/ataricommon/SDL_ataridevmouse.c	Thu Feb 23 21:51:10 2006 +0000
     2.3 @@ -0,0 +1,159 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2006 Sam Lantinga
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +*/
    2.25 +#include "SDL_config.h"
    2.26 +
    2.27 +/*
    2.28 +	MiNT /dev/mouse driver
    2.29 +
    2.30 +	Patrice Mandin
    2.31 +*/
    2.32 +
    2.33 +#include <fcntl.h>
    2.34 +#include <unistd.h>
    2.35 +
    2.36 +#include "../../events/SDL_events_c.h"
    2.37 +#include "SDL_ataridevmouse_c.h"
    2.38 +
    2.39 +/* Defines */
    2.40 +
    2.41 +#define DEVICE_NAME	"/dev/mouse"
    2.42 +
    2.43 +/* Local variables */
    2.44 +
    2.45 +static int handle = -1;
    2.46 +static int mouseb, prev_mouseb;
    2.47 +
    2.48 +/* Functions */
    2.49 +
    2.50 +int SDL_AtariDevMouse_Open(void)
    2.51 +{
    2.52 +	int r;
    2.53 +	const char *mousedev;
    2.54 +
    2.55 +	/*
    2.56 +		TODO: Fix the MiNT device driver, that locks mouse for other
    2.57 +		applications, so this is disabled till fixed
    2.58 +	 */
    2.59 +	return 0;
    2.60 +
    2.61 +	/* First, try SDL_MOUSEDEV device */
    2.62 +	mousedev = SDL_getenv("SDL_MOUSEDEV");
    2.63 +	if (!mousedev) {
    2.64 +		handle = open(mousedev, 0);
    2.65 +	}
    2.66 +
    2.67 +	/* Failed, try default device */
    2.68 +	if (handle<0) {
    2.69 +		handle = open(DEVICE_NAME, 0);
    2.70 +	}
    2.71 +
    2.72 +	if (handle<0) {
    2.73 +		handle = -1;
    2.74 +		return 0;
    2.75 +	}
    2.76 +
    2.77 +	/* Set non blocking mode */
    2.78 +	r = fcntl(handle, F_GETFL, 0);
    2.79 +	if (r<0) {
    2.80 +		close(handle);
    2.81 +		handle = -1;
    2.82 +		return 0;
    2.83 +	}
    2.84 +
    2.85 +	r |= O_NDELAY;
    2.86 +
    2.87 +	r = fcntl(handle, F_SETFL, r);
    2.88 +	if (r<0) {
    2.89 +		close(handle);
    2.90 +		handle = -1;
    2.91 +		return 0;
    2.92 +	}
    2.93 +
    2.94 +	prev_mouseb = 7;
    2.95 +	return 1;
    2.96 +}
    2.97 +
    2.98 +void SDL_AtariDevMouse_Close(void)
    2.99 +{
   2.100 +	if (handle>0) {
   2.101 +		close(handle);
   2.102 +		handle = -1;
   2.103 +	}
   2.104 +}
   2.105 +
   2.106 +static int atari_GetButton(int button)
   2.107 +{
   2.108 +	switch(button)
   2.109 +	{
   2.110 +		case 0:
   2.111 +			return SDL_BUTTON_RIGHT;
   2.112 +		case 1:
   2.113 +			return SDL_BUTTON_MIDDLE;
   2.114 +		default:
   2.115 +			break;
   2.116 +	}
   2.117 +
   2.118 +	return SDL_BUTTON_LEFT;
   2.119 +}
   2.120 +
   2.121 +void SDL_AtariDevMouse_PostMouseEvents(_THIS, SDL_bool buttonEvents)
   2.122 +{
   2.123 +	unsigned char buffer[3];
   2.124 +	int mousex, mousey;
   2.125 +
   2.126 +	if (handle<0) {
   2.127 +		return;
   2.128 +	}
   2.129 +
   2.130 +	mousex = mousey = 0;
   2.131 +	while (read(handle, buffer, sizeof(buffer))==sizeof(buffer)) {
   2.132 +		mouseb = buffer[0] & 7;
   2.133 +		mousex += (char) buffer[1];
   2.134 +		mousey += (char) buffer[2];
   2.135 +
   2.136 +		/* Mouse button events */
   2.137 +		if (buttonEvents && (mouseb != prev_mouseb)) {
   2.138 +			int i;
   2.139 +
   2.140 +			for (i=0;i<3;i++) {
   2.141 +				int curbutton, prevbutton;
   2.142 +
   2.143 +				curbutton = mouseb & (1<<i);
   2.144 +				prevbutton = prev_mouseb & (1<<i);
   2.145 +			
   2.146 +				if (curbutton && !prevbutton) {
   2.147 +					SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
   2.148 +				}
   2.149 +				if (!curbutton && prevbutton) {
   2.150 +					SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   2.151 +				}
   2.152 +			}
   2.153 +
   2.154 +			prev_mouseb = mouseb;
   2.155 +		}
   2.156 +	}
   2.157 +
   2.158 +	/* Mouse motion event */
   2.159 +	if (mousex || mousey) {
   2.160 +		SDL_PrivateMouseMotion(0, 1, mousex, -mousey);
   2.161 +	}
   2.162 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/ataricommon/SDL_ataridevmouse_c.h	Thu Feb 23 21:51:10 2006 +0000
     3.3 @@ -0,0 +1,42 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2006 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +#include "SDL_config.h"
    3.26 +
    3.27 +/*
    3.28 +	MiNT /dev/mouse driver
    3.29 +
    3.30 +	Patrice Mandin
    3.31 +*/
    3.32 +
    3.33 +#ifndef _SDL_ATARI_DEVMOUSE_H_
    3.34 +#define _SDL_ATARI_DEVMOUSE_H_
    3.35 +
    3.36 +#include "../SDL_sysvideo.h"
    3.37 +
    3.38 +/* Hidden "this" pointer for the video functions */
    3.39 +#define _THIS	SDL_VideoDevice *this
    3.40 +
    3.41 +extern int SDL_AtariDevMouse_Open(void);
    3.42 +extern void SDL_AtariDevMouse_Close(void);
    3.43 +extern void SDL_AtariDevMouse_PostMouseEvents(_THIS, SDL_bool buttonEvents);
    3.44 +
    3.45 +#endif /* _SDL_ATARI_DEVMOUSE_H_ */
     4.1 --- a/src/video/ataricommon/SDL_biosevents.c	Thu Feb 23 04:16:08 2006 +0000
     4.2 +++ b/src/video/ataricommon/SDL_biosevents.c	Thu Feb 23 21:51:10 2006 +0000
     4.3 @@ -37,6 +37,7 @@
     4.4  #include "SDL_atarikeys.h"
     4.5  #include "SDL_atarievents_c.h"
     4.6  #include "SDL_xbiosevents_c.h"
     4.7 +#include "SDL_ataridevmouse_c.h"
     4.8  
     4.9  /* To save state of keyboard */
    4.10  #define ATARIBIOS_MAXKEYS 128
    4.11 @@ -44,6 +45,7 @@
    4.12  static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
    4.13  static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
    4.14  static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
    4.15 +static SDL_bool use_dev_mouse = SDL_FALSE;
    4.16  
    4.17  /* Special keys state */
    4.18  enum {
    4.19 @@ -101,7 +103,12 @@
    4.20  	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
    4.21  	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    4.22  
    4.23 -	vectors_mask = ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS;
    4.24 +	use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
    4.25 +
    4.26 +	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */
    4.27 +	if (!use_dev_mouse) {
    4.28 +		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
    4.29 +	}
    4.30  	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
    4.31  		vectors_mask = 0;
    4.32  	}
    4.33 @@ -146,7 +153,11 @@
    4.34  				TranslateKey(i, bios_currentascii[i], &keysym, SDL_FALSE));
    4.35  	}
    4.36  
    4.37 -	SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
    4.38 +	if (use_dev_mouse) {
    4.39 +		SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
    4.40 +	} else {
    4.41 +		SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
    4.42 +	}
    4.43  
    4.44  	/* Will be previous table */
    4.45  	SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
    4.46 @@ -192,4 +203,7 @@
    4.47  void AtariBios_ShutdownEvents(void)
    4.48  {
    4.49  	SDL_AtariXbios_RestoreVectors();
    4.50 +	if (use_dev_mouse) {
    4.51 +		SDL_AtariDevMouse_Close();
    4.52 +	}
    4.53  }
     5.1 --- a/src/video/ataricommon/SDL_gemdosevents.c	Thu Feb 23 04:16:08 2006 +0000
     5.2 +++ b/src/video/ataricommon/SDL_gemdosevents.c	Thu Feb 23 21:51:10 2006 +0000
     5.3 @@ -37,6 +37,7 @@
     5.4  #include "SDL_atarikeys.h"
     5.5  #include "SDL_atarievents_c.h"
     5.6  #include "SDL_xbiosevents_c.h"
     5.7 +#include "SDL_ataridevmouse_c.h"
     5.8  
     5.9  /* To save state of keyboard */
    5.10  #define ATARIBIOS_MAXKEYS 128
    5.11 @@ -44,6 +45,7 @@
    5.12  static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
    5.13  static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
    5.14  static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
    5.15 +static SDL_bool use_dev_mouse = SDL_FALSE;
    5.16  
    5.17  /* Special keys state */
    5.18  enum {
    5.19 @@ -106,11 +108,15 @@
    5.20  	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
    5.21  	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    5.22  
    5.23 -	vectors_mask = ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS;
    5.24 +	use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
    5.25 +
    5.26 +	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */
    5.27 +	if (!use_dev_mouse) {
    5.28 +		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
    5.29 +	}
    5.30  	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
    5.31  		vectors_mask = 0;
    5.32  	}
    5.33 -
    5.34  	SDL_AtariXbios_InstallVectors(vectors_mask);
    5.35  }
    5.36  
    5.37 @@ -151,7 +157,11 @@
    5.38  				TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_FALSE));
    5.39  	}
    5.40  
    5.41 -	SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
    5.42 +	if (use_dev_mouse) {
    5.43 +		SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
    5.44 +	} else {
    5.45 +		SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
    5.46 +	}
    5.47  
    5.48  	/* Will be previous table */
    5.49  	SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS);
    5.50 @@ -197,4 +207,7 @@
    5.51  void AtariGemdos_ShutdownEvents(void)
    5.52  {
    5.53  	SDL_AtariXbios_RestoreVectors();
    5.54 +	if (use_dev_mouse) {
    5.55 +		SDL_AtariDevMouse_Close();
    5.56 +	}
    5.57  }
     6.1 --- a/src/video/gem/SDL_gemevents.c	Thu Feb 23 04:16:08 2006 +0000
     6.2 +++ b/src/video/gem/SDL_gemevents.c	Thu Feb 23 21:51:10 2006 +0000
     6.3 @@ -39,6 +39,7 @@
     6.4  #include "../ataricommon/SDL_atarikeys.h"	/* for keyboard scancodes */
     6.5  #include "../ataricommon/SDL_atarievents_c.h"
     6.6  #include "../ataricommon/SDL_xbiosevents_c.h"
     6.7 +#include "../ataricommon/SDL_ataridevmouse_c.h"
     6.8  
     6.9  /* Defines */
    6.10  
    6.11 @@ -376,7 +377,11 @@
    6.12  
    6.13  	/* Mouse motion ? */
    6.14  	if (GEM_mouse_relative) {
    6.15 -		SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
    6.16 +		if (GEM_usedevmouse) {
    6.17 +			SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
    6.18 +		} else {
    6.19 +			SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
    6.20 +		}
    6.21  	} else {
    6.22  		if ((prevmousex!=mx) || (prevmousey!=my)) {
    6.23  			int posx, posy;
     7.1 --- a/src/video/gem/SDL_gemvideo.c	Thu Feb 23 04:16:08 2006 +0000
     7.2 +++ b/src/video/gem/SDL_gemvideo.c	Thu Feb 23 21:51:10 2006 +0000
     7.3 @@ -53,6 +53,7 @@
     7.4  #include "SDL_gemmouse_c.h"
     7.5  #include "SDL_gemwm_c.h"
     7.6  #include "../ataricommon/SDL_xbiosevents_c.h"
     7.7 +#include "../ataricommon/SDL_ataridevmouse_c.h"
     7.8  
     7.9  /* Defines */
    7.10  
    7.11 @@ -189,8 +190,13 @@
    7.12  	device->GL_SwapBuffers = GEM_GL_SwapBuffers;
    7.13  #endif
    7.14  
    7.15 -	/* Joystick + Mouse relative motion */
    7.16 -	vectors_mask = ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS;
    7.17 +	device->hidden->use_dev_mouse =
    7.18 +		(SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
    7.19 +
    7.20 +	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */
    7.21 +	if (!(device->hidden->use_dev_mouse)) {
    7.22 +		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
    7.23 +	}
    7.24  	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
    7.25  		vectors_mask = 0;
    7.26  	}
    7.27 @@ -1094,6 +1100,9 @@
    7.28  void GEM_VideoQuit(_THIS)
    7.29  {
    7.30  	SDL_AtariXbios_RestoreVectors();
    7.31 +	if (GEM_usedevmouse) {
    7.32 +		SDL_AtariDevMouse_Close();
    7.33 +	}
    7.34  
    7.35  	GEM_FreeBuffers(this);
    7.36  
     8.1 --- a/src/video/gem/SDL_gemvideo.h	Thu Feb 23 04:16:08 2006 +0000
     8.2 +++ b/src/video/gem/SDL_gemvideo.h	Thu Feb 23 21:51:10 2006 +0000
     8.3 @@ -81,6 +81,7 @@
     8.4  	SDL_bool lock_redraw;		/* Prevent redraw till buffers are setup */
     8.5  	short message[8];			/* To self-send an AES message */
     8.6  	void *menubar;				/* Menu bar save buffer when going fullscreen */
     8.7 +	SDL_bool use_dev_mouse;		/* Use /dev/mouse ? */
     8.8  
     8.9  	SDL_bool fullscreen;		/* Fullscreen or windowed mode ? */
    8.10  	SDL_Rect *SDL_modelist[SDL_NUMMODES+1];	/* Mode list */
    8.11 @@ -129,6 +130,7 @@
    8.12  #define GEM_icon			(this->hidden->icon)
    8.13  #define GEM_fullscreen		(this->hidden->fullscreen)
    8.14  #define GEM_menubar			(this->hidden->menubar)
    8.15 +#define GEM_usedevmouse		(this->hidden->use_dev_mouse)
    8.16  
    8.17  #define GEM_buffer1			(this->hidden->buffer1)
    8.18  #define GEM_buffer2			(this->hidden->buffer2)