Browse Source

New options on window size & aspect ratio control.

louyihua 8 years ago
parent
commit
9963fee8d1
13 changed files with 344 additions and 293 deletions
  1. 96 0
      common.h
  2. 77 48
      global.c
  3. 9 1
      global.h
  4. 5 106
      main.c
  5. 21 0
      sdlpal.cfg.example
  6. 4 2
      text.c
  7. 5 10
      util.c
  8. 6 0
      util.h
  9. 60 113
      video.c
  10. 2 8
      video.h
  11. 12 0
      winphone/SDLPal/SDLPal.vcxproj
  12. 13 4
      winphone/SDLPal/SDLPal.vcxproj.filters
  13. 34 1
      winphone/SDLPal/WinPhoneUtil.cpp

+ 96 - 0
common.h

@@ -103,6 +103,18 @@ extern "C"
 #define PAL_HAS_MOUSE         1
 #define PAL_PREFIX            "e:/data/pal/"
 #define PAL_SAVE_PREFIX       "e:/data/pal/"
+# ifdef __S60_5X__
+#  define PAL_DEFAULT_WINDOW_WIDTH   640
+#  define PAL_DEFAULT_WINDOW_HEIGHT  360
+# else
+#  define PAL_DEFAULT_WINDOW_WIDTH   320
+#  define PAL_DEFAULT_WINDOW_HEIGHT  240
+# endif
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_SWSURFACE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
+# endif
 
 #elif defined (GEKKO)
 
@@ -111,23 +123,85 @@ extern "C"
 #define PAL_PREFIX            "SD:/apps/sdlpal/"
 #define PAL_SAVE_PREFIX       "SD:/apps/sdlpal/"
 
+#define PAL_DEFAULT_WINDOW_WIDTH   640
+#define PAL_DEFAULT_WINDOW_HEIGHT  480
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_SWSURFACE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
+# endif
+
 #elif defined (PSP)
 
 #define PAL_HAS_JOYSTICKS     0
 #define PAL_PREFIX            "ms0:/"
 #define PAL_SAVE_PREFIX       "ms0:/PSP/SAVEDATA/SDLPAL/"
 
+#define PAL_DEFAULT_WINDOW_WIDTH   320
+#define PAL_DEFAULT_WINDOW_HEIGHT  240
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_SWSURFACE | SDL_FULLSCREEN)
+# endif
+
+#elif defined(GPH) || defined(DINGOO)
+
+#define PAL_PREFIX            "./"
+#define PAL_SAVE_PREFIX       "./"
+
+#  define PAL_DEFAULT_WINDOW_WIDTH   320
+#  define PAL_DEFAULT_WINDOW_HEIGHT  240
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_SWSURFACE | SDL_FULLSCREEN)
+# endif
+
+#elif defined(NDS)
+
+#define PAL_PREFIX            "./"
+#define PAL_SAVE_PREFIX       "./"
+
+#  define PAL_DEFAULT_WINDOW_WIDTH   293
+#  define PAL_DEFAULT_WINDOW_HEIGHT  196
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_SWSURFACE | SDL_FULLSCREEN)
+# endif
+
 #elif defined (__IOS__)
 
 #define PAL_PREFIX            UTIL_IOS_BasePath()
 #define PAL_SAVE_PREFIX       UTIL_IOS_SavePath()
 #define PAL_HAS_TOUCH         1
+#define PAL_DEFAULT_WINDOW_WIDTH   320
+#define PAL_DEFAULT_WINDOW_HEIGHT  200
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_HWSURFACE | SDL_FULLSCREEN)
+# endif
 
 #elif defined (__ANDROID__)
 
 #define PAL_PREFIX            "/mnt/sdcard/sdlpal/"
 #define PAL_SAVE_PREFIX       "/mnt/sdcard/sdlpal/"
 #define PAL_HAS_TOUCH         1
+#define PAL_DEFAULT_WINDOW_WIDTH   320
+#define PAL_DEFAULT_WINDOW_HEIGHT  200
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_HWSURFACE | SDL_FULLSCREEN)
+# endif
 
 #elif defined (__WINPHONE__)
 
@@ -135,6 +209,14 @@ extern "C"
 #define PAL_SAVE_PREFIX       UTIL_WP_SavePath()
 #define PAL_HAS_TOUCH         1
 #define PAL_AUDIO_DEFAULT_BUFFER_SIZE   4096
+#define PAL_DEFAULT_WINDOW_WIDTH   320
+#define PAL_DEFAULT_WINDOW_HEIGHT  200
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_HWSURFACE | SDL_RESIZABLE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0))
+# endif
 
 #else
 
@@ -148,6 +230,20 @@ extern "C"
 #define PAL_PREFIX            "./"
 #define PAL_SAVE_PREFIX       "./"
 
+#define PAL_DEFAULT_WINDOW_WIDTH   640
+#define PAL_DEFAULT_WINDOW_HEIGHT  400
+#define PAL_DEFAULT_FULLSCREEN_HEIGHT 480
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_HWSURFACE | SDL_FULLSCREEN)
+# endif
+
+#endif
+
+#ifndef PAL_DEFAULT_FULLSCREEN_HEIGHT
+# define PAL_DEFAULT_FULLSCREEN_HEIGHT PAL_DEFAULT_WINDOW_HEIGHT
 #endif
 
 /* Default for 1024 samples */

+ 77 - 48
global.c

@@ -24,8 +24,8 @@
 #include "main.h"
 #include "resampler.h"
 
-LPGLOBALVARS gpGlobals = NULL;
-extern BOOL g_fUseMidi;
+static GLOBALVARS _gGlobals;
+GLOBALVARS * const  gpGlobals = &_gGlobals;
 
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
 #define DO_BYTESWAP(buf, size)
@@ -71,6 +71,10 @@ PAL_InitGlobals(
    DWORD     dwWordLength = 10;			// Default for PAL DOS/WIN95
    DWORD     dwExtraMagicDescLines = 0;	// Default for PAL DOS/WIN95
    DWORD     dwExtraItemDescLines = 0;	// Default for PAL DOS/WIN95
+   DWORD     dwScreenWidth = 0;
+   DWORD     dwScreenHeight = 0;
+   DWORD     dwFullScreen = FALSE;
+   DWORD     dwKeepAspectRatio = TRUE;
    DWORD     dwIsDOS = 1;				// Default for DOS
    DWORD     dwUseEmbeddedFonts = 1;	// Default for using embedded fonts in DOS version
    DWORD     dwUseSurroundOPL = 1;		// Default for using surround opl
@@ -81,19 +85,10 @@ PAL_InitGlobals(
    INT       iResampleQuality = RESAMPLER_QUALITY_MAX;	// Default to maximum quality
    INT       iAudioBufferSize = PAL_AUDIO_DEFAULT_BUFFER_SIZE;
    INT       iVolume = 100;				// Default for 100%
-   MUSICTYPE eMusicType = g_fUseMidi ? MUSIC_MIDI : MUSIC_RIX;
+   MUSICTYPE eMusicType = MUSIC_RIX;
    MUSICTYPE eCDType = PAL_HAS_SDLCD ? MUSIC_SDLCD : MUSIC_OGG;
    OPLTYPE   eOPLType = OPL_DOSBOX;
 
-   if (gpGlobals == NULL)
-   {
-      gpGlobals = (LPGLOBALVARS)calloc(1, sizeof(GLOBALVARS));
-      if (gpGlobals == NULL)
-      {
-         return -1;
-      }
-   }
-
 #if USE_RIX_EXTRA_INIT
    gpGlobals->pExtraFMRegs = NULL;
    gpGlobals->pExtraFMVals = NULL;
@@ -181,6 +176,22 @@ PAL_InitGlobals(
 				   {
 					   sscanf(ptr, "%f", &flSurroundOPLOffset);
 				   }
+				   else if (SDL_strcasecmp(p, "WINDOWWIDTH") == 0)
+				   {
+					   sscanf(ptr, "%u", &dwScreenWidth);
+				   }
+				   else if (SDL_strcasecmp(p, "WINDOWHEIGHT") == 0)
+				   {
+					   sscanf(ptr, "%u", &dwScreenHeight);
+				   }
+				   else if (SDL_strcasecmp(p, "FULLSCREEN") == 0)
+				   {
+					   sscanf(ptr, "%u", &dwFullScreen);
+				   }
+				   else if (SDL_strcasecmp(p, "KEEPASPECTRATIO") == 0)
+				   {
+					   sscanf(ptr, "%u", &dwKeepAspectRatio);
+				   }
 				   else if (SDL_strcasecmp(p, "AUDIOBUFFERSIZE") == 0)
 				   {
 					   sscanf(ptr, "%d", &iAudioBufferSize);
@@ -308,6 +319,29 @@ PAL_InitGlobals(
    gpGlobals->dwExtraItemDescLines = dwExtraItemDescLines;
    gpGlobals->wAudioBufferSize = (WORD)iAudioBufferSize;
    gpGlobals->iVolume = SDL_MIX_MAXVOLUME * iVolume / 100;
+#if defined(NDS) || defined(__SYMBIAN32__) || defined(GEKKO) || defined(PSP) || defined(GEKKO) || defined(GPH) || defined(DINGOO) || defined(__IOS__) || defined(__ANDROID__)
+   gpGlobals->dwScreenWidth = PAL_DEFAULT_WINDOW_WIDTH;
+   gpGlobals->dwScreenHeight = PAL_DEFAULT_WINDOW_HEIGHT;
+#elif defined(__WINPHONE__)
+   if (UTIL_WP_GetScreenSize(&dwScreenWidth, &dwScreenHeight))
+   {
+      gpGlobals->dwScreenWidth = dwScreenWidth;
+      gpGlobals->dwScreenHeight = dwScreenHeight;
+   }
+   else
+   {
+      gpGlobals->dwScreenWidth = PAL_DEFAULT_WINDOW_WIDTH;
+      gpGlobals->dwScreenHeight = PAL_DEFAULT_WINDOW_HEIGHT;
+   }
+#else
+   gpGlobals->dwScreenWidth = dwScreenWidth ? dwScreenWidth : PAL_DEFAULT_WINDOW_WIDTH;
+   gpGlobals->dwScreenHeight = dwScreenHeight ? dwScreenHeight : (dwFullScreen ? PAL_DEFAULT_FULLSCREEN_HEIGHT : PAL_DEFAULT_WINDOW_HEIGHT);
+#endif
+#if SDL_VERSION_ATLEAST(2,0,0)
+   gpGlobals->fKeepAspectRatio = dwKeepAspectRatio ? TRUE : FALSE;
+#else
+   gpGlobals->fFullScreen = dwFullScreen ? TRUE : FALSE;
+#endif
 
    //
    // Set decompress function
@@ -351,45 +385,40 @@ PAL_FreeGlobals(
 
 --*/
 {
-   if (gpGlobals != NULL)
-   {
-      //
-      // Close all opened files
-      //
-      UTIL_CloseFile(gpGlobals->f.fpFBP);
-      UTIL_CloseFile(gpGlobals->f.fpMGO);
-      UTIL_CloseFile(gpGlobals->f.fpBALL);
-      UTIL_CloseFile(gpGlobals->f.fpDATA);
-      UTIL_CloseFile(gpGlobals->f.fpF);
-      UTIL_CloseFile(gpGlobals->f.fpFIRE);
-      UTIL_CloseFile(gpGlobals->f.fpRGM);
-      UTIL_CloseFile(gpGlobals->f.fpSSS);
-
-      //
-      // Free the game data
-      //
-      free(gpGlobals->g.lprgEventObject);
-      free(gpGlobals->g.lprgScriptEntry);
-      free(gpGlobals->g.lprgStore);
-      free(gpGlobals->g.lprgEnemy);
-      free(gpGlobals->g.lprgEnemyTeam);
-      free(gpGlobals->g.lprgMagic);
-      free(gpGlobals->g.lprgBattleField);
-      free(gpGlobals->g.lprgLevelUpMagic);
+   //
+   // Close all opened files
+   //
+   UTIL_CloseFile(gpGlobals->f.fpFBP);
+   UTIL_CloseFile(gpGlobals->f.fpMGO);
+   UTIL_CloseFile(gpGlobals->f.fpBALL);
+   UTIL_CloseFile(gpGlobals->f.fpDATA);
+   UTIL_CloseFile(gpGlobals->f.fpF);
+   UTIL_CloseFile(gpGlobals->f.fpFIRE);
+   UTIL_CloseFile(gpGlobals->f.fpRGM);
+   UTIL_CloseFile(gpGlobals->f.fpSSS);
 
-      //
-      // Free the object description data
-      //
-	  if (!gpGlobals->fIsWIN95)
-         PAL_FreeObjectDesc(gpGlobals->lpObjectDesc);
+   //
+   // Free the game data
+   //
+   free(gpGlobals->g.lprgEventObject);
+   free(gpGlobals->g.lprgScriptEntry);
+   free(gpGlobals->g.lprgStore);
+   free(gpGlobals->g.lprgEnemy);
+   free(gpGlobals->g.lprgEnemyTeam);
+   free(gpGlobals->g.lprgMagic);
+   free(gpGlobals->g.lprgBattleField);
+   free(gpGlobals->g.lprgLevelUpMagic);
 
-      //
-      // Delete the instance
-      //
-      free(gpGlobals);
-   }
+   //
+   // Free the object description data
+   //
+   if (!gpGlobals->fIsWIN95)
+      PAL_FreeObjectDesc(gpGlobals->lpObjectDesc);
 
-   gpGlobals = NULL;
+   //
+   // Clear the instance
+   //
+   memset(gpGlobals, 0, sizeof(GLOBALVARS));
 }
 
 

+ 9 - 1
global.h

@@ -620,6 +620,8 @@ typedef struct tagGLOBALVARS
    DWORD            dwWordLength;
    DWORD            dwExtraMagicDescLines;
    DWORD            dwExtraItemDescLines;
+   DWORD            dwScreenWidth;
+   DWORD            dwScreenHeight;
    double           dSurroundOPLOffset;
    INT              iAudioChannels;
    INT              iSampleRate;
@@ -633,9 +635,15 @@ typedef struct tagGLOBALVARS
    BOOL             fIsWIN95;
    BOOL             fUseEmbeddedFonts;
    BOOL             fUseSurroundOPL;
+#if SDL_VERSION_ATLEAST(2,0,0)
+   BOOL             fKeepAspectRatio;
+#else
+   BOOL             fFullScreen;
+#endif
+   BOOL             fEnableJoyStick;
 } GLOBALVARS, *LPGLOBALVARS;
 
-extern LPGLOBALVARS gpGlobals;
+extern GLOBALVARS * const gpGlobals;
 
 INT
 PAL_InitGlobals(

+ 5 - 106
main.c

@@ -22,7 +22,6 @@
 //
 
 #include "main.h"
-#include "getopt.h"
 
 #ifdef PSP
 #include "main_PSP.h"
@@ -46,13 +45,10 @@ static jmp_buf g_exit_jmp_env;
 #define SPRITENUM_SPLASH_CRANE      0x49
 #define NUM_RIX_TITLE               0x05
 
-BOOL g_fUseMidi = FALSE;
 
 static VOID
 PAL_Init(
-   WORD             wScreenWidth,
-   WORD             wScreenHeight,
-   BOOL             fFullScreen
+   VOID
 )
 /*++
   Purpose:
@@ -61,11 +57,7 @@ PAL_Init(
 
   Parameters:
 
-    [IN]  wScreenWidth - width of the screen.
-
-    [IN]  wScreenHeight - height of the screen.
-
-    [IN]  fFullScreen - TRUE to use full screen mode, FALSE to use windowed mode.
+    None.
 
   Return value:
 
@@ -113,11 +105,7 @@ PAL_Init(
 	   TerminateOnError("Could not initialize global data: %d.\n", e);
    }
 
-#ifdef GEKKO
-   e = VIDEO_Init_GEKKO(wScreenWidth, wScreenHeight, fFullScreen);
-#else
-   e = VIDEO_Init(wScreenWidth, wScreenHeight, fFullScreen);
-#endif
+   e = VIDEO_Startup();
    if (e != 0)
    {
       TerminateOnError("Could not initialize Video: %d.\n", e);
@@ -523,10 +511,6 @@ main(
 
 --*/
 {
-   WORD          wScreenWidth = 0, wScreenHeight = 0;
-   int           c;
-   BOOL          fFullScreen = FALSE;
-
 #if defined(__APPLE__) && !defined(__IOS__)
    char *p = strstr(argv[0], "/Pal.app/");
 
@@ -546,94 +530,9 @@ main(
 
    UTIL_OpenLog();
 
-#ifdef _WIN32
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
+#if defined(_WIN32) && SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
    putenv("SDL_VIDEODRIVER=directx");
 #endif
-#endif
-
-#ifndef __SYMBIAN32__
-   //
-   // Parse parameters.
-   //
-   while ((c = getopt(argc, argv, "w:h:fjm")) != -1)
-   {
-      switch (c)
-      {
-      case 'w':
-         //
-         // Set the width of the screen
-         //
-         wScreenWidth = atoi(optarg);
-         if (wScreenHeight == 0)
-         {
-            wScreenHeight = wScreenWidth * 200 / 320;
-         }
-         break;
-
-      case 'h':
-         //
-         // Set the height of the screen
-         //
-         wScreenHeight = atoi(optarg);
-         if (wScreenWidth == 0)
-         {
-            wScreenWidth = wScreenHeight * 320 / 200;
-         }
-         break;
-
-      case 'f':
-         //
-         // Fullscreen Mode
-         //
-         fFullScreen = TRUE;
-         break;
-
-      case 'j':
-         //
-         // Disable joystick
-         //
-         g_fUseJoystick = FALSE;
-         break;
-
-#if PAL_HAS_NATIVEMIDI
-      case 'm':
-         //
-         // Use MIDI music
-         //
-         g_fUseMidi = TRUE;
-         break;
-#endif
-      }
-   }
-#endif
-
-   //
-   // Default resolution is 640x400 (windowed) or 640x480 (fullscreen).
-   //
-   if (wScreenWidth == 0)
-   {
-#ifdef __SYMBIAN32__
-#ifdef __S60_5X__
-      wScreenWidth = 640;
-      wScreenHeight = 360;
-#else
-      wScreenWidth = 320;
-      wScreenHeight = 240;
-#endif
-#else
-#if defined(GPH) || defined(DINGOO)
-      wScreenWidth = 320;
-      wScreenHeight = 240;
-#elif defined (__IOS__) || defined (__ANDROID__)
-      wScreenWidth = 320;
-      wScreenHeight = 200;
-#else
-      wScreenWidth = 640;
-      wScreenHeight = fFullScreen ? 480 : 400;
-#endif
-#endif
-   }
 
    //
    // Initialize everything
@@ -641,7 +540,7 @@ main(
 #ifdef PSP
    sdlpal_psp_init();
 #endif
-   PAL_Init(wScreenWidth, wScreenHeight, fFullScreen);
+   PAL_Init();
 
 #ifdef __WINPHONE__
    //

+ 21 - 0
sdlpal.cfg.example

@@ -82,3 +82,24 @@
 
 # Volume: Indicates the global volume. Valid values are from 0 to 100, default is 100.
 #Volume=100
+
+# WindowWidth: Indicates the width of game window. Default value varies on different
+#              platforms. On desktop, the default value is 640.
+#WindowWidth=640
+
+# WindowHeight: Indicates the height of game window. Default value varies on different
+#               platforms. On desktop, the default value is 400 for non-fullsceen mode,
+#               and 480 for full-screen mode.
+#WindowHeight=400
+
+# FullScreen: Indicates whether the game should started fullscreen or not, default is not.
+#             Currently only valid when the game is built with SDL 1.2 builds. If the game
+#             is built with SDL 2.0 or higher, this value is ignored.
+#FullScreen=0
+
+# KeepAspectRatio: Indicates whether the content in game window should keep its original
+#                  aspect ratio (default) or not. When aspect ratio is kept, there may be
+#                  left/right or top/bottom black edges in the game window. Currently this
+#                  value is only valid if the game is built with SDL 2.0 or higher, otherwise
+#                  this value is ignored.
+#KeepAspectRatio=1

+ 4 - 2
text.c

@@ -780,8 +780,9 @@ PAL_ShowDialogText(
                }
                lpszText++;
                break;
-            case '\'':
-               // !PAL_WIN95
+#if 0
+			/* Not used */
+			case '\'':
                //
                // Set the font color to Red
                //
@@ -795,6 +796,7 @@ PAL_ShowDialogText(
                }
                lpszText++;
                break;
+#endif
             case '\"':
                //
                // Set the font color to Yellow

+ 5 - 10
util.c

@@ -309,18 +309,14 @@ TerminateOnError(
    }
 #else
 
-#ifdef _WIN32
+# if defined(_WIN32)
    MessageBoxA(0, string, "FATAL ERROR", MB_ICONERROR);
-#endif
-
-#ifdef __linux__
+# elif defined(__linux__)
    system(va("beep; xmessage -center \"FATAL ERROR: %s\"", string));
-#endif
-
-#if defined(__SYMBIAN32__)
+# elif defined(__SYMBIAN32__)
    UTIL_WriteLog(LOG_DEBUG,"[0x%08x][%s][%s] - %s",(long)TerminateOnError,"TerminateOnError",__FILE__, string);
    SDL_Delay(3000);
-#endif
+# endif
 
 #endif
 
@@ -328,8 +324,7 @@ TerminateOnError(
    assert(!"TerminateOnError()"); // allows jumping to debugger
 #endif
 
-
-PAL_Shutdown();
+   PAL_Shutdown();
 
 #if defined (NDS)
    while (1);

+ 6 - 0
util.h

@@ -112,6 +112,12 @@ UTIL_WP_SavePath(
    VOID
 );
 
+BOOL
+UTIL_WP_GetScreenSize(
+   DWORD *pdwScreenWidth,
+   DWORD *pdwScreenHeight
+);
+
 #endif
 
 #define _PATH_LOG           PAL_PREFIX "log.txt"

+ 60 - 113
video.c

@@ -32,9 +32,11 @@ SDL_Window               *gpWindow           = NULL;
 static SDL_Renderer      *gpRenderer         = NULL;
 static SDL_Texture       *gpTexture          = NULL;
 static SDL_Texture       *gpTouchOverlay     = NULL;
+static SDL_Rect          *gpRenderRect       = NULL;
 #ifdef __WINPHONE__
 static SDL_Texture       *gpBackKeyMessage   = NULL;
 #endif
+static SDL_Rect           gRenderRect;
 #endif
 
 // The real screen surface
@@ -48,10 +50,6 @@ volatile BOOL g_bRenderPaused = FALSE;
    static BOOL bScaleScreen = TRUE;
 #endif
 
-// Initial screen size
-static WORD               g_wInitialWidth    = 640;
-static WORD               g_wInitialHeight   = 400;
-
 // Shake times and level
 static WORD               g_wShakeTime       = 0;
 static WORD               g_wShakeLevel      = 0;
@@ -61,14 +59,8 @@ static WORD               g_wShakeLevel      = 0;
 #endif
 
 INT
-#ifdef GEKKO // Rikku2000: Crash on compile, allready define on WIISDK
-VIDEO_Init_GEKKO(
-#else
-VIDEO_Init(
-#endif
-   WORD             wScreenWidth,
-   WORD             wScreenHeight,
-   BOOL             fFullScreen
+VIDEO_Startup(
+   VOID
 )
 /*++
   Purpose:
@@ -77,11 +69,7 @@ VIDEO_Init(
 
   Parameters:
 
-    [IN]  wScreenWidth - width of the screen.
-
-    [IN]  wScreenHeight - height of the screen.
-
-    [IN]  fFullScreen - TRUE to use full screen mode, FALSE to use windowed mode.
+    None.
 
   Return value:
 
@@ -94,22 +82,12 @@ VIDEO_Init(
    SDL_Surface *overlay;
 #endif
 
-   g_wInitialWidth = wScreenWidth;
-   g_wInitialHeight = wScreenHeight;
-
 #if SDL_VERSION_ATLEAST(2,0,0)
    //
    // Before we can render anything, we need a window and a renderer.
    //
-#if defined (__IOS__) || defined (__ANDROID__) || defined (__WINPHONE__)
-   gpWindow = SDL_CreateWindow("Pal",
-      SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, wScreenWidth, wScreenHeight,
-      SDL_WINDOW_SHOWN);
-#else
-   gpWindow = SDL_CreateWindow("Pal",
-      SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, wScreenWidth, wScreenHeight,
-      SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
-#endif
+   gpWindow = SDL_CreateWindow("Pal", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+      gpGlobals->dwScreenWidth, gpGlobals->dwScreenHeight, PAL_VIDEO_INIT_FLAGS);
 
    if (gpWindow == NULL)
    {
@@ -224,30 +202,31 @@ VIDEO_Init(
    }
 #endif
 
+   gpRenderRect = NULL;
+   if (gpGlobals->fKeepAspectRatio)
+   {
+	   float ax = (float)gpGlobals->dwScreenWidth / 320.0f;
+	   float ay = (float)gpGlobals->dwScreenHeight / 200.0f;
+	   if (ax != ay)
+	   {
+		   float ratio = (ax > ay) ? ay : ax;
+		   WORD w = (WORD)(ratio * 320.0f);
+		   WORD h = (WORD)(ratio * 200.0f);
+		   if (w % 4 != 0) w += 4 - (w % 4);
+		   if (h % 4 != 0) h += 4 - (h % 4);
+		   gRenderRect.x = (gpGlobals->dwScreenWidth - w) / 2;
+		   gRenderRect.y = (gpGlobals->dwScreenHeight - h) / 2;
+		   gRenderRect.w = w;
+		   gRenderRect.h = h;
+		   gpRenderRect = &gRenderRect;
+	   }
+   }
 #else
 
    //
    // Create the screen surface.
    //
-#if defined (NDS)
-   gpScreenReal = SDL_SetVideoMode(293, 196, 8, SDL_SWSURFACE | SDL_FULLSCREEN);
-#elif defined (__SYMBIAN32__)
-#ifdef __S60_5X__
-   gpScreenReal = SDL_SetVideoMode(640, 360, 8,
-      SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
-#else
-   gpScreenReal = SDL_SetVideoMode(320, 240, 8,
-      SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
-#endif
-#elif defined (GEKKO)
-   gpScreenReal = SDL_SetVideoMode(640, 480, 8,
-      SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
-#elif defined (PSP)
-   gpScreenReal = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE | SDL_FULLSCREEN);
-#else
-   gpScreenReal = SDL_SetVideoMode(wScreenWidth, wScreenHeight, 8,
-      SDL_HWSURFACE | SDL_RESIZABLE | (fFullScreen ? SDL_FULLSCREEN : 0));
-#endif
+   gpScreenReal = SDL_SetVideoMode(gpGlobals->dwScreenWidth, gpGlobals->dwScreenHeight, 8, PAL_VIDEO_INIT_FLAGS);
 
    if (gpScreenReal == NULL)
    {
@@ -255,7 +234,7 @@ VIDEO_Init(
       // Fall back to 640x480 software mode.
       //
       gpScreenReal = SDL_SetVideoMode(640, 480, 8,
-         SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
+         SDL_SWSURFACE | (gpGlobals->fFullScreen ? SDL_FULLSCREEN : 0));
    }
 
    //
@@ -300,13 +279,13 @@ VIDEO_Init(
       return -2;
    }
 
-#endif
-
-   if (fFullScreen)
+   if (gpGlobals->fFullScreen)
    {
       SDL_ShowCursor(FALSE);
    }
 
+#endif
+
    return 0;
 }
 
@@ -443,28 +422,6 @@ VIDEO_UpdateScreen(
       {
          SDL_UnlockSurface(gpScreenReal);
       }
-
-#if SDL_VERSION_ATLEAST(2,0,0)
-      SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
-      SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
-      if (gpTouchOverlay)
-      {
-         SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
-      }
-#ifdef __WINPHONE__
-      if (gpBackKeyMessage)
-      {
-         extern unsigned int g_uiLastBackKeyTime;
-         if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
-         {
-           SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
-         }
-      }
-#endif
-      SDL_RenderPresent(gpRenderer);
-#else
-      SDL_UpdateRect(gpScreenReal, dstrect.x, dstrect.y, dstrect.w, dstrect.h);
-#endif
    }
    else if (g_wShakeTime != 0)
    {
@@ -510,26 +467,10 @@ VIDEO_UpdateScreen(
          SDL_UnlockSurface(gpScreenReal);
       }
 
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-      SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
-      SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
-      if (gpTouchOverlay)
-      {
-         SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
-      }
-#ifdef __WINPHONE__
-      if (gpBackKeyMessage)
-      {
-         extern unsigned int g_uiLastBackKeyTime;
-         if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
-         {
-           SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
-         }
-      }
-#endif
-      SDL_RenderPresent(gpRenderer);
-#else
-      SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
+#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
+      dstrect.x = dstrect.y = 0;
+      dstrect.w = gpScreenReal->w;
+      dstrect.h = gpScreenReal->h;
 #endif
       g_wShakeTime--;
    }
@@ -547,28 +488,34 @@ VIDEO_UpdateScreen(
          SDL_UnlockSurface(gpScreenReal);
       }
 
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-      SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
-      SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
-      if (gpTouchOverlay)
-      {
-         SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
-      }
+#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
+      dstrect.x = dstrect.y = 0;
+      dstrect.w = gpScreenReal->w;
+      dstrect.h = gpScreenReal->h;
+#endif
+   }
+
+#if SDL_VERSION_ATLEAST(2,0,0)
+   SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
+   SDL_RenderCopy(gpRenderer, gpTexture, NULL, gpRenderRect);
+   if (gpTouchOverlay)
+   {
+     SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
+   }
 #ifdef __WINPHONE__
-      if (gpBackKeyMessage)
+   if (gpBackKeyMessage)
+   {
+      extern unsigned int g_uiLastBackKeyTime;
+      if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
       {
-         extern unsigned int g_uiLastBackKeyTime;
-         if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
-         {
-           SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
-         }
+         SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
       }
+   }
 #endif
-      SDL_RenderPresent(gpRenderer);
+   SDL_RenderPresent(gpRenderer);
 #else
-      SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
+   SDL_UpdateRect(gpScreenReal, dstrect.x, dstrect.y, dstrect.w, dstrect.h);
 #endif
-   }
 }
 
 VOID
@@ -816,17 +763,17 @@ VIDEO_ToggleFullscreen(
    //
    // ... and create a new one
    //
-   if (g_wInitialWidth == 640 && g_wInitialHeight == 400 && (flags & SDL_FULLSCREEN))
+   if (gpGlobals->dwScreenWidth == 640 && gpGlobals->dwScreenHeight == 400 && (flags & SDL_FULLSCREEN))
    {
       gpScreenReal = SDL_SetVideoMode(640, 480, 8, flags);
    }
-   else if (g_wInitialWidth == 640 && g_wInitialHeight == 480 && !(flags & SDL_FULLSCREEN))
+   else if (gpGlobals->dwScreenWidth == 640 && gpGlobals->dwScreenHeight == 480 && !(flags & SDL_FULLSCREEN))
    {
       gpScreenReal = SDL_SetVideoMode(640, 400, 8, flags);
    }
    else
    {
-      gpScreenReal = SDL_SetVideoMode(g_wInitialWidth, g_wInitialHeight, 8, flags);
+      gpScreenReal = SDL_SetVideoMode(gpGlobals->dwScreenWidth, gpGlobals->dwScreenHeight, 8, flags);
    }
 
    VIDEO_SetPalette(palette);

+ 2 - 8
video.h

@@ -34,14 +34,8 @@ extern SDL_Surface *gpScreenBak;
 extern volatile BOOL g_bRenderPaused;
 
 INT
-#ifdef GEKKO // Rikku2000: Crash on compile, allready define on WIISDK
-VIDEO_Init_GEKKO(
-#else
-VIDEO_Init(
-#endif
-   WORD             wScreenWidth,
-   WORD             wScreenHeight,
-   BOOL             fFullScreen
+VIDEO_Startup(
+   VOID
 );
 
 VOID

+ 12 - 0
winphone/SDLPal/SDLPal.vcxproj

@@ -88,6 +88,9 @@
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
       <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
+    <Link>
+      <AdditionalDependencies>dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
     <ClCompile>
@@ -96,6 +99,9 @@
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
       <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
+    <Link>
+      <AdditionalDependencies>dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -104,6 +110,9 @@
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
       <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
+    <Link>
+      <AdditionalDependencies>dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
@@ -112,6 +121,9 @@
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
       <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
+    <Link>
+      <AdditionalDependencies>dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
     <AppxManifest Include="Package.appxmanifest">

+ 13 - 4
winphone/SDLPal/SDLPal.vcxproj.filters

@@ -25,17 +25,26 @@
     </Image>
     <Filter Include="资产\Data">
       <UniqueIdentifier>{77c8944a-e166-4a2c-b515-9550e82a9d63}</UniqueIdentifier>
+      <SourceControlFiles>False</SourceControlFiles>
     </Filter>
     <Filter Include="资产\Data\OGG">
       <UniqueIdentifier>{08b020ee-aa73-48f6-83b9-ad6573dd0dcc}</UniqueIdentifier>
+      <SourceControlFiles>False</SourceControlFiles>
     </Filter>
     <Filter Include="资产\Data\MP3">
       <UniqueIdentifier>{eb7b143d-6d18-479d-8908-7d6fc6f86449}</UniqueIdentifier>
+      <SourceControlFiles>False</SourceControlFiles>
+    </Filter>
+    <Filter Include="SDL2">
+      <UniqueIdentifier>{1b4126fa-ab18-4d2a-8fc0-dff551a94158}</UniqueIdentifier>
+      <SourceControlFiles>False</SourceControlFiles>
     </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="WinPhoneUtil.cpp" />
-    <ClCompile Include="..\SDL2\src\main\winrt\SDL_winrt_main_NonXAML.cpp" />
+    <ClCompile Include="..\SDL2\src\main\winrt\SDL_winrt_main_NonXAML.cpp">
+      <Filter>SDL2</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <AppxManifest Include="Package.appxmanifest" />
@@ -83,6 +92,9 @@
     <None Include="Assets\Data\RNG.MKF">
       <Filter>资产\Data</Filter>
     </None>
+    <None Include="Assets\Data\sdlpal.cfg">
+      <Filter>资产\Data</Filter>
+    </None>
     <None Include="Assets\Data\SSS.MKF">
       <Filter>资产\Data</Filter>
     </None>
@@ -98,9 +110,6 @@
     <None Include="Assets\Data\WORD.DAT">
       <Filter>资产\Data</Filter>
     </None>
-    <None Include="Assets\Data\sdlpal.cfg">
-      <Filter>资产\Data</Filter>
-    </None>
     <None Include="Assets\Data\OGG\10002.ogg">
       <Filter>资产\Data\OGG</Filter>
     </None>

+ 34 - 1
winphone/SDLPal/WinPhoneUtil.cpp

@@ -1,5 +1,6 @@
 #include <wrl.h>
 #include <string>
+#include <DXGI.h>
 
 //#include <stdio.h>
 //#include <share.h>
@@ -59,10 +60,42 @@ static std::string g_savepath;
 extern "C"
 LPCSTR UTIL_WP_SavePath(VOID)
 {
-	Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
+	auto localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
 	int len = WideCharToMultiByte(CP_ACP, 0, localfolder->Begin(), -1, nullptr, 0, nullptr, nullptr);
 	g_savepath.resize(len);
 	WideCharToMultiByte(CP_ACP, 0, localfolder->Begin(), -1, (char*)g_savepath.data(), len, nullptr, nullptr);
 	const_cast<char*>(g_savepath.data())[len - 1] = '\\';
 	return g_savepath.c_str();
 }
+
+extern "C"
+BOOL UTIL_WP_GetScreenSize(DWORD *pdwScreenWidth, DWORD *pdwScreenHeight)
+{
+	DXGI_OUTPUT_DESC desc;
+	IDXGIFactory1* pFactory = nullptr;
+	IDXGIAdapter1* pAdapter = nullptr;
+	IDXGIOutput* pOutput = nullptr;
+	DWORD retval = FALSE;
+
+	if (!pdwScreenWidth || !pdwScreenHeight) return FALSE;
+
+	if (FAILED(CreateDXGIFactory1(IID_IDXGIFactory1, (void**)&pFactory))) goto UTIL_WP_GetScreenSize_exit;
+
+	if (FAILED(pFactory->EnumAdapters1(0, &pAdapter))) goto UTIL_WP_GetScreenSize_exit;
+
+	if (FAILED(pAdapter->EnumOutputs(0, &pOutput))) goto UTIL_WP_GetScreenSize_exit;
+
+	if (SUCCEEDED(pOutput->GetDesc(&desc)))
+	{
+		*pdwScreenWidth = (desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top);
+		*pdwScreenHeight = (desc.DesktopCoordinates.right - desc.DesktopCoordinates.left);
+		retval = TRUE;
+	}
+
+UTIL_WP_GetScreenSize_exit:
+	if (pOutput) pOutput->Release();
+	if (pAdapter) pAdapter->Release();
+	if (pFactory) pFactory->Release();
+
+	return retval;
+}