Index: SDL/include/SDL_audio.h
===================================================================
RCS file: /cvs/ports/SDL/include/SDL_audio.h,v
retrieving revision 1.1
diff -u -r1.1 SDL_audio.h
--- SDL/include/SDL_audio.h	2 Feb 2004 23:01:44 -0000	1.1
+++ SDL/include/SDL_audio.h	30 May 2004 14:03:04 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 /* Access to the raw audio mixing buffer for the SDL library */
@@ -53,6 +53,7 @@
 	Uint16 samples;		/* Audio buffer size in samples (power of 2) */
 	Uint16 padding;		/* Necessary for some compile environments */
 	Uint32 size;		/* Audio buffer size in bytes (calculated) */
+	Uint8  thread_priority; /* Thread priority */
 	/* This function is called when the audio device needs more data.
 	   'stream' is a pointer to the audio data buffer
 	   'len' is the length of that buffer in bytes.
Index: SDL/src/audio/windib/SDL_dibaudio.c
===================================================================
RCS file: /cvs/ports/SDL/src/audio/windib/SDL_dibaudio.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_dibaudio.c
--- SDL/src/audio/windib/SDL_dibaudio.c	2 Feb 2004 23:01:45 -0000	1.1
+++ SDL/src/audio/windib/SDL_dibaudio.c	30 May 2004 13:53:10 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 /* Allow access to a raw mixing buffer */
@@ -147,7 +147,7 @@
 /* Set high priority for the audio thread */
 static void DIB_ThreadInit(_THIS)
 {
-	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
+	SetThreadPriority(GetCurrentThread(), this->hidden->thread_priority);
 }
 
 void DIB_WaitAudio(_THIS)
@@ -229,6 +229,10 @@
 	int i;
 	WAVEFORMATEX waveformat;
 
+	this->hidden->thread_priority = spec->thread_priority;
+	if (this->hidden->thread_priority <= 0)
+		this->hidden->thread_priority = THREAD_PRIORITY_NORMAL;
+
 	/* Initialize the wavebuf structures for closing */
 	sound = NULL;
 	audio_sem = NULL;
Index: SDL/src/audio/windib/SDL_dibaudio.h
===================================================================
RCS file: /cvs/ports/SDL/src/audio/windib/SDL_dibaudio.h,v
retrieving revision 1.1
diff -u -r1.1 SDL_dibaudio.h
--- SDL/src/audio/windib/SDL_dibaudio.h	2 Feb 2004 23:01:45 -0000	1.1
+++ SDL/src/audio/windib/SDL_dibaudio.h	30 May 2004 13:53:11 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 #ifndef _SDL_lowaudio_h
@@ -41,6 +41,7 @@
 	Uint8 *mixbuf;		/* The raw allocated mixing buffer */
 	WAVEHDR wavebuf[NUM_BUFFERS];	/* Wave audio fragments */
 	int next_buffer;
+	Uint8 thread_priority; /* Thread priority */
 };
 
 /* Old variable names */
Index: SDL/src/cdrom/win32/SDL_syscdrom.c
===================================================================
RCS file: /cvs/ports/SDL/src/cdrom/win32/SDL_syscdrom.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_syscdrom.c
--- SDL/src/cdrom/win32/SDL_syscdrom.c	2 Feb 2004 23:01:45 -0000	1.1
+++ SDL/src/cdrom/win32/SDL_syscdrom.c	30 May 2004 14:04:45 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 /* Functions for system-level CD-ROM audio control */
@@ -30,12 +30,30 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <windows.h>
+#ifndef _WIN32_WCE
 #include <mmsystem.h>
+#endif
 
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
+
+#ifdef _WIN32_WCE
+
+int SDL_SYS_CDInit() {
+	return 0;
+}
+
+static void SDL_SYS_CDClose(SDL_CD *cdrom) {
+}
+
+void SDL_SYS_CDQuit(void) {
+}
+
+#else
+
 #include "SDL_syscdrom.h"
 
+
 /* This really broken?? */
 #define BROKEN_MCI_PAUSE	/* Pausing actually stops play -- Doh! */
 
@@ -384,3 +402,5 @@
 		SDL_numcds = 0;
 	}
 }
+
+#endif
\ No newline at end of file
Index: SDL/src/joystick/win32/SDL_mmjoystick.c
===================================================================
RCS file: /cvs/ports/SDL/src/joystick/win32/SDL_mmjoystick.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_mmjoystick.c
--- SDL/src/joystick/win32/SDL_mmjoystick.c	2 Feb 2004 23:01:45 -0000	1.1
+++ SDL/src/joystick/win32/SDL_mmjoystick.c	30 May 2004 14:05:42 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
@@ -36,6 +36,39 @@
 #include "SDL_joystick_c.h"
 
 #include <windows.h>
+
+#ifdef _WIN32_WCE
+
+int SDL_SYS_JoystickInit(void)
+{
+	return 0;
+}
+
+void SDL_SYS_JoystickClose(SDL_Joystick *joystick) 
+{
+}
+
+const char *SDL_SYS_JoystickName(int index)
+{
+	return NULL;
+}
+
+int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
+{
+	return 0;
+}
+
+void SDL_SYS_JoystickQuit(void)
+{
+	return;
+}
+
+void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
+{
+}
+
+#else
+
 #include <mmsystem.h>
 
 #define MAX_JOYSTICKS	16
@@ -336,3 +369,5 @@
 	}
 	SDL_SetError("%s", errbuf);
 }
+
+#endif
\ No newline at end of file
Index: SDL/src/video/SDL_RLEaccel.c
===================================================================
RCS file: /cvs/ports/SDL/src/video/SDL_RLEaccel.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_RLEaccel.c
--- SDL/src/video/SDL_RLEaccel.c	2 Feb 2004 23:01:46 -0000	1.1
+++ SDL/src/video/SDL_RLEaccel.c	30 May 2004 14:00:00 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 /*
@@ -102,6 +102,28 @@
 #include "SDL_memops.h"
 #include "SDL_RLEaccel_c.h"
 
+#if defined(_WIN32_WCE) && (_WIN32_WCE < 300) && defined(ARM)
+
+/* Crashes the compiler otherwise !!! */
+
+int SDL_RLESurface(SDL_Surface *surface) {
+	return -1;
+}
+
+int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect) {
+	return -1;
+}
+
+int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect) {
+	return -1;
+}
+
+void SDL_UnRLESurface(SDL_Surface *surface, int recode) {
+}
+
+#else
+
+
 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
 #include "mmx.h"
 /* Function to check the CPU flags */
@@ -1938,4 +1960,4 @@
     }
 }
 
-
+#endif // HPC workaround
Index: SDL/src/video/SDL_sysvideo.h
===================================================================
RCS file: /cvs/ports/SDL/src/video/SDL_sysvideo.h,v
retrieving revision 1.1
diff -u -r1.1 SDL_sysvideo.h
--- SDL/src/video/SDL_sysvideo.h	2 Feb 2004 23:01:46 -0000	1.1
+++ SDL/src/video/SDL_sysvideo.h	30 May 2004 14:00:01 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 #ifndef _SDL_sysvideo_h
@@ -362,6 +362,9 @@
 #ifdef ENABLE_WINDIB
 extern VideoBootStrap WINDIB_bootstrap;
 #endif
+#ifdef ENABLE_WINGAPI
+extern VideoBootStrap WINGAPI_bootstrap;
+#endif
 #ifdef ENABLE_DIRECTX
 extern VideoBootStrap DIRECTX_bootstrap;
 #endif
Index: SDL/src/video/SDL_video.c
===================================================================
RCS file: /cvs/ports/SDL/src/video/SDL_video.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_video.c
--- SDL/src/video/SDL_video.c	2 Feb 2004 23:01:46 -0000	1.1
+++ SDL/src/video/SDL_video.c	30 May 2004 14:00:01 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 /* The high-level video driver subsystem */
@@ -81,6 +81,9 @@
 #ifdef ENABLE_DIRECTX
 	&DIRECTX_bootstrap,
 #endif
+#ifdef ENABLE_WINGAPI
+	&WINGAPI_bootstrap,
+#endif
 #ifdef ENABLE_WINDIB
 	&WINDIB_bootstrap,
 #endif
@@ -856,6 +859,7 @@
 				(SDL_VideoSurface->flags&SDL_HWSURFACE) &&
 				!(SDL_VideoSurface->flags&SDL_DOUBLEBUF))
 	     ) ) {
+
 		SDL_CreateShadowSurface(bpp);
 		if ( SDL_ShadowSurface == NULL ) {
 			SDL_SetError("Couldn't create shadow surface");
Index: SDL/src/video/wincommon/SDL_sysevents.c
===================================================================
RCS file: /cvs/ports/SDL/src/video/wincommon/SDL_sysevents.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_sysevents.c
--- SDL/src/video/wincommon/SDL_sysevents.c	2 Feb 2004 23:02:58 -0000	1.1
+++ SDL/src/video/wincommon/SDL_sysevents.c	30 May 2004 13:59:05 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 #include <stdlib.h>
@@ -41,6 +41,8 @@
 #include "SDL_syswm_c.h"
 #include "SDL_main.h"
 
+#include "SDL_dibvideo.h"
+
 #ifdef WMMSG_DEBUG
 #include "wmmsg.h"
 #endif
@@ -172,6 +174,37 @@
 #endif /* !NO_GETKEYBOARDSTATE */
 }
 
+void transform(SDL_RotateAttr rotate, char ozone, Sint16 *x, Sint16 *y) {
+	Sint16 rotatedX;
+	Sint16 rotatedY;
+
+	if (ozone) {
+		*x = *x * 2;
+		*y = *y * 2;
+	}
+
+	switch(rotate) {
+		case SDL_ROTATE_NONE:
+			break;
+		case SDL_ROTATE_LEFT:
+			if (!SDL_VideoSurface)
+				break;
+			rotatedX = SDL_VideoSurface->w - *y;
+			rotatedY = *x;
+			*x = rotatedX;
+			*y = rotatedY;
+			break;
+		case SDL_ROTATE_RIGHT:
+			if (!SDL_VideoSurface)
+				break;
+			rotatedX = *y;
+			rotatedY = SDL_VideoSurface->h - *x;
+			*x = rotatedX;
+			*y = rotatedY;
+			break;
+	}
+}
+
 /* The main Win32 event handler
 DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it
 */
@@ -180,6 +213,7 @@
 	SDL_VideoDevice *this = current_video;
 	static int mouse_pressed = 0;
 	static int in_window = 0;
+
 #ifdef WMMSG_DEBUG
 	fprintf(stderr, "Received windows message:  ");
 	if ( msg > MAX_WMMSG ) {
@@ -272,6 +306,8 @@
 						posted = SDL_PrivateMouseMotion(0, 1, x, y);
 					}
 				} else {
+					if (SDL_VideoSurface)
+						transform(rotation, ozoneHack, &x, &y);
 					posted = SDL_PrivateMouseMotion(0, 0, x, y);
 				}
 			}
@@ -360,7 +396,13 @@
 				} else {
 					x = (Sint16)LOWORD(lParam);
 					y = (Sint16)HIWORD(lParam);
+					if (SDL_VideoSurface)
+						transform(rotation, ozoneHack, &x, &y);
 				}
+#ifdef _WIN32_WCE
+				/* Since stylus movements are not continuous */
+				posted = SDL_PrivateMouseMotion(0, 0, x, y);
+#endif
 				posted = SDL_PrivateMouseButton(
 							state, button, x, y);
 			}
Index: SDL/src/video/wincommon/SDL_sysmouse.c
===================================================================
RCS file: /cvs/ports/SDL/src/video/wincommon/SDL_sysmouse.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_sysmouse.c
--- SDL/src/video/wincommon/SDL_sysmouse.c	2 Feb 2004 23:02:58 -0000	1.1
+++ SDL/src/video/wincommon/SDL_sysmouse.c	30 May 2004 13:59:05 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 #include <stdlib.h>
@@ -251,6 +251,7 @@
 /* Check to see if we need to enter or leave mouse relative mode */
 void WIN_CheckMouseMode(_THIS)
 {
+#ifndef _WIN32_WCE
         /* If the mouse is hidden and input is grabbed, we use relative mode */
         if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
              (this->input_grab != SDL_GRAB_OFF) ) {
@@ -258,4 +259,7 @@
         } else {
                 mouse_relative = 0;
         }
+#else
+		mouse_relative =  0;
+#endif
 }
Index: SDL/src/video/windib/SDL_dibevents.c
===================================================================
RCS file: /cvs/ports/SDL/src/video/windib/SDL_dibevents.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_dibevents.c
--- SDL/src/video/windib/SDL_dibevents.c	2 Feb 2004 23:02:58 -0000	1.1
+++ SDL/src/video/windib/SDL_dibevents.c	30 May 2004 13:57:04 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 #include <stdlib.h>
@@ -59,6 +59,29 @@
    and give him a chance to handle some messages. */
 static WNDPROC userWindowProc = NULL;
 
+#ifdef _WIN32_WCE
+
+WPARAM rotateKey(WPARAM key, SDL_RotateAttr direction) {
+	if (direction != SDL_ROTATE_LEFT)
+		return key;
+
+	switch (key) {
+		case 0x26: /* up */
+			return 0x27;
+		case 0x27: /* right */
+			return 0x28;
+		case 0x28: /* down */
+			return 0x25;
+		case 0x25: /* left */
+			return 0x26;
+	}
+
+	return key;
+}
+
+#endif
+
+
 /* The main Win32 event handler */
 LONG
  DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -70,6 +93,16 @@
 		case WM_KEYDOWN: {
 			SDL_keysym keysym;
 
+#ifdef _WIN32_WCE
+			// Drop GAPI artefacts
+			if (wParam == 0x84 || wParam == 0x5B)
+				return 0;
+
+			// Rotate key if necessary
+			if (rotation != SDL_ROTATE_NONE)
+				wParam = rotateKey(wParam, rotation);	
+#endif
+
 			/* Ignore repeated keys */
 			if ( lParam&REPEATED_KEYMASK ) {
 				return(0);
@@ -100,6 +133,7 @@
 						wParam = VK_LMENU;
 					break;
 			}
+
 #ifdef NO_GETKEYBOARDSTATE
 			/* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */
 			if ( SDL_TranslateUNICODE ) {
@@ -114,12 +148,13 @@
 					GetMessage(&m, hwnd, 0, WM_USER);
 			    		wParam = m.wParam;
 				} else {
-					wParam = 0;
+						//wParam = 0;  // I don't get it !
 				}
 			} else {
-				wParam = 0;
+				//wParam = 0;   // I don't get it !
 			}
 #endif /* NO_GETKEYBOARDSTATE */
+
 			posted = SDL_PrivateKeyboard(SDL_PRESSED,
 				TranslateKey(wParam,HIWORD(lParam),&keysym,1));
 		}
@@ -129,6 +164,16 @@
 		case WM_KEYUP: {
 			SDL_keysym keysym;
 
+#ifdef _WIN32_WCE
+			// Drop GAPI artefacts
+			if (wParam == 0x84 || wParam == 0x5B)
+				return 0;
+
+			// Rotate key if necessary
+			if (rotation != SDL_ROTATE_NONE)
+				wParam = rotateKey(wParam, rotation);
+#endif
+
 			switch (wParam) {
 				case VK_CONTROL:
 					if ( lParam&EXTENDED_KEYMASK )
@@ -155,6 +200,7 @@
 						wParam = VK_LMENU;
 					break;
 			}
+			
 			posted = SDL_PrivateKeyboard(SDL_RELEASED,
 				TranslateKey(wParam,HIWORD(lParam),&keysym,0));
 		}
@@ -325,6 +371,15 @@
 
 	prev_shiftstates[0] = FALSE;
 	prev_shiftstates[1] = FALSE;
+
+#ifdef _WIN32_WCE
+	/* Hardcode the 4 magic keys to F1 F2 F3 F4 - the actual location of the keys varies ... */
+	VK_keymap[0xC1] = SDLK_F1;
+	VK_keymap[0xC2] = SDLK_F2;
+	VK_keymap[0xC3] = SDLK_F3;
+	VK_keymap[0xC4] = SDLK_F4;
+#endif
+
 }
 
 static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed)
@@ -356,8 +411,14 @@
 #ifndef CS_BYTEALIGNCLIENT
 #define CS_BYTEALIGNCLIENT	0
 #endif
+#ifndef _WIN32_WCE
 	SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0);
+#else
+	SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW, 0);
+#endif
 	if ( SDL_windowid ) {
+// FIXME 
+#ifndef _WIN32_WCE
 		SDL_Window = (HWND)strtol(SDL_windowid, NULL, 0);
 
       /* DJM: we want all event's for the user specified
@@ -367,16 +428,28 @@
          userWindowProc = (WNDPROC)GetWindowLong(SDL_Window, GWL_WNDPROC);
          SetWindowLong(SDL_Window, GWL_WNDPROC, (LONG)WinMessage);
       }
+#endif
 	} else {
+				
+#ifndef _WIN32_WCE
 		SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
                         (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX),
                                  0, 0, 0, 0, NULL, NULL, SDL_Instance, NULL);
+#else		
+
+		SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX),
+						0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), 
+						NULL, NULL, SDL_Instance, NULL);
+
+#endif	
 		if ( SDL_Window == NULL ) {
 			SDL_SetError("Couldn't create window");
 			return(-1);
 		}
-		ShowWindow(SDL_Window, SW_HIDE);
+
+		ShowWindow(SDL_Window, SW_HIDE);		
 	}
+
 	return(0);
 }
 
Index: SDL/src/video/windib/SDL_dibvideo.c
===================================================================
RCS file: /cvs/ports/SDL/src/video/windib/SDL_dibvideo.c,v
retrieving revision 1.1
diff -u -r1.1 SDL_dibvideo.c
--- SDL/src/video/windib/SDL_dibvideo.c	2 Feb 2004 23:02:58 -0000	1.1
+++ SDL/src/video/windib/SDL_dibvideo.c	30 May 2004 14:47:41 -0000
@@ -22,23 +22,31 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <malloc.h>
 #include <windows.h>
-#if defined(WIN32_PLATFORM_PSPC)
+#if defined (UNDER_CE) && (!defined(WIN32_PLATFORM_HPCPRO) && !defined(WIN32_PLATFORM_PSPC))
 #include <aygshell.h>                      // Add Pocket PC includes
 #pragma comment( lib, "aygshell" )         // Link Pocket PC library
 #endif
 
+#ifdef _MSC_VER
+#define inline __inline
+#endif
+
 /* Not yet in the mingw32 cross-compile headers */
 #ifndef CDS_FULLSCREEN
 #define CDS_FULLSCREEN	4
 #endif
 
+#ifndef WS_THICKFRAME
+#define WS_THICKFRAME 0
+#endif
+
 #include "SDL.h"
 #include "SDL_mutex.h"
 #include "SDL_syswm.h"
@@ -56,6 +64,17 @@
 #define NO_GETDIBITS
 #define NO_CHANGEDISPLAYSETTINGS
 #define NO_GAMMA_SUPPORT
+
+/* uncomment this line if you target WinCE 3.x platform: */
+//#define NO_SETDIBCOLORTABLE
+
+/* these 2 variables are used to suport paletted DIBs on WinCE 3.x that 
+   does not implement SetDIBColorTable, and when SetDIBColorTable is not working.
+   Slow. DIB is recreated every time.
+*/
+static BITMAPINFO *last_bitmapinfo;
+static void** last_bits;
+
 #endif
 #ifndef WS_MAXIMIZE
 #define WS_MAXIMIZE		0
@@ -94,6 +113,13 @@
 /* helper fn */
 static int DIB_SussScreenDepth();
 
+#ifdef _WIN32_WCE
+void DIB_ShowTaskBar(BOOL taskBarShown);
+#ifdef ENABLE_WINGAPI
+extern void GAPI_GrabHardwareKeys(BOOL grab);
+#endif
+#endif
+
 /* DIB driver bootstrap functions */
 
 static int DIB_Available(void)
@@ -350,6 +376,9 @@
 	/* Fill in some window manager capabilities */
 	this->info.wm_available = 1;
 
+	/* Rotation information */
+	rotation = SDL_ROTATE_NONE;
+
 	/* We're done! */
 	return(0);
 }
@@ -368,6 +397,42 @@
 #endif
 }
 
+#ifdef _WIN32_WCE
+
+void DIB_ShowTaskBar(BOOL taskBarShown) {
+#if defined(WIN32_PLATFORM_HPCPRO) || defined(WIN32_PLATFORM_PSPC)
+	// Hide taskbar, WinCE 2.x style - from EasyCE
+	HKEY hKey=0;
+	DWORD dwValue = 0;
+	unsigned long lSize = sizeof( DWORD );
+	DWORD dwType = REG_DWORD;
+	HWND hWnd;
+
+	RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("\\software\\microsoft\\shell"), 0, KEY_ALL_ACCESS, &hKey );
+	RegQueryValueEx( hKey, TEXT("TBOpt"), 0, &dwType, (BYTE*)&dwValue, &lSize );
+	if (taskBarShown)
+		dwValue &= 0xFFFFFFFF - 8;	// reset bit to show taskbar
+    else 
+		dwValue |= 8;	// set bit to hide taskbar
+	RegSetValueEx( hKey, TEXT("TBOpt"), 0, REG_DWORD, (BYTE*)&dwValue, lSize );
+	hWnd = FindWindow( TEXT("HHTaskBar"), NULL );
+	SendMessage(hWnd, WM_COMMAND, 0x03EA, 0 );
+	SetForegroundWindow(SDL_Window);
+#else
+	if (taskBarShown) 
+		SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON);
+	else 
+		SHFullScreen(SDL_Window, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
+#endif
+	if (FindWindow(TEXT("HHTaskBar"), NULL)) { // is it valid for HPC ?
+		if (taskBarShown) 
+			ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL);
+		else 
+			ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE);
+	}
+}
+
+#endif
 
 /*
   Helper fn to work out which screen depth windows is currently using.
@@ -442,6 +507,7 @@
 
 /* Various screen update functions available */
 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
+static void DIB_RotatedUpdate(_THIS, int numrects, SDL_Rect *rects);
 
 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current,
 				int width, int height, int bpp, Uint32 flags)
@@ -462,14 +528,17 @@
 	int x, y;
 	BOOL was_visible;
 	Uint32 Rmask, Gmask, Bmask;
+	int screenWidth, screenHeight, i;
 
 	/* See whether or not we should center the window */
 	was_visible = IsWindowVisible(SDL_Window);
 
+#ifdef HAVE_OPENGL
 	/* Clean up any GL context that may be hanging around */
 	if ( current->flags & SDL_OPENGL ) {
 		WIN_GL_ShutDown(this);
 	}
+#endif
 
 	/* Recalculate the bitmasks if necessary */
 	if ( bpp == current->format->BitsPerPixel ) {
@@ -518,23 +587,30 @@
 	video->h = height;
 	video->pitch = SDL_CalculatePitch(video);
 
-#ifdef WIN32_PLATFORM_PSPC
+//#ifdef WIN32_PLATFORM_PSPC
 	 /* Stuff to hide that $#!^%#$ WinCE taskbar in fullscreen... */
 	if ( flags & SDL_FULLSCREEN ) {
 		if ( !(prev_flags & SDL_FULLSCREEN) ) {
-			SHFullScreen(SDL_Window, SHFS_HIDETASKBAR);
-			SHFullScreen(SDL_Window, SHFS_HIDESIPBUTTON);
-			ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE);
+
+			//ShowWindow(SDL_Window, SW_SHOW);
+			//SetWindowPos(SDL_Window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+			//SetForegroundWindow(SDL_Window);
+
+			//SHFullScreen(SDL_Window, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
+			//ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE);
+
+			DIB_ShowTaskBar(FALSE);
+
 		}
 		video->flags |= SDL_FULLSCREEN;
 	} else {
 		if ( prev_flags & SDL_FULLSCREEN ) {
-			SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR);
-			SHFullScreen(SDL_Window, SHFS_SHOWSIPBUTTON);
-			ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL);
+			//SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON);
+			//ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL);
+			DIB_ShowTaskBar(TRUE);
 		}
 	}
-#endif
+//#endif
 #ifndef NO_CHANGEDISPLAYSETTINGS
 	/* Set fullscreen mode if appropriate */
 	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
@@ -560,6 +636,7 @@
 		DeleteObject(screen_pal);
 		screen_pal = NULL;
 	}
+
 	if ( bpp <= 8 )
 	{
 	/*	RJR: March 28, 2000
@@ -615,6 +692,7 @@
 			binfo_size += video->format->palette->ncolors *
 							sizeof(RGBQUAD);
 		}
+
 		binfo = (BITMAPINFO *)malloc(binfo_size);
 		if ( ! binfo ) {
 			if ( video != current ) {
@@ -642,19 +720,65 @@
 			((Uint32*)binfo->bmiColors)[1] = video->format->Gmask;
 			((Uint32*)binfo->bmiColors)[2] = video->format->Bmask;
 		} else {
+#ifdef UNDER_CE
+			binfo->bmiHeader.biCompression = BI_RGB;	/* 332 */
+			if ( video->format->palette ) {
+				binfo->bmiHeader.biClrUsed = video->format->palette->ncolors;
+				for(i=0; i<video->format->palette->ncolors; i++)
+				{
+					binfo->bmiColors[i].rgbRed=i&(7<<5);
+					binfo->bmiColors[i].rgbGreen=(i&(7<<2))<<3;
+					binfo->bmiColors[i].rgbBlue=(i&3)<<5;
+					binfo->bmiColors[i].rgbReserved=0;
+			   }
+			}
+#else
 			binfo->bmiHeader.biCompression = BI_RGB;	/* BI_BITFIELDS for 565 vs 555 */
 			if ( video->format->palette ) {
 				memset(binfo->bmiColors, 0,
 					video->format->palette->ncolors*sizeof(RGBQUAD));
 			}
+#endif
 		}
 
 		/* Create the offscreen bitmap buffer */
 		hdc = GetDC(SDL_Window);
+		/* See if we need to rotate the buffer (WinCE specific) */
+		screenWidth = GetDeviceCaps(hdc, HORZRES);
+		screenHeight = GetDeviceCaps(hdc, VERTRES);
+		rotation = SDL_ROTATE_NONE;
+		work_pixels = NULL;
+		if (rotation_pixels) {
+			free(rotation_pixels);
+			rotation_pixels = NULL;
+		}
+
+		if ((flags & SDL_FULLSCREEN) && (width>height) && (width > screenWidth) ) {
+			/* OK, we rotate the screen */
+			video->pixels = malloc(video->h * video->pitch);
+			rotation_pixels = video->pixels;
+			if (video->pixels)
+				rotation = SDL_ROTATE_LEFT;
+			OutputDebugString(TEXT("will rotate\r\n"));
+		}
+
 		screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS,
-					(void **)(&video->pixels), NULL, 0);
+			(rotation == SDL_ROTATE_NONE ? (void **)(&video->pixels) : (void**)&work_pixels), NULL, 0);
 		ReleaseDC(SDL_Window, hdc);
+#if defined(UNDER_CE) 
+/* keep bitmapinfo for palette in 8-bit modes for devices that don't have SetDIBColorTable */
+		last_bits = (rotation == SDL_ROTATE_NONE ? (void **)(&video->pixels) : (void**)&work_pixels);
+		if(last_bitmapinfo)
+			free(last_bitmapinfo);
+		if(is16bitmode)
+		{
+			last_bitmapinfo = 0;
+			free(binfo);
+		} else
+			last_bitmapinfo = binfo;
+#else
 		free(binfo);
+#endif
 		if ( screen_bmp == NULL ) {
 			if ( video != current ) {
 				SDL_FreeSurface(video);
@@ -662,7 +786,7 @@
 			SDL_SetError("Couldn't create DIB section");
 			return(NULL);
 		}
-		this->UpdateRects = DIB_NormalUpdate;
+		this->UpdateRects = (work_pixels ? DIB_RotatedUpdate : DIB_NormalUpdate);
 
 		/* Set video surface flags */
 		if ( bpp <= 8 ) {
@@ -681,6 +805,14 @@
 		bounds.top = 0;
 		bounds.right = video->w;
 		bounds.bottom = video->h;
+#ifdef UNDER_CE
+		if(rotation != SDL_ROTATE_NONE)
+		{   
+			int t=bounds.right;
+			bounds.right = bounds.bottom;
+			bounds.bottom=t;
+		}
+#endif
 		AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
 		width = bounds.right-bounds.left;
 		height = bounds.bottom-bounds.top;
@@ -690,27 +822,56 @@
 			y -= GetSystemMetrics(SM_CYCAPTION)/2;
 		}
 		swp_flags = (SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_SHOWWINDOW);
-		if ( was_visible && !(flags & SDL_FULLSCREEN) ) {
+#ifndef UNDER_CE
+		if ( was_visible && !(flags & SDL_FULLSCREEN)) {
 			swp_flags |= SWP_NOMOVE;
 		}
+#endif
 		if ( flags & SDL_FULLSCREEN ) {
 			top = HWND_TOPMOST;
 		} else {
 			top = HWND_NOTOPMOST;
 		}
+#ifndef _WIN32_WCE
 		SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags);
+#else
+		if (flags & SDL_FULLSCREEN) {
+/* When WinCE program switches resolution from larger to smaller we should move its window so it would be visible in fullscreen */
+//			SetWindowPos(SDL_Window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+			DIB_ShowTaskBar(FALSE);
+			if(x>0) x=0;	// remove space from the left side of a screen in 320x200 mode
+			if(y>0) y=0;
+			SetWindowPos(SDL_Window, HWND_TOPMOST, x, y, width, height, SWP_NOCOPYBITS);
+			ShowWindow(SDL_Window, SW_SHOW);
+		}
+		else
+			SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags);
+#endif
+		
 		SDL_resizing = 0;
 		SetForegroundWindow(SDL_Window);
 	}
 
 	/* Set up for OpenGL */
 	if ( flags & SDL_OPENGL ) {
+#ifdef HAVE_OPENGL
 		if ( WIN_GL_SetupWindow(this) < 0 ) {
 			return(NULL);
 		}
 		video->flags |= SDL_OPENGL;
+#else
+		return (NULL);
+#endif
+
 	}
 
+#ifdef ENABLE_WINGAPI
+	/* Grab hardware keys if necessary */
+	if ( flags & SDL_FULLSCREEN ) {
+		GAPI_GrabHardwareKeys(TRUE);
+	}
+#endif
+
 	/* We're live! */
 	return(video);
 }
@@ -726,28 +887,163 @@
 }
 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface)
 {
-	return(0);
+	return(0); 
 }
 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface)
 {
 	return;
 }
 
+static inline void rotateBlit(unsigned short *src, unsigned short *dest, SDL_Rect *rect, int pitch) {
+	int i=rect->w, j=rect->h;
+	src+=i;
+
+	for (;i--;) {
+		register unsigned short *S=src--;
+// I use loop unrolling to spedup things a little
+		int cnt = j;
+		if(cnt&1)
+		{
+			*(dest++) = *S;
+			S+=pitch;
+		}
+		cnt>>=1;
+		if(cnt&1)
+		{
+			*(dest++) = *S;
+			S+=pitch;
+			*(dest++) = *S;
+			S+=pitch;
+		}
+		cnt>>=1;
+		for (; cnt--; ) {
+			*(dest++) = *S;
+			S+=pitch;
+			*(dest++) = *S;
+			S+=pitch;
+			*(dest++) = *S;
+			S+=pitch;
+			*(dest++) = *S;
+			S+=pitch;
+		}
+	}
+/* tiny optimization
+	int i, j;
+	src+=rect->w;
+
+	for (i=0; i<rect->w; i++) {
+		register unsigned short *S=src--;
+		for (j=0; j<rect->h; j++) {
+			*(dest++) = *S;
+			S+=pitch;
+		}
+	}
+*/
+/* original unoptimized version
+	int i, j;
+
+	for (i=0; i<rect->w; i++) {
+		for (j=0; j<rect->h; j++) {
+			dest[i * rect->h + j] = src[pitch * j + (rect->w - i)];
+		}
+	}
+*/
+}
+
+static inline void rotateBlit8(unsigned char *src, unsigned char *dest, SDL_Rect *rect, int pitch) {
+	int i=rect->w, j=rect->h;
+	src+=i;
+
+	for (;i--;) {
+		register unsigned char *S=src--;
+// I use loop unrolling to spedup things a little
+		int cnt = j;
+		if(cnt&1)
+		{
+			*(dest++) = *S;
+			S+=pitch;
+		}
+		cnt>>=1;
+		if(cnt&1)
+		{
+			*(dest++) = *S;
+			S+=pitch;
+			*(dest++) = *S;
+			S+=pitch;
+		}
+		cnt>>=1;
+		for (; cnt--; ) {
+			*(dest++) = *S;
+			S+=pitch;
+			*(dest++) = *S;
+			S+=pitch;
+			*(dest++) = *S;
+			S+=pitch;
+			*(dest++) = *S;
+			S+=pitch;
+		}
+	}
+}
+
+static void DIB_RotatedUpdate(_THIS, int numrects, SDL_Rect *rects) 
+{
+	HDC hdc, mdc;
+	HBITMAP hb, old;
+	int i;
+
+	hdc = GetDC(SDL_Window);
+	if ( screen_pal ) {
+		SelectPalette(hdc, screen_pal, FALSE);
+	}
+	mdc = CreateCompatibleDC(hdc);
+	/*SelectObject(mdc, screen_bmp);*/
+	if(this->screen->format->BytesPerPixel == 2) {
+		for ( i=0; i<numrects; ++i ) {	
+			unsigned short *src = (unsigned short*)this->screen->pixels;
+			rotateBlit(src + (this->screen->w * rects[i].y) + rects[i].x, work_pixels, &rects[i], this->screen->w);		
+			hb = CreateBitmap(rects[i].h, rects[i].w, 1, 16, work_pixels);
+			old = (HBITMAP)SelectObject(mdc, hb);
+			BitBlt(hdc, rects[i].y, this->screen->w - (rects[i].x + rects[i].w), rects[i].h, rects[i].w,
+					mdc, 0, 0, SRCCOPY);
+			SelectObject(mdc, old);
+			DeleteObject(hb);
+		}
+	} else {
+		if ( screen_pal ) {
+			SelectPalette(mdc, screen_pal, FALSE);
+		}
+		for ( i=0; i<numrects; ++i ) {	
+			unsigned char *src = (unsigned char*)this->screen->pixels;
+			rotateBlit8(src + (this->screen->w * rects[i].y) + rects[i].x, work_pixels, &rects[i], this->screen->w);
+			hb = CreateBitmap(rects[i].h, rects[i].w, 1, 8, work_pixels);
+			old = (HBITMAP)SelectObject(mdc, hb);
+			BitBlt(hdc, rects[i].y, this->screen->w - (rects[i].x + rects[i].w), rects[i].h, rects[i].w,
+					mdc, 0, 0, SRCCOPY);
+			SelectObject(mdc, old);
+			DeleteObject(hb); 
+		}
+	}
+	DeleteDC(mdc);
+	ReleaseDC(SDL_Window, hdc);
+}
+
 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
 {
 	HDC hdc, mdc;
 	int i;
+	HBITMAP old;
 
 	hdc = GetDC(SDL_Window);
 	if ( screen_pal ) {
 		SelectPalette(hdc, screen_pal, FALSE);
 	}
 	mdc = CreateCompatibleDC(hdc);
-	SelectObject(mdc, screen_bmp);
+	old = (HBITMAP)SelectObject(mdc, screen_bmp);
 	for ( i=0; i<numrects; ++i ) {
 		BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h,
 					mdc, rects[i].x, rects[i].y, SRCCOPY);
 	}
+	SelectObject(mdc, old);
 	DeleteDC(mdc);
 	ReleaseDC(SDL_Window, hdc);
 }
@@ -756,10 +1052,11 @@
 {
 	RGBQUAD *pal;
 	int i;
-#ifndef _WIN32_WCE
 	HDC hdc, mdc;
-#else
-	HDC hdc;
+
+#if defined(UNDER_CE) && defined(NO_SETDIBCOLORTABLE)
+	if(last_bitmapinfo==0)
+		return 0;
 #endif
 
 	/* Update the display palette */
@@ -789,14 +1086,39 @@
 	}
 
 	/* Set the DIB palette and update the display */
-#ifndef _WIN32_WCE
 	mdc = CreateCompatibleDC(hdc);
+
+#if defined(UNDER_CE) 
+#if !defined(NO_SETDIBCOLORTABLE)
+/* BUG: For some reason SetDIBColorTable is not working when screen is not rotated */
+	if(rotation == SDL_ROTATE_NONE && last_bitmapinfo)
+#else
+	if(1)
+#endif
+	{
+		DeleteObject(screen_bmp);
+		last_bitmapinfo->bmiHeader.biClrUsed=256;
+		for ( i=firstcolor; i<firstcolor+ncolors; ++i )
+			last_bitmapinfo->bmiColors[i]=pal[i];
+		screen_bmp = CreateDIBSection(hdc, last_bitmapinfo, DIB_RGB_COLORS,
+			last_bits, NULL, 0);
+    }
+#else
 	SelectObject(mdc, screen_bmp);
 	SetDIBColorTable(mdc, firstcolor, ncolors, pal);
+#endif
+#ifndef UNDER_CE
 	BitBlt(hdc, 0, 0, this->screen->w, this->screen->h,
 	       mdc, 0, 0, SRCCOPY);
-	DeleteDC(mdc);
+#else
+	{
+		SDL_Rect rect;
+		rect.x=0; rect.y=0;
+		rect.w=this->screen->w; rect.h=this->screen->h;
+// Fixme: screen flickers:		(this->UpdateRects)(this, 1, &rect) ;
+	}
 #endif
+	DeleteDC(mdc);
 	ReleaseDC(SDL_Window, hdc);
 	return(1);
 }
@@ -916,26 +1238,34 @@
 void DIB_VideoQuit(_THIS)
 {
 	/* Destroy the window and everything associated with it */
+	DIB_ShowTaskBar(TRUE);
+#ifdef ENABLE_WINGAPI
+	GAPI_GrabHardwareKeys(FALSE);
+#endif
+
 	if ( SDL_Window ) {
 		/* Delete the screen bitmap (also frees screen->pixels) */
 		if ( this->screen ) {
-#ifdef WIN32_PLATFORM_PSPC
+//#ifdef WIN32_PLATFORM_PSPC
 			if ( this->screen->flags & SDL_FULLSCREEN ) {
 				/* Unhide taskbar, etc. */
-				SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR);
-				SHFullScreen(SDL_Window, SHFS_SHOWSIPBUTTON);
-				ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL);
+				//SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON);
+				//ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL);
 			}
-#endif
+//#endif
 #ifndef NO_CHANGEDISPLAYSETTINGS
 			if ( this->screen->flags & SDL_FULLSCREEN ) {
 				ChangeDisplaySettings(NULL, 0);
 				ShowWindow(SDL_Window, SW_HIDE);
 			}
 #endif
+
+#ifdef HAVE_OPENGL
 			if ( this->screen->flags & SDL_OPENGL ) {
 				WIN_GL_ShutDown(this);
 			}
+#endif
+
 			this->screen->pixels = NULL;
 		}
 		if ( screen_bmp ) {
Index: SDL/src/video/windib/SDL_dibvideo.h
===================================================================
RCS file: /cvs/ports/SDL/src/video/windib/SDL_dibvideo.h,v
retrieving revision 1.1
diff -u -r1.1 SDL_dibvideo.h
--- SDL/src/video/windib/SDL_dibvideo.h	2 Feb 2004 23:02:58 -0000	1.1
+++ SDL/src/video/windib/SDL_dibvideo.h	30 May 2004 13:57:04 -0000
@@ -22,7 +22,7 @@
 
 #ifdef SAVE_RCSID
 static char rcsid =
- "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
+ "@(#) $Id: patch_SDL_1.2.6.txt,v 1.1 2005/07/07 12:43:46 klschoef Exp $";
 #endif
 
 #ifndef _SDL_dibvideo_h
@@ -30,19 +30,34 @@
 
 #include <windows.h>
 
+/* Rotation direction */
+typedef enum {
+	SDL_ROTATE_NONE,
+	SDL_ROTATE_LEFT,
+	SDL_ROTATE_RIGHT
+} SDL_RotateAttr;
+
 /* Private display data */
 struct SDL_PrivateVideoData {
     HBITMAP screen_bmp;
     HPALETTE screen_pal;
+	void *work_pixels; /* if the display needs to be rotated, memory allocated by the API */
+	void *rotation_pixels; /* if the display needs to be rotated, memory allocated by the code */
+	SDL_RotateAttr rotation;
+	char ozoneHack; /* force stylus translation if running without Hi Res flag */
 
 #define NUM_MODELISTS	4		/* 8, 16, 24, and 32 bits-per-pixel */
     int SDL_nummodes[NUM_MODELISTS];
     SDL_Rect **SDL_modelist[NUM_MODELISTS];
 };
 /* Old variable names */
-#define screen_bmp		(this->hidden->screen_bmp)
-#define screen_pal		(this->hidden->screen_pal)
+#define screen_bmp			(this->hidden->screen_bmp)
+#define screen_pal			(this->hidden->screen_pal)
 #define SDL_nummodes		(this->hidden->SDL_nummodes)
 #define SDL_modelist		(this->hidden->SDL_modelist)
+#define work_pixels			(this->hidden->work_pixels)
+#define rotation			(this->hidden->rotation)
+#define rotation_pixels		(this->hidden->rotation_pixels)
+#define ozoneHack			(this->hidden->ozoneHack)
 
 #endif /* _SDL_dibvideo_h */
