removing lots of unused code
[drnoksnes] / gfx.cpp
diff --git a/gfx.cpp b/gfx.cpp
index 3a92def..44dd230 100644 (file)
--- a/gfx.cpp
+++ b/gfx.cpp
@@ -46,7 +46,6 @@
 #include "memmap.h"
 #include "ppu.h"
 #include "cpuexec.h"
-#include "display.h"
 #include "gfx.h"
 #include "apu.h"
 #include "cheats.h"
@@ -107,7 +106,7 @@ extern uint8  Mode7Depths [2];
 
 #define BLACK BUILD_PIXEL(0,0,0)
 
-bool8_32 S9xGraphicsInit ()
+bool8 S9xGraphicsInit ()
 {
     register uint32 PixelOdd = 1;
     register uint32 PixelEven = 2;
@@ -212,27 +211,15 @@ bool8_32 S9xGraphicsInit ()
 
     PPU.BG_Forced = 0;
     IPPU.OBJChanged = TRUE;
-    if (Settings.Transparency)
-       Settings.SixteenBit = TRUE;
 
        IPPU.DirectColourMapsNeedRebuild = TRUE;
-       if (Settings.SixteenBit) {
-               DrawTilePtr = DrawTile16;
-               DrawClippedTilePtr = DrawClippedTile16;
-               DrawLargePixelPtr = DrawLargePixel16;
-               DrawHiResTilePtr= DrawHiResTile16;
-               DrawHiResClippedTilePtr = DrawHiResClippedTile16;
-       } else {
-               DrawTilePtr = DrawTile;
-               DrawClippedTilePtr = DrawClippedTile;
-               DrawLargePixelPtr = DrawLargePixel;
-               DrawHiResTilePtr = DrawTile;
-               DrawHiResClippedTilePtr = DrawClippedTile;
-       }
+       DrawTilePtr = DrawTile16;
+       DrawClippedTilePtr = DrawClippedTile16;
+       DrawLargePixelPtr = DrawLargePixel16;
+       DrawHiResTilePtr= DrawHiResTile16;
+       DrawHiResClippedTilePtr = DrawHiResClippedTile16;
     S9xFixColourBrightness();
 
-    if (Settings.SixteenBit)
-    {
        if (!(GFX.X2 = (uint16 *) malloc (sizeof (uint16) * 0x10000)))
            return (FALSE);
 
@@ -379,15 +366,8 @@ bool8_32 S9xGraphicsInit ()
                }
            }
        }
-    }
-    else
-    {
-       GFX.X2 = NULL;
-       GFX.ZERO_OR_X2 = NULL;
-       GFX.ZERO = NULL;
-    }
 
-    return (TRUE);
+    return TRUE;
 }
 
 void S9xGraphicsDeinit (void)
@@ -507,24 +487,7 @@ void S9xEndScreenRefresh()
                IPPU.RenderedFramesCount++;
 
                if (IPPU.ColorsChanged) {
-                       uint32 saved = PPU.CGDATA[0];
-
-                       if (!Settings.SixteenBit) {
-                               // Hack for Super Mario World - to get its sky blue
-                               // (It uses Fixed colour addition on the backdrop colour)
-                               if (!(Memory.FillRAM [0x2131] & 0x80) &&
-                                       (Memory.FillRAM[0x2131] & 0x20) &&
-                                       (PPU.FixedColourRed || PPU.FixedColourGreen ||
-                                        PPU.FixedColourBlue)) {
-                                       PPU.CGDATA[0] = PPU.FixedColourRed |
-                                                       (PPU.FixedColourGreen << 5) |
-                                                       (PPU.FixedColourBlue << 10);
-                               }
-                       }
-
                        IPPU.ColorsChanged = FALSE;
-                   S9xSetPalette();
-                       PPU.CGDATA[0] = saved;
                }
 
                if (Settings.DisplayFrameRate) {
@@ -535,9 +498,7 @@ void S9xEndScreenRefresh()
                        S9xDisplayString(GFX.InfoString);
                }
 
-               S9xDeinitUpdate(
-                       IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight,
-                       Settings.SixteenBit);
+               S9xDeinitUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight);
     }
 
 #ifndef RC_OPTIMIZED
@@ -1474,7 +1435,7 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                    continue;
            }
 
-           uint32 s = (Left>>1) * GFX_PIX_SIZE + Y * GFX.PPL;
+           intptr_t s = (Left>>1) * GFX_PIX_SIZE + Y * GFX.PPL;
            uint32 HPos = (HOffset + Left * GFX_PIX_SIZE) & 0x3ff;
 
            uint32 Quot = HPos >> 3;
@@ -1494,8 +1455,7 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2)
                Count = 8 - Offset;
                if (Count > Width)
                    Count = Width;
-               if (s) // XXX: Workaround for underflow (Secret of MANA)
-                       s -= (Offset>>1);
+               s -= (Offset>>1);
                Tile = READ_2BYTES (t);
                GFX.Z1 = GFX.Z2 = depths [(Tile & 0x2000) >> 13];
 
@@ -1822,7 +1782,7 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                            continue;
                    }
 
-                   uint32 s = Left * GFX_PIX_SIZE + Y * GFX.PPL;
+                   intptr_t s = Left * GFX_PIX_SIZE + Y * GFX.PPL;
                    uint32 HPos = (HOffset + Left) & OffsetMask;
 
                    uint32 Quot = HPos >> 3;
@@ -1852,7 +1812,7 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
                        Count = 8 - Offset;
                        if (Count > Width)
                            Count = Width;
-                       s -= Offset * GFX_PIX_SIZE;
+                   s -= Offset * GFX_PIX_SIZE;
                        Tile = READ_2BYTES(t);
                        GFX.Z1 = GFX.Z2 = depths [(Tile & 0x2000) >> 13];
 
@@ -2904,10 +2864,7 @@ static void DisplayChar(uint8 *Screen, uint8 c)
 {
     int line = (((c & 0x7f) - 32) >> 4) * font_height;
     int offset = (((c & 0x7f) - 32) & 15) * font_width;
-#ifndef _SNESPPC
-    if (Settings.SixteenBit)
-#endif
-    {
+
        int h, w;
        uint16 *s = (uint16 *) Screen;
        for (h = 0; h < font_height; h++, line++,
@@ -2924,39 +2881,15 @@ static void DisplayChar(uint8 *Screen, uint8 c)
                    *s = BLACK;
            }
        }
-    }
-#ifndef _SNESPPC
-    else
-    {
-       int h, w;
-       uint8 *s = Screen;
-       for (h = 0; h < font_height; h++, line++,
-            s += GFX.PPL - font_width)
-       {
-           for (w = 0; w < font_width; w++, s++)
-           {
-               uint8 p = font [line][offset + w];
-
-               if (p == '#')
-                   *s = 255;
-               else
-               if (p == '.')
-                   *s = BLACK;
-           }
-       }
-    }
-#endif
 }
 
 static void S9xDisplayFrameRate()
 {
+    const unsigned int char_width = (font_width - 1) * sizeof (uint16);
        uint8 *Screen = GFX.Screen + 2 +
                (IPPU.RenderedScreenHeight - font_height - 1) * GFX.Pitch;
        char string[12];
     int len;
-    const unsigned int char_width = Settings.SixteenBit ? 
-                               (font_width - 1) * sizeof (uint16) : 
-                               (font_width - 1);
 
        if (Settings.TurboMode) {
                len = sprintf(string, "%u",
@@ -2975,6 +2908,7 @@ static void S9xDisplayFrameRate()
 
 static void S9xDisplayString(const char *string)
 {
+    const unsigned int char_width = (font_width - 1) * sizeof (uint16);
     uint8 *Screen = GFX.Screen + 2 +
                    (IPPU.RenderedScreenHeight - font_height * 5) * GFX.Pitch;
     int len = strlen (string);
@@ -2986,9 +2920,7 @@ static void S9xDisplayString(const char *string)
     {
        if (char_count >= max_chars || string [i] < 32)
        {
-           Screen -= Settings.SixteenBit ? 
-                       (font_width - 1) * sizeof (uint16) * max_chars :
-                       (font_width - 1) * max_chars;
+           Screen -= char_width * max_chars;
            Screen += font_height * GFX.Pitch;
            if (Screen >= GFX.Screen + GFX.Pitch * IPPU.RenderedScreenHeight)
                break;
@@ -2997,8 +2929,7 @@ static void S9xDisplayString(const char *string)
        if (string [i] < 32)
            continue;
        DisplayChar (Screen, string [i]);
-       Screen += Settings.SixteenBit ? (font_width - 1) * sizeof (uint16) : 
-                 (font_width - 1);
+       Screen += char_width;
     }
 }
 
@@ -3061,27 +2992,15 @@ void S9xUpdateScreen () // ~30-50ms! (called from FLUSH_REDRAW())
                if (!IPPU.DoubleWidthPixels) {
                        // The game has switched from lo-res to hi-res mode part way down
                        // the screen. Scale any existing lo-res pixels on screen
-                       if (Settings.SixteenBit) {
-                               for (register uint32 y = 0; y < GFX.StartY; y++) {
-                                       register uint16 *p =
-                                               (uint16 *) (GFX.Screen + y * GFX.Pitch) + 255;
-                                       register uint16 *q =
-                                               (uint16 *) (GFX.Screen + y * GFX.Pitch) + 510;
-                                       for (register int x = 255; x >= 0; x--, p--, q -= 2) {
-                                               *q = *(q + 1) = *p;
-                                       }
+                       for (register uint32 y = 0; y < GFX.StartY; y++) {
+                               register uint16 *p =
+                                       (uint16 *) (GFX.Screen + y * GFX.Pitch) + 255;
+                               register uint16 *q =
+                                       (uint16 *) (GFX.Screen + y * GFX.Pitch) + 510;
+                               for (register int x = 255; x >= 0; x--, p--, q -= 2) {
+                                       *q = *(q + 1) = *p;
                                }
-                   } else {
-                               for (register uint32 y = 0; y < GFX.StartY; y++) {
-                                       register uint8 *p =
-                                               GFX.Screen + y * GFX.Pitch + 255;
-                                       register uint8 *q =
-                                               GFX.Screen + y * GFX.Pitch + 510;
-                                       for (register int x = 255; x >= 0; x--, p--, q -= 2) {
-                                               *q = *(q + 1) = *p;
-                                       }
-                               }
-                   }
+                       }
 
                        IPPU.DoubleWidthPixels = TRUE;
                }
@@ -3091,7 +3010,7 @@ void S9xUpdateScreen () // ~30-50ms! (called from FLUSH_REDRAW())
     uint32 black = BLACK | (BLACK << 16);
 
        // Are we worrying about transparencies?
-    if (Settings.Transparency && Settings.SixteenBit)
+    if (Settings.Transparency)
     {
                if (GFX.Pseudo)
                {
@@ -3662,57 +3581,39 @@ void S9xUpdateScreen () // ~30-50ms! (called from FLUSH_REDRAW())
     }
     else // Transparencys are disabled, ahh lovely ... nice and easy.
        {
-#ifndef _SNESPPC
-               if (Settings.SixteenBit)
-#endif
+           // get back colour to be used in clearing the screen
+               register uint32 back;
+               if (!(Memory.FillRAM [0x2131] & 0x80) &&(Memory.FillRAM[0x2131] & 0x20) &&
+                               (PPU.FixedColourRed || PPU.FixedColourGreen || PPU.FixedColourBlue))
                {
-                   // get back colour to be used in clearing the screen
-                       register uint32 back;
-                       if (!(Memory.FillRAM [0x2131] & 0x80) &&(Memory.FillRAM[0x2131] & 0x20) &&
-                                       (PPU.FixedColourRed || PPU.FixedColourGreen || PPU.FixedColourBlue))
-                       {
-                               back = (IPPU.XB[PPU.FixedColourRed]<<11) |
-                                          (IPPU.XB[PPU.FixedColourGreen] << 6) | 
-                                          (IPPU.XB[PPU.FixedColourBlue] << 1) | 1;
-                               back = (back << 16) | back;
-                       }
-                       else
-                       {
-                               back = IPPU.ScreenColors [0] | (IPPU.ScreenColors [0] << 16);
-                       }
-    
-                   // if Forcedblanking in use then back colour becomes black
-                       if (PPU.ForcedBlanking)
-                               back = black;
-                   else
-                       {
-                               SelectTileRenderer (TRUE);  //selects the tile renderers to be used
-                                                                                       // TRUE means to use the default
-                                                                                       // FALSE means use best renderer based on current
-                                                                                       // graphics register settings
-                       }
-                   
-                       // now clear all graphics lines which are being updated using the back colour
-                       for (register uint32 y = starty; y <= endy; y++)
-                   {
-                               memset32 ((uint32_t*)(GFX.Screen + y * GFX.Pitch), back,
-                                       IPPU.RenderedScreenWidth>>1);
-                   }
+                       back = (IPPU.XB[PPU.FixedColourRed]<<11) |
+                                  (IPPU.XB[PPU.FixedColourGreen] << 6) |
+                                  (IPPU.XB[PPU.FixedColourBlue] << 1) | 1;
+                       back = (back << 16) | back;
                }
-#ifndef _SNESPPC
-               else // Settings.SixteenBit == false
+               else
                {
-                   // because we are in 8 bit we can just use 0 to clear the screen
-                       // this means we can use the Zero Memory function
-                       
-                       // Loop through all lines being updated and clear the pixels to 0
-                       for (uint32 y = starty; y <= endy; y++)
-                   {
-                       ZeroMemory (GFX.Screen + y * GFX.Pitch,
-                                   IPPU.RenderedScreenWidth);
-                   }
+                       back = IPPU.ScreenColors [0] | (IPPU.ScreenColors [0] << 16);
                }
-#endif
+
+               // if Forcedblanking in use then back colour becomes black
+               if (PPU.ForcedBlanking)
+                       back = black;
+               else
+               {
+                       SelectTileRenderer (TRUE);  //selects the tile renderers to be used
+                                                                               // TRUE means to use the default
+                                                                               // FALSE means use best renderer based on current
+                                                                               // graphics register settings
+               }
+
+               // now clear all graphics lines which are being updated using the back colour
+               for (register uint32 y = starty; y <= endy; y++)
+               {
+                       memset32 ((uint32_t*)(GFX.Screen + y * GFX.Pitch), back,
+                               IPPU.RenderedScreenWidth>>1);
+               }
+
                if (!PPU.ForcedBlanking)
                {
                        // Loop through all lines being updated and clear the
@@ -3826,12 +3727,6 @@ else \
                                        bg = 0;
                                    }
 
-#ifndef _SNESPPC
-                                   if (!Settings.SixteenBit)
-                                       DrawBGMode7Background (GFX.Screen, bg);
-                                   else
-#endif
-                                   {
                                        if (!Settings.Mode7Interpolate)
                                        {       
                                            DrawBGMode7Background16 (GFX.Screen, bg);
@@ -3840,7 +3735,6 @@ else \
                                        {       
                                            DrawBGMode7Background16_i (GFX.Screen, bg);
                                        }
-                                 }
                                }
                    }
                }
@@ -3852,10 +3746,6 @@ else \
        {
            // Mixure of background modes used on screen - scale width
            // of all non-mode 5 and 6 pixels.
-#ifndef _SNESPPC
-               if (Settings.SixteenBit)
-#endif
-           {
                for (register uint32 y = GFX.StartY; y <= GFX.EndY; y++)
                {
                    register uint16 *p = (uint16 *) (GFX.Screen + y * GFX.Pitch) + 255;
@@ -3863,19 +3753,6 @@ else \
                    for (register int x = 255; x >= 0; x--, p--, q -= 2)
                        *q = *(q + 1) = *p;
                }
-           }
-#ifndef _SNESPPC
-           else
-           {
-               for (register uint32 y = GFX.StartY; y <= GFX.EndY; y++)
-               {
-                   register uint8 *p = GFX.Screen + y * GFX.Pitch + 255;
-                   register uint8 *q = GFX.Screen + y * GFX.Pitch + 510;
-                   for (register int x = 255; x >= 0; x--, p--, q -= 2)
-                       *q = *(q + 1) = *p;
-               }
-           }
-#endif
        }
 
        if (IPPU.LatchedInterlace)