minor code trimming and reformatting
[drnoksnes] / tile.cpp
index 22bd06b..5597a14 100644 (file)
--- a/tile.cpp
+++ b/tile.cpp
 #include "gfx.h"
 #include "tile.h"
 
-#ifdef USE_GLIDE
-#include "3d.h"
-#endif
+#define TILE_PREAMBLE \
+    uint8 *pCache; \
+\
+    uint32 TileAddr = BG.TileAddress + ((Tile & 0x3ff) << BG.TileShift); \
+    if ((Tile & 0x1ff) >= 256) \
+       TileAddr += BG.NameSelect; \
+\
+    TileAddr &= 0xffff; \
+\
+    uint32 TileNumber; \
+    pCache = &BG.Buffer[(TileNumber = (TileAddr >> BG.TileShift)) << 6]; \
+\
+    if (!BG.Buffered [TileNumber]) \
+       BG.Buffered[TileNumber] = ConvertTile (pCache, TileAddr); \
+\
+    if (BG.Buffered [TileNumber] == BLANK_TILE) \
+       return; \
+\
+    register uint32 l; \
+    if (BG.DirectColourMode) \
+    { \
+       if (IPPU.DirectColourMapsNeedRebuild) \
+            S9xBuildDirectColourMaps (); \
+        GFX.ScreenColors = DirectColourMaps [(Tile >> 10) & BG.PaletteMask]; \
+    } \
+    else \
+       GFX.ScreenColors = &IPPU.ScreenColors [(((Tile >> 10) & BG.PaletteMask) << BG.PaletteShift) + BG.StartPalette];
+
+#define RENDER_TILE(NORMAL, FLIPPED, N) \
+    if (!(Tile & (V_FLIP | H_FLIP))) \
+    { \
+       bp = pCache + StartLine; \
+       for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
+       { \
+           if (*(uint32 *) bp) \
+               NORMAL (Offset, bp); \
+           if (*(uint32 *) (bp + 4)) \
+               NORMAL (Offset + N, bp + 4); \
+       } \
+    } \
+    else \
+    if (!(Tile & V_FLIP)) \
+    { \
+       bp = pCache + StartLine; \
+       for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
+       { \
+           if (*(uint32 *) (bp + 4)) \
+               FLIPPED (Offset, bp + 4); \
+           if (*(uint32 *) bp) \
+               FLIPPED (Offset + N, bp); \
+       } \
+    } \
+    else \
+    if (Tile & H_FLIP) \
+    { \
+       bp = pCache + 56 - StartLine; \
+       for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
+       { \
+           if (*(uint32 *) (bp + 4)) \
+               FLIPPED (Offset, bp + 4); \
+           if (*(uint32 *) bp) \
+               FLIPPED (Offset + N, bp); \
+       } \
+    } \
+    else \
+    { \
+       bp = pCache + 56 - StartLine; \
+       for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
+       { \
+           if (*(uint32 *) bp) \
+               NORMAL (Offset, bp); \
+           if (*(uint32 *) (bp + 4)) \
+               NORMAL (Offset + N, bp + 4); \
+       } \
+    }
+
+#define TILE_CLIP_PREAMBLE \
+    uint32 dd; \
+    uint32 d1; \
+    uint32 d2; \
+\
+    if (StartPixel < 4) \
+    { \
+       d1 = HeadMask [StartPixel]; \
+       if (StartPixel + Width < 4) \
+           d1 &= TailMask [StartPixel + Width]; \
+    } \
+    else \
+       d1 = 0; \
+\
+    if (StartPixel + Width > 4) \
+    { \
+       if (StartPixel > 4) \
+           d2 = HeadMask [StartPixel - 4]; \
+       else \
+           d2 = 0xffffffff; \
+\
+       d2 &= TailMask [(StartPixel + Width - 4)]; \
+    } \
+    else \
+       d2 = 0;
+
+
+#define RENDER_CLIPPED_TILE(NORMAL, FLIPPED, N) \
+    if (!(Tile & (V_FLIP | H_FLIP))) \
+    { \
+       bp = pCache + StartLine; \
+       for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
+       { \
+           if ((dd = (*(uint32 *) bp) & d1)) \
+               NORMAL (Offset, (uint8 *) &dd); \
+           if ((dd = (*(uint32 *) (bp + 4)) & d2)) \
+               NORMAL (Offset + N, (uint8 *) &dd); \
+       } \
+    } \
+    else \
+    if (!(Tile & V_FLIP)) \
+    { \
+       bp = pCache + StartLine; \
+       SWAP_DWORD (d1); \
+       SWAP_DWORD (d2); \
+       for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
+       { \
+           if ((dd = *(uint32 *) (bp + 4) & d1)) \
+               FLIPPED (Offset, (uint8 *) &dd); \
+           if ((dd = *(uint32 *) bp & d2)) \
+               FLIPPED (Offset + N, (uint8 *) &dd); \
+       } \
+    } \
+    else \
+    if (Tile & H_FLIP) \
+    { \
+       bp = pCache + 56 - StartLine; \
+       SWAP_DWORD (d1); \
+       SWAP_DWORD (d2); \
+       for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
+       { \
+           if ((dd = *(uint32 *) (bp + 4) & d1)) \
+               FLIPPED (Offset, (uint8 *) &dd); \
+           if ((dd = *(uint32 *) bp & d2)) \
+               FLIPPED (Offset + N, (uint8 *) &dd); \
+       } \
+    } \
+    else \
+    { \
+       bp = pCache + 56 - StartLine; \
+       for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
+       { \
+           if ((dd = (*(uint32 *) bp) & d1)) \
+               NORMAL (Offset, (uint8 *) &dd); \
+           if ((dd = (*(uint32 *) (bp + 4)) & d2)) \
+               NORMAL (Offset + N, (uint8 *) &dd); \
+       } \
+    }
+
+#define RENDER_TILE_LARGE(PIXEL, FUNCTION) \
+    if (!(Tile & (V_FLIP | H_FLIP))) \
+    { \
+       if ((pixel = *(pCache + StartLine + StartPixel))) \
+       { \
+           pixel = PIXEL; \
+           for (l = LineCount; l != 0; l--, sp += GFX.PPL, Depth += GFX.PPL) \
+           { \
+               for (int z = Pixels - 1; z >= 0; z--) \
+                   if (GFX.Z1 > Depth [z]) \
+                   { \
+                       sp [z] = FUNCTION(sp + z, pixel); \
+                       Depth [z] = GFX.Z2; \
+                   }\
+           } \
+       } \
+    } \
+    else \
+    if (!(Tile & V_FLIP)) \
+    { \
+       StartPixel = 7 - StartPixel; \
+       if ((pixel = *(pCache + StartLine + StartPixel))) \
+       { \
+           pixel = PIXEL; \
+           for (l = LineCount; l != 0; l--, sp += GFX.PPL, Depth += GFX.PPL) \
+           { \
+               for (int z = Pixels - 1; z >= 0; z--) \
+                   if (GFX.Z1 > Depth [z]) \
+                   { \
+                       sp [z] = FUNCTION(sp + z, pixel); \
+                       Depth [z] = GFX.Z2; \
+                   }\
+           } \
+       } \
+    } \
+    else \
+    if (Tile & H_FLIP) \
+    { \
+       StartPixel = 7 - StartPixel; \
+       if ((pixel = *(pCache + 56 - StartLine + StartPixel))) \
+       { \
+           pixel = PIXEL; \
+           for (l = LineCount; l != 0; l--, sp += GFX.PPL, Depth += GFX.PPL) \
+           { \
+               for (int z = Pixels - 1; z >= 0; z--) \
+                   if (GFX.Z1 > Depth [z]) \
+                   { \
+                       sp [z] = FUNCTION(sp + z, pixel); \
+                       Depth [z] = GFX.Z2; \
+                   }\
+           } \
+       } \
+    } \
+    else \
+    { \
+       if ((pixel = *(pCache + 56 - StartLine + StartPixel))) \
+       { \
+           pixel = PIXEL; \
+           for (l = LineCount; l != 0; l--, sp += GFX.PPL, Depth += GFX.PPL) \
+           { \
+               for (int z = Pixels - 1; z >= 0; z--) \
+                   if (GFX.Z1 > Depth [z]) \
+                   { \
+                       sp [z] = FUNCTION(sp + z, pixel); \
+                       Depth [z] = GFX.Z2; \
+                   }\
+           } \
+       } \
+    }
+       
+#define RENDER_TILEHI(NORMAL, FLIPPED, N) \
+    if (!(Tile & (V_FLIP | H_FLIP))) \
+    { \
+       bp = pCache + StartLine; \
+       for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
+       { \
+           /*if (*(uint32 *) bp)*/if (((uint32)bp[0])|((uint32)bp[2])|((uint32)bp[4])|((uint32)bp[6])) \
+               NORMAL (Offset, bp); \
+       } \
+    } \
+    else \
+    if (!(Tile & V_FLIP)) \
+    { \
+       bp = pCache + StartLine; \
+       for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
+       { \
+           /*if (*(uint32 *) (bp + 4))*/if (((uint32)bp[0])|((uint32)bp[2])|((uint32)bp[4])|((uint32)bp[6])) \
+               FLIPPED (Offset, bp); \
+       } \
+    } \
+    else \
+    if (Tile & H_FLIP) \
+    { \
+       bp = pCache + 56 - StartLine; \
+       for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
+       { \
+           /*if (*(uint32 *) (bp + 4))*/if (((uint32)bp[0])|((uint32)bp[2])|((uint32)bp[4])|((uint32)bp[6]))  \
+               FLIPPED (Offset, bp); \
+       } \
+    } \
+    else \
+    { \
+       bp = pCache + 56 - StartLine; \
+       for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
+       { \
+           /*if (*(uint32 *) bp)*/if (((uint32)bp[0])|((uint32)bp[2])|((uint32)bp[4])|((uint32)bp[6])) \
+               NORMAL (Offset, bp); \
+       } \
+    }
+    
+    
+    
+#define RENDER_CLIPPED_TILEHI(NORMAL, FLIPPED, N) \
+       d1=(d1&0xFF)|((d1&0xFF0000)>>8)|((d2&0xFF)<<16)|((d2&0xFF0000)<<8);\
+    if (!(Tile & (V_FLIP | H_FLIP))) \
+    { \
+       bp = pCache + StartLine; \
+       for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
+       { \
+           /*if ((dd = (*(uint32 *) bp) & d1))*/if ((dd = (((((uint32)bp[6])<<24)|(((uint32)bp[4])<<16)|(((uint32)bp[2])<<8)|((uint32)bp[0]))&d1))) \
+               NORMAL (Offset, (uint8 *) &dd); \
+       } \
+    } \
+    else \
+    if (!(Tile & V_FLIP)) \
+    { \
+       bp = pCache + StartLine; \
+       SWAP_DWORD (d1); \
+       /*SWAP_DWORD (d2);*/ \
+       for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
+       { \
+           /*if ((dd = *(uint32 *) (bp + 4) & d1))*/if ((dd = (((((uint32)bp[6])<<24)|(((uint32)bp[4])<<16)|(((uint32)bp[2])<<8)|((uint32)bp[0]))&d1))) \
+               FLIPPED (Offset, (uint8 *) &dd); \
+       } \
+    } \
+    else \
+    if (Tile & H_FLIP) \
+    { \
+       bp = pCache + 56 - StartLine; \
+       SWAP_DWORD (d1); \
+       /*SWAP_DWORD (d2);*/ \
+       for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
+       { \
+           /*if ((dd = *(uint32 *) (bp + 4) & d1))*/if ((dd = (((((uint32)bp[6])<<24)|(((uint32)bp[4])<<16)|(((uint32)bp[2])<<8)|((uint32)bp[0]))&d1))) \
+               FLIPPED (Offset, (uint8 *) &dd); \
+       } \
+    } \
+    else \
+    { \
+       bp = pCache + 56 - StartLine; \
+       for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
+       { \
+           /*if ((dd = (*(uint32 *) bp) & d1))*/ if ((dd = (((((uint32)bp[6])<<24)|(((uint32)bp[4])<<16)|(((uint32)bp[2])<<8)|((uint32)bp[0]))&d1))) \
+               NORMAL (Offset, (uint8 *) &dd); \
+       } \
+    }
 
 extern uint32 HeadMask [4];
 extern uint32 TailMask [5];
@@ -168,17 +476,17 @@ uint8 ConvertTile (uint8 *pCache, uint32 TileAddr)
     return (non_zero ? TRUE : BLANK_TILE);
 }
 
-INLINE void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+INLINE void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels)
 {
     register uint8 Pixel;
-    uint8 *Screen = gfx->S + Offset;
-    uint8 *Depth = gfx->DB + Offset;
+    uint8 *Screen = GFX.S + Offset;
+    uint8 *Depth = GFX.DB + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N])) \
     { \
-       Screen [N] = (uint8) gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+       Screen [N] = (uint8) GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -188,17 +496,17 @@ INLINE void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS_FLIPPED (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+INLINE void WRITE_4PIXELS_FLIPPED (uint32 Offset, uint8 *Pixels)
 {
     register uint8 Pixel;
-    uint8 *Screen = gfx->S + Offset;
-    uint8 *Depth = gfx->DB + Offset;
+    uint8 *Screen = GFX.S + Offset;
+    uint8 *Depth = GFX.DB + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
     { \
-       Screen [N] = (uint8) gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+       Screen [N] = (uint8) GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -248,92 +556,7 @@ inline void WRITE_4PIXELSHI16_FLIPPED (uint32 Offset, uint8 *Pixels)
 #undef FN
 }
 
-INLINE void WRITE_4PIXELSx2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
-{
-    register uint8 Pixel;
-    uint8 *Screen = gfx->S + Offset;
-    uint8 *Depth = gfx->DB + Offset;
-
-#define FN(N) \
-    if (gfx->Z1 > Depth [0] && (Pixel = Pixels[N])) \
-    { \
-       Screen [N * 2] = Screen [N * 2 + 1] = (uint8) gfx->ScreenColors [Pixel]; \
-       Depth [N * 2] = Depth [N * 2 + 1] = gfx->Z2; \
-    }
-
-    FN(0)
-    FN(1)
-    FN(2)
-    FN(3)
-#undef FN
-}
-
-INLINE void WRITE_4PIXELS_FLIPPEDx2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
-{
-    register uint8 Pixel;
-    uint8 *Screen = gfx->S + Offset;
-    uint8 *Depth = gfx->DB + Offset;
-
-#define FN(N) \
-    if (gfx->Z1 > Depth [N * 2] && (Pixel = Pixels[3 - N])) \
-    { \
-       Screen [N * 2] = Screen [N * 2 + 1] = (uint8) gfx->ScreenColors [Pixel]; \
-       Depth [N * 2] = Depth [N * 2 + 1] = gfx->Z2; \
-    }
-
-    FN(0)
-    FN(1)
-    FN(2)
-    FN(3)
-#undef FN
-}
-
-INLINE void WRITE_4PIXELSx2x2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
-{
-    register uint8 Pixel;
-    uint8 *Screen = gfx->S + Offset;
-    uint8 *Depth = gfx->DB + Offset;
-
-#define FN(N) \
-    if (gfx->Z1 > Depth [N * 2] && (Pixel = Pixels[N])) \
-    { \
-       Screen [N * 2] = Screen [N * 2 + 1] = Screen [gfx->RealPitch + N * 2] =  \
-           Screen [gfx->RealPitch + N * 2 + 1] = (uint8) gfx->ScreenColors [Pixel]; \
-       Depth [N * 2] = Depth [N * 2 + 1] = Depth [gfx->RealPitch + N * 2] = \
-           Depth [gfx->RealPitch + N * 2 + 1] = gfx->Z2; \
-    }
-
-    FN(0)
-    FN(1)
-    FN(2)
-    FN(3)
-#undef FN
-}
-
-INLINE void WRITE_4PIXELS_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
-{
-    register uint8 Pixel;
-    uint8 *Screen = gfx->S + Offset;
-    uint8 *Depth = gfx->DB + Offset;
-
-#define FN(N) \
-    if (gfx->Z1 > Depth [N * 2] && (Pixel = Pixels[3 - N])) \
-    { \
-       Screen [N * 2] = Screen [N * 2 + 1] = Screen [gfx->RealPitch + N * 2] =  \
-           Screen [gfx->RealPitch + N * 2 + 1] = (uint8) gfx->ScreenColors [Pixel]; \
-       Depth [N * 2] = Depth [N * 2 + 1] = Depth [gfx->RealPitch + N * 2] = \
-           Depth [gfx->RealPitch + N * 2 + 1] = gfx->Z2; \
-    }
-
-    FN(0)
-    FN(1)
-    FN(2)
-    FN(3)
-#undef FN
-}
-
-void DrawTile (uint32 Tile, uint32 Offset, uint32 StartLine,
-              uint32 LineCount, struct SGFX * gfx)
+void DrawTile(uint32 Tile, uint32 Offset, uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
 
@@ -342,9 +565,9 @@ void DrawTile (uint32 Tile, uint32 Offset, uint32 StartLine,
     RENDER_TILE(WRITE_4PIXELS, WRITE_4PIXELS_FLIPPED, 4)
 }
 
-void DrawClippedTile (uint32 Tile, uint32 Offset,
+void DrawClippedTile(uint32 Tile, uint32 Offset,
                      uint32 StartPixel, uint32 Width,
-                     uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                     uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -353,155 +576,31 @@ void DrawClippedTile (uint32 Tile, uint32 Offset,
     RENDER_CLIPPED_TILE(WRITE_4PIXELS, WRITE_4PIXELS_FLIPPED, 4)
 }
 
-void DrawTilex2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                uint32 LineCount, struct SGFX * gfx)
-{
-    TILE_PREAMBLE
-
-    register uint8 *bp;
-
-    RENDER_TILE(WRITE_4PIXELSx2, WRITE_4PIXELS_FLIPPEDx2, 8)
-}
-
-void DrawClippedTilex2 (uint32 Tile, uint32 Offset,
-                       uint32 StartPixel, uint32 Width,
-                       uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
-{
-    TILE_PREAMBLE
-    register uint8 *bp;
-
-    TILE_CLIP_PREAMBLE
-    RENDER_CLIPPED_TILE(WRITE_4PIXELSx2, WRITE_4PIXELS_FLIPPEDx2, 8)
-}
-
-void DrawTilex2x2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                  uint32 LineCount, struct SGFX * gfx)
-{
-    TILE_PREAMBLE
-
-    register uint8 *bp;
-
-    RENDER_TILE(WRITE_4PIXELSx2x2, WRITE_4PIXELS_FLIPPEDx2x2, 8)
-}
-
-void DrawClippedTilex2x2 (uint32 Tile, uint32 Offset,
-                         uint32 StartPixel, uint32 Width,
-                         uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
-{
-    TILE_PREAMBLE
-    register uint8 *bp;
-
-    TILE_CLIP_PREAMBLE
-    RENDER_CLIPPED_TILE(WRITE_4PIXELSx2x2, WRITE_4PIXELS_FLIPPEDx2x2, 8)
-}
-
 void DrawLargePixel (uint32 Tile, uint32 Offset,
                     uint32 StartPixel, uint32 Pixels,
-                    uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                    uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
 
-    register uint8 *sp = gfx->S + Offset;
-    uint8  *Depth = gfx->DB + Offset;
+    register uint8 *sp = GFX.S + Offset;
+    uint8  *Depth = GFX.DB + Offset;
     uint8 pixel;
 #define PLOT_PIXEL(screen, pixel) (pixel)
 
-    RENDER_TILE_LARGE (((uint8) gfx->ScreenColors [pixel]), PLOT_PIXEL)
-}
-
-INLINE void WRITE_4PIXELS16 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
-{
-    register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->DB + Offset;
-
-#define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[N])) \
-    { \
-       Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
-    }
-
-    FN(0)
-    FN(1)
-    FN(2)
-    FN(3)
-#undef FN
-}
-
-INLINE void WRITE_4PIXELS16_FLIPPED (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
-{
-    register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->DB + Offset;
-
-#define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
-    { \
-       Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
-    }
-
-    FN(0)
-    FN(1)
-    FN(2)
-    FN(3)
-#undef FN
+    RENDER_TILE_LARGE (((uint8) GFX.ScreenColors [pixel]), PLOT_PIXEL)
 }
 
-INLINE void WRITE_4PIXELS16x2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->DB + Offset;
-
-#define FN(N) \
-    if (gfx->Z1 > Depth [N * 2] && (Pixel = Pixels[N])) \
-    { \
-       Screen [N * 2] = Screen [N * 2 + 1] = gfx->ScreenColors [Pixel]; \
-       Depth [N * 2] = Depth [N * 2 + 1] = gfx->Z2; \
-    }
-
-    FN(0)
-    FN(1)
-    FN(2)
-    FN(3)
-#undef FN
-}
-
-INLINE void WRITE_4PIXELS16_FLIPPEDx2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
-{
-    register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->DB + Offset;
-
-#define FN(N) \
-    if (gfx->Z1 > Depth [N * 2] && (Pixel = Pixels[3 - N])) \
-    { \
-       Screen [N * 2] = Screen [N * 2 + 1] = gfx->ScreenColors [Pixel]; \
-       Depth [N * 2] = Depth [N * 2 + 1] = gfx->Z2; \
-    }
-
-    FN(0)
-    FN(1)
-    FN(2)
-    FN(3)
-#undef FN
-}
-
-INLINE void WRITE_4PIXELS16x2x2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
-{
-    register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->DB + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.DB + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N * 2] && (Pixel = Pixels[N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N])) \
     { \
-       Screen [N * 2] = Screen [N * 2 + 1] = Screen [(gfx->RealPitch >> 1) + N * 2] = \
-           Screen [(gfx->RealPitch >> 1) + N * 2 + 1] = gfx->ScreenColors [Pixel]; \
-       Depth [N * 2] = Depth [N * 2 + 1] = Depth [(gfx->RealPitch >> 1) + N * 2] = \
-           Depth [(gfx->RealPitch >> 1) + N * 2 + 1] = gfx->Z2; \
+       Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -511,19 +610,17 @@ INLINE void WRITE_4PIXELS16x2x2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_FLIPPED (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->DB + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.DB + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N * 2] && (Pixel = Pixels[3 - N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
     { \
-       Screen [N * 2] = Screen [N * 2 + 1] = Screen [(gfx->RealPitch >> 1) + N * 2] = \
-           Screen [(gfx->RealPitch >> 1) + N * 2 + 1] = gfx->ScreenColors [Pixel]; \
-       Depth [N * 2] = Depth [N * 2 + 1] = Depth [(gfx->RealPitch >> 1) + N * 2] = \
-           Depth [(gfx->RealPitch >> 1) + N * 2 + 1] = gfx->Z2; \
+       Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -534,7 +631,7 @@ INLINE void WRITE_4PIXELS16_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels, struct SG
 }
 
 void DrawTile16 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                uint32 LineCount, struct SGFX * gfx)
+                uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -544,7 +641,7 @@ void DrawTile16 (uint32 Tile, uint32 Offset, uint32 StartLine,
 
 void DrawClippedTile16 (uint32 Tile, uint32 Offset,
                        uint32 StartPixel, uint32 Width,
-                       uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                       uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -553,81 +650,41 @@ void DrawClippedTile16 (uint32 Tile, uint32 Offset,
     RENDER_CLIPPED_TILE(WRITE_4PIXELS16, WRITE_4PIXELS16_FLIPPED, 4)
 }
 
-void DrawTile16x2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                  uint32 LineCount, struct SGFX * gfx)
-{
-    TILE_PREAMBLE
-    register uint8 *bp;
-
-    RENDER_TILE(WRITE_4PIXELS16x2, WRITE_4PIXELS16_FLIPPEDx2, 8)
-}
-
-void DrawClippedTile16x2 (uint32 Tile, uint32 Offset,
-                         uint32 StartPixel, uint32 Width,
-                         uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
-{
-    TILE_PREAMBLE
-    register uint8 *bp;
-
-    TILE_CLIP_PREAMBLE
-    RENDER_CLIPPED_TILE(WRITE_4PIXELS16x2, WRITE_4PIXELS16_FLIPPEDx2, 8)
-}
-
-void DrawTile16x2x2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                    uint32 LineCount, struct SGFX * gfx)
-{
-    TILE_PREAMBLE
-    register uint8 *bp;
-
-    RENDER_TILE(WRITE_4PIXELS16x2x2, WRITE_4PIXELS16_FLIPPEDx2x2, 8)
-}
-
-void DrawClippedTile16x2x2 (uint32 Tile, uint32 Offset,
-                           uint32 StartPixel, uint32 Width,
-                           uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
-{
-    TILE_PREAMBLE
-    register uint8 *bp;
-
-    TILE_CLIP_PREAMBLE
-    RENDER_CLIPPED_TILE(WRITE_4PIXELS16x2x2, WRITE_4PIXELS16_FLIPPEDx2x2, 8)
-}
-
 void DrawLargePixel16 (uint32 Tile, uint32 Offset,
                       uint32 StartPixel, uint32 Pixels,
-                      uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                      uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
 
-    register uint16 *sp = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->DB + Offset;
+    register uint16 *sp = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.DB + Offset;
     uint16 pixel;
 
-    RENDER_TILE_LARGE (gfx->ScreenColors [pixel], PLOT_PIXEL)
+    RENDER_TILE_LARGE (GFX.ScreenColors [pixel], PLOT_PIXEL)
 }
 
-INLINE void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N])) \
     { \
        if (SubDepth [N]) \
        { \
            if (SubDepth [N] != 1) \
-               Screen [N] = COLOR_ADD (gfx->ScreenColors [Pixel], \
-                                       Screen [gfx->Delta + N]); \
+               Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], \
+                                       Screen [GFX.Delta + N]); \
            else \
-               Screen [N] = COLOR_ADD (gfx->ScreenColors [Pixel], \
-                                       gfx->FixedColour); \
+               Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], \
+                                       GFX.FixedColour); \
        } \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -638,28 +695,28 @@ INLINE void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels, struct SGFX * gfx
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
     { \
        if (SubDepth [N]) \
        { \
            if (SubDepth [N] != 1) \
-               Screen [N] = COLOR_ADD (gfx->ScreenColors [Pixel], \
-                                       Screen [gfx->Delta + N]); \
+               Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], \
+                                       Screen [GFX.Delta + N]); \
            else \
-               Screen [N] = COLOR_ADD (gfx->ScreenColors [Pixel], \
-                                       gfx->FixedColour); \
+               Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], \
+                                       GFX.FixedColour); \
        } \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -670,28 +727,28 @@ INLINE void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels, struct SG
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N])) \
     { \
        if (SubDepth [N]) \
        { \
            if (SubDepth [N] != 1) \
-               Screen [N] = (uint16) (COLOR_ADD1_2 (gfx->ScreenColors [Pixel], \
-                                                    Screen [gfx->Delta + N])); \
+               Screen [N] = (uint16) (COLOR_ADD1_2 (GFX.ScreenColors [Pixel], \
+                                                    Screen [GFX.Delta + N])); \
            else \
-               Screen [N] = COLOR_ADD (gfx->ScreenColors [Pixel], \
-                                       gfx->FixedColour); \
+               Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], \
+                                       GFX.FixedColour); \
        } \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -702,28 +759,28 @@ INLINE void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels, struct SGFX *
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
     { \
        if (SubDepth [N]) \
        { \
            if (SubDepth [N] != 1) \
-               Screen [N] = (uint16) (COLOR_ADD1_2 (gfx->ScreenColors [Pixel], \
-                                                    Screen [gfx->Delta + N])); \
+               Screen [N] = (uint16) (COLOR_ADD1_2 (GFX.ScreenColors [Pixel], \
+                                                    Screen [GFX.Delta + N])); \
            else \
-               Screen [N] = COLOR_ADD (gfx->ScreenColors [Pixel], \
-                                       gfx->FixedColour); \
+               Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], \
+                                       GFX.FixedColour); \
        } \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -734,28 +791,28 @@ INLINE void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels, struct
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N])) \
     { \
        if (SubDepth [N]) \
        { \
            if (SubDepth [N] != 1) \
-               Screen [N] = (uint16) COLOR_SUB (gfx->ScreenColors [Pixel], \
-                                       Screen [gfx->Delta + N]); \
+               Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], \
+                                       Screen [GFX.Delta + N]); \
            else \
-               Screen [N] = (uint16) COLOR_SUB (gfx->ScreenColors [Pixel], \
-                                       gfx->FixedColour); \
+               Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], \
+                                       GFX.FixedColour); \
        } \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -766,28 +823,28 @@ INLINE void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels, struct SGFX * gfx
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
     { \
        if (SubDepth [N]) \
        { \
            if (SubDepth [N] != 1) \
-               Screen [N] = (uint16) COLOR_SUB (gfx->ScreenColors [Pixel], \
-                                       Screen [gfx->Delta + N]); \
+               Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], \
+                                       Screen [GFX.Delta + N]); \
            else \
-               Screen [N] = (uint16) COLOR_SUB (gfx->ScreenColors [Pixel], \
-                                       gfx->FixedColour); \
+               Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], \
+                                       GFX.FixedColour); \
        } \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -798,28 +855,28 @@ INLINE void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels, struct SG
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N])) \
     { \
        if (SubDepth [N]) \
        { \
            if (SubDepth [N] != 1) \
-               Screen [N] = (uint16) COLOR_SUB1_2 (gfx->ScreenColors [Pixel], \
-                                          Screen [gfx->Delta + N]); \
+               Screen [N] = (uint16) COLOR_SUB1_2 (GFX.ScreenColors [Pixel], \
+                                          Screen [GFX.Delta + N]); \
            else \
-               Screen [N] = (uint16) COLOR_SUB (gfx->ScreenColors [Pixel], \
-                                       gfx->FixedColour); \
+               Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], \
+                                       GFX.FixedColour); \
        } \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -830,28 +887,28 @@ INLINE void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels, struct SGFX *
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
     { \
        if (SubDepth [N]) \
        { \
            if (SubDepth [N] != 1) \
-               Screen [N] = (uint16) COLOR_SUB1_2 (gfx->ScreenColors [Pixel], \
-                                          Screen [gfx->Delta + N]); \
+               Screen [N] = (uint16) COLOR_SUB1_2 (GFX.ScreenColors [Pixel], \
+                                          Screen [GFX.Delta + N]); \
            else \
-               Screen [N] = (uint16) COLOR_SUB (gfx->ScreenColors [Pixel], \
-                                       gfx->FixedColour); \
+               Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], \
+                                       GFX.FixedColour); \
        } \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -864,7 +921,7 @@ INLINE void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels, struct
 
 
 void DrawTile16Add (uint32 Tile, uint32 Offset, uint32 StartLine,
-                   uint32 LineCount, struct SGFX * gfx)
+                   uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -874,7 +931,7 @@ void DrawTile16Add (uint32 Tile, uint32 Offset, uint32 StartLine,
 
 void DrawClippedTile16Add (uint32 Tile, uint32 Offset,
                           uint32 StartPixel, uint32 Width,
-                          uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                          uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -884,7 +941,7 @@ void DrawClippedTile16Add (uint32 Tile, uint32 Offset,
 }
 
 void DrawTile16Add1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                      uint32 LineCount, struct SGFX * gfx)
+                      uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -894,7 +951,7 @@ void DrawTile16Add1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
 
 void DrawClippedTile16Add1_2 (uint32 Tile, uint32 Offset,
                              uint32 StartPixel, uint32 Width,
-                             uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                             uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -904,7 +961,7 @@ void DrawClippedTile16Add1_2 (uint32 Tile, uint32 Offset,
 }
 
 void DrawTile16Sub (uint32 Tile, uint32 Offset, uint32 StartLine,
-                   uint32 LineCount, struct SGFX * gfx)
+                   uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -914,7 +971,7 @@ void DrawTile16Sub (uint32 Tile, uint32 Offset, uint32 StartLine,
 
 void DrawClippedTile16Sub (uint32 Tile, uint32 Offset,
                           uint32 StartPixel, uint32 Width,
-                          uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                          uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -924,7 +981,7 @@ void DrawClippedTile16Sub (uint32 Tile, uint32 Offset,
 }
 
 void DrawTile16Sub1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                      uint32 LineCount, struct SGFX * gfx)
+                      uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -934,7 +991,7 @@ void DrawTile16Sub1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
 
 void DrawClippedTile16Sub1_2 (uint32 Tile, uint32 Offset,
                              uint32 StartPixel, uint32 Width,
-                             uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                             uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -943,22 +1000,22 @@ void DrawClippedTile16Sub1_2 (uint32 Tile, uint32 Offset,
     RENDER_CLIPPED_TILE(WRITE_4PIXELS16_SUB1_2, WRITE_4PIXELS16_FLIPPED_SUB1_2, 4)
 }
 
-INLINE void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N])) \
     { \
        if (SubDepth [N] == 1) \
-           Screen [N] = (uint16) (COLOR_ADD1_2 (gfx->ScreenColors [Pixel], \
-                                                gfx->FixedColour)); \
+           Screen [N] = (uint16) (COLOR_ADD1_2 (GFX.ScreenColors [Pixel], \
+                                                GFX.FixedColour)); \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel];\
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel];\
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -969,22 +1026,22 @@ INLINE void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels, struct SGFX *
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
     { \
        if (SubDepth [N] == 1) \
-           Screen [N] = (uint16) (COLOR_ADD1_2 (gfx->ScreenColors [Pixel], \
-                                                gfx->FixedColour)); \
+           Screen [N] = (uint16) (COLOR_ADD1_2 (GFX.ScreenColors [Pixel], \
+                                                GFX.FixedColour)); \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel];\
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel];\
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -995,22 +1052,22 @@ INLINE void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels, struc
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N])) \
     { \
        if (SubDepth [N] == 1) \
-           Screen [N] = (uint16) COLOR_SUB1_2 (gfx->ScreenColors [Pixel], \
-                                               gfx->FixedColour); \
+           Screen [N] = (uint16) COLOR_SUB1_2 (GFX.ScreenColors [Pixel], \
+                                               GFX.FixedColour); \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -1021,22 +1078,22 @@ INLINE void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels, struct SGFX *
 #undef FN
 }
 
-INLINE void WRITE_4PIXELS16_FLIPPED_SUBF1_2 (uint32 Offset, uint8 *Pixels, struct SGFX * gfx)
+STATIC INLINE void WRITE_4PIXELS16_FLIPPED_SUBF1_2 (uint32 Offset, uint8 *Pixels)
 {
     register uint32 Pixel;
-    uint16 *Screen = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
-    uint8  *SubDepth = gfx->SubZBuffer + Offset;
+    uint16 *Screen = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
+    uint8  *SubDepth = GFX.SubZBuffer + Offset;
 
 #define FN(N) \
-    if (gfx->Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
+    if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N])) \
     { \
        if (SubDepth [N] == 1) \
-           Screen [N] = (uint16) COLOR_SUB1_2 (gfx->ScreenColors [Pixel], \
-                                               gfx->FixedColour); \
+           Screen [N] = (uint16) COLOR_SUB1_2 (GFX.ScreenColors [Pixel], \
+                                               GFX.FixedColour); \
        else \
-           Screen [N] = gfx->ScreenColors [Pixel]; \
-       Depth [N] = gfx->Z2; \
+           Screen [N] = GFX.ScreenColors [Pixel]; \
+       Depth [N] = GFX.Z2; \
     }
 
     FN(0)
@@ -1048,7 +1105,7 @@ INLINE void WRITE_4PIXELS16_FLIPPED_SUBF1_2 (uint32 Offset, uint8 *Pixels, struc
 }
 
 void DrawTile16FixedAdd1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                           uint32 LineCount, struct SGFX * gfx)
+                           uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -1058,7 +1115,7 @@ void DrawTile16FixedAdd1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
 
 void DrawClippedTile16FixedAdd1_2 (uint32 Tile, uint32 Offset,
                                   uint32 StartPixel, uint32 Width,
-                                  uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                                  uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -1069,7 +1126,7 @@ void DrawClippedTile16FixedAdd1_2 (uint32 Tile, uint32 Offset,
 }
 
 void DrawTile16FixedSub1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                           uint32 LineCount, struct SGFX * gfx)
+                           uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -1079,7 +1136,7 @@ void DrawTile16FixedSub1_2 (uint32 Tile, uint32 Offset, uint32 StartLine,
 
 void DrawClippedTile16FixedSub1_2 (uint32 Tile, uint32 Offset,
                                   uint32 StartPixel, uint32 Width,
-                                  uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                                  uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -1091,82 +1148,82 @@ void DrawClippedTile16FixedSub1_2 (uint32 Tile, uint32 Offset,
 
 void DrawLargePixel16Add (uint32 Tile, uint32 Offset,
                          uint32 StartPixel, uint32 Pixels,
-                         uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                         uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
 
-    register uint16 *sp = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
+    register uint16 *sp = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
     register uint16 pixel;
 
 #define LARGE_ADD_PIXEL(s, p) \
-(Depth [z + gfx->DepthDelta] ? (Depth [z + gfx->DepthDelta] != 1 ? \
-                              COLOR_ADD (p, *(s + gfx->Delta))    : \
-                              COLOR_ADD (p, gfx->FixedColour)) \
+(Depth [z + GFX.DepthDelta] ? (Depth [z + GFX.DepthDelta] != 1 ? \
+                              COLOR_ADD (p, *(s + GFX.Delta))    : \
+                              COLOR_ADD (p, GFX.FixedColour)) \
                            : p)
                              
-    RENDER_TILE_LARGE (gfx->ScreenColors [pixel], LARGE_ADD_PIXEL)
+    RENDER_TILE_LARGE (GFX.ScreenColors [pixel], LARGE_ADD_PIXEL)
 }
 
 void DrawLargePixel16Add1_2 (uint32 Tile, uint32 Offset,
                             uint32 StartPixel, uint32 Pixels,
-                            uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                            uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
 
-    register uint16 *sp = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
+    register uint16 *sp = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
     register uint16 pixel;
 
 #define LARGE_ADD_PIXEL1_2(s, p) \
-((uint16) (Depth [z + gfx->DepthDelta] ? (Depth [z + gfx->DepthDelta] != 1 ? \
-                              COLOR_ADD1_2 (p, *(s + gfx->Delta))    : \
-                              COLOR_ADD (p, gfx->FixedColour)) \
+((uint16) (Depth [z + GFX.DepthDelta] ? (Depth [z + GFX.DepthDelta] != 1 ? \
+                              COLOR_ADD1_2 (p, *(s + GFX.Delta))    : \
+                              COLOR_ADD (p, GFX.FixedColour)) \
                            : p))
                              
-    RENDER_TILE_LARGE (gfx->ScreenColors [pixel], LARGE_ADD_PIXEL1_2)
+    RENDER_TILE_LARGE (GFX.ScreenColors [pixel], LARGE_ADD_PIXEL1_2)
 }
 
 void DrawLargePixel16Sub (uint32 Tile, uint32 Offset,
                          uint32 StartPixel, uint32 Pixels,
-                         uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                         uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
 
-    register uint16 *sp = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
+    register uint16 *sp = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
     register uint16 pixel;
 
 #define LARGE_SUB_PIXEL(s, p) \
-(Depth [z + gfx->DepthDelta] ? (Depth [z + gfx->DepthDelta] != 1 ? \
-                              COLOR_SUB (p, *(s + gfx->Delta))    : \
-                              COLOR_SUB (p, gfx->FixedColour)) \
+(Depth [z + GFX.DepthDelta] ? (Depth [z + GFX.DepthDelta] != 1 ? \
+                              COLOR_SUB (p, *(s + GFX.Delta))    : \
+                              COLOR_SUB (p, GFX.FixedColour)) \
                            : p)
                              
-    RENDER_TILE_LARGE (gfx->ScreenColors [pixel], LARGE_SUB_PIXEL)
+    RENDER_TILE_LARGE (GFX.ScreenColors [pixel], LARGE_SUB_PIXEL)
 }
 
 void DrawLargePixel16Sub1_2 (uint32 Tile, uint32 Offset,
                             uint32 StartPixel, uint32 Pixels,
-                            uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                            uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
 
-    register uint16 *sp = (uint16 *) gfx->S + Offset;
-    uint8  *Depth = gfx->ZBuffer + Offset;
+    register uint16 *sp = (uint16 *) GFX.S + Offset;
+    uint8  *Depth = GFX.ZBuffer + Offset;
     uint16 pixel;
 
 #define LARGE_SUB_PIXEL1_2(s, p) \
-(Depth [z + gfx->DepthDelta] ? (Depth [z + gfx->DepthDelta] != 1 ? \
-                              COLOR_SUB1_2 (p, *(s + gfx->Delta))    : \
-                              COLOR_SUB (p, gfx->FixedColour)) \
+(Depth [z + GFX.DepthDelta] ? (Depth [z + GFX.DepthDelta] != 1 ? \
+                              COLOR_SUB1_2 (p, *(s + GFX.Delta))    : \
+                              COLOR_SUB (p, GFX.FixedColour)) \
                            : p)
                              
-    RENDER_TILE_LARGE (gfx->ScreenColors [pixel], LARGE_SUB_PIXEL1_2)
+    RENDER_TILE_LARGE (GFX.ScreenColors [pixel], LARGE_SUB_PIXEL1_2)
 }
 
 void DrawHiResTile16 (uint32 Tile, uint32 Offset, uint32 StartLine,
-                uint32 LineCount, struct SGFX * gfx)
+                uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -1176,7 +1233,7 @@ void DrawHiResTile16 (uint32 Tile, uint32 Offset, uint32 StartLine,
 
 void DrawHiResClippedTile16 (uint32 Tile, uint32 Offset,
                          uint32 StartPixel, uint32 Width,
-                       uint32 StartLine, uint32 LineCount, struct SGFX * gfx)
+                       uint32 StartLine, uint32 LineCount)
 {
     TILE_PREAMBLE
     register uint8 *bp;
@@ -1184,3 +1241,4 @@ void DrawHiResClippedTile16 (uint32 Tile, uint32 Offset,
     TILE_CLIP_PREAMBLE
     RENDER_CLIPPED_TILEHI(WRITE_4PIXELSHI16, WRITE_4PIXELSHI16_FLIPPED, 4)
 }
+