aboutsummaryrefslogtreecommitdiffstats
path: root/distrib/sdl-1.2.15/test
diff options
context:
space:
mode:
Diffstat (limited to 'distrib/sdl-1.2.15/test')
-rw-r--r--distrib/sdl-1.2.15/test/COPYING8
-rw-r--r--distrib/sdl-1.2.15/test/Makefile.in117
-rw-r--r--distrib/sdl-1.2.15/test/README35
-rw-r--r--distrib/sdl-1.2.15/test/acinclude.m4181
-rwxr-xr-xdistrib/sdl-1.2.15/test/autogen.sh12
-rw-r--r--distrib/sdl-1.2.15/test/checkkeys.c146
-rw-r--r--distrib/sdl-1.2.15/test/configure.in105
-rwxr-xr-xdistrib/sdl-1.2.15/test/gcc-fat.sh134
-rw-r--r--distrib/sdl-1.2.15/test/graywin.c257
-rw-r--r--distrib/sdl-1.2.15/test/icon.bmpbin0 -> 578 bytes
-rw-r--r--distrib/sdl-1.2.15/test/loopwave.c114
-rw-r--r--distrib/sdl-1.2.15/test/moose.datbin0 -> 56320 bytes
-rw-r--r--distrib/sdl-1.2.15/test/picture.xbm14
-rw-r--r--distrib/sdl-1.2.15/test/sail.bmpbin0 -> 15858 bytes
-rw-r--r--distrib/sdl-1.2.15/test/sample.bmpbin0 -> 69202 bytes
-rw-r--r--distrib/sdl-1.2.15/test/sample.wavbin0 -> 121946 bytes
-rw-r--r--distrib/sdl-1.2.15/test/testalpha.c547
-rw-r--r--distrib/sdl-1.2.15/test/testbitmap.c184
-rw-r--r--distrib/sdl-1.2.15/test/testblitspeed.c420
-rw-r--r--distrib/sdl-1.2.15/test/testcdrom.c209
-rw-r--r--distrib/sdl-1.2.15/test/testcursor.c216
-rw-r--r--distrib/sdl-1.2.15/test/testdyngl.c209
-rw-r--r--distrib/sdl-1.2.15/test/testerror.c61
-rw-r--r--distrib/sdl-1.2.15/test/testfile.c182
-rw-r--r--distrib/sdl-1.2.15/test/testgamma.c197
-rw-r--r--distrib/sdl-1.2.15/test/testgl.c856
-rw-r--r--distrib/sdl-1.2.15/test/testhread.c82
-rw-r--r--distrib/sdl-1.2.15/test/testiconv.c73
-rw-r--r--distrib/sdl-1.2.15/test/testjoystick.c188
-rw-r--r--distrib/sdl-1.2.15/test/testkeys.c25
-rw-r--r--distrib/sdl-1.2.15/test/testloadso.c71
-rw-r--r--distrib/sdl-1.2.15/test/testlock.c102
-rw-r--r--distrib/sdl-1.2.15/test/testoverlay.c594
-rw-r--r--distrib/sdl-1.2.15/test/testoverlay2.c600
-rw-r--r--distrib/sdl-1.2.15/test/testpalette.c342
-rw-r--r--distrib/sdl-1.2.15/test/testplatform.c210
-rw-r--r--distrib/sdl-1.2.15/test/testsem.c103
-rw-r--r--distrib/sdl-1.2.15/test/testsprite.c323
-rw-r--r--distrib/sdl-1.2.15/test/testtimer.c87
-rw-r--r--distrib/sdl-1.2.15/test/testver.c37
-rw-r--r--distrib/sdl-1.2.15/test/testvidinfo.c465
-rw-r--r--distrib/sdl-1.2.15/test/testwin.c377
-rw-r--r--distrib/sdl-1.2.15/test/testwm.c443
-rw-r--r--distrib/sdl-1.2.15/test/threadwin.c338
-rw-r--r--distrib/sdl-1.2.15/test/torturethread.c91
-rw-r--r--distrib/sdl-1.2.15/test/utf8.txt287
46 files changed, 9042 insertions, 0 deletions
diff --git a/distrib/sdl-1.2.15/test/COPYING b/distrib/sdl-1.2.15/test/COPYING
new file mode 100644
index 0000000..c4c27e0
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/COPYING
@@ -0,0 +1,8 @@
+
+The test programs in this directory tree are for demonstrating and
+testing the functionality of the SDL library, and are placed in the
+public domain.
+
+October 28, 1997
+--
+ Sam Lantinga (slouken@libsdl.org)
diff --git a/distrib/sdl-1.2.15/test/Makefile.in b/distrib/sdl-1.2.15/test/Makefile.in
new file mode 100644
index 0000000..7d5bb8b
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/Makefile.in
@@ -0,0 +1,117 @@
+# Makefile to build the SDL tests
+
+srcdir = @srcdir@
+
+CC = @CC@
+EXE = @EXE@
+CFLAGS = @CFLAGS@
+LIBS = @LIBS@
+
+TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE)
+
+all: $(TARGETS)
+
+checkkeys$(EXE): $(srcdir)/checkkeys.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+graywin$(EXE): $(srcdir)/graywin.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+loopwave$(EXE): $(srcdir)/loopwave.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testalpha$(EXE): $(srcdir)/testalpha.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
+
+testbitmap$(EXE): $(srcdir)/testbitmap.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testblitspeed$(EXE): $(srcdir)/testblitspeed.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testcdrom$(EXE): $(srcdir)/testcdrom.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testcursor$(EXE): $(srcdir)/testcursor.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testdyngl$(EXE): $(srcdir)/testdyngl.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testerror$(EXE): $(srcdir)/testerror.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testfile$(EXE): $(srcdir)/testfile.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testgamma$(EXE): $(srcdir)/testgamma.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
+
+testgl$(EXE): $(srcdir)/testgl.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
+
+testhread$(EXE): $(srcdir)/testhread.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testiconv$(EXE): $(srcdir)/testiconv.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testjoystick$(EXE): $(srcdir)/testjoystick.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testkeys$(EXE): $(srcdir)/testkeys.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testlock$(EXE): $(srcdir)/testlock.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testoverlay2$(EXE): $(srcdir)/testoverlay2.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testoverlay$(EXE): $(srcdir)/testoverlay.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testpalette$(EXE): $(srcdir)/testpalette.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
+
+testplatform$(EXE): $(srcdir)/testplatform.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testsem$(EXE): $(srcdir)/testsem.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testsprite$(EXE): $(srcdir)/testsprite.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
+
+testtimer$(EXE): $(srcdir)/testtimer.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testver$(EXE): $(srcdir)/testver.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testvidinfo$(EXE): $(srcdir)/testvidinfo.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testwin$(EXE): $(srcdir)/testwin.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testwm$(EXE): $(srcdir)/testwm.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+threadwin$(EXE): $(srcdir)/threadwin.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+torturethread$(EXE): $(srcdir)/torturethread.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+testloadso$(EXE): $(srcdir)/testloadso.c
+ $(CC) -o $@ $? $(CFLAGS) $(LIBS)
+
+
+clean:
+ rm -f $(TARGETS)
+
+distclean: clean
+ rm -f Makefile
+ rm -f config.status config.cache config.log
+ rm -rf $(srcdir)/autom4te*
diff --git a/distrib/sdl-1.2.15/test/README b/distrib/sdl-1.2.15/test/README
new file mode 100644
index 0000000..9cf5659
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/README
@@ -0,0 +1,35 @@
+
+These are test programs for the SDL library:
+
+ checkkeys Watch the key events to check the keyboard
+ graywin Display a gray gradient and center mouse on spacebar
+ loopwave Audio test -- loop playing a WAV file
+ testalpha Display an alpha faded icon -- paint with mouse
+ testbitmap Test displaying 1-bit bitmaps
+ testblitspeed Tests performance of SDL's blitters and converters.
+ testcdrom Sample audio CD control program
+ testcursor Tests custom mouse cursor
+ testdyngl Tests dynamically loading OpenGL library
+ testerror Tests multi-threaded error handling
+ testfile Tests RWops layer
+ testgamma Tests video device gamma ramp
+ testgl A very simple example of using OpenGL with SDL
+ testhread Hacked up test of multi-threading
+ testiconv Tests international string conversion
+ testjoystick List joysticks and watch joystick events
+ testkeys List the available keyboard keys
+ testloadso Tests the loadable library layer
+ testlock Hacked up test of multi-threading and locking
+ testoverlay Tests the software/hardware overlay functionality.
+ testoverlay2 Tests the overlay flickering/scaling during playback.
+ testpalette Tests palette color cycling
+ testplatform Tests types, endianness and cpu capabilities
+ testsem Tests SDL's semaphore implementation
+ testsprite Example of fast sprite movement on the screen
+ testtimer Test the timer facilities
+ testver Check the version and dynamic loading and endianness
+ testvidinfo Show the pixel format of the display and perfom the benchmark
+ testwin Display a BMP image at various depths
+ testwm Test window manager -- title, icon, events
+ threadwin Test multi-threaded event handling
+ torturethread Simple test for thread creation/destruction
diff --git a/distrib/sdl-1.2.15/test/acinclude.m4 b/distrib/sdl-1.2.15/test/acinclude.m4
new file mode 100644
index 0000000..b6df43f
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/acinclude.m4
@@ -0,0 +1,181 @@
+# Configure paths for SDL
+# Sam Lantinga 9/21/99
+# stolen from Manish Singh
+# stolen back from Frank Belew
+# stolen from Manish Singh
+# Shamelessly stolen from Owen Taylor
+
+dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
+dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
+dnl
+AC_DEFUN([AM_PATH_SDL],
+[dnl
+dnl Get the cflags and libraries from the sdl-config script
+dnl
+AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
+ sdl_prefix="$withval", sdl_prefix="")
+AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
+ sdl_exec_prefix="$withval", sdl_exec_prefix="")
+AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
+ , 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
+ 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
+ fi
+
+ 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)
+ no_sdl=""
+ if test "$SDL_CONFIG" = "no" ; then
+ no_sdl=yes
+ else
+ SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
+ SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
+
+ sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
+ sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
+ sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
+ if test "x$enable_sdltest" = "xyes" ; then
+ ac_save_CFLAGS="$CFLAGS"
+ ac_save_CXXFLAGS="$CXXFLAGS"
+ ac_save_LIBS="$LIBS"
+ CFLAGS="$CFLAGS $SDL_CFLAGS"
+ CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
+ LIBS="$LIBS $SDL_LIBS"
+dnl
+dnl Now check if the installed SDL is sufficiently new. (Also sanity
+dnl checks the results of sdl-config to some extent
+dnl
+ rm -f conf.sdltest
+ AC_TRY_RUN([
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "SDL.h"
+
+char*
+my_strdup (char *str)
+{
+ char *new_str;
+
+ if (str)
+ {
+ new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
+ strcpy (new_str, str);
+ }
+ else
+ new_str = NULL;
+
+ return new_str;
+}
+
+int main (int argc, char *argv[])
+{
+ int major, minor, micro;
+ char *tmp_version;
+
+ /* This hangs on some systems (?)
+ system ("touch conf.sdltest");
+ */
+ { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
+
+ /* HP/UX 9 (%@#!) writes to sscanf strings */
+ tmp_version = my_strdup("$min_sdl_version");
+ if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
+ printf("%s, bad version string\n", "$min_sdl_version");
+ exit(1);
+ }
+
+ if (($sdl_major_version > major) ||
+ (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
+ (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
+ {
+ return 0;
+ }
+ else
+ {
+ printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
+ printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
+ printf("*** best to upgrade to the required version.\n");
+ printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
+ printf("*** to point to the correct copy of sdl-config, and remove the file\n");
+ printf("*** config.cache before re-running configure\n");
+ return 1;
+ }
+}
+
+],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
+ CFLAGS="$ac_save_CFLAGS"
+ CXXFLAGS="$ac_save_CXXFLAGS"
+ LIBS="$ac_save_LIBS"
+ fi
+ fi
+ if test "x$no_sdl" = x ; then
+ AC_MSG_RESULT(yes)
+ ifelse([$2], , :, [$2])
+ else
+ AC_MSG_RESULT(no)
+ if test "$SDL_CONFIG" = "no" ; then
+ echo "*** The sdl-config script installed by SDL could not be found"
+ echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
+ echo "*** your path, or set the SDL_CONFIG environment variable to the"
+ echo "*** full path to sdl-config."
+ else
+ if test -f conf.sdltest ; then
+ :
+ else
+ echo "*** Could not run SDL test program, checking why..."
+ CFLAGS="$CFLAGS $SDL_CFLAGS"
+ CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
+ LIBS="$LIBS $SDL_LIBS"
+ AC_TRY_LINK([
+#include <stdio.h>
+#include "SDL.h"
+
+int main(int argc, char *argv[])
+{ return 0; }
+#undef main
+#define main K_and_R_C_main
+], [ return 0; ],
+ [ echo "*** The test program compiled, but did not run. This usually means"
+ echo "*** that the run-time linker is not finding SDL or finding the wrong"
+ echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
+ echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
+ echo "*** to the installed location Also, make sure you have run ldconfig if that"
+ echo "*** is required on your system"
+ echo "***"
+ echo "*** If you have an old version installed, it is best to remove it, although"
+ echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
+ [ echo "*** The test program failed to compile or link. See the file config.log for the"
+ echo "*** exact error that occured. This usually means SDL was incorrectly installed"
+ echo "*** or that you have moved SDL since it was installed. In the latter case, you"
+ echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
+ CFLAGS="$ac_save_CFLAGS"
+ CXXFLAGS="$ac_save_CXXFLAGS"
+ LIBS="$ac_save_LIBS"
+ fi
+ fi
+ SDL_CFLAGS=""
+ SDL_LIBS=""
+ ifelse([$3], , :, [$3])
+ fi
+ AC_SUBST(SDL_CFLAGS)
+ AC_SUBST(SDL_LIBS)
+ rm -f conf.sdltest
+])
diff --git a/distrib/sdl-1.2.15/test/autogen.sh b/distrib/sdl-1.2.15/test/autogen.sh
new file mode 100755
index 0000000..939f34c
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/autogen.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# Regenerate configuration files
+cp acinclude.m4 aclocal.m4
+found=false
+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
+ echo "Couldn't find autoconf, aborting"
+ exit 1
+fi
diff --git a/distrib/sdl-1.2.15/test/checkkeys.c b/distrib/sdl-1.2.15/test/checkkeys.c
new file mode 100644
index 0000000..8dbb24f
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/checkkeys.c
@@ -0,0 +1,146 @@
+
+/* Simple program: Loop, watching keystrokes
+ Note that you need to call SDL_PollEvent() or SDL_WaitEvent() to
+ pump the event loop and catch keystrokes.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+static void print_modifiers(void)
+{
+ int mod;
+ printf(" modifiers:");
+ mod = SDL_GetModState();
+ if(!mod) {
+ printf(" (none)");
+ return;
+ }
+ if(mod & KMOD_LSHIFT)
+ printf(" LSHIFT");
+ if(mod & KMOD_RSHIFT)
+ printf(" RSHIFT");
+ if(mod & KMOD_LCTRL)
+ printf(" LCTRL");
+ if(mod & KMOD_RCTRL)
+ printf(" RCTRL");
+ if(mod & KMOD_LALT)
+ printf(" LALT");
+ if(mod & KMOD_RALT)
+ printf(" RALT");
+ if(mod & KMOD_LMETA)
+ printf(" LMETA");
+ if(mod & KMOD_RMETA)
+ printf(" RMETA");
+ if(mod & KMOD_NUM)
+ printf(" NUM");
+ if(mod & KMOD_CAPS)
+ printf(" CAPS");
+ if(mod & KMOD_MODE)
+ printf(" MODE");
+}
+
+static void PrintKey(SDL_keysym *sym, int pressed)
+{
+ /* Print the keycode, name and state */
+ if ( sym->sym ) {
+ printf("Key %s: %d-%s ", pressed ? "pressed" : "released",
+ sym->sym, SDL_GetKeyName(sym->sym));
+ } else {
+ printf("Unknown Key (scancode = %d) %s ", sym->scancode,
+ pressed ? "pressed" : "released");
+ }
+
+ /* Print the translated character, if one exists */
+ if ( sym->unicode ) {
+ /* Is it a control-character? */
+ if ( sym->unicode < ' ' ) {
+ printf(" (^%c)", sym->unicode+'@');
+ } else {
+#ifdef UNICODE
+ printf(" (%c)", sym->unicode);
+#else
+ /* This is a Latin-1 program, so only show 8-bits */
+ if ( !(sym->unicode & 0xFF00) )
+ printf(" (%c)", sym->unicode);
+ else
+ printf(" (0x%X)", sym->unicode);
+#endif
+ }
+ }
+ print_modifiers();
+ printf("\n");
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Event event;
+ int done;
+ Uint32 videoflags;
+
+ /* Initialize SDL */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ videoflags = SDL_SWSURFACE;
+ while( argc > 1 ) {
+ --argc;
+ if ( argv[argc] && !strcmp(argv[argc], "-fullscreen") ) {
+ videoflags |= SDL_FULLSCREEN;
+ } else {
+ fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
+ quit(1);
+ }
+ }
+
+ /* Set 640x480 video mode */
+ if ( SDL_SetVideoMode(640, 480, 0, videoflags) == NULL ) {
+ fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
+ SDL_GetError());
+ quit(2);
+ }
+
+ /* Enable UNICODE translation for keyboard input */
+ SDL_EnableUNICODE(1);
+
+ /* Enable auto repeat for keyboard input */
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
+ SDL_DEFAULT_REPEAT_INTERVAL);
+
+ /* Watch keystrokes */
+ done = 0;
+ while ( !done ) {
+ /* Check for events */
+ SDL_WaitEvent(&event);
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ PrintKey(&event.key.keysym, 1);
+ break;
+ case SDL_KEYUP:
+ PrintKey(&event.key.keysym, 0);
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ /* Any button press quits the app... */
+ case SDL_QUIT:
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/configure.in b/distrib/sdl-1.2.15/test/configure.in
new file mode 100644
index 0000000..7c25c17
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/configure.in
@@ -0,0 +1,105 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(README)
+
+dnl Detect the canonical build and host environments
+AC_CONFIG_AUX_DIRS($srcdir/../build-scripts)
+AC_CANONICAL_HOST
+
+dnl Check for tools
+
+AC_PROG_CC
+
+dnl Check for compiler environment
+
+AC_C_CONST
+
+dnl Figure out which math library to use
+case "$host" in
+ *-*-cygwin* | *-*-mingw32*)
+ EXE=".exe"
+ MATHLIB=""
+ SYS_GL_LIBS="-lopengl32"
+ ;;
+ *-*-beos* | *-*-haiku*)
+ EXE=""
+ MATHLIB=""
+ SYS_GL_LIBS="-lGL"
+ ;;
+ *-*-darwin* )
+ EXE=""
+ MATHLIB=""
+ SYS_GL_LIBS="-Wl,-framework,OpenGL"
+ ;;
+ *-*-aix*)
+ EXE=""
+ if test x$ac_cv_prog_gcc = xyes; then
+ CFLAGS="-mthreads"
+ fi
+ SYS_GL_LIBS=""
+ ;;
+ *-*-mint*)
+ EXE=""
+ MATHLIB=""
+ AC_PATH_PROG(OSMESA_CONFIG, osmesa-config, no)
+ if test "x$OSMESA_CONFIG" = "xyes"; then
+ OSMESA_CFLAGS=`$OSMESA_CONFIG --cflags`
+ OSMESA_LIBS=`$OSMESA_CONFIG --libs`
+ CFLAGS="$CFLAGS $OSMESA_CFLAGS"
+ SYS_GL_LIBS="$OSMESA_LIBS"
+ else
+ SYS_GL_LIBS="-lOSMesa"
+ fi
+ ;;
+ *)
+ EXE=""
+ MATHLIB="-lm"
+ SYS_GL_LIBS="-lGL"
+ ;;
+esac
+AC_SUBST(EXE)
+AC_SUBST(MATHLIB)
+
+dnl Check for SDL
+SDL_VERSION=1.2.10
+AM_PATH_SDL($SDL_VERSION,
+ :,
+ AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
+)
+CFLAGS="$CFLAGS $SDL_CFLAGS"
+LIBS="$LIBS $SDL_LIBS"
+
+dnl Check for X11 path, needed for OpenGL on some systems
+AC_PATH_X
+if test x$have_x = xyes; then
+ if test x$ac_x_includes = xno || test x$ac_x_includes = x; then
+ :
+ else
+ CFLAGS="$CFLAGS -I$ac_x_includes"
+ fi
+ if test x$ac_x_libraries = xno || test x$ac_x_libraries = x; then
+ :
+ else
+ XPATH="-L$ac_x_libraries"
+ fi
+fi
+
+dnl Check for OpenGL
+AC_MSG_CHECKING(for OpenGL support)
+have_opengl=no
+AC_TRY_COMPILE([
+ #include "SDL_opengl.h"
+],[
+],[
+have_opengl=yes
+])
+AC_MSG_RESULT($have_opengl)
+if test x$have_opengl = xyes; then
+ CFLAGS="$CFLAGS -DHAVE_OPENGL"
+ GLLIB="$XPATH $SYS_GL_LIBS"
+else
+ GLLIB=""
+fi
+AC_SUBST(GLLIB)
+
+dnl Finally create all the generated files
+AC_OUTPUT([Makefile])
diff --git a/distrib/sdl-1.2.15/test/gcc-fat.sh b/distrib/sdl-1.2.15/test/gcc-fat.sh
new file mode 100755
index 0000000..203b941
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/gcc-fat.sh
@@ -0,0 +1,134 @@
+#!/bin/sh
+#
+# Build Universal binaries on Mac OS X, thanks Ryan!
+#
+# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc x86
+
+# Locate Xcode SDK path
+SDK_PATH=/Developer/SDKs
+if [ ! -d $SDK_PATH ]; then
+ echo "Couldn't find SDK path"
+ exit 1
+fi
+
+if [ -d "$SDK_PATH/MacOSX10.2.8.sdk" ]; then
+ # PowerPC compiler flags (10.2 runtime compatibility)
+ GCC_COMPILE_PPC="gcc-3.3 -arch ppc \
+-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
+-nostdinc \
+-F$SDK_PATH/MacOSX10.2.8.sdk/System/Library/Frameworks \
+-I$SDK_PATH/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
+-isystem $SDK_PATH/MacOSX10.2.8.sdk/usr/include"
+
+ GCC_LINK_PPC="\
+-L$SDK_PATH/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
+-F$SDK_PATH/MacOSX10.2.8.sdk/System/Library/Frameworks \
+-Wl,-syslibroot,$SDK_PATH/MacOSX10.2.8.sdk"
+
+else # 10.2 or 10.3 SDK
+ # PowerPC compiler flags (10.3 runtime compatibility)
+ GCC_COMPILE_PPC="gcc-4.0 -arch ppc -mmacosx-version-min=10.3 \
+-DMAC_OS_X_VERSION_MIN_REQUIRED=1030 \
+-nostdinc \
+-F$SDK_PATH/MacOSX10.3.9.sdk/System/Library/Frameworks \
+-I$SDK_PATH/MacOSX10.3.9.sdk/usr/lib/gcc/powerpc-apple-darwin9/4.0.1/include \
+-isystem $SDK_PATH/MacOSX10.3.9.sdk/usr/include"
+
+ GCC_LINK_PPC="\
+-L$SDK_PATH/MacOSX10.3.9.sdk/usr/lib/gcc/powerpc-apple-darwin9/4.0.1 \
+-F$SDK_PATH/MacOSX10.3.9.sdk/System/Library/Frameworks \
+-Wl,-syslibroot,$SDK_PATH/MacOSX10.3.9.sdk"
+
+fi # 10.2 or 10.3 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$SDK_PATH/MacOSX10.4u.sdk/System/Library/Frameworks \
+-I$SDK_PATH/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin9/4.0.1/include \
+-isystem $SDK_PATH/MacOSX10.4u.sdk/usr/include"
+
+GCC_LINK_X86="\
+-L$SDK_PATH/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin9/4.0.1 \
+-Wl,-syslibroot,$SDK_PATH/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
diff --git a/distrib/sdl-1.2.15/test/graywin.c b/distrib/sdl-1.2.15/test/graywin.c
new file mode 100644
index 0000000..4563114
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/graywin.c
@@ -0,0 +1,257 @@
+
+/* Simple program: Fill a colormap with gray and stripe it down the screen */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "SDL.h"
+
+#ifdef TEST_VGA16 /* Define this if you want to test VGA 16-color video modes */
+#define NUM_COLORS 16
+#else
+#define NUM_COLORS 256
+#endif
+
+/* Draw a randomly sized and colored box centered about (X,Y) */
+void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height)
+{
+ static unsigned int seeded = 0;
+ SDL_Rect area;
+ Uint32 color;
+ Uint32 randc;
+
+ /* Seed the random number generator */
+ if ( seeded == 0 ) {
+ srand(time(NULL));
+ seeded = 1;
+ }
+
+ /* Get the bounds of the rectangle */
+ area.w = (rand()%width);
+ area.h = (rand()%height);
+ area.x = X-(area.w/2);
+ area.y = Y-(area.h/2);
+ randc = (rand()%NUM_COLORS);
+
+ if (screen->format->BytesPerPixel==1)
+ {
+ color = randc;
+ }
+ else
+ {
+ color = SDL_MapRGB(screen->format, randc, randc, randc);
+ }
+
+ /* Do it! */
+ SDL_FillRect(screen, &area, color);
+ if ( screen->flags & SDL_DOUBLEBUF ) {
+ SDL_Flip(screen);
+ } else {
+ SDL_UpdateRects(screen, 1, &area);
+ }
+}
+
+void DrawBackground(SDL_Surface *screen)
+{
+ int i, j, k;
+ Uint8 *buffer;
+ Uint16 *buffer16;
+ Uint16 color;
+ Uint8 gradient;
+
+ /* Set the surface pixels and refresh! */
+ /* Use two loops in case the surface is double-buffered (both sides) */
+
+ for ( j=0; j<2; ++j ) {
+ if ( SDL_LockSurface(screen) < 0 ) {
+ fprintf(stderr, "Couldn't lock display surface: %s\n",
+ SDL_GetError());
+ return;
+ }
+ buffer = (Uint8 *)screen->pixels;
+
+ if (screen->format->BytesPerPixel!=2) {
+ for ( i=0; i<screen->h; ++i ) {
+ memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
+ buffer += screen->pitch;
+ }
+ }
+ else
+ {
+ for ( i=0; i<screen->h; ++i ) {
+ gradient=((i*(NUM_COLORS-1))/screen->h);
+ color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
+ buffer16=(Uint16*)buffer;
+ for (k=0; k<screen->w; k++)
+ {
+ *(buffer16+k)=color;
+ }
+ buffer += screen->pitch;
+ }
+ }
+
+ SDL_UnlockSurface(screen);
+ if ( screen->flags & SDL_DOUBLEBUF ) {
+ SDL_Flip(screen);
+ } else {
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+ break;
+ }
+ }
+}
+
+SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
+{
+ SDL_Surface *screen;
+ int i;
+ SDL_Color palette[NUM_COLORS];
+
+ /* Set the video mode */
+ screen = SDL_SetVideoMode(w, h, bpp, flags);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't set display mode: %s\n",
+ SDL_GetError());
+ return(NULL);
+ }
+ fprintf(stderr, "Screen is in %s mode\n",
+ (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
+
+ if (bpp==8) {
+ /* Set a gray colormap, reverse order from white to black */
+ for ( i=0; i<NUM_COLORS; ++i ) {
+ palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
+ palette[i].g = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
+ palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
+ }
+ SDL_SetColors(screen, palette, 0, NUM_COLORS);
+ }
+
+ return(screen);
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Surface *screen;
+ Uint32 videoflags;
+ int done;
+ SDL_Event event;
+ int width, height, bpp;
+
+ /* Initialize SDL */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ exit(1);
+ }
+
+ /* See if we try to get a hardware colormap */
+ width = 640;
+ height = 480;
+ bpp = 8;
+ videoflags = SDL_SWSURFACE;
+ while ( argc > 1 ) {
+ --argc;
+ if ( argv[argc-1] && (strcmp(argv[argc-1], "-width") == 0) ) {
+ width = atoi(argv[argc]);
+ --argc;
+ } else
+ if ( argv[argc-1] && (strcmp(argv[argc-1], "-height") == 0) ) {
+ height = atoi(argv[argc]);
+ --argc;
+ } else
+ if ( argv[argc-1] && (strcmp(argv[argc-1], "-bpp") == 0) ) {
+ bpp = atoi(argv[argc]);
+ --argc;
+ } else
+ if ( argv[argc] && (strcmp(argv[argc], "-hw") == 0) ) {
+ videoflags |= SDL_HWSURFACE;
+ } else
+ if ( argv[argc] && (strcmp(argv[argc], "-hwpalette") == 0) ) {
+ videoflags |= SDL_HWPALETTE;
+ } else
+ if ( argv[argc] && (strcmp(argv[argc], "-flip") == 0) ) {
+ videoflags |= SDL_DOUBLEBUF;
+ } else
+ if ( argv[argc] && (strcmp(argv[argc], "-noframe") == 0) ) {
+ videoflags |= SDL_NOFRAME;
+ } else
+ if ( argv[argc] && (strcmp(argv[argc], "-resize") == 0) ) {
+ videoflags |= SDL_RESIZABLE;
+ } else
+ if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) {
+ videoflags |= SDL_FULLSCREEN;
+ } else {
+ fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-flip] [-noframe] [-fullscreen] [-resize]\n",
+ argv[0]);
+ exit(1);
+ }
+ }
+
+ /* Set a video mode */
+ screen = CreateScreen(width, height, bpp, videoflags);
+ if ( screen == NULL ) {
+ exit(2);
+ }
+
+ DrawBackground(screen);
+
+ /* Wait for a keystroke */
+ done = 0;
+ while ( !done && SDL_WaitEvent(&event) ) {
+ switch (event.type) {
+ case SDL_MOUSEBUTTONDOWN:
+ DrawBox(screen, event.button.x, event.button.y, width, height);
+ break;
+ case SDL_KEYDOWN:
+ /* Ignore ALT-TAB for windows */
+ if ( (event.key.keysym.sym == SDLK_LALT) ||
+ (event.key.keysym.sym == SDLK_TAB) ) {
+ break;
+ }
+ /* Center the mouse on <SPACE> */
+ if ( event.key.keysym.sym == SDLK_SPACE ) {
+ SDL_WarpMouse(width/2, height/2);
+ break;
+ }
+ /* Toggle fullscreen mode on <RETURN> */
+ if ( event.key.keysym.sym == SDLK_RETURN ) {
+ videoflags ^= SDL_FULLSCREEN;
+ screen = CreateScreen(
+ screen->w, screen->h,
+ screen->format->BitsPerPixel,
+ videoflags);
+ if ( screen == NULL ) {
+ fprintf(stderr,
+ "Couldn't toggle fullscreen mode\n");
+ done = 1;
+ }
+ DrawBackground(screen);
+ break;
+ }
+ /* Any other key quits the application... */
+ case SDL_QUIT:
+ done = 1;
+ break;
+ case SDL_VIDEOEXPOSE:
+ DrawBackground(screen);
+ break;
+ case SDL_VIDEORESIZE:
+ screen = CreateScreen(
+ event.resize.w, event.resize.h,
+ screen->format->BitsPerPixel,
+ videoflags);
+ if ( screen == NULL ) {
+ fprintf(stderr,
+ "Couldn't resize video mode\n");
+ done = 1;
+ }
+ DrawBackground(screen);
+ break;
+ default:
+ break;
+ }
+ }
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/icon.bmp b/distrib/sdl-1.2.15/test/icon.bmp
new file mode 100644
index 0000000..cc96356
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/icon.bmp
Binary files differ
diff --git a/distrib/sdl-1.2.15/test/loopwave.c b/distrib/sdl-1.2.15/test/loopwave.c
new file mode 100644
index 0000000..e1df747
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/loopwave.c
@@ -0,0 +1,114 @@
+
+/* Program to load a wave file and loop playing it using SDL sound */
+
+/* loopwaves.c is much more robust in handling WAVE files --
+ This is only for simple WAVEs
+*/
+#include "SDL_config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+
+#include "SDL.h"
+#include "SDL_audio.h"
+
+struct {
+ SDL_AudioSpec spec;
+ Uint8 *sound; /* Pointer to wave data */
+ Uint32 soundlen; /* Length of wave data */
+ int soundpos; /* Current play position */
+} wave;
+
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+
+void SDLCALL fillerup(void *unused, Uint8 *stream, int len)
+{
+ Uint8 *waveptr;
+ int waveleft;
+
+ /* Set up the pointers */
+ waveptr = wave.sound + wave.soundpos;
+ waveleft = wave.soundlen - wave.soundpos;
+
+ /* Go! */
+ while ( waveleft <= len ) {
+ SDL_memcpy(stream, waveptr, waveleft);
+ stream += waveleft;
+ len -= waveleft;
+ waveptr = wave.sound;
+ waveleft = wave.soundlen;
+ wave.soundpos = 0;
+ }
+ SDL_memcpy(stream, waveptr, len);
+ wave.soundpos += len;
+}
+
+static int done = 0;
+void poked(int sig)
+{
+ done = 1;
+}
+
+int main(int argc, char *argv[])
+{
+ char name[32];
+
+ /* Load the SDL library */
+ if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+ if ( argv[1] == NULL ) {
+ argv[1] = "sample.wav";
+ }
+ /* Load the wave file into memory */
+ if ( SDL_LoadWAV(argv[1],
+ &wave.spec, &wave.sound, &wave.soundlen) == NULL ) {
+ fprintf(stderr, "Couldn't load %s: %s\n",
+ argv[1], SDL_GetError());
+ quit(1);
+ }
+
+ wave.spec.callback = fillerup;
+#if HAVE_SIGNAL_H
+ /* Set the signals */
+#ifdef SIGHUP
+ signal(SIGHUP, poked);
+#endif
+ signal(SIGINT, poked);
+#ifdef SIGQUIT
+ signal(SIGQUIT, poked);
+#endif
+ signal(SIGTERM, poked);
+#endif /* HAVE_SIGNAL_H */
+
+ /* Initialize fillerup() variables */
+ if ( SDL_OpenAudio(&wave.spec, NULL) < 0 ) {
+ fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
+ SDL_FreeWAV(wave.sound);
+ quit(2);
+ }
+ SDL_PauseAudio(0);
+
+ /* Let the audio run */
+ printf("Using audio driver: %s\n", SDL_AudioDriverName(name, 32));
+ while ( ! done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) )
+ SDL_Delay(1000);
+
+ /* Clean up on signal */
+ SDL_CloseAudio();
+ SDL_FreeWAV(wave.sound);
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/moose.dat b/distrib/sdl-1.2.15/test/moose.dat
new file mode 100644
index 0000000..1053004
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/moose.dat
Binary files differ
diff --git a/distrib/sdl-1.2.15/test/picture.xbm b/distrib/sdl-1.2.15/test/picture.xbm
new file mode 100644
index 0000000..c873a60
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/picture.xbm
@@ -0,0 +1,14 @@
+#define picture_width 32
+#define picture_height 32
+static char picture_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x80, 0x01, 0x18,
+ 0x64, 0x6f, 0xf6, 0x26, 0x0a, 0x00, 0x00, 0x50, 0xf2, 0xff, 0xff, 0x4f,
+ 0x14, 0x04, 0x00, 0x28, 0x14, 0x0e, 0x00, 0x28, 0x10, 0x32, 0x00, 0x08,
+ 0x94, 0x03, 0x00, 0x08, 0xf4, 0x04, 0x00, 0x08, 0xb0, 0x08, 0x00, 0x08,
+ 0x34, 0x01, 0x00, 0x28, 0x34, 0x01, 0x00, 0x28, 0x12, 0x00, 0x40, 0x48,
+ 0x12, 0x20, 0xa6, 0x48, 0x14, 0x50, 0x11, 0x29, 0x14, 0x50, 0x48, 0x2a,
+ 0x10, 0x27, 0xac, 0x0e, 0xd4, 0x71, 0xe8, 0x0a, 0x74, 0x20, 0xa8, 0x0a,
+ 0x14, 0x20, 0x00, 0x08, 0x10, 0x50, 0x00, 0x08, 0x14, 0x00, 0x00, 0x28,
+ 0x14, 0x00, 0x00, 0x28, 0xf2, 0xff, 0xff, 0x4f, 0x0a, 0x00, 0x00, 0x50,
+ 0x64, 0x6f, 0xf6, 0x26, 0x18, 0x80, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/distrib/sdl-1.2.15/test/sail.bmp b/distrib/sdl-1.2.15/test/sail.bmp
new file mode 100644
index 0000000..12850c3
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/sail.bmp
Binary files differ
diff --git a/distrib/sdl-1.2.15/test/sample.bmp b/distrib/sdl-1.2.15/test/sample.bmp
new file mode 100644
index 0000000..aca8bbc
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/sample.bmp
Binary files differ
diff --git a/distrib/sdl-1.2.15/test/sample.wav b/distrib/sdl-1.2.15/test/sample.wav
new file mode 100644
index 0000000..002f815
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/sample.wav
Binary files differ
diff --git a/distrib/sdl-1.2.15/test/testalpha.c b/distrib/sdl-1.2.15/test/testalpha.c
new file mode 100644
index 0000000..7e04fbe
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testalpha.c
@@ -0,0 +1,547 @@
+
+/* Simple program: Fill a colormap with gray and stripe it down the screen,
+ Then move an alpha valued sprite around the screen.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "SDL.h"
+
+#define FRAME_TICKS (1000/30) /* 30 frames/second */
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+/* Fill the screen with a gradient */
+static void FillBackground(SDL_Surface *screen)
+{
+ Uint8 *buffer;
+ Uint16 *buffer16;
+ Uint16 color;
+ Uint8 gradient;
+ int i, k;
+
+ /* Set the surface pixels and refresh! */
+ if ( SDL_LockSurface(screen) < 0 ) {
+ fprintf(stderr, "Couldn't lock the display surface: %s\n",
+ SDL_GetError());
+ quit(2);
+ }
+ buffer=(Uint8 *)screen->pixels;
+ if (screen->format->BytesPerPixel!=2) {
+ for ( i=0; i<screen->h; ++i ) {
+ memset(buffer,(i*255)/screen->h, screen->w*screen->format->BytesPerPixel);
+ buffer += screen->pitch;
+ }
+ }
+ else
+ {
+ for ( i=0; i<screen->h; ++i ) {
+ gradient=((i*255)/screen->h);
+ color = (Uint16)SDL_MapRGB(screen->format, gradient, gradient, gradient);
+ buffer16=(Uint16*)buffer;
+ for (k=0; k<screen->w; k++)
+ {
+ *(buffer16+k)=color;
+ }
+ buffer += screen->pitch;
+ }
+ }
+
+ SDL_UnlockSurface(screen);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+}
+
+/* Create a "light" -- a yellowish surface with variable alpha */
+SDL_Surface *CreateLight(int radius)
+{
+ Uint8 trans, alphamask;
+ int range, addition;
+ int xdist, ydist;
+ Uint16 x, y;
+ Uint16 skip;
+ Uint32 pixel;
+ SDL_Surface *light;
+
+#ifdef LIGHT_16BIT
+ Uint16 *buf;
+
+ /* Create a 16 (4/4/4/4) bpp square with a full 4-bit alpha channel */
+ /* Note: this isn't any faster than a 32 bit alpha surface */
+ alphamask = 0x0000000F;
+ light = SDL_CreateRGBSurface(SDL_SWSURFACE, 2*radius, 2*radius, 16,
+ 0x0000F000, 0x00000F00, 0x000000F0, alphamask);
+#else
+ Uint32 *buf;
+
+ /* Create a 32 (8/8/8/8) bpp square with a full 8-bit alpha channel */
+ alphamask = 0x000000FF;
+ light = SDL_CreateRGBSurface(SDL_SWSURFACE, 2*radius, 2*radius, 32,
+ 0xFF000000, 0x00FF0000, 0x0000FF00, alphamask);
+ if ( light == NULL ) {
+ fprintf(stderr, "Couldn't create light: %s\n", SDL_GetError());
+ return(NULL);
+ }
+#endif
+
+ /* Fill with a light yellow-orange color */
+ skip = light->pitch-(light->w*light->format->BytesPerPixel);
+#ifdef LIGHT_16BIT
+ buf = (Uint16 *)light->pixels;
+#else
+ buf = (Uint32 *)light->pixels;
+#endif
+ /* Get a tranparent pixel value - we'll add alpha later */
+ pixel = SDL_MapRGBA(light->format, 0xFF, 0xDD, 0x88, 0);
+ for ( y=0; y<light->h; ++y ) {
+ for ( x=0; x<light->w; ++x ) {
+ *buf++ = pixel;
+ }
+ buf += skip; /* Almost always 0, but just in case... */
+ }
+
+ /* Calculate alpha values for the surface. */
+#ifdef LIGHT_16BIT
+ buf = (Uint16 *)light->pixels;
+#else
+ buf = (Uint32 *)light->pixels;
+#endif
+ for ( y=0; y<light->h; ++y ) {
+ for ( x=0; x<light->w; ++x ) {
+ /* Slow distance formula (from center of light) */
+ xdist = x-(light->w/2);
+ ydist = y-(light->h/2);
+ range = (int)sqrt(xdist*xdist+ydist*ydist);
+
+ /* Scale distance to range of transparency (0-255) */
+ if ( range > radius ) {
+ trans = alphamask;
+ } else {
+ /* Increasing transparency with distance */
+ trans = (Uint8)((range*alphamask)/radius);
+
+ /* Lights are very transparent */
+ addition = (alphamask+1)/8;
+ if ( (int)trans+addition > alphamask ) {
+ trans = alphamask;
+ } else {
+ trans += addition;
+ }
+ }
+ /* We set the alpha component as the right N bits */
+ *buf++ |= (255-trans);
+ }
+ buf += skip; /* Almost always 0, but just in case... */
+ }
+ /* Enable RLE acceleration of this alpha surface */
+ SDL_SetAlpha(light, SDL_SRCALPHA|SDL_RLEACCEL, 0);
+
+ /* We're done! */
+ return(light);
+}
+
+static Uint32 flashes = 0;
+static Uint32 flashtime = 0;
+
+void FlashLight(SDL_Surface *screen, SDL_Surface *light, int x, int y)
+{
+ SDL_Rect position;
+ Uint32 ticks1;
+ Uint32 ticks2;
+
+ /* Easy, center light */
+ position.x = x-(light->w/2);
+ position.y = y-(light->h/2);
+ position.w = light->w;
+ position.h = light->h;
+ ticks1 = SDL_GetTicks();
+ SDL_BlitSurface(light, NULL, screen, &position);
+ ticks2 = SDL_GetTicks();
+ SDL_UpdateRects(screen, 1, &position);
+ ++flashes;
+
+ /* Update time spend doing alpha blitting */
+ flashtime += (ticks2-ticks1);
+}
+
+static int sprite_visible = 0;
+static SDL_Surface *sprite;
+static SDL_Surface *backing;
+static SDL_Rect position;
+static int x_vel, y_vel;
+static int alpha_vel;
+
+int LoadSprite(SDL_Surface *screen, char *file)
+{
+ SDL_Surface *converted;
+
+ /* Load the sprite image */
+ sprite = SDL_LoadBMP(file);
+ if ( sprite == NULL ) {
+ fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
+ return(-1);
+ }
+
+ /* Set transparent pixel as the pixel at (0,0) */
+ if ( sprite->format->palette ) {
+ SDL_SetColorKey(sprite, SDL_SRCCOLORKEY,
+ *(Uint8 *)sprite->pixels);
+ }
+
+ /* Convert sprite to video format */
+ converted = SDL_DisplayFormat(sprite);
+ SDL_FreeSurface(sprite);
+ if ( converted == NULL ) {
+ fprintf(stderr, "Couldn't convert background: %s\n",
+ SDL_GetError());
+ return(-1);
+ }
+ sprite = converted;
+
+ /* Create the background */
+ backing = SDL_CreateRGBSurface(SDL_SWSURFACE, sprite->w, sprite->h, 8,
+ 0, 0, 0, 0);
+ if ( backing == NULL ) {
+ fprintf(stderr, "Couldn't create background: %s\n",
+ SDL_GetError());
+ SDL_FreeSurface(sprite);
+ return(-1);
+ }
+
+ /* Convert background to video format */
+ converted = SDL_DisplayFormat(backing);
+ SDL_FreeSurface(backing);
+ if ( converted == NULL ) {
+ fprintf(stderr, "Couldn't convert background: %s\n",
+ SDL_GetError());
+ SDL_FreeSurface(sprite);
+ return(-1);
+ }
+ backing = converted;
+
+ /* Set the initial position of the sprite */
+ position.x = (screen->w-sprite->w)/2;
+ position.y = (screen->h-sprite->h)/2;
+ position.w = sprite->w;
+ position.h = sprite->h;
+ x_vel = 0; y_vel = 0;
+ alpha_vel = 1;
+
+ /* We're ready to roll. :) */
+ return(0);
+}
+
+void AttractSprite(Uint16 x, Uint16 y)
+{
+ x_vel = ((int)x-position.x)/10;
+ y_vel = ((int)y-position.y)/10;
+}
+
+void MoveSprite(SDL_Surface *screen, SDL_Surface *light)
+{
+ SDL_Rect updates[2];
+ int alpha;
+
+ /* Erase the sprite if it was visible */
+ if ( sprite_visible ) {
+ updates[0] = position;
+ SDL_BlitSurface(backing, NULL, screen, &updates[0]);
+ } else {
+ updates[0].x = 0; updates[0].y = 0;
+ updates[0].w = 0; updates[0].h = 0;
+ sprite_visible = 1;
+ }
+
+ /* Since the sprite is off the screen, we can do other drawing
+ without being overwritten by the saved area behind the sprite.
+ */
+ if ( light != NULL ) {
+ int x, y;
+
+ SDL_GetMouseState(&x, &y);
+ FlashLight(screen, light, x, y);
+ }
+
+ /* Move the sprite, bounce at the wall */
+ position.x += x_vel;
+ if ( (position.x < 0) || (position.x >= screen->w) ) {
+ x_vel = -x_vel;
+ position.x += x_vel;
+ }
+ position.y += y_vel;
+ if ( (position.y < 0) || (position.y >= screen->h) ) {
+ y_vel = -y_vel;
+ position.y += y_vel;
+ }
+
+ /* Update transparency (fade in and out) */
+ alpha = sprite->format->alpha;
+ if ( (alpha+alpha_vel) < 0 ) {
+ alpha_vel = -alpha_vel;
+ } else
+ if ( (alpha+alpha_vel) > 255 ) {
+ alpha_vel = -alpha_vel;
+ }
+ SDL_SetAlpha(sprite, SDL_SRCALPHA, (Uint8)(alpha+alpha_vel));
+
+ /* Save the area behind the sprite */
+ updates[1] = position;
+ SDL_BlitSurface(screen, &updates[1], backing, NULL);
+
+ /* Blit the sprite onto the screen */
+ updates[1] = position;
+ SDL_BlitSurface(sprite, NULL, screen, &updates[1]);
+
+ /* Make it so! */
+ SDL_UpdateRects(screen, 2, updates);
+}
+
+void WarpSprite(SDL_Surface *screen, int x, int y)
+{
+ SDL_Rect updates[2];
+
+ /* Erase, move, Draw, update */
+ updates[0] = position;
+ SDL_BlitSurface(backing, NULL, screen, &updates[0]);
+ position.x = x-sprite->w/2; /* Center about X */
+ position.y = y-sprite->h/2; /* Center about Y */
+ updates[1] = position;
+ SDL_BlitSurface(screen, &updates[1], backing, NULL);
+ updates[1] = position;
+ SDL_BlitSurface(sprite, NULL, screen, &updates[1]);
+ SDL_UpdateRects(screen, 2, updates);
+}
+
+int main(int argc, char *argv[])
+{
+ const SDL_VideoInfo *info;
+ SDL_Surface *screen;
+ int w, h;
+ Uint8 video_bpp;
+ Uint32 videoflags;
+ int i, done;
+ SDL_Event event;
+ SDL_Surface *light;
+ int mouse_pressed;
+ Uint32 ticks, lastticks;
+
+
+ /* Initialize SDL */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ /* Alpha blending doesn't work well at 8-bit color */
+#ifdef _WIN32_WCE
+ /* Pocket PC */
+ w = 240;
+ h = 320;
+#else
+ w = 640;
+ h = 480;
+#endif
+ info = SDL_GetVideoInfo();
+ if ( info->vfmt->BitsPerPixel > 8 ) {
+ video_bpp = info->vfmt->BitsPerPixel;
+ } else {
+ video_bpp = 16;
+ fprintf(stderr, "forced 16 bpp mode\n");
+ }
+ videoflags = SDL_SWSURFACE;
+ for ( i = 1; argv[i]; ++i ) {
+ if ( strcmp(argv[i], "-bpp") == 0 ) {
+ video_bpp = atoi(argv[++i]);
+ if (video_bpp<=8) {
+ video_bpp=16;
+ fprintf(stderr, "forced 16 bpp mode\n");
+ }
+ } else
+ if ( strcmp(argv[i], "-hw") == 0 ) {
+ videoflags |= SDL_HWSURFACE;
+ } else
+ if ( strcmp(argv[i], "-warp") == 0 ) {
+ videoflags |= SDL_HWPALETTE;
+ } else
+ if ( strcmp(argv[i], "-width") == 0 && argv[i+1] ) {
+ w = atoi(argv[++i]);
+ } else
+ if ( strcmp(argv[i], "-height") == 0 && argv[i+1] ) {
+ h = atoi(argv[++i]);
+ } else
+ if ( strcmp(argv[i], "-resize") == 0 ) {
+ videoflags |= SDL_RESIZABLE;
+ } else
+ if ( strcmp(argv[i], "-noframe") == 0 ) {
+ videoflags |= SDL_NOFRAME;
+ } else
+ if ( strcmp(argv[i], "-fullscreen") == 0 ) {
+ videoflags |= SDL_FULLSCREEN;
+ } else {
+ fprintf(stderr,
+ "Usage: %s [-width N] [-height N] [-bpp N] [-warp] [-hw] [-fullscreen]\n",
+ argv[0]);
+ quit(1);
+ }
+ }
+
+ /* Set video mode */
+ if ( (screen=SDL_SetVideoMode(w,h,video_bpp,videoflags)) == NULL ) {
+ fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
+ w, h, video_bpp, SDL_GetError());
+ quit(2);
+ }
+ FillBackground(screen);
+
+ /* Create the light */
+ light = CreateLight(82);
+ if ( light == NULL ) {
+ quit(1);
+ }
+
+ /* Load the sprite */
+ if ( LoadSprite(screen, "icon.bmp") < 0 ) {
+ SDL_FreeSurface(light);
+ quit(1);
+ }
+
+ /* Print out information about our surfaces */
+ printf("Screen is at %d bits per pixel\n",screen->format->BitsPerPixel);
+ if ( (screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
+ printf("Screen is in video memory\n");
+ } else {
+ printf("Screen is in system memory\n");
+ }
+ if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
+ printf("Screen has double-buffering enabled\n");
+ }
+ if ( (sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
+ printf("Sprite is in video memory\n");
+ } else {
+ printf("Sprite is in system memory\n");
+ }
+
+ /* Run a sample blit to trigger blit acceleration */
+ MoveSprite(screen, NULL);
+ if ( (sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
+ printf("Sprite blit uses hardware alpha acceleration\n");
+ } else {
+ printf("Sprite blit dosn't uses hardware alpha acceleration\n");
+ }
+
+ /* Set a clipping rectangle to clip the outside edge of the screen */
+ { SDL_Rect clip;
+ clip.x = 32;
+ clip.y = 32;
+ clip.w = screen->w-(2*32);
+ clip.h = screen->h-(2*32);
+ SDL_SetClipRect(screen, &clip);
+ }
+
+ /* Wait for a keystroke */
+ lastticks = SDL_GetTicks();
+ done = 0;
+ mouse_pressed = 0;
+ while ( !done ) {
+ /* Update the frame -- move the sprite */
+ if ( mouse_pressed ) {
+ MoveSprite(screen, light);
+ mouse_pressed = 0;
+ } else {
+ MoveSprite(screen, NULL);
+ }
+
+ /* Slow down the loop to 30 frames/second */
+ ticks = SDL_GetTicks();
+ if ( (ticks-lastticks) < FRAME_TICKS ) {
+#ifdef CHECK_SLEEP_GRANULARITY
+fprintf(stderr, "Sleeping %d ticks\n", FRAME_TICKS-(ticks-lastticks));
+#endif
+ SDL_Delay(FRAME_TICKS-(ticks-lastticks));
+#ifdef CHECK_SLEEP_GRANULARITY
+fprintf(stderr, "Slept %d ticks\n", (SDL_GetTicks()-ticks));
+#endif
+ }
+ lastticks = ticks;
+
+ /* Check for events */
+ while ( SDL_PollEvent(&event) ) {
+ switch (event.type) {
+ case SDL_VIDEORESIZE:
+ screen = SDL_SetVideoMode(event.resize.w, event.resize.h, video_bpp, videoflags);
+ if ( screen ) {
+ FillBackground(screen);
+ }
+ break;
+ /* Attract sprite while mouse is held down */
+ case SDL_MOUSEMOTION:
+ if (event.motion.state != 0) {
+ AttractSprite(event.motion.x,
+ event.motion.y);
+ mouse_pressed = 1;
+ }
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ if ( event.button.button == 1 ) {
+ AttractSprite(event.button.x,
+ event.button.y);
+ mouse_pressed = 1;
+ } else {
+ SDL_Rect area;
+
+ area.x = event.button.x-16;
+ area.y = event.button.y-16;
+ area.w = 32;
+ area.h = 32;
+ SDL_FillRect(screen, &area, 0);
+ SDL_UpdateRects(screen,1,&area);
+ }
+ break;
+ case SDL_KEYDOWN:
+#ifdef _WIN32_WCE
+ // there is no ESC key at all
+ done = 1;
+#else
+ if ( event.key.keysym.sym == SDLK_ESCAPE ) {
+ done = 1;
+ } else if (event.key.keysym.sym == SDLK_t) {
+ videoflags ^= SDL_FULLSCREEN;
+ screen = SDL_SetVideoMode(w, h, video_bpp, videoflags);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't toggle video mode: %s\n",
+ SDL_GetError());
+ quit(2);
+ }
+ FillBackground(screen);
+ }
+#endif
+
+ break;
+ case SDL_QUIT:
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ SDL_FreeSurface(light);
+ SDL_FreeSurface(sprite);
+ SDL_FreeSurface(backing);
+
+ /* Print out some timing information */
+ if ( flashes > 0 ) {
+ printf("%d alpha blits, ~%4.4f ms per blit\n",
+ flashes, (float)flashtime/flashes);
+ }
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testbitmap.c b/distrib/sdl-1.2.15/test/testbitmap.c
new file mode 100644
index 0000000..50cfcbb
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testbitmap.c
@@ -0,0 +1,184 @@
+
+/* Simple program: Test bitmap blits */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+#include "picture.xbm"
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+SDL_Surface *LoadXBM(SDL_Surface *screen, int w, int h, Uint8 *bits)
+{
+ SDL_Surface *bitmap;
+ Uint8 *line;
+
+ /* Allocate the bitmap */
+ bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 1, 0, 0, 0, 0);
+ if ( bitmap == NULL ) {
+ fprintf(stderr, "Couldn't allocate bitmap: %s\n",
+ SDL_GetError());
+ return(NULL);
+ }
+
+ /* Copy the pixels */
+ line = (Uint8 *)bitmap->pixels;
+ w = (w+7)/8;
+ while ( h-- ) {
+ memcpy(line, bits, w);
+ /* X11 Bitmap images have the bits reversed */
+ { int i, j; Uint8 *buf, byte;
+ for ( buf=line, i=0; i<w; ++i, ++buf ) {
+ byte = *buf;
+ *buf = 0;
+ for ( j=7; j>=0; --j ) {
+ *buf |= (byte&0x01)<<j;
+ byte >>= 1;
+ }
+ }
+ }
+ line += bitmap->pitch;
+ bits += w;
+ }
+ return(bitmap);
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Surface *screen;
+ SDL_Surface *bitmap;
+ Uint8 video_bpp;
+ Uint32 videoflags;
+ Uint8 *buffer;
+ int i, k, done;
+ SDL_Event event;
+ Uint16 *buffer16;
+ Uint16 color;
+ Uint8 gradient;
+ SDL_Color palette[256];
+
+
+ /* Initialize SDL */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ video_bpp = 0;
+ videoflags = SDL_SWSURFACE;
+ while ( argc > 1 ) {
+ --argc;
+ if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
+ video_bpp = atoi(argv[argc]);
+ --argc;
+ } else
+ if ( strcmp(argv[argc], "-warp") == 0 ) {
+ videoflags |= SDL_HWPALETTE;
+ } else
+ if ( strcmp(argv[argc], "-hw") == 0 ) {
+ videoflags |= SDL_HWSURFACE;
+ } else
+ if ( strcmp(argv[argc], "-fullscreen") == 0 ) {
+ videoflags |= SDL_FULLSCREEN;
+ } else {
+ fprintf(stderr,
+ "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n",
+ argv[0]);
+ quit(1);
+ }
+ }
+
+ /* Set 640x480 video mode */
+ if ( (screen=SDL_SetVideoMode(640,480,video_bpp,videoflags)) == NULL ) {
+ fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
+ video_bpp, SDL_GetError());
+ quit(2);
+ }
+
+ if (video_bpp==8) {
+ /* Set a gray colormap, reverse order from white to black */
+ for ( i=0; i<256; ++i ) {
+ palette[i].r = 255-i;
+ palette[i].g = 255-i;
+ palette[i].b = 255-i;
+ }
+ SDL_SetColors(screen, palette, 0, 256);
+ }
+
+ /* Set the surface pixels and refresh! */
+ if ( SDL_LockSurface(screen) < 0 ) {
+ fprintf(stderr, "Couldn't lock the display surface: %s\n",
+ SDL_GetError());
+ quit(2);
+ }
+ buffer=(Uint8 *)screen->pixels;
+ if (screen->format->BytesPerPixel!=2) {
+ for ( i=0; i<screen->h; ++i ) {
+ memset(buffer,(i*255)/screen->h, screen->pitch);
+ buffer += screen->pitch;
+ }
+ }
+ else
+ {
+ for ( i=0; i<screen->h; ++i ) {
+ gradient=((i*255)/screen->h);
+ color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
+ buffer16=(Uint16*)buffer;
+ for (k=0; k<screen->w; k++)
+ {
+ *(buffer16+k)=color;
+ }
+ buffer += screen->pitch;
+ }
+ }
+ SDL_UnlockSurface(screen);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+ /* Load the bitmap */
+ bitmap = LoadXBM(screen, picture_width, picture_height,
+ (Uint8 *)picture_bits);
+ if ( bitmap == NULL ) {
+ quit(1);
+ }
+
+ /* Wait for a keystroke */
+ done = 0;
+ while ( !done ) {
+ /* Check for events */
+ while ( SDL_PollEvent(&event) ) {
+ switch (event.type) {
+ case SDL_MOUSEBUTTONDOWN: {
+ SDL_Rect dst;
+
+ dst.x = event.button.x - bitmap->w/2;
+ dst.y = event.button.y - bitmap->h/2;
+ dst.w = bitmap->w;
+ dst.h = bitmap->h;
+ SDL_BlitSurface(bitmap, NULL,
+ screen, &dst);
+ SDL_UpdateRects(screen,1,&dst);
+ }
+ break;
+ case SDL_KEYDOWN:
+ /* Any key press quits the app... */
+ done = 1;
+ break;
+ case SDL_QUIT:
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ SDL_FreeSurface(bitmap);
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testblitspeed.c b/distrib/sdl-1.2.15/test/testblitspeed.c
new file mode 100644
index 0000000..f5dff6b
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testblitspeed.c
@@ -0,0 +1,420 @@
+/*
+ * Benchmarks surface-to-surface blits in various formats.
+ *
+ * Written by Ryan C. Gordon.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+
+static SDL_Surface *dest = NULL;
+static SDL_Surface *src = NULL;
+static int testSeconds = 10;
+
+
+static int percent(int val, int total)
+{
+ return((int) ((((float) val) / ((float) total)) * 100.0f));
+}
+
+static int randRange(int lo, int hi)
+{
+ return(lo + (int) (((double) hi)*rand()/(RAND_MAX+1.0)));
+}
+
+static void copy_trunc_str(char *str, size_t strsize, const char *flagstr)
+{
+ if ( (strlen(str) + strlen(flagstr)) >= (strsize - 1) )
+ strcpy(str + (strsize - 5), " ...");
+ else
+ strcat(str, flagstr);
+}
+
+static void __append_sdl_surface_flag(SDL_Surface *_surface, char *str,
+ size_t strsize, Uint32 flag,
+ const char *flagstr)
+{
+ if (_surface->flags & flag)
+ copy_trunc_str(str, strsize, flagstr);
+}
+
+
+#define append_sdl_surface_flag(a, b, c, fl) __append_sdl_surface_flag(a, b, c, fl, " " #fl)
+#define print_tf_state(str, val) printf("%s: {%s}\n", str, (val) ? "true" : "false" )
+
+static void output_videoinfo_details(void)
+{
+ const SDL_VideoInfo *info = SDL_GetVideoInfo();
+ printf("SDL_GetVideoInfo():\n");
+ if (info == NULL)
+ printf(" (null.)\n");
+ else
+ {
+ print_tf_state(" hardware surface available", info->hw_available);
+ print_tf_state(" window manager available", info->wm_available);
+ print_tf_state(" accelerated hardware->hardware blits", info->blit_hw);
+ print_tf_state(" accelerated hardware->hardware colorkey blits", info->blit_hw_CC);
+ print_tf_state(" accelerated hardware->hardware alpha blits", info->blit_hw_A);
+ print_tf_state(" accelerated software->hardware blits", info->blit_sw);
+ print_tf_state(" accelerated software->hardware colorkey blits", info->blit_sw_CC);
+ print_tf_state(" accelerated software->hardware alpha blits", info->blit_sw_A);
+ print_tf_state(" accelerated color fills", info->blit_fill);
+ printf(" video memory: (%d)\n", info->video_mem);
+ }
+
+ printf("\n");
+}
+
+static void output_surface_details(const char *name, SDL_Surface *surface)
+{
+ printf("Details for %s:\n", name);
+
+ if (surface == NULL)
+ {
+ printf("-WARNING- You've got a NULL surface!");
+ }
+ else
+ {
+ char f[256];
+ printf(" width : %d\n", surface->w);
+ printf(" height : %d\n", surface->h);
+ printf(" depth : %d bits per pixel\n", surface->format->BitsPerPixel);
+ printf(" pitch : %d\n", (int) surface->pitch);
+ printf(" alpha : %d\n", (int) surface->format->alpha);
+ printf(" colorkey : 0x%X\n", (unsigned int) surface->format->colorkey);
+
+ printf(" red bits : 0x%08X mask, %d shift, %d loss\n",
+ (int) surface->format->Rmask,
+ (int) surface->format->Rshift,
+ (int) surface->format->Rloss);
+ printf(" green bits : 0x%08X mask, %d shift, %d loss\n",
+ (int) surface->format->Gmask,
+ (int) surface->format->Gshift,
+ (int) surface->format->Gloss);
+ printf(" blue bits : 0x%08X mask, %d shift, %d loss\n",
+ (int) surface->format->Bmask,
+ (int) surface->format->Bshift,
+ (int) surface->format->Bloss);
+ printf(" alpha bits : 0x%08X mask, %d shift, %d loss\n",
+ (int) surface->format->Amask,
+ (int) surface->format->Ashift,
+ (int) surface->format->Aloss);
+
+ f[0] = '\0';
+
+ /*append_sdl_surface_flag(surface, f, sizeof (f), SDL_SWSURFACE);*/
+ if ((surface->flags & SDL_HWSURFACE) == 0)
+ copy_trunc_str(f, sizeof (f), " SDL_SWSURFACE");
+
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWSURFACE);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_ASYNCBLIT);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_ANYFORMAT);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWPALETTE);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_DOUBLEBUF);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_FULLSCREEN);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_OPENGL);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_OPENGLBLIT);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_RESIZABLE);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_NOFRAME);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWACCEL);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_SRCCOLORKEY);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_RLEACCELOK);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_RLEACCEL);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_SRCALPHA);
+ append_sdl_surface_flag(surface, f, sizeof (f), SDL_PREALLOC);
+
+ if (f[0] == '\0')
+ strcpy(f, " (none)");
+
+ printf(" flags :%s\n", f);
+ }
+
+ printf("\n");
+}
+
+static void output_details(void)
+{
+ output_videoinfo_details();
+ output_surface_details("Source Surface", src);
+ output_surface_details("Destination Surface", dest);
+}
+
+static Uint32 blit(SDL_Surface *dst, SDL_Surface *src, int x, int y)
+{
+ Uint32 start = 0;
+ SDL_Rect srcRect;
+ SDL_Rect dstRect;
+
+ srcRect.x = 0;
+ srcRect.y = 0;
+ dstRect.x = x;
+ dstRect.y = y;
+ dstRect.w = srcRect.w = src->w; /* SDL will clip as appropriate. */
+ dstRect.h = srcRect.h = src->h;
+
+ start = SDL_GetTicks();
+ SDL_BlitSurface(src, &srcRect, dst, &dstRect);
+ return(SDL_GetTicks() - start);
+}
+
+static void blitCentered(SDL_Surface *dst, SDL_Surface *src)
+{
+ int x = (dst->w - src->w) / 2;
+ int y = (dst->h - src->h) / 2;
+ blit(dst, src, x, y);
+}
+
+static int atoi_hex(const char *str)
+{
+ if (str == NULL)
+ return 0;
+
+ if (strlen(str) > 2)
+ {
+ int retval = 0;
+ if ((str[0] == '0') && (str[1] == 'x'))
+ sscanf(str + 2, "%X", &retval);
+ return(retval);
+ }
+
+ return(atoi(str));
+}
+
+
+static int setup_test(int argc, char **argv)
+{
+ const char *dumpfile = NULL;
+ SDL_Surface *bmp = NULL;
+ Uint32 dstbpp = 32;
+ Uint32 dstrmask = 0x00FF0000;
+ Uint32 dstgmask = 0x0000FF00;
+ Uint32 dstbmask = 0x000000FF;
+ Uint32 dstamask = 0x00000000;
+ Uint32 dstflags = 0;
+ int dstw = 640;
+ int dsth = 480;
+ Uint32 srcbpp = 32;
+ Uint32 srcrmask = 0x00FF0000;
+ Uint32 srcgmask = 0x0000FF00;
+ Uint32 srcbmask = 0x000000FF;
+ Uint32 srcamask = 0x00000000;
+ Uint32 srcflags = 0;
+ int srcw = 640;
+ int srch = 480;
+ Uint32 origsrcalphaflags = 0;
+ Uint32 origdstalphaflags = 0;
+ Uint32 srcalphaflags = 0;
+ Uint32 dstalphaflags = 0;
+ int srcalpha = 255;
+ int dstalpha = 255;
+ int screenSurface = 0;
+ int i = 0;
+
+ for (i = 1; i < argc; i++)
+ {
+ const char *arg = argv[i];
+
+ if (strcmp(arg, "--dstbpp") == 0)
+ dstbpp = atoi(argv[++i]);
+ else if (strcmp(arg, "--dstrmask") == 0)
+ dstrmask = atoi_hex(argv[++i]);
+ else if (strcmp(arg, "--dstgmask") == 0)
+ dstgmask = atoi_hex(argv[++i]);
+ else if (strcmp(arg, "--dstbmask") == 0)
+ dstbmask = atoi_hex(argv[++i]);
+ else if (strcmp(arg, "--dstamask") == 0)
+ dstamask = atoi_hex(argv[++i]);
+ else if (strcmp(arg, "--dstwidth") == 0)
+ dstw = atoi(argv[++i]);
+ else if (strcmp(arg, "--dstheight") == 0)
+ dsth = atoi(argv[++i]);
+ else if (strcmp(arg, "--dsthwsurface") == 0)
+ dstflags |= SDL_HWSURFACE;
+ else if (strcmp(arg, "--srcbpp") == 0)
+ srcbpp = atoi(argv[++i]);
+ else if (strcmp(arg, "--srcrmask") == 0)
+ srcrmask = atoi_hex(argv[++i]);
+ else if (strcmp(arg, "--srcgmask") == 0)
+ srcgmask = atoi_hex(argv[++i]);
+ else if (strcmp(arg, "--srcbmask") == 0)
+ srcbmask = atoi_hex(argv[++i]);
+ else if (strcmp(arg, "--srcamask") == 0)
+ srcamask = atoi_hex(argv[++i]);
+ else if (strcmp(arg, "--srcwidth") == 0)
+ srcw = atoi(argv[++i]);
+ else if (strcmp(arg, "--srcheight") == 0)
+ srch = atoi(argv[++i]);
+ else if (strcmp(arg, "--srchwsurface") == 0)
+ srcflags |= SDL_HWSURFACE;
+ else if (strcmp(arg, "--seconds") == 0)
+ testSeconds = atoi(argv[++i]);
+ else if (strcmp(arg, "--screen") == 0)
+ screenSurface = 1;
+ else if (strcmp(arg, "--dumpfile") == 0)
+ dumpfile = argv[++i];
+ /* !!! FIXME: set colorkey. */
+ else if (0) /* !!! FIXME: we handle some commandlines elsewhere now */
+ {
+ fprintf(stderr, "Unknown commandline option: %s\n", arg);
+ return(0);
+ }
+ }
+
+ if (SDL_Init(SDL_INIT_VIDEO) == -1)
+ {
+ fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
+ return(0);
+ }
+
+ bmp = SDL_LoadBMP("sample.bmp");
+ if (bmp == NULL)
+ {
+ fprintf(stderr, "SDL_LoadBMP failed: %s\n", SDL_GetError());
+ SDL_Quit();
+ return(0);
+ }
+
+ if ((dstflags & SDL_HWSURFACE) == 0) dstflags |= SDL_SWSURFACE;
+ if ((srcflags & SDL_HWSURFACE) == 0) srcflags |= SDL_SWSURFACE;
+
+ if (screenSurface)
+ dest = SDL_SetVideoMode(dstw, dsth, dstbpp, dstflags);
+ else
+ {
+ dest = SDL_CreateRGBSurface(dstflags, dstw, dsth, dstbpp,
+ dstrmask, dstgmask, dstbmask, dstamask);
+ }
+
+ if (dest == NULL)
+ {
+ fprintf(stderr, "dest surface creation failed: %s\n", SDL_GetError());
+ SDL_Quit();
+ return(0);
+ }
+
+ src = SDL_CreateRGBSurface(srcflags, srcw, srch, srcbpp,
+ srcrmask, srcgmask, srcbmask, srcamask);
+ if (src == NULL)
+ {
+ fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError());
+ SDL_Quit();
+ return(0);
+ }
+
+ /* handle alpha settings... */
+ srcalphaflags = (src->flags&SDL_SRCALPHA) | (src->flags&SDL_RLEACCEL);
+ dstalphaflags = (dest->flags&SDL_SRCALPHA) | (dest->flags&SDL_RLEACCEL);
+ origsrcalphaflags = srcalphaflags;
+ origdstalphaflags = dstalphaflags;
+ srcalpha = src->format->alpha;
+ dstalpha = dest->format->alpha;
+ for (i = 1; i < argc; i++)
+ {
+ const char *arg = argv[i];
+
+ if (strcmp(arg, "--srcalpha") == 0)
+ srcalpha = atoi(argv[++i]);
+ else if (strcmp(arg, "--dstalpha") == 0)
+ dstalpha = atoi(argv[++i]);
+ else if (strcmp(arg, "--srcsrcalpha") == 0)
+ srcalphaflags |= SDL_SRCALPHA;
+ else if (strcmp(arg, "--srcnosrcalpha") == 0)
+ srcalphaflags &= ~SDL_SRCALPHA;
+ else if (strcmp(arg, "--srcrleaccel") == 0)
+ srcalphaflags |= SDL_RLEACCEL;
+ else if (strcmp(arg, "--srcnorleaccel") == 0)
+ srcalphaflags &= ~SDL_RLEACCEL;
+ else if (strcmp(arg, "--dstsrcalpha") == 0)
+ dstalphaflags |= SDL_SRCALPHA;
+ else if (strcmp(arg, "--dstnosrcalpha") == 0)
+ dstalphaflags &= ~SDL_SRCALPHA;
+ else if (strcmp(arg, "--dstrleaccel") == 0)
+ dstalphaflags |= SDL_RLEACCEL;
+ else if (strcmp(arg, "--dstnorleaccel") == 0)
+ dstalphaflags &= ~SDL_RLEACCEL;
+ }
+ if ((dstalphaflags != origdstalphaflags) || (dstalpha != dest->format->alpha))
+ SDL_SetAlpha(dest, dstalphaflags, (Uint8) dstalpha);
+ if ((srcalphaflags != origsrcalphaflags) || (srcalpha != src->format->alpha))
+ SDL_SetAlpha(src, srcalphaflags, (Uint8) srcalpha);
+
+ /* set some sane defaults so we can see if the blit code is broken... */
+ SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0));
+ SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0));
+
+ blitCentered(src, bmp);
+ SDL_FreeSurface(bmp);
+
+ if (dumpfile)
+ SDL_SaveBMP(src, dumpfile); /* make sure initial convert is sane. */
+
+ output_details();
+
+ return(1);
+}
+
+
+static void test_blit_speed(void)
+{
+ Uint32 clearColor = SDL_MapRGB(dest->format, 0, 0, 0);
+ Uint32 iterations = 0;
+ Uint32 elasped = 0;
+ Uint32 end = 0;
+ Uint32 now = 0;
+ Uint32 last = 0;
+ int testms = testSeconds * 1000;
+ int wmax = (dest->w - src->w);
+ int hmax = (dest->h - src->h);
+ int isScreen = (SDL_GetVideoSurface() == dest);
+ SDL_Event event;
+
+ printf("Testing blit speed for %d seconds...\n", testSeconds);
+
+ now = SDL_GetTicks();
+ end = now + testms;
+
+ do
+ {
+ /* pump the event queue occasionally to keep OS happy... */
+ if (now - last > 1000)
+ {
+ last = now;
+ while (SDL_PollEvent(&event)) { /* no-op. */ }
+ }
+
+ iterations++;
+ elasped += blit(dest, src, randRange(0, wmax), randRange(0, hmax));
+ if (isScreen)
+ {
+ SDL_Flip(dest); /* show it! */
+ SDL_FillRect(dest, NULL, clearColor); /* blank it for next time! */
+ }
+
+ now = SDL_GetTicks();
+ } while (now < end);
+
+ printf("Non-blitting crap accounted for %d percent of this run.\n",
+ percent(testms - elasped, testms));
+
+ printf("%d blits took %d ms (%d fps).\n",
+ (int) iterations,
+ (int) elasped,
+ (int) (((float)iterations) / (((float)elasped) / 1000.0f)));
+}
+
+int main(int argc, char **argv)
+{
+ int initialized = setup_test(argc, argv);
+ if (initialized)
+ {
+ test_blit_speed();
+ SDL_Quit();
+ }
+ return(!initialized);
+}
+
+/* end of testblitspeed.c ... */
+
diff --git a/distrib/sdl-1.2.15/test/testcdrom.c b/distrib/sdl-1.2.15/test/testcdrom.c
new file mode 100644
index 0000000..782a66c
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testcdrom.c
@@ -0,0 +1,209 @@
+
+/* Test the SDL CD-ROM audio functions */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "SDL.h"
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+static void PrintStatus(int driveindex, SDL_CD *cdrom)
+{
+ CDstatus status;
+ char *status_str;
+
+ status = SDL_CDStatus(cdrom);
+ switch (status) {
+ case CD_TRAYEMPTY:
+ status_str = "tray empty";
+ break;
+ case CD_STOPPED:
+ status_str = "stopped";
+ break;
+ case CD_PLAYING:
+ status_str = "playing";
+ break;
+ case CD_PAUSED:
+ status_str = "paused";
+ break;
+ case CD_ERROR:
+ status_str = "error state";
+ break;
+ }
+ printf("Drive %d status: %s\n", driveindex, status_str);
+ if ( status >= CD_PLAYING ) {
+ int m, s, f;
+ FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f);
+ printf("Currently playing track %d, %d:%2.2d\n",
+ cdrom->track[cdrom->cur_track].id, m, s);
+ }
+}
+
+static void ListTracks(SDL_CD *cdrom)
+{
+ int i;
+ int m, s, f;
+ char* trtype;
+
+ SDL_CDStatus(cdrom);
+ printf("Drive tracks: %d\n", cdrom->numtracks);
+ for ( i=0; i<cdrom->numtracks; ++i ) {
+ FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f);
+ if ( f > 0 )
+ ++s;
+ switch(cdrom->track[i].type)
+ {
+ case SDL_AUDIO_TRACK:
+ trtype="audio";
+ break;
+ case SDL_DATA_TRACK:
+ trtype="data";
+ break;
+ default:
+ trtype="unknown";
+ break;
+ }
+ printf("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i,
+ cdrom->track[i].id, m, s, cdrom->track[i].length, trtype);
+ }
+}
+
+static void PrintUsage(char *argv0)
+{
+ fprintf(stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0);
+ fprintf(stderr, "Where 'command' is one of:\n");
+ fprintf(stderr, " -status\n");
+ fprintf(stderr, " -list\n");
+ fprintf(stderr, " -play [first_track] [first_frame] [num_tracks] [num_frames]\n");
+ fprintf(stderr, " -pause\n");
+ fprintf(stderr, " -resume\n");
+ fprintf(stderr, " -stop\n");
+ fprintf(stderr, " -eject\n");
+ fprintf(stderr, " -sleep <milliseconds>\n");
+}
+
+int main(int argc, char *argv[])
+{
+ int drive;
+ int i;
+ SDL_CD *cdrom;
+
+ /* Initialize SDL first */
+ if ( SDL_Init(SDL_INIT_CDROM) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ /* Find out how many CD-ROM drives are connected to the system */
+ if ( SDL_CDNumDrives() == 0 ) {
+ printf("No CD-ROM devices detected\n");
+ quit(0);
+ }
+ printf("Drives available: %d\n", SDL_CDNumDrives());
+ for ( i=0; i<SDL_CDNumDrives(); ++i ) {
+ printf("Drive %d: \"%s\"\n", i, SDL_CDName(i));
+ }
+
+ /* Open the CD-ROM */
+ drive = 0;
+ i=1;
+ if ( argv[i] && isdigit(argv[i][0]) ) {
+ drive = atoi(argv[i++]);
+ }
+ cdrom = SDL_CDOpen(drive);
+ if ( cdrom == NULL ) {
+ fprintf(stderr, "Couldn't open drive %d: %s\n", drive,
+ SDL_GetError());
+ quit(2);
+ }
+#ifdef TEST_NULLCD
+ cdrom = NULL;
+#endif
+
+ /* Find out which function to perform */
+ for ( ; argv[i]; ++i ) {
+ if ( strcmp(argv[i], "-status") == 0 ) {
+ /* PrintStatus(drive, cdrom); */
+ } else
+ if ( strcmp(argv[i], "-list") == 0 ) {
+ ListTracks(cdrom);
+ } else
+ if ( strcmp(argv[i], "-play") == 0 ) {
+ int strack, sframe;
+ int ntrack, nframe;
+
+ strack = 0;
+ if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
+ strack = atoi(argv[++i]);
+ }
+ sframe = 0;
+ if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
+ sframe = atoi(argv[++i]);
+ }
+ ntrack = 0;
+ if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
+ ntrack = atoi(argv[++i]);
+ }
+ nframe = 0;
+ if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
+ nframe = atoi(argv[++i]);
+ }
+ if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
+ if ( SDL_CDPlayTracks(cdrom, strack, sframe,
+ ntrack, nframe) < 0 ) {
+ fprintf(stderr,
+ "Couldn't play tracks %d/%d for %d/%d: %s\n",
+ strack, sframe, ntrack, nframe, SDL_GetError());
+ }
+ } else {
+ fprintf(stderr, "No CD in drive!\n");
+ }
+ } else
+ if ( strcmp(argv[i], "-pause") == 0 ) {
+ if ( SDL_CDPause(cdrom) < 0 ) {
+ fprintf(stderr, "Couldn't pause CD: %s\n",
+ SDL_GetError());
+ }
+ } else
+ if ( strcmp(argv[i], "-resume") == 0 ) {
+ if ( SDL_CDResume(cdrom) < 0 ) {
+ fprintf(stderr, "Couldn't resume CD: %s\n",
+ SDL_GetError());
+ }
+ } else
+ if ( strcmp(argv[i], "-stop") == 0 ) {
+ if ( SDL_CDStop(cdrom) < 0 ) {
+ fprintf(stderr, "Couldn't eject CD: %s\n",
+ SDL_GetError());
+ }
+ } else
+ if ( strcmp(argv[i], "-eject") == 0 ) {
+ if ( SDL_CDEject(cdrom) < 0 ) {
+ fprintf(stderr, "Couldn't eject CD: %s\n",
+ SDL_GetError());
+ }
+ } else
+ if ( (strcmp(argv[i], "-sleep") == 0) &&
+ (argv[i+1] && isdigit(argv[i+1][0])) ) {
+ SDL_Delay(atoi(argv[++i]));
+ printf("Delayed %d milliseconds\n", atoi(argv[i]));
+ } else {
+ PrintUsage(argv[0]);
+ SDL_CDClose(cdrom);
+ quit(1);
+ }
+ }
+ PrintStatus(drive, cdrom);
+ SDL_CDClose(cdrom);
+ SDL_Quit();
+
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testcursor.c b/distrib/sdl-1.2.15/test/testcursor.c
new file mode 100644
index 0000000..010e0a6
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testcursor.c
@@ -0,0 +1,216 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "SDL.h"
+
+/* This is an example 16x16 cursor
+ top left : black
+ top right : inverted color or black
+ bottom left: white
+ bottom right: transparent
+ (swap left and right for different endianness)
+*/
+
+Uint16 cursor_data[16]={
+ 0xffff,
+ 0xffff,
+ 0xffff,
+ 0xffff,
+
+ 0xffff,
+ 0xffff,
+ 0xffff,
+ 0xffff,
+
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0000
+};
+
+Uint16 cursor_mask[16]={
+ 0xff00,
+ 0xff00,
+ 0xff00,
+ 0xff00,
+
+ 0xff00,
+ 0xff00,
+ 0xff00,
+ 0xff00,
+
+ 0xff00,
+ 0xff00,
+ 0xff00,
+ 0xff00,
+
+ 0xff00,
+ 0xff00,
+ 0xff00,
+ 0xff00
+};
+
+/* another test cursor: smaller than 16x16, and with an odd height */
+
+Uint8 small_cursor_data[11] = { 0x00, 0x18, 0x08, 0x38, 0x44, 0x54, 0x44, 0x38, 0x20, 0x20, 0x00 };
+Uint8 small_cursor_mask[11] = { 0x3C, 0x3C, 0x3C, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x78, 0x70, 0x70 };
+
+/* XPM */
+static const char *arrow[] = {
+ /* width height num_colors chars_per_pixel */
+ " 32 32 3 1",
+ /* colors */
+ "X c #000000",
+ ". c #ffffff",
+ " c None",
+ /* pixels */
+ "X ",
+ "XX ",
+ "X.X ",
+ "X..X ",
+ "X...X ",
+ "X....X ",
+ "X.....X ",
+ "X......X ",
+ "X.......X ",
+ "X........X ",
+ "X.....XXXXX ",
+ "X..X..X ",
+ "X.X X..X ",
+ "XX X..X ",
+ "X X..X ",
+ " X..X ",
+ " X..X ",
+ " X..X ",
+ " XX ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ "0,0"
+};
+
+static SDL_Cursor *create_arrow_cursor()
+{
+ int i, row, col;
+ Uint8 data[4*32];
+ Uint8 mask[4*32];
+ int hot_x, hot_y;
+
+ i = -1;
+ for ( row=0; row<32; ++row ) {
+ for ( col=0; col<32; ++col ) {
+ if ( col % 8 ) {
+ data[i] <<= 1;
+ mask[i] <<= 1;
+ } else {
+ ++i;
+ data[i] = mask[i] = 0;
+ }
+ switch (arrow[4+row][col]) {
+ case 'X':
+ data[i] |= 0x01;
+ mask[i] |= 0x01;
+ break;
+ case '.':
+ mask[i] |= 0x01;
+ break;
+ case ' ':
+ break;
+ }
+ }
+ }
+ sscanf(arrow[4+row], "%d,%d", &hot_x, &hot_y);
+ return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
+}
+
+
+int main(int argc, char *argv[])
+{
+ SDL_Surface *screen;
+ SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
+ SDL_Cursor *cursor[3];
+ int current;
+
+ /* Load the SDL library */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT);
+ if (screen==NULL) {
+ fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ SDL_FillRect(screen, NULL, 0x664422);
+
+ cursor[0] = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask,
+ 16, 16, 8, 8);
+ if (cursor[0]==NULL) {
+ fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError());
+ SDL_Quit();
+ return(1);
+ }
+ cursor[1] = create_arrow_cursor();
+ if (cursor[1]==NULL) {
+ fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",SDL_GetError());
+ SDL_FreeCursor(cursor[0]);
+ SDL_Quit();
+ return(1);
+ }
+ cursor[2] = SDL_CreateCursor(small_cursor_data, small_cursor_mask,
+ 8, 11, 3, 5);
+ if (cursor[2]==NULL) {
+ fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError());
+ SDL_Quit();
+ return(1);
+ }
+
+ current = 0;
+ SDL_SetCursor(cursor[current]);
+
+ while (!quit) {
+ SDL_Event event;
+ while (SDL_PollEvent(&event)) {
+ switch(event.type) {
+ case SDL_MOUSEBUTTONDOWN:
+ current = (current + 1)%3;
+ SDL_SetCursor(cursor[current]);
+ break;
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ quit = SDL_TRUE;
+ }
+ break;
+ case SDL_QUIT:
+ quit = SDL_TRUE;
+ break;
+ }
+ }
+ SDL_Flip(screen);
+ SDL_Delay(1);
+ }
+
+ SDL_FreeCursor(cursor[0]);
+ SDL_FreeCursor(cursor[1]);
+ SDL_FreeCursor(cursor[2]);
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testdyngl.c b/distrib/sdl-1.2.15/test/testdyngl.c
new file mode 100644
index 0000000..a20bd1a
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testdyngl.c
@@ -0,0 +1,209 @@
+/*
+ * Small SDL example to demonstrate dynamically loading
+ * OpenGL lib and functions
+ *
+ * (FYI it was supposed to look like snow in the wind or something...)
+ *
+ * Compile with :
+ * gcc testdyngl.c `sdl-config --libs --cflags` -o testdyngl -DHAVE_OPENGL
+ *
+ * You can specify a different OpenGL lib on the command line, i.e. :
+ * ./testdyngl /usr/X11R6/lib/libGL.so.1.2
+ * or
+ * ./testdyngl /usr/lib/libGL.so.1.0.4496
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "SDL.h"
+
+#ifdef __MACOS__
+#define HAVE_OPENGL
+#endif
+
+#ifdef HAVE_OPENGL
+
+#include "SDL_opengl.h"
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+void* get_funcaddr(const char* p)
+{
+ void* f=SDL_GL_GetProcAddress(p);
+ if (f)
+ {
+ return f;
+ }
+ else
+ {
+ printf("Unable to get function pointer for %s\n",p);
+ quit(1);
+ }
+ return NULL;
+}
+
+typedef struct
+{
+ void(APIENTRY*glBegin)(GLenum);
+ void(APIENTRY*glEnd)();
+ void(APIENTRY*glVertex3f)(GLfloat, GLfloat, GLfloat);
+ void(APIENTRY*glClearColor)(GLfloat, GLfloat, GLfloat, GLfloat);
+ void(APIENTRY*glClear)(GLbitfield);
+ void(APIENTRY*glDisable)(GLenum);
+ void(APIENTRY*glEnable)(GLenum);
+ void(APIENTRY*glColor4ub)(GLubyte,GLubyte,GLubyte,GLubyte);
+ void(APIENTRY*glPointSize)(GLfloat);
+ void(APIENTRY*glHint)(GLenum,GLenum);
+ void(APIENTRY*glBlendFunc)(GLenum,GLenum);
+ void(APIENTRY*glMatrixMode)(GLenum);
+ void(APIENTRY*glLoadIdentity)();
+ void(APIENTRY*glOrtho)(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble);
+ void(APIENTRY*glRotatef)(GLfloat,GLfloat,GLfloat,GLfloat);
+ void(APIENTRY*glViewport)(GLint,GLint,GLsizei,GLsizei);
+ void(APIENTRY*glFogf)(GLenum,GLfloat);
+}
+glfuncs;
+
+void init_glfuncs(glfuncs* f)
+{
+ f->glBegin=get_funcaddr("glBegin");
+ f->glEnd=get_funcaddr("glEnd");
+ f->glVertex3f=get_funcaddr("glVertex3f");
+ f->glClearColor=get_funcaddr("glClearColor");
+ f->glClear=get_funcaddr("glClear");
+ f->glDisable=get_funcaddr("glDisable");
+ f->glEnable=get_funcaddr("glEnable");
+ f->glColor4ub=get_funcaddr("glColor4ub");
+ f->glPointSize=get_funcaddr("glPointSize");
+ f->glHint=get_funcaddr("glHint");
+ f->glBlendFunc=get_funcaddr("glBlendFunc");
+ f->glMatrixMode=get_funcaddr("glMatrixMode");
+ f->glLoadIdentity=get_funcaddr("glLoadIdentity");
+ f->glOrtho=get_funcaddr("glOrtho");
+ f->glRotatef=get_funcaddr("glRotatef");
+ f->glViewport=get_funcaddr("glViewport");
+ f->glFogf=get_funcaddr("glFogf");
+}
+
+#define NB_PIXELS 1000
+
+int main(int argc,char *argv[])
+{
+ glfuncs f;
+ int i;
+ SDL_Event event;
+ int done=0;
+ GLfloat pixels[NB_PIXELS*3];
+ const char *gl_library = NULL; /* Use the default GL library */
+
+ if (argv[1]) {
+ gl_library = argv[1];
+ }
+
+ if (SDL_Init(SDL_INIT_VIDEO)<0)
+ {
+ printf("Unable to init SDL : %s\n",SDL_GetError());
+ return(1);
+ }
+
+ if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1)<0)
+ {
+ printf("Unable to set GL attribute : %s\n",SDL_GetError());
+ quit(1);
+ }
+
+ if (SDL_GL_LoadLibrary(gl_library)<0)
+ {
+ printf("Unable to dynamically open GL lib : %s\n",SDL_GetError());
+ quit(1);
+ }
+
+ if (SDL_SetVideoMode(640,480,0,SDL_OPENGL)==NULL)
+ {
+ printf("Unable to open video mode : %s\n",SDL_GetError());
+ quit(1);
+ }
+
+ /* Set the window manager title bar */
+ SDL_WM_SetCaption( "SDL Dynamic OpenGL Loading Test", "testdyngl" );
+
+ init_glfuncs(&f);
+
+ for(i=0;i<NB_PIXELS;i++)
+ {
+ pixels[3*i]=rand()%250-125;
+ pixels[3*i+1]=rand()%250-125;
+ pixels[3*i+2]=rand()%250-125;
+ }
+
+ f.glViewport(0,0,640,480);
+
+ f.glMatrixMode(GL_PROJECTION);
+ f.glLoadIdentity();
+ f.glOrtho(-100,100,-100,100,-500,500);
+
+ f.glMatrixMode(GL_MODELVIEW);
+ f.glLoadIdentity();
+
+ f.glEnable(GL_DEPTH_TEST);
+ f.glDisable(GL_TEXTURE_2D);
+ f.glEnable(GL_BLEND);
+ f.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ f.glClearColor(0.0f,0.0f,0.0f,0.0f);
+ f.glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+
+ f.glEnable(GL_POINT_SMOOTH);
+ f.glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
+ f.glPointSize(5.0f);
+ f.glEnable(GL_FOG);
+ f.glFogf(GL_FOG_START,-500);
+ f.glFogf(GL_FOG_END,500);
+ f.glFogf(GL_FOG_DENSITY,0.005);
+
+ do
+ {
+ f.glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+
+ f.glRotatef(2.0,1.0,1.0,1.0);
+ f.glRotatef(1.0,0.0,1.0,1.0);
+
+ f.glColor4ub(255,255,255,255);
+ f.glBegin(GL_POINTS);
+ for(i=0;i<NB_PIXELS;i++)
+ {
+ f.glVertex3f(pixels[3*i],pixels[3*i+1],pixels[3*i+2]);
+ }
+ f.glEnd();
+ SDL_GL_SwapBuffers();
+
+ while(SDL_PollEvent(&event))
+ {
+ if(event.type & SDL_KEYDOWN)
+ done=1;
+ }
+
+ SDL_Delay(20);
+ }
+ while(!done);
+
+ SDL_Quit();
+ return 0;
+}
+
+#else /* HAVE_OPENGL */
+
+int main(int argc, char *argv[])
+{
+ printf("No OpenGL support on this system\n");
+ return 1;
+}
+
+#endif /* HAVE_OPENGL */
diff --git a/distrib/sdl-1.2.15/test/testerror.c b/distrib/sdl-1.2.15/test/testerror.c
new file mode 100644
index 0000000..9211dfc
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testerror.c
@@ -0,0 +1,61 @@
+
+/* Simple test of the SDL threading code and error handling */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include "SDL.h"
+#include "SDL_thread.h"
+
+static int alive = 0;
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+int SDLCALL ThreadFunc(void *data)
+{
+ /* Set the child thread error string */
+ SDL_SetError("Thread %s (%d) had a problem: %s",
+ (char *)data, SDL_ThreadID(), "nevermind");
+ while ( alive ) {
+ printf("Thread '%s' is alive!\n", (char *)data);
+ SDL_Delay(1*1000);
+ }
+ printf("Child thread error string: %s\n", SDL_GetError());
+ return(0);
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Thread *thread;
+
+ /* Load the SDL library */
+ if ( SDL_Init(0) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ /* Set the error value for the main thread */
+ SDL_SetError("No worries");
+
+ alive = 1;
+ thread = SDL_CreateThread(ThreadFunc, "#1");
+ if ( thread == NULL ) {
+ fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
+ quit(1);
+ }
+ SDL_Delay(5*1000);
+ printf("Waiting for thread #1\n");
+ alive = 0;
+ SDL_WaitThread(thread, NULL);
+
+ printf("Main thread error string: %s\n", SDL_GetError());
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testfile.c b/distrib/sdl-1.2.15/test/testfile.c
new file mode 100644
index 0000000..ecebb7d
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testfile.c
@@ -0,0 +1,182 @@
+
+/* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
+
+#include <stdlib.h>
+
+#ifndef _MSC_VER
+#include <unistd.h>
+#endif
+
+#include "SDL.h"
+#include "SDL_endian.h"
+
+
+#include <stdio.h>
+
+/* WARNING ! those 2 files will be destroyed by this test program */
+#define FBASENAME1 "sdldata1" /* this file will be created during tests */
+#define FBASENAME2 "sdldata2" /* this file should not exists before starting test */
+
+
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+static void cleanup( void ) {
+
+ unlink(FBASENAME1);
+ unlink(FBASENAME2);
+}
+
+static void rwops_error_quit( unsigned line, SDL_RWops *rwops) {
+
+ printf("testfile.c(%d): failed\n",line);
+ if (rwops) {
+ rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
+ }
+ cleanup();
+ exit(1); /* quit with rwops error (test failed) */
+}
+
+#define RWOP_ERR_QUIT(x) rwops_error_quit( __LINE__, (x) )
+
+
+
+int main(int argc, char *argv[])
+{
+ SDL_RWops *rwops = NULL;
+ char test_buf[30];
+
+ cleanup();
+
+/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
+
+ rwops = SDL_RWFromFile(NULL,NULL);
+ if (rwops) RWOP_ERR_QUIT(rwops);
+ rwops = SDL_RWFromFile(NULL,"ab+");
+ if (rwops) RWOP_ERR_QUIT(rwops);
+ rwops = SDL_RWFromFile(NULL,"sldfkjsldkfj");
+ if (rwops) RWOP_ERR_QUIT(rwops);
+ rwops = SDL_RWFromFile("something","");
+ if (rwops) RWOP_ERR_QUIT(rwops);
+ rwops = SDL_RWFromFile("something",NULL);
+ if (rwops) RWOP_ERR_QUIT(rwops);
+ printf("test1 OK\n");
+
+/* test 2 : check that inexistant file is not successfully opened/created when required */
+/* modes : r, r+ implie that file MUST exist
+ modes : a, a+, w, w+ checks that it succeeds (file may not exists)
+
+ */
+ rwops = SDL_RWFromFile(FBASENAME2,"rb"); /* this file doesn't exist that call must fail */
+ if (rwops) RWOP_ERR_QUIT(rwops);
+ rwops = SDL_RWFromFile(FBASENAME2,"rb+"); /* this file doesn't exist that call must fail */
+ if (rwops) RWOP_ERR_QUIT(rwops);
+ rwops = SDL_RWFromFile(FBASENAME2,"wb");
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ rwops->close(rwops); unlink(FBASENAME2);
+ rwops = SDL_RWFromFile(FBASENAME2,"wb+");
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ rwops->close(rwops); unlink(FBASENAME2);
+ rwops = SDL_RWFromFile(FBASENAME2,"ab");
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ rwops->close(rwops); unlink(FBASENAME2);
+ rwops = SDL_RWFromFile(FBASENAME2,"ab+");
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ rwops->close(rwops); unlink(FBASENAME2);
+ printf("test2 OK\n");
+
+/* test 3 : creation, writing , reading, seeking,
+ test : w mode, r mode, w+ mode
+ */
+ rwops = SDL_RWFromFile(FBASENAME1,"wb"); /* write only */
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops);
+ if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops);
+ if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in write only mode */
+ rwops->close(rwops);
+
+ rwops = SDL_RWFromFile(FBASENAME1,"rb"); /* read mode, file must exists */
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+ if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops);
+ if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops);
+ if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops);
+ if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops);
+ if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->write(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* readonly mode */
+ rwops->close(rwops);
+
+/* test 3: same with w+ mode */
+ rwops = SDL_RWFromFile(FBASENAME1,"wb+"); /* write + read + truncation */
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops);
+ if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops);
+ if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+ if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+ if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops);
+ if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops);
+ if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops);
+ if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops);
+ if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops);
+ rwops->close(rwops);
+ printf("test3 OK\n");
+
+/* test 4: same in r+ mode */
+ rwops = SDL_RWFromFile(FBASENAME1,"rb+"); /* write + read + file must exists, no truncation */
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops);
+ if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops);
+ if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+ if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+ if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops);
+ if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops);
+ if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops);
+ if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops);
+ if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops);
+ rwops->close(rwops);
+ printf("test4 OK\n");
+
+/* test5 : append mode */
+ rwops = SDL_RWFromFile(FBASENAME1,"ab+"); /* write + read + append */
+ if (!rwops) RWOP_ERR_QUIT(rwops);
+ if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops);
+ if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops);
+ if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+
+ if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+
+ if (20+27!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops);
+ if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops);
+ if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops);
+ if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops);
+
+ if (27!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops);
+
+ if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops);
+ if (3!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops);
+ if (SDL_memcmp(test_buf,"123456789012345678901234567123",30))
+ RWOP_ERR_QUIT(rwops);
+ rwops->close(rwops);
+ printf("test5 OK\n");
+ cleanup();
+ return 0; /* all ok */
+}
diff --git a/distrib/sdl-1.2.15/test/testgamma.c b/distrib/sdl-1.2.15/test/testgamma.c
new file mode 100644
index 0000000..70f4b3c
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testgamma.c
@@ -0,0 +1,197 @@
+
+/* Bring up a window and manipulate the gamma on it */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include "SDL.h"
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+/* Turn a normal gamma value into an appropriate gamma ramp */
+void CalculateGamma(double gamma, Uint16 *ramp)
+{
+ int i, value;
+
+ gamma = 1.0 / gamma;
+ for ( i=0; i<256; ++i ) {
+ value = (int)(pow((double)i/256.0, gamma)*65535.0 + 0.5);
+ if ( value > 65535 ) {
+ value = 65535;
+ }
+ ramp[i] = (Uint16)value;
+ }
+}
+
+/* This can be used as a general routine for all of the test programs */
+int get_video_args(char *argv[], int *w, int *h, int *bpp, Uint32 *flags)
+{
+ int i;
+
+ *w = 640;
+ *h = 480;
+ *bpp = 0;
+ *flags = SDL_SWSURFACE;
+
+ for ( i=1; argv[i]; ++i ) {
+ if ( strcmp(argv[i], "-width") == 0 ) {
+ if ( argv[i+1] ) {
+ *w = atoi(argv[++i]);
+ }
+ } else
+ if ( strcmp(argv[i], "-height") == 0 ) {
+ if ( argv[i+1] ) {
+ *h = atoi(argv[++i]);
+ }
+ } else
+ if ( strcmp(argv[i], "-bpp") == 0 ) {
+ if ( argv[i+1] ) {
+ *bpp = atoi(argv[++i]);
+ }
+ } else
+ if ( strcmp(argv[i], "-fullscreen") == 0 ) {
+ *flags |= SDL_FULLSCREEN;
+ } else
+ if ( strcmp(argv[i], "-hw") == 0 ) {
+ *flags |= SDL_HWSURFACE;
+ } else
+ if ( strcmp(argv[i], "-hwpalette") == 0 ) {
+ *flags |= SDL_HWPALETTE;
+ } else
+ break;
+ }
+ return i;
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Surface *screen;
+ SDL_Surface *image;
+ float gamma;
+ int i;
+ int w, h, bpp;
+ Uint32 flags;
+ Uint16 ramp[256];
+ Uint16 red_ramp[256];
+ Uint32 then, timeout;
+
+ /* Check command line arguments */
+ argv += get_video_args(argv, &w, &h, &bpp, &flags);
+
+ /* Initialize SDL */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr,
+ "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return(1);
+ }
+
+ /* Initialize the display, always use hardware palette */
+ screen = SDL_SetVideoMode(w, h, bpp, flags | SDL_HWPALETTE);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
+ w, h, SDL_GetError());
+ quit(1);
+ }
+
+ /* Set the window manager title bar */
+ SDL_WM_SetCaption("SDL gamma test", "testgamma");
+
+ /* Set the desired gamma, if any */
+ gamma = 1.0f;
+ if ( *argv ) {
+ gamma = (float)atof(*argv);
+ }
+ if ( SDL_SetGamma(gamma, gamma, gamma) < 0 ) {
+ fprintf(stderr, "Unable to set gamma: %s\n", SDL_GetError());
+ quit(1);
+ }
+
+#if 0 /* This isn't supported. Integrating the gamma ramps isn't exact */
+ /* See what gamma was actually set */
+ float real[3];
+ if ( SDL_GetGamma(&real[0], &real[1], &real[2]) < 0 ) {
+ printf("Couldn't get gamma: %s\n", SDL_GetError());
+ } else {
+ printf("Set gamma values: R=%2.2f, G=%2.2f, B=%2.2f\n",
+ real[0], real[1], real[2]);
+ }
+#endif
+
+ /* Do all the drawing work */
+ image = SDL_LoadBMP("sample.bmp");
+ if ( image ) {
+ SDL_Rect dst;
+
+ dst.x = (screen->w - image->w)/2;
+ dst.y = (screen->h - image->h)/2;
+ dst.w = image->w;
+ dst.h = image->h;
+ SDL_BlitSurface(image, NULL, screen, &dst);
+ SDL_UpdateRects(screen, 1, &dst);
+ }
+
+ /* Wait a bit, handling events */
+ then = SDL_GetTicks();
+ timeout = (5*1000);
+ while ( (SDL_GetTicks()-then) < timeout ) {
+ SDL_Event event;
+
+ while ( SDL_PollEvent(&event) ) {
+ switch (event.type) {
+ case SDL_QUIT: /* Quit now */
+ timeout = 0;
+ break;
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym) {
+ case SDLK_SPACE: /* Go longer.. */
+ timeout += (5*1000);
+ break;
+ case SDLK_UP:
+ gamma += 0.2f;
+ SDL_SetGamma(gamma, gamma, gamma);
+ break;
+ case SDLK_DOWN:
+ gamma -= 0.2f;
+ SDL_SetGamma(gamma, gamma, gamma);
+ break;
+ case SDLK_ESCAPE:
+ timeout = 0;
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ }
+ }
+
+ /* Perform a gamma flash to red using color ramps */
+ while ( gamma < 10.0 ) {
+ /* Increase the red gamma and decrease everything else... */
+ gamma += 0.1f;
+ CalculateGamma(gamma, red_ramp);
+ CalculateGamma(1.0/gamma, ramp);
+ SDL_SetGammaRamp(red_ramp, ramp, ramp);
+ }
+ /* Finish completely red */
+ memset(red_ramp, 255, sizeof(red_ramp));
+ memset(ramp, 0, sizeof(ramp));
+ SDL_SetGammaRamp(red_ramp, ramp, ramp);
+
+ /* Now fade out to black */
+ for ( i=(red_ramp[0] >> 8); i >= 0; --i ) {
+ memset(red_ramp, i, sizeof(red_ramp));
+ SDL_SetGammaRamp(red_ramp, NULL, NULL);
+ }
+ SDL_Delay(1*1000);
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testgl.c b/distrib/sdl-1.2.15/test/testgl.c
new file mode 100644
index 0000000..34b88cf
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testgl.c
@@ -0,0 +1,856 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include "SDL.h"
+
+#ifdef __MACOS__
+#define HAVE_OPENGL
+#endif
+
+#ifdef HAVE_OPENGL
+
+#include "SDL_opengl.h"
+
+/* Undefine this if you want a flat cube instead of a rainbow cube */
+#define SHADED_CUBE
+
+/* Define this to be the name of the logo image to use with -logo */
+#define LOGO_FILE "icon.bmp"
+
+/* The SDL_OPENGLBLIT interface is deprecated.
+ The code is still available for benchmark purposes though.
+*/
+
+static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
+
+static SDL_Surface *global_image = NULL;
+static GLuint global_texture = 0;
+static GLuint cursor_texture = 0;
+
+/**********************************************************************/
+
+void HotKey_ToggleFullScreen(void)
+{
+ SDL_Surface *screen;
+
+ screen = SDL_GetVideoSurface();
+ if ( SDL_WM_ToggleFullScreen(screen) ) {
+ printf("Toggled fullscreen mode - now %s\n",
+ (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
+ } else {
+ printf("Unable to toggle fullscreen mode\n");
+ }
+}
+
+void HotKey_ToggleGrab(void)
+{
+ SDL_GrabMode mode;
+
+ printf("Ctrl-G: toggling input grab!\n");
+ mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
+ if ( mode == SDL_GRAB_ON ) {
+ printf("Grab was on\n");
+ } else {
+ printf("Grab was off\n");
+ }
+ mode = SDL_WM_GrabInput(!mode);
+ if ( mode == SDL_GRAB_ON ) {
+ printf("Grab is now on\n");
+ } else {
+ printf("Grab is now off\n");
+ }
+}
+
+void HotKey_Iconify(void)
+{
+ printf("Ctrl-Z: iconifying window!\n");
+ SDL_WM_IconifyWindow();
+}
+
+int HandleEvent(SDL_Event *event)
+{
+ int done;
+
+ done = 0;
+ switch( event->type ) {
+ case SDL_ACTIVEEVENT:
+ /* See what happened */
+ printf( "app %s ", event->active.gain ? "gained" : "lost" );
+ if ( event->active.state & SDL_APPACTIVE ) {
+ printf( "active " );
+ } else if ( event->active.state & SDL_APPMOUSEFOCUS ) {
+ printf( "mouse " );
+ } else if ( event->active.state & SDL_APPINPUTFOCUS ) {
+ printf( "input " );
+ }
+ printf( "focus\n" );
+ break;
+
+
+ case SDL_KEYDOWN:
+ if ( event->key.keysym.sym == SDLK_ESCAPE ) {
+ done = 1;
+ }
+ if ( (event->key.keysym.sym == SDLK_g) &&
+ (event->key.keysym.mod & KMOD_CTRL) ) {
+ HotKey_ToggleGrab();
+ }
+ if ( (event->key.keysym.sym == SDLK_z) &&
+ (event->key.keysym.mod & KMOD_CTRL) ) {
+ HotKey_Iconify();
+ }
+ if ( (event->key.keysym.sym == SDLK_RETURN) &&
+ (event->key.keysym.mod & KMOD_ALT) ) {
+ HotKey_ToggleFullScreen();
+ }
+ printf("key '%s' pressed\n",
+ SDL_GetKeyName(event->key.keysym.sym));
+ break;
+ case SDL_QUIT:
+ done = 1;
+ break;
+ }
+ return(done);
+}
+
+void SDL_GL_Enter2DMode()
+{
+ SDL_Surface *screen = SDL_GetVideoSurface();
+
+ /* Note, there may be other things you need to change,
+ depending on how you have your OpenGL state set up.
+ */
+ glPushAttrib(GL_ENABLE_BIT);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+ glEnable(GL_TEXTURE_2D);
+
+ /* This allows alpha blending of 2D textures with the scene */
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glViewport(0, 0, screen->w, screen->h);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
+}
+
+void SDL_GL_Leave2DMode()
+{
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+
+ glPopAttrib();
+}
+
+/* Quick utility function for texture creation */
+static int power_of_two(int input)
+{
+ int value = 1;
+
+ while ( value < input ) {
+ value <<= 1;
+ }
+ return value;
+}
+
+GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
+{
+ GLuint texture;
+ int w, h;
+ SDL_Surface *image;
+ SDL_Rect area;
+ Uint32 saved_flags;
+ Uint8 saved_alpha;
+
+ /* Use the surface width and height expanded to powers of 2 */
+ w = power_of_two(surface->w);
+ h = power_of_two(surface->h);
+ texcoord[0] = 0.0f; /* Min X */
+ texcoord[1] = 0.0f; /* Min Y */
+ texcoord[2] = (GLfloat)surface->w / w; /* Max X */
+ texcoord[3] = (GLfloat)surface->h / h; /* Max Y */
+
+ image = SDL_CreateRGBSurface(
+ SDL_SWSURFACE,
+ w, h,
+ 32,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
+ 0x000000FF,
+ 0x0000FF00,
+ 0x00FF0000,
+ 0xFF000000
+#else
+ 0xFF000000,
+ 0x00FF0000,
+ 0x0000FF00,
+ 0x000000FF
+#endif
+ );
+ if ( image == NULL ) {
+ return 0;
+ }
+
+ /* Save the alpha blending attributes */
+ saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+ saved_alpha = surface->format->alpha;
+ if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+ SDL_SetAlpha(surface, 0, 0);
+ }
+
+ /* Copy the surface into the GL texture image */
+ area.x = 0;
+ area.y = 0;
+ area.w = surface->w;
+ area.h = surface->h;
+ SDL_BlitSurface(surface, &area, image, &area);
+
+ /* Restore the alpha blending attributes */
+ if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+ SDL_SetAlpha(surface, saved_flags, saved_alpha);
+ }
+
+ /* Create an OpenGL texture for the image */
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D,
+ 0,
+ GL_RGBA,
+ w, h,
+ 0,
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ image->pixels);
+ SDL_FreeSurface(image); /* No longer needed */
+
+ return texture;
+}
+
+void DrawLogoCursor(void)
+{
+ static GLfloat texMinX, texMinY;
+ static GLfloat texMaxX, texMaxY;
+ static int w, h;
+ int x, y;
+
+ if ( ! cursor_texture ) {
+ SDL_Surface *image;
+ GLfloat texcoord[4];
+
+ /* Load the image (could use SDL_image library here) */
+ image = SDL_LoadBMP(LOGO_FILE);
+ if ( image == NULL ) {
+ return;
+ }
+ w = image->w;
+ h = image->h;
+
+ /* Convert the image into an OpenGL texture */
+ cursor_texture = SDL_GL_LoadTexture(image, texcoord);
+
+ /* Make texture coordinates easy to understand */
+ texMinX = texcoord[0];
+ texMinY = texcoord[1];
+ texMaxX = texcoord[2];
+ texMaxY = texcoord[3];
+
+ /* We don't need the original image anymore */
+ SDL_FreeSurface(image);
+
+ /* Make sure that the texture conversion is okay */
+ if ( ! cursor_texture ) {
+ return;
+ }
+ }
+
+ /* Move the image around */
+ SDL_GetMouseState(&x, &y);
+ x -= w/2;
+ y -= h/2;
+
+ /* Show the image on the screen */
+ SDL_GL_Enter2DMode();
+ glBindTexture(GL_TEXTURE_2D, cursor_texture);
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2f(texMinX, texMinY); glVertex2i(x, y );
+ glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y );
+ glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h);
+ glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
+ glEnd();
+ SDL_GL_Leave2DMode();
+}
+
+void DrawLogoTexture(void)
+{
+ static GLfloat texMinX, texMinY;
+ static GLfloat texMaxX, texMaxY;
+ static int x = 0;
+ static int y = 0;
+ static int w, h;
+ static int delta_x = 1;
+ static int delta_y = 1;
+
+ SDL_Surface *screen = SDL_GetVideoSurface();
+
+ if ( ! global_texture ) {
+ SDL_Surface *image;
+ GLfloat texcoord[4];
+
+ /* Load the image (could use SDL_image library here) */
+ image = SDL_LoadBMP(LOGO_FILE);
+ if ( image == NULL ) {
+ return;
+ }
+ w = image->w;
+ h = image->h;
+
+ /* Convert the image into an OpenGL texture */
+ global_texture = SDL_GL_LoadTexture(image, texcoord);
+
+ /* Make texture coordinates easy to understand */
+ texMinX = texcoord[0];
+ texMinY = texcoord[1];
+ texMaxX = texcoord[2];
+ texMaxY = texcoord[3];
+
+ /* We don't need the original image anymore */
+ SDL_FreeSurface(image);
+
+ /* Make sure that the texture conversion is okay */
+ if ( ! global_texture ) {
+ return;
+ }
+ }
+
+ /* Move the image around */
+ x += delta_x;
+ if ( x < 0 ) {
+ x = 0;
+ delta_x = -delta_x;
+ } else
+ if ( (x+w) > screen->w ) {
+ x = screen->w-w;
+ delta_x = -delta_x;
+ }
+ y += delta_y;
+ if ( y < 0 ) {
+ y = 0;
+ delta_y = -delta_y;
+ } else
+ if ( (y+h) > screen->h ) {
+ y = screen->h-h;
+ delta_y = -delta_y;
+ }
+
+ /* Show the image on the screen */
+ SDL_GL_Enter2DMode();
+ glBindTexture(GL_TEXTURE_2D, global_texture);
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2f(texMinX, texMinY); glVertex2i(x, y );
+ glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y );
+ glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h);
+ glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
+ glEnd();
+ SDL_GL_Leave2DMode();
+}
+
+/* This code is deprecated, but available for speed comparisons */
+void DrawLogoBlit(void)
+{
+ static int x = 0;
+ static int y = 0;
+ static int w, h;
+ static int delta_x = 1;
+ static int delta_y = 1;
+
+ SDL_Rect dst;
+ SDL_Surface *screen = SDL_GetVideoSurface();
+
+ if ( global_image == NULL ) {
+ SDL_Surface *temp;
+
+ /* Load the image (could use SDL_image library here) */
+ temp = SDL_LoadBMP(LOGO_FILE);
+ if ( temp == NULL ) {
+ return;
+ }
+ w = temp->w;
+ h = temp->h;
+
+ /* Convert the image into the screen format */
+ global_image = SDL_CreateRGBSurface(
+ SDL_SWSURFACE,
+ w, h,
+ screen->format->BitsPerPixel,
+ screen->format->Rmask,
+ screen->format->Gmask,
+ screen->format->Bmask,
+ screen->format->Amask);
+ if ( global_image ) {
+ SDL_BlitSurface(temp, NULL, global_image, NULL);
+ }
+ SDL_FreeSurface(temp);
+
+ /* Make sure that the texture conversion is okay */
+ if ( ! global_image ) {
+ return;
+ }
+ }
+
+ /* Move the image around
+ Note that we do not clear the old position. This is because we
+ perform a glClear() which clears the framebuffer and then only
+ update the new area.
+ Note that you can also achieve interesting effects by modifying
+ the screen surface alpha channel. It's set to 255 by default..
+ */
+ x += delta_x;
+ if ( x < 0 ) {
+ x = 0;
+ delta_x = -delta_x;
+ } else
+ if ( (x+w) > screen->w ) {
+ x = screen->w-w;
+ delta_x = -delta_x;
+ }
+ y += delta_y;
+ if ( y < 0 ) {
+ y = 0;
+ delta_y = -delta_y;
+ } else
+ if ( (y+h) > screen->h ) {
+ y = screen->h-h;
+ delta_y = -delta_y;
+ }
+ dst.x = x;
+ dst.y = y;
+ dst.w = w;
+ dst.h = h;
+ SDL_BlitSurface(global_image, NULL, screen, &dst);
+
+ /* Show the image on the screen */
+ SDL_UpdateRects(screen, 1, &dst);
+}
+
+int RunGLTest( int argc, char* argv[],
+ int logo, int logocursor, int slowly, int bpp, float gamma, int noframe, int fsaa, int sync, int accel )
+{
+ int i;
+ int rgb_size[3];
+ int w = 640;
+ int h = 480;
+ int done = 0;
+ int frames;
+ Uint32 start_time, this_time;
+ float color[8][3]= {{ 1.0, 1.0, 0.0},
+ { 1.0, 0.0, 0.0},
+ { 0.0, 0.0, 0.0},
+ { 0.0, 1.0, 0.0},
+ { 0.0, 1.0, 1.0},
+ { 1.0, 1.0, 1.0},
+ { 1.0, 0.0, 1.0},
+ { 0.0, 0.0, 1.0}};
+ float cube[8][3]= {{ 0.5, 0.5, -0.5},
+ { 0.5, -0.5, -0.5},
+ {-0.5, -0.5, -0.5},
+ {-0.5, 0.5, -0.5},
+ {-0.5, 0.5, 0.5},
+ { 0.5, 0.5, 0.5},
+ { 0.5, -0.5, 0.5},
+ {-0.5, -0.5, 0.5}};
+ Uint32 video_flags;
+ int value;
+
+ if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
+ fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
+ exit( 1 );
+ }
+
+ /* See if we should detect the display depth */
+ if ( bpp == 0 ) {
+ if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
+ bpp = 8;
+ } else {
+ bpp = 16; /* More doesn't seem to work */
+ }
+ }
+
+ /* Set the flags we want to use for setting the video mode */
+ if ( logo && USE_DEPRECATED_OPENGLBLIT ) {
+ video_flags = SDL_OPENGLBLIT;
+ } else {
+ video_flags = SDL_OPENGL;
+ }
+ for ( i=1; argv[i]; ++i ) {
+ if ( strcmp(argv[i], "-fullscreen") == 0 ) {
+ video_flags |= SDL_FULLSCREEN;
+ }
+ }
+
+ if (noframe) {
+ video_flags |= SDL_NOFRAME;
+ }
+
+ /* Initialize the display */
+ switch (bpp) {
+ case 8:
+ rgb_size[0] = 3;
+ rgb_size[1] = 3;
+ rgb_size[2] = 2;
+ break;
+ case 15:
+ case 16:
+ rgb_size[0] = 5;
+ rgb_size[1] = 5;
+ rgb_size[2] = 5;
+ break;
+ default:
+ rgb_size[0] = 8;
+ rgb_size[1] = 8;
+ rgb_size[2] = 8;
+ break;
+ }
+ SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
+ SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
+ SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
+ SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
+ SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
+ if ( fsaa ) {
+ SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
+ SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, fsaa );
+ }
+ if ( accel ) {
+ SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
+ }
+ if ( sync ) {
+ SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );
+ } else {
+ SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 );
+ }
+ if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
+ fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
+ SDL_Quit();
+ exit(1);
+ }
+
+ printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
+ printf("\n");
+ printf( "Vendor : %s\n", glGetString( GL_VENDOR ) );
+ printf( "Renderer : %s\n", glGetString( GL_RENDERER ) );
+ printf( "Version : %s\n", glGetString( GL_VERSION ) );
+ printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
+ printf("\n");
+
+ SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
+ printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
+ SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
+ printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
+ SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
+ printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
+ SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
+ printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
+ SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
+ printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
+ if ( fsaa ) {
+ SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value );
+ printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value );
+ SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value );
+ printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value );
+ }
+ if ( accel ) {
+ SDL_GL_GetAttribute( SDL_GL_ACCELERATED_VISUAL, &value );
+ printf( "SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value );
+ }
+ if ( sync ) {
+ SDL_GL_GetAttribute( SDL_GL_SWAP_CONTROL, &value );
+ printf( "SDL_GL_SWAP_CONTROL: requested 1, got %d\n", value );
+ }
+
+ /* Set the window manager title bar */
+ SDL_WM_SetCaption( "SDL GL test", "testgl" );
+
+ /* Set the gamma for the window */
+ if ( gamma != 0.0 ) {
+ SDL_SetGamma(gamma, gamma, gamma);
+ }
+
+ glViewport( 0, 0, w, h );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity( );
+
+ glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity( );
+
+ glEnable(GL_DEPTH_TEST);
+
+ glDepthFunc(GL_LESS);
+
+ glShadeModel(GL_SMOOTH);
+
+ /* Loop until done. */
+ start_time = SDL_GetTicks();
+ frames = 0;
+ while( !done ) {
+ GLenum gl_error;
+ char* sdl_error;
+ SDL_Event event;
+
+ /* Do our drawing, too. */
+ glClearColor( 0.0, 0.0, 0.0, 1.0 );
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glBegin( GL_QUADS );
+
+#ifdef SHADED_CUBE
+ glColor3fv(color[0]);
+ glVertex3fv(cube[0]);
+ glColor3fv(color[1]);
+ glVertex3fv(cube[1]);
+ glColor3fv(color[2]);
+ glVertex3fv(cube[2]);
+ glColor3fv(color[3]);
+ glVertex3fv(cube[3]);
+
+ glColor3fv(color[3]);
+ glVertex3fv(cube[3]);
+ glColor3fv(color[4]);
+ glVertex3fv(cube[4]);
+ glColor3fv(color[7]);
+ glVertex3fv(cube[7]);
+ glColor3fv(color[2]);
+ glVertex3fv(cube[2]);
+
+ glColor3fv(color[0]);
+ glVertex3fv(cube[0]);
+ glColor3fv(color[5]);
+ glVertex3fv(cube[5]);
+ glColor3fv(color[6]);
+ glVertex3fv(cube[6]);
+ glColor3fv(color[1]);
+ glVertex3fv(cube[1]);
+
+ glColor3fv(color[5]);
+ glVertex3fv(cube[5]);
+ glColor3fv(color[4]);
+ glVertex3fv(cube[4]);
+ glColor3fv(color[7]);
+ glVertex3fv(cube[7]);
+ glColor3fv(color[6]);
+ glVertex3fv(cube[6]);
+
+ glColor3fv(color[5]);
+ glVertex3fv(cube[5]);
+ glColor3fv(color[0]);
+ glVertex3fv(cube[0]);
+ glColor3fv(color[3]);
+ glVertex3fv(cube[3]);
+ glColor3fv(color[4]);
+ glVertex3fv(cube[4]);
+
+ glColor3fv(color[6]);
+ glVertex3fv(cube[6]);
+ glColor3fv(color[1]);
+ glVertex3fv(cube[1]);
+ glColor3fv(color[2]);
+ glVertex3fv(cube[2]);
+ glColor3fv(color[7]);
+ glVertex3fv(cube[7]);
+#else /* flat cube */
+ glColor3f(1.0, 0.0, 0.0);
+ glVertex3fv(cube[0]);
+ glVertex3fv(cube[1]);
+ glVertex3fv(cube[2]);
+ glVertex3fv(cube[3]);
+
+ glColor3f(0.0, 1.0, 0.0);
+ glVertex3fv(cube[3]);
+ glVertex3fv(cube[4]);
+ glVertex3fv(cube[7]);
+ glVertex3fv(cube[2]);
+
+ glColor3f(0.0, 0.0, 1.0);
+ glVertex3fv(cube[0]);
+ glVertex3fv(cube[5]);
+ glVertex3fv(cube[6]);
+ glVertex3fv(cube[1]);
+
+ glColor3f(0.0, 1.0, 1.0);
+ glVertex3fv(cube[5]);
+ glVertex3fv(cube[4]);
+ glVertex3fv(cube[7]);
+ glVertex3fv(cube[6]);
+
+ glColor3f(1.0, 1.0, 0.0);
+ glVertex3fv(cube[5]);
+ glVertex3fv(cube[0]);
+ glVertex3fv(cube[3]);
+ glVertex3fv(cube[4]);
+
+ glColor3f(1.0, 0.0, 1.0);
+ glVertex3fv(cube[6]);
+ glVertex3fv(cube[1]);
+ glVertex3fv(cube[2]);
+ glVertex3fv(cube[7]);
+#endif /* SHADED_CUBE */
+
+ glEnd( );
+
+ glMatrixMode(GL_MODELVIEW);
+ glRotatef(5.0, 1.0, 1.0, 1.0);
+
+ /* Draw 2D logo onto the 3D display */
+ if ( logo ) {
+ if ( USE_DEPRECATED_OPENGLBLIT ) {
+ DrawLogoBlit();
+ } else {
+ DrawLogoTexture();
+ }
+ }
+ if ( logocursor ) {
+ DrawLogoCursor();
+ }
+
+ SDL_GL_SwapBuffers( );
+
+ /* Check for error conditions. */
+ gl_error = glGetError( );
+
+ if( gl_error != GL_NO_ERROR ) {
+ fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error );
+ }
+
+ sdl_error = SDL_GetError( );
+
+ if( sdl_error[0] != '\0' ) {
+ fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
+ SDL_ClearError();
+ }
+
+ /* Allow the user to see what's happening */
+ if ( slowly ) {
+ SDL_Delay( 20 );
+ }
+
+ /* Check if there's a pending event. */
+ while( SDL_PollEvent( &event ) ) {
+ done = HandleEvent(&event);
+ }
+ ++frames;
+ }
+
+ /* Print out the frames per second */
+ this_time = SDL_GetTicks();
+ if ( this_time != start_time ) {
+ printf("%2.2f FPS\n",
+ ((float)frames/(this_time-start_time))*1000.0);
+ }
+
+ if ( global_image ) {
+ SDL_FreeSurface(global_image);
+ global_image = NULL;
+ }
+ if ( global_texture ) {
+ glDeleteTextures( 1, &global_texture );
+ global_texture = 0;
+ }
+ if ( cursor_texture ) {
+ glDeleteTextures( 1, &cursor_texture );
+ cursor_texture = 0;
+ }
+
+ /* Destroy our GL context, etc. */
+ SDL_Quit( );
+ return(0);
+}
+
+int main(int argc, char *argv[])
+{
+ int i, logo, logocursor = 0;
+ int numtests;
+ int bpp = 0;
+ int slowly;
+ float gamma = 0.0;
+ int noframe = 0;
+ int fsaa = 0;
+ int accel = 0;
+ int sync = 0;
+
+ logo = 0;
+ slowly = 0;
+ numtests = 1;
+ for ( i=1; argv[i]; ++i ) {
+ if ( strcmp(argv[i], "-twice") == 0 ) {
+ ++numtests;
+ }
+ if ( strcmp(argv[i], "-logo") == 0 ) {
+ logo = 1;
+ USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
+ }
+ if ( strcmp(argv[i], "-logoblit") == 0 ) {
+ logo = 1;
+ USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
+ }
+ if ( strcmp(argv[i], "-logocursor") == 0 ) {
+ logocursor = 1;
+ }
+ if ( strcmp(argv[i], "-slow") == 0 ) {
+ slowly = 1;
+ }
+ if ( strcmp(argv[i], "-bpp") == 0 ) {
+ bpp = atoi(argv[++i]);
+ }
+ if ( strcmp(argv[i], "-gamma") == 0 ) {
+ gamma = (float)atof(argv[++i]);
+ }
+ if ( strcmp(argv[i], "-noframe") == 0 ) {
+ noframe = 1;
+ }
+ if ( strcmp(argv[i], "-fsaa") == 0 ) {
+ ++fsaa;
+ }
+ if ( strcmp(argv[i], "-accel") == 0 ) {
+ ++accel;
+ }
+ if ( strcmp(argv[i], "-sync") == 0 ) {
+ ++sync;
+ }
+ if ( strncmp(argv[i], "-h", 2) == 0 ) {
+ printf(
+"Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-accel] [-sync] [-fullscreen]\n",
+ argv[0]);
+ exit(0);
+ }
+ }
+ for ( i=0; i<numtests; ++i ) {
+ RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, noframe, fsaa, sync, accel);
+ }
+ return 0;
+}
+
+#else /* HAVE_OPENGL */
+
+int main(int argc, char *argv[])
+{
+ printf("No OpenGL support on this system\n");
+ return 1;
+}
+
+#endif /* HAVE_OPENGL */
diff --git a/distrib/sdl-1.2.15/test/testhread.c b/distrib/sdl-1.2.15/test/testhread.c
new file mode 100644
index 0000000..f87f374
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testhread.c
@@ -0,0 +1,82 @@
+
+/* Simple test of the SDL threading code */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include "SDL.h"
+#include "SDL_thread.h"
+
+static int alive = 0;
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+int SDLCALL ThreadFunc(void *data)
+{
+ printf("Started thread %s: My thread id is %u\n",
+ (char *)data, SDL_ThreadID());
+ while ( alive ) {
+ printf("Thread '%s' is alive!\n", (char *)data);
+ SDL_Delay(1*1000);
+ }
+ printf("Thread '%s' exiting!\n", (char *)data);
+ return(0);
+}
+
+static void killed(int sig)
+{
+ printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
+ SDL_Delay(5*1000);
+ alive = 0;
+ quit(0);
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Thread *thread;
+
+ /* Load the SDL library */
+ if ( SDL_Init(0) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ alive = 1;
+ thread = SDL_CreateThread(ThreadFunc, "#1");
+ if ( thread == NULL ) {
+ fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
+ quit(1);
+ }
+ SDL_Delay(5*1000);
+ printf("Waiting for thread #1\n");
+ alive = 0;
+ SDL_WaitThread(thread, NULL);
+
+ alive = 1;
+ thread = SDL_CreateThread(ThreadFunc, "#2");
+ if ( thread == NULL ) {
+ fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
+ quit(1);
+ }
+ SDL_Delay(5*1000);
+ printf("Killing thread #2\n");
+ SDL_KillThread(thread);
+
+ alive = 1;
+ signal(SIGTERM, killed);
+ thread = SDL_CreateThread(ThreadFunc, "#3");
+ if ( thread == NULL ) {
+ fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
+ quit(1);
+ }
+ raise(SIGTERM);
+
+ SDL_Quit(); /* Never reached */
+ return(0); /* Never reached */
+}
diff --git a/distrib/sdl-1.2.15/test/testiconv.c b/distrib/sdl-1.2.15/test/testiconv.c
new file mode 100644
index 0000000..53415d0
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testiconv.c
@@ -0,0 +1,73 @@
+
+#include <stdio.h>
+
+#include "SDL.h"
+
+static size_t widelen(char *data)
+{
+ size_t len = 0;
+ Uint32 *p = (Uint32 *)data;
+ while(*p++) {
+ ++len;
+ }
+ return len;
+}
+
+int main(int argc, char *argv[])
+{
+ const char * formats[] = {
+ "UTF8",
+ "UTF-8",
+ "UTF16BE",
+ "UTF-16BE",
+ "UTF16LE",
+ "UTF-16LE",
+ "UTF32BE",
+ "UTF-32BE",
+ "UTF32LE",
+ "UTF-32LE",
+ "UCS4",
+ "UCS-4",
+ };
+ char buffer[BUFSIZ];
+ char *ucs4;
+ char *test[2];
+ int i, index = 0;
+ FILE *file;
+ int errors = 0;
+
+ if ( !argv[1] ) {
+ argv[1] = "utf8.txt";
+ }
+ file = fopen(argv[1], "rb");
+ if ( !file ) {
+ fprintf(stderr, "Unable to open %s\n", argv[1]);
+ return (1);
+ }
+
+ while ( fgets(buffer, sizeof(buffer), file) ) {
+ /* Convert to UCS-4 */
+ size_t len;
+ ucs4 = SDL_iconv_string("UCS-4", "UTF-8", buffer, SDL_strlen(buffer)+1);
+ len = (widelen(ucs4)+1)*4;
+ for ( i = 0; i < SDL_arraysize(formats); ++i ) {
+ test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
+ test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
+ if ( !test[1] || SDL_memcmp(test[1], ucs4, len) != 0 ) {
+ fprintf(stderr, "FAIL: %s\n", formats[i]);
+ ++errors;
+ }
+ if ( test[0] ) {
+ SDL_free(test[0]);
+ }
+ if ( test[1] ) {
+ SDL_free(test[1]);
+ }
+ }
+ test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
+ SDL_free(ucs4);
+ fputs(test[0], stdout);
+ SDL_free(test[0]);
+ }
+ return (errors ? errors + 1 : 0);
+}
diff --git a/distrib/sdl-1.2.15/test/testjoystick.c b/distrib/sdl-1.2.15/test/testjoystick.c
new file mode 100644
index 0000000..1cd8234
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testjoystick.c
@@ -0,0 +1,188 @@
+
+/* Simple program to test the SDL joystick routines */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+
+#define SCREEN_WIDTH 640
+#define SCREEN_HEIGHT 480
+
+void WatchJoystick(SDL_Joystick *joystick)
+{
+ SDL_Surface *screen;
+ const char *name;
+ int i, done;
+ SDL_Event event;
+ int x, y, draw;
+ SDL_Rect axis_area[2];
+
+ /* Set a video mode to display joystick axis position */
+ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't set video mode: %s\n",SDL_GetError());
+ return;
+ }
+
+ /* Print info about the joystick we are watching */
+ name = SDL_JoystickName(SDL_JoystickIndex(joystick));
+ printf("Watching joystick %d: (%s)\n", SDL_JoystickIndex(joystick),
+ name ? name : "Unknown Joystick");
+ printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
+ SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
+ SDL_JoystickNumBalls(joystick),SDL_JoystickNumButtons(joystick));
+
+ /* Initialize drawing rectangles */
+ memset(axis_area, 0, (sizeof axis_area));
+ draw = 0;
+
+ /* Loop, getting joystick events! */
+ done = 0;
+ while ( ! done ) {
+ while ( SDL_PollEvent(&event) ) {
+ switch (event.type) {
+ case SDL_JOYAXISMOTION:
+ printf("Joystick %d axis %d value: %d\n",
+ event.jaxis.which,
+ event.jaxis.axis,
+ event.jaxis.value);
+ break;
+ case SDL_JOYHATMOTION:
+ printf("Joystick %d hat %d value:",
+ event.jhat.which,
+ event.jhat.hat);
+ if ( event.jhat.value == SDL_HAT_CENTERED )
+ printf(" centered");
+ if ( event.jhat.value & SDL_HAT_UP )
+ printf(" up");
+ if ( event.jhat.value & SDL_HAT_RIGHT )
+ printf(" right");
+ if ( event.jhat.value & SDL_HAT_DOWN )
+ printf(" down");
+ if ( event.jhat.value & SDL_HAT_LEFT )
+ printf(" left");
+ printf("\n");
+ break;
+ case SDL_JOYBALLMOTION:
+ printf("Joystick %d ball %d delta: (%d,%d)\n",
+ event.jball.which,
+ event.jball.ball,
+ event.jball.xrel,
+ event.jball.yrel);
+ break;
+ case SDL_JOYBUTTONDOWN:
+ printf("Joystick %d button %d down\n",
+ event.jbutton.which,
+ event.jbutton.button);
+ break;
+ case SDL_JOYBUTTONUP:
+ printf("Joystick %d button %d up\n",
+ event.jbutton.which,
+ event.jbutton.button);
+ break;
+ case SDL_KEYDOWN:
+ if ( event.key.keysym.sym != SDLK_ESCAPE ) {
+ break;
+ }
+ /* Fall through to signal quit */
+ case SDL_QUIT:
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ /* Update visual joystick state */
+ for ( i=0; i<SDL_JoystickNumButtons(joystick); ++i ) {
+ SDL_Rect area;
+
+ area.x = i*34;
+ area.y = SCREEN_HEIGHT-34;
+ area.w = 32;
+ area.h = 32;
+ if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
+ SDL_FillRect(screen, &area, 0xFFFF);
+ } else {
+ SDL_FillRect(screen, &area, 0x0000);
+ }
+ SDL_UpdateRects(screen, 1, &area);
+ }
+
+ /* Erase previous axes */
+ SDL_FillRect(screen, &axis_area[draw], 0x0000);
+
+ /* Draw the X/Y axis */
+ draw = !draw;
+ x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768);
+ x *= SCREEN_WIDTH;
+ x /= 65535;
+ if ( x < 0 ) {
+ x = 0;
+ } else
+ if ( x > (SCREEN_WIDTH-16) ) {
+ x = SCREEN_WIDTH-16;
+ }
+ y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
+ y *= SCREEN_HEIGHT;
+ y /= 65535;
+ if ( y < 0 ) {
+ y = 0;
+ } else
+ if ( y > (SCREEN_HEIGHT-16) ) {
+ y = SCREEN_HEIGHT-16;
+ }
+ axis_area[draw].x = (Sint16)x;
+ axis_area[draw].y = (Sint16)y;
+ axis_area[draw].w = 16;
+ axis_area[draw].h = 16;
+ SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
+
+ SDL_UpdateRects(screen, 2, axis_area);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ const char *name;
+ int i;
+ SDL_Joystick *joystick;
+
+ /* Initialize SDL (Note: video is required to start event loop) */
+ if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ exit(1);
+ }
+
+ /* Print information about the joysticks */
+ printf("There are %d joysticks attached\n", SDL_NumJoysticks());
+ for ( i=0; i<SDL_NumJoysticks(); ++i ) {
+ name = SDL_JoystickName(i);
+ printf("Joystick %d: %s\n",i,name ? name : "Unknown Joystick");
+ joystick = SDL_JoystickOpen(i);
+ if (joystick == NULL) {
+ fprintf(stderr, "SDL_JoystickOpen(%d) failed: %s\n", i, SDL_GetError());
+ } else {
+ printf(" axes: %d\n", SDL_JoystickNumAxes(joystick));
+ printf(" balls: %d\n", SDL_JoystickNumBalls(joystick));
+ printf(" hats: %d\n", SDL_JoystickNumHats(joystick));
+ printf(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
+ SDL_JoystickClose(joystick);
+ }
+ }
+
+ if ( argv[1] ) {
+ joystick = SDL_JoystickOpen(atoi(argv[1]));
+ if ( joystick == NULL ) {
+ printf("Couldn't open joystick %d: %s\n", atoi(argv[1]),
+ SDL_GetError());
+ } else {
+ WatchJoystick(joystick);
+ SDL_JoystickClose(joystick);
+ }
+ }
+ SDL_QuitSubSystem(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK);
+
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testkeys.c b/distrib/sdl-1.2.15/test/testkeys.c
new file mode 100644
index 0000000..e320c6d
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testkeys.c
@@ -0,0 +1,25 @@
+
+/* Print out all the keysyms we have, just to verify them */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+
+int main(int argc, char *argv[])
+{
+ SDLKey key;
+
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",
+ SDL_GetError());
+ exit(1);
+ }
+ for ( key=SDLK_FIRST; key<SDLK_LAST; ++key ) {
+ printf("Key #%d, \"%s\"\n", key, SDL_GetKeyName(key));
+ }
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testloadso.c b/distrib/sdl-1.2.15/test/testloadso.c
new file mode 100644
index 0000000..39c14c6
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testloadso.c
@@ -0,0 +1,71 @@
+
+/* Test program to test dynamic loading with the loadso subsystem.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "SDL.h"
+
+typedef int (*fntype)(const char *);
+
+int main(int argc, char *argv[])
+{
+ int retval = 0;
+ int hello = 0;
+ const char *libname = NULL;
+ const char *symname = NULL;
+ void *lib = NULL;
+ fntype fn = NULL;
+
+ if (argc != 3) {
+ const char *app = argv[0];
+ fprintf(stderr, "USAGE: %s <library> <functionname>\n", app);
+ fprintf(stderr, " %s --hello <lib with puts()>\n", app);
+ return 1;
+ }
+
+ /* Initialize SDL */
+ if ( SDL_Init(0) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return 2;
+ }
+
+ if (strcmp(argv[1], "--hello") == 0) {
+ hello = 1;
+ libname = argv[2];
+ symname = "puts";
+ } else {
+ libname = argv[1];
+ symname = argv[2];
+ }
+
+ lib = SDL_LoadObject(libname);
+ if (lib == NULL) {
+ fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n",
+ libname, SDL_GetError());
+ retval = 3;
+ } else {
+ fn = (fntype) SDL_LoadFunction(lib, symname);
+ if (fn == NULL) {
+ fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n",
+ symname, SDL_GetError());
+ retval = 4;
+ } else {
+ printf("Found %s in %s at %p\n", symname, libname, fn);
+ if (hello) {
+ printf("Calling function...\n");
+ fflush(stdout);
+ fn(" HELLO, WORLD!\n");
+ printf("...apparently, we survived. :)\n");
+ printf("Unloading library...\n");
+ fflush(stdout);
+ }
+ }
+ SDL_UnloadObject(lib);
+ }
+ SDL_Quit();
+ return(0);
+}
+
+
diff --git a/distrib/sdl-1.2.15/test/testlock.c b/distrib/sdl-1.2.15/test/testlock.c
new file mode 100644
index 0000000..bda4b55
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testlock.c
@@ -0,0 +1,102 @@
+
+/* Test the thread and mutex locking functions
+ Also exercises the system's signal/thread interaction
+*/
+
+#include <signal.h>
+#include <stdio.h>
+
+#include "SDL.h"
+#include "SDL_mutex.h"
+#include "SDL_thread.h"
+
+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
+ * calling conventions may differ...
+ */
+static void SDL_Quit_Wrapper(void)
+{
+ SDL_Quit();
+}
+
+void printid(void)
+{
+ printf("Process %u: exiting\n", SDL_ThreadID());
+}
+
+void terminate(int sig)
+{
+ signal(SIGINT, terminate);
+ doterminate = 1;
+}
+void closemutex(int sig)
+{
+ Uint32 id = SDL_ThreadID();
+ int i;
+ printf("Process %u: Cleaning up...\n", id == mainthread ? 0 : id);
+ for ( i=0; i<6; ++i )
+ SDL_KillThread(threads[i]);
+ SDL_DestroyMutex(mutex);
+ exit(sig);
+}
+int SDLCALL Run(void *data)
+{
+ if ( SDL_ThreadID() == mainthread )
+ signal(SIGTERM, closemutex);
+ while ( 1 ) {
+ printf("Process %u ready to work\n", SDL_ThreadID());
+ if ( SDL_mutexP(mutex) < 0 ) {
+ fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
+ exit(1);
+ }
+ printf("Process %u, working!\n", SDL_ThreadID());
+ SDL_Delay(1*1000);
+ printf("Process %u, done!\n", SDL_ThreadID());
+ if ( SDL_mutexV(mutex) < 0 ) {
+ fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError());
+ exit(1);
+ }
+ /* 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);
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+ int maxproc = 6;
+
+ /* Load the SDL library */
+ if ( SDL_Init(0) < 0 ) {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ exit(1);
+ }
+ atexit(SDL_Quit_Wrapper);
+
+ if ( (mutex=SDL_CreateMutex()) == NULL ) {
+ fprintf(stderr, "Couldn't create mutex: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ mainthread = SDL_ThreadID();
+ printf("Main thread: %u\n", mainthread);
+ atexit(printid);
+ for ( i=0; i<maxproc; ++i ) {
+ if ( (threads[i]=SDL_CreateThread(Run, NULL)) == NULL )
+ fprintf(stderr, "Couldn't create thread!\n");
+ }
+ signal(SIGINT, terminate);
+ Run(NULL);
+
+ return(0); /* Never reached */
+}
diff --git a/distrib/sdl-1.2.15/test/testoverlay.c b/distrib/sdl-1.2.15/test/testoverlay.c
new file mode 100644
index 0000000..da53f9e
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testoverlay.c
@@ -0,0 +1,594 @@
+
+/* Bring up a window and play with it */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define BENCHMARK_SDL
+
+#define NOTICE(X) printf("%s", X);
+
+#define WINDOW_WIDTH 640
+#define WINDOW_HEIGHT 480
+
+#include "SDL.h"
+
+SDL_Surface *screen, *pic;
+SDL_Overlay *overlay;
+int scale;
+int monochrome;
+int luminance;
+int w, h;
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+/* NOTE: These RGB conversion functions are not intended for speed,
+ only as examples.
+*/
+
+void RGBtoYUV(Uint8 *rgb, int *yuv, int monochrome, int luminance)
+{
+ if (monochrome)
+ {
+#if 1 /* these are the two formulas that I found on the FourCC site... */
+ yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
+ yuv[1] = 128;
+ yuv[2] = 128;
+#else
+ yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
+ yuv[1] = 128;
+ yuv[2] = 128;
+#endif
+ }
+ else
+ {
+#if 1 /* these are the two formulas that I found on the FourCC site... */
+ yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
+ yuv[1] = (rgb[2]-yuv[0])*0.565 + 128;
+ yuv[2] = (rgb[0]-yuv[0])*0.713 + 128;
+#else
+ yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
+ yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]);
+ yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]);
+#endif
+ }
+
+ if (luminance!=100)
+ {
+ yuv[0]=yuv[0]*luminance/100;
+ if (yuv[0]>255)
+ yuv[0]=255;
+ }
+
+ /* clamp values...if you need to, we don't seem to have a need */
+ /*
+ for(i=0;i<3;i++)
+ {
+ if(yuv[i]<0)
+ yuv[i]=0;
+ if(yuv[i]>255)
+ yuv[i]=255;
+ }
+ */
+}
+
+void ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op[3];
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ /* Black initialization */
+ /*
+ memset(o->pixels[0],0,o->pitches[0]*o->h);
+ memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2));
+ memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2));
+ */
+
+ /* Convert */
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op[0]=o->pixels[0]+o->pitches[0]*y;
+ op[1]=o->pixels[1]+o->pitches[1]*(y/2);
+ op[2]=o->pixels[2]+o->pitches[2]*(y/2);
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p, yuv, monochrome, luminance);
+ *(op[0]++)=yuv[0];
+ if(x%2==0 && y%2==0)
+ {
+ *(op[1]++)=yuv[2];
+ *(op[2]++)=yuv[1];
+ }
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op[3];
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ /* Black initialization */
+ /*
+ memset(o->pixels[0],0,o->pitches[0]*o->h);
+ memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2));
+ memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2));
+ */
+
+ /* Convert */
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op[0]=o->pixels[0]+o->pitches[0]*y;
+ op[1]=o->pixels[1]+o->pitches[1]*(y/2);
+ op[2]=o->pixels[2]+o->pitches[2]*(y/2);
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p,yuv, monochrome, luminance);
+ *(op[0]++)=yuv[0];
+ if(x%2==0 && y%2==0)
+ {
+ *(op[1]++)=yuv[1];
+ *(op[2]++)=yuv[2];
+ }
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op;
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op=o->pixels[0]+o->pitches[0]*y;
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p, yuv, monochrome, luminance);
+ if(x%2==0)
+ {
+ *(op++)=yuv[1];
+ *(op++)=yuv[0];
+ *(op++)=yuv[2];
+ }
+ else
+ *(op++)=yuv[0];
+
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op;
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op=o->pixels[0]+o->pitches[0]*y;
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p,yuv, monochrome, luminance);
+ if(x%2==0)
+ {
+ *(op++)=yuv[0];
+ *(op++)=yuv[2];
+ op[1]=yuv[1];
+ }
+ else
+ {
+ *op=yuv[0];
+ op+=2;
+ }
+
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op;
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op=o->pixels[0]+o->pitches[0]*y;
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p,yuv, monochrome, luminance);
+ if(x%2==0)
+ {
+ *(op++)=yuv[0];
+ *(op++)=yuv[1];
+ op[1]=yuv[2];
+ }
+ else
+ {
+ *op=yuv[0];
+ op+=2;
+ }
+
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void Draw()
+{
+ SDL_Rect rect;
+ int i;
+ int disp;
+
+ if(!scale)
+ {
+ rect.w=overlay->w;
+ rect.h=overlay->h;
+ for(i=0; i<h-rect.h && i<w-rect.w; i++)
+ {
+ rect.x=i;
+ rect.y=i;
+ SDL_DisplayYUVOverlay(overlay,&rect);
+ }
+ }
+ else
+ {
+ rect.w=overlay->w/2;
+ rect.h=overlay->h/2;
+ rect.x=(w-rect.w)/2;
+ rect.y=(h-rect.h)/2;
+ disp=rect.y-1;
+ for(i=0; i<disp; i++)
+ {
+ rect.w+=2;
+ rect.h+=2;
+ rect.x--;
+ rect.y--;
+ SDL_DisplayYUVOverlay(overlay,&rect);
+ }
+ }
+ printf("Displayed %d times.\n",i);
+}
+
+static void PrintUsage(char *argv0)
+{
+ fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
+ fprintf(stderr, "Where 'arg' is one of:\n");
+ fprintf(stderr, " -delay <seconds>\n");
+ fprintf(stderr, " -width <pixels>\n");
+ fprintf(stderr, " -height <pixels>\n");
+ fprintf(stderr, " -bpp <bits>\n");
+ fprintf(stderr, " -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
+ fprintf(stderr, " -hw\n");
+ fprintf(stderr, " -flip\n");
+ fprintf(stderr, " -scale (test scaling features, from 50%% upto window size)\n");
+ fprintf(stderr, " -mono (use monochromatic RGB2YUV conversion)\n");
+ fprintf(stderr, " -lum <perc> (use luminance correction during RGB2YUV conversion,\n");
+ fprintf(stderr, " from 0%% to unlimited, normal is 100%%)\n");
+ fprintf(stderr, " -help (shows this help)\n");
+ fprintf(stderr, " -fullscreen (test overlay in fullscreen mode)\n");
+}
+
+int main(int argc, char **argv)
+{
+ char *argv0 = argv[0];
+ int flip;
+ int delay;
+ int desired_bpp;
+ Uint32 video_flags, overlay_format;
+ char *bmpfile;
+#ifdef BENCHMARK_SDL
+ Uint32 then, now;
+#endif
+ int i;
+
+ /* Set default options and check command-line */
+ flip = 0;
+ scale=0;
+ monochrome=0;
+ luminance=100;
+ delay = 1;
+ w = WINDOW_WIDTH;
+ h = WINDOW_HEIGHT;
+ desired_bpp = 0;
+ video_flags = 0;
+ overlay_format = SDL_YV12_OVERLAY;
+
+ while ( argc > 1 ) {
+ if ( strcmp(argv[1], "-delay") == 0 ) {
+ if ( argv[2] ) {
+ delay = atoi(argv[2]);
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -delay option requires an argument\n");
+ return(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-width") == 0 ) {
+ if ( argv[2] && ((w = atoi(argv[2])) > 0) ) {
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -width option requires an argument\n");
+ return(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-height") == 0 ) {
+ if ( argv[2] && ((h = atoi(argv[2])) > 0) ) {
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -height option requires an argument\n");
+ return(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-bpp") == 0 ) {
+ if ( argv[2] ) {
+ desired_bpp = atoi(argv[2]);
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -bpp option requires an argument\n");
+ return(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-lum") == 0 ) {
+ if ( argv[2] ) {
+ luminance = atoi(argv[2]);
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -lum option requires an argument\n");
+ return(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-format") == 0 ) {
+ if ( argv[2] ) {
+ if(!strcmp(argv[2],"YV12"))
+ overlay_format = SDL_YV12_OVERLAY;
+ else if(!strcmp(argv[2],"IYUV"))
+ overlay_format = SDL_IYUV_OVERLAY;
+ else if(!strcmp(argv[2],"YUY2"))
+ overlay_format = SDL_YUY2_OVERLAY;
+ else if(!strcmp(argv[2],"UYVY"))
+ overlay_format = SDL_UYVY_OVERLAY;
+ else if(!strcmp(argv[2],"YVYU"))
+ overlay_format = SDL_YVYU_OVERLAY;
+ else
+ {
+ fprintf(stderr, "The -format option %s is not recognized\n",argv[2]);
+ return(1);
+ }
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -format option requires an argument\n");
+ return(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-hw") == 0 ) {
+ video_flags |= SDL_HWSURFACE;
+ argv += 1;
+ argc -= 1;
+ } else
+ if ( strcmp(argv[1], "-flip") == 0 ) {
+ video_flags |= SDL_DOUBLEBUF;
+ argv += 1;
+ argc -= 1;
+ } else
+ if ( strcmp(argv[1], "-scale") == 0 ) {
+ scale = 1;
+ argv += 1;
+ argc -= 1;
+ } else
+ if ( strcmp(argv[1], "-mono") == 0 ) {
+ monochrome = 1;
+ argv += 1;
+ argc -= 1;
+ } else
+ if (( strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0)) {
+ PrintUsage(argv0);
+ return(1);
+ } else
+ if ( strcmp(argv[1], "-fullscreen") == 0 ) {
+ video_flags |= SDL_FULLSCREEN;
+ argv += 1;
+ argc -= 1;
+ } else
+ break;
+ }
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr,
+ "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return(1);
+ }
+
+ /* Initialize the display */
+ screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
+ w, h, desired_bpp, SDL_GetError());
+ quit(1);
+ }
+ printf("Set%s %dx%dx%d mode\n",
+ screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
+ screen->w, screen->h, screen->format->BitsPerPixel);
+ printf("(video surface located in %s memory)\n",
+ (screen->flags&SDL_HWSURFACE) ? "video" : "system");
+ if ( screen->flags & SDL_DOUBLEBUF ) {
+ printf("Double-buffering enabled\n");
+ flip = 1;
+ }
+
+ /* Set the window manager title bar */
+ SDL_WM_SetCaption("SDL test overlay", "testoverlay");
+
+ /* Load picture */
+ bmpfile=(argv[1]?argv[1]:"sample.bmp");
+ pic = SDL_LoadBMP(bmpfile);
+ if ( pic == NULL ) {
+ fprintf(stderr, "Couldn't load %s: %s\n", bmpfile,
+ SDL_GetError());
+ quit(1);
+ }
+
+ /* Convert the picture to 32bits, for easy conversion */
+ {
+ SDL_Surface *newsurf;
+ SDL_PixelFormat format;
+
+ format.palette=NULL;
+ format.BitsPerPixel=32;
+ format.BytesPerPixel=4;
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ format.Rshift=0;
+ format.Gshift=8;
+ format.Bshift=16;
+#else
+ format.Rshift=24;
+ format.Gshift=16;
+ format.Bshift=8;
+#endif
+ format.Ashift=0;
+ format.Rmask=0xff<<format.Rshift;
+ format.Gmask=0xff<<format.Gshift;
+ format.Bmask=0xff<<format.Bshift;
+ format.Amask=0;
+ format.Rloss=0;
+ format.Gloss=0;
+ format.Bloss=0;
+ format.Aloss=8;
+ format.colorkey=0;
+ format.alpha=0;
+
+ newsurf=SDL_ConvertSurface(pic, &format, SDL_SWSURFACE);
+ if(!newsurf)
+ {
+ fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n",
+ SDL_GetError());
+ quit(1);
+ }
+ SDL_FreeSurface(pic);
+ pic=newsurf;
+ }
+
+ /* Create the overlay */
+ overlay = SDL_CreateYUVOverlay(pic->w, pic->h, overlay_format, screen);
+ if ( overlay == NULL ) {
+ fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
+ quit(1);
+ }
+ printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
+ overlay->hw_overlay?"hardware":"software",
+ overlay->format==SDL_YV12_OVERLAY?"YV12":
+ overlay->format==SDL_IYUV_OVERLAY?"IYUV":
+ overlay->format==SDL_YUY2_OVERLAY?"YUY2":
+ overlay->format==SDL_UYVY_OVERLAY?"UYVY":
+ overlay->format==SDL_YVYU_OVERLAY?"YVYU":
+ "Unknown");
+ for(i=0; i<overlay->planes; i++)
+ {
+ printf(" plane %d: pitch=%d\n", i, overlay->pitches[i]);
+ }
+
+ /* Convert to YUV, and draw to the overlay */
+#ifdef BENCHMARK_SDL
+ then = SDL_GetTicks();
+#endif
+ switch(overlay->format)
+ {
+ case SDL_YV12_OVERLAY:
+ ConvertRGBtoYV12(pic,overlay,monochrome,luminance);
+ break;
+ case SDL_UYVY_OVERLAY:
+ ConvertRGBtoUYVY(pic,overlay,monochrome,luminance);
+ break;
+ case SDL_YVYU_OVERLAY:
+ ConvertRGBtoYVYU(pic,overlay,monochrome,luminance);
+ break;
+ case SDL_YUY2_OVERLAY:
+ ConvertRGBtoYUY2(pic,overlay,monochrome,luminance);
+ break;
+ case SDL_IYUV_OVERLAY:
+ ConvertRGBtoIYUV(pic,overlay,monochrome,luminance);
+ break;
+ default:
+ printf("cannot convert RGB picture to obtained YUV format!\n");
+ quit(1);
+ break;
+ }
+#ifdef BENCHMARK_SDL
+ now = SDL_GetTicks();
+ printf("Conversion Time: %d milliseconds\n", now-then);
+#endif
+
+ /* Do all the drawing work */
+#ifdef BENCHMARK_SDL
+ then = SDL_GetTicks();
+#endif
+ Draw();
+#ifdef BENCHMARK_SDL
+ now = SDL_GetTicks();
+ printf("Time: %d milliseconds\n", now-then);
+#endif
+ SDL_Delay(delay*1000);
+ SDL_Quit();
+ return(0);
+}
+
diff --git a/distrib/sdl-1.2.15/test/testoverlay2.c b/distrib/sdl-1.2.15/test/testoverlay2.c
new file mode 100644
index 0000000..5f491f2
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testoverlay2.c
@@ -0,0 +1,600 @@
+/********************************************************************************
+ * *
+ * Test of the overlay used for moved pictures, test more closed to real life. *
+ * Running trojan moose :) Coded by Mike Gorchak. *
+ * *
+ ********************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "SDL.h"
+
+#define MOOSEPIC_W 64
+#define MOOSEPIC_H 88
+
+#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
+#define MOOSEFRAMES_COUNT 10
+
+SDL_Color MooseColors[84]={
+ { 49, 49, 49}, { 66, 24, 0}, { 66, 33, 0}, { 66, 66, 66},
+ { 66, 115, 49}, { 74, 33, 0}, { 74, 41, 16}, { 82, 33, 8},
+ { 82, 41, 8}, { 82, 49, 16}, { 82, 82, 82}, { 90, 41, 8},
+ { 90, 41, 16}, { 90, 57, 24}, { 99, 49, 16}, { 99, 66, 24},
+ { 99, 66, 33}, { 99, 74, 33}, {107, 57, 24}, {107, 82, 41},
+ {115, 57, 33}, {115, 66, 33}, {115, 66, 41}, {115, 74, 0},
+ {115, 90, 49}, {115, 115, 115}, {123, 82, 0}, {123, 99, 57},
+ {132, 66, 41}, {132, 74, 41}, {132, 90, 8}, {132, 99, 33},
+ {132, 99, 66}, {132, 107, 66}, {140, 74, 49}, {140, 99, 16},
+ {140, 107, 74}, {140, 115, 74}, {148, 107, 24}, {148, 115, 82},
+ {148, 123, 74}, {148, 123, 90}, {156, 115, 33}, {156, 115, 90},
+ {156, 123, 82}, {156, 132, 82}, {156, 132, 99}, {156, 156, 156},
+ {165, 123, 49}, {165, 123, 90}, {165, 132, 82}, {165, 132, 90},
+ {165, 132, 99}, {165, 140, 90}, {173, 132, 57}, {173, 132, 99},
+ {173, 140, 107}, {173, 140, 115}, {173, 148, 99}, {173, 173, 173},
+ {181, 140, 74}, {181, 148, 115}, {181, 148, 123}, {181, 156, 107},
+ {189, 148, 123}, {189, 156, 82}, {189, 156, 123}, {189, 156, 132},
+ {189, 189, 189}, {198, 156, 123}, {198, 165, 132}, {206, 165, 99},
+ {206, 165, 132}, {206, 173, 140}, {206, 206, 206}, {214, 173, 115},
+ {214, 173, 140}, {222, 181, 148}, {222, 189, 132}, {222, 189, 156},
+ {222, 222, 222}, {231, 198, 165}, {231, 231, 231}, {239, 206, 173}
+};
+
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+/* All RGB2YUV conversion code and some other parts of code has been taken from testoverlay.c */
+
+/* NOTE: These RGB conversion functions are not intended for speed,
+ only as examples.
+*/
+
+void RGBtoYUV(Uint8 *rgb, int *yuv, int monochrome, int luminance)
+{
+ if (monochrome)
+ {
+#if 1 /* these are the two formulas that I found on the FourCC site... */
+ yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
+ yuv[1] = 128;
+ yuv[2] = 128;
+#else
+ yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
+ yuv[1] = 128;
+ yuv[2] = 128;
+#endif
+ }
+ else
+ {
+#if 1 /* these are the two formulas that I found on the FourCC site... */
+ yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
+ yuv[1] = (rgb[2]-yuv[0])*0.565 + 128;
+ yuv[2] = (rgb[0]-yuv[0])*0.713 + 128;
+#else
+ yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
+ yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]);
+ yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]);
+#endif
+ }
+
+ if (luminance!=100)
+ {
+ yuv[0]=yuv[0]*luminance/100;
+ if (yuv[0]>255)
+ yuv[0]=255;
+ }
+}
+
+void ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op[3];
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ /* Convert */
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op[0]=o->pixels[0]+o->pitches[0]*y;
+ op[1]=o->pixels[1]+o->pitches[1]*(y/2);
+ op[2]=o->pixels[2]+o->pitches[2]*(y/2);
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p, yuv, monochrome, luminance);
+ *(op[0]++)=yuv[0];
+ if(x%2==0 && y%2==0)
+ {
+ *(op[1]++)=yuv[2];
+ *(op[2]++)=yuv[1];
+ }
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op[3];
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ /* Convert */
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op[0]=o->pixels[0]+o->pitches[0]*y;
+ op[1]=o->pixels[1]+o->pitches[1]*(y/2);
+ op[2]=o->pixels[2]+o->pitches[2]*(y/2);
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p,yuv, monochrome, luminance);
+ *(op[0]++)=yuv[0];
+ if(x%2==0 && y%2==0)
+ {
+ *(op[1]++)=yuv[1];
+ *(op[2]++)=yuv[2];
+ }
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op;
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op=o->pixels[0]+o->pitches[0]*y;
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p, yuv, monochrome, luminance);
+ if(x%2==0)
+ {
+ *(op++)=yuv[1];
+ *(op++)=yuv[0];
+ *(op++)=yuv[2];
+ }
+ else
+ *(op++)=yuv[0];
+
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op;
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op=o->pixels[0]+o->pitches[0]*y;
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p,yuv, monochrome, luminance);
+ if(x%2==0)
+ {
+ *(op++)=yuv[0];
+ *(op++)=yuv[2];
+ op[1]=yuv[1];
+ }
+ else
+ {
+ *op=yuv[0];
+ op+=2;
+ }
+
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+void ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
+{
+ int x,y;
+ int yuv[3];
+ Uint8 *p,*op;
+
+ SDL_LockSurface(s);
+ SDL_LockYUVOverlay(o);
+
+ for(y=0; y<s->h && y<o->h; y++)
+ {
+ p=((Uint8 *) s->pixels)+s->pitch*y;
+ op=o->pixels[0]+o->pitches[0]*y;
+ for(x=0; x<s->w && x<o->w; x++)
+ {
+ RGBtoYUV(p,yuv, monochrome, luminance);
+ if(x%2==0)
+ {
+ *(op++)=yuv[0];
+ *(op++)=yuv[1];
+ op[1]=yuv[2];
+ }
+ else
+ {
+ *op=yuv[0];
+ op+=2;
+ }
+
+ p+=s->format->BytesPerPixel;
+ }
+ }
+
+ SDL_UnlockYUVOverlay(o);
+ SDL_UnlockSurface(s);
+}
+
+static void PrintUsage(char *argv0)
+{
+ fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Where 'arg' is any of the following options:\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, " -fps <frames per second>\n");
+ fprintf(stderr, " -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
+ fprintf(stderr, " -scale <scale factor> (initial scale of the overlay)\n");
+ fprintf(stderr, " -help (shows this help)\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Press ESC to exit, or SPACE to freeze the movie while application running.\n");
+ fprintf(stderr, "\n");
+}
+
+int main(int argc, char **argv)
+{
+ Uint8* RawMooseData;
+ SDL_RWops* handle;
+ SDL_Surface* screen;
+ SDL_Surface* MooseFrame[MOOSEFRAMES_COUNT];
+ SDL_Overlay* overlay;
+ SDL_Rect overlayrect;
+ SDL_Event event;
+ Uint32 lastftick;
+ int paused=0;
+ int resized=0;
+ int i;
+ int fps=12;
+ int fpsdelay;
+ int overlay_format=SDL_YUY2_OVERLAY;
+ int scale=5;
+
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
+ {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return 3;
+ }
+
+ while ( argc > 1 )
+ {
+ if (strcmp(argv[1], "-fps")== 0)
+ {
+ if (argv[2])
+ {
+ fps = atoi(argv[2]);
+ if (fps==0)
+ {
+ fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
+ quit(10);
+ }
+ if ((fps<0) || (fps>1000))
+ {
+ fprintf(stderr, "The -fps option must be in range from 1 to 1000, default is 12.\n");
+ quit(10);
+ }
+ argv += 2;
+ argc -= 2;
+ }
+ else
+ {
+ fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
+ quit(10);
+ }
+ } else
+ if (strcmp(argv[1], "-format") == 0)
+ {
+ if (argv[2])
+ {
+ if (!strcmp(argv[2],"YV12"))
+ overlay_format = SDL_YV12_OVERLAY;
+ else if(!strcmp(argv[2],"IYUV"))
+ overlay_format = SDL_IYUV_OVERLAY;
+ else if(!strcmp(argv[2],"YUY2"))
+ overlay_format = SDL_YUY2_OVERLAY;
+ else if(!strcmp(argv[2],"UYVY"))
+ overlay_format = SDL_UYVY_OVERLAY;
+ else if(!strcmp(argv[2],"YVYU"))
+ overlay_format = SDL_YVYU_OVERLAY;
+ else
+ {
+ fprintf(stderr, "The -format option %s is not recognized, see help for info.\n", argv[2]);
+ quit(10);
+ }
+ argv += 2;
+ argc -= 2;
+ }
+ else
+ {
+ fprintf(stderr, "The -format option requires an argument, default is YUY2.\n");
+ quit(10);
+ }
+ } else
+ if (strcmp(argv[1], "-scale") == 0)
+ {
+ if (argv[2])
+ {
+ scale = atoi(argv[2]);
+ if (scale==0)
+ {
+ fprintf(stderr, "The -scale option requires an argument [from 1 to 50], default is 5.\n");
+ quit(10);
+ }
+ if ((scale<0) || (scale>50))
+ {
+ fprintf(stderr, "The -scale option must be in range from 1 to 50, default is 5.\n");
+ quit(10);
+ }
+ argv += 2;
+ argc -= 2;
+ }
+ else
+ {
+ fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
+ quit(10);
+ }
+ } else
+ if ((strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0))
+ {
+ PrintUsage(argv[0]);
+ quit(0);
+ } else
+ {
+ fprintf(stderr, "Unrecognized option: %s.\n", argv[1]);
+ quit(10);
+ }
+ break;
+ }
+
+ RawMooseData=(Uint8*)malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
+ if (RawMooseData==NULL)
+ {
+ fprintf(stderr, "Can't allocate memory for movie !\n");
+ free(RawMooseData);
+ quit(1);
+ }
+
+ /* load the trojan moose images */
+ handle=SDL_RWFromFile("moose.dat", "rb");
+ if (handle==NULL)
+ {
+ fprintf(stderr, "Can't find the file moose.dat !\n");
+ free(RawMooseData);
+ quit(2);
+ }
+
+ SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
+
+ SDL_RWclose(handle);
+
+ /* Set video mode */
+ if ( (screen=SDL_SetVideoMode(MOOSEPIC_W*scale, MOOSEPIC_H*scale, 0, SDL_RESIZABLE | SDL_SWSURFACE)) == NULL )
+ {
+ fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
+ free(RawMooseData);
+ quit(4);
+ }
+
+ /* Set the window manager title bar */
+ SDL_WM_SetCaption("SDL test overlay: running moose", "testoverlay2");
+
+ for (i=0; i<MOOSEFRAMES_COUNT; i++)
+ {
+ MooseFrame[i]=SDL_CreateRGBSurfaceFrom(RawMooseData+i*MOOSEFRAME_SIZE, MOOSEPIC_W,
+ MOOSEPIC_H, 8, MOOSEPIC_W, 0, 0, 0, 0);
+ if (MooseFrame[i]==NULL)
+ {
+ fprintf(stderr, "Couldn't create SDL_Surfaces:%s\n", SDL_GetError());
+ free(RawMooseData);
+ quit(5);
+ }
+ SDL_SetColors(MooseFrame[i], MooseColors, 0, 84);
+
+ {
+ SDL_Surface *newsurf;
+ SDL_PixelFormat format;
+
+ format.palette=NULL;
+ format.BitsPerPixel=32;
+ format.BytesPerPixel=4;
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ format.Rshift=0;
+ format.Gshift=8;
+ format.Bshift=16;
+#else
+ format.Rshift=24;
+ format.Gshift=16;
+ format.Bshift=8;
+#endif
+ format.Ashift=0;
+ format.Rmask=0xff<<format.Rshift;
+ format.Gmask=0xff<<format.Gshift;
+ format.Bmask=0xff<<format.Bshift;
+ format.Amask=0;
+ format.Rloss=0;
+ format.Gloss=0;
+ format.Bloss=0;
+ format.Aloss=8;
+ format.colorkey=0;
+ format.alpha=0;
+
+ newsurf=SDL_ConvertSurface(MooseFrame[i], &format, SDL_SWSURFACE);
+ if(!newsurf)
+ {
+ fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", SDL_GetError());
+ quit(6);
+ }
+ SDL_FreeSurface(MooseFrame[i]);
+ MooseFrame[i]=newsurf;
+ }
+ }
+
+ free(RawMooseData);
+
+ overlay=SDL_CreateYUVOverlay(MOOSEPIC_W, MOOSEPIC_H, overlay_format, screen);
+ if (!overlay)
+ {
+ fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
+ quit(7);
+ }
+
+ printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
+ overlay->hw_overlay?"hardware":"software",
+ overlay->format==SDL_YV12_OVERLAY?"YV12":
+ overlay->format==SDL_IYUV_OVERLAY?"IYUV":
+ overlay->format==SDL_YUY2_OVERLAY?"YUY2":
+ overlay->format==SDL_UYVY_OVERLAY?"UYVY":
+ overlay->format==SDL_YVYU_OVERLAY?"YVYU":
+ "Unknown");
+
+ for(i=0; i<overlay->planes; i++)
+ {
+ printf(" plane %d: pitch=%d\n", i, overlay->pitches[i]);
+ }
+
+ overlayrect.x=0;
+ overlayrect.y=0;
+ overlayrect.w=MOOSEPIC_W*scale;
+ overlayrect.h=MOOSEPIC_H*scale;
+
+ /* set the start frame */
+ i=0;
+ fpsdelay=1000/fps;
+
+ /* Ignore key up events, they don't even get filtered */
+ SDL_EventState(SDL_KEYUP, SDL_IGNORE);
+
+ lastftick=SDL_GetTicks();
+
+ /* Loop, waiting for QUIT or RESIZE */
+ while (1)
+ {
+ if (SDL_PollEvent(&event))
+ {
+ switch (event.type)
+ {
+ case SDL_VIDEORESIZE:
+ screen=SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_RESIZABLE | SDL_SWSURFACE);
+ overlayrect.w=event.resize.w;
+ overlayrect.h=event.resize.h;
+ if (paused)
+ {
+ resized=1;
+ }
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ overlayrect.x = event.button.x - overlayrect.w/2;
+ overlayrect.y = event.button.y - overlayrect.h/2;
+ break;
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_SPACE)
+ {
+ paused=!paused;
+ break;
+ }
+ if (event.key.keysym.sym != SDLK_ESCAPE)
+ {
+ break;
+ }
+ case SDL_QUIT:
+ SDL_FreeYUVOverlay(overlay);
+ for (i=0; i<MOOSEFRAMES_COUNT; i++)
+ {
+ SDL_FreeSurface(MooseFrame[i]);
+ }
+ quit(0);
+ }
+ }
+
+ if ((!paused)||(resized))
+ {
+ if (((SDL_GetTicks()-lastftick)>fpsdelay)||(resized))
+ {
+ lastftick=SDL_GetTicks();
+
+ switch (overlay_format)
+ {
+ case SDL_YUY2_OVERLAY:
+ ConvertRGBtoYUY2(MooseFrame[i], overlay, 0, 100);
+ break;
+ case SDL_YV12_OVERLAY:
+ ConvertRGBtoYV12(MooseFrame[i], overlay, 0, 100);
+ break;
+ case SDL_UYVY_OVERLAY:
+ ConvertRGBtoUYVY(MooseFrame[i], overlay, 0, 100);
+ break;
+ case SDL_YVYU_OVERLAY:
+ ConvertRGBtoYVYU(MooseFrame[i], overlay, 0, 100);
+ break;
+ case SDL_IYUV_OVERLAY:
+ ConvertRGBtoIYUV(MooseFrame[i], overlay, 0, 100);
+ break;
+ }
+
+ SDL_DisplayYUVOverlay(overlay, &overlayrect);
+ if (!resized)
+ {
+ i++;
+ if (i==10)
+ {
+ i=0;
+ }
+ }
+ else
+ {
+ resized=0;
+ }
+ }
+ }
+ /* kind of timeslice to OS */
+ SDL_Delay(1);
+ }
+
+ SDL_Quit();
+ return 0;
+}
+
diff --git a/distrib/sdl-1.2.15/test/testpalette.c b/distrib/sdl-1.2.15/test/testpalette.c
new file mode 100644
index 0000000..2ad4916
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testpalette.c
@@ -0,0 +1,342 @@
+/*
+ * testpalette.c
+ *
+ * A simple test of runtime palette modification for animation
+ * (using the SDL_SetPalette() API).
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+/* This isn't in the Windows headers */
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#include "SDL.h"
+
+/* screen size */
+#define SCRW 640
+#define SCRH 480
+
+#define NBOATS 5
+#define SPEED 2
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+/*
+ * wave colours: Made by taking a narrow cross-section of a wave picture
+ * in Gimp, saving in PPM ascii format and formatting with Emacs macros.
+ */
+static SDL_Color wavemap[] = {
+ {0,2,103}, {0,7,110}, {0,13,117}, {0,19,125},
+ {0,25,133}, {0,31,141}, {0,37,150}, {0,43,158},
+ {0,49,166}, {0,55,174}, {0,61,182}, {0,67,190},
+ {0,73,198}, {0,79,206}, {0,86,214}, {0,96,220},
+ {5,105,224}, {12,112,226}, {19,120,227}, {26,128,229},
+ {33,135,230}, {40,143,232}, {47,150,234}, {54,158,236},
+ {61,165,238}, {68,173,239}, {75,180,241}, {82,188,242},
+ {89,195,244}, {96,203,246}, {103,210,248}, {112,218,250},
+ {124,224,250}, {135,226,251}, {146,229,251}, {156,231,252},
+ {167,233,252}, {178,236,252}, {189,238,252}, {200,240,252},
+ {211,242,252}, {222,244,252}, {233,247,252}, {242,249,252},
+ {237,250,252}, {209,251,252}, {174,251,252}, {138,252,252},
+ {102,251,252}, {63,250,252}, {24,243,252}, {7,225,252},
+ {4,203,252}, {3,181,252}, {2,158,252}, {1,136,251},
+ {0,111,248}, {0,82,234}, {0,63,213}, {0,50,192},
+ {0,39,172}, {0,28,152}, {0,17,132}, {0,7,114}
+};
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+static void sdlerr(char *when)
+{
+ fprintf(stderr, "SDL error: %s: %s\n", when, SDL_GetError());
+ quit(1);
+}
+
+/* create a background surface */
+static SDL_Surface *make_bg(SDL_Surface *screen, int startcol)
+{
+ int i;
+ SDL_Surface *bg = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h,
+ 8, 0, 0, 0, 0);
+ if(!bg)
+ sdlerr("creating background surface");
+
+ /* set the palette to the logical screen palette so that blits
+ won't be translated */
+ SDL_SetColors(bg, screen->format->palette->colors, 0, 256);
+
+ /* Make a wavy background pattern using colours 0-63 */
+ if(SDL_LockSurface(bg) < 0)
+ sdlerr("locking background");
+ for(i = 0; i < SCRH; i++) {
+ Uint8 *p = (Uint8 *)bg->pixels + i * bg->pitch;
+ int j, d;
+ d = 0;
+ for(j = 0; j < SCRW; j++) {
+ int v = MAX(d, -2);
+ v = MIN(v, 2);
+ if(i > 0)
+ v += p[-bg->pitch] + 65 - startcol;
+ p[j] = startcol + (v & 63);
+ d += ((rand() >> 3) % 3) - 1;
+ }
+ }
+ SDL_UnlockSurface(bg);
+ return(bg);
+}
+
+/*
+ * Return a surface flipped horisontally. Only works for 8bpp;
+ * extension to arbitrary bitness is left as an exercise for the reader.
+ */
+static SDL_Surface *hflip(SDL_Surface *s)
+{
+ int i;
+ SDL_Surface *z = SDL_CreateRGBSurface(SDL_SWSURFACE, s->w, s->h, 8,
+ 0, 0, 0, 0);
+ /* copy palette */
+ SDL_SetColors(z, s->format->palette->colors,
+ 0, s->format->palette->ncolors);
+ if(SDL_LockSurface(s) < 0 || SDL_LockSurface(z) < 0)
+ sdlerr("locking flip images");
+
+ for(i = 0; i < s->h; i++) {
+ int j;
+ Uint8 *from = (Uint8 *)s->pixels + i * s->pitch;
+ Uint8 *to = (Uint8 *)z->pixels + i * z->pitch + s->w - 1;
+ for(j = 0; j < s->w; j++)
+ to[-j] = from[j];
+ }
+
+ SDL_UnlockSurface(z);
+ SDL_UnlockSurface(s);
+ return z;
+}
+
+int main(int argc, char **argv)
+{
+ SDL_Color cmap[256];
+ SDL_Surface *screen;
+ SDL_Surface *bg;
+ SDL_Surface *boat[2];
+ unsigned vidflags = 0;
+ unsigned start;
+ int fade_max = 400;
+ int fade_level, fade_dir;
+ int boatcols, frames, i, red;
+ int boatx[NBOATS], boaty[NBOATS], boatdir[NBOATS];
+ int gamma_fade = 0;
+ int gamma_ramp = 0;
+
+ if(SDL_Init(SDL_INIT_VIDEO) < 0)
+ sdlerr("initialising SDL");
+
+ while(--argc) {
+ ++argv;
+ if(strcmp(*argv, "-hw") == 0)
+ vidflags |= SDL_HWSURFACE;
+ else if(strcmp(*argv, "-fullscreen") == 0)
+ vidflags |= SDL_FULLSCREEN;
+ else if(strcmp(*argv, "-nofade") == 0)
+ fade_max = 1;
+ else if(strcmp(*argv, "-gamma") == 0)
+ gamma_fade = 1;
+ else if(strcmp(*argv, "-gammaramp") == 0)
+ gamma_ramp = 1;
+ else {
+ fprintf(stderr,
+ "usage: testpalette "
+ " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n");
+ quit(1);
+ }
+ }
+
+ /* Ask explicitly for 8bpp and a hardware palette */
+ if((screen = SDL_SetVideoMode(SCRW, SCRH, 8, vidflags | SDL_HWPALETTE)) == NULL) {
+ fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n",
+ SCRW, SCRH, SDL_GetError());
+ quit(1);
+ }
+
+ if (vidflags & SDL_FULLSCREEN) SDL_ShowCursor (SDL_FALSE);
+
+ if((boat[0] = SDL_LoadBMP("sail.bmp")) == NULL)
+ sdlerr("loading sail.bmp");
+ /* We've chosen magenta (#ff00ff) as colour key for the boat */
+ SDL_SetColorKey(boat[0], SDL_SRCCOLORKEY | SDL_RLEACCEL,
+ SDL_MapRGB(boat[0]->format, 0xff, 0x00, 0xff));
+ boatcols = boat[0]->format->palette->ncolors;
+ boat[1] = hflip(boat[0]);
+ SDL_SetColorKey(boat[1], SDL_SRCCOLORKEY | SDL_RLEACCEL,
+ SDL_MapRGB(boat[1]->format, 0xff, 0x00, 0xff));
+
+ /*
+ * First set the physical screen palette to black, so the user won't
+ * see our initial drawing on the screen.
+ */
+ memset(cmap, 0, sizeof(cmap));
+ SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, 256);
+
+ /*
+ * Proper palette management is important when playing games with the
+ * colormap. We have divided the palette as follows:
+ *
+ * index 0..(boatcols-1): used for the boat
+ * index boatcols..(boatcols+63): used for the waves
+ */
+ SDL_SetPalette(screen, SDL_LOGPAL,
+ boat[0]->format->palette->colors, 0, boatcols);
+ SDL_SetPalette(screen, SDL_LOGPAL, wavemap, boatcols, 64);
+
+ /*
+ * Now the logical screen palette is set, and will remain unchanged.
+ * The boats already have the same palette so fast blits can be used.
+ */
+ memcpy(cmap, screen->format->palette->colors, 256 * sizeof(SDL_Color));
+
+ /* save the index of the red colour for later */
+ red = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00);
+
+ bg = make_bg(screen, boatcols); /* make a nice wavy background surface */
+
+ /* initial screen contents */
+ if(SDL_BlitSurface(bg, NULL, screen, NULL) < 0)
+ sdlerr("blitting background to screen");
+ SDL_Flip(screen); /* actually put the background on screen */
+
+ /* determine initial boat placements */
+ for(i = 0; i < NBOATS; i++) {
+ boatx[i] = (rand() % (SCRW + boat[0]->w)) - boat[0]->w;
+ boaty[i] = i * (SCRH - boat[0]->h) / (NBOATS - 1);
+ boatdir[i] = ((rand() >> 5) & 1) * 2 - 1;
+ }
+
+ start = SDL_GetTicks();
+ frames = 0;
+ fade_dir = 1;
+ fade_level = 0;
+ do {
+ SDL_Event e;
+ SDL_Rect updates[NBOATS];
+ SDL_Rect r;
+ int redphase;
+
+ /* A small event loop: just exit on any key or mouse button event */
+ while(SDL_PollEvent(&e)) {
+ if(e.type == SDL_KEYDOWN || e.type == SDL_QUIT
+ || e.type == SDL_MOUSEBUTTONDOWN) {
+ if(fade_dir < 0)
+ fade_level = 0;
+ fade_dir = -1;
+ }
+ }
+
+ /* move boats */
+ for(i = 0; i < NBOATS; i++) {
+ int old_x = boatx[i];
+ /* update boat position */
+ boatx[i] += boatdir[i] * SPEED;
+ if(boatx[i] <= -boat[0]->w || boatx[i] >= SCRW)
+ boatdir[i] = -boatdir[i];
+
+ /* paint over the old boat position */
+ r.x = old_x;
+ r.y = boaty[i];
+ r.w = boat[0]->w;
+ r.h = boat[0]->h;
+ if(SDL_BlitSurface(bg, &r, screen, &r) < 0)
+ sdlerr("blitting background");
+
+ /* construct update rectangle (bounding box of old and new pos) */
+ updates[i].x = MIN(old_x, boatx[i]);
+ updates[i].y = boaty[i];
+ updates[i].w = boat[0]->w + SPEED;
+ updates[i].h = boat[0]->h;
+ /* clip update rectangle to screen */
+ if(updates[i].x < 0) {
+ updates[i].w += updates[i].x;
+ updates[i].x = 0;
+ }
+ if(updates[i].x + updates[i].w > SCRW)
+ updates[i].w = SCRW - updates[i].x;
+ }
+
+ for(i = 0; i < NBOATS; i++) {
+ /* paint boat on new position */
+ r.x = boatx[i];
+ r.y = boaty[i];
+ if(SDL_BlitSurface(boat[(boatdir[i] + 1) / 2], NULL,
+ screen, &r) < 0)
+ sdlerr("blitting boat");
+ }
+
+ /* cycle wave palette */
+ for(i = 0; i < 64; i++)
+ cmap[boatcols + ((i + frames) & 63)] = wavemap[i];
+
+ if(fade_dir) {
+ /* Fade the entire palette in/out */
+ fade_level += fade_dir;
+
+ if(gamma_fade) {
+ /* Fade linearly in gamma level (lousy) */
+ float level = (float)fade_level / fade_max;
+ if(SDL_SetGamma(level, level, level) < 0)
+ sdlerr("setting gamma");
+
+ } else if(gamma_ramp) {
+ /* Fade using gamma ramp (better) */
+ Uint16 ramp[256];
+ for(i = 0; i < 256; i++)
+ ramp[i] = (i * fade_level / fade_max) << 8;
+ if(SDL_SetGammaRamp(ramp, ramp, ramp) < 0)
+ sdlerr("setting gamma ramp");
+
+ } else {
+ /* Fade using direct palette manipulation (best) */
+ memcpy(cmap, screen->format->palette->colors,
+ boatcols * sizeof(SDL_Color));
+ for(i = 0; i < boatcols + 64; i++) {
+ cmap[i].r = cmap[i].r * fade_level / fade_max;
+ cmap[i].g = cmap[i].g * fade_level / fade_max;
+ cmap[i].b = cmap[i].b * fade_level / fade_max;
+ }
+ }
+ if(fade_level == fade_max)
+ fade_dir = 0;
+ }
+
+ /* pulse the red colour (done after the fade, for a night effect) */
+ redphase = frames % 64;
+ cmap[red].r = (int)(255 * sin(redphase * M_PI / 63));
+
+ SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, boatcols + 64);
+
+ /* update changed areas of the screen */
+ SDL_UpdateRects(screen, NBOATS, updates);
+ frames++;
+ } while(fade_level > 0);
+
+ printf("%d frames, %.2f fps\n",
+ frames, 1000.0 * frames / (SDL_GetTicks() - start));
+
+ if (vidflags & SDL_FULLSCREEN) SDL_ShowCursor (SDL_TRUE);
+ SDL_Quit();
+ return 0;
+}
+
diff --git a/distrib/sdl-1.2.15/test/testplatform.c b/distrib/sdl-1.2.15/test/testplatform.c
new file mode 100644
index 0000000..328a96f
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testplatform.c
@@ -0,0 +1,210 @@
+
+#include <stdio.h>
+
+#include "SDL.h"
+#include "SDL_endian.h"
+#include "SDL_cpuinfo.h"
+
+/*
+ * Watcom C flags these as Warning 201: "Unreachable code" if you just
+ * compare them directly, so we push it through a function to keep the
+ * compiler quiet. --ryan.
+ */
+static int badsize(size_t sizeoftype, size_t hardcodetype)
+{
+ return sizeoftype != hardcodetype;
+}
+
+int TestTypes(SDL_bool verbose)
+{
+ int error = 0;
+
+ if ( badsize(sizeof(Uint8), 1) ) {
+ if ( verbose )
+ printf("sizeof(Uint8) != 1, instead = %lu\n",
+ (unsigned long) sizeof(Uint8));
+ ++error;
+ }
+ if ( badsize(sizeof(Uint16), 2) ) {
+ if ( verbose )
+ printf("sizeof(Uint16) != 2, instead = %lu\n",
+ (unsigned long) sizeof(Uint16));
+ ++error;
+ }
+ if ( badsize(sizeof(Uint32), 4) ) {
+ if ( verbose )
+ printf("sizeof(Uint32) != 4, instead = %lu\n",
+ (unsigned long) sizeof(Uint32));
+ ++error;
+ }
+#ifdef SDL_HAS_64BIT_TYPE
+ if ( badsize(sizeof(Uint64), 8) ) {
+ if ( verbose )
+ printf("sizeof(Uint64) != 8, instead = %lu\n",
+ (unsigned long) sizeof(Uint64));
+ ++error;
+ }
+#else
+ if ( verbose ) {
+ printf("WARNING: No 64-bit datatype on this platform\n");
+ }
+#endif
+ if ( verbose && !error )
+ printf("All data types are the expected size.\n");
+
+ return( error ? 1 : 0 );
+}
+
+int TestEndian(SDL_bool verbose)
+{
+ int error = 0;
+ Uint16 value = 0x1234;
+ int real_byteorder;
+ Uint16 value16 = 0xCDAB;
+ Uint16 swapped16 = 0xABCD;
+ Uint32 value32 = 0xEFBEADDE;
+ Uint32 swapped32 = 0xDEADBEEF;
+#ifdef SDL_HAS_64BIT_TYPE
+ Uint64 value64, swapped64;
+ value64 = 0xEFBEADDE;
+ value64 <<= 32;
+ value64 |= 0xCDAB3412;
+ swapped64 = 0x1234ABCD;
+ swapped64 <<= 32;
+ swapped64 |= 0xDEADBEEF;
+#endif
+
+ if ( verbose ) {
+ printf("Detected a %s endian machine.\n",
+ (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
+ }
+ if ( (*((char *)&value) >> 4) == 0x1 ) {
+ real_byteorder = SDL_BIG_ENDIAN;
+ } else {
+ real_byteorder = SDL_LIL_ENDIAN;
+ }
+ if ( real_byteorder != SDL_BYTEORDER ) {
+ if ( verbose ) {
+ printf("Actually a %s endian machine!\n",
+ (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
+ }
+ ++error;
+ }
+ if ( verbose ) {
+ printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16));
+ }
+ if ( SDL_Swap16(value16) != swapped16 ) {
+ if ( verbose ) {
+ printf("16 bit value swapped incorrectly!\n");
+ }
+ ++error;
+ }
+ if ( verbose ) {
+ printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32));
+ }
+ if ( SDL_Swap32(value32) != swapped32 ) {
+ if ( verbose ) {
+ printf("32 bit value swapped incorrectly!\n");
+ }
+ ++error;
+ }
+#ifdef SDL_HAS_64BIT_TYPE
+ if ( verbose ) {
+#ifdef _MSC_VER
+ printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64, SDL_Swap64(value64));
+#else
+ printf("Value 64 = 0x%llX, swapped = 0x%llX\n", (unsigned long long) value64, (unsigned long long) SDL_Swap64(value64));
+#endif
+ }
+ if ( SDL_Swap64(value64) != swapped64 ) {
+ if ( verbose ) {
+ printf("64 bit value swapped incorrectly!\n");
+ }
+ ++error;
+ }
+#endif
+ return( error ? 1 : 0 );
+}
+
+
+int TestCPUInfo(SDL_bool verbose)
+{
+ if ( verbose ) {
+ printf("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
+ printf("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
+ printf("MMX Ext %s\n", SDL_HasMMXExt() ? "detected" : "not detected");
+ printf("3DNow %s\n", SDL_Has3DNow() ? "detected" : "not detected");
+ printf("3DNow Ext %s\n", SDL_Has3DNowExt() ? "detected" : "not detected");
+ printf("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
+ printf("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
+ printf("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
+ }
+ return(0);
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_bool verbose = SDL_TRUE;
+ int status = 0;
+
+ if ( argv[1] && (SDL_strcmp(argv[1], "-q") == 0) ) {
+ verbose = SDL_FALSE;
+ }
+ if ( verbose ) {
+ printf("This system is running %s\n",
+#if __AIX__
+ "AIX"
+#elif __HAIKU__
+/* Haiku must appear here before BeOS, since it also defines __BEOS__ */
+ "Haiku"
+#elif __BEOS__
+ "BeOS"
+#elif __BSDI__
+ "BSDI"
+#elif __DREAMCAST__
+ "Dreamcast"
+#elif __FREEBSD__
+ "FreeBSD"
+#elif __HPUX__
+ "HP-UX"
+#elif __IRIX__
+ "Irix"
+#elif __LINUX__
+ "Linux"
+#elif __MINT__
+ "Atari MiNT"
+#elif __MACOS__
+ "MacOS Classic"
+#elif __MACOSX__
+ "Mac OS X"
+#elif __NETBSD__
+ "NetBSD"
+#elif __OPENBSD__
+ "OpenBSD"
+#elif __OS2__
+ "OS/2"
+#elif __OSF__
+ "OSF/1"
+#elif __QNXNTO__
+ "QNX Neutrino"
+#elif __RISCOS__
+ "RISC OS"
+#elif __SOLARIS__
+ "Solaris"
+#elif __WIN32__
+#ifdef _WIN32_WCE
+ "Windows CE"
+#else
+ "Windows"
+#endif
+#else
+ "an unknown operating system! (see SDL_platform.h)"
+#endif
+ );
+ }
+
+ status += TestTypes(verbose);
+ status += TestEndian(verbose);
+ status += TestCPUInfo(verbose);
+ return status;
+}
diff --git a/distrib/sdl-1.2.15/test/testsem.c b/distrib/sdl-1.2.15/test/testsem.c
new file mode 100644
index 0000000..c906432
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testsem.c
@@ -0,0 +1,103 @@
+
+/* Simple test of the SDL semaphore code */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include "SDL.h"
+#include "SDL_thread.h"
+
+#define NUM_THREADS 10
+
+static SDL_sem *sem;
+int alive = 1;
+
+int SDLCALL ThreadFunc(void *data)
+{
+ int threadnum = (int)(uintptr_t)data;
+ while ( alive ) {
+ SDL_SemWait(sem);
+ fprintf(stderr, "Thread number %d has got the semaphore (value = %d)!\n", threadnum, SDL_SemValue(sem));
+ SDL_Delay(200);
+ SDL_SemPost(sem);
+ fprintf(stderr, "Thread number %d has released the semaphore (value = %d)!\n", threadnum, SDL_SemValue(sem));
+ SDL_Delay(1); /* For the scheduler */
+ }
+ printf("Thread number %d exiting.\n", threadnum);
+ return 0;
+}
+
+static void killed(int sig)
+{
+ alive = 0;
+}
+
+static void TestWaitTimeout(void)
+{
+ Uint32 start_ticks;
+ Uint32 end_ticks;
+ Uint32 duration;
+
+ sem = SDL_CreateSemaphore(0);
+ printf("Waiting 2 seconds on semaphore\n");
+
+ start_ticks = SDL_GetTicks();
+ SDL_SemWaitTimeout(sem, 2000);
+ end_ticks = SDL_GetTicks();
+
+ duration = end_ticks - start_ticks;
+
+ /* Accept a little offset in the effective wait */
+ if (duration > 1900 && duration < 2050)
+ printf("Wait done.\n");
+ else
+ fprintf(stderr, "Wait took %d milliseconds\n", duration);
+}
+
+int main(int argc, char **argv)
+{
+ SDL_Thread *threads[NUM_THREADS];
+ uintptr_t i;
+ int init_sem;
+
+ if(argc < 2) {
+ fprintf(stderr,"Usage: %s init_value\n", argv[0]);
+ return(1);
+ }
+
+ /* Load the SDL library */
+ if ( SDL_Init(0) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+ signal(SIGTERM, killed);
+ signal(SIGINT, killed);
+
+ init_sem = atoi(argv[1]);
+ sem = SDL_CreateSemaphore(init_sem);
+
+ printf("Running %d threads, semaphore value = %d\n", NUM_THREADS, init_sem);
+ /* Create all the threads */
+ for( i = 0; i < NUM_THREADS; ++i ) {
+ threads[i] = SDL_CreateThread(ThreadFunc, (void*)i);
+ }
+
+ /* Wait 10 seconds */
+ SDL_Delay(10 * 1000);
+
+ /* Wait for all threads to finish */
+ printf("Waiting for threads to finish\n");
+ alive = 0;
+ for( i = 0; i < NUM_THREADS; ++i ) {
+ SDL_WaitThread(threads[i], NULL);
+ }
+ printf("Finished waiting for threads\n");
+
+ SDL_DestroySemaphore(sem);
+
+ TestWaitTimeout();
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testsprite.c b/distrib/sdl-1.2.15/test/testsprite.c
new file mode 100644
index 0000000..6d9e0a8
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testsprite.c
@@ -0,0 +1,323 @@
+/* Simple program: Move N sprites around on the screen as fast as possible */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <math.h>
+#include <time.h>
+
+#include "SDL.h"
+
+#define NUM_SPRITES 100
+#define MAX_SPEED 1
+
+SDL_Surface *sprite;
+int numsprites;
+SDL_Rect *sprite_rects;
+SDL_Rect *positions;
+SDL_Rect *velocities;
+int sprites_visible;
+int debug_flip;
+Uint16 sprite_w, sprite_h;
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+int LoadSprite(char *file)
+{
+ SDL_Surface *temp;
+
+ /* Load the sprite image */
+ sprite = SDL_LoadBMP(file);
+ if ( sprite == NULL ) {
+ fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
+ return(-1);
+ }
+
+ /* Set transparent pixel as the pixel at (0,0) */
+ if ( sprite->format->palette ) {
+ SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL),
+ *(Uint8 *)sprite->pixels);
+ }
+
+ /* Convert sprite to video format */
+ temp = SDL_DisplayFormat(sprite);
+ SDL_FreeSurface(sprite);
+ if ( temp == NULL ) {
+ fprintf(stderr, "Couldn't convert background: %s\n",
+ SDL_GetError());
+ return(-1);
+ }
+ sprite = temp;
+
+ /* We're ready to roll. :) */
+ return(0);
+}
+
+void MoveSprites(SDL_Surface *screen, Uint32 background)
+{
+ int i, nupdates;
+ SDL_Rect area, *position, *velocity;
+
+ nupdates = 0;
+ /* Erase all the sprites if necessary */
+ if ( sprites_visible ) {
+ SDL_FillRect(screen, NULL, background);
+ }
+
+ /* Move the sprite, bounce at the wall, and draw */
+ for ( i=0; i<numsprites; ++i ) {
+ position = &positions[i];
+ velocity = &velocities[i];
+ position->x += velocity->x;
+ if ( (position->x < 0) || (position->x >= (screen->w - sprite_w)) ) {
+ velocity->x = -velocity->x;
+ position->x += velocity->x;
+ }
+ position->y += velocity->y;
+ if ( (position->y < 0) || (position->y >= (screen->h - sprite_w)) ) {
+ velocity->y = -velocity->y;
+ position->y += velocity->y;
+ }
+
+ /* Blit the sprite onto the screen */
+ area = *position;
+ SDL_BlitSurface(sprite, NULL, screen, &area);
+ sprite_rects[nupdates++] = area;
+ }
+
+ if (debug_flip) {
+ if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
+ static int t = 0;
+
+ Uint32 color = SDL_MapRGB (screen->format, 255, 0, 0);
+ SDL_Rect r;
+ r.x = (sin((float)t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w-20);
+ r.y = 0;
+ r.w = 20;
+ r.h = screen->h;
+
+ SDL_FillRect (screen, &r, color);
+ t+=2;
+ }
+ }
+
+ /* Update the screen! */
+ if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
+ SDL_Flip(screen);
+ } else {
+ SDL_UpdateRects(screen, nupdates, sprite_rects);
+ }
+ sprites_visible = 1;
+}
+
+/* This is a way of telling whether or not to use hardware surfaces */
+Uint32 FastestFlags(Uint32 flags, int width, int height, int bpp)
+{
+ const SDL_VideoInfo *info;
+
+ /* Hardware acceleration is only used in fullscreen mode */
+ flags |= SDL_FULLSCREEN;
+
+ /* Check for various video capabilities */
+ info = SDL_GetVideoInfo();
+ if ( info->blit_hw_CC && info->blit_fill ) {
+ /* We use accelerated colorkeying and color filling */
+ flags |= SDL_HWSURFACE;
+ }
+ /* If we have enough video memory, and will use accelerated
+ blits directly to it, then use page flipping.
+ */
+ if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
+ /* Direct hardware blitting without double-buffering
+ causes really bad flickering.
+ */
+ if ( info->video_mem*1024 > (height*width*bpp/8) ) {
+ flags |= SDL_DOUBLEBUF;
+ } else {
+ flags &= ~SDL_HWSURFACE;
+ }
+ }
+
+ /* Return the flags */
+ return(flags);
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Surface *screen;
+ Uint8 *mem;
+ int width, height;
+ Uint8 video_bpp;
+ Uint32 videoflags;
+ Uint32 background;
+ int i, done;
+ SDL_Event event;
+ Uint32 then, now, frames;
+
+ /* Initialize SDL */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ numsprites = NUM_SPRITES;
+ videoflags = SDL_SWSURFACE|SDL_ANYFORMAT;
+ width = 640;
+ height = 480;
+ video_bpp = 8;
+ debug_flip = 0;
+ while ( argc > 1 ) {
+ --argc;
+ if ( strcmp(argv[argc-1], "-width") == 0 ) {
+ width = atoi(argv[argc]);
+ --argc;
+ } else
+ if ( strcmp(argv[argc-1], "-height") == 0 ) {
+ height = atoi(argv[argc]);
+ --argc;
+ } else
+ if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
+ video_bpp = atoi(argv[argc]);
+ videoflags &= ~SDL_ANYFORMAT;
+ --argc;
+ } else
+ if ( strcmp(argv[argc], "-fast") == 0 ) {
+ videoflags = FastestFlags(videoflags, width, height, video_bpp);
+ } else
+ if ( strcmp(argv[argc], "-hw") == 0 ) {
+ videoflags ^= SDL_HWSURFACE;
+ } else
+ if ( strcmp(argv[argc], "-flip") == 0 ) {
+ videoflags ^= SDL_DOUBLEBUF;
+ } else
+ if ( strcmp(argv[argc], "-debugflip") == 0 ) {
+ debug_flip ^= 1;
+ } else
+ if ( strcmp(argv[argc], "-fullscreen") == 0 ) {
+ videoflags ^= SDL_FULLSCREEN;
+ } else
+ if ( isdigit(argv[argc][0]) ) {
+ numsprites = atoi(argv[argc]);
+ } else {
+ fprintf(stderr,
+ "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n",
+ argv[0]);
+ quit(1);
+ }
+ }
+
+ /* Set video mode */
+ screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
+ if ( ! screen ) {
+ fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
+ width, height, SDL_GetError());
+ quit(2);
+ }
+
+ /* Load the sprite */
+ if ( LoadSprite("icon.bmp") < 0 ) {
+ quit(1);
+ }
+
+ /* Allocate memory for the sprite info */
+ mem = (Uint8 *)malloc(4*sizeof(SDL_Rect)*numsprites);
+ if ( mem == NULL ) {
+ SDL_FreeSurface(sprite);
+ fprintf(stderr, "Out of memory!\n");
+ quit(2);
+ }
+ sprite_rects = (SDL_Rect *)mem;
+ positions = sprite_rects;
+ sprite_rects += numsprites;
+ velocities = sprite_rects;
+ sprite_rects += numsprites;
+ sprite_w = sprite->w;
+ sprite_h = sprite->h;
+ srand(time(NULL));
+ for ( i=0; i<numsprites; ++i ) {
+ positions[i].x = rand()%(screen->w - sprite_w);
+ positions[i].y = rand()%(screen->h - sprite_h);
+ positions[i].w = sprite->w;
+ positions[i].h = sprite->h;
+ velocities[i].x = 0;
+ velocities[i].y = 0;
+ while ( ! velocities[i].x && ! velocities[i].y ) {
+ velocities[i].x = (rand()%(MAX_SPEED*2+1))-MAX_SPEED;
+ velocities[i].y = (rand()%(MAX_SPEED*2+1))-MAX_SPEED;
+ }
+ }
+ background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
+
+ /* Print out information about our surfaces */
+ printf("Screen is at %d bits per pixel\n",screen->format->BitsPerPixel);
+ if ( (screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
+ printf("Screen is in video memory\n");
+ } else {
+ printf("Screen is in system memory\n");
+ }
+ if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
+ printf("Screen has double-buffering enabled\n");
+ }
+ if ( (sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
+ printf("Sprite is in video memory\n");
+ } else {
+ printf("Sprite is in system memory\n");
+ }
+ /* Run a sample blit to trigger blit acceleration */
+ { SDL_Rect dst;
+ dst.x = 0;
+ dst.y = 0;
+ dst.w = sprite->w;
+ dst.h = sprite->h;
+ SDL_BlitSurface(sprite, NULL, screen, &dst);
+ SDL_FillRect(screen, &dst, background);
+ }
+ if ( (sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
+ printf("Sprite blit uses hardware acceleration\n");
+ }
+ if ( (sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
+ printf("Sprite blit uses RLE acceleration\n");
+ }
+
+ /* Loop, blitting sprites and waiting for a keystroke */
+ frames = 0;
+ then = SDL_GetTicks();
+ done = 0;
+ sprites_visible = 0;
+ while ( !done ) {
+ /* Check for events */
+ ++frames;
+ while ( SDL_PollEvent(&event) ) {
+ switch (event.type) {
+ case SDL_MOUSEBUTTONDOWN:
+ SDL_WarpMouse(screen->w/2, screen->h/2);
+ break;
+ case SDL_KEYDOWN:
+ /* Any keypress quits the app... */
+ case SDL_QUIT:
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ MoveSprites(screen, background);
+ }
+ SDL_FreeSurface(sprite);
+ free(mem);
+
+ /* Print out some timing information */
+ now = SDL_GetTicks();
+ if ( now > then ) {
+ printf("%2.2f frames per second\n",
+ ((double)frames*1000)/(now-then));
+ }
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testtimer.c b/distrib/sdl-1.2.15/test/testtimer.c
new file mode 100644
index 0000000..95608c1
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testtimer.c
@@ -0,0 +1,87 @@
+
+/* Test program to check the resolution of the SDL timer on the current
+ platform
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "SDL.h"
+
+#define DEFAULT_RESOLUTION 1
+
+static int ticks = 0;
+
+static Uint32 SDLCALL ticktock(Uint32 interval)
+{
+ ++ticks;
+ return(interval);
+}
+
+static Uint32 SDLCALL callback(Uint32 interval, void *param)
+{
+ printf("Timer %d : param = %d\n", interval, (int)(uintptr_t)param);
+ return interval;
+}
+
+int main(int argc, char *argv[])
+{
+ int desired;
+ SDL_TimerID t1, t2, t3;
+
+ if ( SDL_Init(SDL_INIT_TIMER) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return(1);
+ }
+
+ /* Start the timer */
+ desired = 0;
+ if ( argv[1] ) {
+ desired = atoi(argv[1]);
+ }
+ if ( desired == 0 ) {
+ desired = DEFAULT_RESOLUTION;
+ }
+ SDL_SetTimer(desired, ticktock);
+
+ /* Wait 10 seconds */
+ printf("Waiting 10 seconds\n");
+ SDL_Delay(10*1000);
+
+ /* Stop the timer */
+ SDL_SetTimer(0, NULL);
+
+ /* Print the results */
+ if ( ticks ) {
+ fprintf(stderr,
+ "Timer resolution: desired = %d ms, actual = %f ms\n",
+ desired, (double)(10*1000)/ticks);
+ }
+
+ /* Test multiple timers */
+ printf("Testing multiple timers...\n");
+ t1 = SDL_AddTimer(100, callback, (void*)1);
+ if(!t1)
+ fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError());
+ t2 = SDL_AddTimer(50, callback, (void*)2);
+ if(!t2)
+ fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError());
+ t3 = SDL_AddTimer(233, callback, (void*)3);
+ if(!t3)
+ fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError());
+
+ /* Wait 10 seconds */
+ printf("Waiting 10 seconds\n");
+ SDL_Delay(10*1000);
+
+ printf("Removing timer 1 and waiting 5 more seconds\n");
+ SDL_RemoveTimer(t1);
+
+ SDL_Delay(5*1000);
+
+ SDL_RemoveTimer(t2);
+ SDL_RemoveTimer(t3);
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testver.c b/distrib/sdl-1.2.15/test/testver.c
new file mode 100644
index 0000000..4f45ffe
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testver.c
@@ -0,0 +1,37 @@
+
+/* Test program to compare the compile-time version of SDL with the linked
+ version of SDL
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "SDL.h"
+
+int main(int argc, char *argv[])
+{
+ SDL_version compiled;
+
+ /* Initialize SDL */
+ if ( SDL_Init(0) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ exit(1);
+ }
+#ifdef DEBUG
+ fprintf(stderr, "SDL initialized\n");
+#endif
+#if SDL_VERSION_ATLEAST(1, 2, 0)
+ printf("Compiled with SDL 1.2 or newer\n");
+#else
+ printf("Compiled with SDL older than 1.2\n");
+#endif
+ SDL_VERSION(&compiled);
+ printf("Compiled version: %d.%d.%d\n",
+ compiled.major, compiled.minor, compiled.patch);
+ printf("Linked version: %d.%d.%d\n",
+ SDL_Linked_Version()->major,
+ SDL_Linked_Version()->minor,
+ SDL_Linked_Version()->patch);
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testvidinfo.c b/distrib/sdl-1.2.15/test/testvidinfo.c
new file mode 100644
index 0000000..bbafeb8
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testvidinfo.c
@@ -0,0 +1,465 @@
+
+/* Simple program -- figure out what kind of video display we have */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+
+#define NUM_BLITS 10
+#define NUM_UPDATES 500
+
+#define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF | \
+ SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCEL | \
+ SDL_RLEACCELOK)
+
+void PrintFlags(Uint32 flags)
+{
+ printf("0x%8.8x", (flags & FLAG_MASK));
+ if ( flags & SDL_HWSURFACE ) {
+ printf(" SDL_HWSURFACE");
+ } else {
+ printf(" SDL_SWSURFACE");
+ }
+ if ( flags & SDL_FULLSCREEN ) {
+ printf(" | SDL_FULLSCREEN");
+ }
+ if ( flags & SDL_DOUBLEBUF ) {
+ printf(" | SDL_DOUBLEBUF");
+ }
+ if ( flags & SDL_SRCCOLORKEY ) {
+ printf(" | SDL_SRCCOLORKEY");
+ }
+ if ( flags & SDL_SRCALPHA ) {
+ printf(" | SDL_SRCALPHA");
+ }
+ if ( flags & SDL_RLEACCEL ) {
+ printf(" | SDL_RLEACCEL");
+ }
+ if ( flags & SDL_RLEACCELOK ) {
+ printf(" | SDL_RLEACCELOK");
+ }
+}
+
+int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount)
+{
+ int i, j;
+ int maxx;
+ int maxy;
+ SDL_Rect dst;
+
+ maxx = (int)screen->w - bmp->w + 1;
+ maxy = (int)screen->h - bmp->h + 1;
+ for ( i = 0; i < NUM_UPDATES; ++i ) {
+ for ( j = 0; j < blitcount; ++j ) {
+ if ( maxx ) {
+ dst.x = rand() % maxx;
+ } else {
+ dst.x = 0;
+ }
+ if ( maxy ) {
+ dst.y = rand() % maxy;
+ } else {
+ dst.y = 0;
+ }
+ dst.w = bmp->w;
+ dst.h = bmp->h;
+ SDL_BlitSurface(bmp, NULL, screen, &dst);
+ }
+ SDL_Flip(screen);
+ }
+
+ return i;
+}
+
+int RunModeTests(SDL_Surface *screen)
+{
+ Uint32 then, now;
+ Uint32 frames;
+ float seconds;
+ int i;
+ Uint8 r, g, b;
+ SDL_Surface *bmp, *bmpcc, *tmp;
+ SDL_Event event;
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_KEYDOWN )
+ return 0;
+ }
+
+ /* First test fills and screen update speed */
+ printf("Running color fill and fullscreen update test\n");
+ then = SDL_GetTicks();
+ frames = 0;
+ for ( i = 0; i < 256; ++i ) {
+ r = i;
+ g = 0;
+ b = 0;
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
+ SDL_Flip(screen);
+ ++frames;
+ }
+ for ( i = 0; i < 256; ++i ) {
+ r = 0;
+ g = i;
+ b = 0;
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
+ SDL_Flip(screen);
+ ++frames;
+ }
+ for ( i = 0; i < 256; ++i ) {
+ r = 0;
+ g = 0;
+ b = i;
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
+ SDL_Flip(screen);
+ ++frames;
+ }
+ now = SDL_GetTicks();
+ seconds = (float)(now - then) / 1000.0f;
+ if ( seconds > 0.0f ) {
+ printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds);
+ } else {
+ printf("%d fills and flips in zero seconds!n", frames);
+ }
+
+ /* clear the screen after fill test */
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+ SDL_Flip(screen);
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_KEYDOWN )
+ return 0;
+ }
+
+ /* run the generic blit test */
+ bmp = SDL_LoadBMP("sample.bmp");
+ if ( ! bmp ) {
+ printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
+ return 0;
+ }
+ printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ",
+ bmp->w, bmp->h, bmp->format->BitsPerPixel);
+ PrintFlags(bmp->flags);
+ printf("\n");
+ then = SDL_GetTicks();
+ frames = RunBlitTests(screen, bmp, NUM_BLITS);
+ now = SDL_GetTicks();
+ seconds = (float)(now - then) / 1000.0f;
+ if ( seconds > 0.0f ) {
+ printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
+ } else {
+ printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
+ }
+
+ /* clear the screen after blit test */
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+ SDL_Flip(screen);
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_KEYDOWN )
+ return 0;
+ }
+
+ /* run the colorkeyed blit test */
+ bmpcc = SDL_LoadBMP("sample.bmp");
+ if ( ! bmpcc ) {
+ printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
+ return 0;
+ }
+ printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ",
+ bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
+ SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels);
+
+ PrintFlags(bmpcc->flags);
+ printf("\n");
+ then = SDL_GetTicks();
+ frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
+ now = SDL_GetTicks();
+ seconds = (float)(now - then) / 1000.0f;
+ if ( seconds > 0.0f ) {
+ printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
+ } else {
+ printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
+ }
+
+ /* clear the screen after cc blit test */
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+ SDL_Flip(screen);
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_KEYDOWN )
+ return 0;
+ }
+
+ /* run the generic blit test */
+ tmp = bmp;
+ bmp = SDL_DisplayFormat(bmp);
+ SDL_FreeSurface(tmp);
+ if ( ! bmp ) {
+ printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
+ return 0;
+ }
+ printf("Running display format blit test: %dx%d at %d bpp, flags: ",
+ bmp->w, bmp->h, bmp->format->BitsPerPixel);
+ PrintFlags(bmp->flags);
+ printf("\n");
+ then = SDL_GetTicks();
+ frames = RunBlitTests(screen, bmp, NUM_BLITS);
+ now = SDL_GetTicks();
+ seconds = (float)(now - then) / 1000.0f;
+ if ( seconds > 0.0f ) {
+ printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
+ } else {
+ printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
+ }
+
+ /* clear the screen after blit test */
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+ SDL_Flip(screen);
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_KEYDOWN )
+ return 0;
+ }
+
+ /* run the colorkeyed blit test */
+ tmp = bmpcc;
+ bmpcc = SDL_DisplayFormat(bmpcc);
+ SDL_FreeSurface(tmp);
+ if ( ! bmpcc ) {
+ printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
+ return 0;
+ }
+ printf("Running display format cc blit test: %dx%d at %d bpp, flags: ",
+ bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
+ PrintFlags(bmpcc->flags);
+ printf("\n");
+ then = SDL_GetTicks();
+ frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
+ now = SDL_GetTicks();
+ seconds = (float)(now - then) / 1000.0f;
+ if ( seconds > 0.0f ) {
+ printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
+ } else {
+ printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
+ }
+
+ /* clear the screen after cc blit test */
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+ SDL_Flip(screen);
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_KEYDOWN )
+ return 0;
+ }
+
+ /* run the alpha blit test only if screen bpp>8 */
+ if (bmp->format->BitsPerPixel>8)
+ {
+ SDL_FreeSurface(bmp);
+ bmp = SDL_LoadBMP("sample.bmp");
+ SDL_SetAlpha(bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */
+ tmp = bmp;
+ bmp = SDL_DisplayFormat(bmp);
+ SDL_FreeSurface(tmp);
+ if ( ! bmp ) {
+ printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
+ return 0;
+ }
+ printf("Running display format alpha blit test: %dx%d at %d bpp, flags: ",
+ bmp->w, bmp->h, bmp->format->BitsPerPixel);
+ PrintFlags(bmp->flags);
+ printf("\n");
+ then = SDL_GetTicks();
+ frames = RunBlitTests(screen, bmp, NUM_BLITS);
+ now = SDL_GetTicks();
+ seconds = (float)(now - then) / 1000.0f;
+ if ( seconds > 0.0f ) {
+ printf("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
+ } else {
+ printf("%d alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
+ }
+ }
+
+ /* clear the screen after alpha blit test */
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+ SDL_Flip(screen);
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_KEYDOWN )
+ return 0;
+ }
+
+ /* run the cc+alpha blit test only if screen bpp>8 */
+ if (bmp->format->BitsPerPixel>8)
+ {
+ SDL_FreeSurface(bmpcc);
+ bmpcc = SDL_LoadBMP("sample.bmp");
+ SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */
+ SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels);
+ tmp = bmpcc;
+ bmpcc = SDL_DisplayFormat(bmpcc);
+ SDL_FreeSurface(tmp);
+ if ( ! bmpcc ) {
+ printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
+ return 0;
+ }
+ printf("Running display format cc+alpha blit test: %dx%d at %d bpp, flags: ",
+ bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
+ PrintFlags(bmpcc->flags);
+ printf("\n");
+ then = SDL_GetTicks();
+ frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
+ now = SDL_GetTicks();
+ seconds = (float)(now - then) / 1000.0f;
+ if ( seconds > 0.0f ) {
+ printf("%d cc+alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
+ } else {
+ printf("%d cc+alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
+ }
+ }
+
+ SDL_FreeSurface(bmpcc);
+ SDL_FreeSurface(bmp);
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_KEYDOWN )
+ return 0;
+ }
+ return 1;
+}
+
+void RunVideoTests()
+{
+ static const struct {
+ int w, h, bpp;
+ } mode_list[] = {
+ { 640, 480, 8 }, { 640, 480, 16 }, { 640, 480, 32 },
+ { 800, 600, 8 }, { 800, 600, 16 }, { 800, 600, 32 },
+ { 1024, 768, 8 }, { 1024, 768, 16 }, { 1024, 768, 32 }
+ };
+ static const Uint32 flags[] = {
+ (SDL_SWSURFACE),
+ (SDL_SWSURFACE | SDL_FULLSCREEN),
+ (SDL_HWSURFACE | SDL_FULLSCREEN),
+ (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
+ };
+ int i, j;
+ SDL_Surface *screen;
+
+ /* Test out several different video mode combinations */
+ SDL_WM_SetCaption("SDL Video Benchmark", "vidtest");
+ SDL_ShowCursor(0);
+ for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) {
+ for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) {
+ printf("===================================\n");
+ printf("Setting video mode: %dx%d at %d bpp, flags: ",
+ mode_list[i].w,
+ mode_list[i].h,
+ mode_list[i].bpp);
+ PrintFlags(flags[j]);
+ printf("\n");
+ screen = SDL_SetVideoMode(mode_list[i].w,
+ mode_list[i].h,
+ mode_list[i].bpp,
+ flags[j]);
+ if ( ! screen ) {
+ printf("Setting video mode failed: %s\n", SDL_GetError());
+ continue;
+ }
+ if ( (screen->flags & FLAG_MASK) != flags[j] ) {
+ printf("Flags didn't match: ");
+ PrintFlags(screen->flags);
+ printf("\n");
+ continue;
+ }
+ if ( ! RunModeTests(screen) ) {
+ return;
+ }
+ }
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ const SDL_VideoInfo *info;
+ int i;
+ SDL_Rect **modes;
+ char driver[128];
+
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr,
+ "Couldn't initialize SDL: %s\n", SDL_GetError());
+ exit(1);
+ }
+ if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
+ printf("Video driver: %s\n", driver);
+ }
+ info = SDL_GetVideoInfo();
+ printf(
+"Current display: %dx%d, %d bits-per-pixel\n",
+ info->current_w, info->current_h, info->vfmt->BitsPerPixel);
+ if ( info->vfmt->palette == NULL ) {
+ printf(" Red Mask = 0x%.8x\n", info->vfmt->Rmask);
+ printf(" Green Mask = 0x%.8x\n", info->vfmt->Gmask);
+ printf(" Blue Mask = 0x%.8x\n", info->vfmt->Bmask);
+ }
+ /* Print available fullscreen video modes */
+ modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
+ if ( modes == (SDL_Rect **)0 ) {
+ printf("No available fullscreen video modes\n");
+ } else
+ if ( modes == (SDL_Rect **)-1 ) {
+ printf("No special fullscreen video modes\n");
+ } else {
+ printf("Fullscreen video modes:\n");
+ for ( i=0; modes[i]; ++i ) {
+ printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel);
+ }
+ }
+ if ( info->wm_available ) {
+ printf("A window manager is available\n");
+ }
+ if ( info->hw_available ) {
+ printf("Hardware surfaces are available (%dK video memory)\n",
+ info->video_mem);
+ }
+ if ( info->blit_hw ) {
+ printf(
+"Copy blits between hardware surfaces are accelerated\n");
+ }
+ if ( info->blit_hw_CC ) {
+ printf(
+"Colorkey blits between hardware surfaces are accelerated\n");
+ }
+ if ( info->blit_hw_A ) {
+ printf(
+"Alpha blits between hardware surfaces are accelerated\n");
+ }
+ if ( info->blit_sw ) {
+ printf(
+"Copy blits from software surfaces to hardware surfaces are accelerated\n");
+ }
+ if ( info->blit_sw_CC ) {
+ printf(
+"Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
+ }
+ if ( info->blit_sw_A ) {
+ printf(
+"Alpha blits from software surfaces to hardware surfaces are accelerated\n");
+ }
+ if ( info->blit_fill ) {
+ printf(
+"Color fills on hardware surfaces are accelerated\n");
+ }
+
+ if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) {
+ RunVideoTests();
+ }
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testwin.c b/distrib/sdl-1.2.15/test/testwin.c
new file mode 100644
index 0000000..261ea99
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testwin.c
@@ -0,0 +1,377 @@
+
+/* Bring up a window and play with it */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define BENCHMARK_SDL
+
+#define NOTICE(X) printf("%s", X);
+
+#include "SDL.h"
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+void DrawPict(SDL_Surface *screen, char *bmpfile,
+ int speedy, int flip, int nofade)
+{
+ SDL_Surface *picture;
+ SDL_Rect dest, update;
+ int i, centered;
+ int ncolors;
+ SDL_Color *colors, *cmap;
+
+ /* Load the image into a surface */
+ if ( bmpfile == NULL ) {
+ bmpfile = "sample.bmp"; /* Sample image */
+ }
+fprintf(stderr, "Loading picture: %s\n", bmpfile);
+ picture = SDL_LoadBMP(bmpfile);
+ if ( picture == NULL ) {
+ fprintf(stderr, "Couldn't load %s: %s\n", bmpfile,
+ SDL_GetError());
+ return;
+ }
+
+ /* Set the display colors -- on a hicolor display this is a no-op */
+ if ( picture->format->palette ) {
+ ncolors = picture->format->palette->ncolors;
+ colors = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
+ cmap = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
+ memcpy(colors, picture->format->palette->colors,
+ ncolors*sizeof(SDL_Color));
+ } else {
+ int r, g, b;
+
+ /* Allocate 256 color palette */
+ ncolors = 256;
+ colors = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
+ cmap = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
+
+ /* Set a 3,3,2 color cube */
+ for ( r=0; r<8; ++r ) {
+ for ( g=0; g<8; ++g ) {
+ for ( b=0; b<4; ++b ) {
+ i = ((r<<5)|(g<<2)|b);
+ colors[i].r = r<<5;
+ colors[i].g = g<<5;
+ colors[i].b = b<<6;
+ }
+ }
+ }
+ }
+NOTICE("testwin: setting colors\n");
+ if ( ! SDL_SetColors(screen, colors, 0, ncolors) &&
+ (screen->format->palette != NULL) ) {
+ fprintf(stderr,
+"Warning: Couldn't set all of the colors, but SDL will map the image\n"
+" (colormap fading will suffer - try the -warp option)\n"
+ );
+ }
+
+ /* Set the screen to black (not really necessary) */
+ if ( SDL_LockSurface(screen) == 0 ) {
+ Uint32 black;
+ Uint8 *pixels;
+
+ black = SDL_MapRGB(screen->format, 0, 0, 0);
+ pixels = (Uint8 *)screen->pixels;
+ for ( i=0; i<screen->h; ++i ) {
+ memset(pixels, black,
+ screen->w*screen->format->BytesPerPixel);
+ pixels += screen->pitch;
+ }
+ SDL_UnlockSurface(screen);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+ }
+
+ /* Display the picture */
+ if ( speedy ) {
+ SDL_Surface *displayfmt;
+
+fprintf(stderr, "Converting picture\n");
+ displayfmt = SDL_DisplayFormat(picture);
+ if ( displayfmt == NULL ) {
+ fprintf(stderr,
+ "Couldn't convert image: %s\n", SDL_GetError());
+ goto done;
+ }
+ SDL_FreeSurface(picture);
+ picture = displayfmt;
+ }
+ printf("(image surface located in %s memory)\n",
+ (picture->flags&SDL_HWSURFACE) ? "video" : "system");
+ centered = (screen->w - picture->w)/2;
+ if ( centered < 0 ) {
+ centered = 0;
+ }
+ dest.y = (screen->h - picture->h)/2;
+ dest.w = picture->w;
+ dest.h = picture->h;
+NOTICE("testwin: moving image\n");
+ for ( i=0; i<=centered; ++i ) {
+ dest.x = i;
+ update = dest;
+ if ( SDL_BlitSurface(picture, NULL, screen, &update) < 0 ) {
+ fprintf(stderr, "Blit failed: %s\n", SDL_GetError());
+ break;
+ }
+ if ( flip ) {
+ SDL_Flip(screen);
+ } else {
+ SDL_UpdateRects(screen, 1, &update);
+ }
+ }
+
+#ifdef SCREENSHOT
+ if ( SDL_SaveBMP(screen, "screen.bmp") < 0 )
+ printf("Couldn't save screen: %s\n", SDL_GetError());
+#endif
+
+#ifndef BENCHMARK_SDL
+ /* Let it sit there for a while */
+ SDL_Delay(5*1000);
+#endif
+ /* Fade the colormap */
+ if ( ! nofade ) {
+ int maxstep;
+ SDL_Color final;
+ SDL_Color palcolors[256];
+ struct {
+ Sint16 r, g, b;
+ } cdist[256];
+
+NOTICE("testwin: fading out...\n");
+ memcpy(cmap, colors, ncolors*sizeof(SDL_Color));
+ maxstep = 32-1;
+ final.r = 0xFF;
+ final.g = 0x00;
+ final.b = 0x00;
+ memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
+ for ( i=0; i<ncolors; ++i ) {
+ cdist[i].r = final.r-palcolors[i].r;
+ cdist[i].g = final.g-palcolors[i].g;
+ cdist[i].b = final.b-palcolors[i].b;
+ }
+ for ( i=0; i<=maxstep/2; ++i ) { /* halfway fade */
+ int c;
+ for ( c=0; c<ncolors; ++c ) {
+ colors[c].r =
+ palcolors[c].r+((cdist[c].r*i))/maxstep;
+ colors[c].g =
+ palcolors[c].g+((cdist[c].g*i))/maxstep;
+ colors[c].b =
+ palcolors[c].b+((cdist[c].b*i))/maxstep;
+ }
+ SDL_SetColors(screen, colors, 0, ncolors);
+ SDL_Delay(1);
+ }
+ final.r = 0x00;
+ final.g = 0x00;
+ final.b = 0x00;
+ memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
+ for ( i=0; i<ncolors; ++i ) {
+ cdist[i].r = final.r-palcolors[i].r;
+ cdist[i].g = final.g-palcolors[i].g;
+ cdist[i].b = final.b-palcolors[i].b;
+ }
+ maxstep /= 2;
+ for ( i=0; i<=maxstep; ++i ) { /* finish fade out */
+ int c;
+ for ( c=0; c<ncolors; ++c ) {
+ colors[c].r =
+ palcolors[c].r+((cdist[c].r*i))/maxstep;
+ colors[c].g =
+ palcolors[c].g+((cdist[c].g*i))/maxstep;
+ colors[c].b =
+ palcolors[c].b+((cdist[c].b*i))/maxstep;
+ }
+ SDL_SetColors(screen, colors, 0, ncolors);
+ SDL_Delay(1);
+ }
+ for ( i=0; i<ncolors; ++i ) {
+ colors[i].r = final.r;
+ colors[i].g = final.g;
+ colors[i].b = final.b;
+ }
+ SDL_SetColors(screen, colors, 0, ncolors);
+NOTICE("testwin: fading in...\n");
+ memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
+ for ( i=0; i<ncolors; ++i ) {
+ cdist[i].r = cmap[i].r-palcolors[i].r;
+ cdist[i].g = cmap[i].g-palcolors[i].g;
+ cdist[i].b = cmap[i].b-palcolors[i].b;
+ }
+ for ( i=0; i<=maxstep; ++i ) { /* 32 step fade in */
+ int c;
+ for ( c=0; c<ncolors; ++c ) {
+ colors[c].r =
+ palcolors[c].r+((cdist[c].r*i))/maxstep;
+ colors[c].g =
+ palcolors[c].g+((cdist[c].g*i))/maxstep;
+ colors[c].b =
+ palcolors[c].b+((cdist[c].b*i))/maxstep;
+ }
+ SDL_SetColors(screen, colors, 0, ncolors);
+ SDL_Delay(1);
+ }
+NOTICE("testwin: fading over\n");
+ }
+
+done:
+ /* Free the picture and return */
+ SDL_FreeSurface(picture);
+ free(colors); free(cmap);
+ return;
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Surface *screen;
+ /* Options */
+ int speedy, flip, nofade;
+ int delay;
+ int w, h;
+ int desired_bpp;
+ Uint32 video_flags;
+#ifdef BENCHMARK_SDL
+ Uint32 then, now;
+#endif
+ /* Set default options and check command-line */
+ speedy = 0;
+ flip = 0;
+ nofade = 0;
+ delay = 1;
+
+#ifdef _WIN32_WCE
+ w = 240;
+ h = 320;
+ desired_bpp = 8;
+ video_flags = SDL_FULLSCREEN;
+#else
+ w = 640;
+ h = 480;
+ desired_bpp = 0;
+ video_flags = 0;
+#endif
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr,
+ "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return(1);
+ }
+
+ while ( argc > 1 ) {
+ if ( strcmp(argv[1], "-speedy") == 0 ) {
+ speedy = 1;
+ argv += 1;
+ argc -= 1;
+ } else
+ if ( strcmp(argv[1], "-nofade") == 0 ) {
+ nofade = 1;
+ argv += 1;
+ argc -= 1;
+ } else
+ if ( strcmp(argv[1], "-delay") == 0 ) {
+ if ( argv[2] ) {
+ delay = atoi(argv[2]);
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -delay option requires an argument\n");
+ quit(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-width") == 0 ) {
+ if ( argv[2] && ((w = atoi(argv[2])) > 0) ) {
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -width option requires an argument\n");
+ quit(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-height") == 0 ) {
+ if ( argv[2] && ((h = atoi(argv[2])) > 0) ) {
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -height option requires an argument\n");
+ quit(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-bpp") == 0 ) {
+ if ( argv[2] ) {
+ desired_bpp = atoi(argv[2]);
+ argv += 2;
+ argc -= 2;
+ } else {
+ fprintf(stderr,
+ "The -bpp option requires an argument\n");
+ quit(1);
+ }
+ } else
+ if ( strcmp(argv[1], "-warp") == 0 ) {
+ video_flags |= SDL_HWPALETTE;
+ argv += 1;
+ argc -= 1;
+ } else
+ if ( strcmp(argv[1], "-hw") == 0 ) {
+ video_flags |= SDL_HWSURFACE;
+ argv += 1;
+ argc -= 1;
+ } else
+ if ( strcmp(argv[1], "-flip") == 0 ) {
+ video_flags |= SDL_DOUBLEBUF;
+ argv += 1;
+ argc -= 1;
+ } else
+ if ( strcmp(argv[1], "-fullscreen") == 0 ) {
+ video_flags |= SDL_FULLSCREEN;
+ argv += 1;
+ argc -= 1;
+ } else
+ break;
+ }
+
+ /* Initialize the display */
+ screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
+ w, h, desired_bpp, SDL_GetError());
+ quit(1);
+ }
+ printf("Set%s %dx%dx%d mode\n",
+ screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
+ screen->w, screen->h, screen->format->BitsPerPixel);
+ printf("(video surface located in %s memory)\n",
+ (screen->flags&SDL_HWSURFACE) ? "video" : "system");
+ if ( screen->flags & SDL_DOUBLEBUF ) {
+ printf("Double-buffering enabled\n");
+ flip = 1;
+ }
+
+ /* Set the window manager title bar */
+ SDL_WM_SetCaption("SDL test window", "testwin");
+
+ /* Do all the drawing work */
+#ifdef BENCHMARK_SDL
+ then = SDL_GetTicks();
+ DrawPict(screen, argv[1], speedy, flip, nofade);
+ now = SDL_GetTicks();
+ printf("Time: %d milliseconds\n", now-then);
+#else
+ DrawPict(screen, argv[1], speedy, flip, nofade);
+#endif
+ SDL_Delay(delay*1000);
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/testwm.c b/distrib/sdl-1.2.15/test/testwm.c
new file mode 100644
index 0000000..9c3c050
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/testwm.c
@@ -0,0 +1,443 @@
+
+/* Test out the window manager interaction functions */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+
+/* Is the cursor visible? */
+static int visible = 1;
+
+static Uint8 video_bpp;
+static Uint32 video_flags;
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+int SetVideoMode(int w, int h)
+{
+ SDL_Surface *screen;
+ int i;
+ Uint8 *buffer;
+ SDL_Color palette[256];
+
+ screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
+ w, h, video_bpp, SDL_GetError());
+ return(-1);
+ }
+ printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
+ "fullscreen" : "windowed");
+
+ /* Set the surface pixels and refresh! */
+ for ( i=0; i<256; ++i ) {
+ palette[i].r = 255-i;
+ palette[i].g = 255-i;
+ palette[i].b = 255-i;
+ }
+ SDL_SetColors(screen, palette, 0, 256);
+ if ( SDL_LockSurface(screen) < 0 ) {
+ fprintf(stderr, "Couldn't lock display surface: %s\n",
+ SDL_GetError());
+ return(-1);
+ }
+ buffer = (Uint8 *)screen->pixels;
+ for ( i=0; i<screen->h; ++i ) {
+ memset(buffer,(i*255)/screen->h,
+ screen->w*screen->format->BytesPerPixel);
+ buffer += screen->pitch;
+ }
+ SDL_UnlockSurface(screen);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+ return(0);
+}
+
+SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
+{
+ SDL_Surface *icon;
+ Uint8 *pixels;
+ Uint8 *mask;
+ int mlen, i, j;
+
+ *maskp = NULL;
+
+ /* Load the icon surface */
+ icon = SDL_LoadBMP(file);
+ if ( icon == NULL ) {
+ fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
+ return(NULL);
+ }
+
+ /* Check width and height
+ if ( (icon->w%8) != 0 ) {
+ fprintf(stderr, "Icon width must be a multiple of 8!\n");
+ SDL_FreeSurface(icon);
+ return(NULL);
+ }
+*/
+
+
+ if ( icon->format->palette == NULL ) {
+ fprintf(stderr, "Icon must have a palette!\n");
+ SDL_FreeSurface(icon);
+ return(NULL);
+ }
+
+ /* Set the colorkey */
+ SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *)icon->pixels));
+
+ /* Create the mask */
+ pixels = (Uint8 *)icon->pixels;
+ printf("Transparent pixel: (%d,%d,%d)\n",
+ icon->format->palette->colors[*pixels].r,
+ icon->format->palette->colors[*pixels].g,
+ icon->format->palette->colors[*pixels].b);
+ mlen = (icon->w*icon->h + 7) / 8;
+ mask = (Uint8 *)malloc(mlen);
+ if ( mask == NULL ) {
+ fprintf(stderr, "Out of memory!\n");
+ SDL_FreeSurface(icon);
+ return(NULL);
+ }
+ memset(mask, 0, mlen);
+ for ( i=0; i < icon->h; i++)
+ for (j=0; j < icon->w; j++) {
+ int pindex = i * icon->pitch + j;
+ int mindex = i * icon->w + j;
+ if ( pixels[pindex] != *pixels )
+ mask[mindex>>3] |= 1 << (7 - (mindex & 7));
+ }
+ *maskp = mask;
+ return(icon);
+}
+
+void HotKey_ToggleFullScreen(void)
+{
+ SDL_Surface *screen;
+
+ screen = SDL_GetVideoSurface();
+ if ( SDL_WM_ToggleFullScreen(screen) ) {
+ printf("Toggled fullscreen mode - now %s\n",
+ (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
+ } else {
+ printf("Unable to toggle fullscreen mode\n");
+ video_flags ^= SDL_FULLSCREEN;
+ SetVideoMode(screen->w, screen->h);
+ }
+}
+
+void HotKey_ToggleGrab(void)
+{
+ SDL_GrabMode mode;
+
+ printf("Ctrl-G: toggling input grab!\n");
+ mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
+ if ( mode == SDL_GRAB_ON ) {
+ printf("Grab was on\n");
+ } else {
+ printf("Grab was off\n");
+ }
+ mode = SDL_WM_GrabInput(mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
+ if ( mode == SDL_GRAB_ON ) {
+ printf("Grab is now on\n");
+ } else {
+ printf("Grab is now off\n");
+ }
+}
+
+void HotKey_Iconify(void)
+{
+ printf("Ctrl-Z: iconifying window!\n");
+ SDL_WM_IconifyWindow();
+}
+
+void HotKey_Quit(void)
+{
+ SDL_Event event;
+
+ printf("Posting internal quit request\n");
+ event.type = SDL_USEREVENT;
+ SDL_PushEvent(&event);
+}
+
+static void print_modifiers(void)
+{
+ int mod;
+ printf(" modifiers:");
+ mod = SDL_GetModState();
+ if(!mod) {
+ printf(" (none)");
+ return;
+ }
+ if(mod & KMOD_LSHIFT)
+ printf(" LSHIFT");
+ if(mod & KMOD_RSHIFT)
+ printf(" RSHIFT");
+ if(mod & KMOD_LCTRL)
+ printf(" LCTRL");
+ if(mod & KMOD_RCTRL)
+ printf(" RCTRL");
+ if(mod & KMOD_LALT)
+ printf(" LALT");
+ if(mod & KMOD_RALT)
+ printf(" RALT");
+ if(mod & KMOD_LMETA)
+ printf(" LMETA");
+ if(mod & KMOD_RMETA)
+ printf(" RMETA");
+ if(mod & KMOD_NUM)
+ printf(" NUM");
+ if(mod & KMOD_CAPS)
+ printf(" CAPS");
+ if(mod & KMOD_MODE)
+ printf(" MODE");
+}
+
+static void PrintKey(const SDL_keysym *sym, int pressed)
+{
+ /* Print the keycode, name and state */
+ if ( sym->sym ) {
+ printf("Key %s: %d-%s ", pressed ? "pressed" : "released",
+ sym->sym, SDL_GetKeyName(sym->sym));
+ } else {
+ printf("Unknown Key (scancode = %d) %s ", sym->scancode,
+ pressed ? "pressed" : "released");
+ }
+
+ /* Print the translated character, if one exists */
+ if ( sym->unicode ) {
+ /* Is it a control-character? */
+ if ( sym->unicode < ' ' ) {
+ printf(" (^%c)", sym->unicode+'@');
+ } else {
+#ifdef UNICODE
+ printf(" (%c)", sym->unicode);
+#else
+ /* This is a Latin-1 program, so only show 8-bits */
+ if ( !(sym->unicode & 0xFF00) )
+ printf(" (%c)", sym->unicode);
+ else
+ printf(" (0x%X)", sym->unicode);
+#endif
+ }
+ }
+ print_modifiers();
+ printf("\n");
+}
+
+int SDLCALL FilterEvents(const SDL_Event *event)
+{
+ static int reallyquit = 0;
+
+ switch (event->type) {
+
+ case SDL_ACTIVEEVENT:
+ /* See what happened */
+ printf("App %s ",
+ 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 ");
+ printf("focus\n");
+
+ /* See if we are iconified or restored */
+ if ( event->active.state & SDL_APPACTIVE ) {
+ printf("App has been %s\n",
+ event->active.gain ?
+ "restored" : "iconified");
+ }
+ return(0);
+
+ /* We want to toggle visibility on buttonpress */
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ if ( event->button.state == SDL_PRESSED ) {
+ visible = !visible;
+ SDL_ShowCursor(visible);
+ }
+ printf("Mouse button %d has been %s\n",
+ event->button.button,
+ (event->button.state == SDL_PRESSED) ?
+ "pressed" : "released");
+ return(0);
+
+ /* Show relative mouse motion */
+ case SDL_MOUSEMOTION:
+#if 0
+ printf("Mouse motion: {%d,%d} (%d,%d)\n",
+ event->motion.x, event->motion.y,
+ event->motion.xrel, event->motion.yrel);
+#endif
+ return(0);
+
+ case SDL_KEYDOWN:
+ PrintKey(&event->key.keysym, 1);
+ if ( event->key.keysym.sym == SDLK_ESCAPE ) {
+ HotKey_Quit();
+ }
+ if ( (event->key.keysym.sym == SDLK_g) &&
+ (event->key.keysym.mod & KMOD_CTRL) ) {
+ HotKey_ToggleGrab();
+ }
+ if ( (event->key.keysym.sym == SDLK_z) &&
+ (event->key.keysym.mod & KMOD_CTRL) ) {
+ HotKey_Iconify();
+ }
+ if ( (event->key.keysym.sym == SDLK_RETURN) &&
+ (event->key.keysym.mod & KMOD_ALT) ) {
+ HotKey_ToggleFullScreen();
+ }
+ return(0);
+
+ case SDL_KEYUP:
+ PrintKey(&event->key.keysym, 0);
+ return(0);
+
+ /* Pass the video resize event through .. */
+ case SDL_VIDEORESIZE:
+ return(1);
+
+ /* This is important! Queue it if we want to quit. */
+ case SDL_QUIT:
+ if ( ! reallyquit ) {
+ reallyquit = 1;
+ printf("Quit requested\n");
+ return(0);
+ }
+ printf("Quit demanded\n");
+ return(1);
+
+ /* This will never happen because events queued directly
+ to the event queue are not filtered.
+ */
+ case SDL_USEREVENT:
+ return(1);
+
+ /* Drop all other events */
+ default:
+ return(0);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Event event;
+ char *title;
+ SDL_Surface *icon;
+ Uint8 *icon_mask;
+ int parsed;
+ int w, h;
+
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr,
+ "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return(1);
+ }
+
+ /* Check command line arguments */
+ w = 640;
+ h = 480;
+ video_bpp = 8;
+ video_flags = SDL_SWSURFACE;
+ parsed = 1;
+ while ( parsed ) {
+ if ( (argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0) ) {
+ video_flags |= SDL_FULLSCREEN;
+ argc -= 1;
+ argv += 1;
+ } else
+ if ( (argc >= 2) && (strcmp(argv[1], "-resize") == 0) ) {
+ video_flags |= SDL_RESIZABLE;
+ argc -= 1;
+ argv += 1;
+ } else
+ if ( (argc >= 2) && (strcmp(argv[1], "-noframe") == 0) ) {
+ video_flags |= SDL_NOFRAME;
+ argc -= 1;
+ argv += 1;
+ } else
+ if ( (argc >= 3) && (strcmp(argv[1], "-width") == 0) ) {
+ w = atoi(argv[2]);
+ argc -= 2;
+ argv += 2;
+ } else
+ if ( (argc >= 3) && (strcmp(argv[1], "-height") == 0) ) {
+ h = atoi(argv[2]);
+ argc -= 2;
+ argv += 2;
+ } else
+ if ( (argc >= 3) && (strcmp(argv[1], "-bpp") == 0) ) {
+ video_bpp = atoi(argv[2]);
+ argc -= 2;
+ argv += 2;
+ } else {
+ parsed = 0;
+ }
+ }
+
+ /* Set the icon -- this must be done before the first mode set */
+ icon = LoadIconSurface("icon.bmp", &icon_mask);
+ if ( icon != NULL ) {
+ SDL_WM_SetIcon(icon, icon_mask);
+ }
+ if ( icon_mask != NULL )
+ free(icon_mask);
+
+ /* Set the title bar */
+ if ( argv[1] == NULL )
+ title = "Testing 1.. 2.. 3...";
+ else
+ title = argv[1];
+ SDL_WM_SetCaption(title, "testwm");
+
+ /* See if it's really set */
+ SDL_WM_GetCaption(&title, NULL);
+ if ( title )
+ printf("Title was set to: %s\n", title);
+ else
+ printf("No window title was set!\n");
+
+ /* Initialize the display */
+ if ( SetVideoMode(w, h) < 0 ) {
+ quit(1);
+ }
+
+ /* Set an event filter that discards everything but QUIT */
+ SDL_SetEventFilter(FilterEvents);
+
+ /* Loop, waiting for QUIT */
+ while ( SDL_WaitEvent(&event) ) {
+ switch (event.type) {
+ case SDL_VIDEORESIZE:
+ printf("Got a resize event: %dx%d\n",
+ event.resize.w, event.resize.h);
+ SetVideoMode(event.resize.w, event.resize.h);
+ break;
+ case SDL_USEREVENT:
+ printf("Handling internal quit request\n");
+ /* Fall through to the quit handler */
+ case SDL_QUIT:
+ printf("Bye bye..\n");
+ quit(0);
+ default:
+ /* This should never happen */
+ printf("Warning: Event %d wasn't filtered\n",
+ event.type);
+ break;
+ }
+ }
+ printf("SDL_WaitEvent() error: %s\n", SDL_GetError());
+ SDL_Quit();
+ return(255);
+}
diff --git a/distrib/sdl-1.2.15/test/threadwin.c b/distrib/sdl-1.2.15/test/threadwin.c
new file mode 100644
index 0000000..c704b30
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/threadwin.c
@@ -0,0 +1,338 @@
+
+/* Test out the multi-threaded event handling functions */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "SDL.h"
+#include "SDL_thread.h"
+
+/* Are we done yet? */
+static int done = 0;
+
+/* Is the cursor visible? */
+static int visible = 1;
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
+{
+ SDL_Surface *icon;
+ Uint8 *pixels;
+ Uint8 *mask;
+ int mlen, i;
+
+ *maskp = NULL;
+
+ /* Load the icon surface */
+ icon = SDL_LoadBMP(file);
+ if ( icon == NULL ) {
+ fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
+ return(NULL);
+ }
+
+ /* Check width and height */
+ if ( (icon->w%8) != 0 ) {
+ fprintf(stderr, "Icon width must be a multiple of 8!\n");
+ SDL_FreeSurface(icon);
+ return(NULL);
+ }
+ if ( icon->format->palette == NULL ) {
+ fprintf(stderr, "Icon must have a palette!\n");
+ SDL_FreeSurface(icon);
+ return(NULL);
+ }
+
+ /* Set the colorkey */
+ SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *)icon->pixels));
+
+ /* Create the mask */
+ pixels = (Uint8 *)icon->pixels;
+ printf("Transparent pixel: (%d,%d,%d)\n",
+ icon->format->palette->colors[*pixels].r,
+ icon->format->palette->colors[*pixels].g,
+ icon->format->palette->colors[*pixels].b);
+ mlen = icon->w*icon->h;
+ mask = (Uint8 *)malloc(mlen/8);
+ if ( mask == NULL ) {
+ fprintf(stderr, "Out of memory!\n");
+ SDL_FreeSurface(icon);
+ return(NULL);
+ }
+ memset(mask, 0, mlen/8);
+ for ( i=0; i<mlen; ) {
+ if ( pixels[i] != *pixels )
+ mask[i/8] |= 0x01;
+ ++i;
+ if ( (i%8) != 0 )
+ mask[i/8] <<= 1;
+ }
+ *maskp = mask;
+ return(icon);
+}
+
+int SDLCALL FilterEvents(const SDL_Event *event)
+{
+ static int reallyquit = 0;
+
+ switch (event->type) {
+
+ case SDL_ACTIVEEVENT:
+ /* See what happened */
+ printf("App %s ",
+ event->active.gain ? "gained" : "lost");
+ if ( event->active.state & SDL_APPACTIVE )
+ printf("active ");
+ 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 */
+ if ( event->active.state & SDL_APPACTIVE ) {
+ printf("App has been %s\n",
+ event->active.gain ?
+ "restored" : "iconified");
+ }
+ return(0);
+
+ /* This is important! Queue it if we want to quit. */
+ case SDL_QUIT:
+ if ( ! reallyquit ) {
+ reallyquit = 1;
+ printf("Quit requested\n");
+ return(0);
+ }
+ printf("Quit demanded\n");
+ return(1);
+
+ /* Mouse and keyboard events go to threads */
+ case SDL_MOUSEMOTION:
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ case SDL_KEYDOWN:
+ case SDL_KEYUP:
+ return(1);
+
+ /* Drop all other events */
+ default:
+ return(0);
+ }
+}
+
+int SDLCALL HandleMouse(void *unused)
+{
+ SDL_Event events[10];
+ int i, found;
+ Uint32 mask;
+
+ /* Handle mouse events here */
+ mask = (SDL_MOUSEMOTIONMASK|SDL_MOUSEBUTTONDOWNMASK|SDL_MOUSEBUTTONUPMASK);
+ while ( ! done ) {
+ found = SDL_PeepEvents(events, 10, SDL_GETEVENT, mask);
+ for ( i=0; i<found; ++i ) {
+ switch(events[i].type) {
+ /* We want to toggle visibility on buttonpress */
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ if ( events[i].button.state == SDL_PRESSED ) {
+ visible = !visible;
+ SDL_ShowCursor(visible);
+ }
+ printf("Mouse button %d has been %s\n",
+ events[i].button.button,
+ (events[i].button.state == SDL_PRESSED) ?
+ "pressed" : "released");
+ break;
+ /* Show relative mouse motion */
+ case SDL_MOUSEMOTION:
+ printf("Mouse relative motion: {%d,%d}\n",
+ events[i].motion.xrel, events[i].motion.yrel);
+ break;
+ }
+ }
+ /* Give up some CPU to allow events to arrive */
+ SDL_Delay(20);
+ }
+ return(0);
+}
+
+int SDLCALL HandleKeyboard(void *unused)
+{
+ SDL_Event events[10];
+ int i, found;
+ Uint32 mask;
+
+ /* Handle mouse events here */
+ mask = (SDL_KEYDOWNMASK|SDL_KEYUPMASK);
+ while ( ! done ) {
+ found = SDL_PeepEvents(events, 10, SDL_GETEVENT, mask);
+ for ( i=0; i<found; ++i ) {
+ switch(events[i].type) {
+ /* We want to toggle visibility on buttonpress */
+ case SDL_KEYDOWN:
+ case SDL_KEYUP:
+ printf("Key '%c' (keysym==%d) has been %s\n",
+ events[i].key.keysym.unicode,
+ (int) events[i].key.keysym.sym,
+ (events[i].key.state == SDL_PRESSED) ?
+ "pressed" : "released");
+
+ /* Allow hitting <ESC> to quit the app */
+ if ( events[i].key.keysym.sym == SDLK_ESCAPE ) {
+ done = 1;
+ }
+
+ /* skip events now that aren't KEYUPs... */
+ if (events[i].key.state == SDL_PRESSED)
+ break;
+
+ if ( events[i].key.keysym.sym == SDLK_f ) {
+ int rc = 0;
+ printf("attempting to toggle fullscreen...\n");
+ rc = SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
+ printf("SDL_WM_ToggleFullScreen returned %d.\n", rc);
+ }
+
+ if ( events[i].key.keysym.sym == SDLK_g ) {
+ SDL_GrabMode m;
+ m = SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON ?
+ SDL_GRAB_OFF : SDL_GRAB_ON;
+ printf("attempting to toggle input grab to %s...\n",
+ m == SDL_GRAB_ON ? "ON" : "OFF");
+ SDL_WM_GrabInput(m);
+ printf("attempt finished.\n");
+ }
+
+ break;
+ }
+ }
+ /* Give up some CPU to allow events to arrive */
+ SDL_Delay(20);
+ }
+ return(0);
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Surface *screen;
+ SDL_Surface *icon;
+ Uint8 *icon_mask;
+ int i, parsed;
+ Uint8 *buffer;
+ SDL_Color palette[256];
+ Uint32 init_flags;
+ Uint8 video_bpp;
+ Uint32 video_flags;
+ SDL_Thread *mouse_thread;
+ SDL_Thread *keybd_thread;
+
+ /* Set the options, based on command line arguments */
+ init_flags = SDL_INIT_VIDEO;
+ video_bpp = 8;
+ video_flags = SDL_SWSURFACE;
+ parsed = 1;
+ while ( parsed ) {
+ /* If the threaded option is enabled, and the SDL library hasn't
+ been compiled with threaded events enabled, then the mouse and
+ keyboard won't respond.
+ */
+ if ( (argc >= 2) && (strcmp(argv[1], "-threaded") == 0) ) {
+ init_flags |= SDL_INIT_EVENTTHREAD;
+ argc -= 1;
+ argv += 1;
+ printf("Running with threaded events\n");
+ } else
+ if ( (argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0) ) {
+ video_flags |= SDL_FULLSCREEN;
+ argc -= 1;
+ argv += 1;
+ } else
+ if ( (argc >= 3) && (strcmp(argv[1], "-bpp") == 0) ) {
+ video_bpp = atoi(argv[2]);
+ argc -= 2;
+ argv += 2;
+ } else {
+ parsed = 0;
+ }
+ }
+
+ /* Initialize SDL with the requested flags */
+ if ( SDL_Init(init_flags) < 0 ) {
+ fprintf(stderr,
+ "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return(1);
+ }
+
+ /* Set the icon -- this must be done before the first mode set */
+ icon = LoadIconSurface("icon.bmp", &icon_mask);
+ if ( icon != NULL ) {
+ SDL_WM_SetIcon(icon, icon_mask);
+ }
+ if ( icon_mask != NULL )
+ free(icon_mask);
+
+ /* Initialize the display */
+ screen = SDL_SetVideoMode(640, 480, video_bpp, video_flags);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
+ video_bpp, SDL_GetError());
+ quit(1);
+ }
+ printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
+ "fullscreen" : "windowed");
+
+ /* Enable printable characters */
+ SDL_EnableUNICODE(1);
+
+ /* Set an event filter that discards everything but QUIT */
+ SDL_SetEventFilter(FilterEvents);
+
+ /* Create the event handling threads */
+ mouse_thread = SDL_CreateThread(HandleMouse, NULL);
+ keybd_thread = SDL_CreateThread(HandleKeyboard, NULL);
+
+ /* Set the surface pixels and refresh! */
+ for ( i=0; i<256; ++i ) {
+ palette[i].r = 255-i;
+ palette[i].g = 255-i;
+ palette[i].b = 255-i;
+ }
+ SDL_SetColors(screen, palette, 0, 256);
+ if ( SDL_LockSurface(screen) < 0 ) {
+ fprintf(stderr, "Couldn't lock display surface: %s\n",
+ SDL_GetError());
+ quit(2);
+ }
+ buffer = (Uint8 *)screen->pixels;
+ for ( i=0; i<screen->h; ++i ) {
+ memset(buffer,(i*255)/screen->h,
+ screen->w*screen->format->BytesPerPixel);
+ buffer += screen->pitch;
+ }
+ SDL_UnlockSurface(screen);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+ /* Loop, waiting for QUIT */
+ while ( ! done ) {
+ if ( ! (init_flags & SDL_INIT_EVENTTHREAD) ) {
+ SDL_PumpEvents(); /* Needed when event thread is off */
+ }
+ if ( SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUITMASK) ) {
+ done = 1;
+ }
+ /* Give up some CPU so the events can accumulate */
+ SDL_Delay(20);
+ }
+ SDL_WaitThread(mouse_thread, NULL);
+ SDL_WaitThread(keybd_thread, NULL);
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/torturethread.c b/distrib/sdl-1.2.15/test/torturethread.c
new file mode 100644
index 0000000..cb18954
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/torturethread.c
@@ -0,0 +1,91 @@
+
+/* Simple test of the SDL threading code */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+
+#include "SDL.h"
+#include "SDL_thread.h"
+
+#define NUMTHREADS 10
+
+static char volatile time_for_threads_to_die[NUMTHREADS];
+
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+ SDL_Quit();
+ exit(rc);
+}
+
+int SDLCALL SubThreadFunc(void *data) {
+ while(! *(int volatile *)data) {
+ ; /*SDL_Delay(10);*/ /* do nothing */
+ }
+ return 0;
+}
+
+int SDLCALL ThreadFunc(void *data) {
+ SDL_Thread *sub_threads[NUMTHREADS];
+ int flags[NUMTHREADS];
+ int i;
+ int tid = (int)(uintptr_t)data;
+
+ fprintf(stderr, "Creating Thread %d\n", tid);
+
+ for(i = 0; i < NUMTHREADS; i++) {
+ flags[i] = 0;
+ sub_threads[i] = SDL_CreateThread(SubThreadFunc, &flags[i]);
+ }
+
+ printf("Thread '%d' waiting for signal\n", tid);
+ while(time_for_threads_to_die[tid] != 1) {
+ ; /* do nothing */
+ }
+
+ printf("Thread '%d' sending signals to subthreads\n", tid);
+ for(i = 0; i < NUMTHREADS; i++) {
+ flags[i] = 1;
+ SDL_WaitThread(sub_threads[i], NULL);
+ }
+
+ printf("Thread '%d' exiting!\n", tid);
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Thread *threads[NUMTHREADS];
+ int i;
+
+ /* Load the SDL library */
+ if ( SDL_Init(0) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ signal(SIGSEGV, SIG_DFL);
+ for(i = 0; i < NUMTHREADS; i++) {
+ time_for_threads_to_die[i] = 0;
+ threads[i] = SDL_CreateThread(ThreadFunc, (void *)(uintptr_t)i);
+
+ if ( threads[i] == NULL ) {
+ fprintf(stderr,
+ "Couldn't create thread: %s\n", SDL_GetError());
+ quit(1);
+ }
+ }
+
+ for(i = 0; i < NUMTHREADS; i++) {
+ time_for_threads_to_die[i] = 1;
+ }
+
+ for(i = 0; i < NUMTHREADS; i++) {
+ SDL_WaitThread(threads[i], NULL);
+ }
+ SDL_Quit();
+ return(0);
+}
diff --git a/distrib/sdl-1.2.15/test/utf8.txt b/distrib/sdl-1.2.15/test/utf8.txt
new file mode 100644
index 0000000..aab22f1
--- /dev/null
+++ b/distrib/sdl-1.2.15/test/utf8.txt
@@ -0,0 +1,287 @@
+UTF-8 decoder capability and stress test
+----------------------------------------
+
+Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/> - 2003-02-19
+
+This test file can help you examine, how your UTF-8 decoder handles
+various types of correct, malformed, or otherwise interesting UTF-8
+sequences. This file is not meant to be a conformance test. It does
+not prescribes any particular outcome and therefore there is no way to
+"pass" or "fail" this test file, even though the texts suggests a
+preferable decoder behaviour at some places. The aim is instead to
+help you think about and test the behaviour of your UTF-8 on a
+systematic collection of unusual inputs. Experience so far suggests
+that most first-time authors of UTF-8 decoders find at least one
+serious problem in their decoder by using this file.
+
+The test lines below cover boundary conditions, malformed UTF-8
+sequences as well as correctly encoded UTF-8 sequences of Unicode code
+points that should never occur in a correct UTF-8 file.
+
+According to ISO 10646-1:2000, sections D.7 and 2.3c, a device
+receiving UTF-8 shall interpret a "malformed sequence in the same way
+that it interprets a character that is outside the adopted subset" and
+"characters that are not within the adopted subset shall be indicated
+to the user" by a receiving device. A quite commonly used approach in
+UTF-8 decoders is to replace any malformed UTF-8 sequence by a
+replacement character (U+FFFD), which looks a bit like an inverted
+question mark, or a similar symbol. It might be a good idea to
+visually distinguish a malformed UTF-8 sequence from a correctly
+encoded Unicode character that is just not available in the current
+font but otherwise fully legal, even though ISO 10646-1 doesn't
+mandate this. In any case, just ignoring malformed sequences or
+unavailable characters does not conform to ISO 10646, will make
+debugging more difficult, and can lead to user confusion.
+
+Please check, whether a malformed UTF-8 sequence is (1) represented at
+all, (2) represented by exactly one single replacement character (or
+equivalent signal), and (3) the following quotation mark after an
+illegal UTF-8 sequence is correctly displayed, i.e. proper
+resynchronization takes place immageately after any malformed
+sequence. This file says "THE END" in the last line, so if you don't
+see that, your decoder crashed somehow before, which should always be
+cause for concern.
+
+All lines in this file are exactly 79 characters long (plus the line
+feed). In addition, all lines end with "|", except for the two test
+lines 2.1.1 and 2.2.1, which contain non-printable ASCII controls
+U+0000 and U+007F. If you display this file with a fixed-width font,
+these "|" characters should all line up in column 79 (right margin).
+This allows you to test quickly, whether your UTF-8 decoder finds the
+correct number of characters in every line, that is whether each
+malformed sequences is replaced by a single replacement character.
+
+Note that as an alternative to the notion of malformed sequence used
+here, it is also a perfectly acceptable (and in some situations even
+preferable) solution to represent each individual byte of a malformed
+sequence by a replacement character. If you follow this strategy in
+your decoder, then please ignore the "|" column.
+
+
+Here come the tests: |
+ |
+1 Some correct UTF-8 text |
+ |
+(The codepoints for this test are: |
+ U+03BA U+1F79 U+03C3 U+03BC U+03B5 --ryan.) |
+ |
+You should see the Greek word 'kosme': "κόσμε" |
+ |
+ |
+2 Boundary condition test cases |
+ |
+2.1 First possible sequence of a certain length |
+ |
+(byte zero skipped...there's a null added at the end of the test. --ryan.) |
+ |
+2.1.2 2 bytes (U-00000080): "€" |
+2.1.3 3 bytes (U-00000800): "ࠀ" |
+2.1.4 4 bytes (U-00010000): "𐀀" |
+ |
+(5 and 6 byte sequences were made illegal in rfc3629. --ryan.) |
+2.1.5 5 bytes (U-00200000): "" |
+2.1.6 6 bytes (U-04000000): "" |
+ |
+2.2 Last possible sequence of a certain length |
+ |
+2.2.1 1 byte (U-0000007F): "" |
+2.2.2 2 bytes (U-000007FF): "߿" |
+ |
+(Section 5.3.2 below calls this illegal. --ryan.) |
+2.2.3 3 bytes (U-0000FFFF): "￿" |
+ |
+(5 and 6 bytes sequences, and 4 bytes sequences > 0x10FFFF were made illegal |
+ in rfc3629, so these next three should be replaced with a invalid |
+ character codepoint. --ryan.) |
+2.2.4 4 bytes (U-001FFFFF): "" |
+2.2.5 5 bytes (U-03FFFFFF): "" |
+2.2.6 6 bytes (U-7FFFFFFF): "" |
+ |
+2.3 Other boundary conditions |
+ |
+2.3.1 U-0000D7FF = ed 9f bf = "퟿" |
+2.3.2 U-0000E000 = ee 80 80 = "" |
+2.3.3 U-0000FFFD = ef bf bd = "�" |
+2.3.4 U-0010FFFF = f4 8f bf bf = "􏿿" |
+ |
+(This one is bogus in rfc3629. --ryan.) |
+2.3.5 U-00110000 = f4 90 80 80 = "" |
+ |
+3 Malformed sequences |
+ |
+3.1 Unexpected continuation bytes |
+ |
+Each unexpected continuation byte should be separately signalled as a |
+malformed sequence of its own. |
+ |
+3.1.1 First continuation byte 0x80: "" |
+3.1.2 Last continuation byte 0xbf: "" |
+ |
+3.1.3 2 continuation bytes: "" |
+3.1.4 3 continuation bytes: "" |
+3.1.5 4 continuation bytes: "" |
+3.1.6 5 continuation bytes: "" |
+3.1.7 6 continuation bytes: "" |
+3.1.8 7 continuation bytes: "" |
+ |
+3.1.9 Sequence of all 64 possible continuation bytes (0x80-0xbf): |
+ |
+ " |
+ |
+ |
+ " |
+ |
+3.2 Lonely start characters |
+ |
+3.2.1 All 32 first bytes of 2-byte sequences (0xc0-0xdf), |
+ each followed by a space character: |
+ |
+ " |
+ " |
+ |
+3.2.2 All 16 first bytes of 3-byte sequences (0xe0-0xef), |
+ each followed by a space character: |
+ |
+ " " |
+ |
+3.2.3 All 8 first bytes of 4-byte sequences (0xf0-0xf7), |
+ each followed by a space character: |
+ |
+ " " |
+ |
+3.2.4 All 4 first bytes of 5-byte sequences (0xf8-0xfb), |
+ each followed by a space character: |
+ |
+ " " |
+ |
+3.2.5 All 2 first bytes of 6-byte sequences (0xfc-0xfd), |
+ each followed by a space character: |
+ |
+ " " |
+ |
+3.3 Sequences with last continuation byte missing |
+ |
+All bytes of an incomplete sequence should be signalled as a single |
+malformed sequence, i.e., you should see only a single replacement |
+character in each of the next 10 tests. (Characters as in section 2) |
+ |
+3.3.1 2-byte sequence with last byte missing (U+0000): "" |
+3.3.2 3-byte sequence with last byte missing (U+0000): "" |
+3.3.3 4-byte sequence with last byte missing (U+0000): "" |
+3.3.4 5-byte sequence with last byte missing (U+0000): "" |
+3.3.5 6-byte sequence with last byte missing (U+0000): "" |
+3.3.6 2-byte sequence with last byte missing (U-000007FF): "" |
+3.3.7 3-byte sequence with last byte missing (U-0000FFFF): "" |
+3.3.8 4-byte sequence with last byte missing (U-001FFFFF): "" |
+3.3.9 5-byte sequence with last byte missing (U-03FFFFFF): "" |
+3.3.10 6-byte sequence with last byte missing (U-7FFFFFFF): "" |
+ |
+3.4 Concatenation of incomplete sequences |
+ |
+All the 10 sequences of 3.3 concatenated, you should see 10 malformed |
+sequences being signalled: |
+ |
+ "" |
+ |
+3.5 Impossible bytes |
+ |
+The following two bytes cannot appear in a correct UTF-8 string |
+ |
+3.5.1 fe = "" |
+3.5.2 ff = "" |
+3.5.3 fe fe ff ff = "" |
+ |
+4 Overlong sequences |
+ |
+The following sequences are not malformed according to the letter of |
+the Unicode 2.0 standard. However, they are longer then necessary and |
+a correct UTF-8 encoder is not allowed to produce them. A "safe UTF-8 |
+decoder" should reject them just like malformed sequences for two |
+reasons: (1) It helps to debug applications if overlong sequences are |
+not treated as valid representations of characters, because this helps |
+to spot problems more quickly. (2) Overlong sequences provide |
+alternative representations of characters, that could maliciously be |
+used to bypass filters that check only for ASCII characters. For |
+instance, a 2-byte encoded line feed (LF) would not be caught by a |
+line counter that counts only 0x0a bytes, but it would still be |
+processed as a line feed by an unsafe UTF-8 decoder later in the |
+pipeline. From a security point of view, ASCII compatibility of UTF-8 |
+sequences means also, that ASCII characters are *only* allowed to be |
+represented by ASCII bytes in the range 0x00-0x7f. To ensure this |
+aspect of ASCII compatibility, use only "safe UTF-8 decoders" that |
+reject overlong UTF-8 sequences for which a shorter encoding exists. |
+ |
+4.1 Examples of an overlong ASCII character |
+ |
+With a safe UTF-8 decoder, all of the following five overlong |
+representations of the ASCII character slash ("/") should be rejected |
+like a malformed UTF-8 sequence, for instance by substituting it with |
+a replacement character. If you see a slash below, you do not have a |
+safe UTF-8 decoder! |
+ |
+4.1.1 U+002F = c0 af = "" |
+4.1.2 U+002F = e0 80 af = "" |
+4.1.3 U+002F = f0 80 80 af = "" |
+4.1.4 U+002F = f8 80 80 80 af = "" |
+4.1.5 U+002F = fc 80 80 80 80 af = "" |
+ |
+4.2 Maximum overlong sequences |
+ |
+Below you see the highest Unicode value that is still resulting in an |
+overlong sequence if represented with the given number of bytes. This |
+is a boundary test for safe UTF-8 decoders. All five characters should |
+be rejected like malformed UTF-8 sequences. |
+ |
+4.2.1 U-0000007F = c1 bf = "" |
+4.2.2 U-000007FF = e0 9f bf = "" |
+4.2.3 U-0000FFFF = f0 8f bf bf = "" |
+4.2.4 U-001FFFFF = f8 87 bf bf bf = "" |
+4.2.5 U-03FFFFFF = fc 83 bf bf bf bf = "" |
+ |
+4.3 Overlong representation of the NUL character |
+ |
+The following five sequences should also be rejected like malformed |
+UTF-8 sequences and should not be treated like the ASCII NUL |
+character. |
+ |
+4.3.1 U+0000 = c0 80 = "" |
+4.3.2 U+0000 = e0 80 80 = "" |
+4.3.3 U+0000 = f0 80 80 80 = "" |
+4.3.4 U+0000 = f8 80 80 80 80 = "" |
+4.3.5 U+0000 = fc 80 80 80 80 80 = "" |
+ |
+5 Illegal code positions |
+ |
+The following UTF-8 sequences should be rejected like malformed |
+sequences, because they never represent valid ISO 10646 characters and |
+a UTF-8 decoder that accepts them might introduce security problems |
+comparable to overlong UTF-8 sequences. |
+ |
+5.1 Single UTF-16 surrogates |
+ |
+5.1.1 U+D800 = ed a0 80 = "" |
+5.1.2 U+DB7F = ed ad bf = "" |
+5.1.3 U+DB80 = ed ae 80 = "" |
+5.1.4 U+DBFF = ed af bf = "" |
+5.1.5 U+DC00 = ed b0 80 = "" |
+5.1.6 U+DF80 = ed be 80 = "" |
+5.1.7 U+DFFF = ed bf bf = "" |
+ |
+5.2 Paired UTF-16 surrogates |
+ |
+5.2.1 U+D800 U+DC00 = ed a0 80 ed b0 80 = "" |
+5.2.2 U+D800 U+DFFF = ed a0 80 ed bf bf = "" |
+5.2.3 U+DB7F U+DC00 = ed ad bf ed b0 80 = "" |
+5.2.4 U+DB7F U+DFFF = ed ad bf ed bf bf = "" |
+5.2.5 U+DB80 U+DC00 = ed ae 80 ed b0 80 = "" |
+5.2.6 U+DB80 U+DFFF = ed ae 80 ed bf bf = "" |
+5.2.7 U+DBFF U+DC00 = ed af bf ed b0 80 = "" |
+5.2.8 U+DBFF U+DFFF = ed af bf ed bf bf = "" |
+ |
+5.3 Other illegal code positions |
+ |
+5.3.1 U+FFFE = ef bf be = "￾" |
+5.3.2 U+FFFF = ef bf bf = "￿" |
+ |
+THE END |
+