View | Details | Raw Unified | Return to bug 174017
Collapse All | Expand All

(-)snes9x/Makefile (-57 / +39 lines)
Lines 6-45 Link Here
6
#
6
#
7
7
8
PORTNAME=	snes9x
8
PORTNAME=	snes9x
9
PORTVERSION=	1.51
9
PORTVERSION=	1.53
10
PORTREVISION=	4
11
CATEGORIES=	emulators
10
CATEGORIES=	emulators
12
MASTER_SITES=	http://files.ipherswipsite.com/snes9x/ \
11
MASTER_SITES=	http://files.ipherswipsite.com/snes9x/ \
13
		http://www.lysator.liu.se/snes9x/${PORTVERSION}/
12
		https://sites.google.com/site/bearoso/${PORTNAME}/ \
13
		http://www.s9x-w32.de/dl/ \
14
		http://snesemu.black-ship.net/emus/snes9x/ \
15
		http://camoy.sdf.org/mirror/snes9x/ \
16
		http://bigkidtennis.com/snes9x/
14
DISTNAME=	${PORTNAME}-${PORTVERSION}-src
17
DISTNAME=	${PORTNAME}-${PORTVERSION}-src
15
18
16
MAINTAINER=	acm@FreeBSD.org
19
MAINTAINER=	acm@FreeBSD.org
17
COMMENT=	Super Nintendo Entertainment System(SNES) Emulator
20
COMMENT=	Super Nintendo Entertainment System(SNES) Emulator
18
21
19
LIB_DEPENDS=	png15:${PORTSDIR}/graphics/png
20
21
USE_BZIP2=	yes
22
USE_BZIP2=	yes
22
USE_XORG=	x11 sm ice xext
23
USE_XORG=	x11 sm ice xext
23
USE_GMAKE=	yes
24
USE_GMAKE=	yes
25
# Force GCC (clang freeze in filters/hq2x.cpp)
26
USE_GCC=	4.2+
24
GNU_CONFIGURE=	yes
27
GNU_CONFIGURE=	yes
25
CONFIGURE_ARGS+=	--without-extensions
26
CPPFLAGS+=	-I${LOCALBASE}/include
28
CPPFLAGS+=	-I${LOCALBASE}/include
27
LDFLAGS+=	-L${LOCALBASE}/lib
29
LDFLAGS+=	-L${LOCALBASE}/lib
28
MAKE_ARGS=	INCLUDES="-I${WRKSRC}/unzip -I${WRKSRC} -I${LOCALBASE}/include \
29
		${PTHREAD_CFLAGS}" LDLIBS="-L${LOCALBASE}/lib ${PTHREAD_LIBS}" \
30
		OPTIMISE="${CXXFLAGS}"
31
WRKSRC=		${WRKDIR}/${DISTNAME}
30
WRKSRC=		${WRKDIR}/${DISTNAME}
31
CONFIGURE_WRKSRC=	${WRKSRC}/unix
32
BUILD_WRKSRC=   ${CONFIGURE_WRKSRC}
32
33
33
PLIST_FILES=	bin/${PORTNAME}
34
PLIST_FILES=	bin/${PORTNAME} etc/${PORTNAME}/snes9x.conf
34
SUB_FILES=	pkg-message
35
SUB_FILES=	pkg-message
35
36
36
OPTIONS=	DEBUG	"Enable debug information"	off \
37
OPTIONS_DEFINE=	DEBUG SCREENSHOT JMA NETPLAY
37
		OPENGL	"Enable OpenGL support"	off \
38
OPTIONS_DEFAULT=	SCREENSHOT JMA NETPLAY
38
		SCREENSHOT	"Enable screenshot support"	on \
39
39
		X86_ASM	"Use i386 optimization (only for i386)"	on \
40
SCREENSHOT_DESC=	Enable screenshot support
40
		MMX	"Enable MMX (only for i386)"	off \
41
JMA_DESC=		Enable screenshot support
41
		JMA	"Enable JMA archive decompression support"	on \
42
NETPLAY_DESC=		Enable network support
42
		NETPLAY	"Enable network support"	on
43
43
44
.include <bsd.port.pre.mk>
44
.include <bsd.port.pre.mk>
45
45
Lines 49-113 Link Here
49
		README
49
		README
50
.endif
50
.endif
51
51
52
.if defined(WITH_DEBUG)
52
.if ${PORT_OPTIONS:MDEBUG}
53
CONFIGURE_ARGS+=	--with-debug
53
CONFIGURE_ARGS+=	--enable-debug
54
.else
54
.else
55
CONFIGURE_ARGS+=	--without-debug
55
CONFIGURE_ARGS+=	--disable-debug
56
.endif
56
.endif
57
57
58
.if ${ARCH} == "i386"
58
.if ${PORT_OPTIONS:MSCREENSHOT}
59
.if !defined(WITHOUT_X86_ASM)
60
BUILD_DEPENDS+=	nasm:${PORTSDIR}/devel/nasm
61
CONFIGURE_ARGS+=	--with-assembler
62
.else
63
CONFIGURE_ARGS+=	--without-assembler
64
.endif
65
66
.if defined(WITH_MMX) && !defined(PACKAGE_BUILDING)
67
CONFIGURE_ARGS+=	--with-mmx
68
.else
69
CONFIGURE_ARGS+=	--without-mmx
70
.endif
71
.endif
72
73
.if defined(WITH_OPENGL)
74
USE_GL=		yes
75
CONFIGURE_ARGS+=	--with-opengl
76
SNES9X_BIN=	osnes9x
77
.else
78
SNES9X_BIN=	snes9x
79
.endif
80
81
.if !defined(WITHOUT_SCREENSHOT)
82
LIB_DEPENDS+=	png15:${PORTSDIR}/graphics/png
59
LIB_DEPENDS+=	png15:${PORTSDIR}/graphics/png
83
CONFIGURE_ARGS+=	--with-screenshot
60
CONFIGURE_ARGS+=	--enable-screenshot
84
.else
61
.else
85
CONFIGURE_ARGS+=	--without-screenshot
62
CONFIGURE_ARGS+=	--disable-screenshot
86
.endif
63
.endif
87
64
88
.if !defined(WITHOUT_JMA)
65
.if ${PORT_OPTIONS:MJMA}
89
CONFIGURE_ARGS+=	--with-jma-decomp
66
CONFIGURE_ARGS+=	--enable-jma
90
.else
67
.else
91
CONFIGURE_ARGS+=	--without-jma-decomp
68
CONFIGURE_ARGS+=	--disable-jma
92
.endif
69
.endif
93
70
94
.if !defined(WITHOUT_NETPLAY)
71
.if ${PORT_OPTIONS:MNETPLAY}
95
CONFIGURE_ARGS+=	--with-netplay
72
CONFIGURE_ARGS+=	--enable-netplay
96
.else
73
.else
97
CONFIGURE_ARGS+=	--without-netplay
74
CONFIGURE_ARGS+=	--disable-netplay
98
.endif
75
.endif
99
76
100
.if exists(/usr/lib/libusbhid.a)
77
.if exists(/usr/lib/libusbhid.a)
101
CONFIGURE_ARGS+=	--with-joystick
78
CONFIGURE_ARGS+=	--enable-gamepad
102
.else
79
.else
103
CONFIGURE_ARGS+=	--without-joystick
80
CONFIGURE_ARGS+=	--disable-gamepad
104
.endif
81
.endif
105
82
106
post-patch:
83
post-patch:
107
	@${REINPLACE_CMD} -i "" -e 's|Pitch2|Pitch|g' ${WRKSRC}/unix/opengl.cpp
84
	${REINPLACE_CMD} -e "s|linux|freebsd|g" \
85
		-e "s|lpng|lpng15|g" ${WRKSRC}/unix/configure
86
	${REINPLACE_CMD} -e 's|-DMITSHM||' ${WRKSRC}/unix/Makefile.in
87
	${REINPLACE_CMD} -e "s|%%PREFIX%%|${PREFIX}|" ${WRKSRC}/port.h
108
88
109
do-install:
89
do-install:
110
.if !defined(NOPORTDOCS)
90
.if ${PORT_OPTIONS:MDOCS}
111
	${MKDIR} ${DOCSDIR}
91
	${MKDIR} ${DOCSDIR}
112
.for FILE in control* changes.txt hardware.txt porting.html faqs.txt \
92
.for FILE in control* changes.txt hardware.txt porting.html faqs.txt \
113
		snapshots.txt snes9x.conf.default
93
		snapshots.txt snes9x.conf.default
Lines 115-121 Link Here
115
.endfor
95
.endfor
116
	${INSTALL_DATA} ${WRKSRC}/unix/docs/readme_unix.txt ${DOCSDIR}/README
96
	${INSTALL_DATA} ${WRKSRC}/unix/docs/readme_unix.txt ${DOCSDIR}/README
117
.endif
97
.endif
118
	${INSTALL_PROGRAM} ${WRKSRC}/${SNES9X_BIN} ${PREFIX}/bin/${PORTNAME}
98
	${INSTALL_PROGRAM} ${BUILD_WRKSRC}/snes9x ${PREFIX}/bin/${PORTNAME}
99
	${MKDIR} ${PREFIX}/etc/${PORTNAME}
100
	${INSTALL_PROGRAM} ${WRKSRC}/doc/snes9x.conf.default ${PREFIX}/etc/${PORTNAME}/snes9x.conf
119
101
120
post-install:
102
post-install:
121
	@${CAT} ${PKGMESSAGE}
103
	@${CAT} ${PKGMESSAGE}
(-)snes9x/distinfo (-2 / +2 lines)
Lines 1-2 Link Here
1
SHA256 (snes9x-1.51-src.tar.bz2) = 70c8f41fc7f1e000605127e0f4261e3eb52c72019b3cbf9bc8061b0b8ccdf687
1
SHA256 (snes9x-1.53-src.tar.bz2) = 9f7c5d2d0fa3fe753611cf94e8879b73b8bb3c0eab97cdbcb6ab7376efa78dc3
2
SIZE (snes9x-1.51-src.tar.bz2) = 1707256
2
SIZE (snes9x-1.53-src.tar.bz2) = 1838746
(-)snes9x/files/patch-2XSAI.CPP (-12 lines)
Lines 1-12 Link Here
1
--- 2xsai.cpp.orig	Fri Dec  5 02:03:08 2003
2
+++ 2xsai.cpp	Sun Jan 25 01:41:08 2004
3
@@ -81,7 +81,8 @@
4
 #include "port.h"
5
 #include "gfx.h"
6
 
7
-#if (defined(USE_X86_ASM) && (defined (__i386__) || defined (__i486__) || \
8
+#if (defined(USE_X86_ASM) && defined(ASMKREED) && \
9
+              (defined (__i386__) || defined (__i486__) || \
10
                defined (__i586__) || defined (__WIN32__) || defined (__DJGPP)))
11
 #  ifndef MMX
12
 #    define MMX
(-)snes9x/files/patch-3d.h (-11 lines)
Lines 1-11 Link Here
1
--- 3d.h.orig	Wed Aug 13 06:27:16 2003
2
+++ 3d.h	Fri Sep 12 00:05:49 2003
3
@@ -80,7 +80,7 @@
4
 #include <GL/gl.h>
5
 #include <GL/glu.h>
6
 
7
-#ifdef __linux__
8
+#if defined(__linux__) || defined(__FreeBSD__)
9
 #include <GL/glx.h>
10
 #endif
11
 
(-)snes9x/files/patch-Makefile.in (-19 lines)
Lines 1-19 Link Here
1
--- Makefile.in	Tue Dec 26 16:46:56 2006
2
+++ Makefile.in	Tue Dec 26 16:49:20 2006
3
@@ -138,7 +138,6 @@
4
 
5
 ifdef THREAD_SOUND
6
 CPUDEFINES += -DUSE_THREADS
7
-EXTRALIBS += -lpthread
8
 endif
9
 
10
 ifdef GLIDE
11
@@ -150,7 +149,7 @@
12
 ifdef OPENGL
13
 OPENGLOBJS = unix/opengl.o
14
 OPENGLDEFINES = -DUSE_OPENGL
15
-OPENGLLIBS = -lGL -lGLU -ldl
16
+OPENGLLIBS = -lGL -lGLU
17
 endif
18
 
19
 ifdef AIDO
(-)snes9x/files/patch-ad (-29 lines)
Lines 1-29 Link Here
1
--- memmap.cpp	2007-10-03 11:11:07.000000000 -0500
2
+++ memmap.cpp	2007-10-03 11:11:34.000000000 -0500
3
@@ -169,7 +169,7 @@
4
 #include <ctype.h>
5
 #include <assert.h>
6
 
7
-#ifdef __linux
8
+#if defined(__linux) || defined(__FreeBSD__)
9
 #include <unistd.h>
10
 #endif
11
 
12
@@ -1473,7 +1473,7 @@
13
 		{
14
 			fwrite((char *) Multi.sramB, size, 1, file);
15
 			fclose(file);
16
-#ifdef __linux
17
+#if defined(__linux) || defined(__FreeBSD__)
18
 			chown(name, getuid(), getgid());
19
 #endif
20
 		}
21
@@ -1502,7 +1502,7 @@
22
 		{
23
 			fwrite((char *) SRAM, size, 1, file);
24
 			fclose(file);
25
-#ifdef __linux
26
+#if defined(__linux) || defined(__FreeBSD__)
27
 			chown(sramName, getuid(), getgid());
28
 #endif
29
 			if (Settings.SPC7110RTC)
(-)snes9x/files/patch-ae (-13 lines)
Lines 1-13 Link Here
1
--- port.h.orig	Fri Jun 30 08:40:56 2006
2
+++ port.h	Tue Dec 26 23:09:22 2006
3
@@ -360,6 +360,10 @@
4
 #define SYS_CONFIG_FILE "/etc/snes9x/snes9x.conf"
5
 #endif
6
 
7
+#ifdef __FreeBSD__
8
+#define TITLE "Snes9X: FreeBSD"
9
+#endif
10
+
11
 #ifndef TITLE
12
 #define TITLE "Snes9x"
13
 #endif
(-)snes9x/files/patch-af (-455 lines)
Lines 1-455 Link Here
1
--- unix/unix.cpp	2007-04-28 19:51:08.000000000 -0500
2
+++ unix/unix.cpp	2007-10-03 16:53:16.000000000 -0500
3
@@ -173,7 +173,7 @@
4
 #include <fcntl.h>
5
 #include <sys/time.h>
6
 /* FIXME: Linux alpha (aristocat) has a broken timercmp. Make testcase */
7
-#if defined(__linux)
8
+#if defined(__linux) || defined(__FreeBSD__)
9
 # ifndef timercmp
10
 #  define timercmp(tvp, uvp, cmp)\
11
         ((tvp)->tv_sec cmp (uvp)->tv_sec ||\
12
@@ -197,7 +197,7 @@
13
 pthread_mutex_t mutex;
14
 #endif
15
 
16
-#if !defined(NOSOUND) && defined(__linux)
17
+#if !defined(NOSOUND) && (defined(__linux) || defined(__FreeBSD__))
18
 #include <sys/soundcard.h>
19
 #include <sys/mman.h>
20
 #endif
21
@@ -210,6 +210,11 @@
22
 #endif
23
 #endif
24
 
25
+#if defined(__FreeBSD__)
26
+typedef sig_t SIG_PF;
27
+#include <err.h>
28
+#endif
29
+
30
 //Breaks sol9 and probably others.
31
 //#if defined(__sun) && defined(__GNUC__)
32
 //typedef void (*SIG_PF)();
33
@@ -233,11 +238,12 @@
34
 
35
 #ifdef NETPLAY_SUPPORT
36
 #include "netplay.h"
37
-
38
 #ifdef _DEBUG
39
 #define NP_DEBUG 2
40
 #endif
41
+#endif
42
 
43
+#if defined(NETPLAY_SUPPORT) || defined(JOYSTICK_SUPPORT)
44
 /* accessors into controls.cpp static variables */
45
 uint16 MovieGetJoypad(int i);
46
 void MovieSetJoypad(int i, uint16 buttons);
47
@@ -245,22 +251,86 @@
48
 /* Joypads status information */
49
 uint32 old_joypads[8];
50
 uint32 joypads[8];
51
-
52
 #endif
53
 
54
 #ifdef JOYSTICK_SUPPORT
55
+#define        JOYSTICK_MAX_DEVICES    4
56
+int JoystickShift = 0;
57
+uint8 js_mod [8] = {0, 0, 0, 0, 0, 0, 0, 0};
58
 #if defined(__linux)
59
+#define        JOYSTICK_MAX_BUTTONS    4
60
 #include <linux/joystick.h>
61
-uint8 js_mod [8] = {0, 0, 0, 0, 0, 0, 0, 0};
62
 int js_fd [8] = {-1, -1, -1, -1, -1, -1, -1, -1};
63
 char *js_device [8] = {"/dev/js0", "/dev/js1", "/dev/js2", "/dev/js3", "/dev/js4", "/dev/js5", "/dev/js6", "/dev/js7" };
64
 #endif
65
 
66
+#if defined(__FreeBSD__)
67
+#include <sys/types.h>
68
+#include <sys/param.h>
69
+       
70
+extern "C" {
71
+#define class klass
72
+#include <dev/usb/usb.h>
73
+#include <dev/usb/usbhid.h>   
74
+#undef class
75
+       
76
+#if __FreeBSD_version < 500111
77
+#include <libusbhid.h>
78
+#else
79
+#include <usbhid.h>
80
+#endif
81
+}
82
+
83
+#define        JOYSTICK_MAX_BUTTONS    16
84
+
85
+#define JOYSTICK_MAP_BUTTON_INITIALIZER                                \
86
+    {                                                          \
87
+       SNES_Y_MASK, SNES_B_MASK, SNES_A_MASK,                  \
88
+       SNES_X_MASK, SNES_TL_MASK, SNES_TR_MASK,                \
89
+       SNES_TL_MASK, SNES_TR_MASK,                             \
90
+       SNES_SELECT_MASK, SNES_START_MASK, 0, 0, 0, 0, 0, 0     \
91
+    }
92
+
93
+int js_map_button[JOYSTICK_MAX_BUTTONS][16] = {
94
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
95
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
96
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
97
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
98
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
99
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
100
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
101
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
102
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
103
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
104
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
105
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
106
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
107
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
108
+       JOYSTICK_MAP_BUTTON_INITIALIZER,
109
+       JOYSTICK_MAP_BUTTON_INITIALIZER
110
+};
111
+char *js_device [4] = {"/dev/uhid0", "/dev/uhid1", "/dev/uhid2", "/dev/uhid3"};
112
+struct js_range {
113
+       int min, max, lower_third, higher_third;
114
+};
115
+struct js_info {
116
+       char *buf;
117
+       int reportlen;
118
+       int offset;
119
+       struct js_range x, y;
120
+       int buttons;
121
+       struct hid_item *hids;
122
+       int fd;
123
+       int joy;
124
+} js_info[4];
125
+int js_count = 0;
126
+#endif
127
+
128
 void InitJoysticks ();
129
 void ReadJoysticks ();
130
 #endif
131
 
132
-#if !defined(NOSOUND) && defined (__linux)
133
+#if !defined(NOSOUND) && (defined (__linux) || defined(__FreeBSD__))
134
 #define CONFIGURABLE_SOUND_DEVICE
135
     char *sound_device = "/dev/dsp";
136
 #endif
137
@@ -285,7 +355,7 @@
138
 const char *inc_format="%03d";
139
 
140
 //FIXME: I see no reason not to configureenable this for all Unixen
141
-#if defined(DEBUGGER) && (defined(__linux) || defined(__sun))
142
+#if defined(DEBUGGER) && (defined(__linux) || defined(__sun) || defined(__FreeBSD__))
143
 static void sigbrkhandler(int)
144
 {
145
     CPU.Flags |= DEBUG_MODE_FLAG;
146
@@ -326,22 +396,54 @@
147
 
148
 void S9xParseArg (char **argv, int &i, int argc)
149
 {
150
+#ifdef JOYSTICK_SUPPORT
151
     if (strcmp (argv [i], "-j") == 0 ||
152
 	     strcasecmp (argv [i], "-nojoy") == 0) {
153
-#ifdef JOYSTICK_SUPPORT
154
 	Settings.JoystickEnabled = FALSE;
155
+    } 
156
+
157
+#ifdef __FreeBSD__
158
+    else if (strcasecmp(argv[i], "-joyshift") == 0)
159
+       JoystickShift = 1;
160
+#endif
161
+    else if (strncasecmp(argv[i], "-joydev", sizeof("-joydev") - 1) == 0) {
162
+       char *end, *snum = argv[i] + sizeof("-joydev") - 1;
163
+       unsigned long num;
164
+
165
+       if (*snum == '\0' || argc < i + 1)
166
+               S9xUsage();
167
+       if ((num = strtoul(snum, &end, 10)) < JOYSTICK_MAX_DEVICES &&
168
+           num > 0 && *end == '\0')
169
+               js_device[num - 1] = argv[++i];
170
+       else
171
+            S9xUsage ();
172
+        }
173
+    else if (strncasecmp(argv[i], "-joymap", sizeof("-joymap") - 1) == 0) {
174
+       static const int button_masks[] = {
175
+               SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK,
176
+               SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK
177
+       };
178
+       char *end, *snum = argv[i] + sizeof("-joymap") - 1;
179
+       unsigned long num;
180
+       int *js_buttons, b;
181
+
182
+       if (argc < i + (sizeof(button_masks) / sizeof(int)) || *snum == '\0')
183
+               S9xUsage();
184
+       num = strtoul(snum, &end, 10);
185
+       if (*end != '\0')
186
+               S9xUsage();
187
+       if (num == 0 || num > 4)        /* hardcode: max joysticks */
188
+               S9xUsage();
189
+       js_buttons = js_map_button[num - 1];
190
+       for (b = 0; b < (sizeof(button_masks) / sizeof(int)); b++)
191
+               if ((num = strtoul(argv[++i], &end, 10)) <= 16 && num != 0 &&
192
+                   *end == '\0')
193
+                       js_buttons[num - 1] = button_masks[b];
194
+     }
195
+
196
+    else 
197
 #endif
198
-    } else if (strncasecmp (argv [i], "-joydev", 7) == 0 && argv[i][7]>='1' && argv[i][7]<='8' && argv[i][8]=='\0')
199
-    {
200
-        int j = argv[i][7]-'1';
201
-	if (i + 1 < argc) {
202
-#ifdef JOYSTICK_SUPPORT
203
-	    js_device[j] = argv[++i];
204
-#else
205
-            S9xMessage(S9X_WARNING, S9X_USAGE, "Joystick support is not available!");
206
-#endif
207
-        } else S9xUsage ();
208
-    } else if (strcasecmp (argv [i], "-sounddev") == 0) {
209
+   if (strcasecmp (argv [i], "-sounddev") == 0) {
210
     if (i + 1 < argc) {
211
 #if defined(CONFIGURABLE_SOUND_DEVICE)
212
         sound_device = argv[++i];
213
@@ -552,7 +654,7 @@
214
 #if !defined(__MSDOS) && defined(DEBUGGER)
215
 #if defined(__unix) && !defined(__NeXT__)
216
     struct sigaction sa;
217
-#if defined(__linux)
218
+#if defined(__linux) || defined(__FreeBSD__)
219
     sa.sa_handler = sigbrkhandler;
220
 #else
221
     sa.sa_handler = (SIG_PF) sigbrkhandler;
222
@@ -770,6 +872,7 @@
223
 }
224
 
225
 #ifdef JOYSTICK_SUPPORT
226
+#ifdef __linux
227
 void InitJoysticks ()
228
 {
229
 #ifdef JSIOCGVERSION
230
@@ -854,6 +957,189 @@
231
     }
232
 #endif
233
 }
234
+#endif
235
+#if defined(__FreeBSD__)
236
+
237
+/*
238
+ * USB HID code for FreeBSD/NetBSD
239
+ * Brian Feldman <green@FreeBSD.org>
240
+ *
241
+ * Reference used:
242
+ * X-Mame USB HID joystick driver for NetBSD.
243
+ *
244
+ * Written by Krister Walfridsson <cato@df.lth.se>
245
+ */
246
+
247
+int
248
+InitJoystickFd(int fd, char *dev) {
249
+       report_desc_t rd;
250
+       struct hid_data *d;
251
+       struct hid_item h, new_h;
252
+       struct js_info *my_info;
253
+       int reportlen, report_id, is_joystick;
254
+
255
+       my_info = &js_info[js_count];
256
+       rd = hid_get_report_desc(fd);
257
+       if (rd == 0) {
258
+               warn("%s", dev);
259
+               return (-1);
260
+       }
261
+       report_id = 0;
262
+#if __FreeBSD_version < 500111
263
+       reportlen = hid_report_size(rd, report_id, hid_input);
264
+#else
265
+       reportlen = hid_report_size(rd, hid_input, report_id);
266
+#endif
267
+       my_info->buf = (char *)malloc(reportlen);
268
+       if (my_info->buf == NULL)
269
+               err(1, "malloc");
270
+       my_info->reportlen = reportlen;
271
+       my_info->offset = report_id != 0;
272
+       my_info->buttons = 0;
273
+       my_info->hids = NULL;
274
+
275
+       is_joystick = 0;
276
+#if __FreeBSD_version < 500111
277
+       for (d = hid_start_parse(rd, 1 << hid_input);
278
+#else
279
+       for (d = hid_start_parse(rd, 1 << hid_input, report_id);
280
+#endif
281
+           hid_get_item(d, &h);) {
282
+               int usage, page, link_it = 0;
283
+               struct js_range *axis;
284
+
285
+               page = HID_PAGE(h.usage);
286
+               usage = HID_USAGE(h.usage);
287
+               if (!is_joystick)
288
+                       is_joystick = (h.kind == hid_collection &&
289
+                           page == HUP_GENERIC_DESKTOP &&
290
+                           (usage == HUG_JOYSTICK || usage == HUG_GAME_PAD));
291
+               if (h.kind != hid_input || !is_joystick)
292
+                       continue;
293
+               axis = NULL;
294
+               if (page == HUP_GENERIC_DESKTOP) {
295
+                       switch (usage) {
296
+                       case HUG_X:
297
+                       case HUG_RX:
298
+                               axis = &my_info->x;
299
+                               break;
300
+                       case HUG_Y:
301
+                       case HUG_RY:
302
+                               axis = &my_info->y;
303
+                               break;
304
+                       }
305
+               }
306
+               if (axis != NULL) {
307
+                       axis->min = h.logical_minimum;
308
+                       axis->max = h.logical_maximum;
309
+                       axis->lower_third = axis->min +
310
+                          (axis->max - axis->min) / 3;
311
+                       axis->higher_third = axis->min +
312
+                          (axis->max - axis->min) * 2 / 3;
313
+                       link_it = 1;
314
+               }
315
+               if (!link_it) {
316
+                       if (page != HUP_BUTTON || usage > 16)
317
+                               continue;
318
+                       if (usage > my_info->buttons)
319
+                               my_info->buttons = usage;
320
+               }
321
+               new_h = h;
322
+               new_h.next = my_info->hids;
323
+               my_info->hids = (struct hid_item *)
324
+                   malloc(sizeof(*my_info->hids));
325
+               if (my_info->hids == NULL)
326
+                       err(1, "malloc");
327
+               *my_info->hids = new_h;
328
+       }
329
+       printf("Joystick %s: %d buttons, X range %d - %d, Y range %d - %d\n",
330
+           dev, my_info->buttons, my_info->x.min, my_info->x.max,
331
+           my_info->y.min, my_info->y.max);
332
+       my_info->fd = fd;
333
+       if (JoystickShift) {
334
+               my_info->joy = js_count + 1;
335
+       } else
336
+               my_info->joy = js_count;
337
+       return (0);
338
+}
339
+
340
+void
341
+InitJoysticks() {
342
+       int i, fd;
343
+
344
+       for (i = 0; i < (sizeof(js_device) / sizeof(js_device[0])); i++) {
345
+               fd = open(js_device[i], O_RDONLY | O_NONBLOCK);
346
+               if (fd == -1)
347
+                       continue;
348
+               if (InitJoystickFd(fd, js_device[i]) == 0)
349
+                       js_count++;
350
+               else
351
+                       close(fd);
352
+       }
353
+}
354
+
355
+void
356
+ReadJoysticks() {
357
+       struct hid_item *h;
358
+       int page, usage, njoy, joy;
359
+
360
+       for (njoy = 0; njoy < js_count; njoy++) {
361
+               struct js_info *jsi;
362
+
363
+               jsi = &js_info[njoy];
364
+               joy = jsi->joy;
365
+
366
+               if (read(jsi->fd, jsi->buf, jsi->reportlen) != jsi->reportlen)
367
+                       continue;
368
+               for (h = jsi->hids; h != NULL; h = h->next) {
369
+                       int d;
370
+
371
+                       d = hid_get_data(jsi->buf + jsi->offset, h);
372
+                       page = HID_PAGE(h->usage);
373
+                       usage = HID_USAGE(h->usage);
374
+
375
+                       switch (page) {
376
+                       case HUP_GENERIC_DESKTOP:
377
+                               switch (usage) {
378
+                               case HUG_X:
379
+                               case HUG_RX:
380
+                                       if (d < jsi->x.lower_third) {
381
+                                               joypads[joy] |= SNES_LEFT_MASK;
382
+                                               joypads[joy] &= ~SNES_RIGHT_MASK;
383
+                                       } else if (d < jsi->x.higher_third) {
384
+                                               joypads[joy] &= ~SNES_LEFT_MASK;
385
+                                               joypads[joy] &= ~SNES_RIGHT_MASK;
386
+                                       } else {
387
+                                               joypads[joy] &= ~SNES_LEFT_MASK;
388
+                                               joypads[joy] |= SNES_RIGHT_MASK;
389
+                                       }
390
+                                       break;
391
+                               case HUG_Y:
392
+                               case HUG_RY:
393
+                                       if (d < jsi->y.lower_third) {
394
+                                               joypads[joy] |= SNES_UP_MASK;
395
+                                               joypads[joy] &= ~SNES_DOWN_MASK;
396
+                                       } else if (d < jsi->y.higher_third) {
397
+                                               joypads[joy] &= ~SNES_UP_MASK;
398
+                                               joypads[joy] &= ~SNES_DOWN_MASK;
399
+                                       } else {
400
+                                               joypads[joy] &= ~SNES_UP_MASK;
401
+                                               joypads[joy] |= SNES_DOWN_MASK;
402
+                                       }
403
+                                       break;
404
+                               }
405
+                               break;
406
+                       case HUP_BUTTON:
407
+                               if (d)
408
+                                       joypads[joy] |= js_map_button[njoy][usage - 1];
409
+                               else
410
+                                       joypads[joy] &= ~js_map_button[njoy][usage - 1];
411
+                               break;
412
+                       }
413
+               }
414
+       }
415
+}
416
+#endif // defined(__FreeBSD__)
417
 #endif // defined (JOYSTICK_SUPPORT)
418
 
419
 START_EXTERN_C
420
@@ -1716,7 +2002,7 @@
421
 }
422
 #endif
423
 
424
-#if !defined(NOSOUND) && defined(__linux)
425
+#if !defined(NOSOUND) && (defined(__linux) || defined(__FreeBSD__))
426
 static int Rates[8] =
427
 {
428
     0, 8000, 11025, 16000, 22050, 32000, 44100, 48000
429
@@ -1847,7 +2133,7 @@
430
 #endif
431
 
432
 
433
-#if !defined(NOSOUND) && (defined (__linux) || defined (__sun))
434
+#if !defined(NOSOUND) && (defined (__linux) || defined (__sun) || defined(__FreeBSD__))
435
 void S9xUnixProcessSound (void)
436
 {
437
 }
438
@@ -1890,7 +2176,7 @@
439
 }
440
 #endif
441
 
442
-#if !defined(NOSOUND) && (defined (__linux) || defined (__sun))
443
+#if !defined(NOSOUND) && (defined (__linux) || defined (__sun) || defined(__FreeBSD__))
444
 void S9xGenerateSound ()
445
 {
446
     /* Linux and Sun versions */
447
@@ -1985,7 +2271,7 @@
448
     /* If not, this will be called by timer */
449
     if (Settings.Mute)
450
         return NULL;
451
-#ifdef __linux
452
+#if defined(__linux) || defined(__FreeBSD__)
453
     audio_buf_info info;
454
 
455
     if (!Settings.ThreadSound &&
(-)snes9x/files/patch-ag (-32 lines)
Lines 1-32 Link Here
1
diff -ru ../../work/release/unix/xf86.cpp ./unix/xf86.cpp
2
--- ../../work/release/unix/xf86.cpp	Tue Sep 22 06:36:50 1998
3
+++ ./unix/xf86.cpp	Wed Dec 29 01:54:04 1999
4
@@ -4,16 +4,20 @@
5
    Question/comments regarding this file only: maciej@imsa.edu
6
  */
7
 
8
-#ifdef __linux
9
+#if defined(__linux) || defined(__FreeBSD__)
10
 //#define USE_XF86VIDMODE
11
 
12
+#ifdef __linux
13
 #include <asm/ioctls.h>
14
+#endif
15
+#include <sys/types.h>
16
 #include <sys/ioctl.h>
17
 #include <sys/time.h>
18
+#ifdef __linux
19
 #include <linux/ioctl.h>
20
+#endif
21
 
22
 #include <fcntl.h>
23
-#include <sys/types.h>
24
 
25
 #include <string.h>
26
 #include <ctype.h>
27
@@ -833,4 +837,4 @@
28
 	ret = 1;
29
     return (ret);
30
 }
31
-#endif /* __linux */
32
+#endif /* __linux || __FreeBSD__ */
(-)snes9x/files/patch-ah (-24 lines)
Lines 1-24 Link Here
1
--- unzip/unzip.h	2007-10-03 12:28:47.000000000 -0500
2
+++ unzip/unzip.h	2007-10-03 12:30:22.000000000 -0500
3
@@ -41,14 +41,18 @@
4
 #ifndef _unz_H
5
 #define _unz_H
6
 
7
-#ifdef __cplusplus
8
-extern "C" {
9
-#endif
10
+#include <sys/types.h>
11
 
12
 #ifndef _ZLIB_H
13
 #include <zlib.h>
14
 #endif
15
 
16
+#ifdef __cplusplus
17
+extern "C" {
18
+#endif
19
+
20
+#define ZEXPORT
21
+
22
 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
23
 /* like the STRICT of WIN32, we define a pointer that cannot be converted
24
     from (void*) without cast */
(-)snes9x/files/patch-configure (-124 lines)
Lines 1-124 Link Here
1
--- configure.orig	2007-04-29 16:03:52.000000000 -0500
2
+++ configure	2007-10-03 14:33:44.000000000 -0500
3
@@ -860,6 +860,7 @@
4
   --with(out)-opengl        Use OpenGL for output (default: without)
5
   --with(out)-aido          Use a shared memory area for output (default: without)
6
   --with(out)-assembler   Use assembler cores if available (default: with)
7
+  --with(out)-mmx	Use assembler cores if available (default: with)
8
   --with(out)-zsnesc4     Use ZSNES C4 core if available (default: same as --with-assembler)
9
   --with(out)-zsnesfx     Use ZSNES SuperFX core if available (default: same as --with-assembler)
10
   --with(out)-correct-vram-reads Use Correct VRAM read logic (default: with)
11
@@ -5873,7 +5874,9 @@
12
 ZSNESFX='#ZSNESFX=1'
13
 ZSNESC4='#ZSNESC4=1'
14
 ASMCPU=''
15
+if test yes = "$with_mmx"; then
16
 ASMKREED='#ASMKREED=1'
17
+fi
18
 SDD1_DECOMP='#SDD1_DECOMP=1'
19
 JMA='#JMA=1'
20
 SPC700ASM=''
21
@@ -5995,6 +5998,60 @@
22
 echo "$as_me:$LINENO: result: $snes9x_cv_i386_cpu" >&5
23
 echo "${ECHO_T}$snes9x_cv_i386_cpu" >&6
24
 
25
+echo "$as_me:$LINENO: checking if the OS is FreeBSD" >&5
26
+echo $ECHO_N "checking if the OS is FreeBSD... $ECHO_C" >&6
27
+if test "${snes9x_cv_freebsd_os+set}" = set; then
28
+  echo $ECHO_N "(cached) $ECHO_C" >&6
29
+else
30
+
31
+  cat >conftest.$ac_ext <<_ACEOF
32
+#line 3885 "configure"
33
+/* confdefs.h.  */
34
+_ACEOF
35
+cat confdefs.h >>conftest.$ac_ext
36
+cat >>conftest.$ac_ext <<_ACEOF
37
+/* end confdefs.h.  */
38
+
39
+#ifdef __FreeBSD__
40
+/* */
41
+#else
42
+#error Not FreeBSD.
43
+#endif
44
+
45
+int
46
+main ()
47
+{
48
+
49
+  ;
50
+  return 0;
51
+}
52
+_ACEOF
53
+rm -f conftest.$ac_objext
54
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
55
+  (eval $ac_compile) 2>&5
56
+  ac_status=$?
57
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
58
+  (exit $ac_status); } &&
59
+         { ac_try='test -s conftest.$ac_objext'
60
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
61
+  (eval $ac_try) 2>&5
62
+  ac_status=$?
63
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
64
+  (exit $ac_status); }; }; then
65
+  snes9x_cv_freebsd_os=yes
66
+else
67
+  echo "$as_me: failed program was:" >&5
68
+sed 's/^/| /' conftest.$ac_ext >&5
69
+
70
+snes9x_cv_freebsd_os=no
71
+fi
72
+rm -f conftest.$ac_objext conftest.$ac_ext
73
+fi
74
+
75
+echo "$as_me:$LINENO: result: $snes9x_cv_freebsd_os" >&5
76
+echo "${ECHO_T}$snes9x_cv_freebsd_os" >&6
77
+
78
+
79
 echo "$as_me:$LINENO: checking if the OS is Linux" >&5
80
 echo $ECHO_N "checking if the OS is Linux... $ECHO_C" >&6
81
 if test "${snes9x_cv_linux_os+set}" = set; then
82
@@ -6365,7 +6422,10 @@
83
   with_joystick=yes
84
 fi;
85
 
86
-if test yes = "$snes9x_cv_linux_os" -a yes = "$with_joystick"; then
87
+if test yes = "$snes9x_cv_freebsd_os" -a yes = "$with_joystick"; then
88
+   JOYDEFINES=' -DJOYSTICK_SUPPORT'
89
+   SYSLIBS="$SYSLIBS"' -lusbhid'
90
+elif test yes = "$snes9x_cv_linux_os" -a yes = "$with_joystick"; then
91
    JOYDEFINES=' -DJOYSTICK_SUPPORT'
92
 else
93
    with_joystick="no"
94
@@ -6396,6 +6456,13 @@
95
    CPUINC='-Ish'
96
 fi
97
 
98
+# Check whether --with-mmx or --without-mmx was given.
99
+if test "${with_mmx+set}" = set -a yes = "$with_assembler"; then
100
+  withval="$with_mmx"
101
+
102
+else
103
+  with_mmx=no
104
+fi;
105
 
106
 # Check whether --with-sdd1-decomp or --without-sdd1-decomp was given.
107
 if test "${with_sdd1_decomp+set}" = set; then
108
@@ -9758,7 +9825,7 @@
109
 cat >>conftest.$ac_ext <<_ACEOF
110
 /* end confdefs.h.  */
111
 
112
-#if defined(__linux) || defined(__sun) || defined(__sgi)
113
+#if defined(__linux) || defined(__sun) || defined(__sgi) || defined(__FreeBSD__)
114
 /* */
115
 #else
116
 #error No sound for this platform
117
@@ -10013,6 +10080,7 @@
118
 sound support....... $snes9x_cv_sound
119
 display system...... $snes9x_info_display
120
 joystick support.... $with_joystick
121
+using mmx code....   $with_mmx
122
 netplay support..... $with_netplay
123
 SDD1 decompression.. $with_sdd1_decomp
124
 JMA decompression... $with_jma_decomp
(-)snes9x/files/patch-memmap.cpp (+20 lines)
Line 0 Link Here
1
--- memmap.cpp.orig	2011-04-24 17:38:10.000000000 +0400
2
+++ memmap.cpp	2012-11-30 01:47:27.000000000 +0400
3
@@ -2069,7 +2069,7 @@
4
 			size_t	ignore;
5
 			ignore = fwrite((char *) Multi.sramB, size, 1, file);
6
 			fclose(file);
7
-		#ifdef __linux
8
+		#ifdef __FreeBSD__
9
 			ignore = chown(name, getuid(), getgid());
10
 		#endif
11
 		}
12
@@ -2089,7 +2089,7 @@
13
 			size_t	ignore;
14
 			ignore = fwrite((char *) SRAM, size, 1, file);
15
 			fclose(file);
16
-		#ifdef __linux
17
+		#ifdef __FreeBSD__
18
 			ignore = chown(sramName, getuid(), getgid());
19
 		#endif
20
 
(-)snes9x/files/patch-port.h (+14 lines)
Line 0 Link Here
1
--- port.h.orig	2011-04-24 17:38:10.000000000 +0400
2
+++ port.h	2012-11-30 02:26:23.000000000 +0400
3
@@ -327,6 +327,11 @@
4
 #define SYS_CONFIG_FILE "/etc/snes9x/snes9x.conf"
5
 #endif
6
 
7
+#ifdef __FreeBSD__
8
+#define TITLE "Snes9x: FreeBSD"
9
+#define SYS_CONFIG_FILE "%%PREFIX%%/etc/snes9x/snes9x.conf"
10
+#endif
11
+
12
 #ifndef TITLE
13
 #define TITLE "Snes9x"
14
 #endif
(-)snes9x/files/patch-snes9x.cpp (+31 lines)
Line 0 Link Here
1
--- snes9x.cpp.orig	2011-04-24 17:38:10.000000000 +0400
2
+++ snes9x.cpp	2012-11-30 02:51:24.000000000 +0400
3
@@ -199,6 +199,7 @@
4
 #endif
5
 
6
 #define S9X_CONF_FILE_NAME	"snes9x.conf"
7
+#define S9X_CONF_FILE_LOC		".config/snes9x"
8
 
9
 static char	*rom_filename = NULL;
10
 
11
@@ -346,13 +347,18 @@
12
 
13
 	if (!skip)
14
 	{
15
+		std::string	fname;
16
+		
17
+		fname = S9xGetDirectory(HOME_DIR);
18
+		fname += SLASH_STR S9X_CONF_FILE_LOC;
19
+		fname += SLASH_STR S9X_CONF_FILE_NAME;
20
+		try_load_config_file(fname.c_str(), conf);
21
+		
22
 	#ifdef SYS_CONFIG_FILE
23
 		try_load_config_file(SYS_CONFIG_FILE, conf);
24
 		S9xParsePortConfig(conf, 0);
25
 	#endif
26
 
27
-		std::string	fname;
28
-
29
 		fname = S9xGetDirectory(DEFAULT_DIR);
30
 		fname += SLASH_STR S9X_CONF_FILE_NAME;
31
 		try_load_config_file(fname.c_str(), conf);
(-)snes9x/files/patch-unix-configure (+10 lines)
Line 0 Link Here
1
--- unix/configure.orig	2011-04-24 17:38:10.000000000 +0400
2
+++ unix/configure	2012-11-30 04:12:07.000000000 +0400
3
@@ -4520,6 +4520,7 @@
4
 if test "x$enable_gamepad" = "xyes"; then
5
 	if test "x$snes9x_cv_linux_os" = "xyes"; then
6
 		S9XDEFS="$S9XDEFS -DJOYSTICK_SUPPORT"
7
+		S9XLIBS="$S9XLIBS -lusbhid"
8
 	else
9
 		{ echo "$as_me:$LINENO: WARNING: Your OS is not Linux. Build without gamepad support." >&5
10
 echo "$as_me: WARNING: Your OS is not Linux. Build without gamepad support." >&2;}
(-)snes9x/files/patch-unix-unix.cpp (+331 lines)
Line 0 Link Here
1
--- unix/unix.cpp.orig	2011-04-24 17:38:10.000000000 +0400
2
+++ unix/unix.cpp	2012-11-30 03:24:29.000000000 +0400
3
@@ -202,7 +202,12 @@
4
 #include <sys/mman.h>
5
 #endif
6
 #ifdef JOYSTICK_SUPPORT
7
-#include <linux/joystick.h>
8
+//#include <linux/joystick.h>
9
+#endif
10
+
11
+#ifdef __FreeBSD__
12
+typedef sig_t SIG_PF;
13
+#include <err.h>
14
 #endif
15
 
16
 #include "snes9x.h"
17
@@ -242,7 +247,11 @@
18
 static volatile bool8	block_signal         = FALSE;
19
 static volatile bool8	block_generate_sound = FALSE;
20
 
21
+#ifdef __FreeBSD__
22
+static const char *sound_device = "/dev/dsp";
23
+#else
24
 static const char	*sound_device = NULL;
25
+#endif
26
 
27
 static const char	*s9x_base_dir        = NULL,
28
 					*rom_filename        = NULL,
29
@@ -301,8 +310,65 @@
30
 
31
 #ifdef JOYSTICK_SUPPORT
32
 static uint8		js_mod[8]     = { 0, 0, 0, 0, 0, 0, 0, 0 };
33
-static int			js_fd[8]      = { -1, -1, -1, -1, -1, -1, -1, -1 };
34
-static const char	*js_device[8] = { "/dev/js0", "/dev/js1", "/dev/js2", "/dev/js3", "/dev/js4", "/dev/js5", "/dev/js6", "/dev/js7" };
35
+#define        JOYSTICK_MAX_DEVICES    4
36
+int JoystickShift = 0;
37
+static const char	*js_device[4] = { "/dev/uhid0", "/dev/uhid1", "/dev/uhid2", "/dev/uhid3" };
38
+#if defined(__FreeBSD__)
39
+#include <sys/types.h>
40
+#include <sys/param.h>
41
+
42
+extern "C" {
43
+#define class klass
44
+#include <dev/usb/usb.h>
45
+#include <dev/usb/usbhid.h>   
46
+#undef class
47
+
48
+#include <usbhid.h>
49
+}
50
+
51
+#define        JOYSTICK_MAX_BUTTONS    16
52
+
53
+#define JOYSTICK_MAP_BUTTON_INITIALIZER	                \
54
+	{                                                     \
55
+		SNES_Y_MASK, SNES_B_MASK, SNES_A_MASK,              \
56
+		SNES_X_MASK, SNES_TL_MASK, SNES_TR_MASK,            \
57
+		SNES_TL_MASK, SNES_TR_MASK,                         \
58
+		SNES_SELECT_MASK, SNES_START_MASK, 0, 0, 0, 0, 0, 0	\
59
+	}
60
+
61
+int js_map_button[JOYSTICK_MAX_BUTTONS][16] = {
62
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
63
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
64
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
65
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
66
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
67
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
68
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
69
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
70
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
71
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
72
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
73
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
74
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
75
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
76
+	JOYSTICK_MAP_BUTTON_INITIALIZER,
77
+	JOYSTICK_MAP_BUTTON_INITIALIZER
78
+};
79
+struct js_range {
80
+	int min, max, lower_third, higher_third;
81
+};
82
+struct js_info {
83
+	char *buf;
84
+	int reportlen;
85
+	int offset;
86
+	struct js_range x, y;
87
+	int buttons;
88
+	struct hid_item *hids;
89
+	int fd;
90
+	int joy;
91
+} js_info[4];
92
+int js_count = 0;
93
+#endif
94
 #endif
95
 
96
 #ifdef NETPLAY_SUPPORT
97
@@ -464,15 +530,44 @@
98
 	if (!strcasecmp(argv[i], "-nogamepad"))
99
 		unixSettings.JoystickEnabled = FALSE;
100
 	else
101
-	if (!strncasecmp(argv[i], "-paddev", 7) &&
102
-		argv[i][7] >= '1' && argv[i][7] <= '8' && argv[i][8] == '\0')
103
-	{
104
-		int	j = argv[i][7] - '1';
105
+#ifdef __FreeBSD__
106
+	if (strcasecmp(argv[i], "-joyshift") == 0)
107
+		JoystickShift = 1;
108
+	else
109
+#endif
110
+	if (strncasecmp(argv[i], "-paddev", sizeof("-paddev") - 1) == 0) {
111
+		char *end, *snum = argv[i] + sizeof("-paddev") - 1;
112
+		unsigned long num;
113
 
114
-		if (i + 1 < argc)
115
-			js_device[j] = argv[++i];
116
+		if (*snum == '\0' || argc < i + 1)
117
+			S9xUsage();
118
+		if ((num = strtoul(snum, &end, 10)) < JOYSTICK_MAX_DEVICES &&
119
+				num > 0 && *end == '\0')
120
+			js_device[num - 1] = argv[++i];
121
 		else
122
+			S9xUsage ();
123
+	}
124
+	else if (strncasecmp(argv[i], "-joymap", sizeof("-joymap") - 1) == 0) {
125
+		static const int button_masks[] = {
126
+			SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK,
127
+			SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK
128
+		};
129
+		char *end, *snum = argv[i] + sizeof("-joymap") - 1;
130
+		unsigned long num;
131
+		int *js_buttons, b;
132
+
133
+		if (argc < i + (sizeof(button_masks) / sizeof(int)) || *snum == '\0')
134
+			S9xUsage();
135
+		num = strtoul(snum, &end, 10);
136
+		if (*end != '\0')
137
 			S9xUsage();
138
+		if (num == 0 || num > 4)        /* hardcode: max joysticks */
139
+			S9xUsage();
140
+		js_buttons = js_map_button[num - 1];
141
+		for (b = 0; b < (sizeof(button_masks) / sizeof(int)); b++)
142
+			if ((num = strtoul(argv[++i], &end, 10)) <= 16 && num != 0 &&
143
+					end == '\0')
144
+				js_buttons[num - 1] = button_masks[b];
145
 	}
146
 	else
147
 #endif
148
@@ -1261,7 +1356,7 @@
149
 }
150
 
151
 #ifdef JOYSTICK_SUPPORT
152
-
153
+#ifdef __linux
154
 static void InitJoysticks (void)
155
 {
156
 #ifdef JSIOCGVERSION
157
@@ -1347,7 +1442,174 @@
158
 	}
159
 #endif
160
 }
161
+#endif
162
+#ifdef __FreeBSD__
163
+
164
+/*
165
+	* USB HID code for FreeBSD/NetBSD
166
+	* Brian Feldman <green@FreeBSD.org>
167
+	*
168
+	* Reference used:
169
+	* X-Mame USB HID joystick driver for NetBSD.
170
+	*
171
+	* Written by Krister Walfridsson <cato@df.lth.se>
172
+	*/
173
+
174
+int
175
+InitJoystickFd(int fd, const char *dev) {
176
+	report_desc_t rd;
177
+	struct hid_data *d;
178
+	struct hid_item h, new_h;
179
+	struct js_info *my_info;
180
+	int reportlen, report_id, is_joystick;
181
+
182
+	my_info = &js_info[js_count];
183
+	rd = hid_get_report_desc(fd);
184
+	if (rd == 0) {
185
+		warn("%s", dev);
186
+		return (-1);
187
+	}
188
+	report_id = 0;
189
+	reportlen = hid_report_size(rd, hid_input, report_id);
190
+	my_info->buf = (char *)malloc(reportlen);
191
+	if (my_info->buf == NULL)
192
+		err(1, "malloc");
193
+	my_info->reportlen = reportlen;
194
+	my_info->offset = report_id != 0;
195
+	my_info->buttons = 0;
196
+	my_info->hids = NULL;
197
+	is_joystick = 0;
198
+	for (d = hid_start_parse(rd, 1 << hid_input, report_id); hid_get_item(d, &h);) {
199
+		int usage, page, link_it = 0;
200
+		struct js_range *axis;
201
+
202
+		page = HID_PAGE(h.usage);
203
+		usage = HID_USAGE(h.usage);
204
+		if (!is_joystick)
205
+			is_joystick = (h.kind == hid_collection &&
206
+				page == HUP_GENERIC_DESKTOP &&
207
+				(usage == HUG_JOYSTICK || usage == HUG_GAME_PAD));
208
+		if (h.kind != hid_input || !is_joystick)
209
+			continue;
210
+		axis = NULL;
211
+		if (page == HUP_GENERIC_DESKTOP) {
212
+			switch (usage) {
213
+				case HUG_X:
214
+				case HUG_RX:
215
+					axis = &my_info->x;
216
+					break;
217
+				case HUG_Y:
218
+				case HUG_RY:
219
+					axis = &my_info->y;
220
+					break;
221
+			}
222
+		}
223
+		if (axis != NULL) {
224
+			axis->min = h.logical_minimum;
225
+			axis->max = h.logical_maximum;
226
+			axis->lower_third = axis->min + (axis->max - axis->min) / 3;
227
+			axis->higher_third = axis->min + (axis->max - axis->min) * 2 / 3;
228
+			link_it = 1;
229
+		}
230
+		if (!link_it) {
231
+			if (page != HUP_BUTTON || usage > 16)
232
+				continue;
233
+			if (usage > my_info->buttons)
234
+				my_info->buttons = usage;
235
+		}
236
+		new_h = h;
237
+		new_h.next = my_info->hids;
238
+		my_info->hids = (struct hid_item *) malloc(sizeof(*my_info->hids));
239
+		if (my_info->hids == NULL)
240
+			err(1, "malloc");
241
+		*my_info->hids = new_h;
242
+	}
243
+	printf("Joystick %s: %d buttons, X range %d - %d, Y range %d - %d\n",
244
+				dev, my_info->buttons, my_info->x.min, my_info->x.max,
245
+				my_info->y.min, my_info->y.max);
246
+	my_info->fd = fd;
247
+	if (JoystickShift) {
248
+		my_info->joy = js_count + 1;
249
+	} else
250
+		my_info->joy = js_count;
251
+	return (0);
252
+}
253
+
254
+static void InitJoysticks() {
255
+	int i, fd;
256
+
257
+	for (i = 0; i < (sizeof(js_device) / sizeof(js_device[0])); i++) {
258
+		fd = open(js_device[i], O_RDONLY | O_NONBLOCK);
259
+		if (fd == -1)
260
+			continue;
261
+		if (InitJoystickFd(fd, js_device[i]) == 0)
262
+			js_count++;
263
+		else
264
+			close(fd);
265
+	}
266
+}
267
+
268
+static void ReadJoysticks() {
269
+	struct hid_item *h;
270
+	int page, usage, njoy, joy;
271
+
272
+	for (njoy = 0; njoy < js_count; njoy++) {
273
+		struct js_info *jsi;
274
 
275
+		jsi = &js_info[njoy];
276
+		joy = jsi->joy;
277
+		
278
+		if (read(jsi->fd, jsi->buf, jsi->reportlen) != jsi->reportlen)
279
+			continue;
280
+		for (h = jsi->hids; h != NULL; h = h->next) {
281
+			int d;
282
+		
283
+			d = hid_get_data(jsi->buf + jsi->offset, h);
284
+			page = HID_PAGE(h->usage);
285
+			usage = HID_USAGE(h->usage);
286
+		
287
+			switch (page) {
288
+				case HUP_GENERIC_DESKTOP:
289
+					switch (usage) {
290
+						case HUG_X:
291
+						case HUG_RX:
292
+							if (d < jsi->x.lower_third) {
293
+								joypads[joy] |= SNES_LEFT_MASK;
294
+								joypads[joy] &= ~SNES_RIGHT_MASK;
295
+							} else if (d < jsi->x.higher_third) {
296
+								joypads[joy] &= ~SNES_LEFT_MASK;
297
+								joypads[joy] &= ~SNES_RIGHT_MASK;
298
+							} else {
299
+								joypads[joy] &= ~SNES_LEFT_MASK;
300
+								joypads[joy] |= SNES_RIGHT_MASK;
301
+							}
302
+							break;
303
+						case HUG_Y:
304
+						case HUG_RY:
305
+							if (d < jsi->y.lower_third) {
306
+								joypads[joy] |= SNES_UP_MASK;
307
+								joypads[joy] &= ~SNES_DOWN_MASK;
308
+							} else if (d < jsi->y.higher_third) {
309
+								joypads[joy] &= ~SNES_UP_MASK;
310
+								joypads[joy] &= ~SNES_DOWN_MASK;
311
+							} else {
312
+								joypads[joy] &= ~SNES_UP_MASK;
313
+								joypads[joy] |= SNES_DOWN_MASK;
314
+							}
315
+							break;
316
+					}
317
+					break;
318
+				case HUP_BUTTON:
319
+					if (d)
320
+						joypads[joy] |= js_map_button[njoy][usage - 1];
321
+					else
322
+						joypads[joy] &= ~js_map_button[njoy][usage - 1];
323
+					break;
324
+			}
325
+		}
326
+	}
327
+}
328
+#endif // defined(__FreeBSD__)
329
 #endif
330
 
331
 static void SoundTrigger (void)
(-)snes9x/files/patch-unzip-unzip.h (+34 lines)
Line 0 Link Here
1
--- unzip/unzip.h.orig	2011-04-24 17:38:10.000000000 +0400
2
+++ unzip/unzip.h	2012-11-30 03:04:33.000000000 +0400
3
@@ -45,12 +45,10 @@
4
 #ifndef _unz_H
5
 #define _unz_H
6
 
7
-#ifdef __cplusplus
8
-extern "C" {
9
-#endif
10
+#include <sys/types.h>
11
 
12
 #ifndef _ZLIB_H
13
-#include "zlib.h"
14
+#include <zlib.h>
15
 #endif
16
 
17
 #ifndef _ZLIBIOAPI_H
18
@@ -58,9 +56,15 @@
19
 #endif
20
 
21
 #ifdef HAVE_BZIP2
22
-#include "bzlib.h"
23
+#include <bzlib.h>
24
+#endif
25
+
26
+#ifdef __cplusplus
27
+extern "C" {
28
 #endif
29
 
30
+#define ZEXPORT
31
+
32
 #define Z_BZIP2ED 12
33
 
34
 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
(-)snes9x/files/pkg-message.in (-6 / +6 lines)
Lines 4-10 Link Here
4
4
5
1) You can run the emulator using:
5
1) You can run the emulator using:
6
6
7
   # (o)snes9x -y2 -ts /path/to/rom_file
7
   # snes9x -v6 /path/to/rom_file
8
8
9
2) You can see all options that you can use with snes9x at:
9
2) You can see all options that you can use with snes9x at:
10
10
Lines 12-26 Link Here
12
12
13
   or only typing:
13
   or only typing:
14
  
14
  
15
   # (o)snes9x
15
   # snes9x
16
16
17
3) Also you can define a config file, see an example at:
17
3) Also you can define a config file in
18
18
19
   %%DOCSDIR%%/snes9x.conf.default
19
${HOME}/.config/snes9x/snes9x.conf or
20
20
21
   and you can select this config file using:
21
${PREFIX}/etc/snes9x/snes9x.conf (default conf file)
22
22
23
   # (o)snes9x -conf /path/to/conf_file 
23
Example in ${DOCSDIR}/snes9x.conf.default
24
24
25
4) Enjoy it ;)
25
4) Enjoy it ;)

Return to bug 174017