author Sam Lantinga <>
Mon, 02 Jun 2003 14:50:22 +0000
changeset 632 85e104fe14c2
parent 221 50620ec9c86a
child 869 ae4ab3ac89a9
permissions -rw-r--r--
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
From: Jeff Brown <>
Subject: [patch] SDL-1.2.5 + FreeBSD joystick axes, hat fixes

Hello again! When I sent in some SDL fixes last December, I found out
they'd already been fixed in the CVS version. This time, I checked the
repository before bugging you. =)

I'm using SDL-1.2.5 on a FreeBSD 4.6.2-RELEASE system, and in the course
of getting my multi-analog-axis USB controller (with a hat switch!)
working with d2x-sdl -- the SDL port of the Descent 2 engine -- I came
across a few problems:

1) The second analog stick is reported as a slider in one direction, and
"Rz" in the other. SDL was ignoring the Rz axis, so I added Rx/Ry/Rz to
the set of things SDL considers to be axes.

2) After the above change, the set of JOYAXE_* axes for my gamepad was
{0,1,3,7}; however, d2x-sdl expects the axes to be contiguously numbered
from 0, which seems like a pretty reasonable expectation, rather than
having to scan the entire space of axes that SDL may or may not have.
So, I added a table lookup which maps the JOYAXE_* axis numbers to 0,1,...
in the order they're detected by SDL_SYS_JoystickOpen(), when reporting
them to the application. I also added a function "usage_to_joyaxe()"
which maps the USB HUG_* usage values to JOYAXE_values, since the repeated
case statements testing for HUG_* were getting out of hand.

3) The BSD joystick driver had no hat support, so I added it. It looks
like our USB library can only support one hat switch per device, which
makes life easy.

The patch against SDL-1.2.5 which implements these changes is at:

After applying, SDL's "testjoystick" reports all activity from my gamepad
correctly, and d2x works too (though it needed some other fixes).

Moving on...

There is also a problem with slightly different USBHID library interfaces
on different versions of FreeBSD. I wasn't going to mention this since the
FreeBSD port for SDL-1.2.5 (and not SDL itself) was doing the FreeBSD
version-specific patching, so I e-mailed the port maintainer with this
change. However, I see that you've incorporated the FreeBSD
version-checking stuff into the CVS version of SDL, so now it's relevant
for you too.

The problem is, the FreeBSD #if tests don't work right for FreeBSD
4.6.2-RELEASE. There may be other versions with this problem, but I've
only tested 4.6.2-R. The following patch against your latest CVS version
fixes this:

--- SDL_sysjoystick.c-1.16 Tue Apr 15 09:02:08 2003
+++ SDL_sysjoystick.c Sun Jun 1 15:10:28 2003
@@ -420,6 +420,8 @@
# else
len = hid_report_size(rd, repinfo[repind].kind, r->rid);
# endif
+# elif (__FreeBSD_version == 460002)
+ len = hid_report_size(rd, r->rid, repinfo[repind].kind);
# else
len = hid_report_size(rd, repinfo[repind].kind, &r->rid);

I hope this is all useful to you. I've been getting myself dizzy playing
Descent 2 with it, all morning!

-Jeff Brown

P.S. My USB controller is a Thrustmaster Firestorm Dual Analog 2. That's
probably irrelevant, but I threw it in for completeness.
     1 ==============================================================================
     2 Using the Simple DirectMedia Layer with Mac OS X
     3 ==============================================================================
     5 These instructions are for people using Apple's Mac OS X (pronounced
     6 "ten").
     8 From the developer's point of view, OS X is a sort of hybrid Mac and
     9 Unix system, and you have the option of using either traditional
    10 command line tools or Apple's IDE ProjectBuilder (PB).
    12 To build using the command line, use the standard configure and make
    13 process:
    15 	./configure
    16 	make
    17 	make install
    19 (You may need to create the subdirs of /usr/local manually.)
    21 To use the library once it's built, you essential have two possibilities:
    22 use the traditional autoconf/automake/make method, or use Apple's Project Builder.
    24 ==============================================================================
    25 Using the Simple DirectMedia Layer with a traditional Makefile
    26 ==============================================================================
    28 An existing autoconf/automake build system for your SDL app has good chances
    29 to work almost unchanged on OS X. However, to produce a "real" MacOS X binary
    30 that you can distribute to users, you need to put the generated binary into a
    31 so called "bundle", which basically is a fancy folder with a name like
    32 "".
    34 To get this build automatically, add something like the following rule to
    35 your
    37 bundle_contents =
    38 APP_NAME_bundle: EXE_NAME
    39 	mkdir -p $(bundle_contents)/MacOS
    40 	mkdir -p $(bundle_contents)/Resources
    41 	echo "APPL????" > $(bundle_contents)/PkgInfo
    42 	$(INSTALL_PROGRAM) $< $(bundle_contents)/MacOS/
    44 You should replace EXE_NAME with the name of the executable. APP_NAME is what
    45 will be visible to the user in the Finder. Usually it will be the same
    46 as EXE_NAME but capitalized. E.g. if EXE_NAME is "testgame" then APP_NAME 
    47 usually is "TestGame". You might also want to use @PACKAGE@ to use the package
    48 name as specified in your file.
    50 If your project builds more than one application, you will have to do a bit
    51 more.  For each of your target applications, you need a seperate rule.
    53 If you want the created bundles to be installed, you may want to add this
    54 rule to your
    56 install-exec-hook: APP_NAME_bundle
    57 	rm -rf $(DESTDIR)$(prefix)/Applications/
    58 	mkdir -p $(DESTDIR)$(prefix)/Applications/
    59 	cp -r $< /$(DESTDIR)$(prefix)Applications/
    61 This rule takes the Bundle created by the rule from step 3 and installs them
    62 into $(DESTDIR)$(prefix)/Applications/.
    64 Again, if you want to install multiple applications, you will have to augment
    65 the make rule accordingly.
    68 ==============================================================================
    69 Using the Simple DirectMedia Layer with Project Builder
    70 ==============================================================================
    72 These instructions are for using Apple's Project Builder IDE to build SDL
    73 applications.
    75 - First steps
    77 The first thing to do is to unpack the PBProjects.tar.gz archive in the
    78 top level SDL directory (where the PBProjects.tar.gz archive resides).
    79 Because Stuffit Expander will unpack the archive into a subdirectory,
    80 you should unpack the archive manually from the command line:
    81 	cd [path_to_SDL_source]
    82 	tar zxf PBProjects.tar.gz
    83 This will create a new folder called PBProjects, which you can browse
    84 normally from the Finder.
    86 - Building the Framework
    88 The SDL Library is packaged as a framework bundle, an organized
    89 relocatable folder heirarchy of executible code, interface headers, 
    90 and additional resources. For practical purposes, you can think of a 
    91 framework as a more user and system-friendly shared library, whose library
    92 file behaves more or less like a standard UNIX shared library.
    94 To build the framework, simply open the framework project and build it. 
    95 By default, the framework bundle "SDL.framework" is installed in 
    96 ~/Library/Frameworks. Therefore, the testers and project stationary expect
    97 it to be located there. However, it will function the same in any of the
    98 following locations:
   100     ~/Library/Frameworks
   101     /Local/Library/Frameworks
   102     /System/Library/Frameworks
   104 - Build Options
   105     There are two "Build Styles" (See the "Targets" tab) for SDL.
   106     "Deployment" should be used if you aren't tweaking the SDL library.
   107     "Development" should be used to debug SDL apps or the library itself.
   109 - Building the Testers
   110     Open the SDLTest project and build away!
   112 - Using the Project Stationary
   113     Copy the stationary to the indicated folders to access it from
   114     the "New Project" and "Add target" menus. What could be easier?
   116 - Setting up a new project by hand
   117     Some of you won't want to use the Stationary so I'll give some tips:
   118     * Create a new "Cocoa Application"
   119     * Add src/main/macosx/SDLMain.m , .h and .nib to your project
   120     * Remove "main.c" from your project
   121     * Remove "MainMenu.nib" from your project
   122     * Add "$(HOME)/Library/Frameworks/SDL.framework/Headers" to include path
   123     * Add "$(HOME)/Library/Frameworks" to the frameworks search path
   124     * Add "-framework SDL -framework Foundation -framework AppKit" to "OTHER_LDFLAGS"
   125     * Set the "Main Nib File" under "Application Settings" to "SDLMain.nib"
   126     * Add your files
   127     * Clean and build
   129 - Building from command line
   130     Use pbxbuild in the same directory as your .pbproj file
   132 - Running your app
   133     You can send command line args to your app by either invoking it from
   134     the command line (in *.app/Contents/MacOS) or by entering them in the
   135     "Executibles" panel of the target settings.
   137 - Implementation Notes
   138     Some things that may be of interest about how it all works...
   139     * Working directory
   140         As defined in the SDL_main.m file, the working directory of your SDL app
   141         is by default set to its parent. You may wish to change this to better
   142         suit your needs.
   143     * You have a Cocoa App!
   144         Your SDL app is essentially a Cocoa application. When your app
   145         starts up and the libraries finish loading, a Cocoa procedure is called,
   146         which sets up the working directory and calls your main() method.
   147         You are free to modify your Cocoa app with generally no consequence 
   148         to SDL. You cannot, however, easily change the SDL window itself.
   149         Functionality may be added in the future to help this.
   152 Known bugs are listed in the file "BUGS"