From 3ac47313e2ad610049c0841e06a4e169782beeab Mon Sep 17 00:00:00 2001
From: FunkyFr3sh <cc.red.alert.1@googlemail.com>
Date: Fri, 9 Sep 2022 11:25:15 +0200
Subject: [PATCH] don't use min macro

---
 src/config.c      |  4 ++--
 src/ddsurface.c   | 19 ++++++++++---------
 src/render_d3d9.c |  4 ++--
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/config.c b/src/config.c
index 8a40c21..ea6f50a 100644
--- a/src/config.c
+++ b/src/config.c
@@ -36,7 +36,7 @@ void cfg_load()
     g_ddraw->accurate_timers = cfg_get_bool("accuratetimers", FALSE);
     g_ddraw->resizable = cfg_get_bool("resizable", TRUE);
     g_ddraw->nonexclusive = cfg_get_bool("nonexclusive", FALSE);
-    g_ddraw->fixpitch = cfg_get_bool("fixpitch", FALSE);
+    g_ddraw->fixpitch = cfg_get_bool("fixpitch", TRUE);
     g_ddraw->fixchilds = cfg_get_int("fixchilds", FIX_CHILDS_DETECT_PAINT);
     g_ddraw->fixwndprochook = cfg_get_bool("fixwndprochook", FALSE);
     g_ddraw->novidmem = cfg_get_bool("novidmem", FALSE);
@@ -332,7 +332,7 @@ static void cfg_create_ini()
             "\n"
             "; Fixes issues where the pitch of a surface is not a multiple of 4\n"
             "; Note: Enable this if some parts of the screen are being displayed diagonally\n"
-            "fixpitch=false\n"
+            "fixpitch=true\n"
             "\n"
             "; Force CPU0 affinity, avoids crashes/freezing, *might* have a performance impact\n"
             "singlecpu=true\n"
diff --git a/src/ddsurface.c b/src/ddsurface.c
index 9eb784b..7e867eb 100644
--- a/src/ddsurface.c
+++ b/src/ddsurface.c
@@ -1030,16 +1030,17 @@ HRESULT dd_CreateSurface(
 
     if (dst_surface->width && dst_surface->height)
     {
-        if (dst_surface->width == 71 && dst_surface->height == 24) dst_surface->width = 72; //Commandos
+        DWORD bmp_width = dst_surface->width;
+        DWORD bmp_height = dst_surface->height;
 
         dst_surface->lx_pitch = dst_surface->bpp / 8;
-        dst_surface->l_pitch = dst_surface->width * dst_surface->lx_pitch;
+        dst_surface->l_pitch = bmp_width * dst_surface->lx_pitch;
 
-        if (g_ddraw->fixpitch && !(dst_surface->caps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER)))
+        if (g_ddraw->fixpitch)
         {
             while (dst_surface->l_pitch % 4)
             {
-                dst_surface->l_pitch = ++dst_surface->width * dst_surface->lx_pitch;
+                dst_surface->l_pitch = ++bmp_width * dst_surface->lx_pitch;
             }
         }
 
@@ -1047,8 +1048,8 @@ HRESULT dd_CreateSurface(
             HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
 
         dst_surface->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-        dst_surface->bmi->bmiHeader.biWidth = dst_surface->width;
-        dst_surface->bmi->bmiHeader.biHeight = -((int)dst_surface->height + 200);
+        dst_surface->bmi->bmiHeader.biWidth = bmp_width;
+        dst_surface->bmi->bmiHeader.biHeight = -((int)bmp_height + 200);
         dst_surface->bmi->bmiHeader.biPlanes = 1;
         dst_surface->bmi->bmiHeader.biBitCount = dst_surface->bpp;
         dst_surface->bmi->bmiHeader.biCompression = dst_surface->bpp == 8 ? BI_RGB : BI_BITFIELDS;
@@ -1061,7 +1062,7 @@ HRESULT dd_CreateSurface(
         }
 
         dst_surface->bmi->bmiHeader.biSizeImage =
-            ((dst_surface->width * clr_bits + 31) & ~31) / 8 * dst_surface->height;
+            ((bmp_width * clr_bits + 31) & ~31) / 8 * bmp_height;
 
         if (dst_surface->bpp == 8)
         {
@@ -1090,7 +1091,7 @@ HRESULT dd_CreateSurface(
         dst_surface->bitmap =
             CreateDIBSection(dst_surface->hdc, dst_surface->bmi, DIB_RGB_COLORS, (void**)&dst_surface->surface, NULL, 0);
 
-        dst_surface->bmi->bmiHeader.biHeight = -((int)dst_surface->height);
+        dst_surface->bmi->bmiHeader.biHeight = -((int)bmp_height);
 
         if (!dst_surface->bitmap)
         {
@@ -1098,7 +1099,7 @@ HRESULT dd_CreateSurface(
                 HeapAlloc(
                     GetProcessHeap(),
                     HEAP_ZERO_MEMORY,
-                    dst_surface->l_pitch * (dst_surface->height + 200) * dst_surface->lx_pitch);
+                    dst_surface->l_pitch * (bmp_height + 200) * dst_surface->lx_pitch);
         }
 
         if (dst_surface->caps & DDSCAPS_PRIMARYSURFACE)
diff --git a/src/render_d3d9.c b/src/render_d3d9.c
index 5915280..8e2b07a 100644
--- a/src/render_d3d9.c
+++ b/src/render_d3d9.c
@@ -393,8 +393,8 @@ DWORD WINAPI d3d9_render_main(void)
                         lock_rc.pBits,
                         0,
                         0,
-                        min(g_ddraw->width, g_ddraw->primary->width),
-                        min(g_ddraw->height, g_ddraw->primary->height),
+                        g_ddraw->primary->width,
+                        g_ddraw->primary->height,
                         lock_rc.Pitch,
                         g_ddraw->primary->surface,
                         0,