From d0b0fc8126dedcdfabbed76c5c97fa12523fa8fe Mon Sep 17 00:00:00 2001 From: kristerw Date: Sun, 14 Jul 2002 07:44:43 +0000 Subject: Add USB joystick support (and bump version to 1.39nb1) using (somewhat modified) patches provided by Rui-Xiang Guo in PR 15566. --- emulators/snes9x/Makefile | 10 +- emulators/snes9x/distinfo | 7 +- emulators/snes9x/patches/patch-aa | 36 ++++-- emulators/snes9x/patches/patch-ag | 253 ++++++++++++++++++++++++++++++++++++-- emulators/snes9x/patches/patch-aj | 13 ++ 5 files changed, 298 insertions(+), 21 deletions(-) create mode 100644 emulators/snes9x/patches/patch-aj (limited to 'emulators') diff --git a/emulators/snes9x/Makefile b/emulators/snes9x/Makefile index ee92a34f89f..991a353b11c 100644 --- a/emulators/snes9x/Makefile +++ b/emulators/snes9x/Makefile @@ -1,7 +1,8 @@ -# $NetBSD: Makefile,v 1.9 2002/07/08 01:04:09 kristerw Exp $ +# $NetBSD: Makefile,v 1.10 2002/07/14 07:44:43 kristerw Exp $ DISTNAME= s9xs139 PKGNAME= snes9x-1.39 +PKGREVISION= 1 WRKSRC= ${WRKDIR}/release CATEGORIES= emulators MASTER_SITES= http://www.snes9x.com/zips/ @@ -53,5 +54,12 @@ MAKE_ENV+= ASMKREED=1 MAKE_ENV+= NETBSD_USE_DGA=1 .endif +.if exists(/usr/include/usb.h) || exists(/usr/include/usbhid.h) +MAKE_ENV+= USBJOY=1 +.if exists(/usr/include/usbhid.h) +MAKE_ENV+= USBHID_H=1 +.endif +.endif + .include "../../mk/pthread.buildlink.mk" .include "../../mk/bsd.pkg.mk" diff --git a/emulators/snes9x/distinfo b/emulators/snes9x/distinfo index 745efcbcb9a..60d98387b2d 100644 --- a/emulators/snes9x/distinfo +++ b/emulators/snes9x/distinfo @@ -1,13 +1,14 @@ -$NetBSD: distinfo,v 1.5 2002/07/08 01:04:09 kristerw Exp $ +$NetBSD: distinfo,v 1.6 2002/07/14 07:44:44 kristerw Exp $ SHA1 (s9xs139.zip) = 15acf6d8a31dc51b26a42abf747cec1b72c2aa29 Size (s9xs139.zip) = 666463 bytes -SHA1 (patch-aa) = 5edce58bf67f994d4f4f03519f1f2da3bf060ffe +SHA1 (patch-aa) = 2443c745cbf309690c8e9770dc7c376ac3b1e186 SHA1 (patch-ab) = b99893934074d8693a9609d49e49953ade2b2062 SHA1 (patch-ac) = e54f4fff397dd4ca3be28711fd23c4fbef57ed54 SHA1 (patch-ad) = 72cc9904c74e0668cce450fcada24453aec344e4 SHA1 (patch-ae) = cb2ed8dc3ad409ffb88cb9851b04c6c42c3b2b0e SHA1 (patch-af) = 302967c91a1e0b384c4990687fb11bf236202783 -SHA1 (patch-ag) = 559464862e883b9d8b65a4c0c68d238e1dcdf5af +SHA1 (patch-ag) = 74c74739f4f0f22b76594ba379939df8cfc52188 SHA1 (patch-ah) = 60bd35e51faca36fbd8d8d6354487554af17fe7a SHA1 (patch-ai) = 2f522a560577aff89af9efa7a6b129faa99670fd +SHA1 (patch-aj) = 71f228195be1381f52b1fe875506abde54fd8396 diff --git a/emulators/snes9x/patches/patch-aa b/emulators/snes9x/patches/patch-aa index 711c20d7119..e28959907f4 100644 --- a/emulators/snes9x/patches/patch-aa +++ b/emulators/snes9x/patches/patch-aa @@ -1,6 +1,6 @@ -$NetBSD: patch-aa,v 1.6 2002/07/08 01:04:09 kristerw Exp $ +$NetBSD: patch-aa,v 1.7 2002/07/14 07:44:44 kristerw Exp $ --- Makefile.orig Tue Sep 18 08:03:58 2001 -+++ Makefile Mon Jul 8 02:32:48 2002 ++++ Makefile Sat Jul 13 22:15:09 2002 @@ -1,14 +1,14 @@ -ZSNESFX=1 -ZSNESC4=1 @@ -32,7 +32,24 @@ $NetBSD: patch-aa,v 1.6 2002/07/08 01:04:09 kristerw Exp $ ifdef SPC700ASM SOUNDOBJ=spctool/spc700.o spctool/dsp.o spctool.o spctool/soundmod.o spc.o -@@ -81,9 +84,10 @@ +@@ -58,6 +61,16 @@ + KREEDOBJ=2xsai.o + endif + ++ifdef USBJOY ++ifdef USBHID_H ++USBJOYDEFINES=-DJOYSTICK_SUPPORT -DHAVE_USBHID_H ++EXTRALIBS+=-lusbhid ++else ++USBJOYDEFINES=-DJOYSTICK_SUPPORT ++EXTRALIBS+=-lusb ++endif ++endif ++ + OBJECTS=$(CPUOBJ) $(SOUNDOBJ) apudebug.o $(FXOBJ) $(C4OBJ) \ + cpu.o sa1.o debug.o sdd1.o tile.o srtc.o \ + gfx.o memmap.o snaporig.o clip.o dsp1.o \ +@@ -81,9 +94,10 @@ UNZIPDEFINES=-DUNZIP_SUPPORT endif @@ -45,7 +62,7 @@ $NetBSD: patch-aa,v 1.6 2002/07/08 01:04:09 kristerw Exp $ endif ifdef GLIDE -@@ -113,9 +117,13 @@ +@@ -113,9 +127,13 @@ CC = gcc NASM = nasm @@ -60,7 +77,7 @@ $NetBSD: patch-aa,v 1.6 2002/07/08 01:04:09 kristerw Exp $ #OPTIMISE=-g -fno-exceptions #-DMITSHM -@@ -124,10 +132,8 @@ +@@ -124,10 +142,8 @@ -Ii386 \ -I. \ -Iunzip \ @@ -71,15 +88,16 @@ $NetBSD: patch-aa,v 1.6 2002/07/08 01:04:09 kristerw Exp $ -DCPU_SHUTDOWN \ -DSPC700_SHUTDOWN \ -DOLD_COLOUR_BLENDING \ -@@ -142,7 +148,6 @@ +@@ -142,7 +158,7 @@ $(OPENGLDEFINES) \ $(GUIDEFINES) \ $(KREEDDEFINES) \ --DNO_INLINE_SET_GET ++$(USBJOYDEFINES) #-DSOUND #-DDEBUGGER -@@ -154,9 +159,9 @@ +@@ -154,9 +170,9 @@ CFLAGS=$(CCFLAGS) .SUFFIXES: .o .cpp .c .cc .h .m .i .S .asm .obj @@ -91,7 +109,7 @@ $NetBSD: patch-aa,v 1.6 2002/07/08 01:04:09 kristerw Exp $ #ggisnes9x #xf86snes9x -@@ -182,7 +187,7 @@ +@@ -182,7 +198,7 @@ ./offsets >i386/offsets.h snes9x: $(OBJECTS) unix/x11.o $(GLIDEOBJS) $(OPENGLOBJS) $(GUIOBJS) $(KREEDOBJ) @@ -100,7 +118,7 @@ $NetBSD: patch-aa,v 1.6 2002/07/08 01:04:09 kristerw Exp $ ssnes9x: $(OBJECTS) unix/svga.o $(GLIDEOBJS) $(CCC) $(INCLUDES) -o $@ $(OBJECTS) $(GLIDEOBJS) unix/svga.o $(LDLIBS) $(GLIDELIBS) -lvga -lvgagl -lz $(EXTRALIBS) -lm -@@ -212,7 +217,7 @@ +@@ -212,7 +228,7 @@ $(CCC) $(INCLUDES) -c -E $(CCFLAGS) $*.S -o $@ .asm.o: diff --git a/emulators/snes9x/patches/patch-ag b/emulators/snes9x/patches/patch-ag index e784b2b6f71..0d8c77ffe1d 100644 --- a/emulators/snes9x/patches/patch-ag +++ b/emulators/snes9x/patches/patch-ag @@ -1,6 +1,6 @@ -$NetBSD: patch-ag,v 1.3 2002/07/08 01:04:10 kristerw Exp $ ---- unix/unix.cpp.orig Mon Jul 8 00:54:28 2002 -+++ unix/unix.cpp Mon Jul 8 02:45:13 2002 +$NetBSD: patch-ag,v 1.4 2002/07/14 07:44:44 kristerw Exp $ +--- unix/unix.cpp.orig Tue Sep 18 08:03:40 2001 ++++ unix/unix.cpp Sun Jul 14 04:09:32 2002 @@ -51,7 +51,7 @@ #include #include @@ -42,7 +42,59 @@ $NetBSD: patch-ag,v 1.3 2002/07/08 01:04:10 kristerw Exp $ #include "snes9x.h" #include "memmap.h" -@@ -168,7 +178,7 @@ +@@ -111,6 +121,51 @@ + int NumControllers = 5; + + #ifdef JOYSTICK_SUPPORT ++#ifdef __NetBSD__ ++#ifdef HAVE_USBHID_H ++#include ++#else ++#include ++#endif ++#define class Class ++#include ++#include ++ ++struct priv_joydata_struct ++{ ++ struct hid_item *hids; ++ int dlen; ++ int offset; ++ char *data_buf; ++} priv_joy_data[4]; ++ ++int js_fd [4] = {-1, -1, -1, -1}; ++int js_map_button [4][16] = { ++ { ++ SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK, ++ SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK, ++ 0, 0, 0, 0, 0, 0, 0, 0 ++ }, ++ { ++ SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK, ++ SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK, ++ 0, 0, 0, 0, 0, 0, 0, 0 ++ }, ++ { ++ SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK, ++ SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK, ++ 0, 0, 0, 0, 0, 0, 0, 0 ++ }, ++ { ++ SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK, ++ SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK, ++ 0, 0, 0, 0, 0, 0, 0, 0 ++ } ++}; ++ ++char *js_device [4] = {"/dev/uhid0", "/dev/uhid1", "/dev/uhid2", "/dev/uhid3"}; ++ ++#endif + #ifdef __linux + #include + int js_fd [4] = {-1, -1, -1, -1}; +@@ -168,7 +223,7 @@ char *rom_filename = NULL; char *snapshot_filename = NULL; @@ -51,7 +103,192 @@ $NetBSD: patch-ag,v 1.3 2002/07/08 01:04:10 kristerw Exp $ static void sigbrkhandler(int) { #ifdef DEBUGGER -@@ -1422,7 +1432,7 @@ +@@ -612,6 +667,106 @@ + #ifdef JOYSTICK_SUPPORT + void InitJoysticks () + { ++#ifdef __NetBSD__ ++ int i, size, is_joystick, report_id = 0; ++ struct hid_data *d; ++ struct hid_item h; ++ report_desc_t rd; ++ ++ printf("USB joystick interface initialization...\n"); ++ ++ for (i = 0; i < 4; i++) ++ { ++ if ((js_fd [i] = open (js_device [i], O_RDONLY | O_NONBLOCK)) != -1) ++ { ++ if ((rd = hid_get_report_desc(js_fd [i])) == 0) ++ { ++ perror (js_device [i]); ++ close (js_fd [i]); ++ } ++ ++ priv_joy_data[i].hids = NULL; ++ ++#ifdef HAVE_USBHID_H ++ if (ioctl(js_fd [i], USB_GET_REPORT_ID, &report_id) < 0) ++ { ++ perror (js_device [i]); ++ close (js_fd [i]); ++ } ++ ++ size = hid_report_size(rd, hid_input, report_id); ++ priv_joy_data[i].offset = 0; ++#else ++ size = hid_report_size(rd, hid_input, &report_id); ++ priv_joy_data[i].offset = (report_id != 0); ++#endif ++ if ((priv_joy_data[i].data_buf = malloc(size)) == NULL) ++ { ++ printf("error: couldn't malloc %d bytes\n", size); ++ hid_dispose_report_desc(rd); ++ } ++ priv_joy_data[i].dlen = size; ++ ++ is_joystick = 0; ++#ifdef HAVE_USBHID_H ++ for (d = hid_start_parse(rd, 1 << hid_input, report_id); hid_get_item(d, &h); ) ++#else ++ for (d = hid_start_parse(rd, 1 << hid_input); hid_get_item(d, &h); ) ++#endif ++ { ++ int axes = 0, buttons = 0, usage, page, interesting_hid; ++ ++ page = HID_PAGE(h.usage); ++ usage = HID_USAGE(h.usage); ++ ++ is_joystick = is_joystick || ++ (h.kind == hid_collection && ++ page == HUP_GENERIC_DESKTOP && ++ (usage == HUG_JOYSTICK || usage == HUG_GAME_PAD)); ++ ++ if (h.kind != hid_input) ++ continue; ++ ++ if (!is_joystick) ++ continue; ++ ++ interesting_hid = TRUE; ++ if (page == HUP_GENERIC_DESKTOP) ++ { ++ if (usage == HUG_X || usage == HUG_RX) ++ axes = 1; ++ else if (usage == HUG_Y || usage == HUG_RY) ++ axes = 2; ++ else if (usage == HUG_Z || usage == HUG_RZ) ++ axes = 3; ++ else ++ interesting_hid = FALSE; ++ } ++ else if (page == HUP_BUTTON) ++ { ++ if (usage > 0) ++ buttons = usage; ++ else ++ interesting_hid = FALSE; ++ ++ } ++ ++ if (interesting_hid) ++ { ++ h.next = priv_joy_data[i].hids; ++ priv_joy_data[i].hids = malloc(sizeof *(priv_joy_data[i].hids)); ++ if (priv_joy_data[i].hids == NULL) ++ { ++ printf("error: Not enough memory for joystick.\n"); ++ break; ++ } ++ *(priv_joy_data[i].hids) = h; ++ } ++ } ++ hid_end_parse(d); ++ } ++ } ++#endif + #ifdef JSIOCGVERSION + int version; + unsigned char axes, buttons; +@@ -664,6 +819,77 @@ + + void ReadJoysticks () + { ++#ifdef __NetBSD__ ++ int i, usage, page, d; ++ struct hid_item *h; ++ ++ for (i = 0; i < 4 && js_fd [i] >= 0; i++) ++ { ++ int len; ++ ++ len = read(js_fd [i], priv_joy_data[i].data_buf, priv_joy_data[i].dlen); ++ if (len < priv_joy_data[i].dlen) ++ continue; ++ ++ for (h = priv_joy_data[i].hids; h; h = h->next) ++ { ++ d = hid_get_data(priv_joy_data[i].data_buf + priv_joy_data[i].offset, h); ++ ++ page = HID_PAGE(h->usage); ++ usage = HID_USAGE(h->usage); ++ ++ if (page == HUP_GENERIC_DESKTOP) ++ { ++ int center, trigger_point; ++ ++ center = (h->logical_maximum + h->logical_minimum) / 2; ++ trigger_point = (h->logical_maximum - h->logical_minimum) / 4; ++ ++ if (usage == HUG_X || usage == HUG_RX) ++ { ++ if (d < (center - trigger_point)) ++ { ++ joypads [i] |= SNES_LEFT_MASK; ++ joypads [i] &= ~SNES_RIGHT_MASK; ++ continue; ++ } ++ if (d > (center + trigger_point)) ++ { ++ joypads [i] &= ~SNES_LEFT_MASK; ++ joypads [i] |= SNES_RIGHT_MASK; ++ continue; ++ } ++ joypads [i] &= ~SNES_LEFT_MASK; ++ joypads [i] &= ~SNES_RIGHT_MASK; ++ } ++ if (usage == HUG_Y || usage == HUG_RY) ++ { ++ if (d < (center - trigger_point)) ++ { ++ joypads [i] |= SNES_UP_MASK; ++ joypads [i] &= ~SNES_DOWN_MASK; ++ continue; ++ } ++ if (d > (center + trigger_point)) ++ { ++ joypads [i] &= ~SNES_UP_MASK; ++ joypads [i] |= SNES_DOWN_MASK; ++ continue; ++ } ++ joypads [i] &= ~SNES_UP_MASK; ++ joypads [i] &= ~SNES_DOWN_MASK; ++ } ++ } ++ else if (page == HUP_BUTTON) ++ { ++ if (d == h->logical_maximum) ++ joypads [i] |= js_map_button [i][usage - 1]; ++ else ++ joypads [i] &= ~js_map_button [i][usage - 1]; ++ } ++ } ++ } ++#endif + #ifdef JSIOCGVERSION + struct js_event js_ev; + int i; +@@ -1422,7 +1648,7 @@ } #endif @@ -60,7 +297,7 @@ $NetBSD: patch-ag,v 1.3 2002/07/08 01:04:10 kristerw Exp $ static int Rates[8] = { 0, 8192, 11025, 16500, 22050, 29300, 36600, 44000 -@@ -1437,11 +1447,19 @@ +@@ -1437,11 +1663,19 @@ { int J, K; @@ -80,7 +317,7 @@ $NetBSD: patch-ag,v 1.3 2002/07/08 01:04:10 kristerw Exp $ #ifdef MMAP_SOUND if (ioctl (so.sound_fd, SNDCTL_DSP_GETCAPS, &J) < 0) -@@ -1541,7 +1559,7 @@ +@@ -1541,7 +1775,7 @@ } #endif @@ -89,7 +326,7 @@ $NetBSD: patch-ag,v 1.3 2002/07/08 01:04:10 kristerw Exp $ void S9xUnixProcessSound (void) { } -@@ -1640,7 +1658,7 @@ +@@ -1640,7 +1874,7 @@ void *S9xProcessSound (void *) { diff --git a/emulators/snes9x/patches/patch-aj b/emulators/snes9x/patches/patch-aj new file mode 100644 index 00000000000..58935358c51 --- /dev/null +++ b/emulators/snes9x/patches/patch-aj @@ -0,0 +1,13 @@ +$NetBSD: patch-aj,v 1.1 2002/07/14 07:44:44 kristerw Exp $ +--- snes9x.cpp.orig Sat Jul 13 22:00:14 2002 ++++ snes9x.cpp Sat Jul 13 22:04:07 2002 +@@ -141,6 +141,9 @@ + -joydevX /dev/jsY Use joystick device /dev/jsY for emulation of gamepad X\n"); + S9xMessage (S9X_INFO, S9X_USAGE, "\ + -joymapX 0 1 2 3 4 5 6 7 Joystick buttons which should be assigned to gamepad X - A B X Y TL TR Start and Select\n"); ++#elif defined(__NetBSD__) ++ S9xMessage (S9X_INFO, S9X_USAGE, "\ ++-joymapX 0 1 2 3 4 5 6 7 Joystick buttons which should be assigned to gamepad X - A B X Y TL TR Start and Select\n"); + #else + S9xMessage (S9X_INFO, S9X_USAGE, "\ + -four or -4 Single standard PC joystick has four buttons\n"); -- cgit v1.2.3