SDL-1.2: atari: remove support for /dev/mouse

From 5f749cc33e6f56001506ff0278f22a117f5676f0 Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Fri, 17 May 2024 22:00:31 +0200
Subject: [PATCH] atari: remove support for /dev/mouse

Introduced in 2006 as disabled and never touched again.
---
 README.MiNT                                 |   4 +-
 src/video/ataricommon/SDL_ataridevmouse.c   | 159 --------------------
 src/video/ataricommon/SDL_ataridevmouse_c.h |  42 ------
 src/video/ataricommon/SDL_biosevents.c      |  20 +--
 src/video/ataricommon/SDL_gemdosevents.c    |  21 +--
 src/video/gem/SDL_gemevents.c               |   7 +-
 src/video/gem/SDL_gemvideo.c                |  14 +-
 src/video/gem/SDL_gemvideo.h                |   2 -
 8 files changed, 8 insertions(+), 261 deletions(-)
 delete mode 100644 src/video/ataricommon/SDL_ataridevmouse.c
 delete mode 100644 src/video/ataricommon/SDL_ataridevmouse_c.h

diff --git a/README.MiNT b/README.MiNT
index 3b3351e6a..82e31a3f4 100644
--- a/README.MiNT
+++ b/README.MiNT
@@ -55,7 +55,7 @@ III.  Enjoy! :)
 IV.  What is supported:
 
 Keyboard (GEMDOS, BIOS, GEM, Ikbd)
-Mouse (XBIOS, GEM, Ikbd, /dev/mouse (non working atm, disabled))
+Mouse (XBIOS, GEM, Ikbd)
 Video (XBIOS (Fullscreen), GEM (Windowed and Fullscreen))
 Timer (VBL vector, GNU pth library)
 Joysticks and joypads (Ikbd, Hardware)
@@ -88,8 +88,6 @@ OpenGL driver always uses OSMesa.
 
 (1) GEM does not report relative mouse motion, so xbios mouse driver is used
 to report this type event.
-A preliminary driver for /dev/mouse device driver is present, but is disabled
-till it can be used with other applications simultaneously.
 
 (2) If you build SDL with threads using the GNU pth library, timers are
 supported via the pth library.
diff --git a/src/video/ataricommon/SDL_ataridevmouse.c b/src/video/ataricommon/SDL_ataridevmouse.c
deleted file mode 100644
index 190b9c3bd..000000000
--- a/src/video/ataricommon/SDL_ataridevmouse.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
-    SDL - Simple DirectMedia Layer
-    Copyright (C) 1997-2012 Sam Lantinga
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-    Sam Lantinga
-    slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-/*
-	MiNT /dev/mouse driver
-
-	Patrice Mandin
-*/
-
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "../../events/SDL_events_c.h"
-#include "SDL_ataridevmouse_c.h"
-
-/* Defines */
-
-#define DEVICE_NAME	"/dev/mouse"
-
-/* Local variables */
-
-static int handle = -1;
-static int mouseb, prev_mouseb;
-
-/* Functions */
-
-int SDL_AtariDevMouse_Open(void)
-{
-	int r;
-	const char *mousedev;
-
-	/*
-		TODO: Fix the MiNT device driver, that locks mouse for other
-		applications, so this is disabled till fixed
-	 */
-	return 0;
-
-	/* First, try SDL_MOUSEDEV device */
-	mousedev = SDL_getenv("SDL_MOUSEDEV");
-	if (mousedev) {
-		handle = open(mousedev, 0);
-	}
-
-	/* Failed, try default device */
-	if (handle<0) {
-		handle = open(DEVICE_NAME, 0);
-	}
-
-	if (handle<0) {
-		handle = -1;
-		return 0;
-	}
-
-	/* Set non blocking mode */
-	r = fcntl(handle, F_GETFL, 0);
-	if (r<0) {
-		close(handle);
-		handle = -1;
-		return 0;
-	}
-
-	r |= O_NDELAY;
-
-	r = fcntl(handle, F_SETFL, r);
-	if (r<0) {
-		close(handle);
-		handle = -1;
-		return 0;
-	}
-
-	prev_mouseb = 7;
-	return 1;
-}
-
-void SDL_AtariDevMouse_Close(void)
-{
-	if (handle>0) {
-		close(handle);
-		handle = -1;
-	}
-}
-
-static int atari_GetButton(int button)
-{
-	switch(button)
-	{
-		case 0:
-			return SDL_BUTTON_RIGHT;
-		case 1:
-			return SDL_BUTTON_MIDDLE;
-		default:
-			break;
-	}
-
-	return SDL_BUTTON_LEFT;
-}
-
-void SDL_AtariDevMouse_PostMouseEvents(_THIS, SDL_bool buttonEvents)
-{
-	unsigned char buffer[3];
-	int mousex, mousey;
-
-	if (handle<0) {
-		return;
-	}
-
-	mousex = mousey = 0;
-	while (read(handle, buffer, sizeof(buffer))==sizeof(buffer)) {
-		mouseb = buffer[0] & 7;
-		mousex += (char) buffer[1];
-		mousey += (char) buffer[2];
-
-		/* Mouse button events */
-		if (buttonEvents && (mouseb != prev_mouseb)) {
-			int i;
-
-			for (i=0;i<3;i++) {
-				int curbutton, prevbutton;
-
-				curbutton = mouseb & (1<<i);
-				prevbutton = prev_mouseb & (1<<i);
-			
-				if (curbutton && !prevbutton) {
-					SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
-				}
-				if (!curbutton && prevbutton) {
-					SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
-				}
-			}
-
-			prev_mouseb = mouseb;
-		}
-	}
-
-	/* Mouse motion event */
-	if (mousex || mousey) {
-		SDL_PrivateMouseMotion(0, 1, mousex, -mousey);
-	}
-}
diff --git a/src/video/ataricommon/SDL_ataridevmouse_c.h b/src/video/ataricommon/SDL_ataridevmouse_c.h
deleted file mode 100644
index 7cae0222e..000000000
--- a/src/video/ataricommon/SDL_ataridevmouse_c.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
-    SDL - Simple DirectMedia Layer
-    Copyright (C) 1997-2012 Sam Lantinga
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-    Sam Lantinga
-    slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-/*
-	MiNT /dev/mouse driver
-
-	Patrice Mandin
-*/
-
-#ifndef _SDL_ATARI_DEVMOUSE_H_
-#define _SDL_ATARI_DEVMOUSE_H_
-
-#include "../SDL_sysvideo.h"
-
-/* Hidden "this" pointer for the video functions */
-#define _THIS	SDL_VideoDevice *this
-
-extern int SDL_AtariDevMouse_Open(void);
-extern void SDL_AtariDevMouse_Close(void);
-extern void SDL_AtariDevMouse_PostMouseEvents(_THIS, SDL_bool buttonEvents);
-
-#endif /* _SDL_ATARI_DEVMOUSE_H_ */
diff --git a/src/video/ataricommon/SDL_biosevents.c b/src/video/ataricommon/SDL_biosevents.c
index 20d3dd1ba..7cfcb6b29 100644
--- a/src/video/ataricommon/SDL_biosevents.c
+++ b/src/video/ataricommon/SDL_biosevents.c
@@ -37,11 +37,9 @@
 #include "SDL_atarikeys.h"
 #include "SDL_atarievents_c.h"
 #include "SDL_xbiosevents_c.h"
-#include "SDL_ataridevmouse_c.h"
 
 static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
-static SDL_bool use_dev_mouse = SDL_FALSE;
 
 static void UpdateSpecialKeys(int special_keys_state);
 
@@ -53,15 +51,8 @@ void AtariBios_InitOSKeymap(_THIS)
 	SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
 	SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
 
-	use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
-
 	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */
-	if (!use_dev_mouse) {
-		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
-	}
-/*	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
-		vectors_mask = 0;
-	}*/
+	vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
 
 	SDL_AtariXbios_InstallVectors(vectors_mask);
 }
@@ -116,11 +107,7 @@ void AtariBios_PumpEvents(_THIS)
 		}
 	}
 
-	if (use_dev_mouse) {
-		SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
-	} else {
-		SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
-	}
+	SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
 
 	/* Will be previous table */
 	SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard, sizeof(bios_previouskeyboard));
@@ -146,7 +133,4 @@ static void UpdateSpecialKeys(int special_keys_state)
 void AtariBios_ShutdownEvents(void)
 {
 	SDL_AtariXbios_RestoreVectors();
-	if (use_dev_mouse) {
-		SDL_AtariDevMouse_Close();
-	}
 }
diff --git a/src/video/ataricommon/SDL_gemdosevents.c b/src/video/ataricommon/SDL_gemdosevents.c
index 1e2d4718a..164629599 100644
--- a/src/video/ataricommon/SDL_gemdosevents.c
+++ b/src/video/ataricommon/SDL_gemdosevents.c
@@ -37,13 +37,11 @@
 #include "SDL_atarikeys.h"
 #include "SDL_atarievents_c.h"
 #include "SDL_xbiosevents_c.h"
-#include "SDL_ataridevmouse_c.h"
 
 /* To save state of keyboard */
 
 static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
 static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
-static SDL_bool use_dev_mouse = SDL_FALSE;
 
 static void UpdateSpecialKeys(int special_keys_state);
 
@@ -55,15 +53,9 @@ void AtariGemdos_InitOSKeymap(_THIS)
 	SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
 	SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
 
-	use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
-
 	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */
-	if (!use_dev_mouse) {
-		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
-	}
-/*	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
-		vectors_mask = 0;
-	}*/
+	vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
+
 	SDL_AtariXbios_InstallVectors(vectors_mask);
 }
 
@@ -117,11 +109,7 @@ void AtariGemdos_PumpEvents(_THIS)
 		}
 	}
 
-	if (use_dev_mouse) {
-		SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
-	} else {
-		SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
-	}
+	SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
 
 	/* Will be previous table */
 	SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, sizeof(gemdos_previouskeyboard));
@@ -147,7 +135,4 @@ static void UpdateSpecialKeys(int special_keys_state)
 void AtariGemdos_ShutdownEvents(void)
 {
 	SDL_AtariXbios_RestoreVectors();
-	if (use_dev_mouse) {
-		SDL_AtariDevMouse_Close();
-	}
 }
diff --git a/src/video/gem/SDL_gemevents.c b/src/video/gem/SDL_gemevents.c
index fc091bc46..f9c06870c 100644
--- a/src/video/gem/SDL_gemevents.c
+++ b/src/video/gem/SDL_gemevents.c
@@ -42,7 +42,6 @@
 #include "../ataricommon/SDL_atarikeys.h"	/* for keyboard scancodes */
 #include "../ataricommon/SDL_atarievents_c.h"
 #include "../ataricommon/SDL_xbiosevents_c.h"
-#include "../ataricommon/SDL_ataridevmouse_c.h"
 
 /* Duration after which we consider key released */
 
@@ -356,11 +355,7 @@ static void do_mouse_motion(_THIS, short mx, short my)
 
 	/* Relative mouse motion ? */
 	if (GEM_mouse_relative) {
-		if (GEM_usedevmouse) {
-			SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
-		} else {
-			SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
-		}
+		SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
 		return;
 	}
 
diff --git a/src/video/gem/SDL_gemvideo.c b/src/video/gem/SDL_gemvideo.c
index 3b7f8af8e..8a151cb8b 100644
--- a/src/video/gem/SDL_gemvideo.c
+++ b/src/video/gem/SDL_gemvideo.c
@@ -53,7 +53,6 @@
 #include "SDL_gemmouse_c.h"
 #include "SDL_gemwm_c.h"
 #include "../ataricommon/SDL_xbiosevents_c.h"
-#include "../ataricommon/SDL_ataridevmouse_c.h"
 
 /* Defines */
 
@@ -190,16 +189,8 @@ static SDL_VideoDevice *GEM_CreateDevice(int devindex)
 	device->GL_SwapBuffers = GEM_GL_SwapBuffers;
 #endif
 
-	device->hidden->use_dev_mouse =
-		(SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
-
 	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */
-	if (!(device->hidden->use_dev_mouse)) {
-		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
-	}
-/*	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
-		vectors_mask = 0;
-	}*/
+	vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
 
 	SDL_AtariXbios_InstallVectors(vectors_mask);
 
@@ -1181,9 +1172,6 @@ void GEM_VideoQuit(_THIS)
 	graf_mouse(ARROW, NULL);
 
 	SDL_AtariXbios_RestoreVectors();
-	if (GEM_usedevmouse) {
-		SDL_AtariDevMouse_Close();
-	}
 
 	GEM_FreeBuffers(this);
 
diff --git a/src/video/gem/SDL_gemvideo.h b/src/video/gem/SDL_gemvideo.h
index 1a46e6eb9..ffdc7ec78 100644
--- a/src/video/gem/SDL_gemvideo.h
+++ b/src/video/gem/SDL_gemvideo.h
@@ -90,7 +90,6 @@ struct SDL_PrivateVideoData {
 	SDL_bool align_windows;		/* align windows to 16-pixel boundary */
 	short message[8];			/* To self-send an AES message */
 	void *menubar;				/* Menu bar save buffer when going fullscreen */
-	SDL_bool use_dev_mouse;		/* Use /dev/mouse ? */
 	WMcursor *cursor;			/* To restore cursor when leaving/entering window */
 	WMcursor *prev_cursor;		/* Previous cursor */
 
@@ -141,7 +140,6 @@ struct SDL_PrivateVideoData {
 #define GEM_icon			(this->hidden->icon)
 #define GEM_fullscreen		(this->hidden->fullscreen)
 #define GEM_menubar			(this->hidden->menubar)
-#define GEM_usedevmouse		(this->hidden->use_dev_mouse)
 #define GEM_cursor			(this->hidden->cursor)
 #define GEM_prev_cursor		(this->hidden->prev_cursor)