Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
slouken committed Mar 21, 2006
1 parent 13dae1c commit d3e3cb6
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 43 deletions.
68 changes: 50 additions & 18 deletions configure.in
Expand Up @@ -50,10 +50,13 @@ else
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
Expand Down Expand Up @@ -284,7 +287,7 @@ AC_HELP_STRING([--enable-oss], [support the OSS audio API [default=yes]]),
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";;
Expand Down Expand Up @@ -1499,7 +1502,7 @@ AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [default=yes]]),
# causes Carbon.p complaints?
# pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
;;
*-*-freebsd*)
*-*-freebsd*|*-*-dragonfly*)
pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
pthread_lib="-pthread"
;;
Expand Down Expand Up @@ -1761,14 +1764,17 @@ dnl Check for the usbhid(3) library on *BSD
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"

Expand All @@ -1779,8 +1785,13 @@ CheckUSBHID()
#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)
Expand All @@ -1805,8 +1816,13 @@ CheckUSBHID()
#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)
Expand Down Expand Up @@ -1852,6 +1868,20 @@ CheckUSBHID()
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"
Expand All @@ -1862,6 +1892,7 @@ CheckUSBHID()
fi
}


dnl Check for clock_gettime()
CheckClockGettime()
{
Expand Down Expand Up @@ -1907,7 +1938,7 @@ case "$host" in
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 ;;
Expand All @@ -1916,6 +1947,7 @@ case "$host" in
*-*-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 ;;
Expand Down Expand Up @@ -1961,12 +1993,12 @@ case "$host" in
# 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
Expand Down Expand Up @@ -2388,7 +2420,7 @@ SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects
# 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
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.in
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/SDL_platform.h
Expand Up @@ -45,7 +45,7 @@
#undef __DREAMCAST__
#define __DREAMCAST__ 1
#endif
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__DragonFly__)
#undef __FREEBSD__
#define __FREEBSD__ 1
#endif
Expand Down
25 changes: 12 additions & 13 deletions src/audio/openbsd/SDL_openbsdaudio.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -128,26 +132,18 @@ static SDL_AudioDevice
}

AudioBootStrap OPENBSD_AUDIO_bootstrap = {
#ifdef __NETBSD__
OBSD_DRIVER_NAME, "Native NetBSD audio",
#else
OBSD_DRIVER_NAME, "Native OpenBSD audio",
#endif
Audio_Available, Audio_CreateDevice
};

/* This function waits until it is possible to write a full sound buffer */
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 ) {
Expand Down Expand Up @@ -384,6 +380,9 @@ OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
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;
Expand Down
35 changes: 25 additions & 10 deletions src/joystick/bsd/SDL_sysjoystick.c
Expand Up @@ -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>
Expand All @@ -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

Expand Down Expand Up @@ -231,6 +238,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) {
Expand Down Expand Up @@ -297,6 +305,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;
Expand All @@ -323,8 +333,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++;
}
Expand All @@ -342,6 +351,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. */
Expand All @@ -364,7 +376,7 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joy)
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;

Expand Down Expand Up @@ -413,7 +425,7 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joy)
}
return;
}
#endif /* defined(__FREEBSD__) || defined(__NETBSD__) || defined(__OPENBSD__) */
#endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */

rep = &joy->hwdata->inreport;

Expand Down Expand Up @@ -451,7 +463,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;
}
Expand Down Expand Up @@ -512,7 +525,9 @@ report_alloc(struct report *r, struct report_desc *rd, int repind)
{
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);
Expand All @@ -521,12 +536,12 @@ report_alloc(struct report *r, struct report_desc *rd, int repind)
# 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

Expand Down
2 changes: 1 addition & 1 deletion src/video/vgl/SDL_vglvideo.c
Expand Up @@ -555,7 +555,7 @@ VGLListModes(int depth, int mem_model)
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) {
Expand Down

0 comments on commit d3e3cb6

Please sign in to comment.