Skip to content

Commit

Permalink
Remove most of GFX_MULTI_FORMAT.
Browse files Browse the repository at this point in the history
  • Loading branch information
bearoso committed Mar 7, 2019
1 parent 58aa23b commit 76b6342
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 536 deletions.
11 changes: 0 additions & 11 deletions filter/2xsai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@

#define ALL_COLOR_MASK (FIRST_COLOR_MASK | SECOND_COLOR_MASK | THIRD_COLOR_MASK)

#ifdef GFX_MULTI_FORMAT
static uint32 colorMask = 0, qcolorMask = 0, lowPixelMask = 0, qlowpixelMask = 0;
#else
#define colorMask (((~RGB_LOW_BITS_MASK & ALL_COLOR_MASK) << 16) | (~RGB_LOW_BITS_MASK & ALL_COLOR_MASK))
#define qcolorMask (((~TWO_LOW_BITS_MASK & ALL_COLOR_MASK) << 16) | (~TWO_LOW_BITS_MASK & ALL_COLOR_MASK))
#define lowPixelMask ((RGB_LOW_BITS_MASK << 16) | RGB_LOW_BITS_MASK)
#define qlowpixelMask ((TWO_LOW_BITS_MASK << 16) | TWO_LOW_BITS_MASK)
#endif

static inline int GetResult (uint32, uint32, uint32, uint32);
static inline int GetResult1 (uint32, uint32, uint32, uint32, uint32);
Expand Down Expand Up @@ -78,13 +74,6 @@ static inline uint32 Q_INTERPOLATE (uint32 A, uint32 B, uint32 C, uint32 D)

bool8 S9xBlit2xSaIFilterInit (void)
{
#ifdef GFX_MULTI_FORMAT
colorMask = ((~RGB_LOW_BITS_MASK & ALL_COLOR_MASK) << 16) | (~RGB_LOW_BITS_MASK & ALL_COLOR_MASK);
qcolorMask = ((~TWO_LOW_BITS_MASK & ALL_COLOR_MASK) << 16) | (~TWO_LOW_BITS_MASK & ALL_COLOR_MASK);
lowPixelMask = (RGB_LOW_BITS_MASK << 16) | RGB_LOW_BITS_MASK;
qlowpixelMask = (TWO_LOW_BITS_MASK << 16) | TWO_LOW_BITS_MASK;
#endif

return (TRUE);
}

Expand Down
12 changes: 0 additions & 12 deletions filter/blit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@

#define ALL_COLOR_MASK (FIRST_COLOR_MASK | SECOND_COLOR_MASK | THIRD_COLOR_MASK)

#ifdef GFX_MULTI_FORMAT
static uint16 lowPixelMask = 0, qlowPixelMask = 0, highBitsMask = 0;
static uint32 colorMask = 0;
#else
#define lowPixelMask (RGB_LOW_BITS_MASK)
#define qlowPixelMask ((RGB_HI_BITS_MASK >> 3) | TWO_LOW_BITS_MASK)
#define highBitsMask (ALL_COLOR_MASK & RGB_REMOVE_LOW_BITS_MASK)
#define colorMask (((~RGB_HI_BITS_MASK & ALL_COLOR_MASK) << 16) | (~RGB_HI_BITS_MASK & ALL_COLOR_MASK))
#endif

static snes_ntsc_t *ntsc = NULL;
static uint8 *XDelta = NULL;
Expand All @@ -31,13 +26,6 @@ bool8 S9xBlitFilterInit (void)

S9xBlitClearDelta();

#ifdef GFX_MULTI_FORMAT
lowPixelMask = RGB_LOW_BITS_MASK;
qlowPixelMask = (RGB_HI_BITS_MASK >> 3) | TWO_LOW_BITS_MASK;
highBitsMask = ALL_COLOR_MASK & RGB_REMOVE_LOW_BITS_MASK;
colorMask = ((~RGB_HI_BITS_MASK & ALL_COLOR_MASK) << 16) | (~RGB_HI_BITS_MASK & ALL_COLOR_MASK);
#endif

return (TRUE);
}

Expand Down
9 changes: 0 additions & 9 deletions filter/hq2x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
#define trU 0x000700
#define trV 0x000006

#ifdef GFX_MULTI_FORMAT
static uint16 Mask_2 = 0, Mask13 = 0;
#else
#define Mask_2 SECOND_COLOR_MASK
#define Mask13 FIRST_THIRD_COLOR_MASK
#endif

#define Interp01(c1, c2) \
(c1 == c2) ? c1 : \
Expand Down Expand Up @@ -344,11 +340,6 @@ bool8 S9xBlitHQ2xFilterInit (void)
if (!RGBtoYUV)
return (FALSE);

#ifdef GFX_MULTI_FORMAT
Mask_2 = SECOND_COLOR_MASK;
Mask13 = FIRST_THIRD_COLOR_MASK;
#endif

InitLUTs();

return (TRUE);
Expand Down
154 changes: 1 addition & 153 deletions gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,25 @@ bool8 S9xGraphicsInit (void)
S9xInitTileRenderer();
memset(BlackColourMap, 0, 256 * sizeof(uint16));

#ifdef GFX_MULTI_FORMAT
if (GFX.BuildPixel == NULL)
S9xSetRenderPixelFormat(RGB565);
#endif

GFX.RealPPL = GFX.Pitch >> 1;
IPPU.OBJChanged = TRUE;
Settings.BG_Forced = 0;
S9xFixColourBrightness();
S9xBuildDirectColourMaps();

GFX.X2 = (uint16 *) malloc(sizeof(uint16) * 0x10000);
GFX.ZERO = (uint16 *) malloc(sizeof(uint16) * 0x10000);

GFX.ScreenSize = GFX.Pitch / 2 * SNES_HEIGHT_EXTENDED * (Settings.SupportHiRes ? 2 : 1);
GFX.SubScreen = (uint16 *) malloc(GFX.ScreenSize * sizeof(uint16));
GFX.ZBuffer = (uint8 *) malloc(GFX.ScreenSize);
GFX.SubZBuffer = (uint8 *) malloc(GFX.ScreenSize);

if (!GFX.X2 || !GFX.ZERO || !GFX.SubScreen || !GFX.ZBuffer || !GFX.SubZBuffer)
if (!GFX.ZERO || !GFX.SubScreen || !GFX.ZBuffer || !GFX.SubZBuffer)
{
S9xGraphicsDeinit();
return (FALSE);
}

// Lookup table for color addition
memset(GFX.X2, 0, 0x10000 * sizeof(uint16));
for (uint32 r = 0; r <= MAX_RED; r++)
{
uint32 r2 = r << 1;
if (r2 > MAX_RED)
r2 = MAX_RED;

for (uint32 g = 0; g <= MAX_GREEN; g++)
{
uint32 g2 = g << 1;
if (g2 > MAX_GREEN)
g2 = MAX_GREEN;

for (uint32 b = 0; b <= MAX_BLUE; b++)
{
uint32 b2 = b << 1;
if (b2 > MAX_BLUE)
b2 = MAX_BLUE;

GFX.X2[BUILD_PIXEL2(r, g, b)] = BUILD_PIXEL2(r2, g2, b2);
GFX.X2[BUILD_PIXEL2(r, g, b) & ~ALPHA_BITS_MASK] = BUILD_PIXEL2(r2, g2, b2);
}
}
}

// Lookup table for 1/2 color subtraction
memset(GFX.ZERO, 0, 0x10000 * sizeof(uint16));
for (uint32 r = 0; r <= MAX_RED; r++)
Expand Down Expand Up @@ -136,7 +104,6 @@ bool8 S9xGraphicsInit (void)

void S9xGraphicsDeinit (void)
{
if (GFX.X2) { free(GFX.X2); GFX.X2 = NULL; }
if (GFX.ZERO) { free(GFX.ZERO); GFX.ZERO = NULL; }
if (GFX.SubScreen) { free(GFX.SubScreen); GFX.SubScreen = NULL; }
if (GFX.ZBuffer) { free(GFX.ZBuffer); GFX.ZBuffer = NULL; }
Expand Down Expand Up @@ -2157,122 +2124,3 @@ void S9xDrawCrosshair (const char *crosshair, uint8 fgcolor, uint8 bgcolor, int1
}
}

#ifdef GFX_MULTI_FORMAT

static uint32 BuildPixelRGB565 (uint32, uint32, uint32);
static uint32 BuildPixelRGB555 (uint32, uint32, uint32);
static uint32 BuildPixelBGR565 (uint32, uint32, uint32);
static uint32 BuildPixelBGR555 (uint32, uint32, uint32);
static uint32 BuildPixelGBR565 (uint32, uint32, uint32);
static uint32 BuildPixelGBR555 (uint32, uint32, uint32);
static uint32 BuildPixelRGB5551 (uint32, uint32, uint32);

static uint32 BuildPixel2RGB565 (uint32, uint32, uint32);
static uint32 BuildPixel2RGB555 (uint32, uint32, uint32);
static uint32 BuildPixel2BGR565 (uint32, uint32, uint32);
static uint32 BuildPixel2BGR555 (uint32, uint32, uint32);
static uint32 BuildPixel2GBR565 (uint32, uint32, uint32);
static uint32 BuildPixel2GBR555 (uint32, uint32, uint32);
static uint32 BuildPixel2RGB5551 (uint32, uint32, uint32);

static void DecomposePixelRGB565 (uint32, uint32 &, uint32 &, uint32 &);
static void DecomposePixelRGB555 (uint32, uint32 &, uint32 &, uint32 &);
static void DecomposePixelBGR565 (uint32, uint32 &, uint32 &, uint32 &);
static void DecomposePixelBGR555 (uint32, uint32 &, uint32 &, uint32 &);
static void DecomposePixelGBR565 (uint32, uint32 &, uint32 &, uint32 &);
static void DecomposePixelGBR555 (uint32, uint32 &, uint32 &, uint32 &);
static void DecomposePixelRGB5551 (uint32, uint32 &, uint32 &, uint32 &);

#define _BUILD_PIXEL(F) \
static uint32 BuildPixel##F (uint32 R, uint32 G, uint32 B) \
{ \
return (BUILD_PIXEL_##F(R, G, B)); \
} \
\
static uint32 BuildPixel2##F (uint32 R, uint32 G, uint32 B) \
{ \
return (BUILD_PIXEL2_##F(R, G, B)); \
} \
\
static void DecomposePixel##F (uint32 pixel, uint32 &R, uint32 &G, uint32 &B) \
{ \
DECOMPOSE_PIXEL_##F(pixel, R, G, B); \
}

_BUILD_PIXEL(RGB565)
_BUILD_PIXEL(RGB555)
_BUILD_PIXEL(BGR565)
_BUILD_PIXEL(BGR555)
_BUILD_PIXEL(GBR565)
_BUILD_PIXEL(GBR555)
_BUILD_PIXEL(RGB5551)

#define _BUILD_SETUP(F) \
GFX.BuildPixel = BuildPixel##F; \
GFX.BuildPixel2 = BuildPixel2##F; \
GFX.DecomposePixel = DecomposePixel##F; \
RED_LOW_BIT_MASK = RED_LOW_BIT_MASK_##F; \
GREEN_LOW_BIT_MASK = GREEN_LOW_BIT_MASK_##F; \
BLUE_LOW_BIT_MASK = BLUE_LOW_BIT_MASK_##F; \
RED_HI_BIT_MASK = RED_HI_BIT_MASK_##F; \
GREEN_HI_BIT_MASK = GREEN_HI_BIT_MASK_##F; \
BLUE_HI_BIT_MASK = BLUE_HI_BIT_MASK_##F; \
MAX_RED = MAX_RED_##F; \
MAX_GREEN = MAX_GREEN_##F; \
MAX_BLUE = MAX_BLUE_##F; \
SPARE_RGB_BIT_MASK = SPARE_RGB_BIT_MASK_##F; \
GREEN_HI_BIT = ((MAX_GREEN_##F + 1) >> 1); \
RGB_LOW_BITS_MASK = (RED_LOW_BIT_MASK_##F | GREEN_LOW_BIT_MASK_##F | BLUE_LOW_BIT_MASK_##F); \
RGB_HI_BITS_MASK = (RED_HI_BIT_MASK_##F | GREEN_HI_BIT_MASK_##F | BLUE_HI_BIT_MASK_##F); \
RGB_HI_BITS_MASKx2 = (RED_HI_BIT_MASK_##F | GREEN_HI_BIT_MASK_##F | BLUE_HI_BIT_MASK_##F) << 1; \
RGB_REMOVE_LOW_BITS_MASK = ~RGB_LOW_BITS_MASK; \
FIRST_COLOR_MASK = FIRST_COLOR_MASK_##F; \
SECOND_COLOR_MASK = SECOND_COLOR_MASK_##F; \
THIRD_COLOR_MASK = THIRD_COLOR_MASK_##F; \
ALPHA_BITS_MASK = ALPHA_BITS_MASK_##F; \
FIRST_THIRD_COLOR_MASK = FIRST_COLOR_MASK | THIRD_COLOR_MASK; \
TWO_LOW_BITS_MASK = RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 1); \
HIGH_BITS_SHIFTED_TWO_MASK = ((FIRST_COLOR_MASK | SECOND_COLOR_MASK | THIRD_COLOR_MASK) & ~TWO_LOW_BITS_MASK) >> 2;

bool8 S9xSetRenderPixelFormat (int format)
{
GFX.PixelFormat = format;

switch (format)
{
case RGB565:
_BUILD_SETUP(RGB565)
return (TRUE);

case RGB555:
_BUILD_SETUP(RGB555)
return (TRUE);

case BGR565:
_BUILD_SETUP(BGR565)
return (TRUE);

case BGR555:
_BUILD_SETUP(BGR555)
return (TRUE);

case GBR565:
_BUILD_SETUP(GBR565)
return (TRUE);

case GBR555:
_BUILD_SETUP(GBR555)
return (TRUE);

case RGB5551:
_BUILD_SETUP(RGB5551)
return (TRUE);

default:
break;
}

return (FALSE);
}

#endif
22 changes: 0 additions & 22 deletions gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct SGFX
uint32 ScreenSize;
uint16 *S;
uint8 *DB;
uint16 *X2;
uint16 *ZERO;
uint32 RealPPL; // true PPL of Screen buffer
uint32 PPL; // number of pixels on each of Screen buffer
Expand Down Expand Up @@ -51,13 +50,6 @@ struct SGFX
} OBJ[32];
} OBJLines[SNES_HEIGHT_EXTENDED];

#ifdef GFX_MULTI_FORMAT
uint32 PixelFormat;
uint32 (*BuildPixel) (uint32, uint32, uint32);
uint32 (*BuildPixel2) (uint32, uint32, uint32);
void (*DecomposePixel) (uint32, uint32 &, uint32 &, uint32 &);
#endif

void (*DrawBackdropMath) (uint32, uint32, uint32);
void (*DrawBackdropNomath) (uint32, uint32, uint32);
void (*DrawTileMath) (uint32, uint32, uint32, uint32);
Expand Down Expand Up @@ -140,24 +132,13 @@ extern struct SGFX GFX;
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
((C1) & (C2) & RGB_LOW_BITS_MASK)) | ALPHA_BITS_MASK)

#ifdef GFX_MULTI_FORMAT
#define COLOR_ADD(C1, C2) \
(GFX.X2[((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
((C1) & (C2) & RGB_LOW_BITS_MASK)] | \
(((C1) ^ (C2)) & RGB_LOW_BITS_MASK))

#else

inline uint16 COLOR_ADD(uint16 C1, uint16 C2)
{
return ((brightness_cap[ (C1 >> RED_SHIFT_BITS) + (C2 >> RED_SHIFT_BITS) ] << RED_SHIFT_BITS) |
(brightness_cap[((C1 >> GREEN_SHIFT_BITS) & 0x1f) + ((C2 >> GREEN_SHIFT_BITS) & 0x1f)] << GREEN_SHIFT_BITS) |
(brightness_cap[ (C1 & 0x1f) + (C2 & 0x1f)] ));
}

#endif // GFX_MULTI_FORMAT

#define COLOR_SUB1_2(C1, C2) \
GFX.ZERO[(((C1) | RGB_HI_BITS_MASKx2) - \
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
Expand Down Expand Up @@ -190,9 +171,6 @@ void S9xDisplayChar (uint16 *, uint8);
void S9xGraphicsScreenResize (void);
// called automatically unless Settings.AutoDisplayMessages is false
void S9xDisplayMessages (uint16 *, int, int, int, int);
#ifdef GFX_MULTI_FORMAT
bool8 S9xSetRenderPixelFormat (int);
#endif

// external port interface which must be implemented or initialised for each port
bool8 S9xGraphicsInit (void);
Expand Down
25 changes: 0 additions & 25 deletions globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,6 @@ SnesModel M1SNES = { 1, 3, 2 };
SnesModel M2SNES = { 2, 4, 3 };
SnesModel *Model = &M1SNES;

#ifdef GFX_MULTI_FORMAT
uint32 RED_LOW_BIT_MASK = RED_LOW_BIT_MASK_RGB565;
uint32 GREEN_LOW_BIT_MASK = GREEN_LOW_BIT_MASK_RGB565;
uint32 BLUE_LOW_BIT_MASK = BLUE_LOW_BIT_MASK_RGB565;
uint32 RED_HI_BIT_MASK = RED_HI_BIT_MASK_RGB565;
uint32 GREEN_HI_BIT_MASK = GREEN_HI_BIT_MASK_RGB565;
uint32 BLUE_HI_BIT_MASK = BLUE_HI_BIT_MASK_RGB565;
uint32 MAX_RED = MAX_RED_RGB565;
uint32 MAX_GREEN = MAX_GREEN_RGB565;
uint32 MAX_BLUE = MAX_BLUE_RGB565;
uint32 SPARE_RGB_BIT_MASK = SPARE_RGB_BIT_MASK_RGB565;
uint32 GREEN_HI_BIT = (MAX_GREEN_RGB565 + 1) >> 1;
uint32 RGB_LOW_BITS_MASK = (RED_LOW_BIT_MASK_RGB565 | GREEN_LOW_BIT_MASK_RGB565 | BLUE_LOW_BIT_MASK_RGB565);
uint32 RGB_HI_BITS_MASK = (RED_HI_BIT_MASK_RGB565 | GREEN_HI_BIT_MASK_RGB565 | BLUE_HI_BIT_MASK_RGB565);
uint32 RGB_HI_BITS_MASKx2 = (RED_HI_BIT_MASK_RGB565 | GREEN_HI_BIT_MASK_RGB565 | BLUE_HI_BIT_MASK_RGB565) << 1;
uint32 RGB_REMOVE_LOW_BITS_MASK = ~RGB_LOW_BITS_MASK;
uint32 FIRST_COLOR_MASK = FIRST_COLOR_MASK_RGB565;
uint32 SECOND_COLOR_MASK = SECOND_COLOR_MASK_RGB565;
uint32 THIRD_COLOR_MASK = THIRD_COLOR_MASK_RGB565;
uint32 ALPHA_BITS_MASK = ALPHA_BITS_MASK_RGB565;
uint32 FIRST_THIRD_COLOR_MASK = 0;
uint32 TWO_LOW_BITS_MASK = 0;
uint32 HIGH_BITS_SHIFTED_TWO_MASK = 0;
#endif

uint16 SignExtend[2] =
{
0x0000,
Expand Down
Loading

0 comments on commit 76b6342

Please sign in to comment.