Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Jun 2003 20:29:08 +0200 (CEST)
From:      Tony Voet <20030602@hoegisan.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/52875: devel/sdl12 - patch to support gameport joysticks
Message-ID:  <200306021829.h52IT8h61121@imaging.ugent.be>
Resent-Message-ID: <200306021830.h52IUJSH086561@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         52875
>Category:       ports
>Synopsis:       devel/sdl12 - patch to support gameport joysticks
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 02 11:30:19 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Tony Voet
>Release:        
>Organization:
>Environment:
>Description:
Port devel/sdl12 doesn't support /dev/joy? style gameport joysticks.
>How-To-Repeat:
>Fix:
Buzzword compliant patch featuring noise reduction and auto calibration:

--- src/joystick/bsd/SDL_sysjoystick.c.orig	Sun Jun  1 18:42:04 2003
+++ src/joystick/bsd/SDL_sysjoystick.c	Sun Jun  1 21:57:24 2003
@@ -55,6 +55,7 @@
 
 #ifdef __FreeBSD__
 #include <osreldate.h>
+#include <sys/joystick.h>
 #endif
 
 #include "SDL_error.h"
@@ -196,7 +197,18 @@
 	joy->hwdata = hw;
 	hw->fd = fd;
 	hw->path = strdup(path);
-	hw->type = BSDJOY_UHID;
+	if (! strncmp(path, "/dev/joy", 8))
+	{
+		hw->type = BSDJOY_JOY;
+		joy->naxes = 2;
+		joy->nbuttons = 2;
+		joy->nhats = 0;
+		joy->nballs = 0;
+		joydevnames[joy->index] = strdup("Gameport joystick");
+		goto usbend;
+	}
+	else
+	  hw->type = BSDJOY_UHID;
 	hw->repdesc = hid_get_report_desc(fd);
 	if (hw->repdesc == NULL) {
 		SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path,
@@ -280,6 +292,7 @@
 	}
 	hid_end_parse(hdata);
 
+usbend:
 	/* The poll blocks the event thread. */
 	fcntl(fd, F_SETFL, O_NONBLOCK);
 
@@ -299,6 +312,55 @@
 	struct report *rep;
 	int nbutton, naxe = -1;
 	Sint32 v;
+	struct joystick gameport;
+	static int x, y, xmin=0xffff, ymin=0xffff, xmax=0, ymax=0;
+
+	if (!strncmp(joy->hwdata->path, "/dev/joy", 8)) {
+		if (read(joy->hwdata->fd, &gameport, sizeof(gameport)) != sizeof(gameport)) {
+			return;
+		}
+		if (abs(x - gameport.x) > 8) {
+			x = gameport.x;
+			if (x < xmin) {
+				xmin = x;
+			}
+			if (x > xmax) {
+				xmax = x;
+			}
+			if (xmin == xmax) {
+				xmin--;
+				xmax++;
+			}
+			v = (Sint32)x;
+			v -= (xmax + xmin + 1)/2;
+			v *= 32768/((xmax - xmin + 1)/2);
+			SDL_PrivateJoystickAxis(joy, 0, v);
+		}
+		if (abs(y - gameport.y) > 8) {
+			y = gameport.y;
+			if (y < ymin) {
+				ymin = y;
+			}
+			if (y > ymax) {
+				ymax = y;
+			}
+			if (ymin == ymax) {
+				ymin--;
+				ymax++;
+			}
+			v = (Sint32)y;
+			v -= (ymax + ymin + 1)/2;
+			v *= 32768/((ymax - ymin + 1)/2);
+			SDL_PrivateJoystickAxis(joy, 1, v);
+		}
+		if (gameport.b1 != joy->buttons[0]) {
+			SDL_PrivateJoystickButton(joy, 0, gameport.b1);
+		}
+		if (gameport.b2 != joy->buttons[1]) {
+			SDL_PrivateJoystickButton(joy, 1, gameport.b2);
+		}
+		return;
+	}
 	
 	rep = &joy->hwdata->inreport;
 
@@ -375,8 +437,10 @@
 void
 SDL_SYS_JoystickClose(SDL_Joystick *joy)
 {
-	report_free(&joy->hwdata->inreport);
-	hid_dispose_report_desc(joy->hwdata->repdesc);
+	if (strncmp(joy->hwdata->path, "/dev/joy", 8))	{
+		report_free(&joy->hwdata->inreport);
+		hid_dispose_report_desc(joy->hwdata->repdesc);
+	}
 	close(joy->hwdata->fd);
 	free(joy->hwdata->path);
 	free(joy->hwdata);
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200306021829.h52IT8h61121>