SDL-1.2: mingw32ce build fixes

From e7dcf5ca536d24b17b85aea2cdb7d55263e36056 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 17 Apr 2021 21:55:00 +0300
Subject: [PATCH] mingw32ce build fixes

build-tested **only**
---
 configure                           | 98 +++++++++++++++--------------
 configure.ac                        | 89 +++++++++++++-------------
 src/events/SDL_keyboard.c           |  3 +
 src/video/gapi/SDL_gapivideo.c      | 26 ++++----
 src/video/wincommon/SDL_sysevents.c | 20 +++---
 src/video/wincommon/SDL_syswm.c     | 19 +++---
 src/video/windib/SDL_dibevents.c    | 11 +++-
 7 files changed, 141 insertions(+), 125 deletions(-)

diff --git a/configure b/configure
index 062feae9..bc73f3ac 100755
--- a/configure
+++ b/configure
@@ -22118,6 +22118,56 @@ case "$host" in
             have_timers=yes
         fi
         ;;
+    *-wince*|*mingw32ce*)
+        ARCH=win32
+        CheckDummyVideo
+        CheckDiskAudio
+        CheckDummyAudio
+        CheckWIN32
+        CheckNASM
+        SOURCES="$SOURCES $srcdir/src/video/gapi/*.c"
+        $as_echo "#define SDL_VIDEO_DRIVER_GAPI 1" >>confdefs.h
+
+        EXTRA_CFLAGS="$EXTRA_CFLAGS -D_WIN32_WCE=0x420"
+        if test x$enable_audio = xyes; then
+            $as_echo "#define SDL_AUDIO_DRIVER_WAVEOUT 1" >>confdefs.h
+
+            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
+            $as_echo "#define SDL_THREAD_WIN32 1" >>confdefs.h
+
+            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
+            $as_echo "#define SDL_TIMER_WINCE 1" >>confdefs.h
+
+            SOURCES="$SOURCES $srcdir/src/timer/wince/*.c"
+            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lmmtimer"
+            have_timers=yes
+        fi
+        # Set up files for the shared object loading library
+        if test x$enable_loadso = xyes; then
+            $as_echo "#define SDL_LOADSO_WIN32 1" >>confdefs.h
+
+            SOURCES="$SOURCES $srcdir/src/loadso/win32/*.c"
+            have_loadso=yes
+        fi
+        # Set up the system libraries we need
+        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lcommctrl"
+        # The Win32 platform requires special setup
+        SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
+        SDLMAIN_LDFLAGS="-static"
+        SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main -D_WIN32_WCE=0x420"
+        SDL_LIBS="-lSDLmain $SDL_LIBS"
+        ;;
     *-*-cygwin* | *-*-mingw*)
         ARCH=win32
         if test "$build" != "$host"; then # cross-compiling
@@ -22198,54 +22248,6 @@ case "$host" in
         SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main"
         SDL_LIBS="-lmingw32 -lSDLmain $SDL_LIBS -mwindows"
         ;;
-    *-wince*)
-        ARCH=win32
-        CheckDummyVideo
-        CheckDiskAudio
-        CheckDummyAudio
-        CheckWIN32
-        CheckNASM
-        SOURCES="$SOURCES $srcdir/src/video/gapi/*.c"
-        EXTRA_CFLAGS="$EXTRA_CFLAGS -D_WIN32_WCE=0x420"
-        if test x$enable_audio = xyes; then
-            $as_echo "#define SDL_AUDIO_DRIVER_WAVEOUT 1" >>confdefs.h
-
-            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
-            $as_echo "#define SDL_THREAD_WIN32 1" >>confdefs.h
-
-            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
-            $as_echo "#define SDL_TIMER_WINCE 1" >>confdefs.h
-
-            SOURCES="$SOURCES $srcdir/src/timer/wince/*.c"
-            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lmmtimer"
-            have_timers=yes
-        fi
-        # Set up files for the shared object loading library
-        if test x$enable_loadso = xyes; then
-            $as_echo "#define SDL_LOADSO_WIN32 1" >>confdefs.h
-
-            SOURCES="$SOURCES $srcdir/src/loadso/win32/*.c"
-            have_loadso=yes
-        fi
-        # Set up the system libraries we need
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lcommctrl"
-        # The Win32 platform requires special setup
-        SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
-        SDLMAIN_LDFLAGS="-static"
-        SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main -D_WIN32_WCE=0x420"
-        SDL_LIBS="-lSDLmain $SDL_LIBS"
-        ;;
     *-*-beos* | *-*-haiku*)
         ARCH=beos
         ac_default_prefix=/boot/develop/tools/gnupro
diff --git a/configure.ac b/configure.ac
index 983e6c1c..69ee434f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2616,6 +2616,51 @@ case "$host" in
             have_timers=yes
         fi
         ;;
+    *-wince*|*mingw32ce*)
+        ARCH=win32
+        CheckDummyVideo
+        CheckDiskAudio
+        CheckDummyAudio
+        CheckWIN32
+        CheckNASM
+        SOURCES="$SOURCES $srcdir/src/video/gapi/*.c"
+        AC_DEFINE(SDL_VIDEO_DRIVER_GAPI)
+        EXTRA_CFLAGS="$EXTRA_CFLAGS -D_WIN32_WCE=0x420"
+        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"
+            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lmmtimer"
+            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
+        # Set up the system libraries we need
+        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lcommctrl"
+        # The Win32 platform requires special setup
+        SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
+        SDLMAIN_LDFLAGS="-static"
+        SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main -D_WIN32_WCE=0x420"
+        SDL_LIBS="-lSDLmain $SDL_LIBS"
+        ;;
     *-*-cygwin* | *-*-mingw*)
         ARCH=win32
         if test "$build" != "$host"; then # cross-compiling
@@ -2689,50 +2734,6 @@ case "$host" in
         SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main"
         SDL_LIBS="-lmingw32 -lSDLmain $SDL_LIBS -mwindows"
         ;;
-    *-wince*)
-        ARCH=win32
-        CheckDummyVideo
-        CheckDiskAudio
-        CheckDummyAudio
-        CheckWIN32
-        CheckNASM
-        SOURCES="$SOURCES $srcdir/src/video/gapi/*.c"
-        EXTRA_CFLAGS="$EXTRA_CFLAGS -D_WIN32_WCE=0x420"
-        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"
-            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lmmtimer"
-            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
-        # Set up the system libraries we need
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lcommctrl"
-        # The Win32 platform requires special setup
-        SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
-        SDLMAIN_LDFLAGS="-static"
-        SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main -D_WIN32_WCE=0x420"
-        SDL_LIBS="-lSDLmain $SDL_LIBS"
-        ;;
     *-*-beos* | *-*-haiku*)
         ARCH=beos
         ac_default_prefix=/boot/develop/tools/gnupro
diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index 04d9293f..9f49d17f 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -338,6 +338,9 @@ int SDL_KeyboardInit(void)
 #ifdef _WIN32
 extern void WIN_ResetDeadKeys(void);
 #endif
+#ifdef _WIN32_WCE
+#define WIN_ResetDeadKeys() do {} while(0)
+#endif
 
 void SDL_KeyboardQuit(void)
 {
diff --git a/src/video/gapi/SDL_gapivideo.c b/src/video/gapi/SDL_gapivideo.c
index 220260ab..a8c550f8 100644
--- a/src/video/gapi/SDL_gapivideo.c
+++ b/src/video/gapi/SDL_gapivideo.c
@@ -1132,11 +1132,11 @@ static void GAPI_UpdateRectsColor(_THIS, int numrects, SDL_Rect *rects)
 			switch(bytesPerPixel)
 			{
 			case 1:
-				linesProcessed = updateLine8to8(this, srcPointer, (unsigned char *) destPointer, rects[i].w, rects[i].h, height);
+				linesProcessed = updateLine8to8(this, srcPointer, destPointer, rects[i].w, rects[i].h, height);
 				break;
 			case 2:
 #pragma warning(disable: 4133)
-				linesProcessed = updateLine16to16(this, (PIXEL*) srcPointer, destPointer, rects[i].w, rects[i].h, height);
+				linesProcessed = updateLine16to16(this, (PIXEL*) srcPointer, (PIXEL*) destPointer, rects[i].w, rects[i].h, height);
 				break;
 			}
 			height -= linesProcessed;
@@ -1175,7 +1175,7 @@ void GAPI_VideoQuit(_THIS)
 	/* Destroy the window and everything associated with it */
 	if ( SDL_Window ) 
 	{
-	    if ((g_hGapiLib != 0) && this && gapi && gapi->gxFunc.GXCloseDisplay && !gapi->useVga)
+		if ((g_hGapiLib != 0) && this && gapi && gapi->gxFunc.GXCloseDisplay && !gapi->useVga)
 			gapi->gxFunc.GXCloseDisplay(); 
 
 		if (this->screen->pixels != NULL)
@@ -1192,8 +1192,8 @@ void GAPI_VideoQuit(_THIS)
 		SDL_UnregisterApp();
 
 		SDL_Window = NULL;
-#if defined(_WIN32_WCE)
 
+#if defined(_WIN32_WCE)
 // Unload wince aygshell library to prevent leak
 		if( aygshell ) 
 		{
@@ -1202,18 +1202,16 @@ void GAPI_VideoQuit(_THIS)
 		}
 #endif
 
-	/* Free video mode lists */
-	for ( i=0; i<NUM_MODELISTS; ++i ) {
-		if ( gapi->SDL_modelist[i] != NULL ) {
-			for ( j=0; gapi->SDL_modelist[i][j]; ++j )
-				SDL_free(gapi->SDL_modelist[i][j]);
-			SDL_free(gapi->SDL_modelist[i]);
-			gapi->SDL_modelist[i] = NULL;
+		/* Free video mode lists */
+		for ( i=0; i<NUM_MODELISTS; ++i ) {
+			if ( gapi->SDL_modelist[i] != NULL ) {
+				for ( j=0; gapi->SDL_modelist[i][j]; ++j )
+					SDL_free(gapi->SDL_modelist[i][j]);
+				SDL_free(gapi->SDL_modelist[i]);
+				gapi->SDL_modelist[i] = NULL;
+			}
 		}
 	}
-
-	}
-
 }
 
 static void GAPI_Activate(_THIS, BOOL active, BOOL minimized)
diff --git a/src/video/wincommon/SDL_sysevents.c b/src/video/wincommon/SDL_sysevents.c
index 090f6f16..4f72d521 100644
--- a/src/video/wincommon/SDL_sysevents.c
+++ b/src/video/wincommon/SDL_sysevents.c
@@ -62,6 +62,7 @@
 #if _WIN32_WCE < 420
 #define NO_CHANGEDISPLAYSETTINGS
 #endif
+#undef WM_MOUSELEAVE
 #endif
 
 /* The window we use for everything... */
@@ -376,7 +377,7 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 			if ( SDL_VideoSurface && ! DINPUT() ) {
 				WORD xbuttonval = 0;
 				Uint8 button, state;
-                int x, y;
+				LONG x, y;
 
 				/* DJM:
 				   We want the SDL window to take focus so that
@@ -445,9 +446,9 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 					x = (Sint16)LOWORD(lParam);
 					y = (Sint16)HIWORD(lParam);
 #ifdef _WIN32_WCE
-					if (SDL_VideoSurface)
-						GapiTransform(this->hidden->userOrientation,
-this->hidden->hiresFix, &x, &y);
+					extern void GapiTransform(GapiInfo*, LONG*, LONG*);
+					if (SDL_VideoSurface && this->hidden->gapiInfo)
+						GapiTransform(this->hidden->gapiInfo, &x, &y);
 #endif
 				}
 				posted = SDL_PrivateMouseButton(
@@ -532,12 +533,15 @@ this->hidden->hiresFix, &x, &y);
 			   return value is undefined if hwnd is a child window.
 			   Aparently it's too difficult for MS to check
 			   inside their function, so I have to do it here.
-          		 */
-         		style = GetWindowLong(hwnd, GWL_STYLE);
-         		AdjustWindowRect(
+			 */
+			style = GetWindowLong(hwnd, GWL_STYLE);
+			#ifdef _WIN32_WCE
+			#define GetMenu(x) NULL
+			#endif
+			AdjustWindowRect(
 				&size,
 				style,
-            			style & WS_CHILDWINDOW ? FALSE
+				style & WS_CHILDWINDOW ? FALSE
 						       : GetMenu(hwnd) != NULL);
 
 			width = size.right - size.left;
diff --git a/src/video/wincommon/SDL_syswm.c b/src/video/wincommon/SDL_syswm.c
index 504d95d2..3653ebdc 100644
--- a/src/video/wincommon/SDL_syswm.c
+++ b/src/video/wincommon/SDL_syswm.c
@@ -144,15 +144,15 @@ void WIN_SetWMIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
 	/* Convert icon to a standard surface format.  This may not always
 	   be necessary, as Windows supports a variety of BMP formats, but
 	   it greatly simplifies our code.
-	*/ 
-    bounds.x = 0;
-    bounds.y = 0;
-    bounds.w = icon->w;
-    bounds.h = icon->h;
-    if ( SDL_LowerBlit(icon, &bounds, icon_256, &bounds) < 0 ) {
-	    SDL_stack_free(icon_win32);
+	*/
+	bounds.x = 0;
+	bounds.y = 0;
+	bounds.w = icon->w;
+	bounds.h = icon->h;
+	if ( SDL_LowerBlit(icon, &bounds, icon_256, &bounds) < 0 ) {
+		SDL_stack_free(icon_win32);
 		SDL_FreeSurface(icon_256);
-        return;
+		return;
 	}
 
 	/* Copy pixels upside-down to icon BMP, masked with the icon mask */
@@ -233,6 +233,9 @@ int WIN_IconifyWindow(_THIS)
 	return(1);
 }
 
+#if defined(_WIN32_WCE) && defined(__GNUC__)
+BOOL WINAPI AllKeys(BOOL bAllKeys); /* missing in mingw32ce headers */
+#endif
 SDL_GrabMode WIN_GrabInput(_THIS, SDL_GrabMode mode)
 {
 	if ( mode == SDL_GRAB_OFF ) {
diff --git a/src/video/windib/SDL_dibevents.c b/src/video/windib/SDL_dibevents.c
index e297d776..9bf4f5da 100644
--- a/src/video/windib/SDL_dibevents.c
+++ b/src/video/windib/SDL_dibevents.c
@@ -88,7 +88,7 @@ WPARAM rotateKey(WPARAM key,int direction)
 	return key;
 }
 
-static void GapiTransform(GapiInfo *gapiInfo, LONG *x, LONG *y)
+void GapiTransform(GapiInfo *gapiInfo, LONG *x, LONG *y)
 {
     if(gapiInfo->hiresFix)
     {
@@ -111,7 +111,7 @@ static void GapiTransform(GapiInfo *gapiInfo, LONG *x, LONG *y)
     // 0 0 0
     if((!gapiInfo->userOrientation && !gapiInfo->systemOrientation && !gapiInfo->gapiOrientation) ||
     // 0 0 3
-      (!gapiInfo->userOrientation && !gapiInfo->systemOrientation && gapiInfo->gapiOrientation))
+       (!gapiInfo->userOrientation && !gapiInfo->systemOrientation && gapiInfo->gapiOrientation))
     {
 	// without changes
 	// *x = *x;
@@ -309,6 +309,9 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
 }
 
 #ifdef _WIN32_WCE
+#ifdef __GNUC__
+BOOL WINAPI GetMouseMovePoints(PPOINT pptBuf, UINT nBufPoints, UINT *pnPointsRetrieved); /* missing in mingw32ce headers */
+#endif
 static BOOL GetLastStylusPos(POINT* ptLast)
 {
     BOOL bResult = FALSE;
@@ -350,7 +353,7 @@ static void DIB_GenerateMouseMotionEvent(_THIS)
 	} else {
 		ScreenToClient(SDL_Window, &mouse);
 #ifdef SDL_VIDEO_DRIVER_GAPI
-       if (SDL_VideoSurface && this->hidden->gapiInfo)
+		if (SDL_VideoSurface && this->hidden->gapiInfo)
 			GapiTransform(this->hidden->gapiInfo, &mouse.x, &mouse.y);
 #endif
 		posted = SDL_PrivateMouseMotion(0, 0, (Sint16)mouse.x, (Sint16)mouse.y);
@@ -583,6 +586,7 @@ static int SDL_MapVirtualKey(int scancode, int vkey)
 	return mvke?mvke:vkey;
 }
 
+#ifndef _WIN32_WCE
 #ifndef MAPVK_VK_TO_VSC
 #define MAPVK_VK_TO_VSC 0
 #endif
@@ -613,6 +617,7 @@ WIN_ResetDeadKeys(void)
         }
     }
 }
+#endif
 
 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed)
 {