changeset 1565:57431b199aed

Fixed bug #52 Integrated most of the NetBSD and DragonFly patches at: ftp://ftp.netbsd.org/pub/NetBSD/packages/pkgsrc/devel/SDL/patches/ Thanks to Thomas Klausner for defailed information on the patches
author Sam Lantinga <slouken@libsdl.org>
date Tue, 21 Mar 2006 08:54:50 +0000
parents 4950a25bd91e
children 5bc2a95f9dcf
files configure.in include/SDL_config.h.in include/SDL_platform.h src/audio/openbsd/SDL_openbsdaudio.c src/joystick/bsd/SDL_sysjoystick.c src/video/vgl/SDL_vglvideo.c
diffstat 6 files changed, 90 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Tue Mar 21 07:02:34 2006 +0000
+++ b/configure.in	Tue Mar 21 08:54:50 2006 +0000
@@ -50,10 +50,13 @@
 fi
 
 dnl Set up the compiler and linker flags
-INCLUDE="-I$srcdir/include"
+INCLUDE="-I$srcdir/include $INCLUDE"
 if test x$srcdir != x.; then
     INCLUDE="-Iinclude $INCLUDE"
 fi
+if test -d /usr/local/include; then
+    INCLUDE="$INCLUDE -I/usr/local/include"
+fi
 case "$host" in
     *-*-cygwin*)
         # We build SDL on cygwin without the UNIX emulation layer
@@ -284,7 +287,7 @@
             SOURCES="$SOURCES $srcdir/src/audio/dma/*.c"
             have_audio=yes
 
-            # OpenBSD needs linking with ossaudio emulation library
+            # We may need to link with ossaudio emulation library
             case "$host" in
                 *-*-openbsd*|*-*-netbsd*)
                     EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lossaudio";;
@@ -1499,7 +1502,7 @@
 # causes Carbon.p complaints?
 #            pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
             ;;
-        *-*-freebsd*)
+        *-*-freebsd*|*-*-dragonfly*)
             pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
             pthread_lib="-pthread"
             ;;
@@ -1761,14 +1764,17 @@
 CheckUSBHID()
 {
     if test x$enable_joystick = xyes; then
-        AC_CHECK_HEADER(usb.h, [USB_CFLAGS="-DHAVE_USB_H"])
-        AC_CHECK_HEADER(usbhid.h, [USB_CFLAGS="-DHAVE_USBHID_H"])
-        AC_CHECK_HEADER(libusb.h, [USB_CFLAGS="-DHAVE_LIBUSB_H"])
-        AC_CHECK_HEADER(libusbhid.h, [USB_CFLAGS="-DHAVE_LIBUSBHID_H"])
+        AC_CHECK_LIB(usbhid, hid_init, have_libusbhid=yes)
+        if test x$have_libusbhid = xyes; then
+            AC_CHECK_HEADER(usbhid.h, [USB_CFLAGS="-DHAVE_USBHID_H"])
+            AC_CHECK_HEADER(libusbhid.h, [USB_CFLAGS="-DHAVE_LIBUSBHID_H"])
+            USB_LIBS="$USB_LIBS -lusbhid"
+        else
+            AC_CHECK_HEADER(usb.h, [USB_CFLAGS="-DHAVE_USB_H"])
+            AC_CHECK_HEADER(libusb.h, [USB_CFLAGS="-DHAVE_LIBUSB_H"])
+            AC_CHECK_LIB(usb, hid_init, [USB_LIBS="$USB_LIBS -lusb"])
+        fi
             
-        AC_CHECK_LIB(usbhid, hid_init, [USB_LIBS="$USB_LIBS -lusbhid"])
-        AC_CHECK_LIB(usb, hid_init, [USB_LIBS="$USB_LIBS -lusb"])
-
         save_CFLAGS="$CFLAGS"
         CFLAGS="$CFLAGS $USB_CFLAGS"
 
@@ -1779,8 +1785,13 @@
           #if defined(HAVE_USB_H)
           #include <usb.h>
           #endif
-          #include <dev/usb/usb.h>
-          #include <dev/usb/usbhid.h>
+          #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>
           #elif defined(HAVE_LIBUSB_H)
@@ -1805,8 +1816,13 @@
               #if defined(HAVE_USB_H)
               #include <usb.h>
               #endif
-              #include <dev/usb/usb.h>
-              #include <dev/usb/usbhid.h>
+              #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>
               #elif defined(HAVE_LIBUSB_H)
@@ -1852,6 +1868,20 @@
             fi
             AC_MSG_RESULT($have_usbhid_new)
 
+            AC_MSG_CHECKING(for struct joystick in machine/joystick.h)
+            have_machine_joystick=no
+            AC_TRY_COMPILE([
+              #include <machine/joystick.h>
+            ],[
+              struct joystick t;
+            ],[
+            have_machine_joystick=yes
+            ])
+            if test x$have_machine_joystick = xyes; then
+                AC_DEFINE(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H)
+            fi
+            AC_MSG_RESULT($have_machine_joystick)
+
             AC_DEFINE(SDL_JOYSTICK_USBHID)
             SOURCES="$SOURCES $srcdir/src/joystick/bsd/*.c"
             EXTRA_CFLAGS="$EXTRA_CFLAGS $USB_CFLAGS"
@@ -1862,6 +1892,7 @@
     fi
 }
 
+
 dnl Check for clock_gettime()
 CheckClockGettime()
 {
@@ -1907,7 +1938,7 @@
             have_timers=yes
         fi
         ;;
-    *-*-linux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
+    *-*-linux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
         case "$host" in
             *-*-linux*)         ARCH=linux ;;
             *-*-kfreebsd*-gnu)  ARCH=kfreebsd-gnu ;;
@@ -1916,6 +1947,7 @@
             *-*-gnu*)           ARCH=gnu ;; # must be last of the gnu variants
             *-*-bsdi*)          ARCH=bsdi ;;
             *-*-freebsd*)       ARCH=freebsd ;;
+            *-*-dragonfly*)     ARCH=freebsd ;;
             *-*-netbsd*)        ARCH=netbsd ;;
             *-*-openbsd*)       ARCH=openbsd ;;
             *-*-sysv5*)         ARCH=sysv5 ;;
@@ -1961,12 +1993,12 @@
         # Set up files for the audio library
         if test x$enable_audio = xyes; then
           case $ARCH in
-            netbsd|sysv5|solaris|hpux)
+            sysv5|solaris|hpux)
                 AC_DEFINE(SDL_AUDIO_DRIVER_SUNAUDIO)
                 SOURCES="$SOURCES $srcdir/src/audio/sun/*.c"
                 have_audio=yes
             ;;
-            openbsd)
+            netbsd|openbsd)
                 AC_DEFINE(SDL_AUDIO_DRIVER_OPENBSD)
                 SOURCES="$SOURCES $srcdir/src/audio/openbsd/*.c"
                 have_audio=yes
@@ -2388,7 +2420,7 @@
 # Set runtime shared library paths as needed
 
 if test "x$enable_rpath" = "xyes"; then
-  if test $ARCH = linux -o $ARCH = freebsd -o $ARCH = bsdi -o $ARCH = irix; then
+  if test $ARCH = bsdi -o $ARCH = freebsd -o $ARCH = irix -o $ARCH = linux -o $ARCH = netbsd; then
     SDL_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib"
   fi
   if test $ARCH = solaris; then
--- a/include/SDL_config.h.in	Tue Mar 21 07:02:34 2006 +0000
+++ b/include/SDL_config.h.in	Tue Mar 21 08:54:50 2006 +0000
@@ -208,6 +208,7 @@
 #undef SDL_JOYSTICK_RISCOS
 #undef SDL_JOYSTICK_WINMM
 #undef SDL_JOYSTICK_USBHID
+#undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
 
 /* Enable various shared object loading systems */
 #undef SDL_LOADSO_BEOS
--- a/include/SDL_platform.h	Tue Mar 21 07:02:34 2006 +0000
+++ b/include/SDL_platform.h	Tue Mar 21 08:54:50 2006 +0000
@@ -45,7 +45,7 @@
 #undef __DREAMCAST__
 #define __DREAMCAST__	1
 #endif
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__DragonFly__)
 #undef __FREEBSD__
 #define __FREEBSD__	1
 #endif
--- a/src/audio/openbsd/SDL_openbsdaudio.c	Tue Mar 21 07:02:34 2006 +0000
+++ b/src/audio/openbsd/SDL_openbsdaudio.c	Tue Mar 21 08:54:50 2006 +0000
@@ -42,8 +42,12 @@
 #include "../SDL_audiodev_c.h"
 #include "SDL_openbsdaudio.h"
 
-/* The tag name used by OpenBSD audio */
+/* The tag name used by NetBSD/OpenBSD audio */
+#ifdef __NETBSD__
+#define OBSD_DRIVER_NAME         "netbsd"
+#else
 #define OBSD_DRIVER_NAME         "openbsd"
+#endif
 
 /* Open the audio device for playback, and don't block if busy */
 /* #define USE_BLOCKING_WRITES */
@@ -128,7 +132,11 @@
 }
 
 AudioBootStrap OPENBSD_AUDIO_bootstrap = {
+#ifdef __NETBSD__
+	OBSD_DRIVER_NAME, "Native NetBSD audio",
+#else
 	OBSD_DRIVER_NAME, "Native OpenBSD audio",
+#endif
 	Audio_Available, Audio_CreateDevice
 };
 
@@ -136,18 +144,6 @@
 static void
 OBSD_WaitAudio(_THIS)
 {
-	/* Check to see if the thread-parent process is still alive */
-	{ static int cnt = 0;
-		/* Note that this only works with thread implementations 
-		   that use a different process id for each thread.
-		*/
-		if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
-			if ( kill(parent, 0) < 0 ) {
-				this->enabled = 0;
-			}
-		}
-	}
-
 #ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
 	/* See if we need to use timed audio synchronization */
 	if ( frame_ticks ) {
@@ -384,6 +380,9 @@
     	spec->channels = 1;
     AUDIO_INITINFO(&info);
     info.play.sample_rate = spec->freq;
+    info.blocksize = spec->size;
+    info.hiwat = 5;
+    info.lowat = 3;
     (void)ioctl(audio_fd, AUDIO_SETINFO, &info);
     (void)ioctl(audio_fd, AUDIO_GETINFO, &info);
     spec->freq  = info.play.sample_rate;
--- a/src/joystick/bsd/SDL_sysjoystick.c	Tue Mar 21 07:02:34 2006 +0000
+++ b/src/joystick/bsd/SDL_sysjoystick.c	Tue Mar 21 08:54:50 2006 +0000
@@ -37,8 +37,13 @@
 #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>
@@ -49,11 +54,13 @@
 #endif
 
 #ifdef __FREEBSD__
+#ifndef __DragonFly__
 #include <osreldate.h>
+#endif
 #include <sys/joystick.h>
 #endif
 
-#if defined(__NETBSD__) || (defined(__OPENBSD__) && defined(__i386__))
+#if SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
 #include <machine/joystick.h>
 #endif
 
@@ -231,6 +238,7 @@
 	struct hid_data *hdata;
 	struct report *rep;
 	int fd;
+	int i;
 
 	fd = open(path, O_RDONLY);
 	if (fd == -1) {
@@ -297,6 +305,8 @@
 	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;
@@ -323,8 +333,7 @@
 			    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++;
 			    }
@@ -342,6 +351,9 @@
 		}
 	}
 	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. */
@@ -364,7 +376,7 @@
 	int nbutton, naxe = -1;
 	Sint32 v;
 
-#if defined(__FREEBSD__) || defined(__NETBSD__) || (defined(__OPENBSD__) && defined(__i386__))
+#if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
 	struct joystick gameport;
 	static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
  
@@ -413,7 +425,7 @@
 		}
 		return;
 	}
-#endif /* defined(__FREEBSD__) || defined(__NETBSD__) || defined(__OPENBSD__) */
+#endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
 	
 	rep = &joy->hwdata->inreport;
 
@@ -451,7 +463,8 @@
 			    } 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;
 			}
@@ -512,7 +525,9 @@
 {
 	int len;
 
-#ifdef __FREEBSD__
+#ifdef __DragonFly__
+	len = hid_report_size(rd, r->rid, repinfo[repind].kind);
+#elif __FREEBSD__
 # if (__FreeBSD_version >= 460000)
 #  if (__FreeBSD_version <= 500111)
 	len = hid_report_size(rd, r->rid, repinfo[repind].kind);
@@ -521,12 +536,12 @@
 #  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);
+	len = hid_report_size(rd, repinfo[repind].kind, r->rid);
 # else
-	len = hid_report_size(rd, repinfo[repind].kind, r->rid);
+	len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
 # endif
 #endif
 
--- a/src/video/vgl/SDL_vglvideo.c	Tue Mar 21 07:02:34 2006 +0000
+++ b/src/video/vgl/SDL_vglvideo.c	Tue Mar 21 08:54:50 2006 +0000
@@ -555,7 +555,7 @@
     case V_INFO_MM_VGAX:
       vminfop->Type = VIDBUF8X;
       break;
-#if defined(__FREEBSD__) && __FreeBSD_version >= 500000
+#if defined(__FREEBSD__) && (defined(__DragonFly__) || __FreeBSD_version >= 500000)
     case V_INFO_MM_DIRECT:
       vminfop->PixelBytes = minfo.vi_pixel_size;
       switch (vminfop->PixelBytes) {