summaryrefslogtreecommitdiff
path: root/devel/SDL/patches/patch-aa
blob: 4d9edc10f0728a08e60fb90919faf0230185bbba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
$NetBSD: patch-aa,v 1.11 2005/05/31 17:37:50 wiz Exp $

--- src/joystick/bsd/SDL_sysjoystick.c.orig	2004-12-13 08:54:32.000000000 +0100
+++ src/joystick/bsd/SDL_sysjoystick.c
@@ -44,8 +44,13 @@ static char rcsid =
 #if defined(HAVE_USB_H)
 #include <usb.h>
 #endif
+#ifdef __DragonFly__
+#include <bus/usb/usb.h>
+#include <bus/usb/usbhid.h>
+#else
 #include <dev/usb/usb.h>
 #include <dev/usb/usbhid.h>
+#endif
 
 #if defined(HAVE_USBHID_H)
 #include <usbhid.h>
@@ -55,12 +60,14 @@ static char rcsid =
 #include <libusbhid.h>
 #endif
 
-#ifdef __FreeBSD__
+#ifdef __DragonFly__
+#include <sys/joystick.h>
+#elif defined(__FreeBSD__)
 #include <osreldate.h>
 #include <sys/joystick.h>
 #endif
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
+#if defined(HAVE_MACHINE_JOYSTICK) || defined(__OpenBSD__)
 #include <machine/joystick.h>
 #endif
 
@@ -239,6 +246,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick *joy)
 	struct hid_data *hdata;
 	struct report *rep;
 	int fd;
+	int i;
 
 	fd = open(path, O_RDONLY);
 	if (fd == -1) {
@@ -303,6 +311,8 @@ SDL_SYS_JoystickOpen(SDL_Joystick *joy)
 	joy->nbuttons = 0;
 	joy->nhats = 0;
 	joy->nballs = 0;
+	for (i=0; i<JOYAXE_count; i++)
+		hw->axis_map[i] = -1;
 
 	while (hid_get_item(hdata, &hitem) > 0) {
 		char *sp;
@@ -329,8 +339,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick *joy)
 			    unsigned usage = HID_USAGE(hitem.usage);
 			    int joyaxe = usage_to_joyaxe(usage);
 			    if (joyaxe >= 0) {
-				hw->axis_map[joyaxe] = joy->naxes;
-				joy->naxes++;
+				hw->axis_map[joyaxe] = 1;
 			    } else if (usage == HUG_HAT_SWITCH) {
 				joy->nhats++;
 			    }
@@ -348,6 +357,9 @@ SDL_SYS_JoystickOpen(SDL_Joystick *joy)
 		}
 	}
 	hid_end_parse(hdata);
+	for (i=0; i<JOYAXE_count; i++)
+		if (hw->axis_map[i] > 0)
+			hw->axis_map[i] = joy->naxes++;
 
 usbend:
 	/* The poll blocks the event thread. */
@@ -370,7 +382,7 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joy
 	int nbutton, naxe = -1;
 	Sint32 v;
 
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#if defined(__FreeBSD__) || defined(HAVE_MACHINE_JOYSTICK) || defined(__OpenBSD__) || defined(__DragonFly__)
 	struct joystick gameport;
 	static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
  
@@ -419,7 +431,7 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joy
 		}
 		return;
 	}
-#endif /* defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) */
+#endif /* defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)*/
 	
 	rep = &joy->hwdata->inreport;
 
@@ -457,7 +469,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joy
 			    } else if (usage == HUG_HAT_SWITCH) {
 				v = (Sint32)hid_get_data(REP_BUF_DATA(rep),
 							 &hitem);
-				SDL_PrivateJoystickHat(joy, 0, hatval_to_sdl(v));
+				SDL_PrivateJoystickHat(joy, 0,
+					hatval_to_sdl(v)-hitem.logical_minimum);
 			    }
 			    break;
 			}
@@ -518,7 +531,9 @@ report_alloc(struct report *r, struct re
 {
 	int len;
 
-#ifdef __FreeBSD__
+#ifdef __DragonFly__
+	len = hid_report_size(rd, r->rid, repinfo[repind].kind);
+#elif defined(__FreeBSD__)
 # if (__FreeBSD_version >= 460000)
 #  if (__FreeBSD_version <= 500111)
 	len = hid_report_size(rd, r->rid, repinfo[repind].kind);
@@ -527,12 +542,12 @@ report_alloc(struct report *r, struct re
 #  endif
 # else
 	len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
-#endif
+# endif
 #else
 # ifdef USBHID_NEW
-	len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
-# else
 	len = hid_report_size(rd, repinfo[repind].kind, r->rid);
+# else
+	len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
 # endif
 #endif