Updated WinCE support by Dmitry (with some tweaks)
authorSam Lantinga <slouken@libsdl.org>
Sat, 04 Mar 2006 08:24:35 +0000
changeset 14658dfa9a6d69a5
parent 1464 af30090c0330
child 1466 3c45c578d480
Updated WinCE support by Dmitry (with some tweaks)
Converted the disk audio driver to SDL_RWops for portability
VisualC.zip
VisualCE.zip
include/SDL_config_win32.h
include/SDL_thread.h
src/SDL.c
src/audio/SDL_wave.c
src/audio/disk/SDL_diskaudio.c
src/audio/disk/SDL_diskaudio.h
src/file/SDL_rwops.c
src/main/win32/SDL_win32_main.c
src/stdlib/SDL_malloc.c
src/video/gapi/SDL_gapivideo.c
src/video/gapi/SDL_gapivideo.h
src/video/wincommon/SDL_lowvideo.h
src/video/wincommon/SDL_sysevents.c
src/video/wincommon/SDL_syswm.c
src/video/windib/SDL_dibvideo.c
src/video/windib/SDL_dibvideo.h
test/testalpha.c
     1.1 Binary file VisualC.zip has changed
     2.1 Binary file VisualCE.zip has changed
     3.1 --- a/include/SDL_config_win32.h	Sat Mar 04 05:13:03 2006 +0000
     3.2 +++ b/include/SDL_config_win32.h	Sat Mar 04 08:24:35 2006 +0000
     3.3 @@ -26,18 +26,34 @@
     3.4  /* This is a set of defines to configure the SDL features */
     3.5  
     3.6  #ifdef _MSC_VER
     3.7 -typedef __int8			int8_t;
     3.8 +typedef signed __int8		int8_t;
     3.9  typedef unsigned __int8		uint8_t;
    3.10 -typedef __int16			int16_t;
    3.11 +typedef signed __int16		int16_t;
    3.12  typedef unsigned __int16	uint16_t;
    3.13 -typedef __int32			int32_t;
    3.14 +typedef signed __int32		int32_t;
    3.15  typedef unsigned __int32	uint32_t;
    3.16 -typedef __int64			int64_t;
    3.17 +typedef signed __int64		int64_t;
    3.18  typedef unsigned __int64	uint64_t;
    3.19 -#if _MSC_VER <= 1200
    3.20 +#ifndef _UINTPTR_T_DEFINED
    3.21 +#ifdef  _WIN64
    3.22 +typedef unsigned __int64    uintptr_t;
    3.23 +#else
    3.24 +typedef unsigned int   uintptr_t;
    3.25 +#endif
    3.26 +#define _UINTPTR_T_DEFINED
    3.27 +#endif
    3.28 +#else
    3.29 +typedef signed char int8_t;
    3.30 +typedef unsigned char uint8_t;
    3.31 +typedef signed short int16_t;
    3.32 +typedef unsigned short uint16_t;
    3.33 +typedef signed int int32_t;
    3.34 +typedef unsigned int uint32_t;
    3.35 +typedef signed long long int64_t;
    3.36 +typedef unsigned long long uint64_t;
    3.37 +typedef unsigned int size_t;
    3.38  typedef unsigned long uintptr_t;
    3.39 -#endif
    3.40 -#endif
    3.41 +#endif /* _MSC_VER */
    3.42  #define SDL_HAS_64BIT_TYPE	1
    3.43  
    3.44  /* Useful headers */
    3.45 @@ -79,8 +95,10 @@
    3.46  #define SDL_VIDEO_DRIVER_WINDIB	1
    3.47  
    3.48  /* Enable OpenGL support */
    3.49 +#ifndef _WIN32_WCE
    3.50  #define SDL_VIDEO_OPENGL	1
    3.51  #define SDL_VIDEO_OPENGL_WGL	1
    3.52 +#endif
    3.53  
    3.54  /* Enable assembly routines */
    3.55  #define SDL_ASSEMBLY_ROUTINES	1
     4.1 --- a/include/SDL_thread.h	Sat Mar 04 05:13:03 2006 +0000
     4.2 +++ b/include/SDL_thread.h	Sat Mar 04 08:24:35 2006 +0000
     4.3 @@ -59,7 +59,9 @@
     4.4     So, in short:
     4.5     Always use the _beginthread() and _endthread() of the calling runtime library!
     4.6  */
     4.7 +#ifndef _WIN32_WCE
     4.8  #include <process.h> // This has _beginthread() and _endthread() defined!
     4.9 +#endif
    4.10  #ifdef __EMX__
    4.11  #include <stdlib.h> // This has _beginthread() and _endthread() defined, if -Zmt flag is used!
    4.12  #endif
    4.13 @@ -68,9 +70,6 @@
    4.14  typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg); 
    4.15  typedef void (*pfnSDL_CurrentEndThread)(void);
    4.16  #else
    4.17 -#ifdef __GNUC__
    4.18 -#include <stdint.h>
    4.19 -#endif
    4.20  typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
    4.21          unsigned (__stdcall *func)(void *), void *arg, 
    4.22          unsigned, unsigned *threadID);
     5.1 --- a/src/SDL.c	Sat Mar 04 05:13:03 2006 +0000
     5.2 +++ b/src/SDL.c	Sat Mar 04 08:24:35 2006 +0000
     5.3 @@ -325,8 +325,8 @@
     5.4  
     5.5  #elif defined(__WIN32__)
     5.6  
     5.7 -#if !defined(HAVE_LIBC) || defined(_WIN32_WCE) || (defined(__WATCOMC__) && defined(BUILD_DLL))
     5.8 -/* Need to include DllMain() on Windows CE and Watcom C for some reason.. */
     5.9 +#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
    5.10 +/* Need to include DllMain() on Watcom C for some reason.. */
    5.11  #define WIN32_LEAN_AND_MEAN
    5.12  #include <windows.h>
    5.13  
    5.14 @@ -343,6 +343,6 @@
    5.15  	}
    5.16  	return TRUE;
    5.17  }
    5.18 -#endif /* _WIN32_WCE and building DLL with Watcom C */
    5.19 +#endif /* building DLL with Watcom C */
    5.20  
    5.21  #endif /* OS/2 elif __WIN32__ */
     6.1 --- a/src/audio/SDL_wave.c	Sat Mar 04 05:13:03 2006 +0000
     6.2 +++ b/src/audio/SDL_wave.c	Sat Mar 04 08:24:35 2006 +0000
     6.3 @@ -550,12 +550,13 @@
     6.4  	if ( format != NULL ) {
     6.5  		SDL_free(format);
     6.6  	}
     6.7 -	if ( freesrc && src ) {
     6.8 -		SDL_RWclose(src);
     6.9 -	}
    6.10 -	else {
    6.11 -		// seek to the end of the file (given by the RIFF chunk)
    6.12 -		SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR);
    6.13 +	if ( src ) {
    6.14 +		if ( freesrc ) {
    6.15 +			SDL_RWclose(src);
    6.16 +		} else {
    6.17 +			// seek to the end of the file (given by the RIFF chunk)
    6.18 +			SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR);
    6.19 +		}
    6.20  	}
    6.21  	if ( was_error ) {
    6.22  		spec = NULL;
     7.1 --- a/src/audio/disk/SDL_diskaudio.c	Sat Mar 04 05:13:03 2006 +0000
     7.2 +++ b/src/audio/disk/SDL_diskaudio.c	Sat Mar 04 08:24:35 2006 +0000
     7.3 @@ -26,16 +26,11 @@
     7.4  
     7.5  /* Output raw audio data to a file. */
     7.6  
     7.7 +#if HAVE_STDIO_H
     7.8  #include <stdio.h>
     7.9 -#include <string.h>	/* For strerror() */
    7.10 -#include <errno.h>
    7.11 -#include <unistd.h>
    7.12 -#include <sys/stat.h>
    7.13 -#include <sys/types.h>
    7.14 -#include <sys/stat.h>
    7.15 -#include <fcntl.h>
    7.16 +#endif
    7.17  
    7.18 -
    7.19 +#include "SDL_rwops.h"
    7.20  #include "SDL_timer.h"
    7.21  #include "SDL_audio.h"
    7.22  #include "../SDL_audiomem.h"
    7.23 @@ -61,44 +56,18 @@
    7.24  
    7.25  static const char *DISKAUD_GetOutputFilename(void)
    7.26  {
    7.27 -    const char *envr = SDL_getenv(DISKENVR_OUTFILE);
    7.28 -    return((envr != NULL) ? envr : DISKDEFAULT_OUTFILE);
    7.29 +	const char *envr = SDL_getenv(DISKENVR_OUTFILE);
    7.30 +	return((envr != NULL) ? envr : DISKDEFAULT_OUTFILE);
    7.31  }
    7.32  
    7.33  /* Audio driver bootstrap functions */
    7.34  static int DISKAUD_Available(void)
    7.35  {
    7.36 -#if 0
    7.37 -    int fd;
    7.38 -	int available;
    7.39 -    int exists = 0;
    7.40 -    struct stat statbuf;
    7.41 -    const char *fname = DISKAUD_GetOutputFilename();
    7.42  	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
    7.43 -	available = 0;
    7.44 -
    7.45 -	if ((envr) && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
    7.46 -		if (stat(fname, &statbuf) == 0)
    7.47 -			exists = 1;
    7.48 -
    7.49 -		fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
    7.50 -		if ( fd != -1 ) {
    7.51 -			available = 1;
    7.52 -			close(fd);
    7.53 -			if (!exists) {
    7.54 -				unlink(fname);
    7.55 -			}
    7.56 -		}
    7.57 -	}
    7.58 -	return(available);
    7.59 -#else
    7.60 -	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
    7.61 -	if ((envr) && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
    7.62 +	if (envr && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
    7.63  		return(1);
    7.64  	}
    7.65 -
    7.66  	return(0);
    7.67 -#endif
    7.68  }
    7.69  
    7.70  static void DISKAUD_DeleteDevice(SDL_AudioDevice *device)
    7.71 @@ -110,7 +79,7 @@
    7.72  static SDL_AudioDevice *DISKAUD_CreateDevice(int devindex)
    7.73  {
    7.74  	SDL_AudioDevice *this;
    7.75 -    const char *envr;
    7.76 +	const char *envr;
    7.77  
    7.78  	/* Initialize all variables that we clean on shutdown */
    7.79  	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
    7.80 @@ -128,8 +97,8 @@
    7.81  	}
    7.82  	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    7.83  
    7.84 -    envr = SDL_getenv(DISKENVR_WRITEDELAY);
    7.85 -    this->hidden->write_delay = (envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;
    7.86 +	envr = SDL_getenv(DISKENVR_WRITEDELAY);
    7.87 +	this->hidden->write_delay = (envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;
    7.88  
    7.89  	/* Set the function pointers */
    7.90  	this->OpenAudio = DISKAUD_OpenAudio;
    7.91 @@ -151,26 +120,20 @@
    7.92  /* This function waits until it is possible to write a full sound buffer */
    7.93  static void DISKAUD_WaitAudio(_THIS)
    7.94  {
    7.95 -    SDL_Delay(this->hidden->write_delay);
    7.96 +	SDL_Delay(this->hidden->write_delay);
    7.97  }
    7.98  
    7.99  static void DISKAUD_PlayAudio(_THIS)
   7.100  {
   7.101  	int written;
   7.102  
   7.103 -	/* Write the audio data, checking for EAGAIN on broken audio drivers */
   7.104 -	do {
   7.105 -		written = write(this->hidden->audio_fd,
   7.106 -                        this->hidden->mixbuf,
   7.107 +	/* Write the audio data */
   7.108 +	written = SDL_RWwrite(this->hidden->output,
   7.109 +                        this->hidden->mixbuf, 1,
   7.110                          this->hidden->mixlen);
   7.111 -		if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) {
   7.112 -			SDL_Delay(1);	/* Let a little CPU time go by */
   7.113 -		}
   7.114 -	} while ( (written < 0) && 
   7.115 -	          ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) );
   7.116  
   7.117  	/* If we couldn't write, assume fatal error for now */
   7.118 -	if ( written < 0 ) {
   7.119 +	if ( written != this->hidden->mixlen ) {
   7.120  		this->enabled = 0;
   7.121  	}
   7.122  #ifdef DEBUG_AUDIO
   7.123 @@ -189,25 +152,26 @@
   7.124  		SDL_FreeAudioMem(this->hidden->mixbuf);
   7.125  		this->hidden->mixbuf = NULL;
   7.126  	}
   7.127 -	if ( this->hidden->audio_fd >= 0 ) {
   7.128 -		close(this->hidden->audio_fd);
   7.129 -		this->hidden->audio_fd = -1;
   7.130 +	if ( this->hidden->output != NULL ) {
   7.131 +		SDL_RWclose(this->hidden->output);
   7.132 +		this->hidden->output = NULL;
   7.133  	}
   7.134  }
   7.135  
   7.136  static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
   7.137  {
   7.138 -    const char *fname = DISKAUD_GetOutputFilename();
   7.139 +	const char *fname = DISKAUD_GetOutputFilename();
   7.140  
   7.141  	/* Open the audio device */
   7.142 -    this->hidden->audio_fd = open(fname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
   7.143 -	if ( this->hidden->audio_fd < 0 ) {
   7.144 -		SDL_SetError("Couldn't open %s: %s", fname, strerror(errno));
   7.145 +	this->hidden->output = SDL_RWFromFile(fname, "wb");
   7.146 +	if ( this->hidden->output == NULL ) {
   7.147  		return(-1);
   7.148  	}
   7.149  
   7.150 -    fprintf(stderr, "WARNING: You are using the SDL disk writer"
   7.151 +#if HAVE_STDIO_H
   7.152 +	fprintf(stderr, "WARNING: You are using the SDL disk writer"
   7.153                      " audio driver!\n Writing to file [%s].\n", fname);
   7.154 +#endif
   7.155  
   7.156  	/* Allocate mixing buffer */
   7.157  	this->hidden->mixlen = spec->size;
     8.1 --- a/src/audio/disk/SDL_diskaudio.h	Sat Mar 04 05:13:03 2006 +0000
     8.2 +++ b/src/audio/disk/SDL_diskaudio.h	Sat Mar 04 08:24:35 2006 +0000
     8.3 @@ -24,6 +24,7 @@
     8.4  #ifndef _SDL_diskaudio_h
     8.5  #define _SDL_diskaudio_h
     8.6  
     8.7 +#include "SDL_rwops.h"
     8.8  #include "../SDL_sysaudio.h"
     8.9  
    8.10  /* Hidden "this" pointer for the video functions */
    8.11 @@ -31,10 +32,10 @@
    8.12  
    8.13  struct SDL_PrivateAudioData {
    8.14  	/* The file descriptor for the audio device */
    8.15 -	int audio_fd;
    8.16 -    Uint8 *mixbuf;
    8.17 -    Uint32 mixlen;
    8.18 -    Uint32 write_delay;
    8.19 +	SDL_RWops *output;
    8.20 +	Uint8 *mixbuf;
    8.21 +	Uint32 mixlen;
    8.22 +	Uint32 write_delay;
    8.23  };
    8.24  
    8.25  #endif /* _SDL_diskaudio_h */
     9.1 --- a/src/file/SDL_rwops.c	Sat Mar 04 05:13:03 2006 +0000
     9.2 +++ b/src/file/SDL_rwops.c	Sat Mar 04 08:24:35 2006 +0000
     9.3 @@ -29,16 +29,25 @@
     9.4  #include "SDL_rwops.h"
     9.5  
     9.6  
     9.7 -#ifdef __WIN32__
     9.8 +#if defined(__WIN32__)
     9.9  
    9.10  /* Functions to read/write Win32 API file pointers */
    9.11 +/* Will not use it on WinCE because stdio is buffered, it means
    9.12 +   faster, and all stdio functions anyway are embedded in coredll.dll - 
    9.13 +   the main wince dll*/
    9.14  
    9.15  #define WINDOWS_LEAN_AND_MEAN
    9.16  #include <windows.h>
    9.17  
    9.18 -static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode) {
    9.19 -	
    9.20 +#ifndef INVALID_SET_FILE_POINTER
    9.21 +#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
    9.22 +#endif
    9.23 +
    9.24 +static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
    9.25 +{
    9.26 +#ifndef _WIN32_WCE
    9.27  	UINT	old_error_mode;
    9.28 +#endif
    9.29  	HANDLE	h;
    9.30  	DWORD	r_right, w_right;
    9.31  	DWORD	must_exist, truncate;
    9.32 @@ -64,15 +73,31 @@
    9.33  
    9.34  	if (!r_right && !w_right) /* inconsistent mode */
    9.35  		return -1; /* failed (invalid call)*/
    9.36 -	
    9.37 +
    9.38 +#ifdef _WIN32_WCE
    9.39 +	{
    9.40 +		size_t size = SDL_strlen(filename)+1;
    9.41 +		wchar_t *filenameW = SDL_stack_alloc(wchar_t, size);
    9.42 +
    9.43 +		if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
    9.44 +			SDL_SetError("Unable to convert filename to Unicode");
    9.45 +			SDL_stack_free(filenameW);
    9.46 +			return -1;
    9.47 +		}
    9.48 +		h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
    9.49 +					   NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
    9.50 +		SDL_stack_free(filenameW);
    9.51 +	}
    9.52 +#else
    9.53  	/* Do not open a dialog box if failure */
    9.54 -	old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);	
    9.55 -	
    9.56 +	old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
    9.57 +
    9.58  	h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
    9.59  		           NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
    9.60 -	
    9.61 +
    9.62  	/* restore old behaviour */
    9.63  	SetErrorMode(old_error_mode);
    9.64 +#endif /* _WIN32_WCE */
    9.65  
    9.66  	if (h==INVALID_HANDLE_VALUE) {
    9.67  		SDL_SetError("Couldn't open %s",filename);
    9.68 @@ -83,7 +108,8 @@
    9.69  	
    9.70  	return 0; /* ok */
    9.71  }
    9.72 -static int win32_file_seek(SDL_RWops *context, int offset, int whence) {
    9.73 +static int win32_file_seek(SDL_RWops *context, int offset, int whence)
    9.74 +{
    9.75  	DWORD win32whence;
    9.76  	int   file_pos;
    9.77  	
    9.78 @@ -112,7 +138,8 @@
    9.79  	SDL_Error(SDL_EFSEEK);
    9.80  	return -1; /* error */
    9.81  }
    9.82 -static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum) {
    9.83 +static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
    9.84 +{
    9.85  	
    9.86  	int		total_bytes; 
    9.87  	DWORD	byte_read,nread;
    9.88 @@ -129,7 +156,8 @@
    9.89  	nread = byte_read/size;
    9.90  	return nread;
    9.91  }
    9.92 -static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num) {
    9.93 +static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
    9.94 +{
    9.95  	
    9.96  	int		total_bytes; 
    9.97  	DWORD	byte_written,nwritten;
    9.98 @@ -155,7 +183,8 @@
    9.99  	nwritten = byte_written/size;
   9.100  	return nwritten;
   9.101  }
   9.102 -static int win32_file_close(SDL_RWops *context) {
   9.103 +static int win32_file_close(SDL_RWops *context)
   9.104 +{
   9.105  	
   9.106  	if ( context ) {								
   9.107  		if (context->hidden.win32io.h != INVALID_HANDLE_VALUE) {
   9.108 @@ -249,7 +278,7 @@
   9.109  	size_t mem_available;
   9.110  
   9.111  	total_bytes = (maxnum * size);
   9.112 -	if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) ) {
   9.113 +	if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != (size_t) size) ) {
   9.114  		return 0;
   9.115  	}
   9.116  
   9.117 @@ -335,13 +364,15 @@
   9.118  SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
   9.119  {
   9.120  	SDL_RWops *rwops = NULL;
   9.121 -
   9.122 +#ifdef HAVE_STDIO_H
   9.123 +	FILE *fp = NULL;
   9.124 +#endif
   9.125  	if ( !file || !*file || !mode || !*mode ) {
   9.126  		SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
   9.127  		return NULL;
   9.128  	}
   9.129  
   9.130 -#ifdef __WIN32__
   9.131 +#if defined(__WIN32__)
   9.132  	rwops = SDL_AllocRW();
   9.133  	if (!rwops)
   9.134  		return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
   9.135 @@ -356,7 +387,6 @@
   9.136  	rwops->close = win32_file_close;
   9.137  
   9.138  #elif HAVE_STDIO_H
   9.139 -	FILE *fp;
   9.140  
   9.141  #ifdef __MACOS__
   9.142  	{
    10.1 --- a/src/main/win32/SDL_win32_main.c	Sat Mar 04 05:13:03 2006 +0000
    10.2 +++ b/src/main/win32/SDL_win32_main.c	Sat Mar 04 08:24:35 2006 +0000
    10.3 @@ -51,27 +51,6 @@
    10.4  #if defined(_WIN32_WCE) && _WIN32_WCE < 300
    10.5  /* seems to be undefined in Win CE although in online help */
    10.6  #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
    10.7 -
    10.8 -/* seems to be undefined in Win CE although in online help */
    10.9 -char *SDL_strrchr(char *str, int c)
   10.10 -{
   10.11 -	char *p;
   10.12 -
   10.13 -	/* Skip to the end of the string */
   10.14 -	p=str;
   10.15 -	while (*p)
   10.16 -		p++;
   10.17 -
   10.18 -	/* Look for the given character */
   10.19 -	while ( (p >= str) && (*p != (CHAR)c) )
   10.20 -		p--;
   10.21 -
   10.22 -	/* Return NULL if character not found */
   10.23 -	if ( p < str ) {
   10.24 -		p = NULL;
   10.25 -	}
   10.26 -	return p;
   10.27 -}
   10.28  #endif /* _WIN32_WCE < 300 */
   10.29  
   10.30  /* Parse a command line buffer into arguments */
   10.31 @@ -281,8 +260,13 @@
   10.32  	}
   10.33  	path[pathlen] = '\0';
   10.34  
   10.35 +#ifdef _WIN32_WCE
   10.36 +	wcsncpy( stdoutPath, path, SDL_arraysize(stdoutPath) );
   10.37 +	wcsncat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) );
   10.38 +#else
   10.39  	SDL_strlcpy( stdoutPath, path, SDL_arraysize(stdoutPath) );
   10.40  	SDL_strlcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) );
   10.41 +#endif
   10.42      
   10.43  	/* Redirect standard input and standard output */
   10.44  	newfp = freopen(stdoutPath, TEXT("w"), stdout);
   10.45 @@ -300,8 +284,13 @@
   10.46  	}
   10.47  #endif /* _WIN32_WCE */
   10.48  
   10.49 +#ifdef _WIN32_WCE
   10.50 +	wcsncpy( stderrPath, path, SDL_arraysize(stdoutPath) );
   10.51 +	wcsncat( stderrPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) );
   10.52 +#else
   10.53  	SDL_strlcpy( stderrPath, path, SDL_arraysize(stderrPath) );
   10.54  	SDL_strlcat( stderrPath, DIR_SEPERATOR STDERR_FILE, SDL_arraysize(stderrPath) );
   10.55 +#endif
   10.56  
   10.57  	newfp = freopen(stderrPath, TEXT("w"), stderr);
   10.58  #ifndef _WIN32_WCE
   10.59 @@ -329,7 +318,7 @@
   10.60  	wcscpy (bufp+wcslen(bufp), TEXT("\" "));
   10.61  	wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp));
   10.62  	nLen = wcslen(bufp)+1;
   10.63 -	cmdline = SDL_stack_alloc(wchar_t, nLen);
   10.64 +	cmdline = SDL_stack_alloc(char, nLen);
   10.65  	if ( cmdline == NULL ) {
   10.66  		return OutOfMemory();
   10.67  	}
    11.1 --- a/src/stdlib/SDL_malloc.c	Sat Mar 04 05:13:03 2006 +0000
    11.2 +++ b/src/stdlib/SDL_malloc.c	Sat Mar 04 08:24:35 2006 +0000
    11.3 @@ -27,17 +27,12 @@
    11.4  
    11.5  #ifndef HAVE_MALLOC
    11.6  
    11.7 +#define LACKS_SYS_TYPES_H
    11.8  #define LACKS_STDIO_H
    11.9  #define LACKS_STRINGS_H
   11.10  #define LACKS_STRING_H
   11.11  #define LACKS_STDLIB_H
   11.12  #define ABORT
   11.13 -#define memset	SDL_memset
   11.14 -#define memcpy	SDL_memcpy
   11.15 -#define malloc	SDL_malloc
   11.16 -#define calloc	SDL_calloc
   11.17 -#define realloc	SDL_realloc
   11.18 -#define free	SDL_free
   11.19  
   11.20  /*
   11.21    This is a version (aka dlmalloc) of malloc/free/realloc written by
   11.22 @@ -496,6 +491,7 @@
   11.23  #define LACKS_STRINGS_H
   11.24  #define LACKS_SYS_TYPES_H
   11.25  #define LACKS_ERRNO_H
   11.26 +#define LACKS_FCNTL_H 
   11.27  #define MALLOC_FAILURE_ACTION
   11.28  #define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */
   11.29  #endif  /* WIN32 */
   11.30 @@ -613,6 +609,13 @@
   11.31  #define MALLINFO_FIELD_TYPE size_t
   11.32  #endif  /* MALLINFO_FIELD_TYPE */
   11.33  
   11.34 +#define memset	SDL_memset
   11.35 +#define memcpy	SDL_memcpy
   11.36 +#define malloc	SDL_malloc
   11.37 +#define calloc	SDL_calloc
   11.38 +#define realloc	SDL_realloc
   11.39 +#define free	SDL_free
   11.40 +
   11.41  /*
   11.42    mallopt tuning options.  SVID/XPG defines four standard parameter
   11.43    numbers for mallopt, normally defined in malloc.h.  None of these
    12.1 --- a/src/video/gapi/SDL_gapivideo.c	Sat Mar 04 05:13:03 2006 +0000
    12.2 +++ b/src/video/gapi/SDL_gapivideo.c	Sat Mar 04 08:24:35 2006 +0000
    12.3 @@ -33,15 +33,24 @@
    12.4  // TODO: windib on SH3 PPC2000 landscape test
    12.5  // TODO: optimize 8bpp landscape mode
    12.6  
    12.7 +// there is some problems in runnings apps from a device landscape mode
    12.8 +// due to WinCE bugs. Some works and some - does not.
    12.9 +// TODO: finish Axim Dell X30 and user landscape mode, device landscape mode
   12.10 +// TODO: finish Axim Dell X30 user portrait, device landscape stylus conversion
   12.11 +// TODO: fix running GAPI apps from landscape mode - 
   12.12 +//       wince goes to portrait mode, but does not update video memory
   12.13 +
   12.14 +
   12.15 +#include "SDL.h"
   12.16 +#include "SDL_error.h"
   12.17  #include "SDL_video.h"
   12.18  #include "SDL_mouse.h"
   12.19  #include "../SDL_sysvideo.h"
   12.20  #include "../SDL_pixels_c.h"
   12.21  #include "../../events/SDL_events_c.h"
   12.22 -
   12.23 -#include "SDL_syswm_c.h"
   12.24 -#include "SDL_sysmouse_c.h"
   12.25 -#include "SDL_dibevents_c.h" 
   12.26 +#include "../wincommon/SDL_syswm_c.h"
   12.27 +#include "../wincommon/SDL_sysmouse_c.h"
   12.28 +#include "../windib/SDL_dibevents_c.h" 
   12.29  
   12.30  #include "SDL_gapivideo.h"
   12.31  
   12.32 @@ -55,6 +64,8 @@
   12.33  
   12.34  // for testing with GapiEmu
   12.35  #define USE_GAPI_EMU 0
   12.36 +#define EMULATE_AXIM_X30 0
   12.37 +#define WITHOUT_GAPI 0
   12.38  
   12.39  #if USE_GAPI_EMU && !REPORT_VIDEO_INFO
   12.40  #pragma message("Warning: Using GapiEmu in release build. I assume you'd like to set USE_GAPI_EMU to zero.")
   12.41 @@ -113,7 +124,25 @@
   12.42  
   12.43  #define FORMAT_565 1
   12.44  #define FORMAT_555 2
   12.45 -#define FORMAT_OTHER 3 
   12.46 +#define FORMAT_OTHER 3
   12.47 +
   12.48 +/* Dell Axim x30 hangs when we use GAPI from landscape,
   12.49 +   so lets avoid using GxOpenDisplay there via GETGXINFO trick 
   12.50 +   It seems that GAPI subsystem use the same ExtEscape code.
   12.51 +*/
   12.52 +#define GETGXINFO 0x00020000
   12.53 +
   12.54 +typedef struct GXDeviceInfo
   12.55 +{
   12.56 +long Version; //00 (should filled with 100 before calling ExtEscape)
   12.57 +void * pvFrameBuffer; //04
   12.58 +unsigned long cbStride; //08
   12.59 +unsigned long cxWidth; //0c
   12.60 +unsigned long cyHeight; //10
   12.61 +unsigned long cBPP; //14
   12.62 +unsigned long ffFormat; //18
   12.63 +char Unused[0x84-7*4];
   12.64 +} GXDeviceInfo; 
   12.65  
   12.66  static int GAPI_Available(void)
   12.67  {
   12.68 @@ -123,6 +152,10 @@
   12.69  	ReleaseDC(NULL, hdc);
   12.70  	g_bRawBufferAvailable = result > 0;
   12.71  
   12.72 +#if WITHOUT_GAPI
   12.73 +	return g_bRawBufferAvailable;
   12.74 +#endif
   12.75 +
   12.76  #if USE_GAPI_EMU
   12.77  	g_hGapiLib = LoadLibrary(_T("GAPI_Emu.dll"));
   12.78  	if( !g_hGapiLib )
   12.79 @@ -332,6 +365,8 @@
   12.80  		this->hidden->needUpdate = 1;
   12.81  		this->hidden->hiresFix = 0;
   12.82  		this->hidden->useVga = 0;
   12.83 +		this->hidden->useGXOpenDisplay = 1;
   12.84 +
   12.85  #ifdef _ARM_
   12.86  		/* check some devices and extract addition info */
   12.87  		SystemParametersInfo( SPI_GETOEMINFO, sizeof( oemstr ), oemstr, 0 );
   12.88 @@ -344,6 +379,29 @@
   12.89  			this->hidden->gxProperties.cbyPitch = 2;
   12.90  			this->hidden->needUpdate = 0;
   12.91  		}
   12.92 +#if (EMULATE_AXIM_X30 == 0)
   12.93 +		// buggy Dell Axim X30
   12.94 +		if( _tcsncmp(oemstr, L"Dell Axim X30", 13) == 0 )
   12.95 +#endif
   12.96 +		{
   12.97 +			GXDeviceInfo gxInfo = {0};
   12.98 +			HDC hdc = GetDC(NULL);
   12.99 +			int result;
  12.100 +
  12.101 +			gxInfo.Version = 100;
  12.102 +			result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *)&gxInfo);
  12.103 +			if( result > 0 )
  12.104 +			{
  12.105 +				this->hidden->useGXOpenDisplay = 0;
  12.106 +				this->hidden->videoMem = gxInfo.pvFrameBuffer;
  12.107 +				this->hidden->needUpdate = 0;
  12.108 +				this->hidden->gxProperties.cbxPitch = 2;
  12.109 +				this->hidden->gxProperties.cbyPitch = 480;
  12.110 +				this->hidden->gxProperties.cxWidth = gxInfo.cxWidth;
  12.111 +				this->hidden->gxProperties.cyHeight = gxInfo.cyHeight;
  12.112 +				this->hidden->gxProperties.ffFormat = gxInfo.ffFormat;
  12.113 +			}
  12.114 +		}
  12.115  #endif
  12.116  	} else
  12.117  	{
  12.118 @@ -598,7 +656,7 @@
  12.119  		return(NULL);
  12.120  	}
  12.121  
  12.122 -	/* detect landscape mode */
  12.123 +	/* detect user landscape mode */
  12.124  	if( (width > height) && (GetSystemMetrics(SM_CXSCREEN) < GetSystemMetrics(SM_CYSCREEN))) 
  12.125  		gapi->userOrientation = SDL_ORIENTATION_RIGHT;
  12.126  
  12.127 @@ -610,7 +668,8 @@
  12.128  			gapi->hiresFix = 1;
  12.129  	} else
  12.130  		if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height > GetSystemMetrics(SM_CYSCREEN)))
  12.131 -			gapi->hiresFix = 1;
  12.132 +			if( !((width == GetSystemMetrics(SM_CYSCREEN)) && (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait, device landscape
  12.133 +				gapi->hiresFix = 1;
  12.134  
  12.135  	switch( gapi->userOrientation )
  12.136  	{
  12.137 @@ -652,7 +711,7 @@
  12.138  
  12.139  	if (!SDL_windowid)
  12.140  		SetWindowLong(SDL_Window, GWL_STYLE, style);
  12.141 - 
  12.142 +
  12.143  	/* Allocate bitmap */
  12.144  	if(gapiBuffer) 
  12.145  	{
  12.146 @@ -672,6 +731,14 @@
  12.147  	ShowWindow(SDL_Window, SW_SHOW);
  12.148  	SetForegroundWindow(SDL_Window);
  12.149  
  12.150 +	/* Open GAPI display */
  12.151 +	if( !gapi->useVga && this->hidden->useGXOpenDisplay )
  12.152 +		if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
  12.153 +		{
  12.154 +			SDL_SetError("Couldn't initialize GAPI");
  12.155 +			return(NULL);
  12.156 +		}
  12.157 +
  12.158  #if REPORT_VIDEO_INFO
  12.159  	printf("Video properties:\n");
  12.160  	printf("display bpp: %d\n", gapi->gxProperties.cBPP);
  12.161 @@ -680,24 +747,24 @@
  12.162  	printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
  12.163  	printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
  12.164  	printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
  12.165 +
  12.166 +	if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate)
  12.167 +	{
  12.168 +		gapi->videoMem = gapi->gxFunc.GXBeginDraw(); 
  12.169 +		gapi->gxFunc.GXEndDraw();
  12.170 +	}
  12.171 +
  12.172  	printf("video memory: 0x%x\n", gapi->videoMem);
  12.173  	printf("need update: %d\n", gapi->needUpdate);
  12.174  	printf("hi-res fix: %d\n", gapi->hiresFix);
  12.175  	printf("VGA is available on the device: %d\n", g_bRawBufferAvailable);
  12.176 -	printf("use VGA resolution: %d\n", gapi->useVga);
  12.177 +	printf("use raw framebuffer: %d\n", gapi->useVga);
  12.178  	printf("video surface bpp: %d\n", video->format->BitsPerPixel);
  12.179  	printf("video surface width: %d\n", video->w);
  12.180  	printf("video surface height: %d\n", video->h);
  12.181  #endif
  12.182  
  12.183 -	/* Open GAPI display */
  12.184 -	if( !gapi->useVga )
  12.185 -		if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
  12.186 -		{
  12.187 -			SDL_SetError("Couldn't initialize GAPI");
  12.188 -			return(NULL);
  12.189 -		}
  12.190 - 
  12.191 +
  12.192  	/* Blank screen */
  12.193  	allScreen.x = allScreen.y = 0;
  12.194  	allScreen.w = video->w - 1;
  12.195 @@ -790,6 +857,7 @@
  12.196  			else
  12.197  			{
  12.198  				destPointer += gapi->gxProperties.cbyPitch / 2;
  12.199 +
  12.200  				while(width--) // iPaq 3660
  12.201  				{
  12.202  					*(DWORD*)destPointer =(*line1++ << 16) | *line2++;
    13.1 --- a/src/video/gapi/SDL_gapivideo.h	Sat Mar 04 05:13:03 2006 +0000
    13.2 +++ b/src/video/gapi/SDL_gapivideo.h	Sat Mar 04 08:24:35 2006 +0000
    13.3 @@ -136,6 +136,7 @@
    13.4  	int invert;
    13.5  	char hiresFix; // using hires mode without defining hires resource
    13.6  // --------------
    13.7 +	int useGXOpenDisplay; /* use GXOpenDispplay */
    13.8      int w, h;
    13.9  	enum SDL_ScreenOrientation gapiOrientation;
   13.10  
    14.1 --- a/src/video/wincommon/SDL_lowvideo.h	Sat Mar 04 05:13:03 2006 +0000
    14.2 +++ b/src/video/wincommon/SDL_lowvideo.h	Sat Mar 04 08:24:35 2006 +0000
    14.3 @@ -27,6 +27,16 @@
    14.4  #define WIN32_LEAN_AND_MEAN
    14.5  #include <windows.h>
    14.6  
    14.7 +#ifndef SetClassLongPtr
    14.8 +#define SetClassLongPtr	SetClassLong
    14.9 +#endif
   14.10 +#ifndef GetWindowLongPtr
   14.11 +#define GetWindowLongPtr	GetWindowLong
   14.12 +#endif
   14.13 +#ifndef SetWindowLongPtr
   14.14 +#define SetWindowLongPtr	SetWindowLong
   14.15 +#endif
   14.16 +
   14.17  #include "../SDL_sysvideo.h"
   14.18  
   14.19  /* Hidden "this" pointer for the video functions */
    15.1 --- a/src/video/wincommon/SDL_sysevents.c	Sat Mar 04 05:13:03 2006 +0000
    15.2 +++ b/src/video/wincommon/SDL_sysevents.c	Sat Mar 04 08:24:35 2006 +0000
    15.3 @@ -40,10 +40,14 @@
    15.4  #endif
    15.5  
    15.6  #ifdef _WIN32_WCE
    15.7 -#include "SDL_gapivideo.h"
    15.8 +#include "../gapi/SDL_gapivideo.h"
    15.9 +
   15.10 +#define IsZoomed(HWND) 1
   15.11  #define NO_GETKEYBOARDSTATE
   15.12 +#if _WIN32_WCE < 420
   15.13  #define NO_CHANGEDISPLAYSETTINGS
   15.14  #endif
   15.15 +#endif
   15.16  
   15.17  /* The window we use for everything... */
   15.18  #ifdef _WIN32_WCE
   15.19 @@ -120,6 +124,29 @@
   15.20  
   15.21  	switch(rotate) {
   15.22  		case SDL_ORIENTATION_UP:
   15.23 +			{
   15.24 +/* this code needs testing on a real device!
   15.25 +   So it will be enabled later */
   15.26 +/*
   15.27 +#ifdef _WIN32_WCE
   15.28 +#if _WIN32_WCE >= 420
   15.29 +				// test device orientation
   15.30 +				// FIXME: do not check every mouse message
   15.31 +				DEVMODE settings;
   15.32 +				SDL_memset(&settings, 0, sizeof(DEVMODE));
   15.33 +				settings.dmSize = sizeof(DEVMODE);
   15.34 +				settings.dmFields = DM_DISPLAYORIENTATION;
   15.35 +				ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
   15.36 +				if( settings.dmOrientation == DMDO_90 )
   15.37 +				{
   15.38 +					rotatedX = SDL_VideoSurface->h - *x;
   15.39 +					rotatedY = *y;
   15.40 +					*x = rotatedX;
   15.41 +					*y = rotatedY;
   15.42 +				}
   15.43 +#endif
   15.44 +#endif */
   15.45 +			}
   15.46  			break;
   15.47  		case SDL_ORIENTATION_RIGHT:
   15.48  			if (!SDL_VideoSurface)
   15.49 @@ -144,17 +171,21 @@
   15.50  
   15.51  static void SDL_RestoreGameMode(void)
   15.52  {
   15.53 +	ShowWindow(SDL_Window, SW_RESTORE);
   15.54  #ifndef NO_CHANGEDISPLAYSETTINGS
   15.55 -	ShowWindow(SDL_Window, SW_RESTORE);
   15.56 +#ifndef _WIN32_WCE
   15.57  	ChangeDisplaySettings(&SDL_fullscreen_mode, CDS_FULLSCREEN);
   15.58  #endif
   15.59 +#endif /* NO_CHANGEDISPLAYSETTINGS */
   15.60  }
   15.61  static void SDL_RestoreDesktopMode(void)
   15.62  {
   15.63 +	ShowWindow(SDL_Window, SW_MINIMIZE);
   15.64  #ifndef NO_CHANGEDISPLAYSETTINGS
   15.65 -	ShowWindow(SDL_Window, SW_MINIMIZE);
   15.66 +#ifndef _WIN32_WCE
   15.67  	ChangeDisplaySettings(NULL, 0);
   15.68  #endif
   15.69 +#endif /* NO_CHANGEDISPLAYSETTINGS */
   15.70  }
   15.71  
   15.72  #ifdef WM_MOUSELEAVE
    16.1 --- a/src/video/wincommon/SDL_syswm.c	Sat Mar 04 05:13:03 2006 +0000
    16.2 +++ b/src/video/wincommon/SDL_syswm.c	Sat Mar 04 08:24:35 2006 +0000
    16.3 @@ -220,9 +220,6 @@
    16.4  	if ( screen_icn == NULL ) {
    16.5  		SDL_SetError("Couldn't create Win32 icon handle");
    16.6  	} else {
    16.7 -#ifndef SetClassLongPtr
    16.8 -#define SetClassLongPtr	SetClassLong
    16.9 -#endif
   16.10  		SetClassLongPtr(SDL_Window, GCL_HICON, (LONG_PTR)screen_icn);
   16.11  	}
   16.12  	SDL_stack_free(icon_win32);
    17.1 --- a/src/video/windib/SDL_dibvideo.c	Sat Mar 04 05:13:03 2006 +0000
    17.2 +++ b/src/video/windib/SDL_dibvideo.c	Sat Mar 04 08:24:35 2006 +0000
    17.3 @@ -24,13 +24,6 @@
    17.4  #define WIN32_LEAN_AND_MEAN
    17.5  #include <windows.h>
    17.6  
    17.7 -#if defined(_WIN32_WCE)
    17.8 -
    17.9 -// defined and used in SDL_sysevents.c
   17.10 -extern HINSTANCE aygshell;
   17.11 -
   17.12 -#endif
   17.13 -
   17.14  /* Not yet in the mingw32 cross-compile headers */
   17.15  #ifndef CDS_FULLSCREEN
   17.16  #define CDS_FULLSCREEN	4
   17.17 @@ -49,8 +42,12 @@
   17.18  
   17.19  #ifdef _WIN32_WCE
   17.20  #define NO_GETDIBITS
   17.21 -#define NO_CHANGEDISPLAYSETTINGS
   17.22  #define NO_GAMMA_SUPPORT
   17.23 +  #if _WIN32_WCE < 420
   17.24 +    #define NO_CHANGEDISPLAYSETTINGS
   17.25 +  #else
   17.26 +    #define ChangeDisplaySettings(lpDevMode, dwFlags) ChangeDisplaySettingsEx(NULL, (lpDevMode), 0, (dwFlags), 0)
   17.27 +  #endif
   17.28  #endif
   17.29  #ifndef WS_MAXIMIZE
   17.30  #define WS_MAXIMIZE	0
   17.31 @@ -65,6 +62,11 @@
   17.32  #define PC_NOCOLLAPSE	0
   17.33  #endif
   17.34  
   17.35 +#ifdef _WIN32_WCE
   17.36 +// defined and used in SDL_sysevents.c
   17.37 +extern HINSTANCE aygshell;
   17.38 +#endif
   17.39 +
   17.40  /* Initialization/Query functions */
   17.41  static int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat);
   17.42  static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   17.43 @@ -190,8 +192,6 @@
   17.44  	DIB_Available, DIB_CreateDevice
   17.45  };
   17.46  
   17.47 -#ifndef NO_CHANGEDISPLAYSETTINGS
   17.48 -
   17.49  static int cmpmodes(const void *va, const void *vb)
   17.50  {
   17.51      SDL_Rect *a = *(SDL_Rect **)va;
   17.52 @@ -248,8 +248,6 @@
   17.53  	return(0);
   17.54  }
   17.55  
   17.56 -#endif /* !NO_CHANGEDISPLAYSETTINGS */
   17.57 -
   17.58  static HPALETTE DIB_CreatePalette(int bpp)
   17.59  {
   17.60  /*	RJR: March 28, 2000
   17.61 @@ -326,6 +324,13 @@
   17.62  	DIB_CheckGamma(this);
   17.63  
   17.64  #ifndef NO_CHANGEDISPLAYSETTINGS
   17.65 +
   17.66 +	settings.dmSize = sizeof(DEVMODE);
   17.67 +	settings.dmDriverExtra = 0;
   17.68 +#ifdef _WIN32_WCE
   17.69 +	settings.dmFields = DM_DISPLAYQUERYORIENTATION;
   17.70 +	this->hidden->supportRotation = ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL) == DISP_CHANGE_SUCCESSFUL;
   17.71 +#endif
   17.72  	/* Query for the desktop resolution */
   17.73  	EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
   17.74  
   17.75 @@ -333,13 +338,30 @@
   17.76  	for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) {
   17.77  		DIB_AddMode(this, settings.dmBitsPerPel,
   17.78  			settings.dmPelsWidth, settings.dmPelsHeight);
   17.79 +#ifdef _WIN32_WCE		
   17.80 +		if( this->hidden->supportRotation )
   17.81 +			DIB_AddMode(this, settings.dmBitsPerPel,
   17.82 +				settings.dmPelsHeight, settings.dmPelsWidth);
   17.83 +#endif
   17.84  	}
   17.85  	/* Sort the mode lists */
   17.86 +	if( i > 1 )
   17.87  	for ( i=0; i<NUM_MODELISTS; ++i ) {
   17.88  		if ( SDL_nummodes[i] > 0 ) {
   17.89  			SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
   17.90  		}
   17.91  	}
   17.92 +#else
   17.93 +	// WinCE and fullscreen mode:
   17.94 +	// We use only vformat->BitsPerPixel that allow SDL to
   17.95 +	// emulate other bpp (8, 32) and use triple buffer, 
   17.96 +	// because SDL surface conversion is much faster than the WinCE one.
   17.97 +	// Although it should be tested on devices with graphics accelerator.
   17.98 +
   17.99 +    DIB_AddMode(this, vformat->BitsPerPixel,
  17.100 +			GetDeviceCaps(GetDC(NULL), HORZRES), 
  17.101 +			GetDeviceCaps(GetDC(NULL), VERTRES));
  17.102 +
  17.103  #endif /* !NO_CHANGEDISPLAYSETTINGS */
  17.104  
  17.105  	/* Grab an identity palette if we are in a palettized mode */
  17.106 @@ -352,6 +374,10 @@
  17.107  	/* Fill in some window manager capabilities */
  17.108  	this->info.wm_available = 1;
  17.109  
  17.110 +#ifdef _WIN32_WCE
  17.111 +	this->hidden->origRotation = -1;
  17.112 +#endif
  17.113 +
  17.114  	/* We're done! */
  17.115  	return(0);
  17.116  }
  17.117 @@ -359,15 +385,11 @@
  17.118  /* We support any format at any dimension */
  17.119  SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  17.120  {
  17.121 -#ifdef NO_CHANGEDISPLAYSETTINGS
  17.122 -	return((SDL_Rect **)-1);
  17.123 -#else
  17.124  	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  17.125  		return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
  17.126  	} else {
  17.127  		return((SDL_Rect **)-1);
  17.128  	}
  17.129 -#endif
  17.130  }
  17.131  
  17.132  
  17.133 @@ -531,6 +553,61 @@
  17.134  
  17.135  		SDL_memset(&settings, 0, sizeof(DEVMODE));
  17.136  		settings.dmSize = sizeof(DEVMODE);
  17.137 +
  17.138 +#ifdef _WIN32_WCE
  17.139 +		// try to rotate screen to fit requested resolution
  17.140 +		if( this->hidden->supportRotation )
  17.141 +		{
  17.142 +			DWORD rotation;
  17.143 +
  17.144 +			// ask current mode
  17.145 +			settings.dmFields = DM_DISPLAYORIENTATION;
  17.146 +			ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
  17.147 +			rotation = settings.dmDisplayOrientation;
  17.148 +
  17.149 +			if( (width > GetDeviceCaps(GetDC(NULL), HORZRES))
  17.150 +				&& (height < GetDeviceCaps(GetDC(NULL), VERTRES)))
  17.151 +			{
  17.152 +				switch( rotation )
  17.153 +				{
  17.154 +				case DMDO_0:
  17.155 +					settings.dmDisplayOrientation = DMDO_90;
  17.156 +					break;
  17.157 +				case DMDO_270:
  17.158 +					settings.dmDisplayOrientation = DMDO_180;
  17.159 +					break;
  17.160 +				}
  17.161 +				if( settings.dmDisplayOrientation != rotation )
  17.162 +				{
  17.163 +					// go to landscape
  17.164 +					this->hidden->origRotation = rotation;
  17.165 +					ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL);
  17.166 +				}
  17.167 +			}
  17.168 +			if( (width < GetDeviceCaps(GetDC(NULL), HORZRES))
  17.169 +				&& (height > GetDeviceCaps(GetDC(NULL), VERTRES)))
  17.170 +			{
  17.171 +				switch( rotation )
  17.172 +				{
  17.173 +				case DMDO_90:
  17.174 +					settings.dmDisplayOrientation = DMDO_0;
  17.175 +					break;
  17.176 +				case DMDO_180:
  17.177 +					settings.dmDisplayOrientation = DMDO_270;
  17.178 +					break;
  17.179 +				}
  17.180 +				if( settings.dmDisplayOrientation != rotation )
  17.181 +				{
  17.182 +					// go to portrait
  17.183 +					this->hidden->origRotation = rotation;
  17.184 +					ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL);
  17.185 +				}
  17.186 +			}
  17.187 +
  17.188 +		}
  17.189 +#endif
  17.190 +
  17.191 +#ifndef _WIN32_WCE
  17.192  		settings.dmBitsPerPel = video->format->BitsPerPixel;
  17.193  		settings.dmPelsWidth = width;
  17.194  		settings.dmPelsHeight = height;
  17.195 @@ -545,10 +622,14 @@
  17.196  			settings.dmFields &= ~DM_DISPLAYFREQUENCY;
  17.197  			changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
  17.198  		}
  17.199 +#else
  17.200 +		changed = 1;
  17.201 +#endif
  17.202  		if ( changed ) {
  17.203  			video->flags |= SDL_FULLSCREEN;
  17.204  			SDL_fullscreen_mode = settings;
  17.205  		}
  17.206 +
  17.207  	}
  17.208  #endif /* !NO_CHANGEDISPLAYSETTINGS */
  17.209  
  17.210 @@ -669,9 +750,12 @@
  17.211  			video->flags |= SDL_HWPALETTE;
  17.212  		}
  17.213  	}
  17.214 -
  17.215 +#ifndef _WIN32_WCE
  17.216  	/* Resize the window */
  17.217  	if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
  17.218 +#else
  17.219 +	if ( !SDL_windowid ) {
  17.220 +#endif
  17.221  		HWND top;
  17.222  		UINT swp_flags;
  17.223  		const char *window = NULL;
    18.1 --- a/src/video/windib/SDL_dibvideo.h	Sat Mar 04 05:13:03 2006 +0000
    18.2 +++ b/src/video/windib/SDL_dibvideo.h	Sat Mar 04 08:24:35 2006 +0000
    18.3 @@ -46,8 +46,12 @@
    18.4      SDL_Rect **SDL_modelist[NUM_MODELISTS];
    18.5  
    18.6  	SDL_ScreenOrientation orientation;
    18.7 -	int invert;
    18.8 -	char hiresFix; // using hires mode without defining hires resource
    18.9 +#ifdef _WIN32_WCE
   18.10 +	int invert; /* do to remove, used by GAPI driver! */
   18.11 +	char hiresFix; /* using hires mode without defining hires resource */
   18.12 +	int supportRotation; /* for Pocket PC devices */
   18.13 +	DWORD origRotation; /* for Pocket PC devices */
   18.14 +#endif
   18.15  };
   18.16  /* Old variable names */
   18.17  #define screen_bmp		(this->hidden->screen_bmp)
    19.1 --- a/test/testalpha.c	Sat Mar 04 05:13:03 2006 +0000
    19.2 +++ b/test/testalpha.c	Sat Mar 04 08:24:35 2006 +0000
    19.3 @@ -45,7 +45,7 @@
    19.4          {
    19.5  		for ( i=0; i<screen->h; ++i ) {
    19.6  			gradient=((i*255)/screen->h);
    19.7 -                        color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
    19.8 +                        color = (Uint16)SDL_MapRGB(screen->format, gradient, gradient, gradient);
    19.9                          buffer16=(Uint16*)buffer;
   19.10                          for (k=0; k<screen->w; k++)
   19.11                          {
   19.12 @@ -340,8 +340,14 @@
   19.13  	}
   19.14  
   19.15  	/* Alpha blending doesn't work well at 8-bit color */
   19.16 +#ifdef _WIN32_WCE
   19.17 +	/* Pocket PC */
   19.18 +	w = 240;
   19.19 +	h = 320;
   19.20 +#else
   19.21  	w = 640;
   19.22  	h = 480;
   19.23 +#endif
   19.24  	info = SDL_GetVideoInfo();
   19.25  	if ( info->vfmt->BitsPerPixel > 8 ) {
   19.26  		video_bpp = info->vfmt->BitsPerPixel;
   19.27 @@ -386,21 +392,12 @@
   19.28  		}
   19.29  	}
   19.30  
   19.31 -	/* Set 640x480 video mode */
   19.32 -#ifndef _WIN32_WCE
   19.33 +	/* Set video mode */
   19.34  	if ( (screen=SDL_SetVideoMode(w,h,video_bpp,videoflags)) == NULL ) {
   19.35 -		fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
   19.36 -						video_bpp, SDL_GetError());
   19.37 +		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
   19.38 +						w, h, video_bpp, SDL_GetError());
   19.39  		quit(2);
   19.40  	}
   19.41 -#else
   19.42 -	/* Pocket PC */
   19.43 -	if ( (screen=SDL_SetVideoMode(240,320,video_bpp,SDL_FULLSCREEN)) == NULL ) {
   19.44 -		fprintf(stderr, "Couldn't set 240x320x%d video mode: %s\n",
   19.45 -						video_bpp, SDL_GetError());
   19.46 -		quit(2);
   19.47 -	}
   19.48 -#endif
   19.49  	FillBackground(screen);
   19.50  
   19.51  	/* Create the light */