changeset 1659:14717b52abc0 SDL-1.3

Merge trunk-1.3-3
author Sam Lantinga <slouken@libsdl.org>
date Wed, 17 May 2006 08:18:28 +0000
parents e49147870aac
children 8b9d79e7eacf
files CWprojects.sea.bin Makefile.in README README.MacOSX README.OS2 README.SVN README.Watcom SDL.spec.in TODO VisualCE.zip Watcom-OS2.zip Watcom-Win32.zip WhatsNew autogen.sh build-scripts/fatbuild.sh build-scripts/ltmain.sh configure.in docs.html docs/images/rainbow.gif docs/index.html include/SDL_config.h.in include/SDL_config_macos.h include/SDL_config_macosx.h include/SDL_platform.h include/SDL_stdinc.h include/SDL_syswm.h sdl.m4 src/SDL_error.c src/SDL_error_c.h src/audio/SDL_audio.c src/audio/SDL_audio_c.h src/audio/SDL_audiocvt.c src/audio/SDL_wave.c src/audio/SDL_wave.h src/audio/mint/SDL_mintaudio.c src/audio/mint/SDL_mintaudio.h src/cdrom/macosx/AudioFilePlayer.c src/cdrom/macosx/SDL_syscdrom.c src/events/SDL_events.c src/events/SDL_keyboard.c src/file/SDL_rwops.c src/joystick/linux/SDL_sysjoystick.c src/joystick/win32/SDL_mmjoystick.c src/loadso/macosx/SDL_dlcompat.c src/loadso/macosx/SDL_sysloadso.c src/main/dummy/SDL_dummy_main.c src/main/macosx/SDLMain.m src/main/win32/SDL_win32_main.c src/stdlib/SDL_string.c src/thread/SDL_thread.c src/thread/pth/SDL_systhread.c src/thread/win32/SDL_systhread.c src/timer/SDL_timer.c src/timer/macos/FastTimes.c src/timer/macos/SDL_systimer.c src/video/SDL_blit_A.c src/video/SDL_blit_N.c src/video/ataricommon/SDL_ikbdinterrupt_s.h src/video/ataricommon/SDL_xbiosinterrupt_s.h src/video/dga/SDL_dgavideo.c src/video/dga/SDL_dgavideo.h src/video/directfb/SDL_DirectFB_events.c src/video/directfb/SDL_DirectFB_video.c src/video/directfb/SDL_DirectFB_yuv.c src/video/fbcon/SDL_fb3dfx.c src/video/fbcon/SDL_fbevents.c src/video/fbcon/SDL_fbmatrox.c src/video/fbcon/SDL_fbriva.c src/video/fbcon/SDL_fbvideo.c src/video/fbcon/SDL_fbvideo.h src/video/maccommon/SDL_macgl.c src/video/maccommon/SDL_macgl_c.h src/video/macdsp/SDL_dspvideo.c src/video/macrom/SDL_romvideo.c src/video/ps2gs/SDL_gsyuv.c src/video/quartz/SDL_QuartzVideo.m src/video/quartz/SDL_QuartzWM.m src/video/quartz/SDL_QuartzYUV.m src/video/wincommon/SDL_wingl.c src/video/windib/SDL_dibvideo.c src/video/windx5/SDL_dx5video.c src/video/x11/SDL_x11dyn.c src/video/x11/SDL_x11events.c src/video/x11/SDL_x11events_c.h src/video/x11/SDL_x11gl.c src/video/x11/SDL_x11modes.c src/video/x11/SDL_x11sym.h src/video/x11/SDL_x11video.c src/video/x11/SDL_x11video.h src/video/x11/SDL_x11wm.c src/video/x11/SDL_x11wm_c.h src/video/xbios/SDL_xbios.c test/acinclude.m4 test/autogen.sh test/configure.in test/gcc-fat.sh test/loopwave.c test/testalpha.c test/testdyngl.c test/testerror.c test/testfile.c test/testgl.c test/testhread.c test/testlock.c test/testpalette.c test/testsem.c test/testtimer.c test/testwin.c test/testwm.c test/threadwin.c test/torturethread.c
diffstat 111 files changed, 3349 insertions(+), 3245 deletions(-) [+]
line wrap: on
line diff
Binary file CWprojects.sea.bin has changed
--- a/Makefile.in	Mon May 01 06:58:33 2006 +0000
+++ b/Makefile.in	Wed May 17 08:18:28 2006 +0000
@@ -38,7 +38,7 @@
 SDLMAIN_SOURCES = @SDLMAIN_SOURCES@
 SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@
 
-DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS CWprojects.sea.bin docs docs.html EpocBuildFiles.zip include INSTALL Makefile.dc Makefile.minimal Makefile.in MPWmake.sea.bin README* sdl-config.in sdl.m4 SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualCE.zip VisualC.html VisualC.zip Watcom-OS2.zip WhatsNew Xcode.tar.gz
+DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS CWprojects.sea.bin docs docs.html EpocBuildFiles.zip include INSTALL Makefile.dc Makefile.minimal Makefile.in MPWmake.sea.bin README* sdl-config.in sdl.m4 SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualCE.zip VisualC.html VisualC.zip Watcom-OS2.zip Watcom-Win32.zip WhatsNew Xcode.tar.gz
 
 LT_AGE      = @LT_AGE@
 LT_CURRENT  = @LT_CURRENT@
@@ -78,7 +78,7 @@
 	$(AR) cru $@ $(SDLMAIN_OBJECTS)
 	$(RANLIB) $@
 
-install: install-bin install-hdrs install-lib install-data install-man
+install: all install-bin install-hdrs install-lib install-data install-man
 install-bin:
 	$(SHELL) $(auxdir)/mkinstalldirs $(bindir)
 	$(INSTALL) -m 755 sdl-config $(bindir)/sdl-config
@@ -131,7 +131,6 @@
 
 distclean: clean
 	rm -f Makefile include/SDL_config.h sdl-config
-	rm -f include/SDL_config.h sdl-config
 	rm -f SDL.qpg
 	rm -f config.status config.cache config.log libtool $(depend)
 	rm -rf $(srcdir)/autom4te*
@@ -151,8 +150,15 @@
 	tar cf - $(DIST) | (cd $(distdir); tar xf -)
 	cp $(distdir)/include/SDL_config.h.default $(distdir)/include/SDL_config.h
 	rm -rf `find $(distdir) -name .svn`
-	rm -f `find $(distdir) -name '.#*'`
-	rmdir `find $(distdir) -type d -empty`
+	find $(distdir) \( \
+	    -name '*~' -o \
+	    -name '*.bak' -o \
+	    -name '*.old' -o \
+	    -name '*.rej' -o \
+	    -name '*.orig' -o \
+	    -name '.#*' \) \
+	    -exec rm -f {} \;
+	if test -f $(distdir)/test/Makefile; then (cd $(distdir)/test && make distclean); fi
 	tar cvf - $(distdir) | gzip --best >$(distfile)
 	rm -rf $(distdir)
 
--- a/README	Mon May 01 06:58:33 2006 +0000
+++ b/README	Wed May 17 08:18:28 2006 +0000
@@ -12,14 +12,15 @@
 level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL,
 and 2D framebuffer across multiple platforms.
 
-SDL is written in C, but works with C++ natively, and has bindings to
-several other languages, including Ada, C#, Eiffel, Java, Lua, ML,
-Objective C, Pascal, Perl, PHP, Pike, Python, and Ruby.
+The current version supports Linux, Windows, Windows CE, BeOS, MacOS,
+Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
+The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64,
+RISC OS, SymbianOS, and OS/2, but these are not officially supported.
 
-The current version supports Linux, Windows, BeOS, MacOS, Mac OS X,
-FreeBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.  The code contains
-support for Windows CE, AmigaOS, Dreamcast, Atari, NetBSD, AIX, OSF/Tru64,
-RISC OS, SymbianOS, and OS/2, but these are not officially supported.
+SDL is written in C, but works with C++ natively, and has bindings to
+several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
+Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP,
+Pike, Pliant, Python, Ruby, and Smalltalk.
 
 This library is distributed under GNU LGPL version 2, which can be
 found in the file  "COPYING".  This license allows you to use SDL
@@ -29,7 +30,9 @@
 The best way to learn how to use SDL is to check out the header files in
 the "include" subdirectory and the programs in the "test" subdirectory.
 The header files and test programs are well commented and always up to date.
-More documentation is available in HTML format in "./docs/index.html"
+More documentation is available in HTML format in "docs/index.html", and
+a documentation wiki is available online at:
+	http://www.libsdl.org/cgi/docwiki.cgi
 
 The test programs in the "test" subdirectory are in the public domain.
 
--- a/README.MacOSX	Mon May 01 06:58:33 2006 +0000
+++ b/README.MacOSX	Wed May 17 08:18:28 2006 +0000
@@ -21,6 +21,10 @@
 the fatbuild.sh script in build-scripts:
 	sh build-scripts/fatbuild.sh
 	sudo build-scripts/fatbuild.sh install
+This script builds SDL with 10.2 ABI compatibility on PowerPC and 10.4
+ABI compatibility on Intel architectures.  For best compatibility you
+should compile your application the same way.  A script which wraps
+gcc to make this easy is provided in test/gcc-fat.sh
 
 To use the library once it's built, you essential have two possibilities:
 use the traditional autoconf/automake/make method, or use Xcode.
--- a/README.OS2	Mon May 01 06:58:33 2006 +0000
+++ b/README.OS2	Wed May 17 08:18:28 2006 +0000
@@ -3,7 +3,7 @@
 SDL on OS/2
 ===========
 
-Last updated on Feb. 26, 2006.
+Last updated on May. 1, 2006.
 
 
 1. How to compile?
@@ -16,10 +16,9 @@
 - The FSLib library
   (ftp://ftp.netlabs.org/pub/SDL)
 
-First of all, you have to put the OS/2-specific Watcom makefiles into the
-source code tree by unzipping the file Watcom-OS2.zip here.  This will
-result in a Watcom.mif and a setvars.cmd file in this folder, and several
-Makefile.wat files in the src\ folder and in some of its subfolders.
+First of all, you have to unzip the Watcom-OS2.zip file. This will result in a 
+file called "makefile" and a file called "setvars.cmd" in this folder (and some
+more files...).
 
 Please edit the second, fourth and fifth lines of setvars.cmd file
 to set the folders where the toolkit, the OW compiler and the FSLib are. 
@@ -27,23 +26,22 @@
 Run setvars.cmd, and you should get a shell in which you can
 compile SDL.
 
-Check the "Watcom.mif" file. This is the file which is included by all the
-Watcom makefiles, so changes here will affect the whole build process.
-There is a line in there which determines if the resulting SDL.DLL will be
-a 'debug' or a 'release' build. The 'debug' version is full of printf()'s,
-so if something goes wrong, its output can help a lot for debugging.
+Check the "makefile" file. There is a line in there which determines if the 
+resulting SDL.DLL will be a 'debug' or a 'release' build. The 'debug' version 
+is full of printf()'s, so if something goes wrong, its output can help a lot
+for debugging.
 
-Then go to the 'src' folder, and run "wmake -f makefile.wat".
-This should create the SDL.DLL and the corresponding SDL.LIB file there.
+Then run "wmake".
+This should create the SDL.DLL and the corresponding SDL.LIB file here.
 
 To test applications, it's a good idea to use the 'debug' build of SDL, and
 redirect the standard output and standard error output to files, to see what
 happens internally in SDL.
 (like: testsprite >stdout.txt 2>stderr.txt)
 
-To rebuild SDL, use the following commands in 'src' folder:
-wmake -f makefile.wat clean
-wmake -f makefile.wat
+To rebuild SDL, use the following commands in this folder:
+wmake clean
+wmake
 
 
 
@@ -53,7 +51,7 @@
 Once you have SDL.DLL compiled, navigate into the 'test' folder, copy in there
 the newly built SDL.DLL, and copy in there FSLib.DLL.
 
-Then run "wmake -f makefile.wat" in there to compile some of the testapps.
+Then run "wmake" in there to compile some of the testapps.
 
 
 
@@ -193,6 +191,10 @@
 10. Changelog of the OS/2 port
 ------------------------------
 
+Version 1.2 - 2006-05-01  - Doodle
+ - Modified makefile system to have only one makefile
+ - Included FSLib headers, DLL and LIB file
+
 Version 1.2 - 2006-02-26  - Doodle
  - Updated the official SDL version with the OS/2 specific changes.
  - Added support for real unicode keycode conversion.
--- a/README.SVN	Mon May 01 06:58:33 2006 +0000
+++ b/README.SVN	Wed May 17 08:18:28 2006 +0000
@@ -9,10 +9,12 @@
 
   svn checkout svn://libsdl.org/trunk/SDL
 
-When you check out a fresh copy of SDL out via svn, you need to
-generate the files used by make by running the "autogen.sh"
-script, which will run aclocal, automake, autoconf and then
-run configure.
+If you are building SDL with an IDE, you will need to copy the file
+include/SDL_config.h.default to include/SDL_config.h before building.
 
-There is a web interface to svn at http://www.libsdl.org/wsvn
+If you are building SDL via configure, you will need to run autogen.sh
+before running configure.
 
+There is a web interface to the subversion repository at:
+	http://www.libsdl.org/cgi/viewvc.cgi
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.Watcom	Wed May 17 08:18:28 2006 +0000
@@ -0,0 +1,129 @@
+
+Using SDL under Windows with the OpenWatcom compiler
+====================================================
+
+Prerequisites
+-------------
+
+I have done the port under Windows XP Home with SP2 installed. Windows
+2000 should also be working. I'm not so sure about ancient Windows NT,
+since only DirectX 3 is available there. Building should be possible,
+but running the compiled applications will probalbly fail with
+SDL_VIDEODRIVER=directx. The windib driver should work, though.
+
+To compile and use the SDL with Open Watcom you will need the following:
+- Open Watcom compiler. I used version 1.5. The environment variables
+  PATH, WATCOM and INCLUDE need to be set appropriately - please consult
+  the OpenWatcom documentation and instructions given during the
+  installation of the compiler.
+  My setup looks like this in owvars.bat:
+    set WATCOM=C:\watcom
+    set INCLUDE=%WATCOM%\h;%WATCOM%\h\nt
+    set PATH=%PATH%;%WATCOM%\binnt;%WATCOM%\binw
+- A fairly recent DirectX SDK. The original unmodified DX8 SDK works, as
+  well as the minimal DirectX 7 SDK from the Allegro download site
+  (<http://alleg.sourceforge.net/files/dx70_min.zip>).
+- The SDL sources from Subversion
+- The file Watcom-Win32.zip (now available in Subversion)
+
+
+Building the Library
+--------------------
+
+1) In the SDL base directory extract the archive Watcom-Win32.zip. This
+   creates a subdirectory named 'watcom'.
+2) The makefile expects the environment variable DXDIR to be set to the
+   base directory of a DirectX SDK. I have tried a stock DX8 SDK from
+   Microsoft as well as the minimal DirectX 7 SDK from the Allegro
+   download site.
+   You can also edit the makefile directly and hard code your path to
+   the SDK on your system.
+   I have this in my setup:
+     set DXDIR=D:\devel\DX8_SDK
+3) Enter the watcom directory and run
+     wmake sdl
+4) All tests from the test directory are working and can be built by
+   running
+     wmake tests
+
+Notes:
+
+ The makefile offers some options to tweak the way the library is built.
+ You have at your disposal the option to build a static (default)
+ library, or a DLL (with tgt=dll). You can also choose whether to build
+ a Release (default) or a Debug version (with build=debug) of the tests
+ and library. Please consult the usage comment at the top of the
+ makefile for usage instructions.
+
+ If you specify a test target (i.e. 'wmake tests' for all tests, or
+ selected targets like 'wmake testgl testvidinfo testoverlay2'), the
+ tests are always freshly compiled and linked. This is done to
+ minimise hassle when switching between library versions (static vs.
+ DLL), because they require subtly different options.
+ Also, the test executables are put directly into the test directory,
+ so they can find their data files. The clean target of the makefile
+ removes the test executables and the SDL.dll file from the test
+ directory.
+
+ To use the library in your own projects with Open Watcom, you can use
+ the way the tests are built as base of your own build environment.
+
+
+Test applications
+-----------------
+
+I've tried to make all tests work. The following table gives an overview
+of the current status.
+
+ Testname        Status
+~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+checkkeys       +
+graywin         +
+loopwave        +
+testalpha       +
+testbitmap      +
+testdyngl       +
+testerror       +
+testfile        +
+testgamma       +
+testgl          +
+testhread       +
+testiconv       - (all failed)
+testkeys        +
+testlock        +
+testoverlay     + (needs 'set SDL_VIDEODRIVER=directx')
+testoverlay2    + (needs 'set SDL_VIDEODRIVER=directx')
+testpalette     +
+testplatform    +
+testsem         +
+testsprite      +
+testtimer       +
+testver         +
+testvidinfo     +
+testwin         - (fading doesn't seem right)
+testwm          +
+torturethread   +
+testcdrom       +
+testjoystick    not tested
+threadwin       +
+
+
+TODO
+----
+
+There is room for further improvement:
+- Test joystick functionality.
+- Investigate fading issue in 'testwin' test.
+- Fix the UTF-8 support.
+- Adapt the makefile/object file list to support more target systems
+- Use "#pragma aux" syntax for the CPU info functions.
+
+
+Questions and Comments
+----------------------
+
+Please direct any questions or comments to me:  <mailto:macpete@gmx.de>
+
+   Happy Coding!
+
+   Marc Peter
--- a/SDL.spec.in	Mon May 01 06:58:33 2006 +0000
+++ b/SDL.spec.in	Wed May 17 08:18:28 2006 +0000
@@ -9,9 +9,12 @@
 BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
 Prefix: %{_prefix}
 %ifos linux
-Provides: libSDL-1.1.so.0
+Provides: libSDL-1.2.so.0
 %endif
 
+%define __defattr %defattr(-,root,root)
+%define __soext so
+
 %description
 This is the Simple DirectMedia Layer, a generic API that provides low
 level access to audio, keyboard, mouse, and display framebuffer across
@@ -59,25 +62,13 @@
 %clean
 rm -rf $RPM_BUILD_ROOT
 
-%ifnos darwin
-%define __defattr %defattr(-,root,root)
-%define __soext so
-%else
-%define __defattr %defattr(-,root,wheel)
-%define __soext dylib
-%endif
-
 %files
 %{__defattr}
 %doc README-SDL.txt COPYING CREDITS BUGS
-%ifnos darwin
 %{_libdir}/lib*.%{__soext}.*
-%else
-%{_libdir}/lib*.*.%{__soext}
-%endif
 
 %files devel
-%defattr(-,root,root)
+%{__defattr}
 %doc README README-SDL.txt COPYING CREDITS BUGS WhatsNew docs.html
 %doc docs/index.html docs/html
 %{_bindir}/*-config
@@ -90,6 +81,9 @@
 %{_mandir}/man3/*
 
 %changelog
+* Tue May 16 2006 Sam Lantinga <slouken@libsdl.org>
+- Removed support for Darwin, due to build problems on ps2linux
+
 * Mon Jan 03 2004 Anders Bjorklund <afb@algonet.se>
 - Added support for Darwin, updated spec file
 
--- a/TODO	Mon May 01 06:58:33 2006 +0000
+++ b/TODO	Wed May 17 08:18:28 2006 +0000
@@ -2,6 +2,7 @@
 Wish list for the 1.3 development branch:
 http://bugzilla.libsdl.org/
 
+ * Add internal support for adding video modes and refresh rates
  * Support querying and setting refresh rate with video modes
  * Add mousewheel events (new unified event architecture?)
  * DirectInput joystick support needs to be implemented
Binary file VisualCE.zip has changed
Binary file Watcom-OS2.zip has changed
Binary file Watcom-Win32.zip has changed
--- a/WhatsNew	Mon May 01 06:58:33 2006 +0000
+++ b/WhatsNew	Wed May 17 08:18:28 2006 +0000
@@ -4,6 +4,19 @@
 Version 1.0:
 
 1.2.10:
+	If SDL_OpenAudio() is passed zero for the desired format
+	fields, the following environment variables will be used
+	to fill them in:
+		SDL_AUDIO_FREQUENCY
+		SDL_AUDIO_FORMAT
+		SDL_AUDIO_CHANNELS
+		SDL_AUDIO_SAMPLES
+	If an environment variable is not specified, it will be set
+	to a reasonable default value.
+
+	Added support for the SDL_VIDEO_FULLSCREEN_HEAD environment
+	variable, currently supported on X11 Xinerama configurations.
+
 	Added SDL_GL_SWAP_CONTROL to wait for vsync in OpenGL applications.
 
 	Added SDL_GL_ACCELERATED_VISUAL to guarantee hardware acceleration.
--- a/autogen.sh	Mon May 01 06:58:33 2006 +0000
+++ b/autogen.sh	Wed May 17 08:18:28 2006 +0000
@@ -6,7 +6,7 @@
 # Regenerate configuration files
 cp acinclude.m4 aclocal.m4
 found=false
-for autoconf in autoconf autoconf259
+for autoconf in autoconf autoconf259 autoconf-2.59
 do if which $autoconf >/dev/null 2>&1; then $autoconf && found=true; break; fi
 done
 if test x$found = xfalse; then
--- a/build-scripts/fatbuild.sh	Mon May 01 06:58:33 2006 +0000
+++ b/build-scripts/fatbuild.sh	Wed May 17 08:18:28 2006 +0000
@@ -10,7 +10,12 @@
 # Generic, cross-platform CFLAGS you always want go here.
 CFLAGS="-O3 -g -pipe"
 
-# PowerPC compiler flags (10.2 runtime compatibility)
+# PowerPC configure flags (10.2 runtime compatibility)
+# We dynamically load X11, so using the system X11 headers is fine.
+CONFIG_PPC="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
+--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
+
+# PowerPC compiler flags
 CC_PPC="gcc-3.3 -arch ppc"
 CXX_PPC="g++-3.3 -arch ppc"
 CFLAGS_PPC=""
@@ -26,7 +31,12 @@
 -F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
 
-# Intel compiler flags (10.4 runtime compatibility)
+# Intel configure flags (10.4 runtime compatibility)
+# We dynamically load X11, so using the system X11 headers is fine.
+CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
+--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
+
+# Intel compiler flags
 CC_X86="gcc-4.0 -arch i386"
 CXX_X86="g++-4.0 -arch i386"
 CFLAGS_X86="-mmacosx-version-min=10.4"
@@ -158,7 +168,7 @@
 #
 if test x$configure_ppc = xyes; then
     (cd build/ppc && \
-     sh ../../configure --build=`uname -p`-apple-darwin --host=powerpc-apple-darwin CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
+     sh ../../configure $CONFIG_PPC CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
 fi
 if test x$make_ppc = xyes; then
     (cd build/ppc && ls include && make -j$NJOB) || exit 3
@@ -169,7 +179,7 @@
 #
 if test x$configure_x86 = xyes; then
     (cd build/x86 && \
-     sh ../../configure --build=`uname -p`-apple-darwin --host=i386-apple-darwin CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
+     sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
 fi
 if test x$make_x86 = xyes; then
     (cd build/x86 && make -j$NJOB) || exit 3
--- a/build-scripts/ltmain.sh	Mon May 01 06:58:33 2006 +0000
+++ b/build-scripts/ltmain.sh	Wed May 17 08:18:28 2006 +0000
@@ -5008,7 +5008,7 @@
 EOF
 
             case $host_os in
-              mingw*)
+	      *cygwin* | *mingw* )
                 cat >> $cwrappersource <<EOF
   execv("$SHELL",(char const **)newargz);
 EOF
--- a/configure.in	Mon May 01 06:58:33 2006 +0000
+++ b/configure.in	Wed May 17 08:18:28 2006 +0000
@@ -74,14 +74,15 @@
 EXTRA_CFLAGS="$INCLUDE $BASE_CFLAGS"
 BUILD_LDFLAGS="$LDFLAGS"
 EXTRA_LDFLAGS="$BASE_LDFLAGS"
-for path in /usr/local; do
-    if test -d $path/include; then
-        EXTRA_CFLAGS="$EXTRA_CFLAGS -I$path/include"
-    fi
-    if test -d $path/lib; then
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$path/lib"
-    fi
-done
+# I can't remember why I added this.  I'm sure it'll come to me...
+#for path in /usr/local; do
+#    if test -d $path/include; then
+#        EXTRA_CFLAGS="$EXTRA_CFLAGS -I$path/include"
+#    fi
+#    if test -d $path/lib; then
+#        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$path/lib"
+#    fi
+#done
 SDL_CFLAGS="$BASE_CFLAGS"
 SDL_LIBS="-lSDL $BASE_LDFLAGS"
 CPPFLAGS="$CPPFLAGS $EXTRA_CFLAGS"
@@ -715,7 +716,9 @@
     save_CFLAGS="$CFLAGS"
     CFLAGS="$save_CFLAGS $visibility_CFLAGS"
     AC_TRY_COMPILE([
-        int placeholder = 1;
+    #if !defined(__GNUC__) || __GNUC__ < 4
+    #error SDL only uses visibility attributes in GCC 4 or newer
+    #endif
     ],[
     ],[
     have_gcc_fvisibility=yes
@@ -786,6 +789,15 @@
 AC_HELP_STRING([--enable-video-x11], [use X11 video driver [[default=yes]]]),
                   , enable_video_x11=yes)
     if test x$enable_video = xyes -a x$enable_video_x11 = xyes; then
+        case "$host" in
+            *-*-darwin*)
+                # This isn't necessary for X11, but fixes GLX detection
+                if test "x$x_includes" = xNONE && test "x$x_libraries" = xNONE; then
+                    x_includes="/usr/X11R6/include"
+                    x_libraries="/usr/X11R6/lib"
+                fi
+                ;;
+        esac
         AC_PATH_X
         AC_PATH_XTRA
         if test x$have_x = xyes; then
@@ -813,15 +825,27 @@
                     for path in $x11_lib_path /usr/lib /usr/X11/lib /usr/X11R6/lib; do
                         if test "x$x11_lib" = "x"; then
                             x11_lib=[`ls -- $path/libX11.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+							if test "x$x11_lib" = "x"; then
+								x11_lib=[`ls -- $path/libX11.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+							fi
                         fi
                         if test "x$x11ext_lib" = "x"; then
                             x11ext_lib=[`ls -- $path/libXext.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+							if test "x$x11ext_lib" = "x"; then
+								x11ext_lib=[`ls -- $path/libXext.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+							fi
                         fi
                         if test "x$xrender_lib" = "x"; then
                             xrender_lib=[`ls -- $path/libXrender.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+							if test "x$xrender_lib" = "x"; then
+								xrender_lib=[`ls -- $path/libXrender.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+							fi
                         fi
                         if test "x$xrandr_lib" = "x"; then
                             xrandr_lib=[`ls -- $path/libXrandr.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+							if test "x$xrandr_lib" = "x"; then
+								xrandr_lib=[`ls -- $path/libXrandr.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+							fi
                         fi
                     done
                     ;;
@@ -831,6 +855,8 @@
             if test x$ac_cv_func_shmat != xyes; then
                 X_CFLAGS="$X_CFLAGS -DNO_SHARED_MEMORY"
             fi
+            CFLAGS="$CFLAGS $X_CFLAGS"
+            LDFLAGS="$LDFLAGS $X_LIBS"
 
             AC_DEFINE(SDL_VIDEO_DRIVER_X11)
             SOURCES="$SOURCES $srcdir/src/video/x11/*.c"
@@ -925,10 +951,22 @@
                     fi
                 fi
             fi
-
             if test x$definitely_enable_video_x11_xrandr = xyes; then
                 AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR)
             fi
+            AC_ARG_ENABLE(video-x11-dpms,
+AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]),
+                            , enable_video_x11_dpms=yes)
+            if test x$enable_video_x11_dpms = xyes; then
+                AC_CHECK_HEADER(X11/extensions/dpms.h,
+                                have_dpms_h_hdr=yes,
+                                have_dpms_h_hdr=no,
+                                [#include <X11/Xlib.h>
+                                ])
+                if test x$have_dpms_h_hdr = xyes; then
+                    AC_DEFINE(SDL_VIDEO_DRIVER_X11_DPMS)
+                fi
+            fi
         fi
     fi
 }
@@ -1197,6 +1235,8 @@
          #include <vgl.h>
         ],[
          VGLBitmap bitmap;
+         bitmap.Type = VIDBUF32;
+         bitmap.PixelBytes = 4;
          exit(bitmap.Bitmap);
         ],[
         video_vgl=yes
@@ -1359,7 +1399,7 @@
             video_gem=yes
             AC_DEFINE(SDL_VIDEO_DRIVER_GEM)
             SOURCES="$SOURCES $srcdir/src/video/gem/*.c"
-            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lgem"
+            SDL_LIBS="$SDL_LIBS -lgem"
             have_video=yes
         fi
     fi
@@ -1494,8 +1534,8 @@
         fi
         AC_DEFINE(SDL_VIDEO_OPENGL)
         AC_DEFINE(SDL_VIDEO_OPENGL_OSMESA)
-        EXTRA_CFLAGS="$EXTRA_CFLAGS $OSMESA_CFLAGS"
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS $OSMESA_LIBS"
+        SDL_CFLAGS="$SDL_CFLAGS $OSMESA_CFLAGS"
+        SDL_LIBS="$SDL_LIBS $OSMESA_LIBS"
 
         AC_ARG_ENABLE(osmesa-shared,
 AC_HELP_STRING([--enable-osmesa-shared], [dynamically load OSMesa OpenGL support [[default=yes]]]),
@@ -1597,7 +1637,7 @@
 AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]]),
                   , enable_pthread_sem=yes)
     case "$host" in
-        *-*-linux*)
+        *-*-linux*|*-*-uclinux*)
             pthread_cflags="-D_REENTRANT"
             pthread_lib="-lpthread"
             ;;
@@ -1865,7 +1905,7 @@
         if test x$have_ldg_hdr = xyes -a x$have_ldg_lib = xyes; then
             AC_DEFINE(SDL_LOADSO_LDG)
             SOURCES="$SOURCES $srcdir/src/loadso/mint/*.c"
-            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lldg -lgem"
+            SDL_LIBS="$SDL_LIBS -lldg -lgem"
             have_loadso=yes
         fi
     fi
@@ -2048,9 +2088,10 @@
             have_timers=yes
         fi
         ;;
-    *-*-linux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
+    *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
         case "$host" in
             *-*-linux*)         ARCH=linux ;;
+            *-*-uclinux*)       ARCH=linux ;;
             *-*-kfreebsd*-gnu)  ARCH=kfreebsd-gnu ;;
             *-*-knetbsd*-gnu)   ARCH=knetbsd-gnu ;;
             *-*-kopenbsd*-gnu)  ARCH=kopenbsd-gnu ;;
@@ -2570,9 +2611,6 @@
     if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
       SDL_LIBS="$SDL_LIBS -Wl,-framework,Carbon"
     fi
-    if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
-      SDL_LIBS="$SDL_LIBS -Wl,-framework,OpenGL"
-    fi
     # Evil hack to allow static linking on Mac OS X
     SDL_STATIC_LIBS="\${exec_prefix}/lib/libSDLmain.a \${exec_prefix}/lib/libSDL.a $EXTRA_LDFLAGS"
     ;;
--- a/docs.html	Mon May 01 06:58:33 2006 +0000
+++ b/docs.html	Wed May 17 08:18:28 2006 +0000
@@ -11,779 +11,165 @@
 The latest stable release may be found on the
 	<a href="http://www.libsdl.org/">SDL website</A>.
 </P>
-<P>
 
 <H2> <A HREF="docs/index.html">API Documentation</A> </H2>
+
+<H2> SDL 1.2.10 Release Notes </H2>
 <P>
-
-<H2>
-Major changes since SDL 1.0.0:
-</H2>
+SDL 1.2.10 is a major release, featuring a revamp of the build system and many API improvements and bug fixes.
+</P>
+<H3> API enhancements </H3>
 <UL>
-	<LI> 1.2.9: Numerous improvements to the Atari port (thanks Patrice!)
-	<LI> 1.2.9: SIGTERM and SIGINT handlers are reset when SDL shuts down
-	<LI> 1.2.9: Added support for Visual C++ 2005 (Express Beta 2) to VisualC.zip
-	<LI> 1.2.9: Fixed crash trying to allocate hardware surfaces on MacOS X (thanks Ryan!)
-	<LI> 1.2.9: SDL.dll works on Windows 95 again
-	<LI> 1.2.9: Dropping a document onto an SDL app passes it as a command line parameter in MacOS X (thanks Ryan!)
-	<LI> 1.2.9: Fixed short read problem with SDL_RWFromMem() (thanks Antonio!)
-	<LI> 1.2.9: Added support for SDL_VIDEO_X11_NODIRECTCOLOR on OpenGL visuals
-	<LI> 1.2.9: Altivec optimized blitters (thanks Bob!)
-	<LI> 1.2.9: YUV mmx code should compile with gcc 2.x and 3.x (thanks Stephane!)
-	<LI> 1.2.9: Fixed hang on shutdown using framebuffer console on ia64 (thanks Jesse!)
-	<LI> 1.2.9: Improved RISC OS support (thanks Peter and Alan!)
-	<LI> 1.2.9: Added support for direct color 8-bpp surfaces
-	<LI> 1.2.9: Fixed gcc parse errors in SDL_audio.h on Windows
-	<LI> 1.2.9: Fixed potential crash in multi-threaded timers
-	<LI> 1.2.9: Added support for Tru64 UNIX 4.X (thanks Hayashi!)
-	<LI> 1.2.9: SDL_OPENGLBLIT has been renamed SDL_OPENGLBLIT_OBSOLETE
-	<LI> 1.2.8: Fixed pitch vs width bug in SDL_SaveBMP() (thanks Jonathan!)
-	<LI> 1.2.8: Build ALSA support when building RPM files
-	<LI> 1.2.8: Added support for MacOS X Xcode environment (thanks Eric!)
-	<LI> 1.2.8: Fixed compiling SDL under Linux 2.6.9 (thanks Stephane!)
-	<LI> 1.2.8: Added m68k assembly routines for endianness conversion
-	<LI> 1.2.8: Added OSMesa support to the Atari port (thanks Patrice!)
-	<LI> 1.2.8: Fixed MacOS X mouse coordinate inversion (thanks Eric!)
-	<LI> 1.2.8: Fixed Win32 window centering when resettting video mode (thanks Gautier!)
-	<LI> 1.2.8: Fixed DirectInput intitialization with SDL_WINDOWID (thanks Trevor!)
-	<LI> 1.2.8: Fixed NSWindow release count bug on MacOS X (thanks Bob!)
-	<LI> 1.2.8: Video modes are sorted by width first, then by height
-	<LI> 1.2.8: Improved Atari audio drivers (thanks Patrice!)
-	<LI> 1.2.8: Improved OSS audio support, contributed by OpenSound.com
-	<LI> 1.2.8: Added MacOS X menu options for SDL apps built without a nib (thanks Max!)
-	<LI> 1.2.8: aRts audio driver has been renamed "arts" instead of "artsc"
-	<LI> 1.2.8: Added thread support on RISC OS (thanks Alan!)
-	<LI> 1.2.8: Added support for UTF-8 window titles on MacOS X (thanks Tomas!)
-	<LI> 1.2.8: Set XV_AUTOPAINT_COLORKEY property for X11 YUV support (thanks Christian!)
-	<LI> 1.2.8: Updated libtool support to libtool 1.5.8
-	<LI> 1.2.8: Fixed problem compiling without nasm with new versions of gcc
-	<LI> 1.2.8: Check for malloc() returning NULL in a few places
-	<LI> 1.2.8: Added 4/6 channel surround sound support on ALSA (not 3D audio)
-	<LI> 1.2.8: Added SDL_FB_BROKEN_MODES environment variable
-	<LI> 1.2.8: Fixed memory corruption when allocating large surfaces (fails now)
-	<LI> 1.2.8: Show correct joystick names on Windows (thanks Eckhard!)
-	<LI> 1.2.8: Added a CoreAudio driver for MacOS X (thanks Max!)
-	<LI> 1.2.8: Added support for right handed modifier keys on Panther (thanks Eric!)
-	<LI> 1.2.8: Finally fixed OpenGL coordinate inversion on MacOS X (thanks Eric!)
-	<LI> 1.2.8: Worked around a crash in aRts audio detection (thanks Yves!)
-	<LI> 1.2.8: Lots more Atari video fixes (thanks Patrice!)
-	<LI> 1.2.8: Allow UTF-8 strings in X11 window captions
-	<LI> 1.2.8: Fixed basic type collision on Tru64 (thanks Hayashi!)
-	<LI> 1.2.8: Improved keyboard and mouse handling on BeOS (thanks Marcin!)
-	<LI> 1.2.8: Added missing window manager and OpenGL functions on BeOS
-	<LI> 1.2.8: Fixed resuming CD-ROM playback on Windows (thanks Andreas!)
-	<LI> 1.2.8: Fixed compiling on IRIX 5.3
-	<LI> 1.2.8: Fixed crash if software stretch is used on hardware surfaces
-	<LI> 1.2.8: Fixed crash on exit in framebuffer console driver
-	<LI> 1.2.8: Added support for logical joysticks on Linux
-	<LI> 1.2.8: Added OpenGL accum buffer support on MacOS X (thanks Christian!)
-	<LI> 1.2.8: Fixed pixmap leak in X11 cursor code (thanks Paul!)
-	<LI> 1.2.8: Fixed compilation problems with newer versions of gcc
-	<LI> 1.2.8: Updated QNX support for QNX6 (thanks Mike!)
-	<LI> 1.2.8: Fixed testdyngl crash on Windows (thanks Damien!)
-	<LI> 1.2.8: Compile most of the blitter assembly on Opteron
-	<LI> 1.2.8: Compile CPU detection code on Opteron
-	<LI> 1.2.8: Fixed floating point exception with Linux 2.6 joysticks
-	<LI> 1.2.8: Fixed toggling SDL_NOFRAME on X11 video modes
-	<LI> 1.2.8: Fixed loading ESD and aRts function pointers
-	<LI> 1.2.8: IRIX uses libGL.so, not libGL.so.1
-	<LI> 1.2.8: Fixed typo in fatal signal handling code
-	<LI> 1.2.8: Fix potential deadlock in MacOS X joystick code
-	<LI> 1.2.8: Build FSAA code on all versions of MacOS X (thanks tigital!)
-	<LI> 1.2.8: Avoid using kernel headers for byte swapping macros
-	<LI> 1.2.7: Added a test program for dynamically loading OpenGL
-	<LI> 1.2.7: Increased sensitivity of the Windows joystick driver 
-	<LI> 1.2.7: Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows 
-	<LI> 1.2.7: Added fullscreen toggle support in testwm for Windows, etc. 
-	<LI> 1.2.7: Fixed mouse focus events after resetting video mode on Windows 
-	<LI> 1.2.7: Added colorkey blit tests to testvidinfo (thanks Mike!) 
-	<LI> 1.2.7: Added video hardware acceleration support on QNX (thanks Mike!) 
-	<LI> 1.2.7: SDL no longer sets a fatal signal handler for SIGPIPE 
-	<LI> 1.2.7: Fixed modifier key state on MacOS X (thanks Max!) 
-	<LI> 1.2.7: Added support for remote XVideo (thanks Frederic!) 
-	<LI> 1.2.7: Try to use higher refresh rate by default in DirectX driver (thanks Dmitry!) 
-	<LI> 1.2.7: Fixed static linking on MacOS X (thanks Max!) 
-	<LI> 1.2.7: Various Atari video driver improvements (thanks Patrice!) 
-	<LI> 1.2.7: Fixed compiling with broken Linux 2.6 headers 
-	<LI> 1.2.7: Fixed mouse cursor visibility and focus events on MacOS X (thanks Max!) 
-	<LI> 1.2.7: Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!) 
-	<LI> 1.2.7: Fixed problems with CD-ROM audio playback on MacOS X 10.1 
-	<LI> 1.2.7: Added dynamic GL library loading to MacOS Carbon support (thanks Anders!) 
-	<LI> 1.2.7: Added the ability to hide the cursor in the DirectFB driver (thanks Pete!) 
-	<LI> 1.2.7: Added minor cleanup for Embedded Visual C++ 3.0 (thanks Andy!) 
-	<LI> 1.2.7: Fixed high CPU usage with ALSA audio driver (thanks Michel!) 
-	<LI> 1.2.7: Added function to create RWops from const memory: SDL_RWFromConstMem() 
-	<LI> 1.2.7: Fixed compiling with ALSA 1.0 (thanks Stephane!) 
-	<LI> 1.2.7: Added YUV overlay support on BeOS (thanks Andrew!) 
-	<LI> 1.2.7: Fixed build problems with newer versions of automake
-	<LI> 1.2.7: Fixed MacOS X libtool framework support (thanks Max!) 
-	<LI> 1.2.7: Added CPU feature detection functions to SDL_cpuinfo.h
-	<LI> 1.2.7: Fixed illegal instruction crash using 3DNow on Intel processors 
-	<LI> 1.2.7: Fixed asm issues with mmx.h and gcc 3.3 (thanks Stephane!) 
-	<LI> 1.2.7: Updated libtool support so Mingw32 builds work. 
-	<LI> 1.2.7: Disable screen saver in Windows DIB video driver 
-	<LI> 1.2.7: Added Atari CD-ROM support (thanks Patrice!) 
-	<LI> 1.2.7: Fixed crash calling app defined window proc (thanks Scott!) 
-	<LI> 1.2.7: Fixed long long constant warnings in GCC 3.3.1 (thanks Stephane!) 
-	<LI> 1.2.7: Added configure.in support for K*BSD (thanks Robert!) 
-	<LI> 1.2.7: Added QNX package and audio fixes (thanks Mike!) 
-	<LI> 1.2.7: Fixed joystick open problems on BSD (thanks SUGIMOTO!) 
-	<LI> 1.2.7: Fixed X11 mode line crash with only one video mode (thanks Alan!) 
-	<LI> 1.2.6: Fixed bugs in the Nano-X video driver
-	<LI> 1.2.6: Fixed use of SDL with XInitThreads()
-	<LI> 1.2.6: Added MMX and 3DNow! optimized alpha blitters (thanks Stephane!)
-	<LI> 1.2.6: Turned dynamic loading of ESD and aRts on by default
-	<LI> 1.2.6: Fixed fullscreen mouse click bug in Quartz events (thanks Max!)
-	<LI> 1.2.6: Added an environment variable SDL_VIDEO_WINDOW_POS for MacOS X
-	<LI> 1.2.6: Added SDL_GL_MULTISAMPLEBUFFERS and SDL_GL_MULTISAMPLESAMPLES for FSAA support (thanks Shawn and Ryan!)
-	<LI> 1.2.6: Added audio and CD-ROM support for OSF/Tru64 (thanks Hayashi!)
-	<LI> 1.2.6: Added SDL_LoadObject(), SDL_LoadFunction(), and SDL_UnloadObject()
-	<LI> 1.2.6: Added new Atari audio drivers (thanks Patrice!)
-	<LI> 1.2.6: Added more-than-three mouse button support for the Quartz target
-	<LI> 1.2.6: Fixed compile problem in SDL_stretch.c with gcc 3.3
-	<LI> 1.2.6: Added initial support for RISC OS (thanks Peter and Alan!)
-	<LI> 1.2.6: Improved video mode selection under XFree86 (thanks Despair!)
-	<LI> 1.2.6: Added support for HID sliders wheels and dials on MacOS X
-	<LI> 1.2.6: Added m68k assembly routines for audio mixing (thanks Patrice!)
-	<LI> 1.2.6: Updated FreeBSD joystick USBHID support (thanks Matthew!)
-	<LI> 1.2.6: Fixed video intitialization problem on Qtopia (thanks David!)
-	<LI> 1.2.6: Fixed refresh rate issue with XFree86 4.3.0 (thanks Stephen!)
-	<LI> 1.2.6: Fixed lost cursor bug under MacOS X (thanks Darrell!)
-	<LI> 1.2.6: Fixed crash in SDL_SetIcon() under Quartz (thanks Darrell!)
-	<LI> 1.2.6: Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
-	<LI> 1.2.6: Cth converted the MMX audio mixing routines to VC++ syntax
-	<LI> 1.2.6: David MacCormack fixed a bug in window sizing with Windows menus
-	<LI> 1.2.6: Enable the glXGetProcAddressARB code on X11 (fixes NVidia issues)
-	<LI> 1.2.6: Added support for SDL_WM_GrabInput and SDL_WM_IconifyWindow on Qtopia (thanks David!)
-	<LI> 1.2.6: Almost completely rewritten and improved QNX code (thanks Mike and Julian!)
-	<LI> 1.2.6: Fixed left/right shift detection on Windows (thanks Mike!)
-	<LI> 1.2.6: Fixed invalid memory access in DGA video driver (thanks ldb!)
-	<LI> 1.2.6: Generate an expose event on MacOS X after power save (thanks Darrell!)
-	<LI> 1.2.6: Updated Atari port for new system headers (thanks Patrice!)
-	<LI> 1.2.6: Linux joystick cleanups from Alan Swanson
-	<LI> 1.2.6: *BSD joystick cleanups from Wilbern Cobb
-	<LI> 1.2.6: Worked around Visual C++ 7 optimizer bug in blit code
-	<LI> 1.2.6: Open ALSA devices in non-blocking mode (thanks Aleksey!)
-	<LI> 1.2.6: Updated for DirectDB 0.9.15 (thanks Denis!)
-	<LI> 1.2.6: Fixed building SDL DLL with Watcom C++ (thanks Jean-Pierre)
-	<LI> 1.2.6: Support 1-bit alpha on surfaces passed to SDL_WM_SetIcon() (thanks Glenn!)
-	<LI> 1.2.6: Greatly improved X11 DGA video speed (thanks Cezary!)
-	<LI> 1.2.6: Added MMX audio mixing code for gcc (thanks Stephane!)
-	<LI> 1.2.6: Fixed potential dropped events under DirectInput
-	<LI> 1.2.6: Fixed alpha blending bug (thanks Glenn!)
-	<LI> 1.2.6: Fixed joystick detection on Windows XP (thanks Maciej!)
-	<LI> 1.2.6: Fixed a crash blitting RLE surfaces to RLE surfaces
-	<LI> 1.2.6: Fixed mouse warp position bug with offset video modes
-	<LI> 1.2.6: Fixed windows event handling for ActiveX controls
-	<LI> 1.2.6: Added Visual C++ 7 (.NET) projects (thanks James!)
-	<LI> 1.2.5: Added an environment variable SDL_HAS3BUTTONMOUSE for Quartz
-	<LI> 1.2.5: Added initial support for Dreamcast (thanks HERO!) 
-	<LI> 1.2.5: Implemented resizing Cocoa windows (thanks Darrell!) 
-	<LI> 1.2.5: Updated Quartz video code for MacOS X 10.2 (thanks Darrell!) 
-	<LI> 1.2.5: Added an environment variable SDL_VIDEO_WINDOW_POS for X11
-	<LI> 1.2.5: Fixed mouse focus problems caused by X11 'unclutter' hack 
-	<LI> 1.2.5: Applied John's fix for left-handed mice under Windows. 
-	<LI> 1.2.5: Gamepads and other HID devices should work under MacOS X 
-	<LI> 1.2.5: Fixed missing cursor after shadow buffer flip (thanks Jan!) 
-	<LI> 1.2.5: Updated MacOS projects with "enums as int" build option 
-	<LI> 1.2.5: Added -benchmark flag to testvidinfo for testing video speed 
-	<LI> 1.2.5: Added accelerated YUV code to DirectFB driver (thanks Denis!) 
-	<LI> 1.2.5: Command line apps on MacOS X go to forground (thanks Max!) 
-	<LI> 1.2.5: Fixed aRts runtime sound daemon detection 
-	<LI> 1.2.5: Improved the Nano-X video support (thanks Greg!) 
-	<LI> 1.2.5: Updated Borland projects for Kylix 3 (thanks Dominique) 
-	<LI> 1.2.5: Added compile-time checking for the size of enums 
-	<LI> 1.2.5: Fixed offset bug in hardware accelerated fills and blits 
-	<LI> 1.2.5: Fixed serious bugs in BSD HID joystick code (thanks Krister!) 
-	<LI> 1.2.5: Added project files for embedded Visual C++ 4.0 
-	<LI> 1.2.5: Added SDL_BUTTON_WHEELUP (4) and SDL_BUTTON_WHEELDOWN (5) 
-	<LI> 1.2.5: Added SDL_GL_STEREO for stereoscopic OpenGL contexts 
-	<LI> 1.2.5: Added the environment variable SDL_VIDEO_X11_WMCLASS 
-	<LI> 1.2.5: Fullscreen windows are always topmost in Windows 
-	<LI> 1.2.5: Fixed mouse grab going fullscreen to windowed in Windows 
-	<LI> 1.2.5: Fixed VidMode error when running on XFree86 3.3 
-	<LI> 1.2.5: Fixed Quartz mouse motion and window centering bugs 
-	<LI> 1.2.5: Updated configure.in for automake 1.6.2 
-	<LI> 1.2.5: Fixed building Windows DLL with latest native Cygwin tools 
-	<LI> 1.2.5: Added a way to get the Windows OpenGL context in SDL_syswm.h 
-	<LI> 1.2.5: Removed DDFLIP_WAIT flag from DirectX flip for performance 
-	<LI> 1.2.5: Zeroed SDL_Surface::unused1 so glSDL will work on stock SDL 
-	<LI> 1.2.5: Only modifier key state is noted when X11 window opens 
-	<LI> 1.2.5: Added initial support for PicoGUI (thanks Micah!) 
-	<LI> 1.2.5: Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha 
-	<LI> 1.2.5: Added pthread detection for HP-UX 11.X 
-	<LI> 1.2.5: SDL_Init(SDL_INIT_JOYSTICK) on MacOS X works with no joystick 
-	<LI> 1.2.5: Fixed DirectX software surface memory leak 
-	<LI> 1.2.5: Fixed video initialization crash on Windows CE 
-	<LI> 1.2.5: Updated the QNX audio code for QNX 6.2 (thanks Travis!) 
-	<LI> 1.2.5: Fixed building with pthread and pth support on UNIX 
-	<LI> 1.2.5: Added detection of several joysticks to Linux code 
-	<LI> 1.2.5: Fixed thread detection and joystick code for NetBSD 
-	<LI> 1.2.5: Added support for audio in the Atari port (thanks Patrice!) 
-	<LI> 1.2.5: Added check for ENOMEDIUM to the Linux CDROM code 
-	<LI> 1.2.5: Added YUV hardware acceleration on MacOS X (thanks Darrell!) 
-	<LI> 1.2.5: Fixed building shared libraries on MacOS X (thanks Max!) 
-	<LI> 1.2.5: Use secondary audio buffers in DirectSound by default 
-	<LI> 1.2.5: Fixed window tab on Windows taskbar after application quit 
-	<LI> 1.2.5: Fixed setting OpenGL mode multiple times on Windows 
-	<LI> 1.2.5: Added Zaurus PDA (Qtopia) support by David Hedbor 
-	<LI> 1.2.5: Removed README.OpenBSD - SDL works out of the box on OpenBSD 
-	<LI> 1.2.5: Fixed crash in QZ_SetCaption() (thanks Darrell) 
-	<LI> 1.2.5: Updated ALSA audio support for ALSA 0.9 
-	<LI> 1.2.5: Don't build RPM archives with ALSA library dependencies 
-	<LI> 1.2.5: SDL_PollEvent()/SDL_WaitEvent() return values now match docs 
-	<LI> 1.2.4: Added initial support for Atari (thanks Patrice!)
-	<LI> 1.2.4: Added support for building SDL for EPOC/SymbianOS 6.0
-	<LI> 1.2.4: SDL now compiles and works cleanly on stock BSDI
-	<LI> 1.2.4: Added support for joysticks on *BSD (thanks Wilbern!)
-	<LI> 1.2.4: Added support for Xi Graphics XME fullscreen extension
-	<LI> 1.2.4: Incorporated XFree86 extension libraries into the source
-	<LI> 1.2.4: Dynamically load sound daemon audio drivers on UNIX
-	<LI> 1.2.4: David Snopek added Borland compiler support
-	<LI> 1.2.4: Updated for Watcom and LCC compilers (thanks Jean-Pierre)
-	<LI> 1.2.4: Added a YUV overlay test program (thanks Jon!)
-	<LI> 1.2.4: Fixed gamma ramps in DirectX windowed and OpenGL modes
-	<LI> 1.2.4: John Popplewell fixed mousewheel support on Windows
-	<LI> 1.2.4: Disabled QueryPerformanceCounter() due to problems on Win2K
-	<LI> 1.2.4: Fixed Windows OpenGL mouse cursor/position mismatch bug
-	<LI> 1.2.4: Fixed display settings with ALT-tab and OpenGL on Windows
-	<LI> 1.2.4: Fixed timeout in Linux condition variable implementation
-	<LI> 1.2.4: Fixed bug in joystick detection code under Linux
-	<LI> 1.2.4: Fix crash with Linux supermount fstab entries (thanks Erno!)
-	<LI> 1.2.4: Fixed X11 crash updating rectangles of zero height (thanks Mattias!)
-	<LI> 1.2.4: Fixed spurious keypress at startup on BeOS
-	<LI> 1.2.4: MacOS audio locking has been implemented by Ryan Gordon
-	<LI> 1.2.4: Fixed "short jump out of range" error in MMX code (thanks Steven)
-	<LI> 1.2.4: Specify the SDL API calling convention (C by default)
-	<LI> 1.2.4: Updated autogen.sh for new versions of automake
-	<LI> 1.2.4: Fixed SDL 1.1 RPM dependency problem (thanks Edward!)
-	<LI> 1.2.3: Added X11 Xinerama support - fullscreen starts on screen 0
-	<LI> 1.2.3: Added platform independent OpenGL header - SDL_opengl.h
-	<LI> 1.2.3: Fixed flashing the screen when creating a window on BeOS
-	<LI> 1.2.3: Added double-buffering support for SVGAlib (thanks Kutak!)
-	<LI> 1.2.3: Fixed crash when using double-buffering with DGA
-	<LI> 1.2.3: Fixed resuming a paused CD on Win2K (thanks Aragorn)
-	<LI> 1.2.3: Improved MacOS international keyboard handling (thanks Max!)
-	<LI> 1.2.3: Added support for the GNU Pth thread lib (thanks Mandin!)
-	<LI> 1.2.3: Added the Undo key for the Atari keyboard (thanks Mandin!)
-	<LI> 1.2.3: Fixed XVideo on GeForce by using last available adaptor
-	<LI> 1.2.3: Added CD-ROM support for BSD/OS (thanks Steven!)
-	<LI> 1.2.3: Added library version information to the Windows DLL
-	<LI> 1.2.3: Added initial support for EPOC/Symbian OS (thanks Hannu!)
-	<LI> 1.2.3: Added a joystick driver for MacOS X (thanks Max!)
-	<LI> 1.2.3: Improved MacOS X international keyboard handling
-	<LI> 1.2.3: Added support for DirectFB video on Linux (thanks Denis!)
-	<LI> 1.2.3: Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
-	<LI> 1.2.3: Fixed the system dependent SDL_WINDOWID hack on Windows
-	<LI> 1.2.3: Added 640x480 as a scaled resolution for NTSC/PAL output 
-	<LI> 1.2.3: Added support for TV output on the Linux PlayStation Beta
-	<LI> 1.2.3: Added initial NVidia acceleration on framebuffer console
-	<LI> 1.2.3: Fixed audio format selection for OpenBSD (thanks Peter!)
-	<LI> 1.2.2: Fixed crash when quitting fullscreen mode on MacOS X
-	<LI> 1.2.2: Fixed fullscreen mouse events on MacOS X
-	<LI> 1.2.2: Now returns an error if unable to open audio on BeOS
-	<LI> 1.2.2: Fixed keyboard input translation on WinCE (thanks Rainer!)
-	<LI> 1.2.2: Now gets correct keyboard state when starting up on X11
-	<LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers
-	<LI> 1.2.2: Improved the OpenBSD port (native audio default, etc.)
-	<LI> 1.2.2: Improved OSS audio driver support, thanks to 4Front Tech.
-	<LI> 1.2.2: Improved X11 fullscreen support, works better with KDE
-	<LI> 1.2.2: Improved SDL_GetTicks() resolution on W2K (thanks Holger!)
-	<LI> 1.2.2: Added FreeBSD VGL video driver from FreeBSD ports
-	<LI> 1.2.1: Added Linux PlayStation 2 Graphics Synthesizer support
-	<LI> 1.2.1: Added an audio driver that writes to disk (thanks Ryan!)
-	<LI> 1.2.1: Mouse wheel sends mouse button (4/5) events on Windows
-	<LI> 1.2.1: Added MacOS X Project Builder projects (thanks Darrell!)
-	<LI> 1.2.1: Added initial support for Quartz video (thanks Darrell!)
-	<LI> 1.2.1: Disabled Linux /dev/event joystick interface by default
-	<LI> 1.2.1: Added native OpenBSD audio driver (thanks vedge!)
-	<LI> 1.2.1: Added detection of Open Sound System on Solaris x86
-	<LI> 1.2.1: Added initial support for Nano-X (thanks Hsieh-Fu!)
-	<LI> 1.2.1: Fixed endian detection on IA64 architectures (thanks Bill!)
-	<LI> 1.2.1: Added --disable-dga configure option to disable DGA
-	<LI> 1.2.1: Fixed stuck keys when changing the video mode
-	<LI> 1.2.1: Fixed double-mouse event bug on Windows using OpenGL
-	<LI> 1.2.1: Fixed 320x200 video mode on framebuffer console
-	<LI> 1.2.1: Improved robustness for the ELO touchpad (thanks Alex!)
-	<LI> 1.2.1: Added support for building under Cygwin on Windows
-	<LI> 1.2.1: Added a dummy video driver for benchmarking (thanks Ryan!)
-	<LI> 1.2.1: Fixed fullscreen cursor offset bug on BeOS
-	<LI> 1.2.0: Added initial support for HP-UX (thanks Stephanie)
-	<LI> 1.2.0: Added initial support for BSDI (thanks Kurt)
-	<LI> 1.2.0: Fixed blitting 32-bit ARGB images to SDL_OPENGLBLIT screens
-	<LI> 1.2.0: Fixed automake build dependencies (thanks Markus!)
-	<LI> 1.2.0: Added 24 bpp support to software YUV display functions
-	<LI> 1.2.0: Don't bomb trying to get DGA mouse on XFree86 4.0
-	<LI> 1.2.0: Added initial support for OSF/Tru64 (thanks Anders)
-	<LI> 1.1.8: Fixed joystick hat motion on MacOS
-	<LI> 1.1.8: Don't detect mouse and keyboard as joystick on MacOS
-	<LI> 1.1.8: Check for OpenGL 1.2 before using 16-bit SDL_OPENGLBLIT
-	<LI> 1.1.8: Added support for /dev/sound/* in Linux 2.4
-	<LI> 1.1.8: Fixed crash when blitting to RLE encoded surfaces
-	<LI> 1.1.8: Fixed 8-bit audio on MacOS X
-	<LI> 1.1.8: Fixed keyboard handling on MacOS X and MacOS classic
-	<LI> 1.1.8: Fixed mouse cursor visibility when switching apps on MacOS
-	<LI> 1.1.8: Implemented semaphore support on MacOS X
-	<LI> 1.1.8: Worked around broken sem_getvalue() on MacOS X
-	<LI> 1.1.8: Fixed 16-bit big-endian audio on MacOS X and MacOS classic
-	<LI> 1.1.8: Fixed mutex locking on Linux glibc 2.0
-	<LI> 1.1.8: SDL_Quit() removes the parachute signal handlers
-	<LI> 1.1.8: Added NAS audio server support (thanks Erik!)
-	<LI> 1.1.8: Added SDL_NOFRAME for frameless windows (thanks Andreas)
-	<LI> 1.1.8: Added support for resizable windows on MacOS
-	<LI> 1.1.8: Added a function to query the surface clip rectangle
-	<LI> 1.1.8: Added a function to query the current event filter
-	<LI> 1.1.8: The X11 XVideo adapter is now locked (thanks Jeffrey)
-	<LI> 1.1.8: Improved the speed of fullscreen OpenGL on Windows
-	<LI> 1.1.8: Added ELO touchscreen support for fbcon (thanks Alex)
-	<LI> 1.1.8: Added accelerated MacOS X OpenGL support
-	<LI> 1.1.8: Surface lock and unlock operations can now be nested
-	<LI> 1.1.8: Optimized fillrect for PPC video memory (thanks Mattias)
-	<LI> 1.1.8: Work around "blackout" problem with XVideo acceleration
-	<LI> 1.1.8: Obtain correct key state on X11 focus (thanks Mattias)
-	<LI> 1.1.8: Fixed keyboard handling on the framebuffer console
-	<LI> 1.1.8: Added basic support for VGA16 framebuffer console
-	<LI> 1.1.8: Open a new virtual terminal if possible on fbcon
-	<LI> 1.1.8: Fixed default audio driver on FreeBSD (thanks Maxim)
-	<LI> 1.1.8: Fixed joystick crash on Windows (thanks Pete)
-	<LI> 1.1.7: Expanded documentation from the SDL Documentation Project
-	<LI> 1.1.7: Report X11 client message events if SYSWMEVENTS enabled
-	<LI> 1.1.7: Added support for a single hat on Windows joysticks
-	<LI> 1.1.7: The gamma ramp routines now take arrays of Uint16 values
-	<LI> 1.1.7: Added initial support for QNX RTP (thanks Patrick)
-	<LI> 1.1.7: Added ALSA sound driver (thanks Patrick Trainor)
-	<LI> 1.1.7: Added aRts UNIX sound driver (thanks Neil Stevens)
-	<LI> 1.1.7: Get keyboard modifier state on input focus on Win32
-	<LI> 1.1.7: SDL_ConvertSurface() now accepts SDL_RLEACCEL as a flag
-	<LI> 1.1.7: Added initial UnixWare 7 support (thanks rr)
-	<LI> 1.1.7: Added working YUY -> RGB conversion code (thanks Eugene)
-	<LI> 1.1.7: Fixed video initialization crash on IRIX
-	<LI> 1.1.7: Fixed MacOS fullscreen palette code (thanks Darrell)
-	<LI> 1.1.7: Fixed background brush flicker on Win32 (thanks Gautier)
-	<LI> 1.1.7: Fixed incorrect pitch when switching to window on Win32
-	<LI> 1.1.7: Fixed memory leak when switching video modes on Win32
-	<LI> 1.1.7: Init of fbcon shouldn't automatically set graphics mode
-	<LI> 1.1.6: Allow SDL_VIDEO_INIT when built without thread support
-	<LI> 1.1.6: Fixed palette problems with non-X11 fullscreen displays
-	<LI> 1.1.6: Fixed Win32 crash with SDL_OPENGLBLIT and GL functions
-	<LI> 1.1.6: Improved default MacOS millisecond time resolution
-	<LI> 1.1.6: Fixed X11 overlapping endian blit bug (thanks Mattias)
-	<LI> 1.1.6: Fixed starting directory on BeOS (thanks Samuel)
-	<LI> 1.1.6: Integrated FreeBSD SVGAlib support (thanks folks)
-	<LI> 1.1.6: Fixed middle-button handling on DirectInput
-	<LI> 1.1.6: Added SDL_GetThreadID() to get a specific thread's ID
-	<LI> 1.1.6: Worked around a crash in pthreads on RedHat 7
-	<LI> 1.1.6: Fixed a brown-bag crash in clipping code
-	<LI> 1.1.5: Convert from '/' to ':' opening files on MacOS
-	<LI> 1.1.5: Clean up empty output files on Win32 and MacOS 
-	<LI> 1.1.5: Run command dialog if command key on startup on MacOS
-	<LI> 1.1.5: Initial NetBSD support (thanks Krister Walfridsson)
-	<LI> 1.1.5: Expanded the YUV overlay to handle odd (ATI) hardware
-	<LI> 1.1.5: Fixed MacOS GL attribute selection (thanks Darrell)
-	<LI> 1.1.5: Implemented gamma correction on 8-bit hardware displays
-	<LI> 1.1.5: Performed logical/physical palette split (thanks Mattias)
-	<LI> 1.1.5: Added initial MacOS X support (thanks Stan)
-	<LI> 1.1.5: SDL_WarpMouse() now works on BeOS (thanks Christian)
-	<LI> 1.1.5: Windows GDI driver now supports 565 modes (thanks Ben)
-	<LI> 1.1.5: Correctly load OpenGL extensions on Win32 (thanks Beosil)
-	<LI> 1.1.5: Fixed crash with some threaded audio drivers
-	<LI> 1.1.5: Audio is now closed in SDL_Quit(), if necessary
-	<LI> 1.1.5: Win32 version now uses MSVC multi-threaded DLL runtime
-	<LI> 1.1.5: Replaced useless SDL_SetClipping() with SDL_SetClipRect()
-	<LI> 1.1.5: Added a flag to YUV overlays to show hardware support
-	<LI> 1.1.5: Added SDL_WasInit() to see what is currently initialized
-	<LI> 1.1.5: YUV overlays can now be accelerated with DirectX
-	<LI> 1.1.5: YUV overlays now have working pitch (thanks Vivien)
-	<LI> 1.1.5: Prompt the user if MacOS mode change may damage hardware
-	<LI> 1.1.5: Fixed DrawSprocket video mode lists and mode changes
-	<LI> 1.1.5: Added DrawSprocket acceleration of colorkey blits
-	<LI> 1.1.5: MacOS event handling is much more responsive by default
-	<LI> 1.1.5: MacOS modifier keys now generate key events
-	<LI> 1.1.5: Mattias Engdegård did the "Great Alpha Flip"
-	<LI> 1.1.5: Added SDL_DisplayFormatAlpha() for fast alpha blits
-	<LI> 1.1.5: Added SDL_MapRGBA() and SDL_GetRGBA() to handle alpha
-	<LI> 1.1.5: SDL_SetAlpha() now accepts the SDL_RLEACCEL flag
-	<LI> 1.1.5: Blit semantics involving alpha are now well defined
-	<LI> 1.1.5: Added support for X11 DirectColor visuals for gamma API
-	<LI> 1.1.5: Added initial AmigaOS support (thanks Gabriele Greco)
-	<LI> 1.1.5: Added an initial gamma correction API (thanks Daniel)
-	<LI> 1.1.5: Disable DGA mouse while X11 application is iconified
-	<LI> 1.1.5: Allow 16-bit audio on Solaris (thanks Mattias)
-	<LI> 1.1.5: Added RLE acceleration of alpha blits (thanks Mattias)
-	<LI> 1.1.5: New documentation from the SDL Documentation Project
-	<LI> 1.1.4: Work around window resize bug in KDE 1.2
-	<LI> 1.1.4: Command-click is interpreted as right click on MacOS
-	<LI> 1.1.4: Removed ESounD detection on Solaris
-	<LI> 1.1.4: Updated to libtool 1.3.5 and latest config.guess
-	<LI> 1.1.4: testgl now works on 8-bit displays under X11
-	<LI> 1.1.4: SDL_WINDOWID hack now works with OpenGL on Linux
-	<LI> 1.1.4: Builds correctly on UNIX without X11 installed
-	<LI> 1.1.4: Fixed default GL driver loading on Win32
-	<LI> 1.1.4: Implemented fullscreen toggle on BeOS (thanks David)
-	<LI> 1.1.4: No longer use DirectDraw with OpenGL modes on Win32
-	<LI> 1.1.4: Added support for 320x200x8 in SVGAlib (thanks Michele)
-	<LI> 1.1.4: Implemented resizable windows on BeOS (thanks David)
-	<LI> 1.1.4: RLE colorkey encoding reduces memory use (thanks Mattias)
-	<LI> 1.1.4: The CD track length variable is now 32-bits (thanks Martin)
-	<LI> 1.1.4: Fixed crashing bug in Win32 semaphores (thanks Markus)
-	<LI> 1.1.4: Disabled aggresive gcc optimizations on X86
-	<LI> 1.1.4: Added support for blitting with GL (thanks Daniel Vogel)
-	<LI> 1.1.4: Improved the speed of the 16-bit colorkey copy blit
-	<LI> 1.1.4: Fixed pthread condition variable timeout
-	<LI> 1.1.3: Use timeGetTime() instead of GetTickCount() on Win32
-	<LI> 1.1.3: Release mouse when popped out of fullscreen on X11
-	<LI> 1.1.3: IRIX 6.5 and FreeBSD 4.0 are now officially supported
-	<LI> 1.1.3: Added optimization flags when compiling on x86 with gcc
-	<LI> 1.1.3: On BeOS, change to app directory when launched by Tracker
-	<LI> 1.1.3: Hold the option key on launch to get dialog on MacOS
-	<LI> 1.1.3: Added DrawSprockets on MacOS (thanks Darrell Walisser)
-	<LI> 1.1.3: Added support for Linux 2.4 input interface (HID)
-	<LI> 1.1.3: Fixed 24-bpp blits on big-endian systems (thanks Mattias)
-	<LI> 1.1.3: Don't try to use DGA mouse support on XFree86 4.00
-	<LI> 1.1.3: Don't create an X11 shared memory buffer for GL displays
-	<LI> 1.1.3: Framebuffer console acceleration disabled (broken) on G200
-	<LI> 1.1.3: Allow maximize on resizable Win32 surfaces (thanks Randi)
-	<LI> 1.1.3: Much faster RLE colorkey blit (thanks Xark and Mattias)
-	<LI> 1.1.3: Fixed some problems with iconification and focus in X11
-	<LI> 1.1.3: Added IMPS/2 protocol support for framebuffer console
-	<LI> 1.1.3: Added user-resizable video mode support
-	<LI> 1.1.3: Added arbitrary scaling of YUV overlay surfaces
-	<LI> 1.1.3: Added support for semaphores and condition variables
-	<LI> 1.1.3: Added SDL_ASYNCBLIT flag for asynchronous video updates
-	<LI> 1.1.3: Don't let the WM place window in X11 fullscreen mode
-	<LI> 1.1.3: Unload GL library after X11 display has closed
-	<LI> 1.1.3: Fixed X11 error when a clipped rectangle is updated
-	<LI> 1.1.3: Fixed crash when surface memory can't be allocated
-	<LI> 1.1.3: Added a check for DirectX 5 audio (thanks Markus)
-	<LI> 1.1.3: Added inline MMX assembly for YUV -> RGB conversion
-	<LI> 1.1.3: Fixed startup crash in X11_RefreshDisplay()
-	<LI> 1.1.3: SDL_Init(SDL_INIT_AUDIO) no longer fails with no soundcard
-	<LI> 1.1.3: Initial YUV video overlay support (supports XvImages)
-	<LI> 1.1.3: Fixed BadMatch X11 error with GLX 1.3
-	<LI> 1.1.3: Worked around incompatibilities with XFree86 4.0 vidmode
-	<LI> 1.1.3: The audio Makefile no longer takes forever to create
-	<LI> 1.1.3: The joystick hat positions changed to constants
-	<LI> 1.1.3: Fixed overlapping copy blit with odd widths
-	<LI> 1.1.3: Fix for SDL_WINDOWID crash contributed by Mattias
-	<LI> 1.1.3: Speeded up 32-bit alpha channel blits by nearly 100%
-	<LI> 1.1.3: Added experimental DGA 2.0 support (set SDL_VIDEODRIVER)
-	<LI> 1.1.2: Fixed crash running on NT with a read-only filesystem
-	<LI> 1.1.2: Re-use thread creation mutex on glibc-2.0 systems
-	<LI> 1.1.2: SDL_WM_SetIcon() now uses icon colorkey if mask is NULL
-	<LI> 1.1.2: Win32 relative mouse mode fixes (thanks Randi Relander)
-	<LI> 1.1.2: Not being able to set audio frags is no longer fatal
-	<LI> 1.1.2: Added support for multiple timers (thanks Stephane Peter)
-	<LI> 1.1.2: Copy blits optimized using inline assembly on x86 Linux
-	<LI> 1.1.2: Copy blit can now handle overlapping blits
-	<LI> 1.1.2: Fixed GL direct rendering on Utah GLX (thanks John Fulmer)
-	<LI> 1.1.2: Added unofficial support for AIX (thanks Carsten Griwodz)
-	<LI> 1.1.2: Enabled X11 VidMode extension on remote displays
-	<LI> 1.1.2: Load libGL.so.1 under X11 if an app isn't linked with GL
-	<LI> 1.1.2: Don't restack windows in the X11 environment
-	<LI> 1.1.2: Multiple X11 visual support (thanks Mattias Engdegård)
-	<LI> 1.1.0: Internal event state is updated before filter is called
-	<LI> 1.1.0: Worked around DGA mouse cursor bug in Voodoo X server
-	<LI> 1.1.0: Added SDL OpenGL documentation (thanks Nicholas Vining)
-	<LI> 1.1.0: Added AAlib video driver support (thanks Stephane Peter)
-	<LI> 1.1.0: Added fullscreen support for Win32 GDI video driver
-	<LI> 1.1.0: Added SDL_GetAudioState() to get current audio status
-	<LI> 1.1.0: Added SDL_GetRelativeMouseState() to get relative motion
-	<LI> 1.1.0: Added 32-bit PII MMX optimized blitters from Hermes
-	<LI> 1.1.0: Added SDL_bool datatype for functions returning true/false
-	<LI> 1.1.0: Improved alpha blend speed (thanks Alexandre Courbot)
-	<LI> 1.1.0: Added function to queue events: SDL_PushEvent()
-	<LI> 1.1.0: Added user-defined event type to SDL_Event structure
-	<LI> 1.1.0: Added SDL_InitSubSystem() and SDL_QuitSubSystem()
-	<LI> 1.1.0: Added BDirectWindow fullscreen support on BeOS
-	<LI> 1.1.0: Added initial joystick support (Linux, Win32, BeOS, MacOS)
-	<LI> 1.1.0: The timer now runs in a separate thread if possible
-	<LI> 1.1.0: Added initial OpenGL support (Linux, Win32, BeOS, MacOS)
-	<LI> 1.0.9: Avoid potential crash in Win32 mouse handling (thanks Cliff)
-	<LI> 1.0.9: Fixed bug where /dev/dsp was incorrectly marked available
-	<LI> 1.0.9: Fixed DirectX crash if video height is larger than width
-	<LI> 1.0.9: Fixed win32 timer error message typo (thanks Martin Dvorak)
-	<LI> 1.0.8: Fixed deadlock if SDL_LockAudio() called from audio thread
-	<LI> 1.0.8: Fixed a race condition in thread creation
-	<LI> 1.0.7: Added detection for Linux supermount CD-ROM drives
-	<LI> 1.0.6: Added --static-libs option to sdl-config
-	<LI> 1.0.6: Fixed a clipping bug in the RLE colorkey blitting
-	<LI> 1.0.6: Mouse window manager routines implemented on MacOS
-	<LI> 1.0.6: Fixed SDL_HWPALETTE in fullscreen X11 video driver
-	<LI> 1.0.6: Improved relative mouse warping in X11 video driver
-	<LI> 1.0.6: DGA mouse mode is now enabled by SDL_VIDEO_X11_DGAMOUSE
-	<LI> 1.0.6: Grab input by default in fullscreen mode
-	<LI> 1.0.6: Detect hanging (incorrectly configured) Linux soundcard
-	<LI> 1.0.6: If ESPEAKER env variable is set, use ESD audio driver
-	<LI> 1.0.5: Fixed audio structure alignment for packing compilers
-	<LI> 1.0.5: Exposed SDL_AudioInit() and SDL_VideoInit()
-	<LI> 1.0.5: Added SDL_WM_ToggleFullScreen(), implemented for X11
-	<LI> 1.0.5: Removed ALT-Enter functionality - should be in apps
-	<LI> 1.0.5: The DSP audio driver is used by default on Linux
-	<LI> 1.0.4: Added optional DMA support for the Linux audio driver
-	<LI> 1.0.4: Fixed CD-ROM opening on the iBook under MacOS
-	<LI> 1.0.4: Fixed a crash in 8-bit mode when using X11 video
-	<LI> 1.0.4: Initial audio support on MacOS (thanks Darrell Walisser)
-	<LI> 1.0.4: The audio thread runs at high priority on Win32
-	<LI> 1.0.4: ESD audio support is now a separate selectable driver
-	<LI> 1.0.4: Initial OpenBSD support (thanks Federico Schwindt)
-	<LI> 1.0.4: Fixed hang when closing audio on Windows 2000
-	<LI> 1.0.4: Warn about monochrome X displays (thanks Christian Bauer)
-	<LI> 1.0.4: Fixed spurious X11 mouse focus events at ALT-ENTER
-	<LI> 1.0.4: Perform input ungrab at video quit, just in case
-	<LI> 1.0.4: Corrected X11 depth reporting in SDL_VideoModeOK()
-	<LI> 1.0.3: Disable mouse threshold when X11 mouse is in warp mode
-	<LI> 1.0.3: Fixed black-screen on exit in fbcon video driver
-	<LI> 1.0.3: Much improved console switching in fbcon video driver
-	<LI> 1.0.3: Fixed X11 UNICODE translation bug (thanks Andreas Arens)
-	<LI> 1.0.3: Fixed WaveOut mutex logic bug (thanks Markus Oberhum)
-	<LI> 1.0.3: Use X11 mouse warping when cursor hidden and input grabbed
-	<LI> 1.0.3: Doesn't try to use TrackMouseEvent() on Win95
-	<LI> 1.0.3: DirectColor support in fbcon driver (thanks Adam Meyerowitz)
-	<LI> 1.0.3: Fixed ALT-ENTER key state problem on X11
-	<LI> 1.0.2: Fixed Win32 code to run on VMWare with DIB video driver
-	<LI> 1.0.2: Added window manager function: SDL_WM_GrabInput()
-	<LI> 1.0.2: Added window manager function: SDL_WM_IconifyWindow()
-	<LI> 1.0.2: Added ALT-ENTER fullscreen toggle for X11 video driver
-	<LI> 1.0.2: X11 fullscreen mode uses DGA mouse if cursor is hidden
-	<LI> 1.0.2: New X11 fullscreen code doesn't require root
-	<LI> 1.0.2: Mouse focus and position is now updated at video mode set
-	<LI> 1.0.2: Mouse focus loss is now detected under Win32
-	<LI> 1.0.2: Menubar hiding is more robust on MacOS (thanks Matt Slott)
-	<LI> 1.0.2: Added CD-ROM support on MacOS (thanks Matt Slott)
-	<LI> 1.0.2: Added non-root fullscreen modes under X11 (thanks Stephane)
-	<LI> 1.0.2: Added docs for time functions (thanks Christian Biesinger)
-	<LI> 1.0.2: Squeezed a little more speed out of blitters (Duff's device)
-	<LI> 1.0.2: Added hardware acceleration for 3Dfx to fbcon driver.
-	<LI> 1.0.2: Added hardware acceleration for Matrox to fbcon driver.
-	<LI> 1.0.2: Windows mouse driver now recognizes the middle button.
-	<LI> 1.0.2: X11 driver now recognizes the "unix:0" display as local.
-	<LI> 1.0.2: Fixed a bug in DGA support which crashed some X servers.
-	<LI> 1.0.2: Added GPM repeater support (gpm -R) to fbcon driver
-	<LI> 1.0.2: Added support for hardware surfaces to fbcon driver
-	<LI> 1.0.2: Implemented console switching in fbcon driver
-	<LI> 1.0.2: Implemented graphics mode detection in fbcon driver
-	<LI> 1.0.2: Added SDL_EnableKeyRepeat() (thanks Jim Kutter)
-	<LI> 1.0.2: Enabled DirectSound on Windows 2000
-	<LI> 1.0.1: Fixed the frame buffer video driver on LinuxPPC
-	<LI> 1.0.1: Stopped using DirectSound on Windows NT.
-	<LI> 1.0.1: Stopped using DirectX when DINPUT.DLL is not installed.
-	<LI> 1.0.1: Added pthread detection to configure.in for FreeBSD.
-	<LI> 1.0.1: Updated the Solaris audio code for the 1.0 API
-	<LI> 1.0.1: Updated the MacOS code for the 1.0 internal API
+<LI>
+	If SDL_OpenAudio() is passed zero for the desired format
+	fields, the following environment variables will be used
+	to fill them in:
+<pre><code>
+		SDL_AUDIO_FREQUENCY
+		SDL_AUDIO_FORMAT
+		SDL_AUDIO_CHANNELS
+		SDL_AUDIO_SAMPLES
+</code></pre>
+	If an environment variable is not specified, it will be set
+	to a reasonable default value.
+<LI>
+	SDL_SetVideoMode() now accepts 0 for width or height and will use
+	the current video mode (or the desktop mode if no mode has been set.)
+<LI>
+	Added current_w and current_h to the SDL_VideoInfo structure,
+	which is set to the desktop resolution during video intialization,
+	and then set to the current resolution when a video mode is set.
+<LI>
+	SDL_GL_LoadLibrary() will load the system default OpenGL library
+	if it is passed NULL as a parameter.
+<LI>
+	Added SDL_GL_SWAP_CONTROL to wait for vsync in OpenGL applications.
+<LI>
+	Added SDL_GL_ACCELERATED_VISUAL to guarantee hardware acceleration.
+<LI>
+	SDL_WM_SetCaption() now officially takes UTF-8 title and icon strings, and displays international characters on supported platforms.
+<LI>
+	Added SDL_GetKeyRepeat() to query the key repeat settings.
+<LI>
+	Added the "dummy" audio driver, which can be used to emulate audio
+	output without a sound card.
+<LI>
+	Added SDL_config.h, with defaults for various build environments.
 </UL>
 
-<H2>
-Major changes since SDL 0.10.0:
-</H2>
-<UL>
-	<LI> 0.11.5: Fixed mouse warping in fullscreen mode
-	<LI> 0.11.5: Added a new function SDL_GetVideoSurface()
-	<LI> 0.11.5: Renamed SDL_AllocSurface() SDL_CreateRGBSurface()
-	<LI> 0.11.5: Added a new function SDL_CreateRGBSurfaceFrom()
-	<LI> 0.11.4: Added support for multiple compiled-in video drivers
-	<LI> 0.11.3: Fixed 16 --> 32 bpp blitting - using C instead of Hermes. 
-	<LI> 0.11.3: Fixed double-buffering bug in the DirectX driver
-	<LI> 0.11.3: Added GGI video driver (thanks Jon Taylor)
-	<LI> 0.11.2: Added automake/aclocal/autoconf support
-	<LI> 0.11.1: Added an initial (buggy) MacOS CD-ROM driver
-	<LI> 0.11.1: Improved Linux CD-ROM detection
-	<LI> 0.11.1: Added a workaround for DGA mouse bug on Voodoo 3
-	<LI> 0.11.1: Fixed 24bpp --> 8bpp blit crash
-	<LI> 0.11.1: Fixed a bug in blit mapping when palette changed
-	<LI> 0.11.1: Added a Linux SBLive beta driver workaround
-	<LI> 0.11.1: Fixed Win32 cross-compile problem with mingw32
-	<LI> 0.11.1: Loss of keyboard focus now causes keys to be reset
-	<LI> 0.11.1: DGA DirectMouse is conditionally compiled (default off)
-</UL>
+<H3> General Notes </H3>
+
+<BLOCKQUOTE>
+<P>
+	The SDL website now has an <A HREF="http://www.libsdl.org/rss/rss.xml">RSS feed</A>!
+<P>
+	The SDL development source code is now managed with <A HREF="http://www.libsdl.org/svn.php">Subversion</A>.
+<P>
+	SDL now uses the Bugzilla <A HREF="http://bugzilla.libsdl.org/">bug tracking system</A>, hosted by icculus.org.
+<P>
+	SDL is licensed under version 2.1 of the GNU Lesser General Public License.
+<P>
+	The entire build system has been revamped to make it much more portable, including versions of C library functions to make it possible to run SDL on a minimal embedded environment.  See README.Porting in the SDL source distribution for information on how to port SDL to a new platform.
+<P>
+	SDL_opengl.h has been updated with the latest glext.h from <A HREF="http://oss.sgi.com/projects/ogl-sample/registry/">http://oss.sgi.com/projects/ogl-sample/registry/</A>
+<P>
+	Alex Volkov contributed highly optimized RGB <-> RGBA blitters.
+</BLOCKQUOTE>
+
+<H3> Unix Notes </H3>
 
-<H2>
-Major changes since SDL 0.8.0:
-</H2>
-<UL>
-	<LI> 0.9.16: Made SDL error messages thread-safe
-	<LI> 0.9.15: If you have r/w access to /dev/mem, DGA works on Linux
-	<LI> 0.9.15: Added support for Linux on the ARM (Netwinder)
-	<LI> 0.9.14: Removed color cursor support, fixed b/w cursors
-	<LI> 0.9.14: Fixed long-standing X11 DGA colormap problem
-	<LI> 0.9.13: Added dynamic load function: SDL_SetLibraryPath()
-	<LI> 0.9.13: Added unofficial support for MacOS
-	<LI> 0.9.13: Added unofficial support for FreeBSD
-	<LI> 0.9.13: Added unofficial support for IRIX
-	<LI> 0.9.13: Updated support for BeOS from R3 to R4.5
-	<LI> 0.9.13: Added SDL_SetLibraryPath() function (thanks Karsten Laux)
-	<LI> 0.9.13: Fixed 8-bit audio conversion when using SDL_MixAudio()
-	<LI> 0.9.13: Fixed audio thread lingering when app dies on Linux
-	<LI> 0.9.13: Fixed color problem in X display to other-endian systems
-	<LI> 0.9.13: Finally able to detect X11 key repeat (thanks GII team!)
-	<LI> 0.9.13: Added support for Visual C++ 5.0 development environment
-	<LI> 0.9.13: Added support for Linux on the Alpha
-	<LI> 0.9.13: Added support for international keyboards (see WhatsNew)
-	<LI> 0.9.12: Added support for loading IMA ADPCM compressed WAV files
-	<LI> 0.9.12: Fixed bug when mixing 8-bit audio in SDL_MixAudio()
-	<LI> 0.9.12: Added Enlightenment Sound Daemon audio support on Linux
-	<LI> 0.9.12: Added MTRR support for Linux/X11 (thanks David Barth)
-	<LI> 0.9.12: Added support for LinuxPPC 5.0
-	<LI> 0.9.12: Fixed place where some audio conversions aren't detected
-	<LI> 0.9.12: Fixed serious bug in installation script
-	<LI> 0.9.12: Added SDL_FreeWAV() function for freeing DLL memory
-	<LI> 0.9.12: Fixed potential memory leak in SDL_LoadWAV_RW()
-	<LI> 0.9.11: Freeing video surface has no longer crashes SDL_Quit()
-	<LI> 0.9.11: Included new asm blitters from Hermes library 1.2.4
-	<LI> 0.9.11: SDL_WaitThread() now gets the thread's return status
-	<LI> 0.9.11: SDL_MixAudio() takes a larger volume range (0-128)
-	<LI> 0.9.11: SDL no longer changes the X11 keyboard repeat
-	<LI> 0.9.11: Added a data source abstraction for loading/saving data
-	<LI> 0.9.11: Added three built in data abstractions:<BR>
-	               SDL_RWFromFile(), SDL_RWFromFP(), SDL_RWFromMem()
-	<LI> 0.9.11: Added stdio-like functions for using data sources:<BR>
-	               SDL_RWseek(), SDL_RWread(), SDL_RWwrite(), SDL_RWclose()
-	<LI> 0.9.11: Replaced SDL_CalculateEndian() with SDL_BYTEORDER macro
-	<LI> 0.9.11: Endian swapping functions are now macros, for speed.
-	<LI> 0.9.11: Endian read/write functions now use data sources
-	<LI> 0.9.11: Added function SDL_LoadWAV_RW() for data sources
-	<LI> 0.9.11: Added function SDL_LoadBMP_RW() for data sources
-	<LI> 0.9.11: Added function SDL_SaveBMP_RW() for data sources
-	<LI> 0.9.10: Mixer no longer fails if timidity isn't installed
-	<LI> 0.9.10: Mixer restarts MOD files on play (thanks Bill Kendrick)
-	<LI> 0.9.10: Fixed occasional crashing of the mixer library
-	<LI> 0.9.10: Fixed icon display on Afterstep under Linux
-	<LI> 0.9.10: Fixed occasional crash in mixer example
-	<LI> 0.9.10: Linux cdrom list now comes from /etc/fstab
-	<LI> 0.9.10: Fixed support for UK keyboard (thanks John Elliott)
-	<LI> 0.9.10: The event queue is now thread-safe
-	<LI> 0.9.10: Added event queue pump function: SDL_PumpEvents()
-	<LI> 0.9.10: Added low level event function: SDL_PeepEvents()
-	<LI> 0.9.10: Added a new thread function: SDL_ThreadID()
-	<LI> 0.9.10: Fixed an audio rate conversion memory overrun
-	<LI> 0.9.10: Fixed crash with RLE acceleration on big surfaces
-	<LI> 0.9.10: Improved MacOS display driver - added fullscreen
-	<LI> 0.9.10: Removed spurious warnings from Linux X11 driver
-	<LI> 0.9.10: Fixed memory leak in SDL_InvalidateMap()
-	<LI> 0.9.10: Fixed right button of 2-button mice on Win32
-	<LI> 0.9.10: Enabled XFree86 mode changes on older servers
-	<LI> 0.9.9: SDL_LoadBMP() handles BMP files created with GIMP
-	<LI> 0.9.9: SDL_LoadWAV() handles WAV files with "LIST" chunks
-	<LI> 0.9.9: Fixed problem with audio underflow on Solaris
-	<LI> 0.9.9: Initial support for 4-speaker audio output devices
-	<LI> 0.9.8: Fixed corrupt VC++ 5.0 desktop file
-	<LI> 0.9.8: Now detects fixed version of Metro-X X11 server
-	<LI> 0.9.8: Fixed XFree86 DGA banked mode update
-	<LI> 0.9.8: Fixed mouse press viewport shift on XFree86 DGA
-	<LI> 0.9.7: Fixed problem with displaying remotely via X11
-	<LI> 0.9.7: Win32 uses software cursor when fullscreen
-	<LI> 0.9.7: Win32 mouse uses DirectInput when fullscreen
-	<LI> 0.9.7: Added OpenGL software rendering via Mesa (demos archive)
-	<LI> 0.9.7: Fixed memory leak in ADPCM WAV decoding
-	<LI> 0.9.6: Added CD-ROM audio API documentation
-	<LI> 0.9.6: Fixed potential BeOS audio-related crash
-	<LI> 0.9.6: Fixed crash when resetting the video mode in DirectX
-	<LI> 0.9.6: Fixed errors compiling with the SparcWorks compiler
-	<LI> 0.9.6: Replaced SDL_GetDisplayFormat() with SDL_GetVideoInfo()
-	<LI> 0.9.6: Added a new fast fill function: SDL_FillRect()
-	<LI> 0.9.6: Added blit acceleration flags to SDL_AllocSurface()
-	<LI> 0.9.6: Added new double-buffering function: SDL_Flip()
-	<LI> 0.9.6: Fixed problem with buggy Metro-X X11 server
-	<LI> 0.9.6: Fixed 8-bit audio on Solaris with dbri hardware
-	<LI> 0.9.6: Fixed alarm clock problem with Solaris pthreads
-	<LI> 0.9.6: Fixed BeOS compilation problem
-	<LI> 0.9.5: Added tools to create Win32 icons in directx/icon/
-	<LI> 0.9.5: You can now pass a NULL mask to SDL_WM_SetIcon()
-	<LI> 0.9.5: Added support files for compiling with VC++ 5.0
-	<LI> 0.9.5: Fixed icon color bug under Win32
-	<LI> 0.9.5: Re-added SDL_LowerBlit() - not safe for use on display
-	<LI> 0.9.5: Fixed 0.9.x cursor blit deadlock
-	<LI> 0.9.5: Added SDL_FPLoadWAV(), SDL_FPLoadBMP(), SDL_FPSaveBMP()
-	<LI> 0.9.5: Added Linux, Win32, and BeOS CD audio support
-	<LI> 0.9.5: MMX accelerated blit disabled -- temporarily broken
-	<LI> 0.9.4: Fixed endianness issue with BeOS x86 blitting
-	<LI> 0.9.4: Fixed quit interrupt delivery on BeOS
-	<LI> 0.9.4: Fixed dynamic loading on BeOS
-	<LI> 0.9.4: Fixed DirectX audio on Win98
-	<LI> 0.9.4: Fixed possible sound-related crash on Linux PPC
-	<LI> 0.9.3: Mouse motion arrives as absolute and relative coordinates
-	<LI> 0.9.3: Fixed Visual C++ structure packing
-	<LI> 0.9.3: Fixed UNIX dynamic link library installation
-	<LI> 0.9.2: DirectX audio no longer hangs when app loses focus
-	<LI> 0.9.2: Fixed DirectX HiColor crash (palette bug)
-	<LI> 0.9.1: Fixed DirectX &lt;ALT&gt; key handling
-	<LI> 0.9.1: Fixed DirectX windowed palette problems
-	<LI> 0.9.1: Removed SDL_MapSurface() and SDL_UnmapSurface()
-	<LI> 0.9.0: Initial port to IRIX 6.x
-	<LI> 0.9.0: Initial port to OSF/1 3.2       (no sound yet)
-	<LI> 0.9.0: MacOS port in progress
-</UL>
+<BLOCKQUOTE>
+<P>
+	The X11 libraries are dynamically loaded at runtime by default.  This allows the distributed version of SDL to run on systems without X11 libraries installed.
+<P>
+	The XiG XME extension code is now included in the X11 video driver by default.
+<P>
+	XRandR support for video mode switching has been added to the X11 driver, but is disabled because of undesired interactions with window managers.  You can enable this by setting the environment variable SDL_VIDEO_X11_XRANDR to 1.
+<P>
+	Xinerama multi-head displays are properly handled now, and the SDL_VIDEO_FULLSCREEN_HEAD environment variable can be used to select the screen used for fullscreen video modes.  Note that changing the video modes only works on screen 0.
+<P>
+	XVidMode video modes are now sorted so they maintain the refresh rates specified in the X11 configuration file.
+<P>
+	SDL windows are no longer transparent in X11 compositing systems like XGL.
+<P>
+	The mouse is properly released by the X11 video driver if the fullscreen window loses focus.
+<P>
+	The X11 input driver now uses XIM to handle international input.
+<P>
+	The screensaver and DPMS monitor blanking are disabled while SDL games are running under the X11 and DGA video drivers.  This behavior will be formalized and selectable in SDL 1.3.
+<P>
+	Fixed a bug preventing stereo OpenGL contexts from being selected on the X11 driver.
+<P>
+	The DGA video driver now waits for pending blits involving surfaces before they are freed.  This prevents display oddities when using SDL_DisplayFormat() to convert many images.
+<P>
+	The framebuffer console video driver now has a parser for /etc/fb.modes for improved video mode handling.
+<P>
+	The framebuffer console video driver now allows asynchronous VT switching, and restores the full contents of the screen when switched back.
+<P>
+	The framebuffer console now uses CTRL-ALT-FN to switch virtual terminals, to avoid collisions with application key bindings.
+<P>
+	The framebuffer console input driver correctly sets IMPS/2 mode for wheel mice.  It also properly detects when gpm is in IMPS/2 protocol mode, or passing raw protocol from an IMPS/2 mouse.
+<P>
+	The SVGAlib video driver now has support for banked (non-linear) video modes.
+<P>
+	A video driver for OpenBSD on the Sharp Zaurus has been contributed by Staffan Ulfberg.  See the file README.wscons in the SDL source distribution for details.
+<P>
+	Many patches have been incorporated from *BSD ports.
+</BLOCKQUOTE>
+
+<H3> Windows Notes </H3>
 
-<H2>
-Major changes since SDL 0.7:
-</H2>
-<UL>
-	<LI>	Separated the demos and examples into a separate archive
-	<LI>	Added support for loading Microsoft compressed WAV files
-	<LI>	Added "soft" application crash recovery (signal handlers)
-	<LI>	Fixed POSIX signal handling interaction with threads
-	<LI>	Fixed audio output on MKLinux
-	<LI>	Added dynamic library version checking
-	<LI>	Updated for DirectX 6.0
-	<LI>	Cleaned up dynamic linking and added static linking
-	<LI>	Added automatic audio format and rate conversion
-	<LI>	Optimized some blitter cases (8 --> 16/32 and 32 --> 16/8)
-	<LI>	Removed precalculated alpha blending acceleration
-	<LI>	Key and mouse button events are split into up/down events
-	<LI>	It is now much easier to set an optimal video mode
-</UL>
+<BLOCKQUOTE>
+<P>
+	The "windib" video driver is the default now, to prevent problems with certain laptops, 64-bit Windows, and Windows Vista.  The DirectX driver is still available, and can be selected by setting the environment variable SDL_VIDEODRIVER to "directx".
+<P>
+	SDL has been ported to 64-bit Windows.
+<P>
+	Dmitry Yakimov contributed a GAPI video driver for Windows CE.
+<P>
+	The default fullscreen refresh rate has been increased to match the desktop refresh rate, when using equivalent resolutions.  A full API for querying and selecting refresh rates is planned for SDL 1.3.
+<P>
+	Dialog boxes are now shown when SDL is in windowed OpenGL mode.
+<P>
+	The SDL window is recreated when necessary to maintain OpenGL context attributes, when switching between windowed and fullscreen modes.
+<P>
+	An SDL_VIDEORESIZE event is properly sent when the SDL window is maximized and restored.
+<P>
+	Window positions are retained when switching between fullscreen and windowed modes.
+<P>
+	ToUnicode() is used, when available, for improved handling of international keyboard input.
+<P>
+	The PrtScrn is now treated normally with both key down and key up events.
+<P>
+	Pressing ALT-F4 now delivers an SDL_QUIT event to SDL applications.
+<P>
+	Joystick names are now correct for joysticks which have been unplugged and then plugged back in since booting.
+<P>
+	An MCI error when playing the last track on a CD-ROM has been fixed.
+<P>
+	OpenWatcom projects for building SDL have been provided by Marc Peter.
+</BLOCKQUOTE>
 
-<H2>
-Major changes since SDL 0.5:
-</H2>
-<UL>
-	<LI>	Ported to Solaris 2.6
-	<LI>	Added XFree86 Direct Graphic Access support
-	<LI>	Supports LinuxPPC without threads
-	<LI>	Completely rewritten video/surface API -- see SDL_video.h
-	<LI>	Completely rewritten event API
-	<LI>	Optimized black-white cursor creation
-	<LI>	Added support for run-length-encoded colorkeying
-	<LI>	Added support for hardware accelerated blits
-	<LI>	Added support for blitting from 1-bit surfaces (bitmaps)
-	<LI>	Added a function to simplify setting video modes
-	<LI>	Added support for loading WAV files
-	<LI>	Added endian swapping functions for memory values
-	<LI>	Added alpha blending using alpha value or channel
-	<LI>	Added precalculated alpha blending acceleration
-	<LI>	Added function to return current time in milliseconds
-	<LI>	New event type SDL_ACTIVEEVENT, to detect iconification
-	<LI>	New event type SDL_SYSWMEVENT, for custom window hooks
-	<LI>	Added a platform dependent function to get window handle
-	<LI>	Added a function to check the run-time version of SDL
-	<LI>	Added periodic timer support at 10 ms resolution
-	<LI>	Added support for the SDL_DEBUG environment variable
-	<LI>	Miscellaneous internal cleanups
-</UL>
+<H3> Mac OS X Notes </H3>
 
-<H2>
-Major changes since SDL 0.4:
-</H2>
-<UL>
-	<LI>	SDL library code is now dynamically loaded
-	<LI>	Added support for pthreads (Linux glibc2)
-	<LI>	Removed SDL_mutexN() and SDL_mutexIncr()
-</UL>
+<BLOCKQUOTE>
+<P>
+	SDL now supports building Universal binaries, both through Xcode projects and when using configure/make.  See README.MacOSX in the SDL source archive for details.
+<P>
+	The X11 video driver with GLX support can be built on Mac OS X, if the X11 development SDK is installed.
+<P>
+	Transitions between fullscreen resolutions and windowed mode now use a much faster asynchronous fade to hide desktop flicker.
+<P>
+	Icons set with SDL_WM_SetIcon() now have the proper colors on Intel Macs.
+</BLOCKQUOTE>
 
-<H2>
-Major changes since SDL 0.3:
-</H2>
-<UL>
-	<LI>	Added support for DirectX 5.0
-	<LI>	Added support for surfaces in video memory
-	<LI>	Added support for source color-key blitting
-	<LI>	Added support for single-rectangle clipping
-	<LI>	Added support for warping (moving) the cursor
-	<LI>	Added support for color cursors
-	<LI>	Greatly simplified internal event queue
-	<LI>	Minor bug-fixes
-</UL>
+<H3> OS/2 Notes </H3>
 
+<BLOCKQUOTE>
 <P>
+	Projects for building SDL on OS/2 with OpenWatcom have been contributed by Doodle.  See the file README.OS2 in the SDL source distribution for details.
+</BLOCKQUOTE>
+
 <IMG SRC="docs/images/rainbow.gif" ALT="[separator]" WIDTH="100%">
 
 </BODY>
Binary file docs/images/rainbow.gif has changed
--- a/docs/index.html	Mon May 01 06:58:33 2006 +0000
+++ b/docs/index.html	Wed May 17 08:18:28 2006 +0000
@@ -1,102 +1,36 @@
 <!DOCTYPE HTML PUBLIC "-//Norman Walsh//DTD DocBook HTML 1.0//EN">
-<HTML
-><HEAD
-><TITLE
->Introduction</TITLE
->
-</HEAD
-><BODY
-BGCOLOR="#FFF8DC"
-TEXT="#000000"
-LINK="#0000ee"
-VLINK="#551a8b"
-ALINK="#ff0000"
-><DIV
-CLASS="NAVHEADER"
->
-<HR
-ALIGN="LEFT"
-WIDTH="100%"></DIV
-><DIV
-CLASS="PREFACE"
-><H1
-><A
-NAME="AEN8"
->Introduction</A
-></H1
-><P
->This library is designed to make it easy to write games that run on Linux,
-Win32 and BeOS using the various native high-performance media interfaces,
+<HTML>
+<HEAD><TITLE>Simple DirectMedia Layer Introduction</TITLE></HEAD>
+<BODY BGCOLOR="#FFF8DC" TEXT="#000000" LINK="#0000ee" VLINK="#551a8b" ALINK="#ff0000">
+<DIV CLASS="NAVHEADER">
+<HR ALIGN="LEFT" WIDTH="100%">
+</DIV>
+<DIV CLASS="PREFACE">
+<H2><A NAME="AEN8">Simple DirectMedia Layer Introduction</A></H2>
+<P>
+This library is designed to make it easy to write games that run on many
+different platforms using the various native high-performance media interfaces,
 (for video, audio, etc) and presenting a single source-code level API to
 your application.  This is a fairly low level API, but using this, completely
-portable applications can be written with a great deal of flexibility.</P
-><P
->The library is loaded as a dynamically linked library on its native
-platform, and is currently compiled natively for Linux, compiled for
-Win32 using a Linux hosted GCC
-<A
-HREF="http://www.libsdl.org/Xmingw32/"
-TARGET="_top"
->cross-compilation</A
->
-environment, and compiled using the EGCS C++ compiler under BeOS.</P
-><P
->An introduction to SDL can be found online at:
-<A
-HREF="http://www.libsdl.org/intro/toc.html"
-TARGET="_top"
->http://www.libsdl.org/intro/</A
->&#13;</P
-><P
->There are code examples on each of the main library pages, and there are
-fully fleshed example C++ classes and programs in the examples archive,
-available on the
-<A
-HREF="http://www.libsdl.org/download.html"
-TARGET="_top"
->SDL download page</A
->.</P
-><P
->For an introduction to basic multi-media programming concepts, you might try
-some of the following links:
-<P
-></P
-><UL
-><LI
-><P
-><A
-HREF="http://www.ziron.com/links/"
-TARGET="_top"
->Game Programming Links</A
-></P
-></LI
-><LI
-><P
-><A
-HREF="http://developer.dungeon-crawl.com/"
-TARGET="_top"
->Game Developer Search Engine</A
-></P
-></LI
-></UL
-></P
-><P
->Enjoy!</P
-><P
->&nbsp;&nbsp;&nbsp; Sam Lantinga
-<TT
-CLASS="EMAIL"
->&#60;<A
-HREF="mailto:slouken@libsdl.org"
-><A
-HREF="mailto:slouken@libsdl.org"
-TARGET="_top"
->slouken@libsdl.org</A
-></A
->&#62;</TT
-></P
->
-<P>
+portable applications can be written with a great deal of flexibility.
+</P><P>
+An introduction to SDL can be found online at:
+<A HREF="http://www.libsdl.org/intro.php" TARGET="_top">
+         http://www.libsdl.org/intro.php</A>
+</P><P>
+Tutorials on a variety of topics can be found online at:
+<A HREF="http://www.libsdl.org/tutorials.php" TARGET="_top">
+         http://www.libsdl.org/tutorials.php</A>
+</P><P>
+Documentation in Wiki form can be found online at:
+<A HREF="http://www.libsdl.org/cgi/docwiki.cgi/" TARGET="_top">
+         http://www.libsdl.org/cgi/docwiki.cgi/</A>
+</P><P>
+Enjoy!
+</P><P>
+&nbsp;&nbsp;&nbsp; Sam Lantinga
+<TT CLASS="EMAIL">&#60;<A HREF="mailto:slouken@libsdl.org"><A HREF="mailto:slouken@libsdl.org" TARGET="_top" >slouken@libsdl.org</A></A>&#62;</TT>
+</P> <P>
 <br><br><HR>
 <H1>Table of Contents</H1>
 <UL>
--- a/include/SDL_config.h.in	Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_config.h.in	Wed May 17 08:18:28 2006 +0000
@@ -279,6 +279,7 @@
 #undef SDL_VIDEO_DRIVER_WSCONS
 #undef SDL_VIDEO_DRIVER_X11
 #undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
+#undef SDL_VIDEO_DRIVER_X11_DPMS
 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC
 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
--- a/include/SDL_config_macos.h	Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_config_macos.h	Wed May 17 08:18:28 2006 +0000
@@ -27,14 +27,20 @@
 
 /* This is a set of defines to configure the SDL features */
 
-typedef signed char	int8_t;
-typedef unsigned char	uint8_t;
-typedef signed short	int16_t;
-typedef unsigned short	uint16_t;
-typedef signed long	int32_t;
-typedef unsigned long	uint32_t;
+#include <MacTypes.h>
+
+typedef SInt8	int8_t;
+typedef UInt8	uint8_t;
+typedef SInt16	int16_t;
+typedef UInt16	uint16_t;
+typedef SInt32	int32_t;
+typedef UInt32	uint32_t;
+typedef SInt64	int64_t;
+typedef UInt64	uint64_t;
 typedef unsigned long	uintptr_t;
 
+#define SDL_HAS_64BIT_TYPE	1
+
 /* Useful headers */
 #define HAVE_STDIO_H	1
 #define STDC_HEADERS	1
@@ -73,10 +79,18 @@
 #define SDL_AUDIO_DRIVER_DUMMY	1
 
 /* Enable various cdrom drivers */
-#define SDL_CDROM_MACOS	1
+#if TARGET_API_MAC_CARBON
+#define SDL_CDROM_DUMMY		1
+#else
+#define SDL_CDROM_MACOS		1
+#endif
 
 /* Enable various input drivers */
+#if TARGET_API_MAC_CARBON
+#define SDL_JOYSTICK_DUMMY	1
+#else
 #define SDL_JOYSTICK_MACOS	1
+#endif
 
 /* Enable various shared object loading systems */
 #define SDL_LOADSO_MACOS	1
--- a/include/SDL_config_macosx.h	Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_config_macosx.h	Wed May 17 08:18:28 2006 +0000
@@ -30,7 +30,10 @@
 #define SDL_HAS_64BIT_TYPE	1
 
 /* Useful headers */
+/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */
+#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) )
 #define HAVE_ALLOCA_H		1
+#endif
 #define HAVE_SYS_TYPES_H	1
 #define HAVE_STDIO_H	1
 #define STDC_HEADERS	1
@@ -46,12 +49,7 @@
 #define HAVE_CALLOC	1
 #define HAVE_REALLOC	1
 #define HAVE_FREE	1
-
-/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */
-#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) )
 #define HAVE_ALLOCA	1
-#endif
-
 #define HAVE_GETENV	1
 #define HAVE_PUTENV	1
 #define HAVE_UNSETENV	1
@@ -116,8 +114,11 @@
 
 /* Enable various video drivers */
 #define SDL_VIDEO_DRIVER_DUMMY	1
-#define SDL_VIDEO_DRIVER_GLSDL	1
+#if TARGET_API_MAC_CARBON
+#define SDL_VIDEO_DRIVER_TOOLBOX	1
+#else
 #define SDL_VIDEO_DRIVER_QUARTZ	1
+#endif
 
 /* Enable OpenGL support */
 #define SDL_VIDEO_OPENGL	1
--- a/include/SDL_platform.h	Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_platform.h	Wed May 17 08:18:28 2006 +0000
@@ -61,13 +61,12 @@
 #undef __LINUX__
 #define __LINUX__	1
 #endif
-#if defined(macintosh)
-#undef __MACOS__
-#define __MACOS__	1
-#endif
 #if defined(__APPLE__)
 #undef __MACOSX__
 #define __MACOSX__	1
+#elif defined(macintosh)
+#undef __MACOS__
+#define __MACOS__	1
 #endif
 #if defined(__NetBSD__)
 #undef __NETBSD__
--- a/include/SDL_stdinc.h	Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_stdinc.h	Wed May 17 08:18:28 2006 +0000
@@ -168,8 +168,12 @@
 # elif defined(_MSC_VER)
 #  include <malloc.h>
 #  define alloca _alloca
+# elif defined(__WATCOMC__)
+#  include <malloc.h>
 # elif defined(__AIX__)
   #pragma alloca
+# elif defined(__MRC__)
+   void *alloca (unsigned);
 # else
    char *alloca ();
 # endif
--- a/include/SDL_syswm.h	Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_syswm.h	Wed May 17 08:18:28 2006 +0000
@@ -115,7 +115,7 @@
 	GR_WINDOW_ID window ;	/* The display window */
 } SDL_SysWMinfo;
 
-#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW)
+#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
--- a/sdl.m4	Mon May 01 06:58:33 2006 +0000
+++ b/sdl.m4	Wed May 17 08:18:28 2006 +0000
@@ -20,19 +20,21 @@
 		    , enable_sdltest=yes)
 
   if test x$sdl_exec_prefix != x ; then
-     sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
-     if test x${SDL_CONFIG+set} != xset ; then
-        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
-     fi
+    sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
+    if test x${SDL_CONFIG+set} != xset ; then
+      SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
+    fi
   fi
   if test x$sdl_prefix != x ; then
-     sdl_args="$sdl_args --prefix=$sdl_prefix"
-     if test x${SDL_CONFIG+set} != xset ; then
-        SDL_CONFIG=$sdl_prefix/bin/sdl-config
-     fi
+    sdl_args="$sdl_args --prefix=$sdl_prefix"
+    if test x${SDL_CONFIG+set} != xset ; then
+      SDL_CONFIG=$sdl_prefix/bin/sdl-config
+    fi
   fi
 
-  PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+  if test "x$prefix" != xNONE; then
+    PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+  fi
   AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
   min_sdl_version=ifelse([$1], ,0.11.0,$1)
   AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
--- a/src/SDL_error.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/SDL_error.c	Wed May 17 08:18:28 2006 +0000
@@ -39,15 +39,10 @@
 
 /* Private functions */
 
-static void SDL_LookupString(const Uint8 *key, Uint16 *buf, int buflen)
+static const char *SDL_LookupString(const char *key)
 {
 	/* FIXME: Add code to lookup key in language string hash-table */
-
-	/* Key not found in language string hash-table */
-	while ( *key && (--buflen > 0) ) {
-		*buf++ = *key++;
-	}
-	*buf = 0;	/* NULL terminate string */
+	return key;
 }
 
 /* Public functions */
@@ -66,17 +61,20 @@
 	error->argc = 0;
 	while ( *fmt ) {
 		if ( *fmt++ == '%' ) {
+			while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
+				++fmt;
+			}
 			switch (*fmt++) {
 			    case 0:  /* Malformed format string.. */
 				--fmt;
 				break;
-#if 0	/* What is a character anyway?  (UNICODE issues) */
 			    case 'c':
-				error->args[error->argc++].value_c =
-						va_arg(ap, unsigned char);
-				break;
-#endif
+			    case 'i':
 			    case 'd':
+			    case 'u':
+			    case 'o':
+			    case 'x':
+			    case 'X':
 				error->args[error->argc++].value_i =
 							va_arg(ap, int);
 				break;
@@ -114,124 +112,67 @@
 #endif
 }
 
-/* Print out an integer value to a UNICODE buffer */
-static int PrintInt(Uint16 *str, unsigned int maxlen, int value)
-{
-	char tmp[128];
-	int len, i;
-
-	SDL_snprintf(tmp, SDL_arraysize(tmp), "%d", value);
-	len = 0;
-	if ( SDL_strlen(tmp) < maxlen ) {
-		for ( i=0; tmp[i]; ++i ) {
-			*str++ = tmp[i];
-			++len;
-		}
-	}
-	return(len);
-}
-/* Print out a double value to a UNICODE buffer */
-static int PrintDouble(Uint16 *str, unsigned int maxlen, double value)
-{
-	char tmp[128];
-	int len, i;
-
-	SDL_snprintf(tmp, SDL_arraysize(tmp), "%f", value);
-	len = 0;
-	if ( SDL_strlen(tmp) < maxlen ) {
-		for ( i=0; tmp[i]; ++i ) {
-			*str++ = tmp[i];
-			++len;
-		}
-	}
-	return(len);
-}
-/* Print out a pointer value to a UNICODE buffer */
-static int PrintPointer(Uint16 *str, unsigned int maxlen, void *value)
-{
-	char tmp[128];
-	int len, i;
-
-	SDL_snprintf(tmp, SDL_arraysize(tmp), "%p", value);
-	len = 0;
-	if ( SDL_strlen(tmp) < maxlen ) {
-		for ( i=0; tmp[i]; ++i ) {
-			*str++ = tmp[i];
-			++len;
-		}
-	}
-	return(len);
-}
-
 /* This function has a bit more overhead than most error functions
    so that it supports internationalization and thread-safe errors.
 */
-Uint16 *SDL_GetErrorMsgUNICODE(Uint16 *errstr, unsigned int maxlen)
+char *SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
 {
 	SDL_error *error;
 
 	/* Clear the error string */
-	*errstr = 0; --maxlen;
+	*errstr = '\0'; --maxlen;
 
 	/* Get the thread-safe error, and print it out */
 	error = SDL_GetErrBuf();
 	if ( error->error ) {
-		Uint16 translated[ERR_MAX_STRLEN], *fmt, *msg;
+		const char *fmt;
+		char *msg = errstr;
 		int len;
 		int argi;
 
-		/* Print out the UNICODE error message */
-		SDL_LookupString(error->key, translated, sizeof(translated));
-		msg = errstr;
+		fmt = SDL_LookupString(error->key);
 		argi = 0;
-		for ( fmt=translated; *fmt && (maxlen > 0); ) {
+		while ( *fmt && (maxlen > 0) ) {
 			if ( *fmt == '%' ) {
-				switch (fmt[1]) {
-				    case 'S':	/* Special SKIP operand */
-					argi += (fmt[2] - '0');
-					++fmt;
-					break;
+				char tmp[32], *spot = tmp;
+				*spot++ = *fmt++;
+				while ( (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) && spot < (tmp+SDL_arraysize(tmp)-2) ) {
+					*spot++ = *fmt++;
+				}
+				*spot++ = *fmt++;
+				*spot++ = '\0';
+				switch (spot[-2]) {
 				    case '%':
 					*msg++ = '%';
 					maxlen -= 1;
 					break;
-#if 0	/* What is a character anyway?  (UNICODE issues) */
 				    case 'c':
-                                        *msg++ = (unsigned char)
-					         error->args[argi++].value_c;
-					maxlen -= 1;
-					break;
-#endif
-				    case 'd':
-					len = PrintInt(msg, maxlen,
-						error->args[argi++].value_i);
+				    case 'i':
+			            case 'd':
+			            case 'u':
+			            case 'o':
+				    case 'x':
+				    case 'X':
+					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_i);
 					msg += len;
 					maxlen -= len;
 					break;
 				    case 'f':
-					len = PrintDouble(msg, maxlen,
-						error->args[argi++].value_f);
+					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_f);
 					msg += len;
 					maxlen -= len;
 					break;
 				    case 'p':
-					len = PrintPointer(msg, maxlen,
-						error->args[argi++].value_ptr);
+					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_ptr);
 					msg += len;
 					maxlen -= len;
 					break;
-				    case 's': /* UNICODE string */
-					{ Uint16 buf[ERR_MAX_STRLEN], *str;
-					  SDL_LookupString(error->args[argi++].buf, buf, sizeof(buf));
-					  str = buf;
-					  while ( *str && (maxlen > 0) ) {
-						*msg++ = *str++;
-						maxlen -= 1;
-					  }
-					}
+				    case 's':
+					len = SDL_snprintf(msg, maxlen, tmp, SDL_LookupString(error->args[argi++].buf));
+					msg += len;
+					maxlen -= len;
 					break;
 				}
-				fmt += 2;
 			} else {
 				*msg++ = *fmt++;
 				maxlen -= 1;
@@ -242,38 +183,12 @@
 	return(errstr);
 }
 
-Uint8 *SDL_GetErrorMsg(Uint8 *errstr, unsigned int maxlen)
-{
-	Uint16 *errstr16;
-	unsigned int i;
-
-	/* Allocate the UNICODE buffer */
-	errstr16 = (Uint16 *)SDL_malloc(maxlen * (sizeof *errstr16));
-	if ( ! errstr16 ) {
-		SDL_strlcpy((char *)errstr, "Out of memory", maxlen);
-		return(errstr);
-	}
-
-	/* Get the error message */
-	SDL_GetErrorMsgUNICODE(errstr16, maxlen);
-
-	/* Convert from UNICODE to Latin1 encoding */
-	for ( i=0; i<maxlen; ++i ) {
-		errstr[i] = (Uint8)errstr16[i];
-	}
-
-	/* Free UNICODE buffer (if necessary) */
-	SDL_free(errstr16);
-
-	return(errstr);
-}
-
 /* Available for backwards compatibility */
 char *SDL_GetError (void)
 {
 	static char errmsg[SDL_ERRBUFIZE];
 
-	return((char *)SDL_GetErrorMsg((unsigned char *)errmsg, SDL_ERRBUFIZE));
+	return((char *)SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE));
 }
 
 void SDL_ClearError(void)
--- a/src/SDL_error_c.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/SDL_error_c.h	Wed May 17 08:18:28 2006 +0000
@@ -40,7 +40,7 @@
 	   is not in the hashtable, or no hashtable is available, the key is
 	   used directly as an error message format string.
 	*/
-	unsigned char key[ERR_MAX_STRLEN];
+	char key[ERR_MAX_STRLEN];
 
 	/* These are the arguments for the error functions */
 	int argc;
@@ -51,7 +51,7 @@
 #endif
 		int value_i;
 		double value_f;
-		unsigned char buf[ERR_MAX_STRLEN];
+		char buf[ERR_MAX_STRLEN];
 	} args[ERR_MAX_ARGS];
 } SDL_error;
 
--- a/src/audio/SDL_audio.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_audio.c	Wed May 17 08:18:28 2006 +0000
@@ -120,13 +120,13 @@
 #endif
 
 /* The general mixing thread function */
-int SDL_RunAudio(void *audiop)
+int SDLCALL SDL_RunAudio(void *audiop)
 {
 	SDL_AudioDevice *audio = (SDL_AudioDevice *)audiop;
 	Uint8 *stream;
 	int    stream_len;
 	void  *udata;
-	void (*fill)(void *userdata,Uint8 *stream, int len);
+	void (SDLCALL *fill)(void *userdata,Uint8 *stream, int len);
 	int    silence;
 #if SDL_AUDIO_DRIVER_AHI
 	int started = 0;
@@ -285,6 +285,51 @@
 	SDL_mutexV(audio->mixer_lock);
 }
 
+static Uint16 SDL_ParseAudioFormat(const char *string)
+{
+	Uint16 format = 0;
+
+	switch (*string) {
+	    case 'U':
+		++string;
+		format |= 0x0000;
+		break;
+	    case 'S':
+		++string;
+		format |= 0x8000;
+		break;
+	    default:
+		return 0;
+	}
+	switch (SDL_atoi(string)) {
+	    case 8:
+		string += 1;
+		format |= 8;
+		break;
+	    case 16:
+		string += 2;
+		format |= 16;
+		if ( SDL_strcmp(string, "LSB") == 0
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+		     || SDL_strcmp(string, "SYS") == 0
+#endif
+		    ) {
+			format |= 0x0000;
+		}
+		if ( SDL_strcmp(string, "MSB") == 0
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+		     || SDL_strcmp(string, "SYS") == 0
+#endif
+		    ) {
+			format |= 0x1000;
+		}
+		break;
+	    default:
+		return 0;
+	}
+	return format;
+}
+
 int SDL_AudioInit(const char *driver_name)
 {
 	SDL_AudioDevice *audio;
@@ -386,6 +431,7 @@
 int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
 {
 	SDL_AudioDevice *audio;
+	const char *env;
 
 	/* Start up the audio driver, if necessary */
 	if ( ! current_audio ) {
@@ -402,9 +448,35 @@
 	}
 
 	/* Verify some parameters */
-	if ( desired->callback == NULL ) {
-		SDL_SetError("SDL_OpenAudio() passed a NULL callback");
-		return(-1);
+	if ( desired->freq == 0 ) {
+		env = SDL_getenv("SDL_AUDIO_FREQUENCY");
+		if ( env ) {
+			desired->freq = SDL_atoi(env);
+		}
+	}
+	if ( desired->freq == 0 ) {
+		/* Pick some default audio frequency */
+		desired->freq = 22050;
+	}
+	if ( desired->format == 0 ) {
+		env = SDL_getenv("SDL_AUDIO_FORMAT");
+		if ( env ) {
+			desired->format = SDL_ParseAudioFormat(env);
+		}
+	}
+	if ( desired->format == 0 ) {
+		/* Pick some default audio format */
+		desired->format = AUDIO_S16;
+	}
+	if ( desired->channels == 0 ) {
+		env = SDL_getenv("SDL_AUDIO_CHANNELS");
+		if ( env ) {
+			desired->channels = SDL_atoi(env);
+		}
+	}
+	if ( desired->channels == 0 ) {
+		/* Pick a default number of channels */
+		desired->channels = 2;
 	}
 	switch ( desired->channels ) {
 	    case 1:	/* Mono */
@@ -416,6 +488,25 @@
 		SDL_SetError("1 (mono) and 2 (stereo) channels supported");
 		return(-1);
 	}
+	if ( desired->samples == 0 ) {
+		env = SDL_getenv("SDL_AUDIO_SAMPLES");
+		if ( env ) {
+			desired->samples = SDL_atoi(env);
+		}
+	}
+	if ( desired->samples == 0 ) {
+		/* Pick a default of ~46 ms at desired frequency */
+		int samples = (desired->freq / 1000) * 46;
+		int power2 = 1;
+		while ( power2 < samples ) {
+			power2 *= 2;
+		}
+		desired->samples = power2;
+	}
+	if ( desired->callback == NULL ) {
+		SDL_SetError("SDL_OpenAudio() passed a NULL callback");
+		return(-1);
+	}
 
 #if defined(__MACOS__) || (defined(__RISCOS__) && SDL_THREADS_DISABLED)
 	/* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */
--- a/src/audio/SDL_audio_c.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_audio_c.h	Wed May 17 08:18:28 2006 +0000
@@ -31,4 +31,4 @@
 extern void SDL_CalculateAudioSpec(SDL_AudioSpec *spec);
 
 /* The actual mixing thread function */
-extern int SDL_RunAudio(void *audiop);
+extern int SDLCALL SDL_RunAudio(void *audiop);
--- a/src/audio/SDL_audiocvt.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_audiocvt.c	Wed May 17 08:18:28 2006 +0000
@@ -27,7 +27,7 @@
 
 
 /* Effectively mix right and left channels into a single channel */
-void SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Sint32 sample;
@@ -169,7 +169,7 @@
 }
 
 /* Discard top 4 channels */
-void SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Sint32 lsample, rsample;
@@ -285,7 +285,7 @@
 
 
 /* Discard top 2 channels of 6 */
-void SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Sint32 lsample, rsample;
@@ -400,7 +400,7 @@
 }
 
 /* Duplicate a mono channel to both stereo channels */
-void SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 
@@ -438,7 +438,7 @@
 
 
 /* Duplicate a stereo channel to a pseudo-5.1 stream */
-void SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 
@@ -615,7 +615,7 @@
 
 
 /* Duplicate a stereo channel to a pseudo-4.0 stream */
-void SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 
@@ -768,7 +768,7 @@
 
 
 /* Convert 8-bit to 16-bit - LSB */
-void SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -791,7 +791,7 @@
 	}
 }
 /* Convert 8-bit to 16-bit - MSB */
-void SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -815,7 +815,7 @@
 }
 
 /* Convert 16-bit to 8-bit */
-void SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -841,7 +841,7 @@
 }
 
 /* Toggle signed/unsigned */
-void SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *data;
@@ -870,7 +870,7 @@
 }
 
 /* Toggle endianness */
-void SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *data, tmp;
@@ -892,7 +892,7 @@
 }
 
 /* Convert rate up by multiple of 2 */
-void SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -930,7 +930,7 @@
 
 
 /* Convert rate up by multiple of 2, for stereo */
-void SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -973,7 +973,7 @@
 }
 
 /* Convert rate up by multiple of 2, for quad */
-void SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -1029,7 +1029,7 @@
 
 
 /* Convert rate up by multiple of 2, for 5.1 */
-void SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -1096,7 +1096,7 @@
 }
 
 /* Convert rate down by multiple of 2 */
-void SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -1131,7 +1131,7 @@
 
 
 /* Convert rate down by multiple of 2, for stereo */
-void SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -1169,7 +1169,7 @@
 
 
 /* Convert rate down by multiple of 2, for quad */
-void SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -1212,7 +1212,7 @@
 }
 
 /* Convert rate down by multiple of 2, for 5.1 */
-void SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format)
 {
 	int i;
 	Uint8 *src, *dst;
@@ -1261,7 +1261,7 @@
 }
 
 /* Very slow rate conversion routine */
-void SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format)
 {
 	double ipos;
 	int i, clen;
@@ -1474,7 +1474,7 @@
 		Uint32 hi_rate, lo_rate;
 		int len_mult;
 		double len_ratio;
-		void (*rate_cvt)(SDL_AudioCVT *cvt, Uint16 format);
+		void (SDLCALL *rate_cvt)(SDL_AudioCVT *cvt, Uint16 format);
 
 		if ( src_rate > dst_rate ) {
 			hi_rate = src_rate;
--- a/src/audio/SDL_wave.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_wave.c	Wed May 17 08:18:28 2006 +0000
@@ -478,6 +478,11 @@
 			}
 			IMA_ADPCM_encoded = 1;
 			break;
+		case MP3_CODE:
+			SDL_SetError("MPEG Layer 3 data not supported",
+					SDL_SwapLE16(format->encoding));
+			was_error = 1;
+			goto done;
 		default:
 			SDL_SetError("Unknown WAVE data format: 0x%.4x",
 					SDL_SwapLE16(format->encoding));
--- a/src/audio/SDL_wave.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_wave.h	Wed May 17 08:18:28 2006 +0000
@@ -35,6 +35,7 @@
 #define PCM_CODE	0x0001
 #define MS_ADPCM_CODE	0x0002
 #define IMA_ADPCM_CODE	0x0011
+#define MP3_CODE	0x0055
 #define WAVE_MONO	1
 #define WAVE_STEREO	2
 
--- a/src/audio/mint/SDL_mintaudio.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio.c	Wed May 17 08:18:28 2006 +0000
@@ -42,9 +42,9 @@
 SDL_AudioDevice *SDL_MintAudio_device;
 Uint8 *SDL_MintAudio_audiobuf[2];	/* Pointers to buffers */
 unsigned long SDL_MintAudio_audiosize;		/* Length of audio buffer=spec->size */
-unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
-unsigned short SDL_MintAudio_mutex;
-unsigned long SDL_MintAudio_clocktics;
+volatile unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
+volatile unsigned short SDL_MintAudio_mutex;
+volatile unsigned long SDL_MintAudio_clocktics;
 cookie_stfa_t	*SDL_MintAudio_stfa;
 
 /* MiNT thread variables */
--- a/src/audio/mint/SDL_mintaudio.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio.h	Wed May 17 08:18:28 2006 +0000
@@ -119,10 +119,10 @@
 extern SDL_AudioDevice *SDL_MintAudio_device;
 extern Uint8 *SDL_MintAudio_audiobuf[2];	/* Pointers to buffers */
 extern unsigned long SDL_MintAudio_audiosize;		/* Length of audio buffer=spec->size */
-extern unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
-extern unsigned short SDL_MintAudio_mutex;
+extern volatile unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
+extern volatile unsigned short SDL_MintAudio_mutex;
 extern cookie_stfa_t *SDL_MintAudio_stfa;
-extern unsigned long SDL_MintAudio_clocktics;
+extern volatile unsigned long SDL_MintAudio_clocktics;
 
 /* MiNT thread variables */
 extern SDL_bool	SDL_MintAudio_mint_present;
--- a/src/cdrom/macosx/AudioFilePlayer.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/cdrom/macosx/AudioFilePlayer.c	Wed May 17 08:18:28 2006 +0000
@@ -153,7 +153,7 @@
         }
     
         if (afp->mForkRefNum) {
-            FSClose (afp->mForkRefNum);
+            FSCloseFork (afp->mForkRefNum);
             afp->mForkRefNum = 0;
         }
         SDL_free(afp);
--- a/src/cdrom/macosx/SDL_syscdrom.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/cdrom/macosx/SDL_syscdrom.c	Wed May 17 08:18:28 2006 +0000
@@ -453,8 +453,8 @@
 static int SDL_SYS_CDEject(SDL_CD *cdrom)
 {
     OSStatus err;
-	HParamBlockRec  pb;
-    
+    pid_t dissenter;
+
     if (fakeCD) {
         SDL_SetError (kErrorFakeDevice);
         return -1;
@@ -475,9 +475,7 @@
     status = CD_STOPPED;
     
 	/* Eject the volume */
-	pb.ioParam.ioNamePtr = NULL;
-	pb.ioParam.ioVRefNum = volumes[cdrom->id];
-	err = PBUnmountVol((ParamBlockRec *) &pb);
+	err = FSEjectVolumeSync(volumes[cdrom->id], kNilOptions, &dissenter);
 
 	if (err != noErr) {
         Unlock ();
--- a/src/events/SDL_events.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/events/SDL_events.c	Wed May 17 08:18:28 2006 +0000
@@ -87,7 +87,7 @@
 #include <time.h>
 #endif
 
-static int SDL_GobbleEvents(void *unused)
+static int SDLCALL SDL_GobbleEvents(void *unused)
 {
 	event_thread = SDL_ThreadID();
 
--- a/src/events/SDL_keyboard.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/events/SDL_keyboard.c	Wed May 17 08:18:28 2006 +0000
@@ -59,7 +59,7 @@
 
 	/* Initialize the tables */
 	SDL_ModState = KMOD_NONE;
-	SDL_memset(keynames, 0, sizeof(keynames));
+	SDL_memset((void*)keynames, 0, sizeof(keynames));
 	SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
 	video->InitOSKeymap(this);
 
--- a/src/file/SDL_rwops.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/file/SDL_rwops.c	Wed May 17 08:18:28 2006 +0000
@@ -43,7 +43,7 @@
 #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
 #endif
 
-static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
+static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
 {
 #ifndef _WIN32_WCE
 	UINT	old_error_mode;
@@ -108,7 +108,7 @@
 	
 	return 0; /* ok */
 }
-static int win32_file_seek(SDL_RWops *context, int offset, int whence)
+static int SDLCALL win32_file_seek(SDL_RWops *context, int offset, int whence)
 {
 	DWORD win32whence;
 	int   file_pos;
@@ -138,7 +138,7 @@
 	SDL_Error(SDL_EFSEEK);
 	return -1; /* error */
 }
-static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
+static int SDLCALL win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
 {
 	
 	int		total_bytes; 
@@ -156,7 +156,7 @@
 	nread = byte_read/size;
 	return nread;
 }
-static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
+static int SDLCALL win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
 {
 	
 	int		total_bytes; 
@@ -183,7 +183,7 @@
 	nwritten = byte_written/size;
 	return nwritten;
 }
-static int win32_file_close(SDL_RWops *context)
+static int SDLCALL win32_file_close(SDL_RWops *context)
 {
 	
 	if ( context ) {								
@@ -201,7 +201,7 @@
 
 /* Functions to read/write stdio file pointers */
 
-static int stdio_seek(SDL_RWops *context, int offset, int whence)
+static int SDLCALL stdio_seek(SDL_RWops *context, int offset, int whence)
 {
 	if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) {
 		return(ftell(context->hidden.stdio.fp));
@@ -210,7 +210,7 @@
 		return(-1);
 	}
 }
-static int stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
+static int SDLCALL stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
 {
 	size_t nread;
 
@@ -220,7 +220,7 @@
 	}
 	return(nread);
 }
-static int stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
+static int SDLCALL stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
 {
 	size_t nwrote;
 
@@ -230,7 +230,7 @@
 	}
 	return(nwrote);
 }
-static int stdio_close(SDL_RWops *context)
+static int SDLCALL stdio_close(SDL_RWops *context)
 {
 	if ( context ) {
 		if ( context->hidden.stdio.autoclose ) {
@@ -245,7 +245,7 @@
 
 /* Functions to read/write memory pointers */
 
-static int mem_seek(SDL_RWops *context, int offset, int whence)
+static int SDLCALL mem_seek(SDL_RWops *context, int offset, int whence)
 {
 	Uint8 *newpos;
 
@@ -272,7 +272,7 @@
 	context->hidden.mem.here = newpos;
 	return(context->hidden.mem.here-context->hidden.mem.base);
 }
-static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
+static int SDLCALL mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
 {
 	size_t total_bytes;
 	size_t mem_available;
@@ -292,7 +292,7 @@
 
 	return (total_bytes / size);
 }
-static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
+static int SDLCALL mem_write(SDL_RWops *context, const void *ptr, int size, int num)
 {
 	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
 		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
@@ -301,12 +301,12 @@
 	context->hidden.mem.here += num*size;
 	return(num);
 }
-static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
+static int SDLCALL mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
 {
 	SDL_SetError("Can't write to read-only memory");
 	return(-1);
 }
-static int mem_close(SDL_RWops *context)
+static int SDLCALL mem_close(SDL_RWops *context)
 {
 	if ( context ) {
 		SDL_FreeRW(context);
--- a/src/joystick/linux/SDL_sysjoystick.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/joystick/linux/SDL_sysjoystick.c	Wed May 17 08:18:28 2006 +0000
@@ -30,9 +30,6 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <limits.h>		/* For the definition of PATH_MAX */
-#ifdef __arm__
-#include <linux/limits.h> /* Arm cross-compiler needs this */
-#endif
 #include <linux/joystick.h>
 #if SDL_INPUT_LINUXEV
 #include <linux/input.h>
@@ -980,7 +977,8 @@
 #ifndef NO_LOGICAL_JOYSTICKS
 	if (SDL_joylist[joystick->index].fname == NULL) {
 		SDL_joylist_head(i, joystick->index);
-		return JS_HandleEvents(SDL_joylist[i].joy);
+		JS_HandleEvents(SDL_joylist[i].joy);
+		return;
 	}
 #endif
 
--- a/src/joystick/win32/SDL_mmjoystick.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/joystick/win32/SDL_mmjoystick.c	Wed May 17 08:18:28 2006 +0000
@@ -154,34 +154,26 @@
 	JOYCAPS	joycaps;
 	MMRESULT result;
 
-	numdevs = 0;
-	maxdevs = joyGetNumDevs();
-
-	if ( maxdevs > MAX_JOYSTICKS ) {
-		maxdevs = MAX_JOYSTICKS;
-	}
-
-
-	for ( i = 0; i < MAX_JOYSTICKS; i++ ) {
-		SYS_JoystickID[i] = JOYSTICKID1 + i;
+	/* Reset the joystick ID & name mapping tables */
+	for ( i = 0; i < MAX_JOYSTICKS; ++i ) {
+		SYS_JoystickID[i] = 0;
 		SYS_JoystickName[i] = NULL;
 	}
 
-
-	for ( i = 0; (i < maxdevs); ++i ) {
+	/* Loop over all potential joystick devices */
+	numdevs = 0;
+	maxdevs = joyGetNumDevs();
+	for ( i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i ) {
 		
-		/* added 8/31/2001 By Vitaliy Mikitchenko */
 		joyinfo.dwSize = sizeof(joyinfo);
 		joyinfo.dwFlags = JOY_RETURNALL;
-		/* end addition */
-
 		result = joyGetPosEx(SYS_JoystickID[i], &joyinfo);
 		if ( result == JOYERR_NOERROR ) {
-			result = joyGetDevCaps(SYS_JoystickID[i], &joycaps, sizeof(joycaps));
+			result = joyGetDevCaps(i, &joycaps, sizeof(joycaps));
 			if ( result == JOYERR_NOERROR ) {
-				SYS_JoystickID[numdevs] = SYS_JoystickID[i];
+				SYS_JoystickID[numdevs] = i;
 				SYS_Joystick[numdevs] = joycaps;
-				SYS_JoystickName[numdevs] = GetJoystickName(numdevs, joycaps.szRegKey);
+				SYS_JoystickName[numdevs] = GetJoystickName(i, joycaps.szRegKey);
 				numdevs++;
 			}
 		}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/loadso/macosx/SDL_dlcompat.c	Wed May 17 08:18:28 2006 +0000
@@ -0,0 +1,1407 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2006 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+#include "SDL_config.h"
+
+#ifdef SDL_LOADSO_DLCOMPAT
+
+/* Please note that dlcompat apparently ships in current Mac OS X versions
+ *  as a system library that provides compatibility with the Unix "dlopen"
+ *  interface. In order to allow SDL to work on older OS X releases and also
+ *  not conflict with the system lib on newer versions, we include dlcompat
+ *  in SDL and change the symbols to prevent symbol clash with any existing
+ *  system libraries.  --ryan.
+ */
+
+/* here is the dlcompat license: */
+
+/*
+Copyright (c) 2002 Jorge Acereda  <jacereda@users.sourceforge.net> &
+                   Peter O'Gorman <ogorman@users.sourceforge.net>
+                   
+Portions may be copyright others, see the AUTHORS file included with this
+distribution.
+
+Maintained by Peter O'Gorman <ogorman@users.sourceforge.net>
+
+Bug Reports and other queries should go to <ogorman@users.sourceforge.net>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <mach-o/dyld.h>
+#include <mach-o/nlist.h>
+#include <mach-o/getsect.h>
+
+#include "SDL_stdinc.h"
+
+/* Just playing to see if it would compile with the freebsd headers, it does,
+ * but because of the different values for RTLD_LOCAL etc, it would break binary
+ * compat... oh well
+ */
+#ifndef __BSD_VISIBLE
+#define __BSD_VISIBLE 1
+#endif
+
+/*include "dlfcn.h"*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined (__GNUC__) && __GNUC__ > 3
+#define dl_restrict __restrict
+#else
+#define dl_restrict
+#endif
+
+#if 0
+#ifndef _POSIX_SOURCE
+/*
+ * Structure filled in by dladdr().
+ */
+typedef struct SDL_OSX_dl_info {
+        const char      *dli_fname;     /* Pathname of shared object */
+        void            *dli_fbase;     /* Base address of shared object */
+        const char      *dli_sname;     /* Name of nearest symbol */
+        void            *dli_saddr;     /* Address of nearest symbol */
+} SDL_OSX_Dl_info;
+
+static int SDL_OSX_dladdr(const void * dl_restrict, SDL_OSX_Dl_info * dl_restrict);
+#endif /* ! _POSIX_SOURCE */
+#endif /* 0 */
+
+static int SDL_OSX_dlclose(void * handle);
+static const char * SDL_OSX_dlerror(void);
+static void * SDL_OSX_dlopen(const char *path, int mode);
+static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol);
+
+#define RTLD_LAZY	0x1
+#define RTLD_NOW	0x2
+#define RTLD_LOCAL	0x4
+#define RTLD_GLOBAL	0x8
+
+#ifndef _POSIX_SOURCE
+#define RTLD_NOLOAD	0x10
+#define RTLD_NODELETE	0x80
+
+/*
+ * Special handle arguments for SDL_OSX_dlsym().
+ */
+#define	RTLD_NEXT		((void *) -1)	/* Search subsequent objects. */
+#define	RTLD_DEFAULT	((void *) -2)	/* Use default search algorithm. */
+#endif /* ! _POSIX_SOURCE */
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifndef dl_restrict
+#define dl_restrict __restrict
+#endif
+/* This is not available on 10.1 */
+#ifndef LC_LOAD_WEAK_DYLIB
+#define	LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
+#endif
+
+/* With this stuff here, this thing may actually compile/run on 10.0 systems
+ * Not that I have a 10.0 system to test it on anylonger
+ */
+#ifndef LC_REQ_DYLD
+#define LC_REQ_DYLD 0x80000000
+#endif
+#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
+#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
+#endif
+#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
+#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
+#endif
+#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
+#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
+#endif
+#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
+#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
+#endif
+/* These symbols will be looked for in dyld */
+static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0;
+static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0;
+static NSSymbol(*dyld_NSLookupSymbolInImage)
+	(const struct mach_header *, const char *, unsigned long) = 0;
+
+/* Define this to make dlcompat reuse data block. This way in theory we save
+ * a little bit of overhead. However we then couldn't correctly catch excess
+ * calls to SDL_OSX_dlclose(). Hence we don't use this feature
+ */
+#undef REUSE_STATUS
+
+/* Size of the internal error message buffer (used by dlerror()) */
+#define ERR_STR_LEN			251
+
+/* Maximum number of search paths supported by getSearchPath */
+#define MAX_SEARCH_PATHS	32
+
+
+#define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
+#define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
+
+/* internal flags */
+#define DL_IN_LIST 0x01
+
+/* our mutex */
+static pthread_mutex_t dlcompat_mutex;
+/* Our thread specific storage
+ */
+static pthread_key_t dlerror_key;
+
+struct dlthread
+{
+	int lockcnt;
+	unsigned char errset;
+	char errstr[ERR_STR_LEN];
+};
+
+/* This is our central data structure. Whenever a module is loaded via
+ * SDL_OSX_dlopen(), we create such a struct.
+ */
+struct dlstatus
+{
+	struct dlstatus *next;		/* pointer to next element in the linked list */
+	NSModule module;
+	const struct mach_header *lib;
+	int refs;					/* reference count */
+	int mode;					/* mode in which this module was loaded */
+	dev_t device;
+	ino_t inode;
+	int flags;					/* Any internal flags we may need */
+};
+
+/* Head node of the dlstatus list */
+static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
+static struct dlstatus *stqueue = &mainStatus;
+
+
+/* Storage for the last error message (used by dlerror()) */
+/* static char err_str[ERR_STR_LEN]; */
+/* static int err_filled = 0; */
+
+/* Prototypes to internal functions */
+static void debug(const char *fmt, ...);
+static void error(const char *str, ...);
+static const char *safegetenv(const char *s);
+static const char *searchList(void);
+static const char *getSearchPath(int i);
+static const char *getFullPath(int i, const char *file);
+static const struct stat *findFile(const char *file, const char **fullPath);
+static int isValidStatus(struct dlstatus *status);
+static inline int isFlagSet(int mode, int flag);
+static struct dlstatus *lookupStatus(const struct stat *sbuf);
+static void insertStatus(struct dlstatus *dls, const struct stat *sbuf);
+static int promoteLocalToGlobal(struct dlstatus *dls);
+static void *reference(struct dlstatus *dls, int mode);
+static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError);
+static struct dlstatus *allocStatus(void);
+static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode);
+static NSSymbol search_linked_libs(const struct mach_header *mh, const char *symbol);
+static const char *get_lib_name(const struct mach_header *mh);
+static const struct mach_header *get_mach_header_from_NSModule(NSModule mod);
+static void dlcompat_init_func(void);
+static inline void dlcompat_init_check(void);
+static inline void dolock(void);
+static inline void dounlock(void);
+static void dlerrorfree(void *data);
+static void resetdlerror(void);
+static const struct mach_header *my_find_image(const char *name);
+static const struct mach_header *image_for_address(const void *address);
+static inline char *dyld_error_str(void);
+
+#if FINK_BUILD
+/* Two Global Functions */
+static void *dlsym_prepend_underscore(void *handle, const char *symbol);
+static void *dlsym_auto_underscore(void *handle, const char *symbol);
+
+/* And their _intern counterparts */
+static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol);
+static void *dlsym_auto_underscore_intern(void *handle, const char *symbol);
+#endif
+
+/* Functions */
+
+static void debug(const char *fmt, ...)
+{
+#if DEBUG > 1
+	va_list arg;
+	va_start(arg, fmt);
+	fprintf(stderr, "DLDEBUG: ");
+	vfprintf(stderr, fmt, arg);
+	fprintf(stderr, "\n");
+	fflush(stderr);
+	va_end(arg);
+#endif
+}
+
+static void error(const char *str, ...)
+{
+	va_list arg;
+	struct dlthread  *tss;
+	char * err_str;
+	va_start(arg, str);
+	tss = pthread_getspecific(dlerror_key);
+	err_str = tss->errstr;
+	SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN);
+	vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
+	va_end(arg);
+	debug("ERROR: %s\n", err_str);
+	tss->errset = 1;
+}
+
+static void warning(const char *str)
+{
+#if DEBUG > 0
+	fprintf(stderr, "WARNING: dlcompat: %s\n", str);
+#endif
+}
+
+static const char *safegetenv(const char *s)
+{
+	const char *ss = SDL_getenv(s);
+	return ss ? ss : "";
+}
+
+/* because this is only used for debugging and error reporting functions, we
+ * don't really care about how elegant it is... it could use the load
+ * commands to find the install name of the library, but...
+ */
+static const char *get_lib_name(const struct mach_header *mh)
+{
+	unsigned long count = _dyld_image_count();
+	unsigned long i;
+	const char *val = NULL;
+	if (mh)
+	{
+		for (i = 0; i < count; i++)
+		{
+			if (mh == _dyld_get_image_header(i))
+			{
+				val = _dyld_get_image_name(i);
+				break;
+			}
+		}
+	}
+	return val;
+}
+
+/* Returns the mach_header for the module bu going through all the loaded images
+ * and finding the one with the same name as the module. There really ought to be
+ * an api for doing this, would be faster, but there isn't one right now
+ */
+static const struct mach_header *get_mach_header_from_NSModule(NSModule mod)
+{
+	const char *mod_name = NSNameOfModule(mod);
+	const struct mach_header *mh = NULL;
+	unsigned long count = _dyld_image_count();
+	unsigned long i;
+	debug("Module name: %s", mod_name);
+	for (i = 0; i < count; i++)
+	{
+		if (!SDL_strcmp(mod_name, _dyld_get_image_name(i)))
+		{
+			mh = _dyld_get_image_header(i);
+			break;
+		}
+	}
+	return mh;
+}
+
+
+/* Compute and return a list of all directories that we should search when
+ * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
+ * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
+ * /usr/lib and /lib. Since both of the environments variables can contain a
+ * list of colon seperated paths, we simply concat them and the two other paths
+ * into one big string, which we then can easily parse.
+ * Splitting this string into the actual path list is done by getSearchPath()
+ */
+static const char *searchList()
+{
+	size_t buf_size;
+	static char *buf=NULL;
+	const char *ldlp = safegetenv("LD_LIBRARY_PATH");
+	const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
+	const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH");
+	if (!stdpath)
+		stdpath = "/usr/local/lib:/lib:/usr/lib";
+	if (!buf)
+	{	
+		buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4;
+		buf = SDL_malloc(buf_size);
+		SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
+				 stdpath, '\0');
+	}
+	return buf;
+}
+
+/* Returns the ith search path from the list as computed by searchList() */
+static const char *getSearchPath(int i)
+{
+	static const char *list = 0;
+	static char **path = (char **)0;
+	static int end = 0;
+	static int numsize = MAX_SEARCH_PATHS;
+	static char **tmp;
+	/* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
+	if (i == -1)
+	{
+		return (const char*)path;
+	}
+	if (!path)
+	{
+		path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **));
+	}
+	if (!list && !end)
+		list = searchList();
+	if (i >= (numsize))
+	{
+		debug("Increasing size for long PATH");
+		tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
+		if (tmp)
+		{
+			SDL_memcpy(tmp, path, sizeof(char **) * numsize);
+			SDL_free(path);
+			path = tmp;
+			numsize += MAX_SEARCH_PATHS;
+		}
+		else
+		{
+			return 0;
+		}
+	}
+
+	while (!path[i] && !end)
+	{
+		path[i] = strsep((char **)&list, ":");
+
+		if (path[i][0] == 0)
+			path[i] = 0;
+		end = (list == 0);
+	}
+	return path[i];
+}
+
+static const char *getFullPath(int i, const char *file)
+{
+	static char buf[PATH_MAX];
+	const char *path = getSearchPath(i);
+	if (path)
+	{
+		SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file);
+	}
+	return path ? buf : 0;
+}
+
+/* Given a file name, try to determine the full path for that file. Starts
+ * its search in the current directory, and then tries all paths in the 
+ * search list in the order they are specified there.
+ */
+static const struct stat *findFile(const char *file, const char **fullPath)
+{
+	int i = 0;
+	static struct stat sbuf;
+	char *fileName;
+	debug("finding file %s", file);
+	*fullPath = file;
+	if (0 == stat(file, &sbuf))
+		return &sbuf;
+	if (SDL_strchr(file, '/'))
+		return 0;				/* If the path had a / we don't look in env var places */
+	fileName = NULL;
+	if (!fileName)
+		fileName = (char *)file;
+	while ((*fullPath = getFullPath(i++, fileName)))
+	{
+		if (0 == stat(*fullPath, &sbuf))
+			return &sbuf;
+	}
+	;
+	return 0;
+}
+
+/* Determine whether a given dlstatus is valid or not */
+static int isValidStatus(struct dlstatus *status)
+{
+	/* Walk the list to verify status is contained in it */
+	struct dlstatus *dls = stqueue;
+	while (dls && status != dls)
+		dls = dls->next;
+	if (dls == 0)
+		error("invalid handle");
+	else if ((dls->module == 0) || (dls->refs == 0))
+		error("handle to closed library");
+	else
+		return TRUE;
+	return FALSE;
+}
+
+static inline int isFlagSet(int mode, int flag)
+{
+	return (mode & flag) == flag;
+}
+
+static struct dlstatus *lookupStatus(const struct stat *sbuf)
+{
+	struct dlstatus *dls = stqueue;
+	debug("looking for status");
+	while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
+				   || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode))
+		dls = dls->next;
+	return dls;
+}
+
+static void insertStatus(struct dlstatus *dls, const struct stat *sbuf)
+{
+	debug("inserting status");
+	dls->inode = sbuf->st_ino;
+	dls->device = sbuf->st_dev;
+	dls->refs = 0;
+	dls->mode = 0;
+	if ((dls->flags & DL_IN_LIST) == 0)
+	{
+		dls->next = stqueue;
+		stqueue = dls;
+		dls->flags |= DL_IN_LIST;
+	}
+}
+
+static struct dlstatus *allocStatus()
+{
+	struct dlstatus *dls;
+#ifdef REUSE_STATUS
+	dls = stqueue;
+	while (dls && dls->module)
+		dls = dls->next;
+	if (!dls)
+#endif
+		dls = SDL_calloc(sizeof(*dls),1);
+	return dls;
+}
+
+static int promoteLocalToGlobal(struct dlstatus *dls)
+{
+	static int (*p) (NSModule module) = 0;
+	debug("promoting");
+	if (!p)
+		_dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (void **)&p);
+	return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module));
+}
+
+static void *reference(struct dlstatus *dls, int mode)
+{
+	if (dls)
+	{
+		if (dls->module == MAGIC_DYLIB_MOD && isFlagSet(mode, RTLD_LOCAL))
+		{
+			warning("trying to open a .dylib with RTLD_LOCAL");
+			error("unable to open a .dylib with RTLD_LOCAL");
+			return NULL;
+		}
+		if (isFlagSet(mode, RTLD_GLOBAL) &&
+			!isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls))
+		{
+			error("unable to promote local module to global");
+			return NULL;
+		}
+		dls->mode |= mode;
+		dls->refs++;
+	}
+	else
+		debug("reference called with NULL argument");
+
+	return dls;
+}
+
+static const struct mach_header *my_find_image(const char *name)
+{
+	const struct mach_header *mh = 0;
+	const char *id = NULL;
+	int i = _dyld_image_count();
+	int j;
+	mh = (struct mach_header *)
+		dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
+						NSADDIMAGE_OPTION_RETURN_ON_ERROR);
+	if (!mh)
+	{
+		for (j = 0; j < i; j++)
+		{
+			id = _dyld_get_image_name(j);
+			if (!SDL_strcmp(id, name))
+			{
+				mh = _dyld_get_image_header(j);
+				break;
+			}
+		}
+	}
+	return mh;
+}
+
+/*
+ * dyld adds libraries by first adding the directly dependant libraries in link order, and
+ * then adding the dependencies for those libraries, so we should do the same... but we don't
+ * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
+ * any of it's direct dependencies, then it probably isn't there.
+ */
+static NSSymbol search_linked_libs(const struct mach_header * mh, const char *symbol)
+{
+	unsigned int n;
+	struct load_command *lc = 0;
+	struct mach_header *wh;
+	NSSymbol nssym = 0;
+	if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
+	{
+		lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+		for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+		{
+			if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
+			{
+				if ((wh = (struct mach_header *)
+					 my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
+											(char *)lc))))
+				{
+					if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
+					{
+						nssym = dyld_NSLookupSymbolInImage(wh,
+														   symbol,
+														   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
+														   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+						break;
+					}
+				}
+			}
+		}
+		if ((!nssym) && NSIsSymbolNameDefined(symbol))
+		{
+			/* I've never seen this debug message...*/
+			debug("Symbol \"%s\" is defined but was not found", symbol);
+		}
+	}
+	return nssym;
+}
+
+/* Up to the caller to SDL_free() returned string */
+static inline char *dyld_error_str()
+{
+	NSLinkEditErrors dylder;
+	int dylderno;
+	const char *dylderrstr;
+	const char *dyldfile;
+	char* retStr = NULL;
+	NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
+	if (dylderrstr && *dylderrstr)
+	{
+		retStr = SDL_strdup(dylderrstr);
+	}
+	return retStr;
+}
+
+static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
+{
+  NSSymbol nssym = 0;
+#ifdef __GCC__  
+	void *caller = __builtin_return_address(1);	/* Be *very* careful about inlining */
+#else
+	void *caller = NULL;
+#endif
+	const struct mach_header *caller_mh = 0;
+	char *savedErrorStr = NULL;
+	resetdlerror();
+#ifndef RTLD_SELF
+#define	RTLD_SELF		((void *) -3)
+#endif
+	if (NULL == dls)
+		dls = RTLD_SELF;
+	if ((RTLD_NEXT == dls) || (RTLD_SELF == dls))
+	{
+		if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage && caller)
+		  {
+			caller_mh = image_for_address(caller);
+			if (RTLD_SELF == dls)
+			{
+				/* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
+				 * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
+				 * this is acceptable.
+				 */
+				if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol))
+				{
+					nssym = dyld_NSLookupSymbolInImage(caller_mh,
+													   symbol,
+													   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
+													   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+				}
+			}
+			if (!nssym)
+			{
+				if (RTLD_SELF == dls)
+					savedErrorStr = dyld_error_str();
+				nssym = search_linked_libs(caller_mh, symbol);
+			}
+		}
+		else
+		{
+			if (canSetError)
+				error("RTLD_SELF and RTLD_NEXT are not supported");
+			return NULL;
+		}
+	}
+	if (!nssym)
+	{
+
+		if (RTLD_DEFAULT == dls)
+		{
+			dls = &mainStatus;
+		}
+		if (!isValidStatus(dls))
+			return NULL;
+
+		if (dls->module != MAGIC_DYLIB_MOD)
+		{
+			nssym = NSLookupSymbolInModule(dls->module, symbol);
+			if (!nssym && NSIsSymbolNameDefined(symbol))
+			{
+				debug("Searching dependencies");
+				savedErrorStr = dyld_error_str();
+				nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol);
+			}
+		}
+		else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
+		{
+			if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol))
+			{
+				nssym = dyld_NSLookupSymbolInImage(dls->lib,
+												   symbol,
+												   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
+												   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+			}
+			else if (NSIsSymbolNameDefined(symbol))
+			{
+				debug("Searching dependencies");
+				savedErrorStr = dyld_error_str();
+				nssym = search_linked_libs(dls->lib, symbol);
+			}
+		}
+		else if (dls->module == MAGIC_DYLIB_MOD)
+		{
+			/* Global context, use NSLookupAndBindSymbol */
+			if (NSIsSymbolNameDefined(symbol))
+			{
+				/* There doesn't seem to be a return on error option for this call???
+				   this is potentially broken, if binding fails, it will improperly
+				   exit the application. */
+				nssym = NSLookupAndBindSymbol(symbol);
+			}
+			else
+			{
+				if (savedErrorStr)
+					SDL_free(savedErrorStr);			
+				savedErrorStr = SDL_malloc(256);
+				SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);	
+			}
+		}
+	}
+	/* Error reporting */
+	if (!nssym)
+	{
+		if (!savedErrorStr || !SDL_strlen(savedErrorStr))
+		{
+			if (savedErrorStr)
+				SDL_free(savedErrorStr);
+			savedErrorStr = SDL_malloc(256);
+			SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
+		}
+		if (canSetError)
+		{
+			error(savedErrorStr);
+		}
+		else
+		{
+			debug(savedErrorStr);
+		}
+		if (savedErrorStr)
+			SDL_free(savedErrorStr);
+		return NULL;
+	}
+	return NSAddressOfSymbol(nssym);
+}
+
+static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
+{
+	NSObjectFileImage ofi = 0;
+	NSObjectFileImageReturnCode ofirc;
+	struct dlstatus *dls;
+	NSLinkEditErrors ler;
+	int lerno;
+	const char *errstr;
+	const char *file;
+	void (*init) (void);
+
+	ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
+	switch (ofirc)
+	{
+		case NSObjectFileImageSuccess:
+			break;
+		case NSObjectFileImageInappropriateFile:
+			if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
+			{	
+				if (isFlagSet(mode, RTLD_LOCAL))
+				{
+					warning("trying to open a .dylib with RTLD_LOCAL");
+					error("unable to open this file with RTLD_LOCAL");
+					return NULL;
+				}
+			}
+			else
+			{
+				error("opening this file is unsupported on this system");
+				return NULL;
+			}
+			break;
+		case NSObjectFileImageFailure:
+			error("object file setup failure");
+			return NULL;
+		case NSObjectFileImageArch:
+			error("no object for this architecture");
+			return NULL;
+		case NSObjectFileImageFormat:
+			error("bad object file format");
+			return NULL;
+		case NSObjectFileImageAccess:
+			error("can't read object file");
+			return NULL;
+		default:
+			error("unknown error from NSCreateObjectFileImageFromFile()");
+			return NULL;
+	}
+	dls = lookupStatus(sbuf);
+	if (!dls)
+	{
+		dls = allocStatus();
+	}
+	if (!dls)
+	{
+		error("unable to allocate memory");
+		return NULL;
+	}
+	//	dls->lib = 0;
+	if (ofirc == NSObjectFileImageInappropriateFile)
+	{
+		if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
+		{
+			debug("Dynamic lib loaded at %ld", dls->lib);
+			ofi = MAGIC_DYLIB_OFI;
+			dls->module = MAGIC_DYLIB_MOD;
+			ofirc = NSObjectFileImageSuccess;
+			/* Although it is possible with a bit of work to modify this so it works and
+			   functions with RTLD_NOW, I don't deem it necessary at the moment */
+		}
+		if (!(dls->module))
+		{
+			NSLinkEditError(&ler, &lerno, &file, &errstr);
+			if (!errstr || (!SDL_strlen(errstr)))
+				error("Can't open this file type");
+			else
+				error(errstr);
+			if ((dls->flags & DL_IN_LIST) == 0)
+			{
+				SDL_free(dls);
+			}
+			return NULL;
+		}
+	}
+	else
+	{
+		dls->module = NSLinkModule(ofi, path,
+								   NSLINKMODULE_OPTION_RETURN_ON_ERROR |
+								   NSLINKMODULE_OPTION_PRIVATE |
+								   (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
+		NSDestroyObjectFileImage(ofi);
+		if (dls->module)
+		{
+			dls->lib = get_mach_header_from_NSModule(dls->module);
+		}
+	}
+	if (!dls->module)
+	{
+		NSLinkEditError(&ler, &lerno, &file, &errstr);
+		if ((dls->flags & DL_IN_LIST) == 0)
+		{
+			SDL_free(dls);
+		}
+		error(errstr);
+		return NULL;
+	}
+
+	insertStatus(dls, sbuf);
+	dls = reference(dls, mode);
+	if ((init = dlsymIntern(dls, "__init", 0)))
+	{
+		debug("calling _init()");
+		init();
+	}
+	return dls;
+}
+
+inline static void dlcompat_init_check(void)
+{
+	static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER;
+	static int init_done = 0;
+
+	pthread_mutex_lock(&l);
+	if (!init_done) {
+		dlcompat_init_func();
+		init_done = 1;
+	}
+	pthread_mutex_unlock(&l);
+}
+
+static void dlcompat_init_func(void)
+{
+        _dyld_func_lookup("__dyld_NSAddImage", (void **)&dyld_NSAddImage);
+	_dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",
+			  (void **)&dyld_NSIsSymbolNameDefinedInImage);
+	_dyld_func_lookup("__dyld_NSLookupSymbolInImage", (void **)&dyld_NSLookupSymbolInImage);
+	if (pthread_mutex_init(&dlcompat_mutex, NULL))
+	    exit(1);
+	if (pthread_key_create(&dlerror_key, &dlerrorfree))
+	    exit(1);
+}
+
+static void resetdlerror()
+{
+	struct dlthread *tss;
+	tss = pthread_getspecific(dlerror_key);
+	tss->errset = 0;
+}
+
+static void dlerrorfree(void *data)
+{
+	SDL_free(data);
+}
+
+/* We kind of want a recursive lock here, but meet a little trouble
+ * because they are not available pre OS X 10.2, so we fake it
+ * using thread specific storage to keep a lock count
+ */ 
+static inline void dolock(void)
+{
+	int err = 0;
+	struct dlthread *tss;
+	dlcompat_init_check();
+	tss = pthread_getspecific(dlerror_key);
+	if (!tss)
+	{
+		tss = SDL_malloc(sizeof(struct dlthread));
+		tss->lockcnt = 0;
+		tss->errset = 0;
+		if (pthread_setspecific(dlerror_key, tss))
+		{
+			fprintf(stderr,"dlcompat: pthread_setspecific failed\n");
+			exit(1);
+		}
+	}
+	if (!tss->lockcnt)
+		err = pthread_mutex_lock(&dlcompat_mutex);
+	tss->lockcnt = tss->lockcnt +1;	
+	if (err)
+		exit(err);
+}
+
+static inline void dounlock(void)
+{
+	int err = 0;
+	struct dlthread *tss;
+	tss = pthread_getspecific(dlerror_key);
+	tss->lockcnt = tss->lockcnt -1;
+	if (!tss->lockcnt)
+		err = pthread_mutex_unlock(&dlcompat_mutex);
+	if (err)
+		exit(err);
+}
+
+static void *SDL_OSX_dlopen(const char *path, int mode)
+{
+	const struct stat *sbuf;
+	struct dlstatus *dls;
+	const char *fullPath;
+
+	dolock();
+	resetdlerror();
+	if (!path)
+	{
+		dls = &mainStatus;
+		goto dlopenok;
+	}
+	if (!(sbuf = findFile(path, &fullPath)))
+	{
+		error("file \"%s\" not found", path);
+		goto dlopenerror;
+	}
+	/* Now checks that it hasn't been closed already */
+	if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
+	{
+		/* debug("status found"); */
+		dls = reference(dls, mode);
+		goto dlopenok;
+	}
+#ifdef 	RTLD_NOLOAD
+	if (isFlagSet(mode, RTLD_NOLOAD))
+	{
+		error("no existing handle and RTLD_NOLOAD specified");
+		goto dlopenerror;
+	}
+#endif
+	if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
+	{
+		error("how can I load something both RTLD_LAZY and RTLD_NOW?");
+		goto dlopenerror;
+	}
+	dls = loadModule(fullPath, sbuf, mode);
+	
+  dlopenok:
+	dounlock();
+	return (void *)dls;
+  dlopenerror:
+	dounlock();
+	return NULL;
+}
+
+#if !FINK_BUILD
+static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
+{
+	int sym_len = SDL_strlen(symbol);
+	void *value = NULL;
+	char *malloc_sym = NULL;
+	dolock();
+	malloc_sym = SDL_malloc(sym_len + 2);
+	if (malloc_sym)
+	{
+		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
+		value = dlsymIntern(handle, malloc_sym, 1);
+		SDL_free(malloc_sym);
+	}
+	else
+	{
+		error("Unable to allocate memory");
+		goto dlsymerror;
+	}
+	dounlock();
+	return value;
+  dlsymerror:
+	dounlock();
+	return NULL;
+}
+#endif
+
+#if FINK_BUILD
+
+static void *dlsym_prepend_underscore(void *handle, const char *symbol)
+{
+	void *answer;
+	dolock();
+	answer = dlsym_prepend_underscore_intern(handle, symbol);
+	dounlock();
+	return answer;
+}
+
+static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol)
+{
+/*
+ *	A quick and easy way for porting packages which call dlsym(handle,"sym")
+ *	If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
+ *	this function will be called, and will add the required underscore.
+ *	
+ *	Note that I haven't figured out yet which should be "standard", prepend
+ *	the underscore always, or not at all. These global functions need to go away
+ *	for opendarwin.
+ */
+	int sym_len = SDL_strlen(symbol);
+	void *value = NULL;
+	char *malloc_sym = NULL;
+	malloc_sym = SDL_malloc(sym_len + 2);
+	if (malloc_sym)
+	{
+		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
+		value = dlsymIntern(handle, malloc_sym, 1);
+		SDL_free(malloc_sym);
+	}
+	else
+	{
+		error("Unable to allocate memory");
+	}
+	return value;
+}
+
+static void *dlsym_auto_underscore(void *handle, const char *symbol)
+{
+	void *answer;
+	dolock();
+	answer = dlsym_auto_underscore_intern(handle, symbol);
+	dounlock();
+	return answer;
+
+}
+static void *dlsym_auto_underscore_intern(void *handle, const char *symbol)
+{
+	struct dlstatus *dls = handle;
+	void *addr = 0;
+	addr = dlsymIntern(dls, symbol, 0);
+	if (!addr)
+		addr = dlsym_prepend_underscore_intern(handle, symbol);
+	return addr;
+}
+
+
+static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
+{
+	struct dlstatus *dls = handle;
+	void *addr = 0;
+	dolock();
+	addr = dlsymIntern(dls, symbol, 1);
+	dounlock();
+	return addr;
+}
+#endif
+
+static int SDL_OSX_dlclose(void *handle)
+{
+	struct dlstatus *dls = handle;
+	dolock();
+	resetdlerror();
+	if (!isValidStatus(dls))
+	{
+		goto dlcloseerror;
+	}
+	if (dls->module == MAGIC_DYLIB_MOD)
+	{
+		const char *name;
+		if (!dls->lib)
+		{
+			name = "global context";
+		}
+		else
+		{
+			name = get_lib_name(dls->lib);
+		}
+		warning("trying to close a .dylib!");
+		error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
+		goto dlcloseerror;
+	}
+	if (!dls->module)
+	{
+		error("module already closed");
+		goto dlcloseerror;
+	}
+	
+	if (dls->refs == 1)
+	{
+		unsigned long options = 0;
+		void (*fini) (void);
+		if ((fini = dlsymIntern(dls, "__fini", 0)))
+		{
+			debug("calling _fini()");
+			fini();
+		}
+		options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
+#ifdef RTLD_NODELETE
+		if (isFlagSet(dls->mode, RTLD_NODELETE))
+			options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
+#endif
+		if (!NSUnLinkModule(dls->module, options))
+		{
+			error("unable to unlink module");
+			goto dlcloseerror;
+		}
+		dls->refs--;
+		dls->module = 0;
+		/* Note: the dlstatus struct dls is neither removed from the list
+		 * nor is the memory it occupies freed. This shouldn't pose a 
+		 * problem in mostly all cases, though.
+		 */
+	}
+	dounlock();
+	return 0;
+  dlcloseerror:
+	dounlock();
+	return 1;
+}
+
+static const char *SDL_OSX_dlerror(void)
+{
+	struct dlthread  *tss;
+	const char * err_str = NULL;
+	dlcompat_init_check();
+	tss = pthread_getspecific(dlerror_key);
+	if (tss != NULL && tss->errset != 0) {
+		tss->errset = 0;	
+		err_str = tss->errstr;
+	}
+	return (err_str);
+}
+
+/* Given an address, return the mach_header for the image containing it
+ * or zero if the given address is not contained in any loaded images.
+ */
+static const struct mach_header *image_for_address(const void *address)
+{
+	unsigned long i;
+	unsigned long j;
+	unsigned long count = _dyld_image_count();
+	const struct mach_header *mh = 0;
+	struct load_command *lc = 0;
+	unsigned long addr = 0;
+	for (i = 0; i < count; i++)
+	{
+		addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i);
+		mh = _dyld_get_image_header(i);
+		if (mh)
+		{
+			lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+			for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+			{
+				if (LC_SEGMENT == lc->cmd &&
+					addr >= ((struct segment_command *)lc)->vmaddr &&
+					addr <
+					((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
+				{
+					goto image_found;
+				}
+			}
+		}
+		mh = 0;
+	}
+  image_found:
+	return mh;
+}
+
+#if 0 /* unused */
+static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restrict info)
+{
+/*
+	FIXME: USe the routine image_for_address.
+*/
+	unsigned long i;
+	unsigned long j;
+	unsigned long count = _dyld_image_count();
+	struct mach_header *mh = 0;
+	struct load_command *lc = 0;
+	unsigned long addr = NULL;
+	unsigned long table_off = (unsigned long)0;
+	int found = 0;
+	if (!info)
+		return 0;
+	dolock();
+	resetdlerror();
+	info->dli_fname = 0;
+	info->dli_fbase = 0;
+	info->dli_sname = 0;
+	info->dli_saddr = 0;
+/* Some of this was swiped from code posted by Douglas Davidson <ddavidso AT apple DOT com>
+ * to darwin-development AT lists DOT apple DOT com and slightly modified
+ */
+	for (i = 0; i < count; i++)
+	{
+		addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
+		mh = _dyld_get_image_header(i);
+		if (mh)
+		{
+			lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+			for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+			{
+				if (LC_SEGMENT == lc->cmd &&
+					addr >= ((struct segment_command *)lc)->vmaddr &&
+					addr <
+					((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
+				{
+					info->dli_fname = _dyld_get_image_name(i);
+					info->dli_fbase = (void *)mh;
+					found = 1;
+					break;
+				}
+			}
+			if (found)
+				break;
+		}
+	}
+	if (!found)
+	{
+		dounlock();
+		return 0;
+	}
+	lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+	for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+	{
+		if (LC_SEGMENT == lc->cmd)
+		{
+			if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
+				break;
+		}
+	}
+	table_off =
+		((unsigned long)((struct segment_command *)lc)->vmaddr) -
+		((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
+	debug("table off %x", table_off);
+
+	lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+	for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+	{
+		if (LC_SYMTAB == lc->cmd)
+		{
+
+			struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
+			unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
+			struct nlist *nearest = NULL;
+			unsigned long diff = 0xffffffff;
+			unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
+			debug("symtable %x", symtable);
+			for (i = 0; i < numsyms; i++)
+			{
+				/* Ignore the following kinds of Symbols */
+				if ((!symtable->n_value)	/* Undefined */
+					|| (symtable->n_type >= N_PEXT)	/* Debug symbol */
+					|| (!(symtable->n_type & N_EXT))	/* Local Symbol */
+					)
+				{
+					symtable++;
+					continue;
+				}
+				if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr)))
+				{
+					diff = (unsigned long)symtable->n_value - addr;
+					nearest = symtable;
+				}
+				symtable++;
+			}
+			if (nearest)
+			{
+				info->dli_saddr = nearest->n_value + ((void *)p - addr);
+				info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
+			}
+		}
+	}
+	dounlock();
+	return 1;
+}
+#endif
+
+/*
+ * Implement the dlfunc() interface, which behaves exactly the same as
+ * dlsym() except that it returns a function pointer instead of a data
+ * pointer.  This can be used by applications to avoid compiler warnings
+ * about undefined behavior, and is intended as prior art for future
+ * POSIX standardization.  This function requires that all pointer types
+ * have the same representation, which is true on all platforms FreeBSD
+ * runs on, but is not guaranteed by the C standard.
+ */
+#if 0 
+static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restrict symbol)
+{
+	union
+	{
+		void *d;
+		dlfunc_t f;
+	} rv;
+	int sym_len = SDL_strlen(symbol);
+	char *malloc_sym = NULL;
+	dolock();
+	malloc_sym = SDL_malloc(sym_len + 2);
+	if (malloc_sym)
+	{
+		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
+		rv.d = dlsymIntern(handle, malloc_sym, 1);
+		SDL_free(malloc_sym);
+	}
+	else
+	{
+		error("Unable to allocate memory");
+		goto dlfuncerror;
+	}
+	dounlock();
+	return rv.f;
+  dlfuncerror:
+	dounlock();
+	return NULL;
+}
+#endif
+
+
+
+/* dlcompat ends, here's the SDL interface...  --ryan.  */
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent library loading routines                           */
+
+#include "SDL_loadso.h"
+
+void *SDL_LoadObject(const char *sofile)
+{
+	void *handle = SDL_OSX_dlopen(sofile, RTLD_NOW);
+	const char *loaderror = SDL_OSX_dlerror();
+	if ( handle == NULL ) {
+		SDL_SetError("Failed loading %s: %s", sofile, loaderror);
+	}
+	return(handle);
+}
+
+void *SDL_LoadFunction(void *handle, const char *name)
+{
+	void *symbol = SDL_OSX_dlsym(handle, name);
+	if ( symbol == NULL ) {
+		SDL_SetError("Failed loading %s: %s", name, SDL_OSX_dlerror());
+	}
+	return(symbol);
+}
+
+void SDL_UnloadObject(void *handle)
+{
+	if ( handle != NULL ) {
+		SDL_OSX_dlclose(handle);
+	}
+}
+
+#endif /* SDL_LOADSO_DLCOMPAT */
--- a/src/loadso/macosx/SDL_sysloadso.c	Mon May 01 06:58:33 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1404 +0,0 @@
-/*
-    SDL - Simple DirectMedia Layer
-    Copyright (C) 1997-2006 Sam Lantinga
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-    Sam Lantinga
-    slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-#ifdef SDL_LOADSO_DLCOMPAT
-
-/* Please note that dlcompat apparently ships in current Mac OS X versions
- *  as a system library that provides compatibility with the Unix "dlopen"
- *  interface. In order to allow SDL to work on older OS X releases and also
- *  not conflict with the system lib on newer versions, we include dlcompat
- *  in SDL and change the symbols to prevent symbol clash with any existing
- *  system libraries.  --ryan.
- */
-
-/* here is the dlcompat license: */
-
-/*
-Copyright (c) 2002 Jorge Acereda  <jacereda@users.sourceforge.net> &
-                   Peter O'Gorman <ogorman@users.sourceforge.net>
-                   
-Portions may be copyright others, see the AUTHORS file included with this
-distribution.
-
-Maintained by Peter O'Gorman <ogorman@users.sourceforge.net>
-
-Bug Reports and other queries should go to <ogorman@users.sourceforge.net>
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <pthread.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdarg.h>
-#include <limits.h>
-#include <mach-o/dyld.h>
-#include <mach-o/nlist.h>
-#include <mach-o/getsect.h>
-
-#include "SDL_stdinc.h"
-
-/* Just playing to see if it would compile with the freebsd headers, it does,
- * but because of the different values for RTLD_LOCAL etc, it would break binary
- * compat... oh well
- */
-#ifndef __BSD_VISIBLE
-#define __BSD_VISIBLE 1
-#endif
-
-/*include "dlfcn.h"*/
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined (__GNUC__) && __GNUC__ > 3
-#define dl_restrict __restrict
-#else
-#define dl_restrict
-#endif
-
-#ifndef _POSIX_SOURCE
-/*
- * Structure filled in by dladdr().
- */
-typedef struct SDL_OSX_dl_info {
-        const char      *dli_fname;     /* Pathname of shared object */
-        void            *dli_fbase;     /* Base address of shared object */
-        const char      *dli_sname;     /* Name of nearest symbol */
-        void            *dli_saddr;     /* Address of nearest symbol */
-} SDL_OSX_Dl_info;
-
-static int SDL_OSX_dladdr(const void * dl_restrict, SDL_OSX_Dl_info * dl_restrict);
-#endif /* ! _POSIX_SOURCE */
-
-static int SDL_OSX_dlclose(void * handle);
-static const char * SDL_OSX_dlerror(void);
-static void * SDL_OSX_dlopen(const char *path, int mode);
-static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol);
-
-#define RTLD_LAZY	0x1
-#define RTLD_NOW	0x2
-#define RTLD_LOCAL	0x4
-#define RTLD_GLOBAL	0x8
-
-#ifndef _POSIX_SOURCE
-#define RTLD_NOLOAD	0x10
-#define RTLD_NODELETE	0x80
-
-/*
- * Special handle arguments for SDL_OSX_dlsym().
- */
-#define	RTLD_NEXT		((void *) -1)	/* Search subsequent objects. */
-#define	RTLD_DEFAULT	((void *) -2)	/* Use default search algorithm. */
-#endif /* ! _POSIX_SOURCE */
-
-#ifdef __cplusplus
-}
-#endif
-
-#ifndef dl_restrict
-#define dl_restrict __restrict
-#endif
-/* This is not available on 10.1 */
-#ifndef LC_LOAD_WEAK_DYLIB
-#define	LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
-#endif
-
-/* With this stuff here, this thing may actually compile/run on 10.0 systems
- * Not that I have a 10.0 system to test it on anylonger
- */
-#ifndef LC_REQ_DYLD
-#define LC_REQ_DYLD 0x80000000
-#endif
-#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
-#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
-#endif
-#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
-#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
-#endif
-#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
-#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
-#endif
-#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
-#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
-#endif
-/* These symbols will be looked for in dyld */
-static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0;
-static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0;
-static NSSymbol(*dyld_NSLookupSymbolInImage)
-	(const struct mach_header *, const char *, unsigned long) = 0;
-
-/* Define this to make dlcompat reuse data block. This way in theory we save
- * a little bit of overhead. However we then couldn't correctly catch excess
- * calls to SDL_OSX_dlclose(). Hence we don't use this feature
- */
-#undef REUSE_STATUS
-
-/* Size of the internal error message buffer (used by dlerror()) */
-#define ERR_STR_LEN			251
-
-/* Maximum number of search paths supported by getSearchPath */
-#define MAX_SEARCH_PATHS	32
-
-
-#define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
-#define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
-
-/* internal flags */
-#define DL_IN_LIST 0x01
-
-/* our mutex */
-static pthread_mutex_t dlcompat_mutex;
-/* Our thread specific storage
- */
-static pthread_key_t dlerror_key;
-
-struct dlthread
-{
-	int lockcnt;
-	unsigned char errset;
-	char errstr[ERR_STR_LEN];
-};
-
-/* This is our central data structure. Whenever a module is loaded via
- * SDL_OSX_dlopen(), we create such a struct.
- */
-struct dlstatus
-{
-	struct dlstatus *next;		/* pointer to next element in the linked list */
-	NSModule module;
-	const struct mach_header *lib;
-	int refs;					/* reference count */
-	int mode;					/* mode in which this module was loaded */
-	dev_t device;
-	ino_t inode;
-	int flags;					/* Any internal flags we may need */
-};
-
-/* Head node of the dlstatus list */
-static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
-static struct dlstatus *stqueue = &mainStatus;
-
-
-/* Storage for the last error message (used by dlerror()) */
-/* static char err_str[ERR_STR_LEN]; */
-/* static int err_filled = 0; */
-
-/* Prototypes to internal functions */
-static void debug(const char *fmt, ...);
-static void error(const char *str, ...);
-static const char *safegetenv(const char *s);
-static const char *searchList(void);
-static const char *getSearchPath(int i);
-static const char *getFullPath(int i, const char *file);
-static const struct stat *findFile(const char *file, const char **fullPath);
-static int isValidStatus(struct dlstatus *status);
-static inline int isFlagSet(int mode, int flag);
-static struct dlstatus *lookupStatus(const struct stat *sbuf);
-static void insertStatus(struct dlstatus *dls, const struct stat *sbuf);
-static int promoteLocalToGlobal(struct dlstatus *dls);
-static void *reference(struct dlstatus *dls, int mode);
-static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError);
-static struct dlstatus *allocStatus(void);
-static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode);
-static NSSymbol *search_linked_libs(const struct mach_header *mh, const char *symbol);
-static const char *get_lib_name(const struct mach_header *mh);
-static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod);
-static void dlcompat_init_func(void);
-static inline void dlcompat_init_check(void);
-static inline void dolock(void);
-static inline void dounlock(void);
-static void dlerrorfree(void *data);
-static void resetdlerror(void);
-static const struct mach_header *my_find_image(const char *name);
-static const struct mach_header *image_for_address(const void *address);
-static inline char *dyld_error_str(void);
-
-#if FINK_BUILD
-/* Two Global Functions */
-static void *dlsym_prepend_underscore(void *handle, const char *symbol);
-static void *dlsym_auto_underscore(void *handle, const char *symbol);
-
-/* And their _intern counterparts */
-static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol);
-static void *dlsym_auto_underscore_intern(void *handle, const char *symbol);
-#endif
-
-/* Functions */
-
-static void debug(const char *fmt, ...)
-{
-#if DEBUG > 1
-	va_list arg;
-	va_start(arg, fmt);
-	fprintf(stderr, "DLDEBUG: ");
-	vfprintf(stderr, fmt, arg);
-	fprintf(stderr, "\n");
-	fflush(stderr);
-	va_end(arg);
-#endif
-}
-
-static void error(const char *str, ...)
-{
-	va_list arg;
-	struct dlthread  *tss;
-	char * err_str;
-	va_start(arg, str);
-	tss = pthread_getspecific(dlerror_key);
-	err_str = tss->errstr;
-	SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN);
-	vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
-	va_end(arg);
-	debug("ERROR: %s\n", err_str);
-	tss->errset = 1;
-}
-
-static void warning(const char *str)
-{
-#if DEBUG > 0
-	fprintf(stderr, "WARNING: dlcompat: %s\n", str);
-#endif
-}
-
-static const char *safegetenv(const char *s)
-{
-	const char *ss = SDL_getenv(s);
-	return ss ? ss : "";
-}
-
-/* because this is only used for debugging and error reporting functions, we
- * don't really care about how elegant it is... it could use the load
- * commands to find the install name of the library, but...
- */
-static const char *get_lib_name(const struct mach_header *mh)
-{
-	unsigned long count = _dyld_image_count();
-	unsigned long i;
-	const char *val = NULL;
-	if (mh)
-	{
-		for (i = 0; i < count; i++)
-		{
-			if (mh == _dyld_get_image_header(i))
-			{
-				val = _dyld_get_image_name(i);
-				break;
-			}
-		}
-	}
-	return val;
-}
-
-/* Returns the mach_header for the module bu going through all the loaded images
- * and finding the one with the same name as the module. There really ought to be
- * an api for doing this, would be faster, but there isn't one right now
- */
-static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod)
-{
-	const char *mod_name = NSNameOfModule(mod);
-	struct mach_header *mh = NULL;
-	unsigned long count = _dyld_image_count();
-	unsigned long i;
-	debug("Module name: %s", mod_name);
-	for (i = 0; i < count; i++)
-	{
-		if (!SDL_strcmp(mod_name, _dyld_get_image_name(i)))
-		{
-			mh = _dyld_get_image_header(i);
-			break;
-		}
-	}
-	return mh;
-}
-
-
-/* Compute and return a list of all directories that we should search when
- * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
- * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
- * /usr/lib and /lib. Since both of the environments variables can contain a
- * list of colon seperated paths, we simply concat them and the two other paths
- * into one big string, which we then can easily parse.
- * Splitting this string into the actual path list is done by getSearchPath()
- */
-static const char *searchList()
-{
-	size_t buf_size;
-	static char *buf=NULL;
-	const char *ldlp = safegetenv("LD_LIBRARY_PATH");
-	const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
-	const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH");
-	if (!stdpath)
-		stdpath = "/usr/local/lib:/lib:/usr/lib";
-	if (!buf)
-	{	
-		buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4;
-		buf = SDL_malloc(buf_size);
-		SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
-				 stdpath, '\0');
-	}
-	return buf;
-}
-
-/* Returns the ith search path from the list as computed by searchList() */
-static const char *getSearchPath(int i)
-{
-	static const char *list = 0;
-	static char **path = (char **)0;
-	static int end = 0;
-	static int numsize = MAX_SEARCH_PATHS;
-	static char **tmp;
-	/* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
-	if (i == -1)
-	{
-		return (const char*)path;
-	}
-	if (!path)
-	{
-		path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **));
-	}
-	if (!list && !end)
-		list = searchList();
-	if (i >= (numsize))
-	{
-		debug("Increasing size for long PATH");
-		tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
-		if (tmp)
-		{
-			SDL_memcpy(tmp, path, sizeof(char **) * numsize);
-			SDL_free(path);
-			path = tmp;
-			numsize += MAX_SEARCH_PATHS;
-		}
-		else
-		{
-			return 0;
-		}
-	}
-
-	while (!path[i] && !end)
-	{
-		path[i] = strsep((char **)&list, ":");
-
-		if (path[i][0] == 0)
-			path[i] = 0;
-		end = (list == 0);
-	}
-	return path[i];
-}
-
-static const char *getFullPath(int i, const char *file)
-{
-	static char buf[PATH_MAX];
-	const char *path = getSearchPath(i);
-	if (path)
-	{
-		SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file);
-	}
-	return path ? buf : 0;
-}
-
-/* Given a file name, try to determine the full path for that file. Starts
- * its search in the current directory, and then tries all paths in the 
- * search list in the order they are specified there.
- */
-static const struct stat *findFile(const char *file, const char **fullPath)
-{
-	int i = 0;
-	static struct stat sbuf;
-	char *fileName;
-	debug("finding file %s", file);
-	*fullPath = file;
-	if (0 == stat(file, &sbuf))
-		return &sbuf;
-	if (SDL_strchr(file, '/'))
-		return 0;				/* If the path had a / we don't look in env var places */
-	fileName = NULL;
-	if (!fileName)
-		fileName = (char *)file;
-	while ((*fullPath = getFullPath(i++, fileName)))
-	{
-		if (0 == stat(*fullPath, &sbuf))
-			return &sbuf;
-	}
-	;
-	return 0;
-}
-
-/* Determine whether a given dlstatus is valid or not */
-static int isValidStatus(struct dlstatus *status)
-{
-	/* Walk the list to verify status is contained in it */
-	struct dlstatus *dls = stqueue;
-	while (dls && status != dls)
-		dls = dls->next;
-	if (dls == 0)
-		error("invalid handle");
-	else if ((dls->module == 0) || (dls->refs == 0))
-		error("handle to closed library");
-	else
-		return TRUE;
-	return FALSE;
-}
-
-static inline int isFlagSet(int mode, int flag)
-{
-	return (mode & flag) == flag;
-}
-
-static struct dlstatus *lookupStatus(const struct stat *sbuf)
-{
-	struct dlstatus *dls = stqueue;
-	debug("looking for status");
-	while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
-				   || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode))
-		dls = dls->next;
-	return dls;
-}
-
-static void insertStatus(struct dlstatus *dls, const struct stat *sbuf)
-{
-	debug("inserting status");
-	dls->inode = sbuf->st_ino;
-	dls->device = sbuf->st_dev;
-	dls->refs = 0;
-	dls->mode = 0;
-	if ((dls->flags & DL_IN_LIST) == 0)
-	{
-		dls->next = stqueue;
-		stqueue = dls;
-		dls->flags |= DL_IN_LIST;
-	}
-}
-
-static struct dlstatus *allocStatus()
-{
-	struct dlstatus *dls;
-#ifdef REUSE_STATUS
-	dls = stqueue;
-	while (dls && dls->module)
-		dls = dls->next;
-	if (!dls)
-#endif
-		dls = SDL_calloc(sizeof(*dls),1);
-	return dls;
-}
-
-static int promoteLocalToGlobal(struct dlstatus *dls)
-{
-	static int (*p) (NSModule module) = 0;
-	debug("promoting");
-	if (!p)
-		_dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (unsigned long *)&p);
-	return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module));
-}
-
-static void *reference(struct dlstatus *dls, int mode)
-{
-	if (dls)
-	{
-		if (dls->module == MAGIC_DYLIB_MOD && isFlagSet(mode, RTLD_LOCAL))
-		{
-			warning("trying to open a .dylib with RTLD_LOCAL");
-			error("unable to open a .dylib with RTLD_LOCAL");
-			return NULL;
-		}
-		if (isFlagSet(mode, RTLD_GLOBAL) &&
-			!isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls))
-		{
-			error("unable to promote local module to global");
-			return NULL;
-		}
-		dls->mode |= mode;
-		dls->refs++;
-	}
-	else
-		debug("reference called with NULL argument");
-
-	return dls;
-}
-
-static const struct mach_header *my_find_image(const char *name)
-{
-	const struct mach_header *mh = 0;
-	const char *id = NULL;
-	int i = _dyld_image_count();
-	int j;
-	mh = (struct mach_header *)
-		dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
-						NSADDIMAGE_OPTION_RETURN_ON_ERROR);
-	if (!mh)
-	{
-		for (j = 0; j < i; j++)
-		{
-			id = _dyld_get_image_name(j);
-			if (!SDL_strcmp(id, name))
-			{
-				mh = _dyld_get_image_header(j);
-				break;
-			}
-		}
-	}
-	return mh;
-}
-
-/*
- * dyld adds libraries by first adding the directly dependant libraries in link order, and
- * then adding the dependencies for those libraries, so we should do the same... but we don't
- * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
- * any of it's direct dependencies, then it probably isn't there.
- */
-static NSSymbol *search_linked_libs(const struct mach_header * mh, const char *symbol)
-{
-	unsigned int n;
-	struct load_command *lc = 0;
-	struct mach_header *wh;
-	NSSymbol *nssym = 0;
-	if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
-	{
-		lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
-		for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
-		{
-			if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
-			{
-				if ((wh = (struct mach_header *)
-					 my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
-											(char *)lc))))
-				{
-					if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
-					{
-						nssym = dyld_NSLookupSymbolInImage(wh,
-														   symbol,
-														   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
-														   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
-						break;
-					}
-				}
-			}
-		}
-		if ((!nssym) && NSIsSymbolNameDefined(symbol))
-		{
-			/* I've never seen this debug message...*/
-			debug("Symbol \"%s\" is defined but was not found", symbol);
-		}
-	}
-	return nssym;
-}
-
-/* Up to the caller to SDL_free() returned string */
-static inline char *dyld_error_str()
-{
-	NSLinkEditErrors dylder;
-	int dylderno;
-	const char *dylderrstr;
-	const char *dyldfile;
-	char* retStr = NULL;
-	NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
-	if (dylderrstr && *dylderrstr)
-	{
-		retStr = SDL_strdup(dylderrstr);
-	}
-	return retStr;
-}
-
-static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
-{
-  NSSymbol *nssym = 0;
-#ifdef __GCC__  
-	void *caller = __builtin_return_address(1);	/* Be *very* careful about inlining */
-#else
-	void *caller = NULL;
-#endif
-	const struct mach_header *caller_mh = 0;
-	char *savedErrorStr = NULL;
-	resetdlerror();
-#ifndef RTLD_SELF
-#define	RTLD_SELF		((void *) -3)
-#endif
-	if (NULL == dls)
-		dls = RTLD_SELF;
-	if ((RTLD_NEXT == dls) || (RTLD_SELF == dls))
-	{
-		if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage && caller)
-		  {
-			caller_mh = image_for_address(caller);
-			if (RTLD_SELF == dls)
-			{
-				/* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
-				 * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
-				 * this is acceptable.
-				 */
-				if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol))
-				{
-					nssym = dyld_NSLookupSymbolInImage(caller_mh,
-													   symbol,
-													   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
-													   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
-				}
-			}
-			if (!nssym)
-			{
-				if (RTLD_SELF == dls)
-					savedErrorStr = dyld_error_str();
-				nssym = search_linked_libs(caller_mh, symbol);
-			}
-		}
-		else
-		{
-			if (canSetError)
-				error("RTLD_SELF and RTLD_NEXT are not supported");
-			return NULL;
-		}
-	}
-	if (!nssym)
-	{
-
-		if (RTLD_DEFAULT == dls)
-		{
-			dls = &mainStatus;
-		}
-		if (!isValidStatus(dls))
-			return NULL;
-
-		if (dls->module != MAGIC_DYLIB_MOD)
-		{
-			nssym = NSLookupSymbolInModule(dls->module, symbol);
-			if (!nssym && NSIsSymbolNameDefined(symbol))
-			{
-				debug("Searching dependencies");
-				savedErrorStr = dyld_error_str();
-				nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol);
-			}
-		}
-		else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
-		{
-			if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol))
-			{
-				nssym = dyld_NSLookupSymbolInImage(dls->lib,
-												   symbol,
-												   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
-												   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
-			}
-			else if (NSIsSymbolNameDefined(symbol))
-			{
-				debug("Searching dependencies");
-				savedErrorStr = dyld_error_str();
-				nssym = search_linked_libs(dls->lib, symbol);
-			}
-		}
-		else if (dls->module == MAGIC_DYLIB_MOD)
-		{
-			/* Global context, use NSLookupAndBindSymbol */
-			if (NSIsSymbolNameDefined(symbol))
-			{
-				/* There doesn't seem to be a return on error option for this call???
-				   this is potentially broken, if binding fails, it will improperly
-				   exit the application. */
-				nssym = NSLookupAndBindSymbol(symbol);
-			}
-			else
-			{
-				if (savedErrorStr)
-					SDL_free(savedErrorStr);			
-				savedErrorStr = SDL_malloc(256);
-				SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);	
-			}
-		}
-	}
-	/* Error reporting */
-	if (!nssym)
-	{
-		if (!savedErrorStr || !SDL_strlen(savedErrorStr))
-		{
-			if (savedErrorStr)
-				SDL_free(savedErrorStr);
-			savedErrorStr = SDL_malloc(256);
-			SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
-		}
-		if (canSetError)
-		{
-			error(savedErrorStr);
-		}
-		else
-		{
-			debug(savedErrorStr);
-		}
-		if (savedErrorStr)
-			SDL_free(savedErrorStr);
-		return NULL;
-	}
-	return NSAddressOfSymbol(nssym);
-}
-
-static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
-{
-	NSObjectFileImage ofi = 0;
-	NSObjectFileImageReturnCode ofirc;
-	struct dlstatus *dls;
-	NSLinkEditErrors ler;
-	int lerno;
-	const char *errstr;
-	const char *file;
-	void (*init) (void);
-
-	ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
-	switch (ofirc)
-	{
-		case NSObjectFileImageSuccess:
-			break;
-		case NSObjectFileImageInappropriateFile:
-			if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
-			{	
-				if (isFlagSet(mode, RTLD_LOCAL))
-				{
-					warning("trying to open a .dylib with RTLD_LOCAL");
-					error("unable to open this file with RTLD_LOCAL");
-					return NULL;
-				}
-			}
-			else
-			{
-				error("opening this file is unsupported on this system");
-				return NULL;
-			}
-			break;
-		case NSObjectFileImageFailure:
-			error("object file setup failure");
-			return NULL;
-		case NSObjectFileImageArch:
-			error("no object for this architecture");
-			return NULL;
-		case NSObjectFileImageFormat:
-			error("bad object file format");
-			return NULL;
-		case NSObjectFileImageAccess:
-			error("can't read object file");
-			return NULL;
-		default:
-			error("unknown error from NSCreateObjectFileImageFromFile()");
-			return NULL;
-	}
-	dls = lookupStatus(sbuf);
-	if (!dls)
-	{
-		dls = allocStatus();
-	}
-	if (!dls)
-	{
-		error("unable to allocate memory");
-		return NULL;
-	}
-	//	dls->lib = 0;
-	if (ofirc == NSObjectFileImageInappropriateFile)
-	{
-		if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
-		{
-			debug("Dynamic lib loaded at %ld", dls->lib);
-			ofi = MAGIC_DYLIB_OFI;
-			dls->module = MAGIC_DYLIB_MOD;
-			ofirc = NSObjectFileImageSuccess;
-			/* Although it is possible with a bit of work to modify this so it works and
-			   functions with RTLD_NOW, I don't deem it necessary at the moment */
-		}
-		if (!(dls->module))
-		{
-			NSLinkEditError(&ler, &lerno, &file, &errstr);
-			if (!errstr || (!SDL_strlen(errstr)))
-				error("Can't open this file type");
-			else
-				error(errstr);
-			if ((dls->flags & DL_IN_LIST) == 0)
-			{
-				SDL_free(dls);
-			}
-			return NULL;
-		}
-	}
-	else
-	{
-		dls->module = NSLinkModule(ofi, path,
-								   NSLINKMODULE_OPTION_RETURN_ON_ERROR |
-								   NSLINKMODULE_OPTION_PRIVATE |
-								   (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
-		NSDestroyObjectFileImage(ofi);
-		if (dls->module)
-		{
-			dls->lib = get_mach_header_from_NSModule(dls->module);
-		}
-	}
-	if (!dls->module)
-	{
-		NSLinkEditError(&ler, &lerno, &file, &errstr);
-		if ((dls->flags & DL_IN_LIST) == 0)
-		{
-			SDL_free(dls);
-		}
-		error(errstr);
-		return NULL;
-	}
-
-	insertStatus(dls, sbuf);
-	dls = reference(dls, mode);
-	if ((init = dlsymIntern(dls, "__init", 0)))
-	{
-		debug("calling _init()");
-		init();
-	}
-	return dls;
-}
-
-inline static void dlcompat_init_check(void)
-{
-	static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER;
-	static int init_done = 0;
-
-	pthread_mutex_lock(&l);
-	if (!init_done) {
-		dlcompat_init_func();
-		init_done = 1;
-	}
-	pthread_mutex_unlock(&l);
-}
-
-static void dlcompat_init_func(void)
-{
-        _dyld_func_lookup("__dyld_NSAddImage", (unsigned long *)&dyld_NSAddImage);
-	_dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",
-			  (unsigned long *)&dyld_NSIsSymbolNameDefinedInImage);
-	_dyld_func_lookup("__dyld_NSLookupSymbolInImage", (unsigned long *)&dyld_NSLookupSymbolInImage);
-	if (pthread_mutex_init(&dlcompat_mutex, NULL))
-	    exit(1);
-	if (pthread_key_create(&dlerror_key, &dlerrorfree))
-	    exit(1);
-}
-
-static void resetdlerror()
-{
-	struct dlthread *tss;
-	tss = pthread_getspecific(dlerror_key);
-	tss->errset = 0;
-}
-
-static void dlerrorfree(void *data)
-{
-	SDL_free(data);
-}
-
-/* We kind of want a recursive lock here, but meet a little trouble
- * because they are not available pre OS X 10.2, so we fake it
- * using thread specific storage to keep a lock count
- */ 
-static inline void dolock(void)
-{
-	int err = 0;
-	struct dlthread *tss;
-	dlcompat_init_check();
-	tss = pthread_getspecific(dlerror_key);
-	if (!tss)
-	{
-		tss = SDL_malloc(sizeof(struct dlthread));
-		tss->lockcnt = 0;
-		tss->errset = 0;
-		if (pthread_setspecific(dlerror_key, tss))
-		{
-			fprintf(stderr,"dlcompat: pthread_setspecific failed\n");
-			exit(1);
-		}
-	}
-	if (!tss->lockcnt)
-		err = pthread_mutex_lock(&dlcompat_mutex);
-	tss->lockcnt = tss->lockcnt +1;	
-	if (err)
-		exit(err);
-}
-
-static inline void dounlock(void)
-{
-	int err = 0;
-	struct dlthread *tss;
-	tss = pthread_getspecific(dlerror_key);
-	tss->lockcnt = tss->lockcnt -1;
-	if (!tss->lockcnt)
-		err = pthread_mutex_unlock(&dlcompat_mutex);
-	if (err)
-		exit(err);
-}
-
-static void *SDL_OSX_dlopen(const char *path, int mode)
-{
-	const struct stat *sbuf;
-	struct dlstatus *dls;
-	const char *fullPath;
-
-	dolock();
-	resetdlerror();
-	if (!path)
-	{
-		dls = &mainStatus;
-		goto dlopenok;
-	}
-	if (!(sbuf = findFile(path, &fullPath)))
-	{
-		error("file \"%s\" not found", path);
-		goto dlopenerror;
-	}
-	/* Now checks that it hasn't been closed already */
-	if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
-	{
-		/* debug("status found"); */
-		dls = reference(dls, mode);
-		goto dlopenok;
-	}
-#ifdef 	RTLD_NOLOAD
-	if (isFlagSet(mode, RTLD_NOLOAD))
-	{
-		error("no existing handle and RTLD_NOLOAD specified");
-		goto dlopenerror;
-	}
-#endif
-	if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
-	{
-		error("how can I load something both RTLD_LAZY and RTLD_NOW?");
-		goto dlopenerror;
-	}
-	dls = loadModule(fullPath, sbuf, mode);
-	
-  dlopenok:
-	dounlock();
-	return (void *)dls;
-  dlopenerror:
-	dounlock();
-	return NULL;
-}
-
-#if !FINK_BUILD
-static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
-{
-	int sym_len = SDL_strlen(symbol);
-	void *value = NULL;
-	char *malloc_sym = NULL;
-	dolock();
-	malloc_sym = SDL_malloc(sym_len + 2);
-	if (malloc_sym)
-	{
-		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
-		value = dlsymIntern(handle, malloc_sym, 1);
-		SDL_free(malloc_sym);
-	}
-	else
-	{
-		error("Unable to allocate memory");
-		goto dlsymerror;
-	}
-	dounlock();
-	return value;
-  dlsymerror:
-	dounlock();
-	return NULL;
-}
-#endif
-
-#if FINK_BUILD
-
-static void *dlsym_prepend_underscore(void *handle, const char *symbol)
-{
-	void *answer;
-	dolock();
-	answer = dlsym_prepend_underscore_intern(handle, symbol);
-	dounlock();
-	return answer;
-}
-
-static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol)
-{
-/*
- *	A quick and easy way for porting packages which call dlsym(handle,"sym")
- *	If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
- *	this function will be called, and will add the required underscore.
- *	
- *	Note that I haven't figured out yet which should be "standard", prepend
- *	the underscore always, or not at all. These global functions need to go away
- *	for opendarwin.
- */
-	int sym_len = SDL_strlen(symbol);
-	void *value = NULL;
-	char *malloc_sym = NULL;
-	malloc_sym = SDL_malloc(sym_len + 2);
-	if (malloc_sym)
-	{
-		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
-		value = dlsymIntern(handle, malloc_sym, 1);
-		SDL_free(malloc_sym);
-	}
-	else
-	{
-		error("Unable to allocate memory");
-	}
-	return value;
-}
-
-static void *dlsym_auto_underscore(void *handle, const char *symbol)
-{
-	void *answer;
-	dolock();
-	answer = dlsym_auto_underscore_intern(handle, symbol);
-	dounlock();
-	return answer;
-
-}
-static void *dlsym_auto_underscore_intern(void *handle, const char *symbol)
-{
-	struct dlstatus *dls = handle;
-	void *addr = 0;
-	addr = dlsymIntern(dls, symbol, 0);
-	if (!addr)
-		addr = dlsym_prepend_underscore_intern(handle, symbol);
-	return addr;
-}
-
-
-static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
-{
-	struct dlstatus *dls = handle;
-	void *addr = 0;
-	dolock();
-	addr = dlsymIntern(dls, symbol, 1);
-	dounlock();
-	return addr;
-}
-#endif
-
-static int SDL_OSX_dlclose(void *handle)
-{
-	struct dlstatus *dls = handle;
-	dolock();
-	resetdlerror();
-	if (!isValidStatus(dls))
-	{
-		goto dlcloseerror;
-	}
-	if (dls->module == MAGIC_DYLIB_MOD)
-	{
-		const char *name;
-		if (!dls->lib)
-		{
-			name = "global context";
-		}
-		else
-		{
-			name = get_lib_name(dls->lib);
-		}
-		warning("trying to close a .dylib!");
-		error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
-		goto dlcloseerror;
-	}
-	if (!dls->module)
-	{
-		error("module already closed");
-		goto dlcloseerror;
-	}
-	
-	if (dls->refs == 1)
-	{
-		unsigned long options = 0;
-		void (*fini) (void);
-		if ((fini = dlsymIntern(dls, "__fini", 0)))
-		{
-			debug("calling _fini()");
-			fini();
-		}
-		options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
-#ifdef RTLD_NODELETE
-		if (isFlagSet(dls->mode, RTLD_NODELETE))
-			options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
-#endif
-		if (!NSUnLinkModule(dls->module, options))
-		{
-			error("unable to unlink module");
-			goto dlcloseerror;
-		}
-		dls->refs--;
-		dls->module = 0;
-		/* Note: the dlstatus struct dls is neither removed from the list
-		 * nor is the memory it occupies freed. This shouldn't pose a 
-		 * problem in mostly all cases, though.
-		 */
-	}
-	dounlock();
-	return 0;
-  dlcloseerror:
-	dounlock();
-	return 1;
-}
-
-static const char *SDL_OSX_dlerror(void)
-{
-	struct dlthread  *tss;
-	const char * err_str = NULL;
-	dlcompat_init_check();
-	tss = pthread_getspecific(dlerror_key);
-	if (tss != NULL && tss->errset != 0) {
-		tss->errset = 0;	
-		err_str = tss->errstr;
-	}
-	return (err_str);
-}
-
-/* Given an address, return the mach_header for the image containing it
- * or zero if the given address is not contained in any loaded images.
- */
-static const struct mach_header *image_for_address(const void *address)
-{
-	unsigned long i;
-	unsigned long j;
-	unsigned long count = _dyld_image_count();
-	struct mach_header *mh = 0;
-	struct load_command *lc = 0;
-	unsigned long addr = NULL;
-	for (i = 0; i < count; i++)
-	{
-		addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i);
-		mh = _dyld_get_image_header(i);
-		if (mh)
-		{
-			lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
-			for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
-			{
-				if (LC_SEGMENT == lc->cmd &&
-					addr >= ((struct segment_command *)lc)->vmaddr &&
-					addr <
-					((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
-				{
-					goto image_found;
-				}
-			}
-		}
-		mh = 0;
-	}
-  image_found:
-	return mh;
-}
-
-static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restrict info)
-{
-/*
-	FIXME: USe the routine image_for_address.
-*/
-	unsigned long i;
-	unsigned long j;
-	unsigned long count = _dyld_image_count();
-	struct mach_header *mh = 0;
-	struct load_command *lc = 0;
-	unsigned long addr = NULL;
-	unsigned long table_off = (unsigned long)0;
-	int found = 0;
-	if (!info)
-		return 0;
-	dolock();
-	resetdlerror();
-	info->dli_fname = 0;
-	info->dli_fbase = 0;
-	info->dli_sname = 0;
-	info->dli_saddr = 0;
-/* Some of this was swiped from code posted by Douglas Davidson <ddavidso AT apple DOT com>
- * to darwin-development AT lists DOT apple DOT com and slightly modified
- */
-	for (i = 0; i < count; i++)
-	{
-		addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
-		mh = _dyld_get_image_header(i);
-		if (mh)
-		{
-			lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
-			for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
-			{
-				if (LC_SEGMENT == lc->cmd &&
-					addr >= ((struct segment_command *)lc)->vmaddr &&
-					addr <
-					((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
-				{
-					info->dli_fname = _dyld_get_image_name(i);
-					info->dli_fbase = (void *)mh;
-					found = 1;
-					break;
-				}
-			}
-			if (found)
-				break;
-		}
-	}
-	if (!found)
-	{
-		dounlock();
-		return 0;
-	}
-	lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
-	for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
-	{
-		if (LC_SEGMENT == lc->cmd)
-		{
-			if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
-				break;
-		}
-	}
-	table_off =
-		((unsigned long)((struct segment_command *)lc)->vmaddr) -
-		((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
-	debug("table off %x", table_off);
-
-	lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
-	for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
-	{
-		if (LC_SYMTAB == lc->cmd)
-		{
-
-			struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
-			unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
-			struct nlist *nearest = NULL;
-			unsigned long diff = 0xffffffff;
-			unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
-			debug("symtable %x", symtable);
-			for (i = 0; i < numsyms; i++)
-			{
-				/* Ignore the following kinds of Symbols */
-				if ((!symtable->n_value)	/* Undefined */
-					|| (symtable->n_type >= N_PEXT)	/* Debug symbol */
-					|| (!(symtable->n_type & N_EXT))	/* Local Symbol */
-					)
-				{
-					symtable++;
-					continue;
-				}
-				if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr)))
-				{
-					diff = (unsigned long)symtable->n_value - addr;
-					nearest = symtable;
-				}
-				symtable++;
-			}
-			if (nearest)
-			{
-				info->dli_saddr = nearest->n_value + ((void *)p - addr);
-				info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
-			}
-		}
-	}
-	dounlock();
-	return 1;
-}
-
-
-/*
- * Implement the dlfunc() interface, which behaves exactly the same as
- * dlsym() except that it returns a function pointer instead of a data
- * pointer.  This can be used by applications to avoid compiler warnings
- * about undefined behavior, and is intended as prior art for future
- * POSIX standardization.  This function requires that all pointer types
- * have the same representation, which is true on all platforms FreeBSD
- * runs on, but is not guaranteed by the C standard.
- */
-#if 0 
-static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restrict symbol)
-{
-	union
-	{
-		void *d;
-		dlfunc_t f;
-	} rv;
-	int sym_len = SDL_strlen(symbol);
-	char *malloc_sym = NULL;
-	dolock();
-	malloc_sym = SDL_malloc(sym_len + 2);
-	if (malloc_sym)
-	{
-		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
-		rv.d = dlsymIntern(handle, malloc_sym, 1);
-		SDL_free(malloc_sym);
-	}
-	else
-	{
-		error("Unable to allocate memory");
-		goto dlfuncerror;
-	}
-	dounlock();
-	return rv.f;
-  dlfuncerror:
-	dounlock();
-	return NULL;
-}
-#endif
-
-
-
-/* dlcompat ends, here's the SDL interface...  --ryan.  */
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/* System dependent library loading routines                           */
-
-#include "SDL_loadso.h"
-
-void *SDL_LoadObject(const char *sofile)
-{
-	void *handle = SDL_OSX_dlopen(sofile, RTLD_NOW);
-	const char *loaderror = SDL_OSX_dlerror();
-	if ( handle == NULL ) {
-		SDL_SetError("Failed loading %s: %s", sofile, loaderror);
-	}
-	return(handle);
-}
-
-void *SDL_LoadFunction(void *handle, const char *name)
-{
-	void *symbol = SDL_OSX_dlsym(handle, name);
-	if ( symbol == NULL ) {
-		SDL_SetError("Failed loading %s: %s", name, SDL_OSX_dlerror());
-	}
-	return(symbol);
-}
-
-void SDL_UnloadObject(void *handle)
-{
-	if ( handle != NULL ) {
-		SDL_OSX_dlclose(handle);
-	}
-}
-
-#endif /* SDL_LOADSO_DLCOMPAT */
--- a/src/main/dummy/SDL_dummy_main.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/main/dummy/SDL_dummy_main.c	Wed May 17 08:18:28 2006 +0000
@@ -9,5 +9,5 @@
 	return(SDL_main(argc, argv));
 }
 #else
-/* Nothing to do on this platform */;
+/* Nothing to do on this platform */
 #endif
--- a/src/main/macosx/SDLMain.m	Mon May 01 06:58:33 2006 +0000
+++ b/src/main/macosx/SDLMain.m	Wed May 17 08:18:28 2006 +0000
@@ -252,19 +252,24 @@
  */
 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
 {
+    const char *temparg;
+    size_t arglen;
+    char *arg;
+    char **newargv;
+
     if (!gFinderLaunch)  /* MacOS is passing command line args. */
         return FALSE;
 
     if (gCalledAppMainline)  /* app has started, ignore this document. */
         return FALSE;
 
-    const char *temparg = [filename UTF8String];
-    size_t arglen = SDL_strlen(temparg) + 1;
-    char *arg = (char *) SDL_malloc(arglen);
+    temparg = [filename UTF8String];
+    arglen = SDL_strlen(temparg) + 1;
+    arg = (char *) SDL_malloc(arglen);
     if (arg == NULL)
         return FALSE;
 
-    char **newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
+    newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
     if (newargv == NULL)
     {
         SDL_free(arg);
@@ -376,3 +381,4 @@
 #endif
     return 0;
 }
+
--- a/src/main/win32/SDL_win32_main.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/main/win32/SDL_win32_main.c	Wed May 17 08:18:28 2006 +0000
@@ -121,8 +121,15 @@
 	return FALSE;
 }
 
+/* SDL_Quit() shouldn't be used with atexit() directly because
+   calling conventions may differ... */
+static void cleanup(void)
+{
+	SDL_Quit();
+}
+
 /* Remove the output files if there was no output written */
-static void __cdecl cleanup_output(void)
+static void cleanup_output(void)
 {
 #ifndef NO_STDIO_REDIRECT
 	FILE *file;
@@ -188,7 +195,7 @@
 	if ( bufp == NULL ) {
 		return OutOfMemory();
 	}
-	SDL_strlcpy(bufp, appname, n);
+	SDL_strlcpy(bufp, appname, n+1);
 	appname = bufp;
 
 	/* Load SDL dynamic link library */
@@ -197,7 +204,7 @@
 		return(FALSE);
 	}
 	atexit(cleanup_output);
-	atexit(SDL_Quit);
+	atexit(cleanup);
 
 	/* Sam:
 	   We still need to pass in the application handle so that
--- a/src/stdlib/SDL_string.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/stdlib/SDL_string.c	Wed May 17 08:18:28 2006 +0000
@@ -985,10 +985,10 @@
 
     SDL_ltoa(value, num, radix);
     size = SDL_strlen(num);
-    if ( size > maxlen ) {
-        size = maxlen;
+    if ( size >= maxlen ) {
+        size = maxlen-1;
     }
-    SDL_strlcpy(text, num, size);
+    SDL_strlcpy(text, num, size+1);
 
     return size;
 }
@@ -999,10 +999,10 @@
 
     SDL_ultoa(value, num, radix);
     size = SDL_strlen(num);
-    if ( size > maxlen ) {
-        size = maxlen;
+    if ( size >= maxlen ) {
+        size = maxlen-1;
     }
-    SDL_strlcpy(text, num, size);
+    SDL_strlcpy(text, num, size+1);
 
     return size;
 }
@@ -1014,10 +1014,10 @@
 
     SDL_lltoa(value, num, radix);
     size = SDL_strlen(num);
-    if ( size > maxlen ) {
-        size = maxlen;
+    if ( size >= maxlen ) {
+        size = maxlen-1;
     }
-    SDL_strlcpy(text, num, size);
+    SDL_strlcpy(text, num, size+1);
 
     return size;
 }
@@ -1028,10 +1028,10 @@
 
     SDL_ulltoa(value, num, radix);
     size = SDL_strlen(num);
-    if ( size > maxlen ) {
-        size = maxlen;
+    if ( size >= maxlen ) {
+        size = maxlen-1;
     }
-    SDL_strlcpy(text, num, size);
+    SDL_strlcpy(text, num, size+1);
 
     return size;
 }
@@ -1101,6 +1101,9 @@
 
             ++fmt;
             /* FIXME: implement more of the format specifiers */
+            while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
+                ++fmt;
+            }
             while (!done) {
                 switch(*fmt) {
                     case '%':
--- a/src/thread/SDL_thread.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/thread/SDL_thread.c	Wed May 17 08:18:28 2006 +0000
@@ -168,7 +168,7 @@
 
 /* Arguments and callback to setup and run the user thread function */
 typedef struct {
-	int (*func)(void *);
+	int (SDLCALL *func)(void *);
 	void *data;
 	SDL_Thread *info;
 	SDL_sem *wait;
@@ -177,7 +177,7 @@
 void SDL_RunThread(void *data)
 {
 	thread_args *args;
-	int (*userfunc)(void *);
+	int (SDLCALL *userfunc)(void *);
 	void *userdata;
 	int *statusloc;
 
@@ -204,9 +204,9 @@
 
 #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
 #undef SDL_CreateThread
-DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
+DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
 #else
-DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data)
+DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data)
 #endif
 {
 	SDL_Thread *thread;
--- a/src/thread/pth/SDL_systhread.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/thread/pth/SDL_systhread.c	Wed May 17 08:18:28 2006 +0000
@@ -27,12 +27,13 @@
  *	Patrice Mandin
  */
 
-#include "SDL_thread.h"
-#include "../SDL_systhread.h"
-
 #include <pth.h>
 #include <signal.h>
 
+#include "SDL_thread.h"
+#include "../SDL_thread_c.h"
+#include "../SDL_systhread.h"
+
 /* List of signals to mask in the subthreads */
 static int sig_list[] = {
 	SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
--- a/src/thread/win32/SDL_systhread.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/thread/win32/SDL_systhread.c	Wed May 17 08:18:28 2006 +0000
@@ -41,6 +41,15 @@
         unsigned (__stdcall *func)(void *), void *arg, 
         unsigned, unsigned *threadID);
 typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
+#elif defined(__WATCOMC__)
+/* This is for Watcom targets except OS2 */
+#if __WATCOMC__ < 1240
+#define __watcall
+#endif
+typedef unsigned long (__watcall *pfnSDL_CurrentBeginThread) (void *, unsigned,
+        unsigned (__stdcall *func)(void *), void *arg, 
+        unsigned, unsigned *threadID);
+typedef void (__watcall *pfnSDL_CurrentEndThread)(unsigned code);
 #else
 typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
         unsigned (__stdcall *func)(void *), void *arg, 
--- a/src/timer/SDL_timer.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/timer/SDL_timer.c	Wed May 17 08:18:28 2006 +0000
@@ -95,6 +95,7 @@
 	}
 	if ( SDL_timer_threaded ) {
 		SDL_DestroyMutex(SDL_timer_mutex);
+		SDL_timer_mutex = NULL;
 	}
 	SDL_timer_started = 0;
 	SDL_timer_threaded = 0;
--- a/src/timer/macos/FastTimes.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/timer/macos/FastTimes.c	Wed May 17 08:18:28 2006 +0000
@@ -19,6 +19,11 @@
 
 #include "FastTimes.h"
 
+#ifdef TARGET_CPU_PPC
+#undef GENERATINGPOWERPC /* stop whining */
+#define GENERATINGPOWERPC TARGET_CPU_PPC
+#endif
+
 /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
 /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
 /*
--- a/src/timer/macos/SDL_systimer.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/timer/macos/SDL_systimer.c	Wed May 17 08:18:28 2006 +0000
@@ -36,6 +36,10 @@
 
 #include "FastTimes.h"
 
+#if TARGET_API_MAC_CARBON
+#define NewTimerProc NewTimerUPP
+#endif
+
 #define MS_PER_TICK	(1000.0/60.0)		/* MacOS tick = 1/60 second */
 
 
@@ -67,7 +71,11 @@
 
         stop = SDL_GetTicks() + ms;
         do {
+            #if TARGET_API_MAC_CARBON
+                MPYield();
+            #else
                 SystemTask();
+            #endif
 
                 now = SDL_GetTicks();
 
--- a/src/video/SDL_blit_A.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/SDL_blit_A.c	Wed May 17 08:18:28 2006 +0000
@@ -637,6 +637,9 @@
 #endif /* GCC_ASMBLIT, MSVC_ASMBLIT */
 
 #if SDL_ALTIVEC_BLITTERS
+#if __MWERKS__
+#pragma altivec_model on
+#endif
 #if HAVE_ALTIVEC_H
 #include <altivec.h>
 #endif
@@ -1406,6 +1409,9 @@
         dstp += dstskip;
     }
 }
+#if __MWERKS__
+#pragma altivec_model off
+#endif
 #endif /* SDL_ALTIVEC_BLITTERS */
 
 /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
--- a/src/video/SDL_blit_N.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/SDL_blit_N.c	Wed May 17 08:18:28 2006 +0000
@@ -29,6 +29,9 @@
 /* Functions to blit from N-bit surfaces to other surfaces */
 
 #if SDL_ALTIVEC_BLITTERS
+#if __MWERKS__
+#pragma altivec_model on
+#endif
 #ifdef HAVE_ALTIVEC_H
 #include <altivec.h>
 #endif
@@ -830,6 +833,9 @@
     }
     return features;
 }
+#if __MWERKS__
+#pragma altivec_model off
+#endif
 #else
 /* Feature 1 is has-MMX */
 #define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
--- a/src/video/ataricommon/SDL_ikbdinterrupt_s.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/ataricommon/SDL_ikbdinterrupt_s.h	Wed May 17 08:18:28 2006 +0000
@@ -44,14 +44,14 @@
 
 /* Variables */
 
-extern Uint8  SDL_AtariIkbd_keyboard[128];	/* Keyboard table */
-extern Uint16 SDL_AtariIkbd_mouseb;	/* Mouse on port 0, buttons */
-extern Sint16 SDL_AtariIkbd_mousex;	/* Mouse X relative motion */
-extern Sint16 SDL_AtariIkbd_mousey;	/* Mouse Y relative motion */
-extern Uint16 SDL_AtariIkbd_joystick;	/* Joystick on port 1 */
+extern volatile Uint8  SDL_AtariIkbd_keyboard[128];	/* Keyboard table */
+extern volatile Uint16 SDL_AtariIkbd_mouseb;	/* Mouse on port 0, buttons */
+extern volatile Sint16 SDL_AtariIkbd_mousex;	/* Mouse X relative motion */
+extern volatile Sint16 SDL_AtariIkbd_mousey;	/* Mouse Y relative motion */
+extern volatile Uint16 SDL_AtariIkbd_joystick;	/* Joystick on port 1 */
 
-extern Uint16 SDL_AtariIkbd_enabled;	/* For joystick driver to know
-											if this is usable */
+/* For joystick driver to know if this is usable */
+extern Uint16 SDL_AtariIkbd_enabled;
 										
 /* Functions */ 
 
--- a/src/video/ataricommon/SDL_xbiosinterrupt_s.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/ataricommon/SDL_xbiosinterrupt_s.h	Wed May 17 08:18:28 2006 +0000
@@ -36,10 +36,10 @@
 
 /* Variables */
 
-extern Uint16 SDL_AtariXbios_mouseb;	/* buttons */
-extern Sint16 SDL_AtariXbios_mousex;	/* X relative motion */
-extern Sint16 SDL_AtariXbios_mousey;	/* Y relative motion */
-extern Uint16 SDL_AtariXbios_joystick;	/* Joystick */
+extern volatile Uint16 SDL_AtariXbios_mouseb;	/* buttons */
+extern volatile Sint16 SDL_AtariXbios_mousex;	/* X relative motion */
+extern volatile Sint16 SDL_AtariXbios_mousey;	/* Y relative motion */
+extern volatile Uint16 SDL_AtariXbios_joystick;	/* Joystick */
 
 /* Functions */ 
 
--- a/src/video/dga/SDL_dgavideo.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/dga/SDL_dgavideo.c	Wed May 17 08:18:28 2006 +0000
@@ -41,6 +41,13 @@
 /* get function pointers... */
 #include "../x11/SDL_x11dyn.h"
 
+/*#define DGA_DEBUG*/
+
+/* Heheh we're using X11 event code */
+extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
+extern void X11_DisableScreenSaver(Display *display);
+extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
+
 /* Initialization/Query functions */
 static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
 static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
@@ -169,7 +176,7 @@
 static int DGA_AddMode(_THIS, int bpp, int w, int h)
 {
 	SDL_Rect *mode;
-	int i, index;
+	int index;
 	int next_mode;
 
 	/* Check to see if we already have this mode */
@@ -177,8 +184,8 @@
 		return(0);
 	}
 	index = ((bpp+7)/8)-1;
-	for ( i=0; i<SDL_nummodes[index]; ++i ) {
-		mode = SDL_modelist[index][i];
+	if ( SDL_nummodes[index] > 0 ) {
+		mode = SDL_modelist[index][SDL_nummodes[index]-1];
 		if ( (mode->w == w) && (mode->h == h) ) {
 			return(0);
 		}
@@ -281,14 +288,21 @@
     const SDL_NAME(XDGAMode) *a = (const SDL_NAME(XDGAMode) *)va;
     const SDL_NAME(XDGAMode) *b = (const SDL_NAME(XDGAMode) *)vb;
 
-    /* Prefer DirectColor visuals for otherwise equal modes */
     if ( (a->viewportWidth == b->viewportWidth) &&
          (b->viewportHeight == a->viewportHeight) ) {
-        if ( a->visualClass == DirectColor )
+        /* Prefer 32 bpp over 24 bpp, 16 bpp over 15 bpp */
+        int a_bpp = a->depth == 24 ? a->bitsPerPixel : a->depth;
+        int b_bpp = b->depth == 24 ? b->bitsPerPixel : b->depth;
+        if ( a_bpp != b_bpp ) {
+            return b_bpp - a_bpp;
+        }
+        /* Prefer DirectColor visuals, for gamma support */
+        if ( a->visualClass == DirectColor && b->visualClass != DirectColor )
             return -1;
-        if ( b->visualClass == DirectColor )
+        if ( b->visualClass == DirectColor && a->visualClass != DirectColor )
             return 1;
-        return 0;
+        /* Maintain server refresh rate sorting */
+        return a->num - b->num;
     } else if ( a->viewportWidth == b->viewportWidth ) {
         return b->viewportHeight - a->viewportHeight;
     } else {
@@ -387,16 +401,21 @@
 		return(-1);
 	}
 
+	/* Save DPMS and screensaver settings */
+	X11_SaveScreenSaver(DGA_Display, &screensaver_timeout, &dpms_enabled);
+	X11_DisableScreenSaver(DGA_Display);
+
 	/* Query for the list of available video modes */
 	modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
 	SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
 	for ( i=0; i<num_modes; ++i ) {
+		if ( ((modes[i].visualClass == PseudoColor) ||
+		      (modes[i].visualClass == DirectColor) ||
+		      (modes[i].visualClass == TrueColor)) && 
+		     !(modes[i].flags & (XDGAInterlaced|XDGADoublescan)) ) {
 #ifdef DGA_DEBUG
-		PrintMode(&modes[i]);
+			PrintMode(&modes[i]);
 #endif
-		if ( (modes[i].visualClass == PseudoColor) ||
-		     (modes[i].visualClass == DirectColor) ||
-		     (modes[i].visualClass == TrueColor) ) {
 			DGA_AddMode(this, modes[i].bitsPerPixel,
 			            modes[i].viewportWidth,
 			            modes[i].viewportHeight);
@@ -452,7 +471,6 @@
 	for ( i=0; i<num_modes; ++i ) {
 		int depth;
 
-		
 		depth = modes[i].depth;
 		if ( depth == 24 ) { /* Distinguish between 24 and 32 bpp */
 			depth = modes[i].bitsPerPixel;
@@ -462,7 +480,8 @@
 		     (modes[i].viewportHeight == height) &&
 		     ((modes[i].visualClass == PseudoColor) ||
 		      (modes[i].visualClass == DirectColor) ||
-		      (modes[i].visualClass == TrueColor)) ) {
+		      (modes[i].visualClass == TrueColor)) &&
+		     !(modes[i].flags & (XDGAInterlaced|XDGADoublescan)) ) {
 			break;
 		}
 	}
@@ -470,6 +489,9 @@
 		SDL_SetError("No matching video mode found");
 		return(NULL);
 	}
+#ifdef DGA_DEBUG
+	PrintMode(&modes[i]);
+#endif
 
 	/* Set the video mode */
 	mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num);
@@ -749,6 +771,13 @@
 {
 	vidmem_bucket *bucket, *freeable;
 
+	/* Wait for any pending operations involving this surface */
+	if ( DGA_IsSurfaceBusy(surface) ) {
+		LOCK_DISPLAY();
+		DGA_WaitBusySurfaces(this);
+		UNLOCK_DISPLAY();
+	}
+
 	/* Look for the bucket in the current list */
 	for ( bucket=&surfaces; bucket; bucket=bucket->next ) {
 		if ( bucket == (vidmem_bucket *)surface->hwdata ) {
@@ -1032,7 +1061,7 @@
 		SDL_NAME(XDGACloseFramebuffer)(DGA_Display, DGA_Screen);
 		if ( this->screen ) {
 			/* Tell SDL not to free the pixels */
-			this->screen->pixels = NULL;
+			DGA_FreeHWSurface(this, this->screen);
 		}
 		SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, 0);
 
@@ -1048,7 +1077,6 @@
 		}
 #endif /* LOCK_DGA_DISPLAY */
 
-
 		/* Clean up defined video modes */
 		for ( i=0; i<NUM_MODELISTS; ++i ) {
 			if ( SDL_modelist[i] != NULL ) {
@@ -1063,6 +1091,9 @@
 		/* Clean up the memory bucket list */
 		DGA_FreeHWSurfaces(this);
 
+		/* Restore DPMS and screensaver settings */
+		X11_RestoreScreenSaver(DGA_Display, screensaver_timeout, dpms_enabled);
+
 		/* Close up the display */
 		XCloseDisplay(DGA_Display);
 	}
--- a/src/video/dga/SDL_dgavideo.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/dga/SDL_dgavideo.h	Wed May 17 08:18:28 2006 +0000
@@ -25,11 +25,16 @@
 #define _SDL_dgavideo_h
 
 #include <X11/Xlib.h>
+#include <X11/Xproto.h>
 
 #include "SDL_mouse.h"
 #include "SDL_mutex.h"
 #include "../SDL_sysvideo.h"
 
+#if SDL_VIDEO_DRIVER_X11_DPMS
+#include <X11/extensions/dpms.h>
+#endif
+
 /* Hidden "this" pointer for the video functions */
 #define _THIS	SDL_VideoDevice *this
 
@@ -86,6 +91,10 @@
 #ifdef LOCK_DGA_DISPLAY
 	SDL_mutex *event_lock;
 #endif
+
+	/* Screensaver settings */
+	int screensaver_timeout;
+	BOOL dpms_enabled;
 };
 /* Old variable names */
 #define DGA_Display		(this->hidden->DGA_Display)
@@ -107,5 +116,7 @@
 #define hw_lock			(this->hidden->hw_lock)
 #define DGA_event_base		(this->hidden->event_base)
 #define event_lock		(this->hidden->event_lock)
+#define screensaver_timeout	(this->hidden->screensaver_timeout)
+#define dpms_enabled		(this->hidden->dpms_enabled)
 
 #endif /* _SDL_dgavideo_h */
--- a/src/video/directfb/SDL_DirectFB_events.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_events.c	Wed May 17 08:18:28 2006 +0000
@@ -155,7 +155,7 @@
   keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
   keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
   keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
-  keymap[DIKI_ALTGR - DIKI_UNKNOWN] = SDLK_RALT;
+  keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDLK_RALT;
   keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
   keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
   keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
--- a/src/video/directfb/SDL_DirectFB_video.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_video.c	Wed May 17 08:18:28 2006 +0000
@@ -191,6 +191,9 @@
 
   HIDDEN->nummodes++;
 
+  if (enumlist && enumlist->r.w == width && enumlist->r.h == height)
+    return DFENUM_OK;
+
   enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect));
   if (!enumrect)
     {
--- a/src/video/directfb/SDL_DirectFB_yuv.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_yuv.c	Wed May 17 08:18:28 2006 +0000
@@ -200,7 +200,7 @@
 {
   DFBResult         ret;
   void             *data;
-  unsigned int      pitch;
+  int               pitch;
   IDirectFBSurface *surface = overlay->hwdata->surface;
 
   ret = surface->Lock (surface, DSLF_READ | DSLF_WRITE, &data, &pitch);
--- a/src/video/fbcon/SDL_fb3dfx.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fb3dfx.c	Wed May 17 08:18:28 2006 +0000
@@ -57,6 +57,9 @@
 	int dstX, dstY;
 
 	/* Don't blit to the display surface when switched away */
+	if ( switched_away ) {
+		return -2; /* no hardware access */
+	}
 	if ( dst == this->screen ) {
 		SDL_mutexP(hw_lock);
 	}
@@ -102,6 +105,9 @@
 	Uint32 use_colorkey;
 
 	/* Don't blit to the display surface when switched away */
+	if ( switched_away ) {
+		return -2; /* no hardware access */
+	}
 	if ( dst == this->screen ) {
 		SDL_mutexP(hw_lock);
 	}
--- a/src/video/fbcon/SDL_fbevents.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbevents.c	Wed May 17 08:18:28 2006 +0000
@@ -55,6 +55,8 @@
 #define GPM_NODE_FIFO	"/dev/gpmdata"
 #endif
 
+/*#define DEBUG_KEYBOARD*/
+/*#define DEBUG_MOUSE*/
 
 /* The translation tables from a console scancode to a SDL keysym */
 #define NUM_VGAKEYMAPS	(1<<KG_CAPSSHIFT)
@@ -207,6 +209,8 @@
 			SDL_SetError("Unable to set keyboard in graphics mode");
 			return(-1);
 		}
+		/* Prevent switching the virtual terminal */
+		ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
 	}
 	return(keyboard_fd);
 }
@@ -220,6 +224,7 @@
 		saved_kbd_mode = -1;
 
 		/* Head back over to the original virtual terminal */
+		ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
 		if ( saved_vt > 0 ) {
 			ioctl(keyboard_fd, VT_ACTIVATE, saved_vt);
 		}
@@ -280,8 +285,15 @@
 		}
  		if ( keyboard_fd < 0 ) {
 			/* Last resort, maybe our tty is a usable VT */
-			current_vt = 0;
+			struct vt_stat vtstate;
+
 			keyboard_fd = open("/dev/tty", O_RDWR);
+
+			if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
+				current_vt = vtstate.v_active;
+			} else {
+				current_vt = 0;
+			}
  		}
 #ifdef DEBUG_KEYBOARD
 		fprintf(stderr, "Current VT: %d\n", current_vt);
@@ -360,7 +372,7 @@
 }
 
 /* Returns true if /dev/gpmdata is being written to by gpm */
-static int gpm_available(void)
+static int gpm_available(char *proto, size_t protolen)
 {
 	int available;
 	DIR *proc;
@@ -370,6 +382,9 @@
 	char args[PATH_MAX], *arg;
 
 	/* Don't bother looking if the fifo isn't there */
+#ifdef DEBUG_MOUSE 
+	fprintf(stderr,"testing gpm\n");
+#endif
 	if ( access(GPM_NODE_FIFO, F_OK) < 0 ) {
 		return(0);
 	}
@@ -377,17 +392,37 @@
 	available = 0;
 	proc = opendir("/proc");
 	if ( proc ) {
-		while ( (pid=find_pid(proc, "gpm")) > 0 ) {
+		char raw_proto[10] = { '\0' };
+		char repeat_proto[10] = { '\0' };
+		while ( !available && (pid=find_pid(proc, "gpm")) > 0 ) {
 			SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
 			cmdline = open(path, O_RDONLY, 0);
 			if ( cmdline >= 0 ) {
 				len = read(cmdline, args, sizeof(args));
 				arg = args;
 				while ( len > 0 ) {
-					if ( SDL_strcmp(arg, "-R") == 0 ) {
+					arglen = SDL_strlen(arg)+1;
+#ifdef DEBUG_MOUSE 
+				        fprintf(stderr,"gpm arg %s len %d\n",arg,arglen);
+#endif
+					if ( SDL_strcmp(arg, "-t") == 0) {
+						/* protocol string, keep it for later */
+						char *t, *s;
+						t = arg + arglen;
+						s = SDL_strchr(t, ' ');
+						if (s) *s = 0;
+						SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto));
+						if (s) *s = ' ';
+					}
+					if ( SDL_strncmp(arg, "-R", 2) == 0 ) {
+						char *t, *s;
 						available = 1;
+						t = arg + 2;
+						s = SDL_strchr(t, ' ');
+						if (s) *s = 0;
+						SDL_strlcpy(repeat_proto, t, SDL_arraysize(repeat_proto));
+						if (s) *s = ' ';
 					}
-					arglen = SDL_strlen(arg)+1;
 					len -= arglen;
 					arg += arglen;
 				}
@@ -395,6 +430,16 @@
 			}
 		}
 		closedir(proc);
+
+		if ( available ) {
+			if ( SDL_strcmp(repeat_proto, "raw") == 0 ) {
+				SDL_strlcpy(proto, raw_proto, protolen);
+			} else if ( *repeat_proto ) {
+				SDL_strlcpy(proto, repeat_proto, protolen);
+			} else {
+				SDL_strlcpy(proto, "msc", protolen);
+			}
+		}
 	}
 	return available;
 }
@@ -414,7 +459,7 @@
 			{0xFF}
 	*/
 	Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};
-	Uint8 reset = 0xff;
+	/*Uint8 reset = 0xff;*/
 	fd_set fdset;
 	struct timeval tv;
 	int retval = 0;
@@ -552,14 +597,35 @@
 		};
 		/* First try to use GPM in repeater mode */
 		if ( mouse_fd < 0 ) {
-			if ( gpm_available() ) {
+			char proto[10];
+			if ( gpm_available(proto, SDL_arraysize(proto)) ) {
 				mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);
 				if ( mouse_fd >= 0 ) {
+					if ( SDL_strcmp(proto, "msc") == 0 ) {
+						mouse_drv = MOUSE_MSC;
+					} else if ( SDL_strcmp(proto, "ps2") == 0 ) {
+						mouse_drv = MOUSE_PS2;
+					} else if ( SDL_strcmp(proto, "imps2") == 0 ) {
+						mouse_drv = MOUSE_IMPS2;
+					} else if ( SDL_strcmp(proto, "ms") == 0 ||
+					            SDL_strcmp(proto, "bare") == 0 ) {
+						mouse_drv = MOUSE_MS;
+					} else if ( SDL_strcmp(proto, "bm") == 0 ) {
+						mouse_drv = MOUSE_BM;
+					} else {
+						/* Unknown protocol... */
 #ifdef DEBUG_MOUSE
-fprintf(stderr, "Using GPM mouse\n");
+						fprintf(stderr, "GPM mouse using unknown protocol = %s\n", proto);
 #endif
-					mouse_drv = MOUSE_MSC;
+						close(mouse_fd);
+						mouse_fd = -1;
+					}
 				}
+#ifdef DEBUG_MOUSE
+				if ( mouse_fd >= 0 ) {
+					fprintf(stderr, "Using GPM mouse, protocol = %s\n", proto);
+				}
+#endif /* DEBUG_MOUSE */
 			}
 		}
 		/* Now try to use a modern PS/2 mouse */
@@ -853,65 +919,65 @@
 	return;
 }
 
-/* Handle switching to another VC, returns when our VC is back.
-   This isn't necessarily the best solution.  For SDL 1.3 we need
-   a way of notifying the application when we lose access to the
-   video hardware and when we regain it.
- */
+/* Handle switching to another VC, returns when our VC is back */
+static void switch_vt_prep(_THIS)
+{
+	SDL_Surface *screen = SDL_VideoSurface;
+
+	SDL_PrivateAppActive(0, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
+
+	/* Save the contents of the screen, and go to text mode */
+	wait_idle(this);
+	screen_arealen = ((screen->h + (2*this->offset_y)) * screen->pitch);
+	screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
+	if ( screen_contents ) {
+		SDL_memcpy(screen_contents, screen->pixels, screen_arealen);
+	}
+	FB_SavePaletteTo(this, 256, screen_palette);
+	ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo);
+	ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
+	ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
+}
+static void switch_vt_done(_THIS)
+{
+	SDL_Surface *screen = SDL_VideoSurface;
+
+	/* Restore graphics mode and the contents of the screen */
+	ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
+	ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
+	ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo);
+	FB_RestorePaletteFrom(this, 256, screen_palette);
+	if ( screen_contents ) {
+		SDL_memcpy(screen->pixels, screen_contents, screen_arealen);
+		SDL_free(screen_contents);
+		screen_contents = NULL;
+	}
+
+	/* Get updates to the shadow surface while switched away */
+	if ( SDL_ShadowSurface ) {
+		SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
+	}
+
+	SDL_PrivateAppActive(1, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
+}
 static void switch_vt(_THIS, unsigned short which)
 {
-	struct fb_var_screeninfo vinfo;
 	struct vt_stat vtstate;
-	unsigned short v_active;
-	__u16 saved_pal[3*256];
-	SDL_Surface *screen;
-	Uint32 screen_arealen;
-	Uint8 *screen_contents = NULL;
 
 	/* Figure out whether or not we're switching to a new console */
 	if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
 	     (which == vtstate.v_active) ) {
 		return;
 	}
-	v_active = vtstate.v_active;
-
-	/* Save the contents of the screen, and go to text mode */
-	SDL_mutexP(hw_lock);
-	wait_idle(this);
-	screen = SDL_VideoSurface;
-	if ( !SDL_ShadowSurface ) {
-		screen_arealen = (screen->h*screen->pitch);
-		screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
-		if ( screen_contents ) {
-			SDL_memcpy(screen_contents, (Uint8 *)screen->pixels + screen->offset, screen_arealen);
-		}
-	}
-	FB_SavePaletteTo(this, 256, saved_pal);
-	ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo);
-	ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
 
 	/* New console, switch to it */
+	SDL_mutexP(hw_lock);
+	switch_vt_prep(this);
 	if ( ioctl(keyboard_fd, VT_ACTIVATE, which) == 0 ) {
-		/* Wait for our console to be activated again */
 		ioctl(keyboard_fd, VT_WAITACTIVE, which);
-		while ( ioctl(keyboard_fd, VT_WAITACTIVE, v_active) < 0 ) {
-			if ( (errno != EINTR) && (errno != EAGAIN) ) {
-				/* Unknown VT error - cancel this */
-				break;
-			}
-			SDL_Delay(500);
-		}
-	}
-
-	/* Restore graphics mode and the contents of the screen */
-	ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
-	ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
-	FB_RestorePaletteFrom(this, 256, saved_pal);
-	if ( screen_contents ) {
-		SDL_memcpy((Uint8 *)screen->pixels + screen->offset, screen_contents, screen_arealen);
-		SDL_free(screen_contents);
+		switched_away = 1;
 	} else {
-		SDL_UpdateRect(screen, 0, 0, 0, 0);
+		switch_vt_done(this);
 	}
 	SDL_mutexV(hw_lock);
 }
@@ -969,6 +1035,18 @@
 	static struct timeval zero;
 
 	do {
+		if ( switched_away ) {
+			struct vt_stat vtstate;
+
+			SDL_mutexP(hw_lock);
+			if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) &&
+			     vtstate.v_active == current_vt ) {
+				switched_away = 0;
+				switch_vt_done(this);
+			}
+			SDL_mutexV(hw_lock);
+		}
+
 		posted = 0;
 
 		FD_ZERO(&fdset);
@@ -1037,6 +1115,12 @@
 	  case SCANCODE_LEFTWIN:
 	    keymap[i] = SDLK_LSUPER;
 	    break;
+	  case SCANCODE_LEFTALT:
+	    keymap[i] = SDLK_LALT;
+	    break;
+	  case SCANCODE_RIGHTALT:
+	    keymap[i] = SDLK_RALT;
+	    break;
 	  case 127:
 	    keymap[i] = SDLK_MENU;
 	    break;
@@ -1138,10 +1222,10 @@
 		if ( modstate & KMOD_CTRL ) {
 			map |= (1<<KG_CTRL);
 		}
-		if ( modstate & KMOD_ALT ) {
+		if ( modstate & KMOD_LALT ) {
 			map |= (1<<KG_ALT);
 		}
-		if ( modstate & KMOD_MODE ) {
+		if ( modstate & KMOD_RALT ) {
 			map |= (1<<KG_ALTGR);
 		}
 		if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) {
--- a/src/video/fbcon/SDL_fbmatrox.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbmatrox.c	Wed May 17 08:18:28 2006 +0000
@@ -70,6 +70,9 @@
 	Uint32 fillop;
 
 	/* Don't blit to the display surface when switched away */
+	if ( switched_away ) {
+		return -2; /* no hardware access */
+	}
 	if ( dst == this->screen ) {
 		SDL_mutexP(hw_lock);
 	}
@@ -132,6 +135,9 @@
 	}
 
 	/* Don't blit to the display surface when switched away */
+	if ( switched_away ) {
+		return -2; /* no hardware access */
+	}
 	if ( dst == this->screen ) {
 		SDL_mutexP(hw_lock);
 	}
--- a/src/video/fbcon/SDL_fbriva.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbriva.c	Wed May 17 08:18:28 2006 +0000
@@ -77,6 +77,9 @@
 	RivaBitmap *Bitmap = (RivaBitmap *)(mapped_io + BITMAP_OFFSET);
 
 	/* Don't blit to the display surface when switched away */
+	if ( switched_away ) {
+		return -2; /* no hardware access */
+	}
 	if ( dst == this->screen ) {
 		SDL_mutexP(hw_lock);
 	}
@@ -120,6 +123,9 @@
 	}
 
 	/* Don't blit to the display surface when switched away */
+	if ( switched_away ) {
+		return -2; /* no hardware access */
+	}
 	if ( dst == this->screen ) {
 		SDL_mutexP(hw_lock);
 	}
--- a/src/video/fbcon/SDL_fbvideo.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbvideo.c	Wed May 17 08:18:28 2006 +0000
@@ -149,11 +149,25 @@
                                   struct fb_var_screeninfo *vinfo);
 static void FB_RestorePalette(_THIS);
 
+/* Small wrapper for mmap() so we can play nicely with no-mmu hosts
+ * (non-mmu hosts disallow the MAP_SHARED flag) */
+
+static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
+{
+	void *ret;
+	ret = mmap(start, length, prot, flags, fd, offset);
+	if ( ret == (char *)-1 && (flags & MAP_SHARED) ) {
+		ret = mmap(start, length, prot,
+		           (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
+	}
+	return ret;
+}
+
 /* FB driver bootstrap functions */
 
 static int FB_Available(void)
 {
-	int console;
+	int console = -1;
 	/* Added check for /fb/0 (devfs) */
 	/* but - use environment variable first... if it fails, still check defaults */
 	int idx = 0;
@@ -535,7 +549,7 @@
 	mapped_offset = (((long)finfo.smem_start) -
 	                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
 	mapped_memlen = finfo.smem_len+mapped_offset;
-	mapped_mem = mmap(NULL, mapped_memlen,
+	mapped_mem = do_mmap(NULL, mapped_memlen,
 	                  PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
 	if ( mapped_mem == (char *)-1 ) {
 		SDL_SetError("Unable to memory map the video hardware");
@@ -579,7 +593,7 @@
 	ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
 	if ( finfo.accel && finfo.mmio_len ) {
 		mapped_iolen = finfo.mmio_len;
-		mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
+		mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
 		                 MAP_SHARED, console_fd, mapped_memlen);
 		if ( mapped_io == (char *)-1 ) {
 			/* Hmm, failed to memory map I/O registers */
@@ -1238,26 +1252,10 @@
 	surface->hwdata = NULL;
 }
 
-/* Routine to check to see if the frame buffer virtual terminal */
-/* is the current(active) one.  If it is not, result will cause */
-/* Lock to fail.  (would have waited forever, since the fbevent */
-/* keyboard handler maintains a lock when switched away from    */
-/* current) */
-static __inline__ int FB_IsFrameBufferActive(_THIS)
-{
-	struct vt_stat vtstate;
-	if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
-	     (current_vt != vtstate.v_active) ) {
-		return 0;
-	}
-	return 1;
-}
-
-
 static int FB_LockHWSurface(_THIS, SDL_Surface *surface)
 {
-	if ( !FB_IsFrameBufferActive(this) ) {
-		return -1; /* fail locking. */
+	if ( switched_away ) {
+		return -2; /* no hardware access */
 	}
 	if ( surface == this->screen ) {
 		SDL_mutexP(hw_lock);
@@ -1293,6 +1291,10 @@
 
 static int FB_FlipHWSurface(_THIS, SDL_Surface *surface)
 {
+	if ( switched_away ) {
+		return -2; /* no hardware access */
+	}
+
 	/* Wait for vertical retrace and then flip display */
 	cache_vinfo.yoffset = flip_page*surface->h;
 	if ( FB_IsSurfaceBusy(this->screen) ) {
@@ -1333,6 +1335,10 @@
     Uint32 *src, *srcPtr;
     Uint8  *dst, *dstPtr;
 
+    if ( switched_away ) {
+        return; /* no hardware access */
+    }
+
     screen = this->screen;
     FBPitch = screen->w >> 3;
     SRCPitch = screen->pitch >> 2;
--- a/src/video/fbcon/SDL_fbvideo.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbvideo.h	Wed May 17 08:18:28 2006 +0000
@@ -85,6 +85,11 @@
 	int surfaces_memleft;
 
 	SDL_mutex *hw_lock;
+	int switched_away;
+	struct fb_var_screeninfo screen_vinfo;
+	Uint32 screen_arealen;
+	Uint8 *screen_contents;
+	__u16  screen_palette[3*256];
 
 	void (*wait_vbl)(_THIS);
 	void (*wait_idle)(_THIS);
@@ -117,6 +122,11 @@
 #define surfaces_memtotal	(this->hidden->surfaces_memtotal)
 #define surfaces_memleft	(this->hidden->surfaces_memleft)
 #define hw_lock			(this->hidden->hw_lock)
+#define switched_away		(this->hidden->switched_away)
+#define screen_vinfo		(this->hidden->screen_vinfo)
+#define screen_arealen		(this->hidden->screen_arealen)
+#define screen_contents		(this->hidden->screen_contents)
+#define screen_palette		(this->hidden->screen_palette)
 #define wait_vbl		(this->hidden->wait_vbl)
 #define wait_idle		(this->hidden->wait_idle)
 
--- a/src/video/maccommon/SDL_macgl.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/maccommon/SDL_macgl.c	Wed May 17 08:18:28 2006 +0000
@@ -168,7 +168,11 @@
 int Mac_GL_LoadLibrary(_THIS, const char *location)
 {
 	if (location == NULL)
+#if __MACH__
+		location = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
+#else
 		location = "OpenGLLibrary";
+#endif
 
 	this->hidden->libraryHandle = SDL_LoadObject(location);
 
--- a/src/video/maccommon/SDL_macgl_c.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/maccommon/SDL_macgl_c.h	Wed May 17 08:18:28 2006 +0000
@@ -26,7 +26,7 @@
 
 #if SDL_VIDEO_OPENGL
 #include "SDL_opengl.h"
-#ifdef MACOSX
+#if __MACOSX__
 #include <AGL/agl.h>   /* AGL.framework */
 #else
 #include <agl.h>
--- a/src/video/macdsp/SDL_dspvideo.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/macdsp/SDL_dspvideo.c	Wed May 17 08:18:28 2006 +0000
@@ -682,7 +682,7 @@
   if (dialog == NULL)
 	 return (0);
   
-#if TARGET_API_CARBON
+#if TARGET_API_MAC_CARBON
   SetPort (GetDialogPort(dialog));
 #else
   SetPort ((WindowPtr) dialog);
--- a/src/video/macrom/SDL_romvideo.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/macrom/SDL_romvideo.c	Wed May 17 08:18:28 2006 +0000
@@ -35,6 +35,7 @@
 #include <Movies.h>
 #endif
 #else
+#include <Quickdraw.h>
 #include <LowMem.h>
 #include <Gestalt.h>
 #include <Devices.h>
@@ -637,12 +638,12 @@
 	SetPortWindowPort(SDL_Window);
 	thePort = GetWindowPort(SDL_Window);
 	memworld = (GWorldPtr)GetWRefCon(SDL_Window);
-#if TARGET_API_MAC_CARBON
+#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
 	memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld);
 #else
 	memBits = &((GrafPtr)memworld)->portBits;
 #endif
-#if TARGET_API_MAC_CARBON
+#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
 	winBits = GetPortBitMapForCopyBits(thePort);
 #else
 	winBits = &SDL_Window->portBits;
--- a/src/video/ps2gs/SDL_gsyuv.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/ps2gs/SDL_gsyuv.c	Wed May 17 08:18:28 2006 +0000
@@ -325,7 +325,7 @@
 	int lum_pitch;
 	int crb_pitch;
 	Uint32 *lum_src, *Cr_src, *Cb_src;
-	Uint32 *src, *dst;
+	Uint32 *srcp, *dstp;
 	unsigned int x, y;
 	SDL_Surface *screen;
 
@@ -345,7 +345,7 @@
 		SDL_SetError("Unsupported YUV format in blit (?)");
 		return(-1);
 	}
-	dst = (Uint32 *)hwdata->ipu_imem;
+	dstp = (Uint32 *)hwdata->ipu_imem;
 	lum_pitch = overlay->w/4;
 	crb_pitch = (overlay->w/2)/4;
 
@@ -355,28 +355,28 @@
 		Cr_src = Cr;
 		Cb_src = Cb;
 		for ( w=overlay->w/16; w; --w ) {
-			src = lum_src;
+			srcp = lum_src;
 			for ( i=0; i<16; ++i ) {
-				dst[0] = src[0];
-				dst[1] = src[1];
-				dst[2] = src[2];
-				dst[3] = src[3];
-				src += lum_pitch;
-				dst += 4;
+				dstp[0] = srcp[0];
+				dstp[1] = srcp[1];
+				dstp[2] = srcp[2];
+				dstp[3] = srcp[3];
+				srcp += lum_pitch;
+				dstp += 4;
 			}
-			src = Cb_src;
+			srcp = Cb_src;
 			for ( i=0; i<8; ++i ) {
-				dst[0] = src[0];
-				dst[1] = src[1];
-				src += crb_pitch;
-				dst += 2;
+				dstp[0] = srcp[0];
+				dstp[1] = srcp[1];
+				srcp += crb_pitch;
+				dstp += 2;
 			}
-			src = Cr_src;
+			srcp = Cr_src;
 			for ( i=0; i<8; ++i ) {
-				dst[0] = src[0];
-				dst[1] = src[1];
-				src += crb_pitch;
-				dst += 2;
+				dstp[0] = srcp[0];
+				dstp[1] = srcp[1];
+				srcp += crb_pitch;
+				dstp += 2;
 			}
 			lum_src += 16 / 4;
 			Cb_src += 8 / 4;
--- a/src/video/quartz/SDL_QuartzVideo.m	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/quartz/SDL_QuartzVideo.m	Wed May 17 08:18:28 2006 +0000
@@ -117,14 +117,14 @@
     SDL_VideoDevice *device;
     SDL_PrivateVideoData *hidden;
 
-    device = (SDL_VideoDevice*) malloc (sizeof (*device) );
-    hidden = (SDL_PrivateVideoData*) malloc (sizeof (*hidden) );
+    device = (SDL_VideoDevice*) SDL_malloc (sizeof (*device) );
+    hidden = (SDL_PrivateVideoData*) SDL_malloc (sizeof (*hidden) );
 
     if (device == NULL || hidden == NULL)
         SDL_OutOfMemory ();
 
-    memset (device, 0, sizeof (*device) );
-    memset (hidden, 0, sizeof (*hidden) );
+    SDL_memset (device, 0, sizeof (*device) );
+    SDL_memset (hidden, 0, sizeof (*hidden) );
 
     device->hidden = hidden;
 
@@ -178,8 +178,8 @@
 
 static void QZ_DeleteDevice (SDL_VideoDevice *device) {
 
-    free (device->hidden);
-    free (device);
+    SDL_free (device->hidden);
+    SDL_free (device);
 }
 
 static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
@@ -242,9 +242,9 @@
         int i;
 
         for (i = 0; client_mode_list[i] != NULL; i++)
-            free (client_mode_list[i]);
+            SDL_free (client_mode_list[i]);
 
-        free (client_mode_list);
+        SDL_free (client_mode_list);
         client_mode_list = NULL;
     }
 
@@ -297,12 +297,12 @@
 
                 if (client_mode_list == NULL)
                     client_mode_list = (SDL_Rect**) 
-                        malloc (sizeof(*client_mode_list) * (list_size+1) );
+                        SDL_malloc (sizeof(*client_mode_list) * (list_size+1) );
                 else
                     client_mode_list = (SDL_Rect**) 
-                        realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
+                        SDL_realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
 
-                rect = (SDL_Rect*) malloc (sizeof(**client_mode_list));
+                rect = (SDL_Rect*) SDL_malloc (sizeof(**client_mode_list));
 
                 if (client_mode_list == NULL || rect == NULL) {
                     SDL_OutOfMemory ();
@@ -372,7 +372,7 @@
             SDL_WaitThread (thread, NULL);
             SDL_DestroySemaphore (sem1);
             SDL_DestroySemaphore (sem2);
-            free (sw_buffers[0]);
+            SDL_free (sw_buffers[0]);
         }
         
         /* 
@@ -493,7 +493,7 @@
         this->UnlockHWSurface = QZ_UnlockDoubleBuffer;
         this->FlipHWSurface = QZ_FlipDoubleBuffer;
 
-        current->pixels = malloc (current->pitch * current->h * 2);
+        current->pixels = SDL_malloc (current->pitch * current->h * 2);
         if (current->pixels == NULL) {
             SDL_OutOfMemory ();
             goto ERR_DOUBLEBUF;
@@ -984,7 +984,7 @@
         
         while ( h-- ) {
         
-            memcpy (dst, src, len);
+            SDL_memcpy (dst, src, len);
             src += skip;
             dst += skip;
         }
@@ -1211,7 +1211,7 @@
                             dockIconCacheMiss) {
 
                             numCachedDockIcons = i - firstDockIcon;
-                            memcpy (dockIcons, &(windows[firstDockIcon]),
+                            SDL_memcpy (dockIcons, &(windows[firstDockIcon]),
                                     numCachedDockIcons * sizeof(*windows));
                         }
 
--- a/src/video/quartz/SDL_QuartzWM.m	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/quartz/SDL_QuartzWM.m	Wed May 17 08:18:28 2006 +0000
@@ -41,12 +41,12 @@
     int row, bytes;
         
     /* Allocate the cursor memory */
-    cursor = (WMcursor *)malloc(sizeof(WMcursor));
+    cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
     if ( cursor == NULL ) {
         SDL_OutOfMemory();
         return(NULL);
     }
-    memset(cursor, 0, sizeof(*cursor));
+    SDL_memset(cursor, 0, sizeof(*cursor));
     
     if (w > 16)
         w = 16;
@@ -57,11 +57,11 @@
     bytes = (w+7)/8;
 
     for ( row=0; row<h; ++row ) {
-        memcpy(&cursor->curs.data[row], data, bytes);
+        SDL_memcpy(&cursor->curs.data[row], data, bytes);
         data += bytes;
     }
     for ( row=0; row<h; ++row ) {
-        memcpy(&cursor->curs.mask[row], mask, bytes);
+        SDL_memcpy(&cursor->curs.mask[row], mask, bytes);
         mask += bytes;
     }
     cursor->curs.hotSpot.h = hot_x;
@@ -262,68 +262,67 @@
     NSBitmapImageRep *imgrep;
     NSImage *img;
     SDL_Surface *mergedSurface;
-    int i,j;
     NSAutoreleasePool *pool;
-    SDL_Rect rrect;
-    NSSize imgSize = {icon->w, icon->h};
+    Uint8 *pixels;
+    SDL_bool iconSrcAlpha;
+    Uint8 iconAlphaValue;
+    int i, j, maskPitch, index;
     
     pool = [ [ NSAutoreleasePool alloc ] init ];
-    SDL_GetClipRect(icon, &rrect);
+    
+    imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4*icon->w bitsPerPixel: 32 ] autorelease ];
+    if (imgrep == nil) goto freePool;
+    pixels = [ imgrep bitmapData ];
+    SDL_memset(pixels, 0, 4*icon->w*icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
     
-    /* create a big endian RGBA surface */
-    mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 
-                    icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
-    if (mergedSurface==NULL) {
-        NSLog(@"Error creating surface for merge");
-        goto freePool;
-    }
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+#define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
+#else
+#define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
+#endif
+    mergedSurface = SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4*icon->w, BYTEORDER_DEPENDENT_RGBA_MASKS);
+    if (mergedSurface == NULL) goto freePool;
     
-    if (mergedSurface->pitch != 
-        mergedSurface->format->BytesPerPixel * mergedSurface->w) {
-        SDL_SetError ("merged surface has wrong format");
-        SDL_FreeSurface (mergedSurface);
-        goto freePool;
-    }
+    /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
+    iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
+    iconAlphaValue = icon->format->alpha;
+    SDL_SetAlpha(icon, 0, 255);
+    SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
+    if (iconSrcAlpha) SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
     
-    if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
-        NSLog(@"Error blitting to mergedSurface");
-        goto freePool;
-    }
+    SDL_FreeSurface(mergedSurface);
     
-    if (mask) {
-
-        Uint32 *pixels = mergedSurface->pixels;
-        for (i = 0; i < mergedSurface->h; i++) {
-            for (j = 0; j < mergedSurface->w; j++) {
-                
-                int index = i * mergedSurface->w + j;
-                int mindex = index >> 3;
-                int bindex = 7 - (index & 0x7);
-                
-                if (mask[mindex] & (1 << bindex))
-                    pixels[index] |= 0x000000FF;
-                else
-                    pixels[index] &= 0xFFFFFF00;
+    /* apply mask, source alpha, and premultiply color values by alpha */
+    maskPitch = (icon->w+7)/8;
+    for (i = 0; i < icon->h; i++) {
+        for (j = 0; j < icon->w; j++) {
+            index = i*4*icon->w + j*4;
+            if (!(mask[i*maskPitch + j/8] & (128 >> j%8))) {
+                pixels[index + 3] = 0;
+            }
+            else {
+                if (iconSrcAlpha) {
+                    if (icon->format->Amask == 0) pixels[index + 3] = icon->format->alpha;
+                }
+                else {
+                    pixels[index + 3] = 255;
+                }
+            }
+            if (pixels[index + 3] < 255) {
+                pixels[index + 0] = (Uint16)pixels[index + 0]*pixels[index + 3]/255;
+                pixels[index + 1] = (Uint16)pixels[index + 1]*pixels[index + 3]/255;
+                pixels[index + 2] = (Uint16)pixels[index + 2]*pixels[index + 3]/255;
             }
         }
     }
     
-    imgrep = [ [ NSBitmapImageRep alloc] 
-                    initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
-                        pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
-                        hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
-                        bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
-    
-    img = [ [ NSImage alloc ] initWithSize:imgSize ];
-    
+    img = [ [ [ NSImage alloc ] initWithSize: NSMakeSize(icon->w, icon->h) ] autorelease ];
+    if (img == nil) goto freePool;
     [ img addRepresentation: imgrep ];
     [ NSApp setApplicationIconImage:img ];
     
-    [ img release ];
-    [ imgrep release ];
-    SDL_FreeSurface(mergedSurface);
 freePool:
-    [pool release];
+    [ pool release ];
 }
 
 int  QZ_IconifyWindow (_THIS) { 
--- a/src/video/quartz/SDL_QuartzYUV.m	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/quartz/SDL_QuartzYUV.m	Wed May 17 08:18:28 2006 +0000
@@ -91,16 +91,16 @@
     CDSequenceEnd (yuv_seq);
     ExitMovies();
 
-    free (overlay->hwfuncs);
-    free (overlay->pitches);
-    free (overlay->pixels);
+    SDL_free (overlay->hwfuncs);
+    SDL_free (overlay->pitches);
+    SDL_free (overlay->pixels);
 
     if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
         [ qz_window close ];
         qz_window = nil;
     }
 
-    free (yuv_matrix);
+    SDL_free (yuv_matrix);
     DisposeHandle ((Handle)yuv_idh);
 }
 
@@ -134,7 +134,7 @@
         return NULL;
     }
 
-    yuv_matrix = (MatrixRecordPtr) malloc (sizeof(MatrixRecord));
+    yuv_matrix = (MatrixRecordPtr) SDL_malloc (sizeof(MatrixRecord));
     if (yuv_matrix == NULL) {
         SDL_OutOfMemory();
         return NULL;
@@ -234,7 +234,7 @@
         return NULL;
     }
     
-    overlay = (SDL_Overlay*) malloc (sizeof(*overlay));
+    overlay = (SDL_Overlay*) SDL_malloc (sizeof(*overlay));
     if (overlay == NULL) {
         SDL_OutOfMemory();
         return NULL;
@@ -267,15 +267,15 @@
             return NULL;
         }
 
-        pixels = (Uint8**) malloc (sizeof(*pixels) * 3);
-        pitches = (Uint16*) malloc (sizeof(*pitches) * 3);
+        pixels = (Uint8**) SDL_malloc (sizeof(*pixels) * 3);
+        pitches = (Uint16*) SDL_malloc (sizeof(*pitches) * 3);
         if (pixels == NULL || pitches == NULL) {
             SDL_OutOfMemory();
             return NULL;
         }
 
         yuv_pixmap = (PlanarPixmapInfoYUV420*)
-            malloc (sizeof(PlanarPixmapInfoYUV420) +
+            SDL_malloc (sizeof(PlanarPixmapInfoYUV420) +
                     (width * height * 2));
         if (yuv_pixmap == NULL) {
             SDL_OutOfMemory ();
@@ -310,7 +310,7 @@
         overlay->pitches = pitches;
     }
 
-    overlay->hwfuncs = malloc (sizeof(*overlay->hwfuncs));
+    overlay->hwfuncs = SDL_malloc (sizeof(*overlay->hwfuncs));
     if (overlay->hwfuncs == NULL) {
         SDL_OutOfMemory();
         return NULL;
--- a/src/video/wincommon/SDL_wingl.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/wincommon/SDL_wingl.c	Wed May 17 08:18:28 2006 +0000
@@ -177,6 +177,7 @@
 	int iAttribs[64];
 	int *iAttr;
 	float fAttribs[1] = { 0 };
+	const GLubyte *(WINAPI *glGetStringFunc)(GLenum);
 	const char *wglext;
 
 	/* load the gl driver from a default path */
@@ -338,8 +339,14 @@
 	 * somewhat a documented and reliable hack - it was originally
 	 * as a feature added by mistake, but since so many people rely
 	 * on it, it will not be removed.  strstr should be safe here.*/
-	wglext = (const char *)this->glGetString(GL_EXTENSIONS);
-	if ( !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
+	glGetStringFunc = WIN_GL_GetProcAddress(this, "glGetString");
+	if ( glGetStringFunc ) {
+		wglext = (const char *)glGetStringFunc(GL_EXTENSIONS);
+	} else {
+		/* Uh oh, something is seriously wrong here... */
+		wglext = NULL;
+	}
+	if ( !wglext || !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
 		this->gl_data->wglSwapIntervalEXT = NULL;
 		this->gl_data->wglGetSwapIntervalEXT = NULL;
 	}
--- a/src/video/windib/SDL_dibvideo.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/windib/SDL_dibvideo.c	Wed May 17 08:18:28 2006 +0000
@@ -348,7 +348,6 @@
 #endif
 	}
 	/* Sort the mode lists */
-	if( i > 1 )
 	for ( i=0; i<NUM_MODELISTS; ++i ) {
 		if ( SDL_nummodes[i] > 0 ) {
 			SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
@@ -361,7 +360,7 @@
 	// because SDL surface conversion is much faster than the WinCE one.
 	// Although it should be tested on devices with graphics accelerator.
 
-    DIB_AddMode(this, vformat->BitsPerPixel,
+	DIB_AddMode(this, vformat->BitsPerPixel,
 			GetDeviceCaps(GetDC(NULL), HORZRES), 
 			GetDeviceCaps(GetDC(NULL), VERTRES));
 
--- a/src/video/windx5/SDL_dx5video.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/windx5/SDL_dx5video.c	Wed May 17 08:18:28 2006 +0000
@@ -636,6 +636,16 @@
 	DX5_Available, DX5_CreateDevice
 };
 
+static int cmpmodes(const void *va, const void *vb)
+{
+    SDL_Rect *a = *(SDL_Rect **)va;
+    SDL_Rect *b = *(SDL_Rect **)vb;
+    if ( a->w == b->w )
+        return b->h - a->h;
+    else
+        return b->w - a->w;
+}
+
 static HRESULT WINAPI EnumModes2(DDSURFACEDESC *desc, VOID *udata)
 {
 	SDL_VideoDevice *this = (SDL_VideoDevice *)udata;
@@ -955,6 +965,10 @@
 			SDL_modelist[i][j] = &rect->r;
 		}
 		SDL_modelist[i][j] = NULL;
+
+		if ( SDL_nummodes[i] > 0 ) {
+			SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
+		}
 	}
 	
 	/* Fill in some window manager capabilities */
--- a/src/video/x11/SDL_x11dyn.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11dyn.c	Wed May 17 08:18:28 2006 +0000
@@ -61,30 +61,27 @@
     { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR },
 };
 
-static void *X11_GetSym(const char *fnname, int *rc)
+static void X11_GetSym(const char *fnname, int *rc, void **fn)
 {
 	int i;
-	void *fn = NULL;
 	for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
 		if (x11libs[i].lib != NULL)
 		{
-			fn = SDL_LoadFunction(x11libs[i].lib, fnname);
-			if (fn != NULL)
+			*fn = SDL_LoadFunction(x11libs[i].lib, fnname);
+			if (*fn != NULL)
 				break;
 		}
 	}
 
 	#if DEBUG_DYNAMIC_X11
-	if (fn != NULL)
-		printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn);
+	if (*fn != NULL)
+		printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, *fn);
 	else
 		printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
 	#endif
 
-	if (fn == NULL)
+	if (*fn == NULL)
 		*rc = 0;  /* kill this module. */
-
-	return fn;
 }
 
 
@@ -159,13 +156,13 @@
 			}
 		}
 		#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
-		#define SDL_X11_SYM(a,fn,x,y,z) p##fn = X11_GetSym(#fn,thismod);
+		#define SDL_X11_SYM(a,fn,x,y,z) X11_GetSym(#fn,thismod,(void**)&p##fn);
 		#include "SDL_x11sym.h"
 		#undef SDL_X11_MODULE
 		#undef SDL_X11_SYM
 
 		#ifdef X_HAVE_UTF8_STRING
-		pXCreateIC = X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8);
+		X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8,(void **)&pXCreateIC);
 		#endif
 
 		if (!SDL_X11_HAVE_BASEXLIB) {  /* some required symbol didn't load. */
--- a/src/video/x11/SDL_x11events.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11events.c	Wed May 17 08:18:28 2006 +0000
@@ -291,11 +291,10 @@
 		     (xevent.xcrossing.mode != NotifyUngrab) ) {
 			if ( this->input_grab == SDL_GRAB_OFF ) {
 				posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
-			} else {
-				posted = SDL_PrivateMouseMotion(0, 0,
-						xevent.xcrossing.x,
-						xevent.xcrossing.y);
 			}
+			posted = SDL_PrivateMouseMotion(0, 0,
+					xevent.xcrossing.x,
+					xevent.xcrossing.y);
 		}
 	    }
 	    break;
@@ -1118,3 +1117,57 @@
 	X11_InitKeymap();
 }
 
+void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms)
+{
+	int timeout, interval, prefer_blank, allow_exp;
+	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
+	*saved_timeout = timeout;
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+	if ( SDL_X11_HAVE_DPMS ) {
+		int dummy;
+	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
+			CARD16 state;
+			DPMSInfo(display, &state, dpms);
+		}
+	}
+#else
+	*dpms = 0;
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
+
+void X11_DisableScreenSaver(Display *display)
+{
+	int timeout, interval, prefer_blank, allow_exp;
+	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
+	timeout = 0;
+	XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+	if ( SDL_X11_HAVE_DPMS ) {
+		int dummy;
+	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
+			DPMSDisable(display);
+		}
+	}
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
+
+void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms)
+{
+	int timeout, interval, prefer_blank, allow_exp;
+	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
+	timeout = saved_timeout;
+	XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+	if ( SDL_X11_HAVE_DPMS ) {
+		int dummy;
+	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
+			if ( dpms ) {
+				DPMSEnable(display);
+			}
+		}
+	}
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
--- a/src/video/x11/SDL_x11events_c.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11events_c.h	Wed May 17 08:18:28 2006 +0000
@@ -28,3 +28,6 @@
 extern void X11_PumpEvents(_THIS);
 extern void X11_SetKeyboardState(Display *display, const char *key_vec);
 
+extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
+extern void X11_DisableScreenSaver(Display *display);
+extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
--- a/src/video/x11/SDL_x11gl.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11gl.c	Wed May 17 08:18:28 2006 +0000
@@ -46,6 +46,7 @@
 #ifndef GLX_EXT_visual_rating
 #define GLX_EXT_visual_rating
 #define GLX_VISUAL_CAVEAT_EXT              0x20
+#define GLX_NONE_EXT                       0x8000
 #define GLX_SLOW_VISUAL_EXT                0x8001
 #define GLX_NON_CONFORMANT_VISUAL_EXT      0x800D
 #endif
@@ -182,7 +183,7 @@
 	if( this->gl_config.accelerated >= 0 &&
 	    glXExtensionSupported(this, "GLX_EXT_visual_rating") ) {
 		attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
-		attribs[i++] = this->gl_config.accelerated ? GLX_NONE : GLX_DONT_CARE;
+		attribs[i++] = GLX_NONE_EXT;
 	}
 
 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
--- a/src/video/x11/SDL_x11modes.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11modes.c	Wed May 17 08:18:28 2006 +0000
@@ -33,12 +33,22 @@
 #include "SDL_x11modes_c.h"
 #include "SDL_x11image_c.h"
 
-#if SDL_VIDEO_DRIVER_X11_XINERAMA
-#include "../Xext/extensions/Xinerama.h"
-#endif 
+/*#define X11MODES_DEBUG*/
 
 #define MAX(a, b)        (a > b ? a : b)
 
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+static int cmpmodelist(const void *va, const void *vb)
+{
+    const SDL_Rect *a = *(const SDL_Rect **)va;
+    const SDL_Rect *b = *(const SDL_Rect **)vb;
+    if ( a->w == b->w )
+        return b->h - a->h;
+    else
+        return b->w - a->w;
+}
+#endif
+
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
 Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info)
 {
@@ -86,18 +96,6 @@
 }
 #endif
 
-#if SDL_VIDEO_DRIVER_X11_XRANDR
-static int cmpmodelist(const void *va, const void *vb)
-{
-    const SDL_Rect *a = *(const SDL_Rect **)va;
-    const SDL_Rect *b = *(const SDL_Rect **)vb;
-    if ( a->w == b->w )
-        return b->h - a->h;
-    else
-        return b->w - a->w;
-}
-#endif
-
 static void get_real_resolution(_THIS, int* w, int* h);
 
 static void set_best_resolution(_THIS, int width, int height)
@@ -107,45 +105,37 @@
         SDL_NAME(XF86VidModeModeLine) mode;
         SDL_NAME(XF86VidModeModeInfo) **modes;
         int i;
-        int best_width = 0, best_height = 0;
         int nmodes;
+        int best = -1;
 
         if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
-             SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
-#ifdef XFREE86_DEBUG
-            printf("Available modes (unsorted):\n");
-            for ( i = 0; i < nmodes; ++i ) {
-                printf("Mode %d: %d x %d @ %d\n", i,
-                        modes[i]->hdisplay, modes[i]->vdisplay,
-                        1000 * modes[i]->dotclock / (modes[i]->htotal *
-                        modes[i]->vtotal) );
-            }
-#endif
+             SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes) ) {
             for ( i = 0; i < nmodes ; i++ ) {
                 if ( (modes[i]->hdisplay == width) &&
-                     (modes[i]->vdisplay == height) )
-                    goto match;
-            }
-            qsort(modes, nmodes, sizeof *modes, cmpmodes);
-            for ( i = nmodes-1; i > 0 ; i-- ) {
-		if ( ! best_width ) {
-                    if ( (modes[i]->hdisplay >= width) &&
-                         (modes[i]->vdisplay >= height) ) {
-                        best_width = modes[i]->hdisplay;
-                        best_height = modes[i]->vdisplay;
-                    }
-                } else {
-                    if ( (modes[i]->hdisplay != best_width) ||
-                         (modes[i]->vdisplay != best_height) ) {
-                        i++;
-                        break;
+                     (modes[i]->vdisplay == height) ) {
+                    best = i;
+                    break;
+                }
+                if ( modes[i]->hdisplay >= width &&
+                     modes[i]->vdisplay >= height ) {
+                    if ( best < 0 ||
+                         (modes[i]->hdisplay < modes[best]->hdisplay &&
+                          modes[i]->vdisplay <= modes[best]->vdisplay) ||
+                         (modes[i]->vdisplay < modes[best]->vdisplay &&
+                          modes[i]->hdisplay <= modes[best]->hdisplay) ) {
+                        best = i;
                     }
                 }
             }
-       match:
-            if ( (modes[i]->hdisplay != mode.hdisplay) ||
-                 (modes[i]->vdisplay != mode.vdisplay) ) {
-                SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
+            if ( best >= 0 &&
+                 ((modes[best]->hdisplay != mode.hdisplay) ||
+                  (modes[best]->vdisplay != mode.vdisplay)) ) {
+#ifdef X11MODES_DEBUG
+                printf("Best Mode %d: %d x %d @ %d\n", best,
+                        modes[best]->hdisplay, modes[best]->vdisplay,
+                        (modes[best]->htotal && modes[best]->vtotal) ? (1000 * modes[best]->dotclock / (modes[best]->htotal * modes[best]->vtotal)) : 0 );
+#endif
+                SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[best]);
             }
             XFree(modes);
         }
@@ -154,13 +144,13 @@
 
                                 /* XiG */
 #if SDL_VIDEO_DRIVER_X11_XME
-#ifdef XIG_DEBUG
-    fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n",
-            width, height);
-#endif
-    if ( SDL_modelist ) {
+    if ( use_xme && SDL_modelist ) {
         int i;
 
+#ifdef X11MODES_DEBUG
+        fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n",
+                width, height);
+#endif
         for ( i=0; SDL_modelist[i]; ++i ) {
             if ( (SDL_modelist[i]->w >= width) &&
                  (SDL_modelist[i]->h >= height) ) {
@@ -175,11 +165,11 @@
             get_real_resolution(this, &w, &h);
 
             if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
-# ifdef XIG_DEBUG
+#ifdef X11MODES_DEBUG
                 fprintf(stderr, "XME: set_best_resolution: "
                         "XiGMiscChangeResolution: %d %d\n",
-                        SDL_modelist[s]->w, SDL_modelist[s]->h);
-# endif
+                        SDL_modelist[i]->w, SDL_modelist[i]->h);
+#endif
                 XiGMiscChangeResolution(SDL_Display, 
                                         SDL_Screen,
                                         0, /* view */
@@ -193,58 +183,73 @@
 #endif /* SDL_VIDEO_DRIVER_X11_XME */
 
 #if SDL_VIDEO_DRIVER_X11_XRANDR
-    if ( use_xrandr ) {
-#ifdef XRANDR_DEBUG
+    if ( use_xrandr && SDL_modelist ) {
+#ifdef X11MODES_DEBUG
         fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n",
                 width, height);
 #endif
-        if ( SDL_modelist ) {
-            int i, nsizes;
-            XRRScreenSize *sizes;
+        int i, nsizes;
+        XRRScreenSize *sizes;
 
-            /* find the smallest resolution that is at least as big as the user requested */
-            sizes = XRRConfigSizes(screen_config, &nsizes);
-            for ( i = (nsizes-1); i >= 0; i-- ) {
-                if ( (SDL_modelist[i]->w >= width) &&
-                     (SDL_modelist[i]->h >= height) ) {
-                    break;
-                }
+        /* find the smallest resolution that is at least as big as the user requested */
+        sizes = XRRConfigSizes(screen_config, &nsizes);
+        for ( i = (nsizes-1); i >= 0; i-- ) {
+            if ( (SDL_modelist[i]->w >= width) &&
+                 (SDL_modelist[i]->h >= height) ) {
+                break;
             }
+        }
 
-            if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */
-                int w, h;
+        if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */
+            int w, h;
 
-                /* check current mode so we can avoid uneccessary mode changes */
-                get_real_resolution(this, &w, &h);
+            /* check current mode so we can avoid uneccessary mode changes */
+            get_real_resolution(this, &w, &h);
 
-                if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
-                    int size_id;
+            if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
+                int size_id;
 
-#ifdef XRANDR_DEBUG
-                    fprintf(stderr, "XRANDR: set_best_resolution: "
-                            "XXRSetScreenConfig: %d %d\n",
-                            SDL_modelist[i]->w, SDL_modelist[i]->h);
+#ifdef X11MODES_DEBUG
+                fprintf(stderr, "XRANDR: set_best_resolution: "
+                        "XXRSetScreenConfig: %d %d\n",
+                        SDL_modelist[i]->w, SDL_modelist[i]->h);
 #endif
 
-                    /* find the matching size entry index */
-                    for ( size_id = 0; size_id < nsizes; ++size_id ) {
-                        if ( (sizes[size_id].width == SDL_modelist[i]->w) &&
-                             (sizes[size_id].height == SDL_modelist[i]->h) )
-                            break;
-                    }
+                /* find the matching size entry index */
+                for ( size_id = 0; size_id < nsizes; ++size_id ) {
+                    if ( (sizes[size_id].width == SDL_modelist[i]->w) &&
+                         (sizes[size_id].height == SDL_modelist[i]->h) )
+                        break;
+                }
 
-                    XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
-                                       size_id, saved_rotation, CurrentTime);
-                }
+                XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
+                                   size_id, saved_rotation, CurrentTime);
             }
         }
     }
 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
-
 }
 
 static void get_real_resolution(_THIS, int* w, int* h)
 {
+#if SDL_VIDEO_DRIVER_X11_XME
+    if ( use_xme ) {
+        int ractive;
+        XiGMiscResolutionInfo *modelist;
+
+        XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
+                                0, /* view */
+                                &ractive, &modelist);
+        *w = modelist[ractive].width;
+        *h = modelist[ractive].height;
+#ifdef X11MODES_DEBUG
+        fprintf(stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h);
+#endif
+        XFree(modelist);
+        return;
+    }
+#endif /* SDL_VIDEO_DRIVER_X11_XME */
+
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
     if ( use_vidmode ) {
         SDL_NAME(XF86VidModeModeLine) mode;
@@ -258,24 +263,6 @@
     }
 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
 
-#if SDL_VIDEO_DRIVER_X11_XME
-    if ( use_xme ) {
-        int ractive;
-        XiGMiscResolutionInfo *modelist;
-
-        XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
-                                0, /* view */
-                                &ractive, &modelist);
-        *w = modelist[ractive].width;
-        *h = modelist[ractive].height;
-#ifdef XIG_DEBUG
-        fprintf(stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h);
-#endif
-        XFree(modelist);
-        return;
-    }
-#endif /* SDL_VIDEO_DRIVER_X11_XME */
-
 #if SDL_VIDEO_DRIVER_X11_XRANDR
     if ( use_xrandr ) {
         int nsizes;
@@ -291,7 +278,7 @@
                 *w = sizes[cur_size].width;
                 *h = sizes[cur_size].height;
             }
-#ifdef XRANDR_DEBUG
+#ifdef X11MODES_DEBUG
             fprintf(stderr, "XRANDR: get_real_resolution: w = %d h = %d\n", *w, *h);
 #endif
             return;
@@ -299,6 +286,14 @@
     }
 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
 
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+    if ( use_xinerama ) {
+        *w = xinerama_info.width;
+        *h = xinerama_info.height;
+        return;
+    }
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
     *w = DisplayWidth(SDL_Display, SDL_Screen);
     *h = DisplayHeight(SDL_Display, SDL_Screen);
 }
@@ -360,10 +355,136 @@
 /* Global for the error handler */
 int vm_event, vm_error = -1;
 
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+static int CheckXinerama(_THIS, int *major, int *minor)
+{
+    const char *env;
+
+    /* Default the extension not available */
+    *major = *minor = 0;
+
+    /* Allow environment override */
+    env = getenv("SDL_VIDEO_X11_XINERAMA");
+    if ( env && !SDL_atoi(env) ) {
+        return 0;
+    }
+
+    /* Query the extension version */
+    if ( !SDL_NAME(XineramaQueryExtension)(SDL_Display, major, minor) ||
+         !SDL_NAME(XineramaIsActive)(SDL_Display) ) {
+        return 0;
+    }
+    return 1;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+static int CheckXRandR(_THIS, int *major, int *minor)
+{
+    const char *env;
+
+    /* Default the extension not available */
+    *major = *minor = 0;
+
+    /* Allow environment override */
+    env = getenv("SDL_VIDEO_X11_XRANDR");
+    if ( env && !SDL_atoi(env) ) {
+        return 0;
+    }
+
+    /* This defaults off now, due to KDE window maximize problems */
+    if ( !env ) {
+        return 0;
+    }
+
+    if ( !SDL_X11_HAVE_XRANDR ) {
+        return 0;
+    }
+
+    /* Query the extension version */
+    if ( !XRRQueryVersion(SDL_Display, major, minor) ) {
+        return 0;
+    }
+    return 1;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
+
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+static int CheckVidMode(_THIS, int *major, int *minor)
+{
+    const char *env;
+
+    /* Default the extension not available */
+    *major = *minor = 0;
+
+    /* Allow environment override */
+    env = getenv("SDL_VIDEO_X11_VIDMODE");
+    if ( env && !SDL_atoi(env) ) {
+        return 0;
+    }
+    
+    /* Metro-X 4.3.0 and earlier has a broken implementation of
+       XF86VidModeGetAllModeLines() - it hangs the client.
+     */
+    if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
+        FILE *metro_fp;
+
+        metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
+        if ( metro_fp != NULL ) {
+            int major, minor, patch, version;
+            major = 0; minor = 0; patch = 0;
+            fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
+            fclose(metro_fp);
+            version = major*100+minor*10+patch;
+            if ( version < 431 ) {
+                return 0;
+            }
+        }
+    }
+
+    /* Query the extension version */
+    vm_error = -1;
+    if ( !SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) ||
+         !SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, major, minor) ) {
+        return 0;
+    }
+    return 1;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
+
+#if SDL_VIDEO_DRIVER_X11_XME
+static int CheckXME(_THIS, int *major, int *minor)
+{
+    const char *env;
+
+    /* Default the extension not available */
+    *major = *minor = 0;
+
+    /* Allow environment override */
+    env = getenv("SDL_VIDEO_X11_VIDMODE");
+    if ( env && !SDL_atoi(env) ) {
+        return 0;
+    }
+    
+    /* Query the extension version */
+    if ( !XiGMiscQueryVersion(SDL_Display, major, minor) ) {
+        return 0;
+    }
+    return 1;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XME */
+
 int X11_GetVideoModes(_THIS)
 {
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+    int xinerama_major, xinerama_minor;
+#endif
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+    int xrandr_major, xrandr_minor;
+    int nsizes;
+    XRRScreenSize *sizes;
+#endif
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
-    int buggy_X11;
     int vm_major, vm_minor;
     int nmodes;
     SDL_NAME(XF86VidModeModeInfo) **modes;
@@ -373,30 +494,90 @@
     int ractive, nummodes;
     XiGMiscResolutionInfo *modelist;
 #endif
-#if SDL_VIDEO_DRIVER_X11_XRANDR
-    int xrandr_major, xrandr_minor;
-    int nsizes;
-    XRRScreenSize *sizes;
-#endif
     int i, n;
     int screen_w;
     int screen_h;
 
-    vm_error = -1;
+    use_xinerama = 0;
+    use_xrandr = 0;
     use_vidmode = 0;
-    use_xrandr = 0;
+    use_xme = 0;
     screen_w = DisplayWidth(SDL_Display, SDL_Screen);
     screen_h = DisplayHeight(SDL_Display, SDL_Screen);
 
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+    /* Query Xinerama extention */
+    if ( CheckXinerama(this, &xinerama_major, &xinerama_minor) ) {
+        /* Find out which screen is the desired one */
+        int desired = 0;
+        int screens;
+        int w, h;
+        SDL_NAME(XineramaScreenInfo) *xinerama;
+
+        const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
+        if ( variable ) {
+                desired = SDL_atoi(variable);
+        }
+#ifdef X11MODES_DEBUG
+        printf("X11 detected Xinerama:\n");
+#endif
+        xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
+        for ( i = 0; i < screens; i++ ) {
+#ifdef X11MODES_DEBUG
+            printf("xinerama %d: %dx%d+%d+%d\n",
+                xinerama[i].screen_number,
+                xinerama[i].width, xinerama[i].height,
+                xinerama[i].x_org, xinerama[i].y_org);
+#endif
+            if ( xinerama[i].screen_number == desired ) {
+                use_xinerama = 1;
+                xinerama_info = xinerama[i];
+            }
+        }
+        XFree(xinerama);
+
+        if ( use_xinerama ) {
+            SDL_modelist = (SDL_Rect **)SDL_malloc(3*sizeof(SDL_Rect *));
+            if ( !SDL_modelist ) {
+                SDL_OutOfMemory();
+                return -1;
+            }
+
+            /* Add the full xinerama mode */
+            n = 0;
+            w = xinerama_info.width;
+            h = xinerama_info.height;
+            if ( screen_w > w || screen_h > h) {
+                SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+                if ( SDL_modelist[n] ) {
+                    SDL_modelist[n]->x = 0;
+                    SDL_modelist[n]->y = 0;
+                    SDL_modelist[n]->w = screen_w;
+                    SDL_modelist[n]->h = screen_h;
+                    ++n;
+                }
+            }
+
+            /* Add the head xinerama mode */
+            SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+            if ( SDL_modelist[n] ) {
+                SDL_modelist[n]->x = 0;
+                SDL_modelist[n]->y = 0;
+                SDL_modelist[n]->w = w;
+                SDL_modelist[n]->h = h;
+                ++n;
+            }
+            SDL_modelist[n] = NULL;
+        }
+    }
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
+#if SDL_VIDEO_DRIVER_X11_XRANDR
     /* XRandR */
-#if SDL_VIDEO_DRIVER_X11_XRANDR
     /* require at least XRandR v1.0 (arbitrary) */
-    if ( ( SDL_X11_HAVE_XRANDR ) &&
-         ( getenv("SDL_VIDEO_X11_NO_XRANDR") == NULL ) &&
-         ( XRRQueryVersion(SDL_Display, &xrandr_major, &xrandr_minor) ) &&
-         ( xrandr_major >= 1 ) ) {
-
-#ifdef XRANDR_DEBUG
+    if ( CheckXRandR(this, &xrandr_major, &xrandr_minor) && (xrandr_major >= 1) )
+    {
+#ifdef X11MODES_DEBUG
         fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
                 xrandr_major, xrandr_minor);
 #endif
@@ -409,27 +590,36 @@
         /* retrieve the list of resolution */
         sizes = XRRConfigSizes(screen_config, &nsizes);
         if (nsizes > 0) {
+            if ( SDL_modelist ) {
+                for ( i = 0; SDL_modelist[i]; ++i ) {
+                    SDL_free(SDL_modelist[i]);
+                }
+                SDL_free(SDL_modelist);
+            }
             SDL_modelist = (SDL_Rect **)malloc((nsizes+1)*sizeof(SDL_Rect *));
-            if (SDL_modelist) {
-                for ( i=0; i < nsizes; i++ ) {
-                    if ((SDL_modelist[i] =
-                         (SDL_Rect *)malloc(sizeof(SDL_Rect))) == NULL)
-                        break;
-#ifdef XRANDR_DEBUG
-                    fprintf(stderr, "XRANDR: mode = %4d, w = %4d, h = %4d\n",
-                            i, sizes[i].width, sizes[i].height);
+            if ( !SDL_modelist ) {
+                SDL_OutOfMemory();
+                return -1;
+            }
+            for ( i=0; i < nsizes; i++ ) {
+                if ((SDL_modelist[i] =
+                     (SDL_Rect *)malloc(sizeof(SDL_Rect))) == NULL)
+                    break;
+#ifdef X11MODES_DEBUG
+                fprintf(stderr, "XRANDR: mode = %4d, w = %4d, h = %4d\n",
+                        i, sizes[i].width, sizes[i].height);
 #endif
 
-                    SDL_modelist[i]->x = 0;
-                    SDL_modelist[i]->y = 0;
-                    SDL_modelist[i]->w = sizes[i].width;
-                    SDL_modelist[i]->h = sizes[i].height;
+                SDL_modelist[i]->x = 0;
+                SDL_modelist[i]->y = 0;
+                SDL_modelist[i]->w = sizes[i].width;
+                SDL_modelist[i]->h = sizes[i].height;
 
-                }
-                /* sort the mode list descending as SDL expects */
-                qsort(SDL_modelist, nsizes, sizeof *SDL_modelist, cmpmodelist);
-                SDL_modelist[i] = NULL; /* terminator */
             }
+            /* sort the mode list descending as SDL expects */
+            SDL_qsort(SDL_modelist, nsizes, sizeof *SDL_modelist, cmpmodelist);
+            SDL_modelist[i] = NULL; /* terminator */
+
             use_xrandr = xrandr_major * 100 + xrandr_minor;
             saved_size_id = XRRConfigCurrentConfiguration(screen_config, &saved_rotation);
         }
@@ -437,110 +627,73 @@
 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
 
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
-    /* Metro-X 4.3.0 and earlier has a broken implementation of
-       XF86VidModeGetAllModeLines() - it hangs the client.
-     */
-    buggy_X11 = 0;
-    if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
-        FILE *metro_fp;
-
-        metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
-        if ( metro_fp != NULL ) {
-            int major, minor, patch, version;
-            major = 0; minor = 0; patch = 0;
-            fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
-            version = major*100+minor*10+patch;
-            if ( version < 431 ) {
-                buggy_X11 = 1;
-            }
-            fclose(metro_fp);
-        }
-    }
-#if 0 /* Let's try this again... hopefully X servers have improved... */
-#if defined(__alpha__) || defined(__sparc64__) || defined(__powerpc__)
-    /* The alpha, sparc64 and PPC XFree86 servers are also buggy */
-    buggy_X11 = 1;
-#endif
-#endif
-    /* Enumerate the available fullscreen modes */
-    if ( ! buggy_X11 ) {
-        if ( SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) &&
-              SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, &vm_major, &vm_minor) ) {
-#ifdef BROKEN_XFREE86_4001
-#ifdef X_XF86VidModeGetDotClocks  /* Compiled under XFree86 4.0 */
-                /* Earlier X servers hang when doing vidmode */
-                if ( vm_major < 2 ) {
-#ifdef XFREE86_DEBUG
-                    printf("Compiled under XFree86 4.0, server is XFree86 3.X\n");
-#endif
-                    buggy_X11 = 1;
-                }
-#else
-                /* XFree86 3.X code works with XFree86 4.0 servers */;
-#endif /* XFree86 4.0 */
-#endif /* XFree86 4.02 and newer are fixed wrt backwards compatibility */
-        } else {
-            buggy_X11 = 1;
-        }
-    }
-    if ( ! buggy_X11 && ! use_xrandr &&
-         SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
-
-#ifdef XFREE86_DEBUG
-        printf("Available modes: (sorted)\n");
+    /* XVidMode */
+    if ( !use_xrandr &&
+         (!use_xinerama || xinerama_info.screen_number == 0) &&
+         CheckVidMode(this, &vm_major, &vm_minor) &&
+         SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) )
+    {
+#ifdef X11MODES_DEBUG
+        printf("VidMode modes: (unsorted)\n");
         for ( i = 0; i < nmodes; ++i ) {
             printf("Mode %d: %d x %d @ %d\n", i,
                     modes[i]->hdisplay, modes[i]->vdisplay,
-                    1000 * modes[i]->dotclock / (modes[i]->htotal *
-                    modes[i]->vtotal) );
+                    (modes[i]->htotal && modes[i]->vtotal) ? (1000 * modes[i]->dotclock / (modes[i]->htotal * modes[i]->vtotal)) : 0 );
         }
 #endif
-
-        SDL_qsort(modes, nmodes, sizeof *modes, cmpmodes);
+        if ( SDL_modelist ) {
+            for ( i = 0; SDL_modelist[i]; ++i ) {
+                SDL_free(SDL_modelist[i]);
+            }
+            SDL_free(SDL_modelist);
+        }
         SDL_modelist = (SDL_Rect **)SDL_malloc((nmodes+2)*sizeof(SDL_Rect *));
-        if ( SDL_modelist ) {
-            n = 0;
-            for ( i=0; i<nmodes; ++i ) {
-                int w, h;
+        if ( !SDL_modelist ) {
+            SDL_OutOfMemory();
+            return -1;
+        }
+        SDL_qsort(modes, nmodes, sizeof *modes, cmpmodes);
+        n = 0;
+        for ( i=0; i<nmodes; ++i ) {
+            int w, h;
 
-		/* Eliminate duplicate modes with different refresh rates */
-		if ( i > 0 &&
-		     modes[i]->hdisplay == modes[i-1]->hdisplay &&
-		     modes[i]->vdisplay == modes[i-1]->vdisplay ) {
-			continue;
-		}
+            /* Eliminate duplicate modes with different refresh rates */
+            if ( i > 0 &&
+                 modes[i]->hdisplay == modes[i-1]->hdisplay &&
+                 modes[i]->vdisplay == modes[i-1]->vdisplay ) {
+                    continue;
+            }
 
-                /* Check to see if we should add the screen size (Xinerama) */
-                w = modes[i]->hdisplay;
-                h = modes[i]->vdisplay;
-                if ( (screen_w * screen_h) >= (w * h) ) {
-                    if ( (screen_w != w) || (screen_h != h) ) {
-                        SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
-                        if ( SDL_modelist[n] ) {
-                            SDL_modelist[n]->x = 0;
-                            SDL_modelist[n]->y = 0;
-                            SDL_modelist[n]->w = screen_w;
-                            SDL_modelist[n]->h = screen_h;
-                            ++n;
-                        }
+            /* Check to see if we should add the screen size (Xinerama) */
+            w = modes[i]->hdisplay;
+            h = modes[i]->vdisplay;
+            if ( (screen_w * screen_h) >= (w * h) ) {
+                if ( (screen_w != w) || (screen_h != h) ) {
+                    SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+                    if ( SDL_modelist[n] ) {
+                        SDL_modelist[n]->x = 0;
+                        SDL_modelist[n]->y = 0;
+                        SDL_modelist[n]->w = screen_w;
+                        SDL_modelist[n]->h = screen_h;
+                        ++n;
                     }
-                    screen_w = 0;
-                    screen_h = 0;
                 }
+                screen_w = 0;
+                screen_h = 0;
+            }
 
-                /* Add the size from the video mode list */
-                SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
-                if ( SDL_modelist[n] == NULL ) {
-                    break;
-                }
-                SDL_modelist[n]->x = 0;
-                SDL_modelist[n]->y = 0;
-                SDL_modelist[n]->w = w;
-                SDL_modelist[n]->h = h;
-                ++n;
+            /* Add the size from the video mode list */
+            SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+            if ( SDL_modelist[n] == NULL ) {
+                break;
             }
-            SDL_modelist[n] = NULL;
+            SDL_modelist[n]->x = 0;
+            SDL_modelist[n]->y = 0;
+            SDL_modelist[n]->w = w;
+            SDL_modelist[n]->h = h;
+            ++n;
         }
+        SDL_modelist[n] = NULL;
         XFree(modes);
 
         use_vidmode = vm_major * 100 + vm_minor;
@@ -548,71 +701,53 @@
     }
 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
 
-                                /* XiG */
 #if SDL_VIDEO_DRIVER_X11_XME
+    /* XiG */
+    modelist = NULL;
     /* first lets make sure we have the extension, and it's at least v2.0 */
-    if (XiGMiscQueryVersion(SDL_Display, &xme_major, &xme_minor)) {
-#ifdef XIG_DEBUG
-        fprintf(stderr, "XME: XiGMiscQueryVersion: V%d.%d\n",
-                xme_major, xme_minor);
-#endif
-        /* work around a XiGMisc bogosity in our version of libXext */
-        if (xme_major == 0 && xme_major == 0) {
-            /* Ideally libxme would spit this out, but the problem is that
-               the right Query func will never be called if using the bogus
-               libXext version.
-             */
-            fprintf(stderr, 
-"XME: If you are using Xi Graphics CDE and a Summit server, you need to\n"
-"XME: get the libXext update from Xi's ftp site before fullscreen switching\n"
-"XME: will work.  Fullscreen switching is only supported on Summit Servers\n");
-          }
-    } else {
-        /* not there. Bummer. */
-        xme_major = xme_minor = 0;
-    }
-
-    modelist = NULL;
-    if (xme_major >= 2 && (nummodes = XiGMiscQueryResolutions(SDL_Display, 
-                                            SDL_Screen,
-                                            0, /* view */
-                                            &ractive, 
-                                            &modelist)) > 1)
+    if ( CheckXME(this, &xme_major, &xme_minor) && xme_major >= 2 &&
+         (nummodes = XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
+                                             0, /* view */
+                                             &ractive, &modelist)) > 1 )
     {                                /* then we actually have some */
         int j;
 
-#ifdef XIG_DEBUG
+        /* We get the list already sorted in descending order.
+           We'll copy it in reverse order so SDL is happy */
+#ifdef X11MODES_DEBUG
         fprintf(stderr, "XME: nummodes = %d, active mode = %d\n",
                 nummodes, ractive);
 #endif
-
+        if ( SDL_modelist ) {
+            for ( i = 0; SDL_modelist[i]; ++i ) {
+                SDL_free(SDL_modelist[i]);
+            }
+            SDL_free(SDL_modelist);
+        }
         SDL_modelist = (SDL_Rect **)SDL_malloc((nummodes+1)*sizeof(SDL_Rect *));
+        if ( !SDL_modelist ) {
+            SDL_OutOfMemory();
+            return -1;
+        }
+        for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
+            if ((SDL_modelist[i] = 
+                 (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
+              break;
+#ifdef X11MODES_DEBUG
+            fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
+                   i, modelist[i].width, modelist[i].height);
+#endif
+            
+            SDL_modelist[i]->x = 0;
+            SDL_modelist[i]->y = 0;
+            SDL_modelist[i]->w = modelist[j].width;
+            SDL_modelist[i]->h = modelist[j].height;
+            
+        }
+        SDL_modelist[i] = NULL; /* terminator */
 
-                                /* we get the list already sorted in */
-                                /* descending order.  We'll copy it in */
-                                /* reverse order so SDL is happy */
-        if (SDL_modelist) {
-            for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
-                if ((SDL_modelist[i] = 
-                     (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
-                  break;
-#ifdef XIG_DEBUG
-                fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
-                       i, modelist[i].width, modelist[i].height);
-#endif
-                
-                SDL_modelist[i]->x = 0;
-                SDL_modelist[i]->y = 0;
-                SDL_modelist[i]->w = modelist[j].width;
-                SDL_modelist[i]->h = modelist[j].height;
-                
-            }
-            SDL_modelist[i] = NULL; /* terminator */
-        }
-        use_xme = 1;
+        use_xme = xme_major * 100 + xme_minor;
         saved_res = modelist[ractive]; /* save the current resolution */
-    } else {
-        use_xme = 0;
     }
     if ( modelist ) {
         XFree(modelist);
@@ -668,31 +803,38 @@
 
     if ( SDL_modelist == NULL ) {
         SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
-        if ( SDL_modelist ) {
-            n = 0;
-            SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
-            if ( SDL_modelist[n] ) {
-                SDL_modelist[n]->x = 0;
-                SDL_modelist[n]->y = 0;
-                SDL_modelist[n]->w = screen_w;
-                SDL_modelist[n]->h = screen_h;
-                ++n;
-            }
-            SDL_modelist[n] = NULL;
+        if ( !SDL_modelist ) {
+            SDL_OutOfMemory();
+            return -1;
         }
+        n = 0;
+        SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+        if ( SDL_modelist[n] ) {
+            SDL_modelist[n]->x = 0;
+            SDL_modelist[n]->y = 0;
+            SDL_modelist[n]->w = screen_w;
+            SDL_modelist[n]->h = screen_h;
+            ++n;
+        }
+        SDL_modelist[n] = NULL;
     }
 
-#if defined(XFREE86_DEBUG) || defined(XIG_DEBUG)
-    if ( use_vidmode ) {
-        printf("XFree86 VidMode is enabled\n");
+#ifdef X11MODES_DEBUG
+    if ( use_xinerama ) {
+        printf("Xinerama is enabled\n");
     }
 
-#if SDL_VIDEO_DRIVER_X11_XME
-    if ( use_xme )
-      printf("Xi Graphics XME fullscreen is enabled\n");
-    else
-      printf("Xi Graphics XME fullscreen is not available\n");
-#endif 
+    if ( use_xrandr ) {
+        printf("XRandR is enabled\n");
+    }
+
+    if ( use_vidmode ) {
+        printf("VidMode is enabled\n");
+    }
+
+    if ( use_xme ) {
+        printf("Xi Graphics XME fullscreen is enabled\n");
+    }
 
     if ( SDL_modelist ) {
         printf("X11 video mode list:\n");
@@ -700,46 +842,7 @@
             printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h);
         }
     }
-#endif /* XFREE86_DEBUG || XIG_DEBUG */
-
-    /* The default X/Y fullscreen offset is 0/0 */
-    xinerama_x = 0;
-    xinerama_y = 0;
-
-#if SDL_VIDEO_DRIVER_X11_XINERAMA
-    /* Query Xinerama extention */
-    if ( SDL_NAME(XineramaQueryExtension)(SDL_Display, &i, &i) &&
-         SDL_NAME(XineramaIsActive)(SDL_Display) ) {
-        /* Find out which screen is the desired one */
-        int desired = 0;
-        int screens;
-        SDL_NAME(XineramaScreenInfo) *xinerama;
-
-#ifdef XINERAMA_DEBUG
-        printf("X11 detected Xinerama:\n");
-#endif
-#if 0 /* Apparently the vidmode extension doesn't work with Xinerama */
-        const char *variable = SDL_getenv("SDL_VIDEO_X11_XINERAMA_SCREEN");
-        if ( variable ) {
-                desired = atoi(variable);
-        }
-#endif
-        xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
-        for ( i = 0; i < screens; i++ ) {
-#ifdef XINERAMA_DEBUG
-            printf("xinerama %d: %dx%d+%d+%d\n",
-                xinerama[i].screen_number,
-                xinerama[i].width, xinerama[i].height,
-                xinerama[i].x_org, xinerama[i].y_org);
-#endif
-            if ( xinerama[i].screen_number == desired ) {
-                xinerama_x = xinerama[i].x_org;
-                xinerama_y = xinerama[i].y_org;
-            }
-        }
-        XFree(xinerama);
-    }
-#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+#endif /* X11MODES_DEBUG */
 
     return 0;
 }
@@ -789,7 +892,7 @@
 
 int X11_ResizeFullScreen(_THIS)
 {
-    int x, y;
+    int x = 0, y = 0;
     int real_w, real_h;
     int screen_w;
     int screen_h;
@@ -797,8 +900,14 @@
     screen_w = DisplayWidth(SDL_Display, SDL_Screen);
     screen_h = DisplayHeight(SDL_Display, SDL_Screen);
 
-    x = xinerama_x;
-    y = xinerama_y;
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+    if ( use_xinerama &&
+         window_w <= xinerama_info.width &&
+         window_h <= xinerama_info.height ) {
+        x = xinerama_info.x_org;
+        y = xinerama_info.y_org;
+    }
+#endif
     if ( currently_fullscreen ) {
         /* Switch resolution and cover it with the FSwindow */
         move_cursor_to(this, x, y);
@@ -840,6 +949,7 @@
     Window tmpwin, *windows;
     int i, nwindows;
 #endif
+    int x = 0, y = 0;
     int real_w, real_h;
     int screen_w;
     int screen_h;
@@ -852,6 +962,14 @@
     /* Ungrab the input so that we can move the mouse around */
     X11_GrabInputNoLock(this, SDL_GRAB_OFF);
 
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+    if ( use_xinerama &&
+         window_w <= xinerama_info.width &&
+         window_h <= xinerama_info.height ) {
+        x = xinerama_info.x_org;
+        y = xinerama_info.y_org;
+    }
+#endif
     /* Map the fullscreen window to blank the screen */
     screen_w = DisplayWidth(SDL_Display, SDL_Screen);
     screen_h = DisplayHeight(SDL_Display, SDL_Screen);
@@ -863,7 +981,7 @@
         real_h = MAX(real_h, screen_h);
     }
     XMoveResizeWindow(SDL_Display, FSwindow,
-                      xinerama_x, xinerama_y, real_w, real_h);
+                      x, y, real_w, real_h);
     XMapRaised(SDL_Display, FSwindow);
     X11_WaitMapped(this, FSwindow);
 
@@ -908,8 +1026,9 @@
     if ( SDL_XColorMap ) {
         XInstallColormap(SDL_Display, SDL_XColorMap);
     }
-    if ( okay )
+    if ( okay ) {
         X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
+    }
 
     /* We may need to refresh the screen at this point (no backing store)
        We also don't get an event, which is why we explicitly refresh. */
--- a/src/video/x11/SDL_x11sym.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11sym.h	Wed May 17 08:18:28 2006 +0000
@@ -56,9 +56,9 @@
 SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return)
 SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
 SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
+SDL_X11_SYM(int,XGetScreenSaver,(Display* a,int* b,int* c,int* d, int* e),(a,b,c,d,e),return)
 SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)
 SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return)
-SDL_X11_SYM(Status,XGetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),return)
 SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return)
 SDL_X11_SYM(int,XGrabKeyboard,(Display* a,Window b,Bool c,int d,int e,Time f),(a,b,c,d,e,f),return)
 SDL_X11_SYM(int,XGrabPointer,(Display* a,Window b,Bool c,unsigned int d,int e,int f,Window g,Cursor h,Time i),(a,b,c,d,e,f,g,h,i),return)
@@ -91,6 +91,7 @@
 SDL_X11_SYM(int,XSetClassHint,(Display* a,Window b,XClassHint* c),(a,b,c),return)
 SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
 SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
+SDL_X11_SYM(int,XSetScreenSaver,(Display* a,int b,int c,int d,int e),(a,b,c,d,e),return)
 SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return)
 SDL_X11_SYM(int,XSetWMHints,(Display* a,Window b,XWMHints* c),(a,b,c),return)
 SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),)
@@ -187,5 +188,14 @@
 SDL_X11_SYM(void,XRRFreeScreenConfigInfo,(XRRScreenConfiguration *config),(config),)
 #endif
 
+/* DPMS support */
+#if SDL_VIDEO_DRIVER_X11_DPMS
+SDL_X11_MODULE(DPMS)
+SDL_X11_SYM(Status,DPMSQueryExtension,(Display *dpy,int *major_versionp,int *minor_versionp),(dpy,major_versionp,minor_versionp),return)
+SDL_X11_SYM(Status,DPMSInfo,(Display *dpy,CARD16 *state,BOOL *onoff),(dpy,state,onoff),return)
+SDL_X11_SYM(Status,DPMSEnable,(Display *dpy),(dpy),return)
+SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return)
+#endif
+
 /* end of SDL_x11sym.h ... */
 
--- a/src/video/x11/SDL_x11video.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11video.c	Wed May 17 08:18:28 2006 +0000
@@ -197,7 +197,7 @@
 	     (((e->error_code == BadRequest)&&(e->request_code == vm_error)) ||
 	      ((e->error_code > vm_error) &&
 	       (e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) {
-#ifdef XFREE86_DEBUG
+#ifdef X11_DEBUG
 { char errmsg[1024];
   XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
 printf("VidMode error: %s\n", errmsg);
@@ -212,7 +212,7 @@
         if ( (dga_error >= 0) &&
 	     ((e->error_code > dga_error) &&
 	      (e->error_code <= (dga_error+XF86DGANumberErrors))) ) {
-#ifdef XFREE86_DEBUG
+#ifdef X11_DEBUG
 { char errmsg[1024];
   XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
 printf("DGA error: %s\n", errmsg);
@@ -244,7 +244,7 @@
 static int (*Xext_handler)(Display *, _Xconst char *, _Xconst char *) = NULL;
 static int xext_errhandler(Display *d, _Xconst char *ext, _Xconst char *reason)
 {
-#ifdef XFREE86_DEBUG
+#ifdef X11_DEBUG
 	printf("Xext error inside SDL (may be harmless):\n");
 	printf("  Extension \"%s\" %s on display \"%s\".\n",
 	       ext, reason, XDisplayString(d));
@@ -310,18 +310,14 @@
 /* Create auxiliary (toplevel) windows with the current visual */
 static void create_aux_windows(_THIS)
 {
-    Atom _NET_WM_NAME;
-    Atom _NET_WM_ICON_NAME;
+    int x = 0, y = 0;
     char classname[1024];
     XSetWindowAttributes xattr;
     XWMHints *hints;
-    XTextProperty titleprop, titlepropUTF8, iconprop, iconpropUTF8;
     int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen));
 
     /* Look up some useful Atoms */
     WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
-    _NET_WM_NAME = XInternAtom(SDL_Display, "_NET_WM_NAME", False);
-    _NET_WM_ICON_NAME = XInternAtom(SDL_Display, "_NET_WM_ICON_NAME", False);
 
     /* Don't create any extra windows if we are being managed */
     if ( SDL_windowid ) {
@@ -333,13 +329,19 @@
     if(FSwindow)
 	XDestroyWindow(SDL_Display, FSwindow);
 
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+    if ( use_xinerama ) {
+        x = xinerama_info.x_org;
+        y = xinerama_info.y_org;
+    }
+#endif
     xattr.override_redirect = True;
     xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0;
     xattr.border_pixel = 0;
     xattr.colormap = SDL_XColorMap;
 
     FSwindow = XCreateWindow(SDL_Display, SDL_Root,
-                             xinerama_x, xinerama_y, 32, 32, 0,
+                             x, y, 32, 32, 0,
 			     this->hidden->depth, InputOutput, SDL_Visual,
 			     CWOverrideRedirect | CWBackPixel | CWBorderPixel
 			     | CWColormap,
@@ -365,21 +367,16 @@
     }
 
     hints = NULL;
-    titleprop.value = titlepropUTF8.value = NULL;
-    iconprop.value = iconpropUTF8.value = NULL;
     if(WMwindow) {
 	/* All window attributes must survive the recreation */
 	hints = XGetWMHints(SDL_Display, WMwindow);
-	XGetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
-	XGetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME);
-	XGetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
-	XGetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME);
 	XDestroyWindow(SDL_Display, WMwindow);
     }
 
     /* Create the window for windowed management */
     /* (reusing the xattr structure above) */
-    WMwindow = XCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0,
+    WMwindow = XCreateWindow(SDL_Display, SDL_Root,
+                             x, y, 32, 32, 0,
 			     this->hidden->depth, InputOutput, SDL_Visual,
 			     CWBackPixel | CWBorderPixel | CWColormap,
 			     &xattr);
@@ -392,22 +389,7 @@
     }
     XSetWMHints(SDL_Display, WMwindow, hints);
     XFree(hints);
-    if(titleprop.value) {
-	XSetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
-	XFree(titleprop.value);
-    }
-    if(titlepropUTF8.value) {
-	XSetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME);
-	XFree(titlepropUTF8.value);
-    }
-    if(iconprop.value) {
-	XSetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
-	XFree(iconprop.value);
-    }
-    if(iconpropUTF8.value) {
-	XSetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME);
-	XFree(iconpropUTF8.value);
-    }
+    X11_SetCaptionNoLock(this, this->wm_title, this->wm_icon);
 
     XSelectInput(SDL_Display, WMwindow,
 		 FocusChangeMask | KeyPressMask | KeyReleaseMask
@@ -562,6 +544,10 @@
 	}
 	X11_SaveVidModeGamma(this);
 
+	/* Save DPMS and screensaver settings */
+	X11_SaveScreenSaver(SDL_Display, &screensaver_timeout, &dpms_enabled);
+	X11_DisableScreenSaver(SDL_Display);
+
 	/* See if we have been passed a window to use */
 	SDL_windowid = SDL_getenv("SDL_WINDOWID");
 
@@ -1382,11 +1368,15 @@
 			SDL_free(SDL_iconcolors);
 			SDL_iconcolors = NULL;
 		} 
+
 		/* Restore gamma settings if they've changed */
 		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
 			X11_SwapVidModeGamma(this);
 		}
 
+		/* Restore DPMS and screensaver settings */
+		X11_RestoreScreenSaver(SDL_Display, screensaver_timeout, dpms_enabled);
+
 		/* Free that blank cursor */
 		if ( SDL_BlankCursor != NULL ) {
 			this->FreeWMCursor(this, SDL_BlankCursor);
--- a/src/video/x11/SDL_x11video.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11video.h	Wed May 17 08:18:28 2006 +0000
@@ -34,14 +34,20 @@
 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE
 #include "../Xext/extensions/xf86dga.h"
 #endif
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+#include "../Xext/extensions/Xinerama.h"
+#endif 
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+#include <X11/extensions/Xrandr.h>
+#endif
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
 #include "../Xext/extensions/xf86vmode.h"
 #endif
 #if SDL_VIDEO_DRIVER_X11_XME
 #include "../Xext/extensions/xme.h"
 #endif
-#if SDL_VIDEO_DRIVER_X11_XRANDR
-#include <X11/extensions/Xrandr.h>
+#if SDL_VIDEO_DRIVER_X11_DPMS
+#include <X11/extensions/dpms.h>
 #endif
 
 #include "SDL_x11dyn.h"
@@ -109,6 +115,14 @@
     int depth;			/* current visual depth (not bpp) */
 
     /* Variables used by the X11 video mode code */
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+    SDL_NAME(XineramaScreenInfo) xinerama_info;
+#endif
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+    XRRScreenConfiguration* screen_config;
+    int saved_size_id;
+    Rotation saved_rotation;
+#endif
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
     SDL_NAME(XF86VidModeModeInfo) saved_mode;
     struct {
@@ -116,19 +130,13 @@
     } saved_view;
 #endif
 #if SDL_VIDEO_DRIVER_X11_XME /* XiG XME fullscreen */
-    int use_xme;
     XiGMiscResolutionInfo saved_res;
 #endif
-#if SDL_VIDEO_DRIVER_X11_XRANDR
-    XRRScreenConfiguration* screen_config;
-    int saved_size_id;
-    Rotation saved_rotation;
-#endif
 
-    int xinerama_x;
-    int xinerama_y;
+    int use_xinerama;
+    int use_xrandr;
     int use_vidmode;
-    int use_xrandr;
+    int use_xme;
     int currently_fullscreen;
 
     /* Automatic mode switching support (entering/leaving fullscreen) */
@@ -146,6 +154,10 @@
     int gamma_changed;		/* flag: has VidMode gamma been modified? */
 
     short *iconcolors;		/* List of colors used by the icon */
+
+    /* Screensaver settings */
+    int screensaver_timeout;
+    BOOL dpms_enabled;
 };
 
 /* Old variable names */
@@ -174,17 +186,17 @@
 #define mouse_accel		(this->hidden->mouse_accel)
 #define mouse_relative		(this->hidden->mouse_relative)
 #define SDL_modelist		(this->hidden->modelist)
+#define xinerama_info		(this->hidden->xinerama_info)
 #define saved_mode		(this->hidden->saved_mode)
 #define saved_view		(this->hidden->saved_view)
-#define use_xme			(this->hidden->use_xme)
 #define saved_res		(this->hidden->saved_res)
-#define use_xrandr		(this->hidden->use_xrandr)
 #define screen_config		(this->hidden->screen_config)
 #define saved_size_id		(this->hidden->saved_size_id)
 #define saved_rotation		(this->hidden->saved_rotation)
-#define xinerama_x		(this->hidden->xinerama_x)
-#define xinerama_y		(this->hidden->xinerama_y)
+#define use_xinerama		(this->hidden->use_xinerama)
 #define use_vidmode		(this->hidden->use_vidmode)
+#define use_xrandr		(this->hidden->use_xrandr)
+#define use_xme			(this->hidden->use_xme)
 #define currently_fullscreen	(this->hidden->currently_fullscreen)
 #define switch_waiting		(this->hidden->switch_waiting)
 #define switch_time		(this->hidden->switch_time)
@@ -196,6 +208,8 @@
 #define gamma_saved		(this->hidden->gamma_saved)
 #define gamma_changed		(this->hidden->gamma_changed)
 #define SDL_iconcolors		(this->hidden->iconcolors)
+#define screensaver_timeout	(this->hidden->screensaver_timeout)
+#define dpms_enabled		(this->hidden->dpms_enabled)
 /* Some versions of XFree86 have bugs - detect if this is one of them */
 #define BUGGY_XFREE86(condition, buggy_version) \
 ((SDL_strcmp(ServerVendor(SDL_Display), "The XFree86 Project, Inc") == 0) && \
--- a/src/video/x11/SDL_x11wm.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11wm.c	Wed May 17 08:18:28 2006 +0000
@@ -240,7 +240,7 @@
 	SDL_FreeSurface(sicon);
 }
 
-void X11_SetCaption(_THIS, const char *title, const char *icon)
+void X11_SetCaptionNoLock(_THIS, const char *title, const char *icon)
 {
 	XTextProperty titleprop, iconprop;
 	Status status;
@@ -256,9 +256,6 @@
 	}
 #endif
 
-	/* Lock the event thread, in multi-threading environments */
-	SDL_Lock_EventThread();
-
 	if ( title != NULL ) {
 		char *title_latin1 = SDL_iconv_utf8_latin1((char *)title);
 		if ( !title_latin1 ) {
@@ -306,7 +303,12 @@
 #endif
 	}
 	XSync(SDL_Display, False);
+}
 
+void X11_SetCaption(_THIS, const char *title, const char *icon)
+{
+	SDL_Lock_EventThread();
+	X11_SetCaptionNoLock(this, title, icon);
 	SDL_Unlock_EventThread();
 }
 
@@ -344,7 +346,7 @@
 #if 0 /* We'll wait here until we actually grab, otherwise behavior undefined */
 		for ( numtries = 0; numtries < 10; ++numtries ) {
 #else
-		while ( 1 ) {
+		for ( ; ; ) {
 #endif
 			result = XGrabPointer(SDL_Display, SDL_Window, True, 0,
 						GrabModeAsync, GrabModeAsync,
--- a/src/video/x11/SDL_x11wm_c.h	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11wm_c.h	Wed May 17 08:18:28 2006 +0000
@@ -24,6 +24,7 @@
 #include "SDL_x11video.h"
 
 /* Functions to be exported */
+extern void X11_SetCaptionNoLock(_THIS, const char *title, const char *icon);
 extern void X11_SetCaption(_THIS, const char *title, const char *icon);
 extern void X11_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask);
 extern int X11_IconifyWindow(_THIS);
--- a/src/video/xbios/SDL_xbios.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/xbios/SDL_xbios.c	Wed May 17 08:18:28 2006 +0000
@@ -418,6 +418,7 @@
 
 	/* Determine the current screen size */
 	if ( XBIOS_nummodes > 0 ) {
+		/* FIXME: parse video mode list to search for current mode */
 		this->info.current_w = XBIOS_modelist[0].width;
 		this->info.current_h = XBIOS_modelist[0].height;
 	}
--- a/test/acinclude.m4	Mon May 01 06:58:33 2006 +0000
+++ b/test/acinclude.m4	Wed May 17 08:18:28 2006 +0000
@@ -20,19 +20,21 @@
 		    , enable_sdltest=yes)
 
   if test x$sdl_exec_prefix != x ; then
-     sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
-     if test x${SDL_CONFIG+set} != xset ; then
-        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
-     fi
+    sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
+    if test x${SDL_CONFIG+set} != xset ; then
+       SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
+    fi
   fi
   if test x$sdl_prefix != x ; then
-     sdl_args="$sdl_args --prefix=$sdl_prefix"
-     if test x${SDL_CONFIG+set} != xset ; then
-        SDL_CONFIG=$sdl_prefix/bin/sdl-config
-     fi
+    sdl_args="$sdl_args --prefix=$sdl_prefix"
+    if test x${SDL_CONFIG+set} != xset ; then
+       SDL_CONFIG=$sdl_prefix/bin/sdl-config
+    fi
   fi
 
-  PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+  if test "x$prefix" != xNONE; then
+    PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+  fi
   AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
   min_sdl_version=ifelse([$1], ,0.11.0,$1)
   AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
--- a/test/autogen.sh	Mon May 01 06:58:33 2006 +0000
+++ b/test/autogen.sh	Wed May 17 08:18:28 2006 +0000
@@ -3,7 +3,7 @@
 # Regenerate configuration files
 cp acinclude.m4 aclocal.m4
 found=false
-for autoconf in autoconf autoconf259
+for autoconf in autoconf autoconf259 autoconf-2.59
 do if which $autoconf >/dev/null 2>&1; then $autoconf && found=true; break; fi
 done
 if test x$found = xfalse; then
--- a/test/configure.in	Mon May 01 06:58:33 2006 +0000
+++ b/test/configure.in	Wed May 17 08:18:28 2006 +0000
@@ -28,7 +28,7 @@
     *-*-darwin* )
         EXE=""
         MATHLIB=""
-        SYS_GL_LIBS=""
+        SYS_GL_LIBS="-Wl,-framework,OpenGL"
         ;;
     *-*-aix*)
         EXE=""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/gcc-fat.sh	Wed May 17 08:18:28 2006 +0000
@@ -0,0 +1,110 @@
+#!/bin/sh
+#
+# Build Universal binaries on Mac OS X, thanks Ryan!
+#
+# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc x86
+
+# PowerPC compiler flags (10.2 runtime compatibility)
+GCC_COMPILE_PPC="gcc-3.3 -arch ppc \
+-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
+-nostdinc \
+-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
+-I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
+-isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include"
+
+GCC_LINK_PPC="\
+-L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
+-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
+-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
+
+# Intel compiler flags (10.4 runtime compatibility)
+GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
+-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
+-nostdinc \
+-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
+-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \
+-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
+
+GCC_LINK_X86="\
+-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \
+-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
+
+# Output both PowerPC and Intel object files
+args="$*"
+compile=yes
+link=yes
+while test x$1 != x; do
+    case $1 in
+        --version) exec gcc $1;;
+        -v) exec gcc $1;;
+        -V) exec gcc $1;;
+        -print-prog-name=*) exec gcc $1;;
+        -print-search-dirs) exec gcc $1;;
+        -E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E"
+            GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
+            compile=no; link=no;;
+        -c) link=no;;
+        -o) output=$2;;
+        *.c|*.cc|*.cpp|*.S) source=$1;;
+    esac
+    shift
+done
+if test x$link = xyes; then
+    GCC_COMPILE_PPC="$GCC_COMPILE_PPC $GCC_LINK_PPC"
+    GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
+fi
+if test x"$output" = x; then
+    if test x$link = xyes; then
+        output=a.out
+    elif test x$compile = xyes; then
+        output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
+    fi
+fi
+
+if test x"$output" != x; then
+    dir=ppc/`dirname $output`
+    if test -d $dir; then
+        :
+    else
+        mkdir -p $dir
+    fi
+fi
+set -- $args
+while test x$1 != x; do
+    if test -f "ppc/$1" && test "$1" != "$output"; then
+        ppc_args="$ppc_args ppc/$1"
+    else
+        ppc_args="$ppc_args $1"
+    fi
+    shift
+done
+$GCC_COMPILE_PPC $ppc_args || exit $?
+if test x"$output" != x; then
+    cp $output ppc/$output
+fi
+
+if test x"$output" != x; then
+    dir=x86/`dirname $output`
+    if test -d $dir; then
+        :
+    else
+        mkdir -p $dir
+    fi
+fi
+set -- $args
+while test x$1 != x; do
+    if test -f "x86/$1" && test "$1" != "$output"; then
+        x86_args="$x86_args x86/$1"
+    else
+        x86_args="$x86_args $1"
+    fi
+    shift
+done
+$GCC_COMPILE_X86 $x86_args || exit $?
+if test x"$output" != x; then
+    cp $output x86/$output
+fi
+
+if test x"$output" != x; then
+    lipo -create -o $output ppc/$output x86/$output
+fi
--- a/test/loopwave.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/loopwave.c	Wed May 17 08:18:28 2006 +0000
@@ -32,7 +32,7 @@
 }
 
 
-void fillerup(void *unused, Uint8 *stream, int len)
+void SDLCALL fillerup(void *unused, Uint8 *stream, int len)
 {
 	Uint8 *waveptr;
 	int    waveleft;
--- a/test/testalpha.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testalpha.c	Wed May 17 08:18:28 2006 +0000
@@ -505,7 +505,10 @@
 					}
 					break;
 				case SDL_KEYDOWN:
-					/* Any keypress quits the app... */
+					if ( event.key.keysym.sym == SDLK_ESCAPE ) {
+						done = 1;
+					}
+					break;
 				case SDL_QUIT:
 					done = 1;
 					break;
--- a/test/testdyngl.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testdyngl.c	Wed May 17 08:18:28 2006 +0000
@@ -19,6 +19,10 @@
 
 #include "SDL.h"
 
+#ifdef __MACOS__
+#define HAVE_OPENGL
+#endif
+
 #ifdef HAVE_OPENGL
 
 #include "SDL_opengl.h"
--- a/test/testerror.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testerror.c	Wed May 17 08:18:28 2006 +0000
@@ -17,7 +17,7 @@
 	exit(rc);
 }
 
-int ThreadFunc(void *data)
+int SDLCALL ThreadFunc(void *data)
 {
 	/* Set the child thread error string */
 	SDL_SetError("Thread %s (%d) had a problem: %s",
--- a/test/testfile.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testfile.c	Wed May 17 08:18:28 2006 +0000
@@ -2,6 +2,7 @@
 /* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
 
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "SDL.h"
 #include "SDL_endian.h"
--- a/test/testgl.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testgl.c	Wed May 17 08:18:28 2006 +0000
@@ -5,6 +5,10 @@
 
 #include "SDL.h"
 
+#ifdef __MACOS__
+#define HAVE_OPENGL
+#endif
+
 #ifdef HAVE_OPENGL
 
 #include "SDL_opengl.h"
--- a/test/testhread.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testhread.c	Wed May 17 08:18:28 2006 +0000
@@ -17,7 +17,7 @@
 	exit(rc);
 }
 
-int ThreadFunc(void *data)
+int SDLCALL ThreadFunc(void *data)
 {
 	printf("Started thread %s: My thread id is %u\n",
 				(char *)data, SDL_ThreadID());
--- a/test/testlock.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testlock.c	Wed May 17 08:18:28 2006 +0000
@@ -5,7 +5,6 @@
 
 #include <signal.h>
 #include <stdio.h>
-#include <stdlib.h>
 
 #include "SDL.h"
 #include "SDL_mutex.h"
@@ -14,6 +13,7 @@
 static SDL_mutex *mutex = NULL;
 static Uint32 mainthread;
 static SDL_Thread *threads[6];
+static volatile int doterminate = 0;
 
 /*
  * SDL_Quit() shouldn't be used with atexit() directly because
@@ -31,8 +31,8 @@
 	
 void terminate(int sig)
 {
-	printf("Process %u:  raising SIGTERM\n", SDL_ThreadID());
-	raise(SIGTERM);
+	signal(SIGINT, terminate);
+	doterminate = 1;
 }
 void closemutex(int sig)
 {
@@ -44,7 +44,7 @@
 	SDL_DestroyMutex(mutex);
 	exit(sig);
 }
-int Run(void *data)
+int SDLCALL Run(void *data)
 {
 	if ( SDL_ThreadID() == mainthread )
 		signal(SIGTERM, closemutex);
@@ -63,6 +63,10 @@
 		}
 		/* If this sleep isn't done, then threads may starve */
 		SDL_Delay(10);
+		if (SDL_ThreadID() == mainthread && doterminate) {
+			printf("Process %u:  raising SIGTERM\n", SDL_ThreadID());
+			raise(SIGTERM);
+		}
 	}
 	return(0);
 }
--- a/test/testpalette.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testpalette.c	Wed May 17 08:18:28 2006 +0000
@@ -15,7 +15,7 @@
 #define M_PI	3.14159265358979323846
 #endif
 
-#include <SDL.h>
+#include "SDL.h"
 
 /* screen size */
 #define SCRW 640
--- a/test/testsem.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testsem.c	Wed May 17 08:18:28 2006 +0000
@@ -13,7 +13,7 @@
 static SDL_sem *sem;
 int alive = 1;
 
-int ThreadFunc(void *data)
+int SDLCALL ThreadFunc(void *data)
 {
 	int threadnum = (int)(uintptr_t)data;
 	while ( alive ) {
--- a/test/testtimer.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testtimer.c	Wed May 17 08:18:28 2006 +0000
@@ -12,13 +12,13 @@
 
 static int ticks = 0;
 
-static Uint32 ticktock(Uint32 interval)
+static Uint32 SDLCALL ticktock(Uint32 interval)
 {
 	++ticks;
 	return(interval);
 }
 
-static Uint32 callback(Uint32 interval, void *param)
+static Uint32 SDLCALL callback(Uint32 interval, void *param)
 {
   printf("Timer %d : param = %d\n", interval, (int)(uintptr_t)param);
   return interval;
--- a/test/testwin.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testwin.c	Wed May 17 08:18:28 2006 +0000
@@ -250,9 +250,9 @@
 	delay = 1;
 
 #ifdef _WIN32_WCE
-	w = 640;
+	w = 240;
 	h = 320;
-	desired_bpp = 0;
+	desired_bpp = 8;
 	video_flags = SDL_FULLSCREEN;
 #else
 	w = 640;
--- a/test/testwm.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/testwm.c	Wed May 17 08:18:28 2006 +0000
@@ -168,7 +168,7 @@
 	SDL_PushEvent(&event);
 }
 
-int FilterEvents(const SDL_Event *event)
+int SDLCALL FilterEvents(const SDL_Event *event)
 {
 	static int reallyquit = 0;
 
@@ -180,10 +180,10 @@
 				event->active.gain ? "gained" : "lost");
 			if ( event->active.state & SDL_APPACTIVE )
 				printf("active ");
+			if ( event->active.state & SDL_APPINPUTFOCUS )
+				printf("input ");
 			if ( event->active.state & SDL_APPMOUSEFOCUS )
 				printf("mouse ");
-			if ( event->active.state & SDL_APPINPUTFOCUS )
-				printf("input ");
 			printf("focus\n");
 
 			/* See if we are iconified or restored */
--- a/test/threadwin.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/threadwin.c	Wed May 17 08:18:28 2006 +0000
@@ -77,7 +77,7 @@
 	return(icon);
 }
 
-int FilterEvents(const SDL_Event *event)
+int SDLCALL FilterEvents(const SDL_Event *event)
 {
 	static int reallyquit = 0;
 
@@ -127,7 +127,7 @@
 	}
 }
 
-int HandleMouse(void *unused)
+int SDLCALL HandleMouse(void *unused)
 {
 	SDL_Event events[10];
 	int i, found;
@@ -164,7 +164,7 @@
 	return(0);
 }
 
-int HandleKeyboard(void *unused)
+int SDLCALL HandleKeyboard(void *unused)
 {
 	SDL_Event events[10];
 	int i, found;
--- a/test/torturethread.c	Mon May 01 06:58:33 2006 +0000
+++ b/test/torturethread.c	Wed May 17 08:18:28 2006 +0000
@@ -20,14 +20,14 @@
 	exit(rc);
 }
 
-int SubThreadFunc(void *data) {
+int SDLCALL SubThreadFunc(void *data) {
 	while(! *(int volatile *)data) {
 		; /*SDL_Delay(10);*/  /* do nothing */
 	}
 	return 0;
 }
 
-int ThreadFunc(void *data) {
+int SDLCALL ThreadFunc(void *data) {
 	SDL_Thread *sub_threads[NUMTHREADS];
 	int flags[NUMTHREADS];
 	int i;