Browse Source

rewritten video properly for SDL2. create texture every frame is NOT the proper way.

Wei Mingzhi 9 years ago
parent
commit
a6678b3087
6 changed files with 142 additions and 330 deletions
  1. 1 1
      common.h
  2. 8 1
      ending.c
  3. 2 89
      ios/SDLPal/SDLPal.xcodeproj/project.pbxproj
  4. 4 0
      ios/SDLPal/SDLPal/SDLPal-Info.plist
  5. 12 1
      util.c
  6. 115 238
      video.c

+ 1 - 1
common.h

@@ -104,7 +104,7 @@ extern "C"
 
 #elif defined (__IOS__)
 
-#define PAL_PREFIX            "./"
+#define PAL_PREFIX            "../Documents/"
 #define PAL_SAVE_PREFIX       "../Documents/"
 #define PAL_HAS_TOUCH         1
 

+ 8 - 1
ending.c

@@ -92,7 +92,9 @@ PAL_ShowFBP(
       p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
          gpScreen->format->Rmask, gpScreen->format->Gmask,
          gpScreen->format->Bmask, gpScreen->format->Amask);
-
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+      SDL_SetSurfacePalette(p, gpScreen->format->palette);
+#endif
       PAL_FBPBlitToSurface(buf, p);
       VIDEO_BackupScreen();
 
@@ -325,6 +327,11 @@ PAL_EndingAnimation(
       gpScreen->format->Rmask, gpScreen->format->Gmask,
       gpScreen->format->Bmask, gpScreen->format->Amask);
 
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+   SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
+   SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
+#endif
+
    PAL_MKFDecompressChunk(buf, 64000, 61, gpGlobals->f.fpFBP);
    PAL_FBPBlitToSurface(buf, pUpper);
 

+ 2 - 89
ios/SDLPal/SDLPal.xcodeproj/project.pbxproj

@@ -7,26 +7,6 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		7111724A195BF53800A7DE3B /* abc.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117236195BF53800A7DE3B /* abc.mkf */; };
-		7111724B195BF53800A7DE3B /* ball.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117237195BF53800A7DE3B /* ball.mkf */; };
-		7111724C195BF53800A7DE3B /* data.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117238195BF53800A7DE3B /* data.mkf */; };
-		7111724D195BF53800A7DE3B /* f.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117239195BF53800A7DE3B /* f.mkf */; };
-		7111724E195BF53800A7DE3B /* fbp.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 7111723A195BF53800A7DE3B /* fbp.mkf */; };
-		7111724F195BF53800A7DE3B /* fire.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 7111723B195BF53800A7DE3B /* fire.mkf */; };
-		71117250195BF53800A7DE3B /* gop.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 7111723C195BF53800A7DE3B /* gop.mkf */; };
-		71117251195BF53800A7DE3B /* m.msg in Resources */ = {isa = PBXBuildFile; fileRef = 7111723D195BF53800A7DE3B /* m.msg */; };
-		71117252195BF53800A7DE3B /* map.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 7111723E195BF53800A7DE3B /* map.mkf */; };
-		71117253195BF53800A7DE3B /* mgo.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 7111723F195BF53800A7DE3B /* mgo.mkf */; };
-		71117254195BF53800A7DE3B /* midi.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117240195BF53800A7DE3B /* midi.mkf */; };
-		71117255195BF53800A7DE3B /* mus.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117241195BF53800A7DE3B /* mus.mkf */; };
-		71117256195BF53800A7DE3B /* pat.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117242195BF53800A7DE3B /* pat.mkf */; };
-		71117257195BF53800A7DE3B /* rgm.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117243195BF53800A7DE3B /* rgm.mkf */; };
-		71117258195BF53800A7DE3B /* rng.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117244195BF53800A7DE3B /* rng.mkf */; };
-		71117259195BF53800A7DE3B /* sss.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117245195BF53800A7DE3B /* sss.mkf */; };
-		7111725A195BF53800A7DE3B /* voc.mkf in Resources */ = {isa = PBXBuildFile; fileRef = 71117246195BF53800A7DE3B /* voc.mkf */; };
-		7111725B195BF53800A7DE3B /* wor16.asc in Resources */ = {isa = PBXBuildFile; fileRef = 71117247195BF53800A7DE3B /* wor16.asc */; };
-		7111725C195BF53800A7DE3B /* wor16.fon in Resources */ = {isa = PBXBuildFile; fileRef = 71117248195BF53800A7DE3B /* wor16.fon */; };
-		7111725D195BF53800A7DE3B /* word.dat in Resources */ = {isa = PBXBuildFile; fileRef = 71117249195BF53800A7DE3B /* word.dat */; };
 		71655061195BB372006E1227 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 71655060195BB372006E1227 /* UIKit.framework */; };
 		71655063195BB372006E1227 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 71655062195BB372006E1227 /* Foundation.framework */; };
 		71655065195BB372006E1227 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 71655064195BB372006E1227 /* CoreGraphics.framework */; };
@@ -184,26 +164,6 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
-		71117236195BF53800A7DE3B /* abc.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = abc.mkf; sourceTree = "<group>"; };
-		71117237195BF53800A7DE3B /* ball.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = ball.mkf; sourceTree = "<group>"; };
-		71117238195BF53800A7DE3B /* data.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = data.mkf; sourceTree = "<group>"; };
-		71117239195BF53800A7DE3B /* f.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = f.mkf; sourceTree = "<group>"; };
-		7111723A195BF53800A7DE3B /* fbp.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = fbp.mkf; sourceTree = "<group>"; };
-		7111723B195BF53800A7DE3B /* fire.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = fire.mkf; sourceTree = "<group>"; };
-		7111723C195BF53800A7DE3B /* gop.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = gop.mkf; sourceTree = "<group>"; };
-		7111723D195BF53800A7DE3B /* m.msg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = m.msg; sourceTree = "<group>"; };
-		7111723E195BF53800A7DE3B /* map.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = map.mkf; sourceTree = "<group>"; };
-		7111723F195BF53800A7DE3B /* mgo.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = mgo.mkf; sourceTree = "<group>"; };
-		71117240195BF53800A7DE3B /* midi.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = midi.mkf; sourceTree = "<group>"; };
-		71117241195BF53800A7DE3B /* mus.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = mus.mkf; sourceTree = "<group>"; };
-		71117242195BF53800A7DE3B /* pat.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = pat.mkf; sourceTree = "<group>"; };
-		71117243195BF53800A7DE3B /* rgm.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = rgm.mkf; sourceTree = "<group>"; };
-		71117244195BF53800A7DE3B /* rng.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = rng.mkf; sourceTree = "<group>"; };
-		71117245195BF53800A7DE3B /* sss.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = sss.mkf; sourceTree = "<group>"; };
-		71117246195BF53800A7DE3B /* voc.mkf */ = {isa = PBXFileReference; lastKnownFileType = file; path = voc.mkf; sourceTree = "<group>"; };
-		71117247195BF53800A7DE3B /* wor16.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = wor16.asc; sourceTree = "<group>"; };
-		71117248195BF53800A7DE3B /* wor16.fon */ = {isa = PBXFileReference; lastKnownFileType = file; path = wor16.fon; sourceTree = "<group>"; };
-		71117249195BF53800A7DE3B /* word.dat */ = {isa = PBXFileReference; lastKnownFileType = file; path = word.dat; sourceTree = "<group>"; };
 		7165505D195BB372006E1227 /* SDLPal.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SDLPal.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		71655060195BB372006E1227 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
 		71655062195BB372006E1227 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -563,34 +523,6 @@
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
-		71117235195BF53800A7DE3B /* Data */ = {
-			isa = PBXGroup;
-			children = (
-				71117236195BF53800A7DE3B /* abc.mkf */,
-				71117237195BF53800A7DE3B /* ball.mkf */,
-				71117238195BF53800A7DE3B /* data.mkf */,
-				71117239195BF53800A7DE3B /* f.mkf */,
-				7111723A195BF53800A7DE3B /* fbp.mkf */,
-				7111723B195BF53800A7DE3B /* fire.mkf */,
-				7111723C195BF53800A7DE3B /* gop.mkf */,
-				7111723D195BF53800A7DE3B /* m.msg */,
-				7111723E195BF53800A7DE3B /* map.mkf */,
-				7111723F195BF53800A7DE3B /* mgo.mkf */,
-				71117240195BF53800A7DE3B /* midi.mkf */,
-				71117241195BF53800A7DE3B /* mus.mkf */,
-				71117242195BF53800A7DE3B /* pat.mkf */,
-				71117243195BF53800A7DE3B /* rgm.mkf */,
-				71117244195BF53800A7DE3B /* rng.mkf */,
-				71117245195BF53800A7DE3B /* sss.mkf */,
-				71117246195BF53800A7DE3B /* voc.mkf */,
-				71117247195BF53800A7DE3B /* wor16.asc */,
-				71117248195BF53800A7DE3B /* wor16.fon */,
-				71117249195BF53800A7DE3B /* word.dat */,
-			);
-			name = Data;
-			path = ../../Data;
-			sourceTree = "<group>";
-		};
 		71655054195BB372006E1227 = {
 			isa = PBXGroup;
 			children = (
@@ -626,7 +558,6 @@
 		71655066195BB372006E1227 /* SDLPal */ = {
 			isa = PBXGroup;
 			children = (
-				71117235195BF53800A7DE3B /* Data */,
 				716551E4195BB6DA006E1227 /* adplug */,
 				716551FE195BB6DA006E1227 /* ascii.h */,
 				716551FF195BB6DA006E1227 /* battle.c */,
@@ -1195,26 +1126,6 @@
 				71655075195BB372006E1227 /* Default@2x.png in Resources */,
 				71655077195BB372006E1227 /* Default-568h@2x.png in Resources */,
 				7165507F195BB3D8006E1227 /* Icon.png in Resources */,
-				7111724A195BF53800A7DE3B /* abc.mkf in Resources */,
-				7111724B195BF53800A7DE3B /* ball.mkf in Resources */,
-				7111724C195BF53800A7DE3B /* data.mkf in Resources */,
-				7111724D195BF53800A7DE3B /* f.mkf in Resources */,
-				7111724E195BF53800A7DE3B /* fbp.mkf in Resources */,
-				7111724F195BF53800A7DE3B /* fire.mkf in Resources */,
-				71117250195BF53800A7DE3B /* gop.mkf in Resources */,
-				71117251195BF53800A7DE3B /* m.msg in Resources */,
-				71117252195BF53800A7DE3B /* map.mkf in Resources */,
-				71117253195BF53800A7DE3B /* mgo.mkf in Resources */,
-				71117254195BF53800A7DE3B /* midi.mkf in Resources */,
-				71117255195BF53800A7DE3B /* mus.mkf in Resources */,
-				71117256195BF53800A7DE3B /* pat.mkf in Resources */,
-				71117257195BF53800A7DE3B /* rgm.mkf in Resources */,
-				71117258195BF53800A7DE3B /* rng.mkf in Resources */,
-				71117259195BF53800A7DE3B /* sss.mkf in Resources */,
-				7111725A195BF53800A7DE3B /* voc.mkf in Resources */,
-				7111725B195BF53800A7DE3B /* wor16.asc in Resources */,
-				7111725C195BF53800A7DE3B /* wor16.fon in Resources */,
-				7111725D195BF53800A7DE3B /* word.dat in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -1436,6 +1347,7 @@
 		7165507B195BB372006E1227 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				GCC_PRECOMPILE_PREFIX_HEADER = NO;
 				GCC_PREFIX_HEADER = "";
 				GCC_PREPROCESSOR_DEFINITIONS = (
@@ -1452,6 +1364,7 @@
 		7165507C195BB372006E1227 /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				GCC_PRECOMPILE_PREFIX_HEADER = NO;
 				GCC_PREFIX_HEADER = "";
 				GCC_PREPROCESSOR_DEFINITIONS = "__IOS__=1";

+ 4 - 0
ios/SDLPal/SDLPal/SDLPal-Info.plist

@@ -18,12 +18,16 @@
 	<string>${PRODUCT_NAME}</string>
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
 	<string>1.0</string>
 	<key>LSRequiresIPhoneOS</key>
 	<false/>
+	<key>UIFileSharingEnabled</key>
+	<true/>
 	<key>UIStatusBarHidden</key>
 	<true/>
 	<key>UIStatusBarStyle</key>

+ 12 - 1
util.c

@@ -28,6 +28,10 @@
 #include "midi.h"
 #endif
 
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+#include "SDL_messagebox.h"
+#endif
+
 void
 trim(
    char *str
@@ -294,9 +298,14 @@ TerminateOnError(
    vsnprintf(string, sizeof(string), fmt, argptr);
    va_end(argptr);
 
-
    fprintf(stderr, "\nFATAL ERROR: %s\n", string);
 
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+
+   SDL_ShowSimpleMessageBox(0, "FATAL ERROR", string, NULL);
+
+#else
+
 #ifdef _WIN32
    MessageBoxA(0, string, "FATAL ERROR", MB_ICONERROR);
 #endif
@@ -310,6 +319,8 @@ TerminateOnError(
    SDL_Delay(3000);
 #endif
 
+#endif
+
 #ifdef _DEBUG
    assert(!"TerminateOnError()"); // allows jumping to debugger
 #endif

+ 115 - 238
video.c

@@ -27,25 +27,23 @@ SDL_Surface              *gpScreen           = NULL;
 // Backup screen buffer
 SDL_Surface              *gpScreenBak        = NULL;
 
-// The real screen surface
 #if SDL_VERSION_ATLEAST(2,0,0)
 static SDL_Window        *gpWindow           = NULL;
 static SDL_Renderer      *gpRenderer         = NULL;
-static SDL_Texture       *gpScreenReal       = NULL;
+static SDL_Texture       *gpTexture          = NULL;
 static SDL_Texture       *gpTouchOverlay     = NULL;
-#else
-static SDL_Surface       *gpScreenReal       = NULL;
 #endif
 
+// The real screen surface
+static SDL_Surface       *gpScreenReal       = NULL;
+
 volatile BOOL g_bRenderPaused = FALSE;
 
-#if !SDL_VERSION_ATLEAST(2, 0, 0)
 #if (defined (__SYMBIAN32__) && !defined (__S60_5X__)) || defined (PSP) || defined (GEKKO)
    static BOOL bScaleScreen = FALSE;
 #else
    static BOOL bScaleScreen = TRUE;
 #endif
-#endif
 
 // Initial screen size
 static WORD               g_wInitialWidth    = 640;
@@ -55,6 +53,10 @@ static WORD               g_wInitialHeight   = 400;
 static WORD               g_wShakeTime       = 0;
 static WORD               g_wShakeLevel      = 0;
 
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+#define SDL_SoftStretch SDL_UpperBlit
+#endif
+
 INT
 #ifdef GEKKO // Rikku2000: Crash on compile, allready define on WIISDK
 VIDEO_Init_GEKKO(
@@ -128,11 +130,19 @@ VIDEO_Init(
    //
    gpScreen = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 8, 0, 0, 0, 0);
    gpScreenBak = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 8, 0, 0, 0, 0);
+   gpScreenReal = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 32,
+                                       0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
+
+   //
+   // Create texture for screen.
+   //
+   gpTexture = SDL_CreateTexture(gpRenderer, SDL_PIXELFORMAT_ARGB8888,
+							  SDL_TEXTUREACCESS_STREAMING, 320, 200);
 
    //
    // Failed?
    //
-   if (gpScreen == NULL || gpScreenBak == NULL)
+   if (gpScreen == NULL || gpScreenBak == NULL || gpScreenReal == NULL || gpTexture == NULL)
    {
       if (gpScreen != NULL)
       {
@@ -146,6 +156,18 @@ VIDEO_Init(
          gpScreenBak = NULL;
       }
 
+      if (gpScreenReal != NULL)
+      {
+         SDL_FreeSurface(gpScreenReal);
+         gpScreenReal = NULL;
+      }
+
+	  if (gpTexture != NULL)
+	  {
+		 SDL_DestroyTexture(gpTexture);
+		 gpTexture = NULL;
+	  }
+
       SDL_DestroyRenderer(gpRenderer);
       gpRenderer = NULL;
 
@@ -155,6 +177,9 @@ VIDEO_Init(
       return -2;
    }
 
+   //
+   // Create texture for overlay.
+   //
    overlay = SDL_LoadBMP(PAL_PREFIX "overlay.bmp");
    if (overlay != NULL)
    {
@@ -289,6 +314,12 @@ VIDEO_Shutdown(
    }
    gpTouchOverlay = NULL;
 
+   if (gpTexture)
+   {
+	  SDL_DestroyTexture(gpTexture);
+   }
+   gpTexture = NULL;
+
    if (gpRenderer)
    {
       SDL_DestroyRenderer(gpRenderer);
@@ -301,15 +332,13 @@ VIDEO_Shutdown(
    }
    gpWindow = NULL;
 
-#else
+#endif
 
    if (gpScreenReal != NULL)
    {
       SDL_FreeSurface(gpScreenReal);
    }
    gpScreenReal = NULL;
-
-#endif
 }
 
 VOID
@@ -332,74 +361,12 @@ VIDEO_UpdateScreen(
 --*/
 {
 #if SDL_VERSION_ATLEAST(2,0,0)
-   if (!g_bRenderPaused)
+   if (g_bRenderPaused)
    {
-      SDL_Texture *pTexture = SDL_CreateTextureFromSurface(gpRenderer, gpScreen);
-
-      if (lpRect != NULL)
-      {
-         SDL_Rect viewport, dstrect;
-
-         SDL_RenderGetViewport(gpRenderer, &viewport);
-         dstrect.x = (SHORT)((INT)(lpRect->x) * viewport.w / gpScreen->w);
-         dstrect.y = (SHORT)((INT)(lpRect->y) * viewport.h / gpScreen->h);
-         dstrect.w = (WORD)((DWORD)(lpRect->w) * viewport.w / gpScreen->w);
-         dstrect.h = (WORD)((DWORD)(lpRect->h) * viewport.h / gpScreen->h);
-         SDL_RenderCopy(gpRenderer, pTexture, lpRect, &dstrect);
-
-         if (gpTouchOverlay)
-         {
-            SDL_RenderCopy(gpRenderer, gpTouchOverlay, lpRect, &dstrect);
-         }
-      }
-      else if (g_wShakeTime != 0)
-      {
-          //
-          // Shake the screen
-          //
-          SDL_Rect srcrect, dstrect, viewport;
-
-          SDL_RenderGetViewport(gpRenderer, &viewport);
-          srcrect.x = 0;
-          srcrect.y = 0;
-          srcrect.w = 320;
-          srcrect.h = 200 - g_wShakeLevel;
-          
-          dstrect.x = 0;
-          dstrect.y = 0;
-          dstrect.w = 320 * viewport.w / gpScreen->w;
-          dstrect.h = (200 - g_wShakeLevel) * viewport.h / gpScreen->h;
-          
-          if (g_wShakeTime & 1)
-          {
-              srcrect.y = g_wShakeLevel;
-          }
-          else
-          {
-              dstrect.y = g_wShakeLevel * viewport.h / gpScreen->h;
-          }
-
-          SDL_RenderClear(gpRenderer);
-          SDL_RenderCopy(gpRenderer, pTexture, &srcrect, &dstrect);
-          if (gpTouchOverlay)
-          {
-             SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
-          }
-
-          g_wShakeTime--;
-      }
-      else
-      {
-         SDL_RenderCopy(gpRenderer, pTexture, NULL, NULL);
-         if (gpTouchOverlay)
-         {
-            SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
-         }
-      }
-      SDL_RenderPresent(gpRenderer);
-      SDL_DestroyTexture(pTexture);
+	  return;
    }
-#else
+#endif
+
    SDL_Rect        srcrect, dstrect;
    short           offset = 240 - 200;
    short           screenRealHeight = gpScreenReal->h;
@@ -434,7 +401,17 @@ 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);
+      }
+      SDL_RenderPresent(gpRenderer);
+#else
       SDL_UpdateRect(gpScreenReal, dstrect.x, dstrect.y, dstrect.w, dstrect.h);
+#endif
    }
    else if (g_wShakeTime != 0)
    {
@@ -480,8 +457,17 @@ 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);
+      }
+      SDL_RenderPresent(gpRenderer);
+#else
       SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
-
+#endif
       g_wShakeTime--;
    }
    else
@@ -498,9 +484,18 @@ 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);
+      }
+      SDL_RenderPresent(gpRenderer);
+#else
       SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
-   }
 #endif
+   }
 }
 
 VOID
@@ -538,7 +533,16 @@ VIDEO_SetPalette(
 
    SDL_SetSurfacePalette(gpScreen, palette);
    SDL_SetSurfacePalette(gpScreenBak, palette);
-    
+
+   //
+   // HACKHACK: need to invalidate gpScreen->map otherwise the palette
+   // would not be effective during blit
+   //
+   SDL_SetSurfaceColorMod(gpScreen, 0, 0, 0);
+   SDL_SetSurfaceColorMod(gpScreen, 0xFF, 0xFF, 0xFF);
+   SDL_SetSurfaceColorMod(gpScreenBak, 0, 0, 0);
+   SDL_SetSurfaceColorMod(gpScreenBak, 0xFF, 0xFF, 0xFF);
+
    VIDEO_UpdateScreen(NULL);
 #else
    SDL_SetPalette(gpScreen, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
@@ -901,43 +905,6 @@ VIDEO_SwitchScreen(
 
 --*/
 {
-#if SDL_VERSION_ATLEAST(2,0,0)
-    int               i, j;
-    const int         rgIndex[6] = {0, 3, 1, 5, 2, 4};
-    SDL_Texture      *pTexture;
-    
-    if (g_bRenderPaused)
-    {
-        return;
-    }
-
-    wSpeed++;
-    wSpeed *= 10;
-
-    for (i = 0; i < 6; i++)
-    {
-        for (j = rgIndex[i]; j < gpScreen->pitch * gpScreen->h; j += 6)
-        {
-            ((LPBYTE)(gpScreenBak->pixels))[j] = ((LPBYTE)(gpScreen->pixels))[j];
-        }
-
-        //
-        // Draw the backup buffer to the screen
-        //
-        pTexture = SDL_CreateTextureFromSurface(gpRenderer, gpScreenBak);
-        SDL_RenderClear(gpRenderer);
-        SDL_RenderCopy(gpRenderer, pTexture, NULL, NULL);
-        if (gpTouchOverlay)
-        {
-            SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
-        }
-        SDL_RenderPresent(gpRenderer);
-        SDL_DestroyTexture(pTexture);
-
-        UTIL_Delay(wSpeed);
-    }
-
-#else
    int               i, j;
    const int         rgIndex[6] = {0, 3, 1, 5, 2, 4};
    SDL_Rect          dstrect;
@@ -971,11 +938,19 @@ VIDEO_SwitchScreen(
       dstrect.h = screenRealHeight;
 
       SDL_SoftStretch(gpScreenBak, NULL, gpScreenReal, &dstrect);
+#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);
+      }
+      SDL_RenderPresent(gpRenderer);
+#else
       SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
-
+#endif
       UTIL_Delay(wSpeed);
    }
-#endif
 }
 
 VOID
@@ -998,123 +973,6 @@ VIDEO_FadeScreen(
 
 --*/
 {
-#if SDL_VERSION_ATLEAST(2,0,0)
-    int               i, j, k;
-    DWORD             time;
-    BYTE              a, b;
-    const int         rgIndex[6] = {0, 3, 1, 5, 2, 4};
-    SDL_Rect          viewport;
-    SDL_Texture      *pTexture;
-    
-    if (g_bRenderPaused)
-    {
-        return;
-    }
-    
-    SDL_RenderGetViewport(gpRenderer, &viewport);
-
-    time = SDL_GetTicks();
-    
-    wSpeed++;
-    wSpeed *= 10;
-    
-    for (i = 0; i < 12; i++)
-    {
-        for (j = 0; j < 6; j++)
-        {
-            PAL_ProcessEvent();
-            while (SDL_GetTicks() <= time)
-            {
-                PAL_ProcessEvent();
-                SDL_Delay(5);
-            }
-            time = SDL_GetTicks() + wSpeed;
-            
-            //
-            // Blend the pixels in the 2 buffers, and put the result into the
-            // backup buffer
-            //
-            for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6)
-            {
-                a = ((LPBYTE)(gpScreen->pixels))[k];
-                b = ((LPBYTE)(gpScreenBak->pixels))[k];
-                
-                if (i > 0)
-                {
-                    if ((a & 0x0F) > (b & 0x0F))
-                    {
-                        b++;
-                    }
-                    else if ((a & 0x0F) < (b & 0x0F))
-                    {
-                        b--;
-                    }
-                }
-                
-                ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F));
-            }
-            
-            //
-            // Draw the backup buffer to the screen
-            //
-            if (g_wShakeTime != 0)
-            {
-                //
-                // Shake the screen
-                //
-                SDL_Rect srcrect, dstrect;
-                
-                srcrect.x = 0;
-                srcrect.y = 0;
-                srcrect.w = 320;
-                srcrect.h = 200 - g_wShakeLevel;
-                
-                dstrect.x = 0;
-                dstrect.y = 0;
-                dstrect.w = 320 * viewport.w / gpScreen->w;
-                dstrect.h = (200 - g_wShakeLevel) * viewport.h / gpScreen->h;
-
-                if (g_wShakeTime & 1)
-                {
-                    srcrect.y = g_wShakeLevel;
-                }
-                else
-                {
-                    dstrect.y = g_wShakeLevel * viewport.h / gpScreen->h;
-                }
-                
-                pTexture = SDL_CreateTextureFromSurface(gpRenderer, gpScreenBak);
-                SDL_RenderClear(gpRenderer);
-                SDL_RenderCopy(gpRenderer, pTexture, &srcrect, &dstrect);
-                if (gpTouchOverlay)
-                {
-                    SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
-                }
-                SDL_RenderPresent(gpRenderer);
-                SDL_DestroyTexture(pTexture);
-
-                g_wShakeTime--;
-            }
-            else
-            {
-                pTexture = SDL_CreateTextureFromSurface(gpRenderer, gpScreenBak);
-                SDL_RenderCopy(gpRenderer, pTexture,  NULL, NULL);
-                if (gpTouchOverlay)
-                {
-                    SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
-                }
-                SDL_RenderPresent(gpRenderer);
-                SDL_DestroyTexture(pTexture);
-            }
-        }
-    }
-
-    //
-    // Draw the result buffer to the screen as the final step
-    //
-    VIDEO_UpdateScreen(NULL);
-
-#else
    int               i, j, k;
    DWORD             time;
    BYTE              a, b;
@@ -1223,7 +1081,17 @@ VIDEO_FadeScreen(
             dstrect.h = g_wShakeLevel * screenRealHeight / gpScreen->h;
 
             SDL_FillRect(gpScreenReal, &dstrect, 0);
-            SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
+#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);
+			}
+			SDL_RenderPresent(gpRenderer);
+#else
+			SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
+#endif
             g_wShakeTime--;
          }
          else
@@ -1234,7 +1102,17 @@ VIDEO_FadeScreen(
             dstrect.h = screenRealHeight;
 
             SDL_SoftStretch(gpScreenBak, NULL, gpScreenReal, &dstrect);
-            SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
+#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);
+			}
+			SDL_RenderPresent(gpRenderer);
+#else
+			SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
+#endif
          }
       }
    }
@@ -1248,7 +1126,6 @@ VIDEO_FadeScreen(
    // Draw the result buffer to the screen as the final step
    //
    VIDEO_UpdateScreen(NULL);
-#endif
 }
 
 #if SDL_VERSION_ATLEAST(2,0,0)