diff -ur orig/SDL-1.2.13/configure.in SDL-1.2.13/configure.in
--- orig/SDL-1.2.13/configure.in	2007-12-31 04:48:39.000000000 +0000
+++ SDL-1.2.13/configure.in	2009-06-25 22:44:21.000000000 +0100
@@ -65,6 +65,10 @@
         BASE_CFLAGS="-I/usr/include/mingw -mno-cygwin"
         BASE_LDFLAGS="-mno-cygwin"
         ;;
+    *mingw32ce*)
+        BASE_CFLAGS=""
+	BASE_LDFLAGS=""
+        ;;
     *)
         BASE_CFLAGS="-D_GNU_SOURCE=1"
         BASE_LDFLAGS=""
@@ -2384,6 +2388,59 @@
             have_timers=yes
         fi
         ;;
+
+    *mingw32ce*)
+        ARCH=wince
+
+        CheckDummyVideo
+        CheckDiskAudio
+        CheckDummyAudio
+        CheckWIN32
+
+#        if test x$enable_video = xyes; then
+#            AC_DEFINE(SDL_VIDEO_DRIVER_GAPI)
+#            SOURCES="$SOURCES $srcdir/src/video/gapi/*.c"
+#            have_video=yes
+#        fi
+
+        # Set up files for the audio library
+        if test x$enable_audio = xyes; then
+            AC_DEFINE(SDL_AUDIO_DRIVER_WAVEOUT)
+            SOURCES="$SOURCES $srcdir/src/audio/windib/*.c"
+            have_audio=yes
+        fi
+        # Set up files for the thread library
+        if test x$enable_threads = xyes; then
+            AC_DEFINE(SDL_THREAD_WIN32)
+            SOURCES="$SOURCES $srcdir/src/thread/win32/SDL_sysmutex.c"
+            SOURCES="$SOURCES $srcdir/src/thread/win32/SDL_syssem.c"
+            SOURCES="$SOURCES $srcdir/src/thread/win32/SDL_systhread.c"
+            SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_syscond.c"
+            have_threads=yes
+        fi
+        # Set up files for the timer library
+        if test x$enable_timers = xyes; then
+            AC_DEFINE(SDL_TIMER_WINCE)
+            SOURCES="$SOURCES $srcdir/src/timer/wince/*.c"
+            have_timers=yes
+        fi
+        # Set up files for the shared object loading library
+        if test x$enable_loadso = xyes; then
+            AC_DEFINE(SDL_LOADSO_WIN32)
+            SOURCES="$SOURCES $srcdir/src/loadso/win32/*.c"
+            have_loadso=yes
+        fi
+
+        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lmmtimer"
+
+        # Windows CE requires special setup
+        SOURCES="$SOURCES $srcdir/src/main/win32/*.rc"
+        SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
+        SDL_CFLAGS="$SDL_CFLAGS -mwin32 -Dmain=SDL_main -D_WIN32_WCE=0x0500"
+        SDL_LIBS="-lSDLmain $SDL_LIBS"
+
+        ;;
+
     *-*-cygwin* | *-*-mingw32*)
         ARCH=win32
         if test "$build" != "$host"; then # cross-compiling
diff -ur orig/SDL-1.2.13/include/SDL_keysym.h SDL-1.2.13/include/SDL_keysym.h
--- orig/SDL-1.2.13/include/SDL_keysym.h	2007-12-31 04:48:36.000000000 +0000
+++ SDL-1.2.13/include/SDL_keysym.h	2009-06-11 20:05:42.000000000 +0100
@@ -281,11 +281,21 @@
 	SDLK_EURO		= 321,		/* Some european keyboards */
 	SDLK_UNDO		= 322,		/* Atari keyboard has Undo */
 
+	/* Windows CE soft keys */
+	SDLK_APP1               = 323,
+	SDLK_APP2               = 324,
+	SDLK_APP3               = 325,
+	SDLK_APP4               = 326,
+	SDLK_APP5               = 327,
+	SDLK_APP6               = 328,
+
 	/* Add any other keys here */
 
 	SDLK_LAST
 } SDLKey;
 
+#define SDL_HAVE_APP_KEYS 1
+
 /* Enumeration of valid key mods (possibly OR'd together) */
 typedef enum {
 	KMOD_NONE  = 0x0000,
diff -ur orig/SDL-1.2.13/src/events/SDL_keyboard.c SDL-1.2.13/src/events/SDL_keyboard.c
--- orig/SDL-1.2.13/src/events/SDL_keyboard.c	2007-12-31 04:47:59.000000000 +0000
+++ SDL-1.2.13/src/events/SDL_keyboard.c	2009-06-10 20:34:52.000000000 +0100
@@ -305,6 +305,13 @@
 	keynames[SDLK_EURO] = "euro";
 	keynames[SDLK_UNDO] = "undo";
 
+	keynames[SDLK_APP1] = "application 1";
+	keynames[SDLK_APP2] = "application 2";
+	keynames[SDLK_APP3] = "application 3";
+	keynames[SDLK_APP4] = "application 4";
+	keynames[SDLK_APP5] = "application 5";
+	keynames[SDLK_APP6] = "application 6";
+
 	/* Done.  Whew. */
 	return(0);
 }
diff -ur orig/SDL-1.2.13/src/thread/win32/SDL_syssem.c SDL-1.2.13/src/thread/win32/SDL_syssem.c
--- orig/SDL-1.2.13/src/thread/win32/SDL_syssem.c	2007-12-31 04:48:14.000000000 +0000
+++ SDL-1.2.13/src/thread/win32/SDL_syssem.c	2009-06-08 19:56:58.000000000 +0100
@@ -38,7 +38,7 @@
 #else
 	HANDLE id;
 #endif
-	Uint32 volatile count;
+	LONG volatile count;
 };
 
 
diff -ur orig/SDL-1.2.13/src/thread/win32/SDL_systhread.c SDL-1.2.13/src/thread/win32/SDL_systhread.c
--- orig/SDL-1.2.13/src/thread/win32/SDL_systhread.c	2007-12-31 04:48:14.000000000 +0000
+++ SDL-1.2.13/src/thread/win32/SDL_systhread.c	2009-06-08 20:05:41.000000000 +0100
@@ -38,8 +38,8 @@
 
 #if __GNUC__
 typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
-        unsigned (__stdcall *func)(void *), void *arg, 
-        unsigned, unsigned *threadID);
+        DWORD (__stdcall *func)(void *), void *arg, 
+        unsigned, DWORD *threadID);
 typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
 #elif defined(__WATCOMC__)
 /* This is for Watcom targets except OS2 */
@@ -65,7 +65,7 @@
   pfnSDL_CurrentEndThread pfnCurrentEndThread;
 } tThreadStartParms, *pThreadStartParms;
 
-static unsigned __stdcall RunThread(void *data)
+static DWORD __stdcall RunThread(void *data)
 {
   pThreadStartParms pThreadParms = (pThreadStartParms)data;
   pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL;
@@ -99,7 +99,7 @@
 	pfnSDL_CurrentEndThread pfnEndThread = _endthreadex;
 #endif
 #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
-	unsigned threadid;
+	DWORD threadid;
 	pThreadStartParms pThreadParms = (pThreadStartParms)SDL_malloc(sizeof(tThreadStartParms));
 	if (!pThreadParms) {
 		SDL_OutOfMemory();
diff -ur orig/SDL-1.2.13/src/video/gapi/SDL_gapivideo.c SDL-1.2.13/src/video/gapi/SDL_gapivideo.c
--- orig/SDL-1.2.13/src/video/gapi/SDL_gapivideo.c	2007-12-31 04:48:00.000000000 +0000
+++ SDL-1.2.13/src/video/gapi/SDL_gapivideo.c	2009-06-08 22:06:24.000000000 +0100
@@ -56,6 +56,10 @@
 
 #define GAPIVID_DRIVER_NAME "gapi"
 
+#ifdef __GNUC__
+#define _T(x) L ## x
+#endif
+
 #if defined(DEBUG) || defined (_DEBUG) || defined(NDEBUG)
 #define REPORT_VIDEO_INFO 1
 #else
@@ -481,8 +485,6 @@
    pLogical->palNumEntries = ncolors;
 
    hPalette = CreatePalette( pLogical );
-   ASSERT(hPalette);
-	
 
    // Realize the palette
    hdc = GetDC(0);
diff -ur orig/SDL-1.2.13/src/video/gapi/SDL_gapivideo.h SDL-1.2.13/src/video/gapi/SDL_gapivideo.h
--- orig/SDL-1.2.13/src/video/gapi/SDL_gapivideo.h	2007-12-31 04:48:00.000000000 +0000
+++ SDL-1.2.13/src/video/gapi/SDL_gapivideo.h	2009-06-08 12:59:22.000000000 +0100
@@ -132,13 +132,13 @@
 #define NUM_MODELISTS	4		/* 8, 16, 24, and 32 bits-per-pixel */
     int SDL_nummodes[NUM_MODELISTS];
     SDL_Rect **SDL_modelist[NUM_MODELISTS];
-	enum SDL_ScreenOrientation userOrientation;
+	SDL_ScreenOrientation userOrientation;
 	int invert;
 	char hiresFix; // using hires mode without defining hires resource
 // --------------
 	int useGXOpenDisplay; /* use GXOpenDispplay */
     int w, h;
-	enum SDL_ScreenOrientation gapiOrientation;
+	SDL_ScreenOrientation gapiOrientation;
 
     void *buffer; // may be 8, 16, 24, 32 bpp
 	PIXEL *videoMem;
@@ -146,7 +146,7 @@
 	struct GXKeyList keyList;
 	struct GapiFunc gxFunc;
 	struct GXDisplayProperties gxProperties;
-	enum GAPIVideoMode videoMode;
+	GAPIVideoMode videoMode;
 	int colorscale;
 	int dstLineStep;  // in bytes
 	int dstPixelStep; // in bytes
diff -ur orig/SDL-1.2.13/src/video/wincommon/SDL_sysevents.c SDL-1.2.13/src/video/wincommon/SDL_sysevents.c
--- orig/SDL-1.2.13/src/video/wincommon/SDL_sysevents.c	2007-12-31 04:48:02.000000000 +0000
+++ SDL-1.2.13/src/video/wincommon/SDL_sysevents.c	2009-06-08 19:46:48.000000000 +0100
@@ -52,6 +52,7 @@
 
 #ifdef _WIN32_WCE
 #include "../gapi/SDL_gapivideo.h"
+#undef WM_MOUSELEAVE
 
 #define IsZoomed(HWND) 1
 #define NO_GETKEYBOARDSTATE
@@ -607,6 +608,7 @@
 			int style;
 			int width;
 			int height;
+                        int have_menu = 0;
 
 			/* We don't want to clobber an internal resize */
 			if ( SDL_resizing )
@@ -639,12 +641,17 @@
 			   Aparently it's too difficult for MS to check
 			   inside their function, so I have to do it here.
           		 */
+
+                        have_menu = 0;
+#ifndef _WIN32_WCE
+                        if ((style & WS_CHILDWINDOW) == 0)
+                        {
+                            have_menu = GetMenu(hwnd) != NULL;
+                        }
+#endif
+
          		style = GetWindowLong(hwnd, GWL_STYLE);
-         		AdjustWindowRect(
-				&size,
-				style,
-            			style & WS_CHILDWINDOW ? FALSE
-						       : GetMenu(hwnd) != NULL);
+         		AdjustWindowRectEx(&size, style, have_menu, 0);
 
 			width = size.right - size.left;
 			height = size.bottom - size.top;
diff -ur orig/SDL-1.2.13/src/video/windib/SDL_dibevents.c SDL-1.2.13/src/video/windib/SDL_dibevents.c
--- orig/SDL-1.2.13/src/video/windib/SDL_dibevents.c	2007-12-31 04:48:05.000000000 +0000
+++ SDL-1.2.13/src/video/windib/SDL_dibevents.c	2009-06-11 19:32:30.000000000 +0100
@@ -430,6 +430,12 @@
 	VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
 	VK_keymap[VK_CANCEL] = SDLK_BREAK;
 	VK_keymap[VK_APPS] = SDLK_MENU;
+	VK_keymap[VK_APP1] = SDLK_APP1;
+	VK_keymap[VK_APP2] = SDLK_APP2;
+	VK_keymap[VK_APP3] = SDLK_APP3;
+	VK_keymap[VK_APP4] = SDLK_APP4;
+	VK_keymap[VK_APP5] = SDLK_APP5;
+	VK_keymap[VK_APP6] = SDLK_APP6;
 }
 
 #define EXTKEYPAD(keypad) ((scancode & 0x100)?(mvke):(keypad))
diff -ur orig/SDL-1.2.13/src/video/windib/SDL_dibvideo.c SDL-1.2.13/src/video/windib/SDL_dibvideo.c
--- orig/SDL-1.2.13/src/video/windib/SDL_dibvideo.c	2007-12-31 04:48:05.000000000 +0000
+++ SDL-1.2.13/src/video/windib/SDL_dibvideo.c	2009-07-08 17:40:57.000000000 +0100
@@ -686,7 +688,7 @@
 				video->flags |= SDL_RESIZABLE;
 			}
 		}
-#if WS_MAXIMIZE
+#ifndef _WIN32_WCE
 		if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
 #endif
 	}
@@ -946,7 +948,7 @@
 			entry->peBlue  = colors[i].b;
 			entry->peFlags = PC_NOCOLLAPSE;
 		}
-#ifdef SYSPAL_NOSTATIC
+#ifndef _WIN32_WCE
 		/* Check to make sure black and white are in position */
 		if ( GetSystemPaletteUse(hdc) != SYSPAL_NOSTATIC256 ) {
 			moved_entries += CheckPaletteEntry(screen_logpal, 0, 0x00, 0x00, 0x00);
@@ -958,9 +960,7 @@
 		   in the desired palette, set those entries (10-245) and
 		   then map everything into the new system palette.
 		 */
-#endif
 
-#ifndef _WIN32_WCE
 		/* Copy the entries into the system palette */
 		UnrealizeObject(screen_pal);
 #endif
@@ -1167,7 +1167,7 @@
 /* Exported for the windows message loop only */
 static void DIB_GrabStaticColors(HWND window)
 {
-#ifdef SYSPAL_NOSTATIC
+#ifndef _WIN32_WCE
 	HDC hdc;
 
 	hdc = GetDC(window);
@@ -1180,7 +1180,7 @@
 }
 static void DIB_ReleaseStaticColors(HWND window)
 {
-#ifdef SYSPAL_NOSTATIC
+#ifndef _WIN32_WCE
 	HDC hdc;
 
 	hdc = GetDC(window);
