Fixed bug #52
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 Mar 2006 08:54:50 +0000
changeset 156557431b199aed
parent 1564 4950a25bd91e
child 1566 5bc2a95f9dcf
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
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
     1.1 --- a/configure.in	Tue Mar 21 07:02:34 2006 +0000
     1.2 +++ b/configure.in	Tue Mar 21 08:54:50 2006 +0000
     1.3 @@ -50,10 +50,13 @@
     1.4  fi
     1.5  
     1.6  dnl Set up the compiler and linker flags
     1.7 -INCLUDE="-I$srcdir/include"
     1.8 +INCLUDE="-I$srcdir/include $INCLUDE"
     1.9  if test x$srcdir != x.; then
    1.10      INCLUDE="-Iinclude $INCLUDE"
    1.11  fi
    1.12 +if test -d /usr/local/include; then
    1.13 +    INCLUDE="$INCLUDE -I/usr/local/include"
    1.14 +fi
    1.15  case "$host" in
    1.16      *-*-cygwin*)
    1.17          # We build SDL on cygwin without the UNIX emulation layer
    1.18 @@ -284,7 +287,7 @@
    1.19              SOURCES="$SOURCES $srcdir/src/audio/dma/*.c"
    1.20              have_audio=yes
    1.21  
    1.22 -            # OpenBSD needs linking with ossaudio emulation library
    1.23 +            # We may need to link with ossaudio emulation library
    1.24              case "$host" in
    1.25                  *-*-openbsd*|*-*-netbsd*)
    1.26                      EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lossaudio";;
    1.27 @@ -1499,7 +1502,7 @@
    1.28  # causes Carbon.p complaints?
    1.29  #            pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
    1.30              ;;
    1.31 -        *-*-freebsd*)
    1.32 +        *-*-freebsd*|*-*-dragonfly*)
    1.33              pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
    1.34              pthread_lib="-pthread"
    1.35              ;;
    1.36 @@ -1761,14 +1764,17 @@
    1.37  CheckUSBHID()
    1.38  {
    1.39      if test x$enable_joystick = xyes; then
    1.40 -        AC_CHECK_HEADER(usb.h, [USB_CFLAGS="-DHAVE_USB_H"])
    1.41 -        AC_CHECK_HEADER(usbhid.h, [USB_CFLAGS="-DHAVE_USBHID_H"])
    1.42 -        AC_CHECK_HEADER(libusb.h, [USB_CFLAGS="-DHAVE_LIBUSB_H"])
    1.43 -        AC_CHECK_HEADER(libusbhid.h, [USB_CFLAGS="-DHAVE_LIBUSBHID_H"])
    1.44 +        AC_CHECK_LIB(usbhid, hid_init, have_libusbhid=yes)
    1.45 +        if test x$have_libusbhid = xyes; then
    1.46 +            AC_CHECK_HEADER(usbhid.h, [USB_CFLAGS="-DHAVE_USBHID_H"])
    1.47 +            AC_CHECK_HEADER(libusbhid.h, [USB_CFLAGS="-DHAVE_LIBUSBHID_H"])
    1.48 +            USB_LIBS="$USB_LIBS -lusbhid"
    1.49 +        else
    1.50 +            AC_CHECK_HEADER(usb.h, [USB_CFLAGS="-DHAVE_USB_H"])
    1.51 +            AC_CHECK_HEADER(libusb.h, [USB_CFLAGS="-DHAVE_LIBUSB_H"])
    1.52 +            AC_CHECK_LIB(usb, hid_init, [USB_LIBS="$USB_LIBS -lusb"])
    1.53 +        fi
    1.54              
    1.55 -        AC_CHECK_LIB(usbhid, hid_init, [USB_LIBS="$USB_LIBS -lusbhid"])
    1.56 -        AC_CHECK_LIB(usb, hid_init, [USB_LIBS="$USB_LIBS -lusb"])
    1.57 -
    1.58          save_CFLAGS="$CFLAGS"
    1.59          CFLAGS="$CFLAGS $USB_CFLAGS"
    1.60  
    1.61 @@ -1779,8 +1785,13 @@
    1.62            #if defined(HAVE_USB_H)
    1.63            #include <usb.h>
    1.64            #endif
    1.65 -          #include <dev/usb/usb.h>
    1.66 -          #include <dev/usb/usbhid.h>
    1.67 +          #ifdef __DragonFly__
    1.68 +          # include <bus/usb/usb.h>
    1.69 +          # include <bus/usb/usbhid.h>
    1.70 +          #else
    1.71 +          # include <dev/usb/usb.h>
    1.72 +          # include <dev/usb/usbhid.h>
    1.73 +          #endif
    1.74            #if defined(HAVE_USBHID_H)
    1.75            #include <usbhid.h>
    1.76            #elif defined(HAVE_LIBUSB_H)
    1.77 @@ -1805,8 +1816,13 @@
    1.78                #if defined(HAVE_USB_H)
    1.79                #include <usb.h>
    1.80                #endif
    1.81 -              #include <dev/usb/usb.h>
    1.82 -              #include <dev/usb/usbhid.h>
    1.83 +              #ifdef __DragonFly__
    1.84 +              # include <bus/usb/usb.h>
    1.85 +              # include <bus/usb/usbhid.h>
    1.86 +              #else
    1.87 +              # include <dev/usb/usb.h>
    1.88 +              # include <dev/usb/usbhid.h>
    1.89 +              #endif
    1.90                #if defined(HAVE_USBHID_H)
    1.91                #include <usbhid.h>
    1.92                #elif defined(HAVE_LIBUSB_H)
    1.93 @@ -1852,6 +1868,20 @@
    1.94              fi
    1.95              AC_MSG_RESULT($have_usbhid_new)
    1.96  
    1.97 +            AC_MSG_CHECKING(for struct joystick in machine/joystick.h)
    1.98 +            have_machine_joystick=no
    1.99 +            AC_TRY_COMPILE([
   1.100 +              #include <machine/joystick.h>
   1.101 +            ],[
   1.102 +              struct joystick t;
   1.103 +            ],[
   1.104 +            have_machine_joystick=yes
   1.105 +            ])
   1.106 +            if test x$have_machine_joystick = xyes; then
   1.107 +                AC_DEFINE(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H)
   1.108 +            fi
   1.109 +            AC_MSG_RESULT($have_machine_joystick)
   1.110 +
   1.111              AC_DEFINE(SDL_JOYSTICK_USBHID)
   1.112              SOURCES="$SOURCES $srcdir/src/joystick/bsd/*.c"
   1.113              EXTRA_CFLAGS="$EXTRA_CFLAGS $USB_CFLAGS"
   1.114 @@ -1862,6 +1892,7 @@
   1.115      fi
   1.116  }
   1.117  
   1.118 +
   1.119  dnl Check for clock_gettime()
   1.120  CheckClockGettime()
   1.121  {
   1.122 @@ -1907,7 +1938,7 @@
   1.123              have_timers=yes
   1.124          fi
   1.125          ;;
   1.126 -    *-*-linux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
   1.127 +    *-*-linux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
   1.128          case "$host" in
   1.129              *-*-linux*)         ARCH=linux ;;
   1.130              *-*-kfreebsd*-gnu)  ARCH=kfreebsd-gnu ;;
   1.131 @@ -1916,6 +1947,7 @@
   1.132              *-*-gnu*)           ARCH=gnu ;; # must be last of the gnu variants
   1.133              *-*-bsdi*)          ARCH=bsdi ;;
   1.134              *-*-freebsd*)       ARCH=freebsd ;;
   1.135 +            *-*-dragonfly*)     ARCH=freebsd ;;
   1.136              *-*-netbsd*)        ARCH=netbsd ;;
   1.137              *-*-openbsd*)       ARCH=openbsd ;;
   1.138              *-*-sysv5*)         ARCH=sysv5 ;;
   1.139 @@ -1961,12 +1993,12 @@
   1.140          # Set up files for the audio library
   1.141          if test x$enable_audio = xyes; then
   1.142            case $ARCH in
   1.143 -            netbsd|sysv5|solaris|hpux)
   1.144 +            sysv5|solaris|hpux)
   1.145                  AC_DEFINE(SDL_AUDIO_DRIVER_SUNAUDIO)
   1.146                  SOURCES="$SOURCES $srcdir/src/audio/sun/*.c"
   1.147                  have_audio=yes
   1.148              ;;
   1.149 -            openbsd)
   1.150 +            netbsd|openbsd)
   1.151                  AC_DEFINE(SDL_AUDIO_DRIVER_OPENBSD)
   1.152                  SOURCES="$SOURCES $srcdir/src/audio/openbsd/*.c"
   1.153                  have_audio=yes
   1.154 @@ -2388,7 +2420,7 @@
   1.155  # Set runtime shared library paths as needed
   1.156  
   1.157  if test "x$enable_rpath" = "xyes"; then
   1.158 -  if test $ARCH = linux -o $ARCH = freebsd -o $ARCH = bsdi -o $ARCH = irix; then
   1.159 +  if test $ARCH = bsdi -o $ARCH = freebsd -o $ARCH = irix -o $ARCH = linux -o $ARCH = netbsd; then
   1.160      SDL_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib"
   1.161    fi
   1.162    if test $ARCH = solaris; then
     2.1 --- a/include/SDL_config.h.in	Tue Mar 21 07:02:34 2006 +0000
     2.2 +++ b/include/SDL_config.h.in	Tue Mar 21 08:54:50 2006 +0000
     2.3 @@ -208,6 +208,7 @@
     2.4  #undef SDL_JOYSTICK_RISCOS
     2.5  #undef SDL_JOYSTICK_WINMM
     2.6  #undef SDL_JOYSTICK_USBHID
     2.7 +#undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
     2.8  
     2.9  /* Enable various shared object loading systems */
    2.10  #undef SDL_LOADSO_BEOS
     3.1 --- a/include/SDL_platform.h	Tue Mar 21 07:02:34 2006 +0000
     3.2 +++ b/include/SDL_platform.h	Tue Mar 21 08:54:50 2006 +0000
     3.3 @@ -45,7 +45,7 @@
     3.4  #undef __DREAMCAST__
     3.5  #define __DREAMCAST__	1
     3.6  #endif
     3.7 -#if defined(__FreeBSD__)
     3.8 +#if defined(__FreeBSD__) || defined(__DragonFly__)
     3.9  #undef __FREEBSD__
    3.10  #define __FREEBSD__	1
    3.11  #endif
     4.1 --- a/src/audio/openbsd/SDL_openbsdaudio.c	Tue Mar 21 07:02:34 2006 +0000
     4.2 +++ b/src/audio/openbsd/SDL_openbsdaudio.c	Tue Mar 21 08:54:50 2006 +0000
     4.3 @@ -42,8 +42,12 @@
     4.4  #include "../SDL_audiodev_c.h"
     4.5  #include "SDL_openbsdaudio.h"
     4.6  
     4.7 -/* The tag name used by OpenBSD audio */
     4.8 +/* The tag name used by NetBSD/OpenBSD audio */
     4.9 +#ifdef __NETBSD__
    4.10 +#define OBSD_DRIVER_NAME         "netbsd"
    4.11 +#else
    4.12  #define OBSD_DRIVER_NAME         "openbsd"
    4.13 +#endif
    4.14  
    4.15  /* Open the audio device for playback, and don't block if busy */
    4.16  /* #define USE_BLOCKING_WRITES */
    4.17 @@ -128,7 +132,11 @@
    4.18  }
    4.19  
    4.20  AudioBootStrap OPENBSD_AUDIO_bootstrap = {
    4.21 +#ifdef __NETBSD__
    4.22 +	OBSD_DRIVER_NAME, "Native NetBSD audio",
    4.23 +#else
    4.24  	OBSD_DRIVER_NAME, "Native OpenBSD audio",
    4.25 +#endif
    4.26  	Audio_Available, Audio_CreateDevice
    4.27  };
    4.28  
    4.29 @@ -136,18 +144,6 @@
    4.30  static void
    4.31  OBSD_WaitAudio(_THIS)
    4.32  {
    4.33 -	/* Check to see if the thread-parent process is still alive */
    4.34 -	{ static int cnt = 0;
    4.35 -		/* Note that this only works with thread implementations 
    4.36 -		   that use a different process id for each thread.
    4.37 -		*/
    4.38 -		if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
    4.39 -			if ( kill(parent, 0) < 0 ) {
    4.40 -				this->enabled = 0;
    4.41 -			}
    4.42 -		}
    4.43 -	}
    4.44 -
    4.45  #ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
    4.46  	/* See if we need to use timed audio synchronization */
    4.47  	if ( frame_ticks ) {
    4.48 @@ -384,6 +380,9 @@
    4.49      	spec->channels = 1;
    4.50      AUDIO_INITINFO(&info);
    4.51      info.play.sample_rate = spec->freq;
    4.52 +    info.blocksize = spec->size;
    4.53 +    info.hiwat = 5;
    4.54 +    info.lowat = 3;
    4.55      (void)ioctl(audio_fd, AUDIO_SETINFO, &info);
    4.56      (void)ioctl(audio_fd, AUDIO_GETINFO, &info);
    4.57      spec->freq  = info.play.sample_rate;
     5.1 --- a/src/joystick/bsd/SDL_sysjoystick.c	Tue Mar 21 07:02:34 2006 +0000
     5.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c	Tue Mar 21 08:54:50 2006 +0000
     5.3 @@ -37,8 +37,13 @@
     5.4  #if defined(HAVE_USB_H)
     5.5  #include <usb.h>
     5.6  #endif
     5.7 +#ifdef __DragonFly__
     5.8 +#include <bus/usb/usb.h>
     5.9 +#include <bus/usb/usbhid.h>
    5.10 +#else
    5.11  #include <dev/usb/usb.h>
    5.12  #include <dev/usb/usbhid.h>
    5.13 +#endif
    5.14  
    5.15  #if defined(HAVE_USBHID_H)
    5.16  #include <usbhid.h>
    5.17 @@ -49,11 +54,13 @@
    5.18  #endif
    5.19  
    5.20  #ifdef __FREEBSD__
    5.21 +#ifndef __DragonFly__
    5.22  #include <osreldate.h>
    5.23 +#endif
    5.24  #include <sys/joystick.h>
    5.25  #endif
    5.26  
    5.27 -#if defined(__NETBSD__) || (defined(__OPENBSD__) && defined(__i386__))
    5.28 +#if SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
    5.29  #include <machine/joystick.h>
    5.30  #endif
    5.31  
    5.32 @@ -231,6 +238,7 @@
    5.33  	struct hid_data *hdata;
    5.34  	struct report *rep;
    5.35  	int fd;
    5.36 +	int i;
    5.37  
    5.38  	fd = open(path, O_RDONLY);
    5.39  	if (fd == -1) {
    5.40 @@ -297,6 +305,8 @@
    5.41  	joy->nbuttons = 0;
    5.42  	joy->nhats = 0;
    5.43  	joy->nballs = 0;
    5.44 +	for (i=0; i<JOYAXE_count; i++)
    5.45 +		hw->axis_map[i] = -1;
    5.46  
    5.47  	while (hid_get_item(hdata, &hitem) > 0) {
    5.48  		char *sp;
    5.49 @@ -323,8 +333,7 @@
    5.50  			    unsigned usage = HID_USAGE(hitem.usage);
    5.51  			    int joyaxe = usage_to_joyaxe(usage);
    5.52  			    if (joyaxe >= 0) {
    5.53 -				hw->axis_map[joyaxe] = joy->naxes;
    5.54 -				joy->naxes++;
    5.55 +				hw->axis_map[joyaxe] = 1;
    5.56  			    } else if (usage == HUG_HAT_SWITCH) {
    5.57  				joy->nhats++;
    5.58  			    }
    5.59 @@ -342,6 +351,9 @@
    5.60  		}
    5.61  	}
    5.62  	hid_end_parse(hdata);
    5.63 +	for (i=0; i<JOYAXE_count; i++)
    5.64 +		if (hw->axis_map[i] > 0)
    5.65 +			hw->axis_map[i] = joy->naxes++;
    5.66  
    5.67  usbend:
    5.68  	/* The poll blocks the event thread. */
    5.69 @@ -364,7 +376,7 @@
    5.70  	int nbutton, naxe = -1;
    5.71  	Sint32 v;
    5.72  
    5.73 -#if defined(__FREEBSD__) || defined(__NETBSD__) || (defined(__OPENBSD__) && defined(__i386__))
    5.74 +#if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
    5.75  	struct joystick gameport;
    5.76  	static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
    5.77   
    5.78 @@ -413,7 +425,7 @@
    5.79  		}
    5.80  		return;
    5.81  	}
    5.82 -#endif /* defined(__FREEBSD__) || defined(__NETBSD__) || defined(__OPENBSD__) */
    5.83 +#endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
    5.84  	
    5.85  	rep = &joy->hwdata->inreport;
    5.86  
    5.87 @@ -451,7 +463,8 @@
    5.88  			    } else if (usage == HUG_HAT_SWITCH) {
    5.89  				v = (Sint32)hid_get_data(REP_BUF_DATA(rep),
    5.90  							 &hitem);
    5.91 -				SDL_PrivateJoystickHat(joy, 0, hatval_to_sdl(v));
    5.92 +				SDL_PrivateJoystickHat(joy, 0,
    5.93 +					hatval_to_sdl(v)-hitem.logical_minimum);
    5.94  			    }
    5.95  			    break;
    5.96  			}
    5.97 @@ -512,7 +525,9 @@
    5.98  {
    5.99  	int len;
   5.100  
   5.101 -#ifdef __FREEBSD__
   5.102 +#ifdef __DragonFly__
   5.103 +	len = hid_report_size(rd, r->rid, repinfo[repind].kind);
   5.104 +#elif __FREEBSD__
   5.105  # if (__FreeBSD_version >= 460000)
   5.106  #  if (__FreeBSD_version <= 500111)
   5.107  	len = hid_report_size(rd, r->rid, repinfo[repind].kind);
   5.108 @@ -521,12 +536,12 @@
   5.109  #  endif
   5.110  # else
   5.111  	len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
   5.112 -#endif
   5.113 +# endif
   5.114  #else
   5.115  # ifdef USBHID_NEW
   5.116 +	len = hid_report_size(rd, repinfo[repind].kind, r->rid);
   5.117 +# else
   5.118  	len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
   5.119 -# else
   5.120 -	len = hid_report_size(rd, repinfo[repind].kind, r->rid);
   5.121  # endif
   5.122  #endif
   5.123  
     6.1 --- a/src/video/vgl/SDL_vglvideo.c	Tue Mar 21 07:02:34 2006 +0000
     6.2 +++ b/src/video/vgl/SDL_vglvideo.c	Tue Mar 21 08:54:50 2006 +0000
     6.3 @@ -555,7 +555,7 @@
     6.4      case V_INFO_MM_VGAX:
     6.5        vminfop->Type = VIDBUF8X;
     6.6        break;
     6.7 -#if defined(__FREEBSD__) && __FreeBSD_version >= 500000
     6.8 +#if defined(__FREEBSD__) && (defined(__DragonFly__) || __FreeBSD_version >= 500000)
     6.9      case V_INFO_MM_DIRECT:
    6.10        vminfop->PixelBytes = minfo.vi_pixel_size;
    6.11        switch (vminfop->PixelBytes) {