Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
authorRyan C. Gordon <icculus@icculus.org>
Thu, 19 Jan 2006 08:43:00 +0000
changeset 125186d0d01290ea
parent 1250 a4d515d0fc3a
child 1252 57be1c741b8b
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
updated project files, VS2005 support, VGA mode, more device support, etc,
etc, etc.

Fixes Bugzilla #47 and #28.

--ryan.
README.WinCE
VisualCE.zip
configure.in
src/thread/win32/SDL_systhread.c
src/thread/win32/win_ce_semaphore.c
src/video/Makefile.am
src/video/SDL_surface.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/gapi/.cvsignore
src/video/gapi/Makefile.am
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_sysmouse.c
src/video/windib/SDL_dibevents.c
src/video/windib/SDL_dibvideo.c
src/video/windib/SDL_dibvideo.h
     1.1 --- a/README.WinCE	Thu Jan 19 08:36:41 2006 +0000
     1.2 +++ b/README.WinCE	Thu Jan 19 08:43:00 2006 +0000
     1.3 @@ -1,5 +1,24 @@
     1.4  
     1.5 -Project files for embedded Visual C++ 4.0 can be found in VisualCE.zip
     1.6 +Project files for embedded Visual C++ 3.0, 4.0 and 
     1.7 +Visual Studio 2005 can be found in VisualCE.zip
     1.8 +
     1.9 +SDL supports GAPI and WinDib output for Windows CE.
    1.10 +
    1.11 +GAPI driver supports:
    1.12 +
    1.13 +- all possible WinCE devices (Pocket PC, Smartphones, HPC)
    1.14 +  with different orientations of video memory and resolutions.
    1.15 +- 4, 8 and 16 bpp devices
    1.16 +- special handling of 8bpp on 8bpp devices
    1.17 +- VGA mode, you can even switch between VGA and GAPI in runtime
    1.18 +  (between 240x320 and 480x640 for example). On VGA devices you can
    1.19 +  use either GAPI or VGA.
    1.20 +- Landscape mode and automatic rotation of buttons and stylus coordinates.
    1.21 +  To enable landscape mode make width of video screen bigger than height.
    1.22 +  For example: 
    1.23 +    SDL_SetVideoMode(320,240,16,SDL_FULLSCREEN)
    1.24 +- WM2005
    1.25 +- SDL_ListModes
    1.26  
    1.27  NOTE:
    1.28  There are several SDL features not available in the WinCE port of SDL.
     2.1 Binary file VisualCE.zip has changed
     3.1 --- a/configure.in	Thu Jan 19 08:36:41 2006 +0000
     3.2 +++ b/configure.in	Thu Jan 19 08:43:00 2006 +0000
     3.3 @@ -3140,6 +3140,7 @@
     3.4  src/video/wincommon/Makefile
     3.5  src/video/windib/Makefile
     3.6  src/video/windx5/Makefile
     3.7 +src/video/gapi/Makefile
     3.8  src/video/x11/Makefile
     3.9  src/video/xbios/Makefile
    3.10  src/video/XFree86/Makefile
     4.1 --- a/src/thread/win32/SDL_systhread.c	Thu Jan 19 08:36:41 2006 +0000
     4.2 +++ b/src/thread/win32/SDL_systhread.c	Thu Jan 19 08:43:00 2006 +0000
     4.3 @@ -30,7 +30,10 @@
     4.4  #include <stdio.h>
     4.5  #include <stdlib.h>
     4.6  #include <windows.h>
     4.7 +
     4.8 +#ifndef _WIN32_WCE
     4.9  #include <process.h>
    4.10 +#endif
    4.11  
    4.12  #include "SDL_error.h"
    4.13  #include "SDL_thread.h"
    4.14 @@ -53,9 +56,14 @@
    4.15  	 * have to use _beginthreadex if we want the returned handle
    4.16  	 * to be accessible after the thread exits
    4.17  	 * threads created with _beginthread auto-close the handle
    4.18 +	 * Windows CE still use CreateThread.
    4.19  	 */
    4.20 +#ifdef _WIN32_WCE
    4.21 +	thread->handle = CreateThread(NULL, 0, RunThread, args, 0, &threadid);
    4.22 +#else
    4.23  	thread->handle = (SYS_ThreadHandle) _beginthreadex(NULL, 0, RunThread,
    4.24  			args, 0, &threadid);
    4.25 +#endif
    4.26  	if (thread->handle == NULL) {
    4.27  		SDL_SetError("Not enough resources to create thread");
    4.28  		return(-1);
     5.1 --- a/src/thread/win32/win_ce_semaphore.c	Thu Jan 19 08:36:41 2006 +0000
     5.2 +++ b/src/thread/win32/win_ce_semaphore.c	Thu Jan 19 08:43:00 2006 +0000
     5.3 @@ -201,9 +201,9 @@
     5.4     BOOL ok = TRUE;
     5.5  
     5.6     if (hSynch == NULL) return NULL;
     5.7 -   if (Flags & 4 == 1 && hSynch->hEvent == NULL) ok = FALSE;
     5.8 -   if (Flags & 2 == 1 && hSynch->hMutex == NULL) ok = FALSE;
     5.9 -   if (Flags & 1 == 1 && hSynch->hEvent == NULL) ok = FALSE;
    5.10 +   if ((Flags & 4) == 1 && (hSynch->hEvent == NULL)) ok = FALSE;
    5.11 +   if ((Flags & 2) == 1 && (hSynch->hMutex == NULL)) ok = FALSE;
    5.12 +   if ((Flags & 1) == 1 && (hSynch->hEvent == NULL)) ok = FALSE;
    5.13     if (!ok) 
    5.14     {
    5.15        CloseSynchHandle (hSynch);
     6.1 --- a/src/video/Makefile.am	Thu Jan 19 08:36:41 2006 +0000
     6.2 +++ b/src/video/Makefile.am	Thu Jan 19 08:43:00 2006 +0000
     6.3 @@ -9,7 +9,7 @@
     6.4                 wincommon windib windx5 \
     6.5                 maccommon macdsp macrom riscos quartz \
     6.6                 bwindow ps2gs photon cybergfx epoc picogui \
     6.7 -               ataricommon xbios gem dc qtopia XFree86 wscons \
     6.8 +               ataricommon xbios gem dc qtopia XFree86 wscons gapi \
     6.9                 ipod os2fslib
    6.10  
    6.11  DRIVERS = @VIDEO_DRIVERS@
     7.1 --- a/src/video/SDL_surface.c	Thu Jan 19 08:36:41 2006 +0000
     7.2 +++ b/src/video/SDL_surface.c	Thu Jan 19 08:43:00 2006 +0000
     7.3 @@ -39,6 +39,7 @@
     7.4  #include "SDL_memops.h"
     7.5  #include "SDL_leaks.h"
     7.6  
     7.7 +
     7.8  /* Public routines */
     7.9  /*
    7.10   * Create an empty RGB surface of the appropriate depth
     8.1 --- a/src/video/SDL_sysvideo.h	Thu Jan 19 08:36:41 2006 +0000
     8.2 +++ b/src/video/SDL_sysvideo.h	Thu Jan 19 08:43:00 2006 +0000
     8.3 @@ -365,6 +365,9 @@
     8.4  #ifdef ENABLE_AALIB
     8.5  extern VideoBootStrap AALIB_bootstrap;
     8.6  #endif
     8.7 +#ifdef ENABLE_GAPI
     8.8 +extern VideoBootStrap GAPI_bootstrap;
     8.9 +#endif
    8.10  #ifdef ENABLE_WINDIB
    8.11  extern VideoBootStrap WINDIB_bootstrap;
    8.12  #endif
     9.1 --- a/src/video/SDL_video.c	Thu Jan 19 08:36:41 2006 +0000
     9.2 +++ b/src/video/SDL_video.c	Thu Jan 19 08:43:00 2006 +0000
     9.3 @@ -87,6 +87,9 @@
     9.4  #ifdef ENABLE_AALIB
     9.5  	&AALIB_bootstrap,
     9.6  #endif
     9.7 +#ifdef ENABLE_GAPI
     9.8 +	&GAPI_bootstrap,
     9.9 +#endif
    9.10  #ifdef ENABLE_WINDIB
    9.11  	&WINDIB_bootstrap,
    9.12  #endif
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/gapi/.cvsignore	Thu Jan 19 08:43:00 2006 +0000
    10.3 @@ -0,0 +1,6 @@
    10.4 +Makefile.in
    10.5 +Makefile
    10.6 +.libs
    10.7 +*.o
    10.8 +*.lo
    10.9 +*.la
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/video/gapi/Makefile.am	Thu Jan 19 08:43:00 2006 +0000
    11.3 @@ -0,0 +1,10 @@
    11.4 +
    11.5 +## Makefile.am for SDL using the PocketPC GAPI video driver
    11.6 +
    11.7 +noinst_LTLIBRARIES = libvideo_gapi.la
    11.8 +libvideo_gapi_la_SOURCES = $(GAPI_SRCS)
    11.9 +
   11.10 +# The SDL GAPI driver sources
   11.11 +GAPI_SRCS = 			\
   11.12 +	SDL_gapivideo.c		\
   11.13 +	SDL_gapivideo.h
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/video/gapi/SDL_gapivideo.c	Thu Jan 19 08:43:00 2006 +0000
    12.3 @@ -0,0 +1,1127 @@
    12.4 +/*
    12.5 +    SDL - Simple DirectMedia Layer
    12.6 +    Copyright (C) 1997-2004 Sam Lantinga
    12.7 +
    12.8 +    This library is free software; you can redistribute it and/or
    12.9 +    modify it under the terms of the GNU Library General Public
   12.10 +    License as published by the Free Software Foundation; either
   12.11 +    version 2 of the License, or (at your option) any later version.
   12.12 +
   12.13 +    This library is distributed in the hope that it will be useful,
   12.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 +    Library General Public License for more details.
   12.17 +
   12.18 +    You should have received a copy of the GNU Library General Public
   12.19 +    License along with this library; if not, write to the Free
   12.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.21 +
   12.22 +    Sam Lantinga
   12.23 +    slouken@libsdl.org
   12.24 +*/
   12.25 +
   12.26 +#ifdef SAVE_RCSID
   12.27 +static char rcsid =
   12.28 + "@(#) $Id$";
   12.29 +#endif
   12.30 +
   12.31 +/* Pocket PC GAPI SDL video driver implementation;
   12.32 +Implemented by Dmitry Yakimov - support@activekitten.com
   12.33 +Inspired by http://arisme.free.fr/ports/SDL.php
   12.34 +*/
   12.35 +
   12.36 +// TODO: copy surface on window when lost focus
   12.37 +// TODO: test buttons rotation
   12.38 +// TODO: test on be300 and HPC ( check WinDib fullscreen keys catching )
   12.39 +// TODO: test on smartphones
   12.40 +// TODO: windib on SH3 PPC2000 landscape test
   12.41 +// TODO: optimize 8bpp landscape mode
   12.42 +
   12.43 +#include <stdio.h>
   12.44 +#include <stdlib.h>
   12.45 +#include <string.h>
   12.46 +
   12.47 +#include "SDL.h"
   12.48 +#include "SDL_error.h"
   12.49 +#include "SDL_video.h"
   12.50 +#include "SDL_mouse.h"
   12.51 +#include "SDL_sysvideo.h"
   12.52 +#include "SDL_pixels_c.h"
   12.53 +#include "SDL_events_c.h"
   12.54 +
   12.55 +#include "SDL_syswm_c.h"
   12.56 +#include "SDL_sysmouse_c.h"
   12.57 +#include "SDL_dibevents_c.h" 
   12.58 +
   12.59 +#include "SDL_gapivideo.h"
   12.60 +
   12.61 +#define GAPIVID_DRIVER_NAME "gapi"
   12.62 +
   12.63 +#if defined(DEBUG) || defined (_DEBUG) || defined(NDEBUG)
   12.64 +#define REPORT_VIDEO_INFO 1
   12.65 +#else
   12.66 +#define REPORT_VIDEO_INFO 0
   12.67 +#endif
   12.68 +
   12.69 +// for testing with GapiEmu
   12.70 +#define USE_GAPI_EMU 0
   12.71 +
   12.72 +#if USE_GAPI_EMU && !REPORT_VIDEO_INFO
   12.73 +#pragma message("Warning: Using GapiEmu in release build. I assume you'd like to set USE_GAPI_EMU to zero.")
   12.74 +#endif
   12.75 +
   12.76 +// defined and used in SDL_sysevents.c
   12.77 +extern HINSTANCE aygshell;
   12.78 +extern void SDL_UnregisterApp();
   12.79 +extern int DIB_AddMode(_THIS, int bpp, int w, int h);
   12.80 +
   12.81 +/* Initialization/Query functions */
   12.82 +static int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat);
   12.83 +static SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   12.84 +static SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
   12.85 +static int GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
   12.86 +static void GAPI_VideoQuit(_THIS);
   12.87 +
   12.88 +/* Hardware surface functions */
   12.89 +static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface);
   12.90 +static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface);
   12.91 +static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface);
   12.92 +static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface);
   12.93 +
   12.94 +/* Windows message handling functions, will not be processed */
   12.95 +static void GAPI_RealizePalette(_THIS);
   12.96 +static void GAPI_PaletteChanged(_THIS, HWND window);
   12.97 +static void GAPI_WinPAINT(_THIS, HDC hdc); 
   12.98 +
   12.99 +/* etc. */
  12.100 +static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
  12.101 +
  12.102 +static HMODULE g_hGapiLib = 0;
  12.103 +#define LINK(type,name,import) \
  12.104 +	if( g_hGapiLib ) \
  12.105 +		name = (PFN##type)GetProcAddress( g_hGapiLib, _T(import) ); 
  12.106 +
  12.107 +static char g_bRawBufferAvailable = 0;
  12.108 +
  12.109 +/* GAPI driver bootstrap functions */
  12.110 +
  12.111 +/* hi res definitions */
  12.112 +typedef struct _RawFrameBufferInfo
  12.113 +{
  12.114 +   WORD wFormat;
  12.115 +   WORD wBPP;
  12.116 +   VOID *pFramePointer;
  12.117 +   int  cxStride;
  12.118 +   int  cyStride;
  12.119 +   int  cxPixels;
  12.120 +   int  cyPixels;
  12.121 +} RawFrameBufferInfo; 
  12.122 +
  12.123 +static struct _RawFrameBufferInfo g_RawFrameBufferInfo = {0};
  12.124 +
  12.125 +#define GETRAWFRAMEBUFFER   0x00020001
  12.126 +
  12.127 +#define FORMAT_565 1
  12.128 +#define FORMAT_555 2
  12.129 +#define FORMAT_OTHER 3 
  12.130 +
  12.131 +static int GAPI_Available(void)
  12.132 +{
  12.133 +	// try to use VGA display, even on emulator
  12.134 +	HDC hdc = GetDC(NULL); 
  12.135 +	int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *)&g_RawFrameBufferInfo);
  12.136 +	ReleaseDC(NULL, hdc);
  12.137 +	g_bRawBufferAvailable = result > 0;
  12.138 +
  12.139 +#if USE_GAPI_EMU
  12.140 +	g_hGapiLib = LoadLibrary(_T("GAPI_Emu.dll"));
  12.141 +	if( !g_hGapiLib )
  12.142 +	{
  12.143 +		SDL_SetError("Gapi Emu not found!");
  12.144 +	}
  12.145 +	return g_hGapiLib != 0;
  12.146 +#endif
  12.147 +
  12.148 +	// try to find gx.dll
  12.149 +	g_hGapiLib = LoadLibrary(_T("\\Windows\\gx.dll"));
  12.150 +	if( !g_hGapiLib )
  12.151 +	{
  12.152 +		g_hGapiLib = LoadLibrary(_T("gx.dll"));
  12.153 +		if( !g_hGapiLib ) return g_bRawBufferAvailable;
  12.154 +	}
  12.155 +
  12.156 +	return(1);
  12.157 +}
  12.158 +
  12.159 +static int cmpmodes(const void *va, const void *vb)
  12.160 +{
  12.161 +    SDL_Rect *a = *(SDL_Rect **)va;
  12.162 +    SDL_Rect *b = *(SDL_Rect **)vb;
  12.163 +    if ( a->w == b->w )
  12.164 +        return b->h - a->h;
  12.165 +    else
  12.166 +        return b->w - a->w;
  12.167 +}
  12.168 +
  12.169 +static int GAPI_AddMode(_THIS, int bpp, int w, int h)
  12.170 +{
  12.171 +	SDL_Rect *mode;
  12.172 +	int i, index;
  12.173 +	int next_mode;
  12.174 +
  12.175 +	/* Check to see if we already have this mode */
  12.176 +	if ( bpp < 8 ) {  /* Not supported */
  12.177 +		return(0);
  12.178 +	}
  12.179 +	index = ((bpp+7)/8)-1;
  12.180 +	for ( i=0; i<gapi->SDL_nummodes[index]; ++i ) {
  12.181 +		mode = gapi->SDL_modelist[index][i];
  12.182 +		if ( (mode->w == w) && (mode->h == h) ) {
  12.183 +			return(0);
  12.184 +		}
  12.185 +	}
  12.186 +
  12.187 +	/* Set up the new video mode rectangle */
  12.188 +	mode = (SDL_Rect *)malloc(sizeof *mode);
  12.189 +	if ( mode == NULL ) {
  12.190 +		SDL_OutOfMemory();
  12.191 +		return(-1);
  12.192 +	}
  12.193 +	mode->x = 0;
  12.194 +	mode->y = 0;
  12.195 +	mode->w = w;
  12.196 +	mode->h = h;
  12.197 +
  12.198 +	/* Allocate the new list of modes, and fill in the new mode */
  12.199 +	next_mode = gapi->SDL_nummodes[index];
  12.200 +	gapi->SDL_modelist[index] = (SDL_Rect **)
  12.201 +	       realloc(gapi->SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
  12.202 +	if ( gapi->SDL_modelist[index] == NULL ) {
  12.203 +		SDL_OutOfMemory();
  12.204 +		gapi->SDL_nummodes[index] = 0;
  12.205 +		free(mode);
  12.206 +		return(-1);
  12.207 +	}
  12.208 +	gapi->SDL_modelist[index][next_mode] = mode;
  12.209 +	gapi->SDL_modelist[index][next_mode+1] = NULL;
  12.210 +	gapi->SDL_nummodes[index]++;
  12.211 +
  12.212 +	return(0);
  12.213 +}
  12.214 +
  12.215 +static void GAPI_DeleteDevice(SDL_VideoDevice *device)
  12.216 +{
  12.217 +	if( g_hGapiLib )
  12.218 +	{
  12.219 +		FreeLibrary(g_hGapiLib);
  12.220 +		g_hGapiLib = 0;
  12.221 +	}
  12.222 +	free(device->hidden);
  12.223 +	free(device);
  12.224 +}
  12.225 +
  12.226 +static SDL_VideoDevice *GAPI_CreateDevice(int devindex)
  12.227 +{
  12.228 +	SDL_VideoDevice *device;
  12.229 +
  12.230 +	if( !g_hGapiLib && !g_bRawBufferAvailable)
  12.231 +	{
  12.232 +		if( !GAPI_Available() )
  12.233 +		{
  12.234 +			SDL_SetError("GAPI dll is not found and VGA mode is not available!");
  12.235 +			return 0;
  12.236 +		}
  12.237 +	}
  12.238 +
  12.239 +	/* Initialize all variables that we clean on shutdown */
  12.240 +	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
  12.241 +	if ( device ) {
  12.242 +		memset(device, 0, (sizeof *device));
  12.243 +		device->hidden = (struct SDL_PrivateVideoData *)
  12.244 +				malloc((sizeof *device->hidden));
  12.245 +	}
  12.246 +	if ( (device == NULL) || (device->hidden == NULL) ) {
  12.247 +		SDL_OutOfMemory();
  12.248 +		if ( device ) {
  12.249 +			free(device);
  12.250 +		}
  12.251 +		return(0);
  12.252 +	}
  12.253 +	memset(device->hidden, 0, (sizeof *device->hidden));
  12.254 +
  12.255 +	/* Set the function pointers */
  12.256 +	device->VideoInit = GAPI_VideoInit;
  12.257 +	device->ListModes = GAPI_ListModes;
  12.258 +	device->SetVideoMode = GAPI_SetVideoMode;
  12.259 +	device->UpdateMouse = WIN_UpdateMouse; 
  12.260 +	device->CreateYUVOverlay = NULL;
  12.261 +	device->SetColors = GAPI_SetColors;
  12.262 +	device->UpdateRects = GAPI_UpdateRects;
  12.263 +	device->VideoQuit = GAPI_VideoQuit;
  12.264 +	device->AllocHWSurface = GAPI_AllocHWSurface;
  12.265 +	device->CheckHWBlit = NULL;
  12.266 +	device->FillHWRect = NULL;
  12.267 +	device->SetHWColorKey = NULL;
  12.268 +	device->SetHWAlpha = NULL;
  12.269 +	device->LockHWSurface = GAPI_LockHWSurface;
  12.270 +	device->UnlockHWSurface = GAPI_UnlockHWSurface;
  12.271 +	device->FlipHWSurface = NULL;
  12.272 +	device->FreeHWSurface = GAPI_FreeHWSurface;
  12.273 +	device->SetCaption = WIN_SetWMCaption;
  12.274 +	device->SetIcon = WIN_SetWMIcon;
  12.275 +	device->IconifyWindow = WIN_IconifyWindow;
  12.276 +	device->GrabInput = WIN_GrabInput;
  12.277 +	device->GetWMInfo = WIN_GetWMInfo;
  12.278 +	device->FreeWMCursor = WIN_FreeWMCursor;
  12.279 +	device->CreateWMCursor = WIN_CreateWMCursor; 
  12.280 +	device->ShowWMCursor = WIN_ShowWMCursor;	
  12.281 +	device->WarpWMCursor = WIN_WarpWMCursor; 
  12.282 +    device->CheckMouseMode = WIN_CheckMouseMode;
  12.283 +	device->InitOSKeymap = DIB_InitOSKeymap;
  12.284 +	device->PumpEvents = DIB_PumpEvents;
  12.285 +
  12.286 +	/* Set up the windows message handling functions */
  12.287 +	WIN_RealizePalette = GAPI_RealizePalette;
  12.288 +	WIN_PaletteChanged = GAPI_PaletteChanged;
  12.289 +	WIN_WinPAINT = GAPI_WinPAINT;
  12.290 +	HandleMessage = DIB_HandleMessage; 
  12.291 +
  12.292 +	device->free = GAPI_DeleteDevice;
  12.293 +
  12.294 +	/* Load gapi library */
  12.295 +#define gx device->hidden->gxFunc
  12.296 +
  12.297 +    LINK( GXOpenDisplay, gx.GXOpenDisplay,         "?GXOpenDisplay@@YAHPAUHWND__@@K@Z" )
  12.298 +    LINK( GXCloseDisplay, gx.GXCloseDisplay,        "?GXCloseDisplay@@YAHXZ" )
  12.299 +    LINK( GXBeginDraw, gx.GXBeginDraw,           "?GXBeginDraw@@YAPAXXZ" )
  12.300 +    LINK( GXEndDraw, gx.GXEndDraw,             "?GXEndDraw@@YAHXZ" )
  12.301 +    LINK( GXOpenInput, gx.GXOpenInput,           "?GXOpenInput@@YAHXZ" )
  12.302 +    LINK( GXCloseInput, gx.GXCloseInput,          "?GXCloseInput@@YAHXZ" )
  12.303 +    LINK( GXGetDisplayProperties, gx.GXGetDisplayProperties,"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ" )
  12.304 +    LINK( GXGetDefaultKeys, gx.GXGetDefaultKeys,      "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z" )
  12.305 +    LINK( GXSuspend, gx.GXSuspend,             "?GXSuspend@@YAHXZ" )
  12.306 +    LINK( GXResume, gx.GXResume,              "?GXResume@@YAHXZ" )
  12.307 +    LINK( GXSetViewport, gx.GXSetViewport,         "?GXSetViewport@@YAHKKKK@Z" )
  12.308 +    LINK( GXIsDisplayDRAMBuffer, gx.GXIsDisplayDRAMBuffer, "?GXIsDisplayDRAMBuffer@@YAHXZ" )
  12.309 +
  12.310 +	/* wrong gapi.dll */
  12.311 +	if( !gx.GXOpenDisplay )
  12.312 +	{
  12.313 +		if( g_hGapiLib ) 
  12.314 +		{
  12.315 +			FreeLibrary(g_hGapiLib);
  12.316 +			g_hGapiLib = 0;
  12.317 +		}
  12.318 +	}
  12.319 +	
  12.320 +	if( !gx.GXOpenDisplay && !g_bRawBufferAvailable)
  12.321 +	{
  12.322 +		SDL_SetError("Error: damaged or unknown gapi.dll!\n");
  12.323 +		GAPI_DeleteDevice(device);
  12.324 +		return 0;
  12.325 +	}
  12.326 +
  12.327 +	return device;
  12.328 +}
  12.329 +
  12.330 +VideoBootStrap GAPI_bootstrap = {
  12.331 +	GAPIVID_DRIVER_NAME, "WinCE GAPI video driver",
  12.332 +	GAPI_Available, GAPI_CreateDevice
  12.333 +};
  12.334 +
  12.335 +static void FillStructs(_THIS, BOOL useVga)
  12.336 +{
  12.337 +#ifdef _ARM_
  12.338 +	WCHAR oemstr[100];
  12.339 +#endif
  12.340 +	/* fill a device properties */
  12.341 +
  12.342 +	if( !useVga )
  12.343 +	{
  12.344 +		this->hidden->gxProperties = this->hidden->gxFunc.GXGetDisplayProperties();
  12.345 +		this->hidden->needUpdate = 1;
  12.346 +		this->hidden->hiresFix = 0;
  12.347 +		this->hidden->useVga = 0;
  12.348 +#ifdef _ARM_
  12.349 +		/* check some devices and extract addition info */
  12.350 +		SystemParametersInfo( SPI_GETOEMINFO, sizeof( oemstr ), oemstr, 0 );
  12.351 +
  12.352 +		// buggy iPaq38xx
  12.353 +		if ((oemstr[12] == 'H') && (oemstr[13] == '3') && (oemstr[14] == '8') && (this->hidden->gxProperties.cbxPitch > 0)) 
  12.354 +		{
  12.355 +			this->hidden->videoMem = (PIXEL*)0xac0755a0;
  12.356 +			this->hidden->gxProperties.cbxPitch = -640;
  12.357 +			this->hidden->gxProperties.cbyPitch = 2;
  12.358 +			this->hidden->needUpdate = 0;
  12.359 +		}
  12.360 +#endif
  12.361 +	} else
  12.362 +	{
  12.363 +	    this->hidden->needUpdate = 0;		
  12.364 +		this->hidden->hiresFix = 0;
  12.365 +		this->hidden->gxProperties.cBPP = g_RawFrameBufferInfo.wBPP;
  12.366 +		this->hidden->gxProperties.cbxPitch = g_RawFrameBufferInfo.cxStride;
  12.367 +		this->hidden->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride;
  12.368 +		this->hidden->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels;
  12.369 +		this->hidden->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels;
  12.370 +		this->hidden->videoMem = g_RawFrameBufferInfo.pFramePointer;
  12.371 +		this->hidden->useVga = 1;
  12.372 +
  12.373 +		switch( g_RawFrameBufferInfo.wFormat )
  12.374 +		{
  12.375 +		case FORMAT_565:
  12.376 +			this->hidden->gxProperties.ffFormat = kfDirect565;
  12.377 +			break;
  12.378 +		case FORMAT_555:
  12.379 +			this->hidden->gxProperties.ffFormat = kfDirect555;
  12.380 +			break;
  12.381 +		default:
  12.382 +			/* unknown pixel format, try define by BPP! */
  12.383 +			switch( g_RawFrameBufferInfo.wBPP )
  12.384 +			{
  12.385 +			case 4:
  12.386 +			case 8:
  12.387 +				this->hidden->gxProperties.ffFormat = kfDirect;
  12.388 +			case 16:
  12.389 +				this->hidden->gxProperties.ffFormat = kfDirect565;
  12.390 +			default:
  12.391 +				this->hidden->gxProperties.ffFormat = kfDirect;
  12.392 +				break;
  12.393 +			}
  12.394 +		}
  12.395 +	}
  12.396 +
  12.397 +	if( this->hidden->gxProperties.cBPP != 16 )
  12.398 +	{
  12.399 +		this->hidden->gapiOrientation = SDL_ORIENTATION_UP;
  12.400 +	} else
  12.401 +	if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch > 0 ))
  12.402 +	{
  12.403 +		this->hidden->gapiOrientation = SDL_ORIENTATION_UP;
  12.404 +	} else
  12.405 +	if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch < 0 ))
  12.406 +	{
  12.407 +		this->hidden->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660
  12.408 +	} else
  12.409 +	if( (this->hidden->gxProperties.cbxPitch < 0) && (this->hidden->gxProperties.cbyPitch > 0 ))
  12.410 +	{
  12.411 +		this->hidden->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800
  12.412 +	}
  12.413 +}
  12.414 +
  12.415 +static void GAPI_CreatePalette(int ncolors, SDL_Color *colors)
  12.416 +{
  12.417 +  // Setup a custom color palette
  12.418 +   BYTE buffer[ sizeof(LOGPALETTE) + 255 * sizeof(PALETTEENTRY) ];
  12.419 +   int i;
  12.420 +   LOGPALETTE*   pLogical = (LOGPALETTE*)buffer;
  12.421 +   PALETTEENTRY* entries  = pLogical->palPalEntry;
  12.422 +   HPALETTE hPalette;
  12.423 +   HDC hdc;
  12.424 +
  12.425 +   for (i = 0; i < ncolors; ++i)
  12.426 +   {
  12.427 +      // Find intensity by replicating the bit patterns over a byte
  12.428 +      entries[i].peRed   = colors[i].r;
  12.429 +      entries[i].peGreen = colors[i].g;
  12.430 +      entries[i].peBlue  = colors[i].b;
  12.431 +      entries[i].peFlags = 0;
  12.432 +   }
  12.433 +
  12.434 +   // Create the GDI palette object
  12.435 +   pLogical->palVersion    = 0x0300;
  12.436 +   pLogical->palNumEntries = ncolors;
  12.437 +
  12.438 +   hPalette = CreatePalette( pLogical );
  12.439 +   ASSERT(hPalette);
  12.440 +	
  12.441 +
  12.442 +   // Realize the palette
  12.443 +   hdc = GetDC(0);
  12.444 +
  12.445 +   SelectPalette( hdc, hPalette, FALSE );
  12.446 +   RealizePalette( hdc );
  12.447 +
  12.448 +   ReleaseDC( 0, hdc );
  12.449 +   DeleteObject( hPalette );
  12.450 +}
  12.451 +
  12.452 +int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat)
  12.453 +{
  12.454 +	int i,bpp;
  12.455 +
  12.456 +	/* Create the window */
  12.457 +	if ( DIB_CreateWindow(this) < 0 ) {
  12.458 +		return(-1);
  12.459 +	}
  12.460 +
  12.461 +	if( g_hGapiLib )
  12.462 +	{
  12.463 +		FillStructs(this, 0);
  12.464 +
  12.465 +		// SDL does not supports 2/4bpp mode, so use 16 bpp
  12.466 +		bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;
  12.467 +		
  12.468 +		/* set up normal and landscape mode */
  12.469 +		GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth);	
  12.470 +		GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);	
  12.471 +	}
  12.472 +
  12.473 +	/* add hi-res mode */
  12.474 +	if( g_bRawBufferAvailable && 
  12.475 +		!((gapi->gxProperties.cxWidth == (unsigned)g_RawFrameBufferInfo.cxPixels) && (gapi->gxProperties.cyHeight == (unsigned)g_RawFrameBufferInfo.cyPixels)))
  12.476 +	{
  12.477 +		FillStructs(this, 1);
  12.478 +
  12.479 +		// SDL does not supports 2/4bpp mode, so use 16 bpp
  12.480 +		bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;
  12.481 +
  12.482 +		/* set up normal and landscape mode */
  12.483 +		GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth);	
  12.484 +		GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);	
  12.485 +	}
  12.486 +
  12.487 +	/* Sort the mode lists */
  12.488 +	for ( i=0; i<NUM_MODELISTS; ++i ) {
  12.489 +		if ( gapi->SDL_nummodes[i] > 0 ) {
  12.490 +			qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i], sizeof *gapi->SDL_modelist[i], cmpmodes);
  12.491 +		}
  12.492 +	}
  12.493 +
  12.494 +	vformat->BitsPerPixel = this->hidden->gxProperties.cBPP < 8 ? 16 : (unsigned char)this->hidden->gxProperties.cBPP;
  12.495 +
  12.496 +	// Get color mask
  12.497 +	if (this->hidden->gxProperties.ffFormat & kfDirect565) {
  12.498 +		vformat->BitsPerPixel = 16;
  12.499 +		vformat->Rmask = 0x0000f800;
  12.500 +		vformat->Gmask = 0x000007e0;
  12.501 +		vformat->Bmask = 0x0000001f;
  12.502 +		this->hidden->videoMode = GAPI_DIRECT_565;
  12.503 +	}
  12.504 +	else
  12.505 +	if (this->hidden->gxProperties.ffFormat & kfDirect555) {
  12.506 +		vformat->BitsPerPixel = 16;
  12.507 +		vformat->Rmask = 0x00007c00;
  12.508 +		vformat->Gmask = 0x000003e0;
  12.509 +		vformat->Bmask = 0x0000001f;
  12.510 +		this->hidden->videoMode = GAPI_DIRECT_555;
  12.511 +	}
  12.512 +	else
  12.513 +	if ((this->hidden->gxProperties.ffFormat & kfDirect) && (this->hidden->gxProperties.cBPP < 8)) {
  12.514 +		// We'll perform the conversion
  12.515 +		vformat->BitsPerPixel = 16;
  12.516 +		vformat->Rmask = 0x0000f800; // 16 bit 565
  12.517 +		vformat->Gmask = 0x000007e0;
  12.518 +		vformat->Bmask = 0x0000001f;
  12.519 +		if (this->hidden->gxProperties.ffFormat & kfDirectInverted)
  12.520 +			this->hidden->invert = (1 << this->hidden->gxProperties.cBPP) - 1;
  12.521 +		this->hidden->colorscale = this->hidden->gxProperties.cBPP < 8 ? 8 - this->hidden->gxProperties.cBPP : 0;
  12.522 +		this->hidden->videoMode = GAPI_MONO;
  12.523 +	}
  12.524 +	else
  12.525 +	if (this->hidden->gxProperties.ffFormat & kfPalette) {
  12.526 +		this->hidden->videoMode = GAPI_PALETTE;
  12.527 +	} 
  12.528 +
  12.529 +	/* We're done! */
  12.530 +	return(0);
  12.531 +}
  12.532 +
  12.533 +SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  12.534 +{
  12.535 +	return(this->hidden->SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
  12.536 +//  	 return (SDL_Rect **) -1;
  12.537 +}
  12.538 +
  12.539 +SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
  12.540 +				int width, int height, int bpp, Uint32 flags)
  12.541 +{
  12.542 +	SDL_Surface *video; 
  12.543 +	Uint32 Rmask, Gmask, Bmask; 
  12.544 +	DWORD style; 
  12.545 +	SDL_Rect allScreen;
  12.546 +
  12.547 +	if( bpp < 4 )
  12.548 +	{
  12.549 +		SDL_SetError("1 bpp and 2 bpp modes is not implemented yet!");
  12.550 +		return 0;
  12.551 +	}
  12.552 +
  12.553 +	/* Recalculate bitmasks if necessary */
  12.554 +	if (bpp == current->format->BitsPerPixel) {
  12.555 +		video = current;
  12.556 +	}
  12.557 +	else {
  12.558 +		switch(bpp) {
  12.559 +			case 8:
  12.560 +				Rmask = 0;
  12.561 +				Gmask = 0;
  12.562 +				Bmask = 0;
  12.563 +				break;
  12.564 +			case 15:				
  12.565 +			case 16:
  12.566 +				/* Default is 565 unless the display is specifically 555 */
  12.567 +				if (this->hidden->gxProperties.ffFormat & kfDirect555) {
  12.568 +					Rmask = 0x00007c00;
  12.569 +					Gmask = 0x000003e0;
  12.570 +					Bmask = 0x0000001f;
  12.571 +				}
  12.572 +				else {
  12.573 +					Rmask = 0x0000f800;
  12.574 +					Gmask = 0x000007e0;
  12.575 +					Bmask = 0x0000001f;
  12.576 +				}
  12.577 +				break;
  12.578 +			case 24:
  12.579 +			case 32:
  12.580 +				Rmask = 0x00ff0000;
  12.581 +				Gmask = 0x0000ff00;
  12.582 +				Bmask = 0x000000ff;
  12.583 +				break;
  12.584 +			default:
  12.585 +				SDL_SetError("Unsupported Bits Per Pixel format requested");
  12.586 +				return NULL;
  12.587 +		}
  12.588 +		video = SDL_CreateRGBSurface(SDL_SWSURFACE,
  12.589 +					0, 0, bpp, Rmask, Gmask, Bmask, 0);
  12.590 +		if ( video == NULL ) {
  12.591 +			SDL_OutOfMemory();
  12.592 +			return(NULL);
  12.593 +		}
  12.594 +	}
  12.595 +
  12.596 +	gapi->userOrientation = SDL_ORIENTATION_UP;
  12.597 +	video->flags = SDL_FULLSCREEN;	/* Clear flags, GAPI supports fullscreen only */
  12.598 +
  12.599 +	/* GAPI or VGA? */
  12.600 +	if( g_hGapiLib )
  12.601 +	{
  12.602 +		FillStructs(this, 0);
  12.603 +		if( (((unsigned)width != gapi->gxProperties.cxWidth) || ((unsigned)height != gapi->gxProperties.cyHeight))
  12.604 +			&& (((unsigned)width != gapi->gxProperties.cyHeight) || ((unsigned)height != gapi->gxProperties.cxWidth)))
  12.605 +			FillStructs(this, 1); // gapi is found but we use VGA resolution			
  12.606 +	} else
  12.607 +		FillStructs(this, 1);
  12.608 +
  12.609 +	if ( !this->hidden->needUpdate && !this->hidden->videoMem) {
  12.610 +		SDL_SetError("Couldn't get address of video memory, may be unsupported device or bug");
  12.611 +		return(NULL);
  12.612 +	}
  12.613 +
  12.614 +	/* detect landscape mode */
  12.615 +	if( (width > height) && (GetSystemMetrics(SM_CXSCREEN) < GetSystemMetrics(SM_CYSCREEN))) 
  12.616 +		gapi->userOrientation = SDL_ORIENTATION_RIGHT;
  12.617 +
  12.618 +	/* shall we apply hires fix? for example when we do not use hires resource */
  12.619 +	gapi->hiresFix = 0;
  12.620 +	if( gapi->userOrientation == SDL_ORIENTATION_RIGHT )
  12.621 +	{
  12.622 +		if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height > GetSystemMetrics(SM_CXSCREEN)))
  12.623 +			gapi->hiresFix = 1;
  12.624 +	} else
  12.625 +		if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height > GetSystemMetrics(SM_CYSCREEN)))
  12.626 +			gapi->hiresFix = 1;
  12.627 +
  12.628 +	switch( gapi->userOrientation )
  12.629 +	{
  12.630 +	case SDL_ORIENTATION_UP:
  12.631 +		gapi->startOffset = 0;
  12.632 +		gapi->dstLineStep = gapi->gxProperties.cbyPitch;
  12.633 +		gapi->dstPixelStep = gapi->gxProperties.cbxPitch;
  12.634 +		break;
  12.635 +	case SDL_ORIENTATION_RIGHT:
  12.636 +		switch( gapi->gapiOrientation )
  12.637 +		{
  12.638 +		case SDL_ORIENTATION_UP:
  12.639 +		case SDL_ORIENTATION_RIGHT:
  12.640 +		case SDL_ORIENTATION_LEFT:
  12.641 +			if( (this->hidden->videoMode == GAPI_MONO) )
  12.642 +				gapi->startOffset = -gapi->gxProperties.cbxPitch + 1; // monochrome mode
  12.643 +			else
  12.644 +				gapi->startOffset = gapi->gxProperties.cbyPitch * (gapi->gxProperties.cyHeight - 1);
  12.645 +				
  12.646 +			gapi->dstLineStep = gapi->gxProperties.cbxPitch;
  12.647 +			gapi->dstPixelStep = -gapi->gxProperties.cbyPitch;
  12.648 +			break;
  12.649 +		}
  12.650 +	}
  12.651 +
  12.652 +	video->w = this->hidden->w = width;
  12.653 +	video->h = this->hidden->h = height;
  12.654 +	video->pitch = SDL_CalculatePitch(video); 
  12.655 +
  12.656 +	/* Small fix for WinCE/Win32 - when activating window
  12.657 +	   SDL_VideoSurface is equal to zero, so activating code
  12.658 +	   is not called properly for fullscreen windows because
  12.659 +	   macros WINDIB_FULLSCREEN uses SDL_VideoSurface
  12.660 +	*/
  12.661 +	SDL_VideoSurface = video;
  12.662 +
  12.663 +	/* GAPI is always fullscreen, title bar is useless */
  12.664 +	style = 0;
  12.665 +
  12.666 +	if (!SDL_windowid)
  12.667 +		SetWindowLong(SDL_Window, GWL_STYLE, style);
  12.668 + 
  12.669 +	/* Allocate bitmap */
  12.670 +	if(gapiBuffer) 
  12.671 +	{
  12.672 +		free(gapiBuffer);
  12.673 +		gapiBuffer = NULL;
  12.674 +	}
  12.675 +	gapiBuffer = malloc(video->h * video->pitch);
  12.676 +	video->pixels = gapiBuffer; 
  12.677 +
  12.678 +	if ( ! this->hidden->buffer ) {
  12.679 +		SDL_SetError("Couldn't allocate buffer for requested mode");
  12.680 +		return(NULL);
  12.681 +	}
  12.682 +
  12.683 +	memset(gapiBuffer, 255, video->h * video->pitch);
  12.684 +	MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE);
  12.685 +	ShowWindow(SDL_Window, SW_SHOW);
  12.686 +	SetForegroundWindow(SDL_Window);
  12.687 +
  12.688 +#if REPORT_VIDEO_INFO
  12.689 +	printf("Video properties:\n");
  12.690 +	printf("display bpp: %d\n", gapi->gxProperties.cBPP);
  12.691 +	printf("display width: %d\n", gapi->gxProperties.cxWidth);
  12.692 +	printf("display height: %d\n", gapi->gxProperties.cyHeight);
  12.693 +	printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
  12.694 +	printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
  12.695 +	printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
  12.696 +	printf("video memory: 0x%x\n", gapi->videoMem);
  12.697 +	printf("need update: %d\n", gapi->needUpdate);
  12.698 +	printf("hi-res fix: %d\n", gapi->hiresFix);
  12.699 +	printf("VGA is available on the device: %d\n", g_bRawBufferAvailable);
  12.700 +	printf("use VGA resolution: %d\n", gapi->useVga);
  12.701 +	printf("video surface bpp: %d\n", video->format->BitsPerPixel);
  12.702 +	printf("video surface width: %d\n", video->w);
  12.703 +	printf("video surface height: %d\n", video->h);
  12.704 +#endif
  12.705 +
  12.706 +	/* Open GAPI display */
  12.707 +	if( !gapi->useVga )
  12.708 +		if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
  12.709 +		{
  12.710 +			SDL_SetError("Couldn't initialize GAPI");
  12.711 +			return(NULL);
  12.712 +		}
  12.713 + 
  12.714 +	/* Blank screen */
  12.715 +	allScreen.x = allScreen.y = 0;
  12.716 +	allScreen.w = video->w - 1;
  12.717 +	allScreen.h = video->h - 1;
  12.718 +	GAPI_UpdateRects(this, 1, &allScreen);
  12.719 +
  12.720 +	/* We're done */
  12.721 +	return(video);
  12.722 +}
  12.723 +
  12.724 +/* We don't actually allow hardware surfaces other than the main one */
  12.725 +static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface)
  12.726 +{
  12.727 +	return(-1);
  12.728 +}
  12.729 +static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface)
  12.730 +{
  12.731 +	return;
  12.732 +}
  12.733 +
  12.734 +/* We need to wait for vertical retrace on page flipped displays */
  12.735 +static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface)
  12.736 +{
  12.737 +	return(0);
  12.738 +}
  12.739 +
  12.740 +static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface)
  12.741 +{
  12.742 +	return;
  12.743 +}
  12.744 +
  12.745 +static int updateLine8to8(_THIS, unsigned char *srcPointer, unsigned char *destPointer, int width, int height, int lines)
  12.746 +{
  12.747 +	if( gapi->dstPixelStep == 1) /* optimized blitting on most devices */
  12.748 +	{
  12.749 +		memcpy(destPointer, srcPointer, width);
  12.750 +		return 1;
  12.751 +	} else
  12.752 +	{
  12.753 +		// TODO: read 4 pixels, write DWORD
  12.754 +		int step = gapi->dstPixelStep;
  12.755 +		while(width--)
  12.756 +		{
  12.757 +			*destPointer = *srcPointer++;
  12.758 +			destPointer += step;
  12.759 +		}
  12.760 +	}
  12.761 +	return 1;
  12.762 +}
  12.763 +
  12.764 +/* Video memory is very slow so lets optimize as much as possible */
  12.765 +static int updateLine16to16(_THIS, PIXEL *srcPointer, PIXEL *destPointer, int width, int height, int lines)
  12.766 +{
  12.767 +	PIXEL *line1, *line2;
  12.768 +	int step = gapi->dstPixelStep / 2;
  12.769 +
  12.770 +	if( step == 1 ) /* optimized blitting on most devices */
  12.771 +	{
  12.772 +		memcpy(destPointer, srcPointer, width * sizeof(PIXEL));
  12.773 +		return 1;
  12.774 +	}
  12.775 +	else
  12.776 +	{
  12.777 +		if( (gapi->gapiOrientation != SDL_ORIENTATION_UP) &&
  12.778 +			(gapi->userOrientation == SDL_ORIENTATION_UP )) // iPaq 3660/3800 and user orientation up
  12.779 +		{	
  12.780 +			// to prevent data misalignment copy only one line
  12.781 +			if( ((((unsigned)destPointer & 3) != 0) && (gapi->gapiOrientation == SDL_ORIENTATION_LEFT)) 
  12.782 +				|| ((((unsigned)destPointer & 3) == 0) && (gapi->gapiOrientation != SDL_ORIENTATION_LEFT))
  12.783 +				|| (lines == 1) ) 
  12.784 +			{
  12.785 +				while(width--)
  12.786 +				{
  12.787 +					*destPointer = *srcPointer++;
  12.788 +					destPointer += step;
  12.789 +				}
  12.790 +				return 1;
  12.791 +			}
  12.792 +
  12.793 +			/* read two lines at the same time, write DWORD */
  12.794 +			line1 = srcPointer;
  12.795 +			line2 = srcPointer + SDL_VideoSurface->pitch / 2;
  12.796 +
  12.797 +			if( gapi->gapiOrientation == SDL_ORIENTATION_LEFT )
  12.798 +				while(width--) // iPaq 3800
  12.799 +				{
  12.800 +					*(DWORD*)destPointer =(*line2++ << 16) | *line1++;
  12.801 +					destPointer += step;
  12.802 +				}
  12.803 +			else
  12.804 +			{
  12.805 +				destPointer += gapi->gxProperties.cbyPitch / 2;
  12.806 +				while(width--) // iPaq 3660
  12.807 +				{
  12.808 +					*(DWORD*)destPointer =(*line1++ << 16) | *line2++;
  12.809 +					destPointer += step;
  12.810 +				}
  12.811 +			}
  12.812 +			return 2;
  12.813 +		} else
  12.814 +		{
  12.815 +			// iPaq 3800 and user orientation landscape
  12.816 +			if( gapi->gapiOrientation == SDL_ORIENTATION_LEFT )
  12.817 +			{
  12.818 +				int w1;
  12.819 +
  12.820 +				// to prevent data misalignment copy only one pixel
  12.821 +				if( (((unsigned)destPointer & 3) == 0) && (width > 0)) 
  12.822 +				{
  12.823 +					*destPointer-- = *srcPointer++;
  12.824 +					width--;
  12.825 +				}
  12.826 +
  12.827 +				destPointer--;
  12.828 +
  12.829 +				w1 = width / 2;
  12.830 +
  12.831 +				while(w1--)
  12.832 +				{
  12.833 +					DWORD p = *(DWORD*)srcPointer;
  12.834 +					*((DWORD*)destPointer) = (p << 16) | (p >> 16);
  12.835 +					destPointer -= 2;
  12.836 +					srcPointer += 2;
  12.837 +				}
  12.838 +
  12.839 +				if( width & 1 ) // copy the last pixel
  12.840 +				{
  12.841 +					destPointer++;
  12.842 +					*destPointer = *srcPointer;
  12.843 +				}
  12.844 +
  12.845 +				return 1;
  12.846 +			}
  12.847 +
  12.848 +			// modern iPaqs and user orientation landscape
  12.849 +			// read two pixels, write DWORD
  12.850 +
  12.851 +			line1 = srcPointer;
  12.852 +			line2 = srcPointer + SDL_VideoSurface->pitch / 2;
  12.853 +
  12.854 +			if( (((unsigned)destPointer & 3) != 0) || (lines == 1) ) 
  12.855 +			{
  12.856 +				while(width--)
  12.857 +				{
  12.858 +					*destPointer = *srcPointer++;
  12.859 +					destPointer += step;
  12.860 +				}
  12.861 +				return 1;
  12.862 +			}
  12.863 +			
  12.864 +			while(width--)
  12.865 +			{
  12.866 +				*(DWORD*)destPointer =(*line2++ << 16) | *line1++;
  12.867 +				destPointer -= gapi->gxProperties.cbyPitch / 2;
  12.868 +			}
  12.869 +			return 2;
  12.870 +		}
  12.871 +	}
  12.872 +}
  12.873 +
  12.874 +// Color component masks for 565
  12.875 +#define REDMASK (31<<11)
  12.876 +#define GREENMASK (63<<5)
  12.877 +#define BLUEMASK (31)
  12.878 +
  12.879 +
  12.880 +static int updateLine16to4(_THIS, PIXEL *srcPointer, unsigned char *destPointer, int width, int height, int lines, int yNibble, int xNibble)
  12.881 +{
  12.882 +	PIXEL *line1, *line2;
  12.883 +	int step = gapi->dstPixelStep;
  12.884 +
  12.885 +	if( gapi->userOrientation == SDL_ORIENTATION_UP )
  12.886 +	{
  12.887 +		if( yNibble ) // copy bottom half of a line
  12.888 +		{
  12.889 +			while(width--)
  12.890 +			{
  12.891 +				PIXEL c1 = *srcPointer++;
  12.892 +				c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK);			
  12.893 +				*destPointer = (*destPointer & 0x0F) | ((~(c1 >> 3) << 4));
  12.894 +				destPointer += step;
  12.895 +			}
  12.896 +			return 1;
  12.897 +		}
  12.898 +
  12.899 +		// either 1 pixel picture or tail, anyway this is the last line
  12.900 +		if( lines == 1 )
  12.901 +		{
  12.902 +			while(width--)
  12.903 +			{
  12.904 +				PIXEL c1 = *srcPointer++;
  12.905 +				c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK);			
  12.906 +				*destPointer = (*destPointer & 0xF0) | ((~(c1 >> 3) & 0xF));
  12.907 +				destPointer += step;
  12.908 +			}
  12.909 +			return 1;
  12.910 +		}
  12.911 +
  12.912 +		line1 = srcPointer;
  12.913 +		line2 = srcPointer + SDL_VideoSurface->pitch / 2;
  12.914 +
  12.915 +		while(width--)
  12.916 +		{
  12.917 +			PIXEL c1 = *line1++;
  12.918 +			PIXEL c2 = *line2++;
  12.919 +			c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK);
  12.920 +			c2 = ((c2 & REDMASK) >> 11) + ((c2 & GREENMASK) >> 5) + (c2 & BLUEMASK);
  12.921 +			*destPointer = ~((c1 >> 3) + ((c2 >> 3) << 4));
  12.922 +			destPointer += step;
  12.923 +		}
  12.924 +		return 2;
  12.925 +	} else
  12.926 +	{
  12.927 +		int w1;
  12.928 +		w1 = width / 2;
  12.929 +
  12.930 +		if( xNibble )
  12.931 +		{
  12.932 +			// copy one pixel
  12.933 +			PIXEL c1 = *srcPointer++;
  12.934 +			c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK);			
  12.935 +			*destPointer = (*destPointer & 0xF0) | ((~(c1 >> 3) & 0xF));
  12.936 +			destPointer++;
  12.937 +		}
  12.938 +
  12.939 +		while(w1--)
  12.940 +		{
  12.941 +			PIXEL c1 = *srcPointer;
  12.942 +			PIXEL c2 = *(srcPointer + 1);
  12.943 +			c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK);
  12.944 +			c2 = ((c2 & REDMASK) >> 11) + ((c2 & GREENMASK) >> 5) + (c2 & BLUEMASK);
  12.945 +			*destPointer++ = ~((c2 >> 3) + ((c1 >> 3) << 4));
  12.946 +			srcPointer += 2;
  12.947 +		}
  12.948 +
  12.949 +		// copy tail
  12.950 +		if( (width & 1) && !xNibble )
  12.951 +		{
  12.952 +			PIXEL c1 = *srcPointer;
  12.953 +			c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK);			
  12.954 +			*destPointer = (*destPointer & 0x0F) | ((~(c1 >> 3) << 4));
  12.955 +		}
  12.956 +
  12.957 +		return 1;
  12.958 +	}
  12.959 +}
  12.960 +
  12.961 +static void GAPI_UpdateRectsMono(_THIS, int numrects, SDL_Rect *rects)
  12.962 +{
  12.963 +	int i, height;
  12.964 +	int linesProcessed;
  12.965 +	int xNibble, yNibble;
  12.966 +
  12.967 +	for (i=0; i<numrects; i++)
  12.968 +	{
  12.969 +		unsigned char *destPointer;
  12.970 +		unsigned char *srcPointer;
  12.971 +
  12.972 +		if( gapi->userOrientation == SDL_ORIENTATION_UP )
  12.973 +			destPointer = (unsigned char*) gapi->videoMem + gapi->startOffset - rects[i].y * gapi->gxProperties.cBPP / 8 + rects[i].x * gapi->dstPixelStep;
  12.974 +		else
  12.975 +			destPointer = (unsigned char*) gapi->videoMem + gapi->startOffset + rects[i].x * gapi->gxProperties.cBPP / 8 + rects[i].y * gapi->dstLineStep;
  12.976 +
  12.977 +		srcPointer = ((unsigned char*) SDL_VideoSurface->pixels) + rects[i].y * SDL_VideoSurface->pitch + rects[i].x * 2;
  12.978 +		yNibble = rects[i].y & 1; // TODO: only for 4 bpp
  12.979 +		xNibble = rects[i].x & 1;
  12.980 +		height = rects[i].h;
  12.981 +		while (height > 0)
  12.982 +		{
  12.983 +			switch(gapi->gxProperties.cBPP)
  12.984 +			{
  12.985 +			case 2: // TODO
  12.986 +			case 4:
  12.987 +					linesProcessed = updateLine16to4(this, (PIXEL*) srcPointer, destPointer, rects[i].w, rects[i].h, height, yNibble, xNibble);
  12.988 +					yNibble = 0;
  12.989 +			}
  12.990 +			height -= linesProcessed;
  12.991 +			if( gapi->userOrientation == SDL_ORIENTATION_UP )
  12.992 +				destPointer--; // always fill 1 byte
  12.993 +			else destPointer += gapi->dstLineStep;
  12.994 +			srcPointer += SDL_VideoSurface->pitch * linesProcessed; // pitch in bytes
  12.995 +		}
  12.996 +	}
  12.997 +}
  12.998 +
  12.999 +static void GAPI_UpdateRectsColor(_THIS, int numrects, SDL_Rect *rects)
 12.1000 +{
 12.1001 +	int i, height;
 12.1002 +	int bytesPerPixel = (gapi->gxProperties.cBPP + 1) / 8;
 12.1003 +	int linesProcessed;
 12.1004 +	for (i=0; i<numrects; i++) {
 12.1005 +		unsigned char *destPointer = (unsigned char*) gapi->videoMem + gapi->startOffset + rects[i].y * gapi->dstLineStep + rects[i].x * gapi->dstPixelStep;
 12.1006 +		unsigned char *srcPointer = ((unsigned char*) SDL_VideoSurface->pixels) + rects[i].y * SDL_VideoSurface->pitch + rects[i].x * bytesPerPixel;
 12.1007 +		height = rects[i].h;
 12.1008 +
 12.1009 +//		fprintf(stderr, "Starting rect %dx%d, dst=0x%x, w = %d, h = %d\n", rects[i].w, rects[i].h,destPointer,rects[i].w,rects[i].h);
 12.1010 +//		fflush(stderr);
 12.1011 +		linesProcessed = height;
 12.1012 +
 12.1013 +		while (height > 0) {
 12.1014 +			switch(bytesPerPixel)
 12.1015 +			{
 12.1016 +			case 1:
 12.1017 +				linesProcessed = updateLine8to8(this, srcPointer, (unsigned char *) destPointer, rects[i].w, rects[i].h, height);
 12.1018 +				break;
 12.1019 +			case 2:
 12.1020 +#pragma warning(disable: 4133)
 12.1021 +				linesProcessed = updateLine16to16(this, (PIXEL*) srcPointer, destPointer, rects[i].w, rects[i].h, height);
 12.1022 +				break;
 12.1023 +			}
 12.1024 +			height -= linesProcessed;
 12.1025 +			destPointer += gapi->dstLineStep * linesProcessed;
 12.1026 +			srcPointer += SDL_VideoSurface->pitch * linesProcessed; // pitch in bytes
 12.1027 +		}
 12.1028 +//		fprintf(stderr, "End of rect\n");
 12.1029 +//		fflush(stderr);
 12.1030 +	}
 12.1031 +}
 12.1032 +
 12.1033 +
 12.1034 +static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
 12.1035 +{
 12.1036 +	if( gapi->needUpdate )
 12.1037 +		gapi->videoMem = gapi->gxFunc.GXBeginDraw(); 
 12.1038 +
 12.1039 +	if( gapi->gxProperties.cBPP < 8 )
 12.1040 +		GAPI_UpdateRectsMono(this, numrects, rects);
 12.1041 +	else
 12.1042 +		GAPI_UpdateRectsColor(this, numrects, rects);
 12.1043 +
 12.1044 +	if( gapi->needUpdate )
 12.1045 +		gapi->gxFunc.GXEndDraw();
 12.1046 +}
 12.1047 +
 12.1048 +static void FlushMessageQueue()
 12.1049 +{
 12.1050 +	MSG  msg;
 12.1051 +	while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) {
 12.1052 +		if ( msg.message == WM_QUIT ) break;
 12.1053 +		TranslateMessage( &msg );
 12.1054 +		DispatchMessage( &msg );
 12.1055 +	}
 12.1056 +}
 12.1057 +
 12.1058 +
 12.1059 +/* Note:  If we are terminated, this could be called in the middle of
 12.1060 +   another SDL video routine -- notably UpdateRects.
 12.1061 +*/
 12.1062 +void GAPI_VideoQuit(_THIS)
 12.1063 +{
 12.1064 +	int i, j;
 12.1065 +	/* Destroy the window and everything associated with it */
 12.1066 +	if ( SDL_Window ) 
 12.1067 +	{
 12.1068 +	    if ((g_hGapiLib != 0) && this && this->hidden && this->hidden->gxFunc.GXCloseDisplay && !this->hidden->useVga)
 12.1069 +			this->hidden->gxFunc.GXCloseDisplay(); 
 12.1070 +
 12.1071 +		if (this->screen->pixels != NULL)
 12.1072 +		{
 12.1073 +			free(this->screen->pixels);
 12.1074 +			this->screen->pixels = NULL;
 12.1075 +		}
 12.1076 +		if ( screen_icn ) {
 12.1077 +			DestroyIcon(screen_icn);
 12.1078 +			screen_icn = NULL;
 12.1079 +		}
 12.1080 +
 12.1081 +		DIB_DestroyWindow(this);
 12.1082 +		SDL_UnregisterApp();
 12.1083 +		FlushMessageQueue();
 12.1084 +
 12.1085 +		SDL_Window = NULL;
 12.1086 +#if defined(_WIN32_WCE)
 12.1087 +
 12.1088 +// Unload wince aygshell library to prevent leak
 12.1089 +		if( aygshell ) 
 12.1090 +		{
 12.1091 +			FreeLibrary(aygshell);
 12.1092 +			aygshell = NULL;
 12.1093 +		}
 12.1094 +#endif
 12.1095 +
 12.1096 +	/* Free video mode lists */
 12.1097 +	for ( i=0; i<NUM_MODELISTS; ++i ) {
 12.1098 +		if ( gapi->SDL_modelist[i] != NULL ) {
 12.1099 +			for ( j=0; gapi->SDL_modelist[i][j]; ++j )
 12.1100 +				free(gapi->SDL_modelist[i][j]);
 12.1101 +			free(gapi->SDL_modelist[i]);
 12.1102 +			gapi->SDL_modelist[i] = NULL;
 12.1103 +		}
 12.1104 +	}
 12.1105 +
 12.1106 +	}
 12.1107 +
 12.1108 +}
 12.1109 +
 12.1110 +static void GAPI_RealizePalette(_THIS)
 12.1111 +{
 12.1112 +	OutputDebugString(TEXT("GAPI_RealizePalette NOT IMPLEMENTED !\r\n"));
 12.1113 +}
 12.1114 +
 12.1115 +static void GAPI_PaletteChanged(_THIS, HWND window)
 12.1116 +{
 12.1117 +	OutputDebugString(TEXT("GAPI_PaletteChanged NOT IMPLEMENTED !\r\n"));
 12.1118 +}
 12.1119 +
 12.1120 +/* Exported for the windows message loop only */
 12.1121 +static void GAPI_WinPAINT(_THIS, HDC hdc)
 12.1122 +{
 12.1123 +	OutputDebugString(TEXT("GAPI_WinPAINT NOT IMPLEMENTED !\r\n"));
 12.1124 +}
 12.1125 +
 12.1126 +int GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 
 12.1127 +{
 12.1128 +	GAPI_CreatePalette(ncolors, colors);
 12.1129 +	return 1;
 12.1130 +}
 12.1131 \ No newline at end of file
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/video/gapi/SDL_gapivideo.h	Thu Jan 19 08:43:00 2006 +0000
    13.3 @@ -0,0 +1,164 @@
    13.4 +/*
    13.5 +    SDL - Simple DirectMedia Layer
    13.6 +    Copyright (C) 1997-2004 Sam Lantinga
    13.7 +
    13.8 +    This library is free software; you can redistribute it and/or
    13.9 +    modify it under the terms of the GNU Library General Public
   13.10 +    License as published by the Free Software Foundation; either
   13.11 +    version 2 of the License, or (at your option) any later version.
   13.12 +
   13.13 +    This library is distributed in the hope that it will be useful,
   13.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 +    Library General Public License for more details.
   13.17 +
   13.18 +    You should have received a copy of the GNU Library General Public
   13.19 +    License along with this library; if not, write to the Free
   13.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.21 +
   13.22 +    Sam Lantinga
   13.23 +    slouken@libsdl.org
   13.24 +*/
   13.25 +
   13.26 +#ifdef SAVE_RCSID
   13.27 +static char rcsid =
   13.28 + "@(#) $Id$";
   13.29 +#endif
   13.30 +
   13.31 +#ifndef _SDL_gapivideo_h
   13.32 +#define _SDL_gapivideo_h
   13.33 +
   13.34 +#include "SDL_mouse.h"
   13.35 +#include "SDL_sysvideo.h"
   13.36 +#include "SDL_mutex.h"
   13.37 +
   13.38 +/* From gx.h, since it's not really C compliant */
   13.39 +
   13.40 +struct GXDisplayProperties {
   13.41 +    DWORD cxWidth;
   13.42 +    DWORD cyHeight;         // notice lack of 'th' in the word height.
   13.43 +    long cbxPitch;          // number of bytes to move right one x pixel - can be negative.
   13.44 +    long cbyPitch;          // number of bytes to move down one y pixel - can be negative.
   13.45 +    long cBPP;              // # of bits in each pixel
   13.46 +    DWORD ffFormat;         // format flags.
   13.47 +};
   13.48 +
   13.49 +struct GXKeyList {
   13.50 +    short vkUp;             // key for up
   13.51 +    POINT ptUp;             // x,y position of key/button.  Not on screen but in screen coordinates.
   13.52 +    short vkDown;
   13.53 +    POINT ptDown;
   13.54 +    short vkLeft;
   13.55 +    POINT ptLeft;
   13.56 +    short vkRight;
   13.57 +    POINT ptRight;
   13.58 +    short vkA;
   13.59 +    POINT ptA;
   13.60 +    short vkB;
   13.61 +    POINT ptB;
   13.62 +    short vkC;
   13.63 +    POINT ptC;
   13.64 +    short vkStart;
   13.65 +    POINT ptStart;
   13.66 +};
   13.67 +
   13.68 +typedef int   (*PFNGXOpenDisplay)(HWND hWnd, DWORD dwFlags);
   13.69 +typedef int   (*PFNGXCloseDisplay)();
   13.70 +typedef void* (*PFNGXBeginDraw)();
   13.71 +typedef int   (*PFNGXEndDraw)();
   13.72 +typedef int   (*PFNGXOpenInput)();
   13.73 +typedef int   (*PFNGXCloseInput)();
   13.74 +typedef struct GXDisplayProperties (*PFNGXGetDisplayProperties)();
   13.75 +typedef struct GXKeyList (*PFNGXGetDefaultKeys)(int iOptions);
   13.76 +typedef int   (*PFNGXSuspend)();
   13.77 +typedef int   (*PFNGXResume)();
   13.78 +typedef int   (*PFNGXSetViewport)( DWORD dwTop, DWORD dwHeight, DWORD dwReserved1, DWORD dwReserved2 );
   13.79 +typedef BOOL  (*PFNGXIsDisplayDRAMBuffer)();
   13.80 +
   13.81 +struct GapiFunc
   13.82 +{
   13.83 +    PFNGXOpenDisplay          GXOpenDisplay;
   13.84 +    PFNGXCloseDisplay         GXCloseDisplay;
   13.85 +    PFNGXBeginDraw            GXBeginDraw;
   13.86 +    PFNGXEndDraw              GXEndDraw;
   13.87 +    PFNGXOpenInput            GXOpenInput;
   13.88 +    PFNGXCloseInput           GXCloseInput;
   13.89 +    PFNGXGetDisplayProperties GXGetDisplayProperties;
   13.90 +    PFNGXGetDefaultKeys       GXGetDefaultKeys;
   13.91 +    PFNGXSuspend              GXSuspend;
   13.92 +    PFNGXResume               GXResume;
   13.93 +    PFNGXSetViewport          GXSetViewport;
   13.94 +    PFNGXIsDisplayDRAMBuffer  GXIsDisplayDRAMBuffer;
   13.95 +};
   13.96 +
   13.97 +#define kfLandscape	0x8			// Screen is rotated 270 degrees
   13.98 +#define kfPalette	0x10		// Pixel values are indexes into a palette
   13.99 +#define kfDirect	0x20		// Pixel values contain actual level information
  13.100 +#define kfDirect555	0x40		// 5 bits each for red, green and blue values in a pixel.
  13.101 +#define kfDirect565	0x80		// 5 red bits, 6 green bits and 5 blue bits per pixel
  13.102 +#define kfDirect888	0x100		// 8 bits each for red, green and blue values in a pixel.
  13.103 +#define kfDirect444	0x200		// 4 red, 4 green, 4 blue
  13.104 +#define kfDirectInverted 0x400
  13.105 +
  13.106 +#define GX_FULLSCREEN	0x01		// for OpenDisplay() 
  13.107 +#define GX_NORMALKEYS   0x02
  13.108 +#define GX_LANDSCAPEKEYS        0x03
  13.109 +
  13.110 +typedef enum
  13.111 +{
  13.112 +	SDL_ORIENTATION_UP,
  13.113 +	SDL_ORIENTATION_DOWN,
  13.114 +	SDL_ORIENTATION_LEFT,
  13.115 +	SDL_ORIENTATION_RIGHT
  13.116 +} SDL_ScreenOrientation;
  13.117 +
  13.118 +/* GAPI video mode */
  13.119 +typedef enum {
  13.120 +	GAPI_NONE = 0,
  13.121 +	GAPI_DIRECT_565,
  13.122 +	GAPI_DIRECT_555,
  13.123 +	GAPI_MONO,
  13.124 +	GAPI_PALETTE
  13.125 +} GAPIVideoMode; 
  13.126 +
  13.127 +/* Hidden "this" pointer for the video functions */
  13.128 +#define _THIS	SDL_VideoDevice *this
  13.129 +
  13.130 +typedef unsigned short PIXEL;
  13.131 +
  13.132 +/* Private display data 
  13.133 +   begin with DIB private structure to allow DIB events code sharing
  13.134 +*/
  13.135 +struct SDL_PrivateVideoData {
  13.136 +    HBITMAP screen_bmp;
  13.137 +    HPALETTE screen_pal;
  13.138 +
  13.139 +#define NUM_MODELISTS	4		/* 8, 16, 24, and 32 bits-per-pixel */
  13.140 +    int SDL_nummodes[NUM_MODELISTS];
  13.141 +    SDL_Rect **SDL_modelist[NUM_MODELISTS];
  13.142 +	enum SDL_ScreenOrientation userOrientation;
  13.143 +	int invert;
  13.144 +	char hiresFix; // using hires mode without defining hires resource
  13.145 +// --------------
  13.146 +    int w, h;
  13.147 +	enum SDL_ScreenOrientation gapiOrientation;
  13.148 +
  13.149 +    void *buffer; // may be 8, 16, 24, 32 bpp
  13.150 +	PIXEL *videoMem;
  13.151 +	BOOL needUpdate;
  13.152 +	struct GXKeyList keyList;
  13.153 +	struct GapiFunc gxFunc;
  13.154 +	struct GXDisplayProperties gxProperties;
  13.155 +	enum GAPIVideoMode videoMode;
  13.156 +	int colorscale;
  13.157 +	int dstLineStep;  // in bytes
  13.158 +	int dstPixelStep; // in bytes
  13.159 +	int startOffset; // in bytes
  13.160 +	int useVga;
  13.161 +};
  13.162 +
  13.163 +
  13.164 +#define gapiBuffer this->hidden->buffer
  13.165 +#define gapi this->hidden
  13.166 +
  13.167 +#endif /* _SDL_gapivideo_h */
    14.1 --- a/src/video/wincommon/SDL_lowvideo.h	Thu Jan 19 08:36:41 2006 +0000
    14.2 +++ b/src/video/wincommon/SDL_lowvideo.h	Thu Jan 19 08:43:00 2006 +0000
    14.3 @@ -40,7 +40,8 @@
    14.4  	SDL_VideoSurface &&						\
    14.5  	((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
    14.6  	(((SDL_VideoSurface->flags & SDL_OPENGL   ) == SDL_OPENGL    ) || \
    14.7 -	 (strcmp(this->name, "windib") == 0))				\
    14.8 +	((strcmp(this->name, "windib") == 0) || \
    14.9 +	 (strcmp(this->name, "gapi") == 0))) \
   14.10  )
   14.11  #define DDRAW_FULLSCREEN() 						\
   14.12  (									\
    15.1 --- a/src/video/wincommon/SDL_sysevents.c	Thu Jan 19 08:36:41 2006 +0000
    15.2 +++ b/src/video/wincommon/SDL_sysevents.c	Thu Jan 19 08:43:00 2006 +0000
    15.3 @@ -47,6 +47,7 @@
    15.4  #endif
    15.5  
    15.6  #ifdef _WIN32_WCE
    15.7 +#include "SDL_gapivideo.h"
    15.8  #define NO_GETKEYBOARDSTATE
    15.9  #define NO_CHANGEDISPLAYSETTINGS
   15.10  #endif
   15.11 @@ -101,6 +102,38 @@
   15.12  	}
   15.13  }
   15.14  
   15.15 +/* for gapi landscape mode */
   15.16 +static void GapiTransform(SDL_ScreenOrientation rotate, char hires, Sint16 *x, Sint16 *y) {
   15.17 +	Sint16 rotatedX;
   15.18 +	Sint16 rotatedY;
   15.19 +
   15.20 +	if (hires) {
   15.21 +		*x = *x * 2;
   15.22 +		*y = *y * 2;
   15.23 +	}
   15.24 +
   15.25 +	switch(rotate) {
   15.26 +		case SDL_ORIENTATION_UP:
   15.27 +			break;
   15.28 +		case SDL_ORIENTATION_RIGHT:
   15.29 +			if (!SDL_VideoSurface)
   15.30 +				break;
   15.31 +			rotatedX = SDL_VideoSurface->w - *y;
   15.32 +			rotatedY = *x;
   15.33 +			*x = rotatedX;
   15.34 +			*y = rotatedY;
   15.35 +			break;
   15.36 +		case SDL_ORIENTATION_LEFT:
   15.37 +			if (!SDL_VideoSurface)
   15.38 +				break;
   15.39 +			rotatedX = *y;
   15.40 +			rotatedY = SDL_VideoSurface->h - *x;
   15.41 +			*x = rotatedX;
   15.42 +			*y = rotatedY;
   15.43 +			break;
   15.44 +	}
   15.45 +}
   15.46 +
   15.47  #endif
   15.48  
   15.49  static void SDL_RestoreGameMode(void)
   15.50 @@ -319,6 +352,10 @@
   15.51  						posted = SDL_PrivateMouseMotion(0, 1, x, y);
   15.52  					}
   15.53  				} else {
   15.54 +#ifdef _WIN32_WCE
   15.55 +					if (SDL_VideoSurface)
   15.56 +						GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &x, &y);
   15.57 +#endif
   15.58  					posted = SDL_PrivateMouseMotion(0, 0, x, y);
   15.59  				}
   15.60  			}
   15.61 @@ -407,6 +444,10 @@
   15.62  				} else {
   15.63  					x = (Sint16)LOWORD(lParam);
   15.64  					y = (Sint16)HIWORD(lParam);
   15.65 +#ifdef _WIN32_WCE
   15.66 +					if (SDL_VideoSurface)
   15.67 +						GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &x, &y);
   15.68 +#endif
   15.69  				}
   15.70  				posted = SDL_PrivateMouseButton(
   15.71  							state, button, x, y);
    16.1 --- a/src/video/wincommon/SDL_sysmouse.c	Thu Jan 19 08:36:41 2006 +0000
    16.2 +++ b/src/video/wincommon/SDL_sysmouse.c	Thu Jan 19 08:43:00 2006 +0000
    16.3 @@ -251,6 +251,7 @@
    16.4  /* Check to see if we need to enter or leave mouse relative mode */
    16.5  void WIN_CheckMouseMode(_THIS)
    16.6  {
    16.7 +#ifndef _WIN32_WCE 
    16.8          /* If the mouse is hidden and input is grabbed, we use relative mode */
    16.9          if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
   16.10               (this->input_grab != SDL_GRAB_OFF) ) {
   16.11 @@ -258,4 +259,7 @@
   16.12          } else {
   16.13                  mouse_relative = 0;
   16.14          }
   16.15 +#else
   16.16 +		mouse_relative =  0; 
   16.17 +#endif
   16.18  }
    17.1 --- a/src/video/windib/SDL_dibevents.c	Thu Jan 19 08:36:41 2006 +0000
    17.2 +++ b/src/video/windib/SDL_dibevents.c	Thu Jan 19 08:43:00 2006 +0000
    17.3 @@ -59,6 +59,31 @@
    17.4     and give him a chance to handle some messages. */
    17.5  static WNDPROC userWindowProc = NULL;
    17.6  
    17.7 +
    17.8 +#ifdef _WIN32_WCE
    17.9 +
   17.10 +WPARAM rotateKey(WPARAM key,SDL_ScreenOrientation direction) 
   17.11 +{
   17.12 +	if (direction != SDL_ORIENTATION_LEFT)
   17.13 +		return key;
   17.14 +
   17.15 +	switch (key) {
   17.16 +		case 0x26: /* up */
   17.17 +			return 0x27;
   17.18 +		case 0x27: /* right */
   17.19 +			return 0x28;
   17.20 +		case 0x28: /* down */
   17.21 +			return 0x25;
   17.22 +		case 0x25: /* left */
   17.23 +			return 0x26;
   17.24 +	}
   17.25 +
   17.26 +	return key;
   17.27 +}
   17.28 +
   17.29 +#endif 
   17.30 +
   17.31 +
   17.32  /* The main Win32 event handler */
   17.33  LONG
   17.34   DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
   17.35 @@ -70,6 +95,15 @@
   17.36  		case WM_KEYDOWN: {
   17.37  			SDL_keysym keysym;
   17.38  
   17.39 +#ifdef _WIN32_WCE
   17.40 +			// Drop GAPI artefacts
   17.41 +			if (wParam == 0x84 || wParam == 0x5B)
   17.42 +				return 0;
   17.43 +
   17.44 +			// Rotate key if necessary
   17.45 +			if (this->hidden->orientation != SDL_ORIENTATION_UP)
   17.46 +				wParam = rotateKey(wParam, this->hidden->orientation);	
   17.47 +#endif 
   17.48  			/* Ignore repeated keys */
   17.49  			if ( lParam&REPEATED_KEYMASK ) {
   17.50  				return(0);
   17.51 @@ -127,6 +161,16 @@
   17.52  		case WM_KEYUP: {
   17.53  			SDL_keysym keysym;
   17.54  
   17.55 +#ifdef _WIN32_WCE
   17.56 +			// Drop GAPI artefacts
   17.57 +			if (wParam == 0x84 || wParam == 0x5B)
   17.58 +				return 0;
   17.59 +
   17.60 +			// Rotate key if necessary
   17.61 +			if (this->hidden->orientation != SDL_ORIENTATION_UP)
   17.62 +				wParam = rotateKey(wParam, this->hidden->orientation);	
   17.63 +#endif
   17.64 +
   17.65  			switch (wParam) {
   17.66  				case VK_CONTROL:
   17.67  					if ( lParam&EXTENDED_KEYMASK )
    18.1 --- a/src/video/windib/SDL_dibvideo.c	Thu Jan 19 08:36:41 2006 +0000
    18.2 +++ b/src/video/windib/SDL_dibvideo.c	Thu Jan 19 08:43:00 2006 +0000
    18.3 @@ -768,14 +768,15 @@
    18.4  	ReleaseDC(SDL_Window, hdc);
    18.5  }
    18.6  
    18.7 +
    18.8  int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
    18.9  {
   18.10  	RGBQUAD *pal;
   18.11  	int i;
   18.12 -#ifndef _WIN32_WCE
   18.13 +#if (_WIN32_WCE < 400 )
   18.14 +	HDC hdc;
   18.15 +#else
   18.16  	HDC hdc, mdc;
   18.17 -#else
   18.18 -	HDC hdc;
   18.19  #endif
   18.20  
   18.21  	/* Update the display palette */
   18.22 @@ -805,7 +806,7 @@
   18.23  	}
   18.24  
   18.25  	/* Set the DIB palette and update the display */
   18.26 -#ifndef _WIN32_WCE
   18.27 +#if ( _WIN32_WCE >= 400 )
   18.28  	mdc = CreateCompatibleDC(hdc);
   18.29  	SelectObject(mdc, screen_bmp);
   18.30  	SetDIBColorTable(mdc, firstcolor, ncolors, pal);
   18.31 @@ -817,6 +818,7 @@
   18.32  	return(1);
   18.33  }
   18.34  
   18.35 +
   18.36  static void DIB_CheckGamma(_THIS)
   18.37  {
   18.38  #ifndef NO_GAMMA_SUPPORT
    19.1 --- a/src/video/windib/SDL_dibvideo.h	Thu Jan 19 08:36:41 2006 +0000
    19.2 +++ b/src/video/windib/SDL_dibvideo.h	Thu Jan 19 08:43:00 2006 +0000
    19.3 @@ -30,6 +30,15 @@
    19.4  
    19.5  #include <windows.h>
    19.6  
    19.7 +/* for PDA */
    19.8 +typedef enum
    19.9 +{
   19.10 +	SDL_ORIENTATION_UP,
   19.11 +	SDL_ORIENTATION_DOWN,
   19.12 +	SDL_ORIENTATION_LEFT,
   19.13 +	SDL_ORIENTATION_RIGHT
   19.14 +} SDL_ScreenOrientation;
   19.15 +
   19.16  /* Private display data */
   19.17  struct SDL_PrivateVideoData {
   19.18      HBITMAP screen_bmp;
   19.19 @@ -38,6 +47,10 @@
   19.20  #define NUM_MODELISTS	4		/* 8, 16, 24, and 32 bits-per-pixel */
   19.21      int SDL_nummodes[NUM_MODELISTS];
   19.22      SDL_Rect **SDL_modelist[NUM_MODELISTS];
   19.23 +
   19.24 +	SDL_ScreenOrientation orientation;
   19.25 +	int invert;
   19.26 +	char hiresFix; // using hires mode without defining hires resource
   19.27  };
   19.28  /* Old variable names */
   19.29  #define screen_bmp		(this->hidden->screen_bmp)