aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/gfx.cpp46
-rw-r--r--source/gfx.h1
-rw-r--r--source/tile.cpp217
-rw-r--r--source/tile.h139
4 files changed, 221 insertions, 182 deletions
diff --git a/source/gfx.cpp b/source/gfx.cpp
index 5e6c650..3303fb9 100644
--- a/source/gfx.cpp
+++ b/source/gfx.cpp
@@ -2596,6 +2596,7 @@ static void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
}
#define RENDER_BACKGROUND_MODE7(TYPE,FUNC) \
+ uint16 *ScreenColors; \
CHECK_SOUND(); \
\
uint8 *VRAM1 = Memory.VRAM + 1; \
@@ -2603,10 +2604,10 @@ static void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2)
{ \
if (IPPU.DirectColourMapsNeedRebuild) \
S9xBuildDirectColourMaps (); \
- GFX.ScreenColors = DirectColourMaps [0]; \
+ ScreenColors = DirectColourMaps [0]; \
} \
else \
- GFX.ScreenColors = IPPU.ScreenColors; \
+ ScreenColors = IPPU.ScreenColors; \
\
int aa, cc; \
int dir; \
@@ -2736,54 +2737,55 @@ static void DrawBGMode7Background (uint8 *Screen, int bg)
static void DrawBGMode7Background16 (uint8 *Screen, int bg)
{
- RENDER_BACKGROUND_MODE7 (uint16, GFX.ScreenColors [b & GFX.Mode7Mask]);
+ RENDER_BACKGROUND_MODE7 (uint16, ScreenColors [b & GFX.Mode7Mask]);
}
static void DrawBGMode7Background16Add (uint8 *Screen, int bg)
{
RENDER_BACKGROUND_MODE7 (uint16, *(d + GFX.DepthDelta) ?
(*(d + GFX.DepthDelta) != 1 ?
- COLOR_ADD (GFX.ScreenColors [b & GFX.Mode7Mask],
+ COLOR_ADD (ScreenColors [b & GFX.Mode7Mask],
p [GFX.Delta]) :
- COLOR_ADD (GFX.ScreenColors [b & GFX.Mode7Mask],
+ COLOR_ADD (ScreenColors [b & GFX.Mode7Mask],
GFX.FixedColour)) :
- GFX.ScreenColors [b & GFX.Mode7Mask]);
+ ScreenColors [b & GFX.Mode7Mask]);
}
static void DrawBGMode7Background16Add1_2 (uint8 *Screen, int bg)
{
RENDER_BACKGROUND_MODE7 (uint16, *(d + GFX.DepthDelta) ?
(*(d + GFX.DepthDelta) != 1 ?
- COLOR_ADD1_2 (GFX.ScreenColors [b & GFX.Mode7Mask],
+ COLOR_ADD1_2 (ScreenColors [b & GFX.Mode7Mask],
p [GFX.Delta]) :
- COLOR_ADD (GFX.ScreenColors [b & GFX.Mode7Mask],
+ COLOR_ADD (ScreenColors [b & GFX.Mode7Mask],
GFX.FixedColour)) :
- GFX.ScreenColors [b & GFX.Mode7Mask]);
+ ScreenColors [b & GFX.Mode7Mask]);
}
static void DrawBGMode7Background16Sub (uint8 *Screen, int bg)
{
RENDER_BACKGROUND_MODE7 (uint16, *(d + GFX.DepthDelta) ?
(*(d + GFX.DepthDelta) != 1 ?
- COLOR_SUB (GFX.ScreenColors [b & GFX.Mode7Mask],
+ COLOR_SUB (ScreenColors [b & GFX.Mode7Mask],
p [GFX.Delta]) :
- COLOR_SUB (GFX.ScreenColors [b & GFX.Mode7Mask],
+ COLOR_SUB (ScreenColors [b & GFX.Mode7Mask],
GFX.FixedColour)) :
- GFX.ScreenColors [b & GFX.Mode7Mask]);
+ ScreenColors [b & GFX.Mode7Mask]);
}
static void DrawBGMode7Background16Sub1_2 (uint8 *Screen, int bg)
{
RENDER_BACKGROUND_MODE7 (uint16, *(d + GFX.DepthDelta) ?
(*(d + GFX.DepthDelta) != 1 ?
- COLOR_SUB1_2 (GFX.ScreenColors [b & GFX.Mode7Mask],
+ COLOR_SUB1_2 (ScreenColors [b & GFX.Mode7Mask],
p [GFX.Delta]) :
- COLOR_SUB (GFX.ScreenColors [b & GFX.Mode7Mask],
+ COLOR_SUB (ScreenColors [b & GFX.Mode7Mask],
GFX.FixedColour)) :
- GFX.ScreenColors [b & GFX.Mode7Mask]);
+ ScreenColors [b & GFX.Mode7Mask]);
}
#define RENDER_BACKGROUND_MODE7_i(TYPE,FUNC,COLORFUNC) \
+ uint16 *ScreenColors; \
CHECK_SOUND(); \
\
uint8 *VRAM1 = Memory.VRAM + 1; \
@@ -2791,10 +2793,10 @@ static void DrawBGMode7Background16Sub1_2 (uint8 *Screen, int bg)
{ \
if (IPPU.DirectColourMapsNeedRebuild) \
S9xBuildDirectColourMaps (); \
- GFX.ScreenColors = DirectColourMaps [0]; \
+ ScreenColors = DirectColourMaps [0]; \
} \
else \
- GFX.ScreenColors = IPPU.ScreenColors; \
+ ScreenColors = IPPU.ScreenColors; \
\
int aa, cc; \
int dir; \
@@ -3167,7 +3169,7 @@ STATIC uint32 Q_INTERPOLATE(uint32 A, uint32 B, uint32 C, uint32 D)
static void DrawBGMode7Background16_i (uint8 *Screen, int bg)
{
- RENDER_BACKGROUND_MODE7_i (uint16, theColor, (GFX.ScreenColors[b & GFX.Mode7Mask]));
+ RENDER_BACKGROUND_MODE7_i (uint16, theColor, (ScreenColors[b & GFX.Mode7Mask]));
}
static void DrawBGMode7Background16Add_i (uint8 *Screen, int bg)
@@ -3178,7 +3180,7 @@ static void DrawBGMode7Background16Add_i (uint8 *Screen, int bg)
p [GFX.Delta])) :
(COLOR_ADD (theColor,
GFX.FixedColour))) :
- theColor, (GFX.ScreenColors[b & GFX.Mode7Mask]));
+ theColor, (ScreenColors[b & GFX.Mode7Mask]));
}
static void DrawBGMode7Background16Add1_2_i (uint8 *Screen, int bg)
@@ -3189,7 +3191,7 @@ static void DrawBGMode7Background16Add1_2_i (uint8 *Screen, int bg)
p [GFX.Delta]) :
COLOR_ADD (theColor,
GFX.FixedColour)) :
- theColor, (GFX.ScreenColors[b & GFX.Mode7Mask]));
+ theColor, (ScreenColors[b & GFX.Mode7Mask]));
}
static void DrawBGMode7Background16Sub_i (uint8 *Screen, int bg)
@@ -3200,7 +3202,7 @@ static void DrawBGMode7Background16Sub_i (uint8 *Screen, int bg)
p [GFX.Delta]) :
COLOR_SUB (theColor,
GFX.FixedColour)) :
- theColor, (GFX.ScreenColors[b & GFX.Mode7Mask]));
+ theColor, (ScreenColors[b & GFX.Mode7Mask]));
}
static void DrawBGMode7Background16Sub1_2_i (uint8 *Screen, int bg)
@@ -3211,7 +3213,7 @@ static void DrawBGMode7Background16Sub1_2_i (uint8 *Screen, int bg)
p [GFX.Delta]) :
COLOR_SUB (theColor,
GFX.FixedColour)) :
- theColor, (GFX.ScreenColors[b & GFX.Mode7Mask]));
+ theColor, (ScreenColors[b & GFX.Mode7Mask]));
}
#define _BUILD_SETUP(F) \
diff --git a/source/gfx.h b/source/gfx.h
index b145f49..d6da783 100644
--- a/source/gfx.h
+++ b/source/gfx.h
@@ -114,7 +114,6 @@ struct SGFX{
uint32 PixSize;
uint8 *S;
uint8 *DB;
- uint16 *ScreenColors;
uint32 DepthDelta;
uint8 Z1; // Depth for comparison
uint8 Z2; // Depth to save
diff --git a/source/tile.cpp b/source/tile.cpp
index c4a211c..c93c02f 100644
--- a/source/tile.cpp
+++ b/source/tile.cpp
@@ -218,7 +218,7 @@ static uint8 ConvertTile (uint8 *pCache, uint32 TileAddr)
#define PLOT_PIXEL(screen, pixel) (pixel)
#ifndef FOREVER_16_BIT
-static void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint8 *Screen = GFX.S + Offset;
@@ -228,13 +228,13 @@ static void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels)
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N]))
{
- Screen [N] = (uint8) GFX.ScreenColors [Pixel];
+ Screen [N] = (uint8) ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS_FLIPPED (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS_FLIPPED (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint8 *Screen = GFX.S + Offset;
@@ -244,13 +244,13 @@ static void WRITE_4PIXELS_FLIPPED (uint32 Offset, uint8 *Pixels)
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N]))
{
- Screen [N] = (uint8) GFX.ScreenColors [Pixel];
+ Screen [N] = (uint8) ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELSx2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELSx2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint8 *Screen = GFX.S + Offset;
@@ -260,13 +260,13 @@ static void WRITE_4PIXELSx2 (uint32 Offset, uint8 *Pixels)
{
if (GFX.Z1 > Depth [N * 2] && (Pixel = Pixels[N]))
{
- Screen [N * 2] = Screen [N * 2 + 1] = (uint8) GFX.ScreenColors [Pixel];
+ Screen [N * 2] = Screen [N * 2 + 1] = (uint8) ScreenColors [Pixel];
Depth [N * 2] = Depth [N * 2 + 1] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS_FLIPPEDx2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS_FLIPPEDx2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint8 *Screen = GFX.S + Offset;
@@ -276,13 +276,13 @@ static void WRITE_4PIXELS_FLIPPEDx2 (uint32 Offset, uint8 *Pixels)
{
if (GFX.Z1 > Depth [N * 2] && (Pixel = Pixels[3 - N]))
{
- Screen [N * 2] = Screen [N * 2 + 1] = (uint8) GFX.ScreenColors [Pixel];
+ Screen [N * 2] = Screen [N * 2 + 1] = (uint8) ScreenColors [Pixel];
Depth [N * 2] = Depth [N * 2 + 1] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELSx2x2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELSx2x2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint8 *Screen = GFX.S + Offset;
@@ -292,13 +292,13 @@ static void WRITE_4PIXELSx2x2 (uint32 Offset, uint8 *Pixels)
{
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];
+ Screen [N * 2] = Screen [N * 2 + 1] = Screen [GFX.RealPitch + N * 2] = Screen [GFX.RealPitch + N * 2 + 1] = (uint8) ScreenColors [Pixel];
Depth [N * 2] = Depth [N * 2 + 1] = Depth [GFX.RealPitch + N * 2] = Depth [GFX.RealPitch + N * 2 + 1] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint8 *Screen = GFX.S + Offset;
@@ -308,7 +308,7 @@ static void WRITE_4PIXELS_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels)
{
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];
+ Screen [N * 2] = Screen [N * 2 + 1] = Screen [GFX.RealPitch + N * 2] = Screen [GFX.RealPitch + N * 2 + 1] = (uint8) ScreenColors [Pixel];
Depth [N * 2] = Depth [N * 2 + 1] = Depth [GFX.RealPitch + N * 2] = Depth [GFX.RealPitch + N * 2 + 1] = GFX.Z2;
}
}
@@ -387,11 +387,11 @@ void DrawLargePixel (uint32 Tile, uint32 Offset,
uint8 *Depth = GFX.DB + Offset;
uint8 pixel;
- RENDER_TILE_LARGE (((uint8) GFX.ScreenColors [pixel]), PLOT_PIXEL)
+ RENDER_TILE_LARGE (((uint8) ScreenColors [pixel]), PLOT_PIXEL)
}
#endif
-static void WRITE_4PIXELS16 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -401,13 +401,13 @@ static void WRITE_4PIXELS16 (uint32 Offset, uint8 *Pixels)
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N]))
{
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPED (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPED (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -417,13 +417,13 @@ static void WRITE_4PIXELS16_FLIPPED (uint32 Offset, uint8 *Pixels)
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N]))
{
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16x2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16x2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -433,13 +433,13 @@ static void WRITE_4PIXELS16x2 (uint32 Offset, uint8 *Pixels)
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N]))
{
- Screen [N * 2] = Screen [N * 2 + 1] = GFX.ScreenColors [Pixel];
+ Screen [N * 2] = Screen [N * 2 + 1] = ScreenColors [Pixel];
Depth [N * 2] = Depth [N * 2 + 1] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPEDx2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPEDx2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -449,13 +449,13 @@ static void WRITE_4PIXELS16_FLIPPEDx2 (uint32 Offset, uint8 *Pixels)
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N]))
{
- Screen [N * 2] = Screen [N * 2 + 1] = GFX.ScreenColors [Pixel];
+ Screen [N * 2] = Screen [N * 2 + 1] = ScreenColors [Pixel];
Depth [N * 2] = Depth [N * 2 + 1] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16x2x2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16x2x2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -465,13 +465,13 @@ static void WRITE_4PIXELS16x2x2 (uint32 Offset, uint8 *Pixels)
{
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];
+ Screen [N * 2] = Screen [N * 2 + 1] = Screen [(GFX.RealPitch >> 1) + N * 2] = Screen [(GFX.RealPitch >> 1) + N * 2 + 1] = ScreenColors [Pixel];
Depth [N * 2] = Depth [N * 2 + 1] = Depth [(GFX.RealPitch >> 1) + N * 2] = Depth [(GFX.RealPitch >> 1) + N * 2 + 1] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -481,7 +481,7 @@ static void WRITE_4PIXELS16_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels)
{
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];
+ Screen [N * 2] = Screen [N * 2 + 1] = Screen [(GFX.RealPitch >> 1) + N * 2] = Screen [(GFX.RealPitch >> 1) + N * 2 + 1] = ScreenColors [Pixel];
Depth [N * 2] = Depth [N * 2 + 1] = Depth [(GFX.RealPitch >> 1) + N * 2] = Depth [(GFX.RealPitch >> 1) + N * 2 + 1] = GFX.Z2;
}
}
@@ -490,10 +490,73 @@ static void WRITE_4PIXELS16_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels)
void DrawTile16 (uint32 Tile, uint32 Offset, uint32 StartLine,
uint32 LineCount)
{
- TILE_PREAMBLE
- register uint8 *bp;
+ TILE_PREAMBLE
+ register uint8 *bp;
+ uint8 Pixel;
+ uint16 *Screen = (uint16 *) GFX.S + Offset;
+ uint8 *Depth = GFX.DB + Offset;
- RENDER_TILE(WRITE_4PIXELS16, WRITE_4PIXELS16_FLIPPED, 4)
+ switch (Tile & (H_FLIP | V_FLIP))
+ {
+ case 0:
+ bp = pCache + StartLine;
+ for (l = LineCount; l != 0; l--, bp += 8, Screen += GFX.PPL, Depth += GFX.PPL)
+ {
+ for (uint8 N = 0; N < 8; N++)
+ {
+ if (GFX.Z1 > Depth [N] && (Pixel = bp[N]))
+ {
+ Screen [N] = ScreenColors [Pixel];
+ Depth [N] = GFX.Z2;
+ }
+ }
+ }
+ break;
+ case H_FLIP:
+ bp = pCache + StartLine;
+ for (l = LineCount; l != 0; l--, bp += 8, Screen += GFX.PPL, Depth += GFX.PPL)
+ {
+ for (uint8 N = 0; N < 8; N++)
+ {
+ if (GFX.Z1 > Depth [N] && (Pixel = bp[7 - N]))
+ {
+ Screen [N] = ScreenColors [Pixel];
+ Depth [N] = GFX.Z2;
+ }
+ }
+ }
+ break;
+ case H_FLIP | V_FLIP:
+ bp = pCache + 56 - StartLine;
+ for (l = LineCount; l != 0; l--, bp -= 8, Screen += GFX.PPL, Depth += GFX.PPL)
+ {
+ for (uint8 N = 0; N < 8; N++)
+ {
+ if (GFX.Z1 > Depth [N] && (Pixel = bp[7 - N]))
+ {
+ Screen [N] = ScreenColors [Pixel];
+ Depth [N] = GFX.Z2;
+ }
+ }
+ }
+ break;
+ case V_FLIP:
+ bp = pCache + 56 - StartLine;
+ for (l = LineCount; l != 0; l--, bp -= 8, Screen += GFX.PPL, Depth += GFX.PPL)
+ {
+ for (uint8 N = 0; N < 8; N++)
+ {
+ if (GFX.Z1 > Depth [N] && (Pixel = bp[N]))
+ {
+ Screen [N] = ScreenColors [Pixel];
+ Depth [N] = GFX.Z2;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
}
void DrawClippedTile16 (uint32 Tile, uint32 Offset,
@@ -557,10 +620,10 @@ void DrawLargePixel16 (uint32 Tile, uint32 Offset,
uint8 *Depth = GFX.DB + Offset;
uint16 pixel;
- RENDER_TILE_LARGE (GFX.ScreenColors [pixel], PLOT_PIXEL)
+ RENDER_TILE_LARGE (ScreenColors [pixel], PLOT_PIXEL)
}
-static void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -574,18 +637,18 @@ static void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels)
if (SubDepth [N])
{
if (SubDepth [N] != 1)
- Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], Screen [GFX.Delta + N]); \
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]); \
else
- Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], GFX.FixedColour); \
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour); \
}
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -599,18 +662,18 @@ static void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels)
if (SubDepth [N])
{
if (SubDepth [N] != 1)
- Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], Screen [GFX.Delta + N]); \
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]); \
else
- Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], GFX.FixedColour); \
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour); \
}
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -624,18 +687,18 @@ static void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels)
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 (ScreenColors [Pixel], Screen [GFX.Delta + N]));
else
- Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], GFX.FixedColour);
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
}
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -649,18 +712,18 @@ static void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels)
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 (ScreenColors [Pixel], Screen [GFX.Delta + N]));
else
- Screen [N] = COLOR_ADD (GFX.ScreenColors [Pixel], GFX.FixedColour);
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
}
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -674,18 +737,18 @@ static void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels)
if (SubDepth [N])
{
if (SubDepth [N] != 1)
- Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], Screen [GFX.Delta + N]);
else
- Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], GFX.FixedColour);
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
}
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -699,18 +762,18 @@ static void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels)
if (SubDepth [N])
{
if (SubDepth [N] != 1)
- Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], Screen [GFX.Delta + N]);
else
- Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], GFX.FixedColour);
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
}
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -724,18 +787,18 @@ static void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels)
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 (ScreenColors [Pixel], Screen [GFX.Delta + N]);
else
- Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], GFX.FixedColour);
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
}
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -749,12 +812,12 @@ static void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels)
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 (ScreenColors [Pixel], Screen [GFX.Delta + N]);
else
- Screen [N] = (uint16) COLOR_SUB (GFX.ScreenColors [Pixel], GFX.FixedColour);
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
}
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
@@ -841,7 +904,7 @@ void DrawClippedTile16Sub1_2 (uint32 Tile, uint32 Offset,
RENDER_CLIPPED_TILE(WRITE_4PIXELS16_SUB1_2, WRITE_4PIXELS16_FLIPPED_SUB1_2, 4)
}
-static void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -853,15 +916,15 @@ static void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels)
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 (ScreenColors [Pixel], GFX.FixedColour));
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -873,15 +936,15 @@ static void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels)
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 (ScreenColors [Pixel], GFX.FixedColour));
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -893,15 +956,15 @@ static void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels)
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 (ScreenColors [Pixel], GFX.FixedColour);
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
}
-static void WRITE_4PIXELS16_FLIPPED_SUBF1_2 (uint32 Offset, uint8 *Pixels)
+static void WRITE_4PIXELS16_FLIPPED_SUBF1_2 (uint32 Offset, uint8 *Pixels, uint16 *ScreenColors)
{
uint8 Pixel;
uint16 *Screen = (uint16 *) GFX.S + Offset;
@@ -913,9 +976,9 @@ static void WRITE_4PIXELS16_FLIPPED_SUBF1_2 (uint32 Offset, uint8 *Pixels)
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 (ScreenColors [Pixel], GFX.FixedColour);
else
- Screen [N] = GFX.ScreenColors [Pixel];
+ Screen [N] = ScreenColors [Pixel];
Depth [N] = GFX.Z2;
}
}
@@ -979,7 +1042,7 @@ void DrawLargePixel16Add (uint32 Tile, uint32 Offset,
COLOR_ADD (p, GFX.FixedColour)) \
: p)
- RENDER_TILE_LARGE (GFX.ScreenColors [pixel], LARGE_ADD_PIXEL)
+ RENDER_TILE_LARGE (ScreenColors [pixel], LARGE_ADD_PIXEL)
}
void DrawLargePixel16Add1_2 (uint32 Tile, uint32 Offset,
@@ -998,7 +1061,7 @@ void DrawLargePixel16Add1_2 (uint32 Tile, uint32 Offset,
COLOR_ADD (p, GFX.FixedColour)) \
: p))
- RENDER_TILE_LARGE (GFX.ScreenColors [pixel], LARGE_ADD_PIXEL1_2)
+ RENDER_TILE_LARGE (ScreenColors [pixel], LARGE_ADD_PIXEL1_2)
}
void DrawLargePixel16Sub (uint32 Tile, uint32 Offset,
@@ -1017,7 +1080,7 @@ void DrawLargePixel16Sub (uint32 Tile, uint32 Offset,
COLOR_SUB (p, GFX.FixedColour)) \
: p)
- RENDER_TILE_LARGE (GFX.ScreenColors [pixel], LARGE_SUB_PIXEL)
+ RENDER_TILE_LARGE (ScreenColors [pixel], LARGE_SUB_PIXEL)
}
void DrawLargePixel16Sub1_2 (uint32 Tile, uint32 Offset,
@@ -1036,6 +1099,6 @@ void DrawLargePixel16Sub1_2 (uint32 Tile, uint32 Offset,
COLOR_SUB (p, GFX.FixedColour)) \
: p)
- RENDER_TILE_LARGE (GFX.ScreenColors [pixel], LARGE_SUB_PIXEL1_2)
+ RENDER_TILE_LARGE (ScreenColors [pixel], LARGE_SUB_PIXEL1_2)
}
diff --git a/source/tile.h b/source/tile.h
index f5b4d85..c43e7af 100644
--- a/source/tile.h
+++ b/source/tile.h
@@ -108,65 +108,64 @@
return; \
\
register uint32 l; \
+ uint16 *ScreenColors; \
if (BG.DirectColourMode) \
{ \
if (IPPU.DirectColourMapsNeedRebuild) \
S9xBuildDirectColourMaps (); \
- GFX.ScreenColors = DirectColourMaps [(Tile >> 10) & BG.PaletteMask]; \
+ ScreenColors = DirectColourMaps [(Tile >> 10) & BG.PaletteMask]; \
} \
else \
- GFX.ScreenColors = &IPPU.ScreenColors [(((Tile >> 10) & BG.PaletteMask) << BG.PaletteShift) + BG.StartPalette];
+ ScreenColors = &IPPU.ScreenColors [(((Tile >> 10) & BG.PaletteMask) << BG.PaletteShift) + BG.StartPalette];
#define RENDER_TILE(NORMAL, FLIPPED, N) \
- if (!(Tile & (V_FLIP | H_FLIP))) \
+ switch (Tile & (V_FLIP | H_FLIP)) \
{ \
+ case 0: \
bp = pCache + StartLine; \
for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
{ \
if (*(uint32 *) bp) \
- NORMAL (Offset, bp); \
+ NORMAL (Offset, bp, ScreenColors); \
if (*(uint32 *) (bp + 4)) \
- NORMAL (Offset + N, bp + 4); \
+ NORMAL (Offset + N, bp + 4, ScreenColors); \
} \
- } \
- else \
- if (!(Tile & V_FLIP)) \
- { \
+ break; \
+ case H_FLIP: \
bp = pCache + StartLine; \
for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
{ \
if (*(uint32 *) (bp + 4)) \
- FLIPPED (Offset, bp + 4); \
+ FLIPPED (Offset, bp + 4, ScreenColors); \
if (*(uint32 *) bp) \
- FLIPPED (Offset + N, bp); \
+ FLIPPED (Offset + N, bp, ScreenColors); \
} \
- } \
- else \
- if (Tile & H_FLIP) \
- { \
+ break; \
+ case H_FLIP | V_FLIP: \
bp = pCache + 56 - StartLine; \
for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
{ \
if (*(uint32 *) (bp + 4)) \
- FLIPPED (Offset, bp + 4); \
+ FLIPPED (Offset, bp + 4, ScreenColors); \
if (*(uint32 *) bp) \
- FLIPPED (Offset + N, bp); \
+ FLIPPED (Offset + N, bp, ScreenColors); \
} \
- } \
- else \
- { \
+ break; \
+ case V_FLIP: \
bp = pCache + 56 - StartLine; \
for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
{ \
if (*(uint32 *) bp) \
- NORMAL (Offset, bp); \
+ NORMAL (Offset, bp, ScreenColors); \
if (*(uint32 *) (bp + 4)) \
- NORMAL (Offset + N, bp + 4); \
+ NORMAL (Offset + N, bp + 4, ScreenColors); \
} \
+ break; \
+ default: \
+ break; \
}
#define TILE_CLIP_PREAMBLE \
- uint32 dd; \
uint32 d1; \
uint32 d2; \
\
@@ -191,80 +190,69 @@
else \
d2 = 0;
-
#define RENDER_CLIPPED_TILE(NORMAL, FLIPPED, N) \
- if (!(Tile & (V_FLIP | H_FLIP))) \
+ uint32 dd; \
+ switch (Tile & (V_FLIP | H_FLIP)) \
{ \
+ case 0: \
bp = pCache + StartLine; \
for (l = LineCount; l != 0; l--, bp += 8, Offset += GFX.PPL) \
{ \
+ /* This is perfectly OK, regardless of endian. The tiles are \
+ * cached in leftmost-endian order (when not horiz flipped) by \
+ * the ConvertTile function. \
+ */ \
if ((dd = (*(uint32 *) bp) & d1)) \
- NORMAL (Offset, (uint8 *) &dd); \
+ NORMAL (Offset, (uint8 *) &dd, ScreenColors); \
if ((dd = (*(uint32 *) (bp + 4)) & d2)) \
- NORMAL (Offset + N, (uint8 *) &dd); \
+ NORMAL (Offset + N, (uint8 *) &dd, ScreenColors); \
} \
- } \
- else \
- if (!(Tile & V_FLIP)) \
- { \
+ break; \
+ case H_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); \
+ FLIPPED (Offset, (uint8 *) &dd, ScreenColors); \
if ((dd = *(uint32 *) bp & d2)) \
- FLIPPED (Offset + N, (uint8 *) &dd); \
+ FLIPPED (Offset + N, (uint8 *) &dd, ScreenColors); \
} \
- } \
- else \
- if (Tile & H_FLIP) \
- { \
+ break; \
+ case H_FLIP | V_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); \
+ FLIPPED (Offset, (uint8 *) &dd, ScreenColors); \
if ((dd = *(uint32 *) bp & d2)) \
- FLIPPED (Offset + N, (uint8 *) &dd); \
+ FLIPPED (Offset + N, (uint8 *) &dd, ScreenColors); \
} \
- } \
- else \
- { \
+ break; \
+ case V_FLIP: \
bp = pCache + 56 - StartLine; \
for (l = LineCount; l != 0; l--, bp -= 8, Offset += GFX.PPL) \
{ \
if ((dd = (*(uint32 *) bp) & d1)) \
- NORMAL (Offset, (uint8 *) &dd); \
+ NORMAL (Offset, (uint8 *) &dd, ScreenColors); \
if ((dd = (*(uint32 *) (bp + 4)) & d2)) \
- NORMAL (Offset + N, (uint8 *) &dd); \
+ NORMAL (Offset + N, (uint8 *) &dd, ScreenColors); \
} \
+ break; \
+ default: \
+ break; \
}
#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)) \
+ switch (Tile & (V_FLIP | H_FLIP)) \
{ \
+ case H_FLIP: \
StartPixel = 7 - StartPixel; \
+ /* fallthrough for no-flip case - above was a horizontal flip */ \
+ case 0: \
if ((pixel = *(pCache + StartLine + StartPixel))) \
{ \
pixel = PIXEL; \
@@ -278,11 +266,11 @@
}\
} \
} \
- } \
- else \
- if (Tile & H_FLIP) \
- { \
+ break; \
+ case H_FLIP | V_FLIP: \
StartPixel = 7 - StartPixel; \
+ /* fallthrough for V_FLIP-only case - above was a horizontal flip */ \
+ case V_FLIP: \
if ((pixel = *(pCache + 56 - StartLine + StartPixel))) \
{ \
pixel = PIXEL; \
@@ -296,22 +284,9 @@
}\
} \
} \
- } \
- 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; \
- }\
- } \
- } \
+ break; \
+ default: \
+ break; \
}
#endif