allow player 2 touchscreen controls
[drnoksnes] / gfx.cpp
diff --git a/gfx.cpp b/gfx.cpp
index 27c1b0d..79f8feb 100644 (file)
--- a/gfx.cpp
+++ b/gfx.cpp
@@ -38,6 +38,9 @@
  * Super NES and Super Nintendo Entertainment System are trademarks of
  * Nintendo Co., Limited and its subsidiary companies.
  */
+
+#include <stdarg.h>
+
 #include "snes9x.h"
 
 #include "memmap.h"
 #include "gfx.h"
 #include "apu.h"
 #include "cheats.h"
-#include <stdint.h>
-//#include "asmmemfuncs.h"
+#include "tile.h"
+#include "misc.h"
 
 #define USE_CRAZY_OPTS
 
-//misc.s
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern void memcpy16(unsigned short *dest, unsigned short *src, int count);
-extern void memcpy16bswap(unsigned short *dest, void *src, int count);
-extern void memcpy32(uint32_t *dest, uint32_t *src, int count);
-extern void memset32(uint32_t *dest, int c, int count);
-#ifdef __cplusplus
-}
-#endif
-
 #define M7 19
 #define M8 19
 
@@ -114,109 +105,6 @@ extern uint8  Mode7Depths [2];
 
 #define BLACK BUILD_PIXEL(0,0,0)
 
-void DrawTile (uint32 Tile, uint32 Offset, uint32 StartLine,
-              uint32 LineCount, struct SGFX * gfx);
-void DrawClippedTile (uint32 Tile, uint32 Offset,
-                     uint32 StartPixel, uint32 Width,
-                     uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-void DrawTilex2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                uint32 LineCount, struct SGFX * gfx);
-void DrawClippedTilex2 (uint32 Tile, uint32 Offset,
-                       uint32 StartPixel, uint32 Width,
-                       uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-void DrawTilex2x2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-              uint32 LineCount, struct SGFX * gfx);
-void DrawClippedTilex2x2 (uint32 Tile, uint32 Offset,
-                         uint32 StartPixel, uint32 Width,
-                         uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-void DrawLargePixel (uint32 Tile, uint32 Offset,
-                    uint32 StartPixel, uint32 Pixels,
-                    uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawTile16 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                uint32 LineCount, struct SGFX * gfx);
-void DrawClippedTile16 (uint32 Tile, uint32 Offset,
-                       uint32 StartPixel, uint32 Width,
-                       uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-void DrawTile16x2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                  uint32 LineCount, struct SGFX * gfx);
-void DrawClippedTile16x2 (uint32 Tile, uint32 Offset,
-                         uint32 StartPixel, uint32 Width,
-                         uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-void DrawTile16x2x2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                    uint32 LineCount, struct SGFX * gfx);
-void DrawClippedTile16x2x2 (uint32 Tile, uint32 Offset,
-                           uint32 StartPixel, uint32 Width,
-                           uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-void DrawLargePixel16 (uint32 Tile, uint32 Offset,
-                      uint32 StartPixel, uint32 Pixels,
-                      uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawTile16Add (uint32 Tile, uint32 Offset, uint32 StartLine,
-                   uint32 LineCount, struct SGFX * gfx);
-
-void DrawClippedTile16Add (uint32 Tile, uint32 Offset,
-                          uint32 StartPixel, uint32 Width,
-                          uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawTile16Add1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                      uint32 LineCount, struct SGFX * gfx);
-
-void DrawClippedTile16Add1_2 (uint32 Tile, uint32 Offset,
-                             uint32 StartPixel, uint32 Width,
-                             uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawTile16FixedAdd1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                           uint32 LineCount, struct SGFX * gfx);
-
-void DrawClippedTile16FixedAdd1_2 (uint32 Tile, uint32 Offset,
-                                  uint32 StartPixel, uint32 Width,
-                                  uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawTile16Sub (uint32 Tile, uint32 Offset, uint32 StartLine,
-                   uint32 LineCount, struct SGFX * gfx);
-
-void DrawClippedTile16Sub (uint32 Tile, uint32 Offset,
-                          uint32 StartPixel, uint32 Width,
-                          uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawTile16Sub1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                      uint32 LineCount, struct SGFX * gfx);
-
-void DrawClippedTile16Sub1_2 (uint32 Tile, uint32 Offset,
-                             uint32 StartPixel, uint32 Width,
-                             uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawTile16FixedSub1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                           uint32 LineCount, struct SGFX * gfx);
-
-void DrawClippedTile16FixedSub1_2 (uint32 Tile, uint32 Offset,
-                                  uint32 StartPixel, uint32 Width,
-                                  uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawLargePixel16Add (uint32 Tile, uint32 Offset,
-                         uint32 StartPixel, uint32 Pixels,
-                         uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawLargePixel16Add1_2 (uint32 Tile, uint32 Offset,
-                            uint32 StartPixel, uint32 Pixels,
-                            uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawLargePixel16Sub (uint32 Tile, uint32 Offset,
-                         uint32 StartPixel, uint32 Pixels,
-                         uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawLargePixel16Sub1_2 (uint32 Tile, uint32 Offset,
-                            uint32 StartPixel, uint32 Pixels,
-                            uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawHiResClippedTile16 (uint32 Tile, uint32 Offset,
-                       uint32 StartPixel, uint32 Width,
-                       uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
-void DrawHiResTile16 (uint32 Tile, uint32 Offset,
-                       uint32 StartLine, uint32 LineCount, struct SGFX * gfx);
-
 bool8_32 S9xGraphicsInit ()
 {
     register uint32 PixelOdd = 1;
@@ -317,14 +205,8 @@ bool8_32 S9xGraphicsInit ()
        PixelOdd <<= 2;
     }
 
-    GFX.RealPitch = GFX.Pitch2 = GFX.Pitch;
-    GFX.ZPitch = GFX.Pitch;
-    if (Settings.SixteenBit)
-       GFX.ZPitch >>= 1;
-    GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
-    GFX.DepthDelta = GFX.SubZBuffer - GFX.ZBuffer;
-    //GFX.InfoStringTimeout = 0;
-    //GFX.InfoString = NULL;
+    GFX.InfoStringTimeout = 0;
+    GFX.InfoString = NULL;
 
     PPU.BG_Forced = 0;
     IPPU.OBJChanged = TRUE;
@@ -551,8 +433,10 @@ void S9xBuildDirectColourMaps ()
 
 void S9xStartScreenRefresh ()
 {
-    if (GFX.InfoStringTimeout > 0 && --GFX.InfoStringTimeout == 0)
-       GFX.InfoString = NULL;
+       if (GFX.InfoStringTimeout > 0 && --GFX.InfoStringTimeout == 0) {
+               free(GFX.InfoString);
+               GFX.InfoString = NULL;
+       }
 
     if (IPPU.RenderThisFrame)
     {
@@ -573,9 +457,6 @@ void S9xStartScreenRefresh ()
        IPPU.DoubleWidthPixels = FALSE;
        GFX.Pitch2 = GFX.Pitch = GFX.RealPitch;
        GFX.PPL = GFX.PPLx2 >> 1;
-       GFX.ZPitch = GFX.RealPitch;
-       if (Settings.SixteenBit)
-                   GFX.ZPitch >>= 1;
        PPU.RecomputeClipWindows = TRUE;
        GFX.DepthDelta = GFX.SubZBuffer - GFX.ZBuffer;
        GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
@@ -715,10 +596,19 @@ void S9xEndScreenRefresh()
     }
 }
 
-void S9xSetInfoString (const char *string)
+void S9xSetInfoString (const char * fmt, ...)
 {
-    GFX.InfoString = string;
-    GFX.InfoStringTimeout = 120;
+       va_list ap;
+       va_start(ap, fmt);
+
+       if (vasprintf(&GFX.InfoString, fmt, ap) > 0) {
+               GFX.InfoStringTimeout = 120;
+       } else {
+               GFX.InfoString = 0;
+               GFX.InfoStringTimeout = 0;
+       }
+
+    va_end(ap);
 }
 
 INLINE void SelectTileRenderer (bool8_32 normal)
@@ -964,7 +854,7 @@ void DrawOBJS (bool8_32 OnMain = FALSE, uint8 D = 0)
                            if (W > Width)
                                W = Width;
                            (*DrawClippedTilePtr) (Tile, O, Offset, W,
-                                                  TileLine, LineCount, &GFX);
+                                                  TileLine, LineCount);
                            
                            if (W >= Width)
                                continue;
@@ -988,12 +878,12 @@ void DrawOBJS (bool8_32 OnMain = FALSE, uint8 D = 0)
                    for (int X = 0; X < Middle; X++, O += 8 * GFX.PixSize,
                         Tile += TileInc)
                    {
-                       (*DrawTilePtr) (Tile, O, TileLine, LineCount, &GFX);
+                       (*DrawTilePtr) (Tile, O, TileLine, LineCount);
                    }
                    if (Offset)
                    {
                        (*DrawClippedTilePtr) (Tile, O, 0, Offset,
-                                              TileLine, LineCount, &GFX);
+                                              TileLine, LineCount);
                    }
                }
            }
@@ -1141,13 +1031,13 @@ void DrawBackgroundMosaic (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                            {
                                (*DrawLargePixelPtr) (Tile + 17 - (Quot & 1), s,
                                                      HPos & 7, PixWidth,
-                                                     VirtAlign, Lines, &GFX);
+                                                     VirtAlign, Lines);
                            }
                            else
                            {
                                (*DrawLargePixelPtr) (Tile + 1 - (Quot & 1), s,
                                                      HPos & 7, PixWidth,
-                                                     VirtAlign, Lines, &GFX);
+                                                     VirtAlign, Lines);
                            }
                        }
                        else
@@ -1157,13 +1047,13 @@ void DrawBackgroundMosaic (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                            {
                                (*DrawLargePixelPtr) (Tile + 17 - (Quot & 1), s,
                                                      HPos & 7, PixWidth,
-                                                     VirtAlign, Lines, &GFX);
+                                                     VirtAlign, Lines);
                            }
                            else
                            {
                                (*DrawLargePixelPtr) (Tile + 1 - (Quot & 1), s,
                                                      HPos & 7, PixWidth,
-                                                     VirtAlign, Lines, &GFX);
+                                                     VirtAlign, Lines);
                            }
                        }
                    }
@@ -1177,13 +1067,13 @@ void DrawBackgroundMosaic (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                            {
                                (*DrawLargePixelPtr) (Tile + 16 + (Quot & 1), s,
                                                      HPos & 7, PixWidth,
-                                                     VirtAlign, Lines, &GFX);
+                                                     VirtAlign, Lines);
                            }
                            else
                            {
                                (*DrawLargePixelPtr) (Tile + (Quot & 1), s,
                                                      HPos & 7, PixWidth,
-                                                     VirtAlign, Lines, &GFX);
+                                                     VirtAlign, Lines);
                            }
                        }
                        else
@@ -1193,20 +1083,20 @@ void DrawBackgroundMosaic (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                            {
                                (*DrawLargePixelPtr) (Tile + 16 + (Quot & 1), s,
                                                      HPos & 7, PixWidth,
-                                                     VirtAlign, Lines, &GFX);
+                                                     VirtAlign, Lines);
                            }
                            else
                            {
                                (*DrawLargePixelPtr) (Tile + (Quot & 1), s,
                                                      HPos & 7, PixWidth,
-                                                     VirtAlign, Lines, &GFX);
+                                                     VirtAlign, Lines);
                            }
                        }
                    }
                }
                else
                    (*DrawLargePixelPtr) (Tile, s, HPos & 7, PixWidth,
-                                         VirtAlign, Lines, &GFX);
+                                         VirtAlign, Lines);
            }
        }
     }
@@ -1451,14 +1341,14 @@ void DrawBackgroundOffset (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                GFX.Z1 = GFX.Z2 = depths [(Tile & 0x2000) >> 13];
 
                if (BG.TileSize == 8)
-                   (*DrawClippedTilePtr) (Tile, s, Offset, Count, VirtAlign, Lines, &GFX);
+                   (*DrawClippedTilePtr) (Tile, s, Offset, Count, VirtAlign, Lines);
                else
                {
                    if (!(Tile & (V_FLIP | H_FLIP)))
                    {
                        // Normal, unflipped
                        (*DrawClippedTilePtr) (Tile + t1 + (Quot & 1),
-                                              s, Offset, Count, VirtAlign, Lines, &GFX);
+                                              s, Offset, Count, VirtAlign, Lines);
                    }
                    else
                    if (Tile & H_FLIP)
@@ -1467,20 +1357,20 @@ void DrawBackgroundOffset (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                        {
                            // H & V flip
                            (*DrawClippedTilePtr) (Tile + t2 + 1 - (Quot & 1),
-                                                  s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                  s, Offset, Count, VirtAlign, Lines);
                        }
                        else
                        {
                            // H flip only
                            (*DrawClippedTilePtr) (Tile + t1 + 1 - (Quot & 1),
-                                                  s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                  s, Offset, Count, VirtAlign, Lines);
                        }
                    }
                    else
                    {
                        // V flip only
                        (*DrawClippedTilePtr) (Tile + t2 + (Quot & 1),
-                                              s, Offset, Count, VirtAlign, Lines, &GFX);
+                                              s, Offset, Count, VirtAlign, Lines);
                    }
                }
 
@@ -1626,7 +1516,8 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                Count = 8 - Offset;
                if (Count > Width)
                    Count = Width;
-               s -= (Offset>>1);
+               if (s) // XXX: Workaround for underflow (Secret of MANA)
+                       s -= (Offset>>1);
                Tile = READ_2BYTES (t);
                GFX.Z1 = GFX.Z2 = depths [(Tile & 0x2000) >> 13];
 
@@ -1636,13 +1527,13 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                    {
                        // Normal, unflipped
                        (*DrawHiResClippedTilePtr) (Tile + (Quot & 1),
-                                                   s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                   s, Offset, Count, VirtAlign, Lines);
                    }
                    else
                    {
                        // H flip
                        (*DrawHiResClippedTilePtr) (Tile + 1 - (Quot & 1),
-                                                   s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                   s, Offset, Count, VirtAlign, Lines);
                    }
                }
                else
@@ -1651,7 +1542,7 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                    {
                        // Normal, unflipped
                        (*DrawHiResClippedTilePtr) (Tile + t1 + (Quot & 1),
-                                                   s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                   s, Offset, Count, VirtAlign, Lines);
                    }
                    else
                    if (Tile & H_FLIP)
@@ -1660,20 +1551,20 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                        {
                            // H & V flip
                            (*DrawHiResClippedTilePtr) (Tile + t2 + 1 - (Quot & 1),
-                                                       s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                       s, Offset, Count, VirtAlign, Lines);
                        }
                        else
                        {
                            // H flip only
                            (*DrawHiResClippedTilePtr) (Tile + t1 + 1 - (Quot & 1),
-                                                       s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                       s, Offset, Count, VirtAlign, Lines);
                        }
                    }
                    else
                    {
                        // V flip only
                        (*DrawHiResClippedTilePtr) (Tile + t2 + (Quot & 1),
-                                                   s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                   s, Offset, Count, VirtAlign, Lines);
                    }
                }
 
@@ -1700,13 +1591,13 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                    {
                        // Normal, unflipped
                        (*DrawHiResTilePtr) (Tile + (Quot & 1),
-                                            s, VirtAlign, Lines, &GFX);
+                                            s, VirtAlign, Lines);
                    }
                    else
                    {
                        // H flip
                        (*DrawHiResTilePtr) (Tile + 1 - (Quot & 1),
-                                           s, VirtAlign, Lines, &GFX);
+                                           s, VirtAlign, Lines);
                    }
                }
                else
@@ -1715,7 +1606,7 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                    {
                        // Normal, unflipped
                        (*DrawHiResTilePtr) (Tile + t1 + (Quot & 1),
-                                            s, VirtAlign, Lines, &GFX);
+                                            s, VirtAlign, Lines);
                    }
                    else
                    if (Tile & H_FLIP)
@@ -1724,20 +1615,20 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                        {
                            // H & V flip
                            (*DrawHiResTilePtr) (Tile + t2 + 1 - (Quot & 1),
-                                                s, VirtAlign, Lines, &GFX);
+                                                s, VirtAlign, Lines);
                        }
                        else
                        {
                            // H flip only
                            (*DrawHiResTilePtr) (Tile + t1 + 1 - (Quot & 1),
-                                                s, VirtAlign, Lines, &GFX);
+                                                s, VirtAlign, Lines);
                        }
                    }
                    else
                    {
                        // V flip only
                        (*DrawHiResTilePtr) (Tile + t2 + (Quot & 1),
-                                            s, VirtAlign, Lines, &GFX);
+                                            s, VirtAlign, Lines);
                    }
                }
 
@@ -1760,13 +1651,13 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                    {
                        // Normal, unflipped
                        (*DrawHiResClippedTilePtr) (Tile + (Quot & 1),
-                                                   s, 0, Count, VirtAlign, Lines, &GFX);
+                                                   s, 0, Count, VirtAlign, Lines);
                    }
                    else
                    {
                        // H flip
                        (*DrawHiResClippedTilePtr) (Tile + 1 - (Quot & 1),
-                                                   s, 0, Count, VirtAlign, Lines, &GFX);
+                                                   s, 0, Count, VirtAlign, Lines);
                    }
                }
                else
@@ -1775,7 +1666,7 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                    {
                        // Normal, unflipped
                        (*DrawHiResClippedTilePtr) (Tile + t1 + (Quot & 1),
-                                                   s, 0, Count, VirtAlign, Lines, &GFX);
+                                                   s, 0, Count, VirtAlign, Lines);
                    }
                    else
                    if (Tile & H_FLIP)
@@ -1784,20 +1675,20 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                        {
                            // H & V flip
                            (*DrawHiResClippedTilePtr) (Tile + t2 + 1 - (Quot & 1),
-                                                       s, 0, Count, VirtAlign, Lines, &GFX);
+                                                       s, 0, Count, VirtAlign, Lines);
                        }
                        else
                        {
                            // H flip only
                            (*DrawHiResClippedTilePtr) (Tile + t1 + 1 - (Quot & 1),
-                                                       s, 0, Count, VirtAlign, Lines, &GFX);
+                                                       s, 0, Count, VirtAlign, Lines);
                        }
                    }
                    else
                    {
                        // V flip only
                        (*DrawHiResClippedTilePtr) (Tile + t2 + (Quot & 1),
-                                                   s, 0, Count, VirtAlign, Lines, &GFX);
+                                                   s, 0, Count, VirtAlign, Lines);
                    }
                }
            }
@@ -1992,7 +1883,7 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                        if (BG.TileSize == 8)
                        {
                            (*DrawClippedTilePtr) (Tile, s, Offset, Count, VirtAlign,
-                                                  Lines, &GFX);
+                                                  Lines);
                        }
                        else
                        {
@@ -2000,7 +1891,7 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                            {
                                        // Normal, unflipped
                                        (*DrawClippedTilePtr) (Tile + t1 + (Quot & 1),
-                                                      s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                      s, Offset, Count, VirtAlign, Lines);
                            }
                            else
                            if (Tile & H_FLIP)
@@ -2009,20 +1900,20 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                                {
                                    // H & V flip
                                    (*DrawClippedTilePtr) (Tile + t2 + 1 - (Quot & 1),
-                                                          s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                          s, Offset, Count, VirtAlign, Lines);
                                }
                                else
                                {
                                    // H flip only
                                    (*DrawClippedTilePtr) (Tile + t1 + 1 - (Quot & 1),
-                                                          s, Offset, Count, VirtAlign, Lines, &GFX);
+                                                          s, Offset, Count, VirtAlign, Lines);
                                }
                            }
                            else
                            {
                                // V flip only
                                (*DrawClippedTilePtr) (Tile + t2 + (Quot & 1), s, 
-                                                      Offset, Count, VirtAlign, Lines, &GFX);
+                                                      Offset, Count, VirtAlign, Lines);
                            }
                        }
 
@@ -2064,13 +1955,13 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                                {
                                    // Both horzontal & vertical flip
                                    (*DrawTilePtr) (Tile + t2 + 1 - (Quot & 1), s, 
-                                                   VirtAlign, Lines, &GFX);
+                                                   VirtAlign, Lines);
                                }
                                else
                                {
                                    // Horizontal flip only
                                    (*DrawTilePtr) (Tile + t1 + 1 - (Quot & 1), s, 
-                                                   VirtAlign, Lines, &GFX);
+                                                   VirtAlign, Lines);
                                }
                            }
                            else
@@ -2080,19 +1971,19 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                                {
                                    // Vertical flip only
                                    (*DrawTilePtr) (Tile + t2 + (Quot & 1), s,
-                                                   VirtAlign, Lines, &GFX);
+                                                   VirtAlign, Lines);
                                }
                                else
                                {
                                    // Normal unflipped
                                    (*DrawTilePtr) (Tile + t1 + (Quot & 1), s,
-                                                   VirtAlign, Lines, &GFX);
+                                                   VirtAlign, Lines);
                                }
                            }
                        }
                        else
                        {
-                           (*DrawTilePtr) (Tile, s, VirtAlign, Lines, &GFX);
+                           (*DrawTilePtr) (Tile, s, VirtAlign, Lines);
                        }
 
                        if (BG.TileSize == 8)
@@ -2122,14 +2013,14 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
 
                        if (BG.TileSize == 8)
                            (*DrawClippedTilePtr) (Tile, s, 0, Count, VirtAlign, 
-                                                  Lines, &GFX);
+                                                  Lines);
                        else
                        {
                            if (!(Tile & (V_FLIP | H_FLIP)))
                            {
                                // Normal, unflipped
                                (*DrawClippedTilePtr) (Tile + t1 + (Quot & 1), s, 0, 
-                                                      Count, VirtAlign, Lines, &GFX);
+                                                      Count, VirtAlign, Lines);
                            }
                            else
                            if (Tile & H_FLIP)
@@ -2139,14 +2030,14 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                                    // H & V flip
                                    (*DrawClippedTilePtr) (Tile + t2 + 1 - (Quot & 1),
                                                           s, 0, Count, VirtAlign, 
-                                                          Lines, &GFX);
+                                                          Lines);
                                }
                                else
                                {
                                    // H flip only
                                    (*DrawClippedTilePtr) (Tile + t1 + 1 - (Quot & 1),
                                                           s, 0, Count, VirtAlign,
-                                                          Lines, &GFX);
+                                                          Lines);
                                }
                            }
                            else
@@ -2154,7 +2045,7 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                                // V flip only
                                (*DrawClippedTilePtr) (Tile + t2 + (Quot & 1),
                                                       s, 0, Count, VirtAlign, 
-                                                      Lines, &GFX);
+                                                      Lines);
                            }
                        }
                    }
@@ -3218,10 +3109,6 @@ void S9xUpdateScreen () // ~30-50ms! (called from FLUSH_REDRAW())
                                                for (register int x = 255; x >= 0; x--, p--, q -= 2)
                                                        *q = *(q + 1) = *p;
                                    }
-                                   GFX.Pitch = GFX.Pitch2 = GFX.RealPitch;
-                                   GFX.PPL = GFX.Pitch >> 1;
-                                   GFX.PPLx2 = GFX.Pitch;
-                                   GFX.ZPitch = GFX.PPL;
                                }
                                else
 #endif
@@ -3899,18 +3786,19 @@ else \
 
 // Define an inline function to handle which BGs are being displayed
 #define DISPLAY(n) \
-(!(PPU.BG_Forced & n) && \
-(GFX.r212c & n) || \
-((GFX.r212d & n) && subadd))
+       ( \
+               (!(PPU.BG_Forced & n) && (GFX.r212c & n)) || \
+               (((GFX.r212d & n) && subadd)) \
+       )
 
                    uint8 subadd = GFX.r2131 & 0x3f;
 
                        // go through all BGS are check if they need to be displayed
-                   bool8_32 BG0 = DISPLAY(1) && !(Settings.os9x_hack & GFX_IGNORE_BG0);
-                   bool8_32 BG1 = DISPLAY(2) && !(Settings.os9x_hack & GFX_IGNORE_BG1);
-                   bool8_32 BG2 = DISPLAY(4) && !(Settings.os9x_hack & GFX_IGNORE_BG2);
-                   bool8_32 BG3 = DISPLAY(8) && !(Settings.os9x_hack & GFX_IGNORE_BG3);
-                   bool8_32 OB  = DISPLAY(16) && !(Settings.os9x_hack & GFX_IGNORE_OBJ);
+                   bool BG0 = DISPLAY(1) && !(Settings.os9x_hack & GFX_IGNORE_BG0);
+                   bool BG1 = DISPLAY(2) && !(Settings.os9x_hack & GFX_IGNORE_BG1);
+                   bool BG2 = DISPLAY(4) && !(Settings.os9x_hack & GFX_IGNORE_BG2);
+                   bool BG3 = DISPLAY(8) && !(Settings.os9x_hack & GFX_IGNORE_BG3);
+                   bool OB  = DISPLAY(16) && !(Settings.os9x_hack & GFX_IGNORE_OBJ);
 
                    if (PPU.BGMode <= 1)
                    {
@@ -4116,4 +4004,6 @@ bool8_32 S9xSetRenderPixelFormat (int format)
     }
     return (FALSE);
 }
+
 #endif
+