mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-12-24 18:21:50 +01:00
Snes9x - Use for loops for DRAW_TILE. 3-4% speed benefit. Backport Select brightness function in tile renderer. (#828)
- Use for loops for DRAW_TILE. 3-4% speed benefit. - Select brightness function in tile renderer.
This commit is contained in:
parent
6dcba441ea
commit
56fb0046ba
@ -131,8 +131,9 @@ extern struct SGFX GFX;
|
|||||||
((((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
|
((((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
|
||||||
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
|
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
|
||||||
((C1) & (C2) & RGB_LOW_BITS_MASK)) | ALPHA_BITS_MASK)
|
((C1) & (C2) & RGB_LOW_BITS_MASK)) | ALPHA_BITS_MASK)
|
||||||
|
#define COLOR_ADD_BRIGHTNESS1_2 COLOR_ADD1_2
|
||||||
|
|
||||||
inline uint16 COLOR_ADD(uint16 C1, uint16 C2)
|
inline uint16 COLOR_ADD_BRIGHTNESS(uint16 C1, uint16 C2)
|
||||||
{
|
{
|
||||||
return ((brightness_cap[ (C1 >> RED_SHIFT_BITS) + (C2 >> RED_SHIFT_BITS) ] << RED_SHIFT_BITS) |
|
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 >> GREEN_SHIFT_BITS) & 0x1f) + ((C2 >> GREEN_SHIFT_BITS) & 0x1f)] << GREEN_SHIFT_BITS) |
|
||||||
@ -143,27 +144,39 @@ inline uint16 COLOR_ADD(uint16 C1, uint16 C2)
|
|||||||
(brightness_cap[ (C1 & 0x1f) + (C2 & 0x1f)] ));
|
(brightness_cap[ (C1 & 0x1f) + (C2 & 0x1f)] ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline uint16 COLOR_ADD(uint16 C1, uint16 C2)
|
||||||
|
{
|
||||||
|
const int RED_MASK = 0x1F << RED_SHIFT_BITS;
|
||||||
|
const int GREEN_MASK = 0x1F << GREEN_SHIFT_BITS;
|
||||||
|
const int BLUE_MASK = 0x1F;
|
||||||
|
|
||||||
|
int rb = C1 & (RED_MASK | BLUE_MASK);
|
||||||
|
rb += C2 & (RED_MASK | BLUE_MASK);
|
||||||
|
int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0));
|
||||||
|
int g = (C1 & (GREEN_MASK)) + (C2 & (GREEN_MASK));
|
||||||
|
int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f;
|
||||||
|
return (uint16)((rb & (RED_MASK | BLUE_MASK)) | (g & GREEN_MASK) | rgbsaturate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define COLOR_SUB1_2(C1, C2) \
|
#define COLOR_SUB1_2(C1, C2) \
|
||||||
GFX.ZERO[(((C1) | RGB_HI_BITS_MASKx2) - \
|
GFX.ZERO[(((C1) | RGB_HI_BITS_MASKx2) - \
|
||||||
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
|
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1]
|
||||||
|
|
||||||
inline uint16 COLOR_SUB (uint16 C1, uint16 C2)
|
inline uint16 COLOR_SUB (uint16 C1, uint16 C2)
|
||||||
{
|
{
|
||||||
uint16 mC1, mC2, v = ALPHA_BITS_MASK;
|
int a = (C1 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | ((0x20 << 0) | (0x20 << RED_SHIFT_BITS));
|
||||||
|
int b = C2 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK);
|
||||||
mC1 = C1 & FIRST_COLOR_MASK;
|
int c = a - b;
|
||||||
mC2 = C2 & FIRST_COLOR_MASK;
|
int d = c & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0));
|
||||||
if (mC1 > mC2) v += (mC1 - mC2);
|
int e = (C1 & (SECOND_COLOR_MASK)) | (0x20 << GREEN_SHIFT_BITS);
|
||||||
|
int f = C2 & (SECOND_COLOR_MASK);
|
||||||
mC1 = C1 & SECOND_COLOR_MASK;
|
int g = e - f;
|
||||||
mC2 = C2 & SECOND_COLOR_MASK;
|
int h = (g & (0x20 << GREEN_SHIFT_BITS)) | d;
|
||||||
if (mC1 > mC2) v += (mC1 - mC2);
|
int i = h >> 5;
|
||||||
|
int j = i * 0x1F;
|
||||||
mC1 = C1 & THIRD_COLOR_MASK;
|
int k = ((c & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | (g & SECOND_COLOR_MASK)) & j;
|
||||||
mC2 = C2 & THIRD_COLOR_MASK;
|
return (uint16)k;
|
||||||
if (mC1 > mC2) v += (mC1 - mC2);
|
|
||||||
|
|
||||||
return (v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void S9xStartScreenRefresh (void);
|
void S9xStartScreenRefresh (void);
|
||||||
|
@ -21,7 +21,6 @@ static uint32 pixbit[8][16];
|
|||||||
static uint8 hrbit_odd[256];
|
static uint8 hrbit_odd[256];
|
||||||
static uint8 hrbit_even[256];
|
static uint8 hrbit_even[256];
|
||||||
|
|
||||||
|
|
||||||
void S9xInitTileRenderer (void)
|
void S9xInitTileRenderer (void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -400,6 +399,14 @@ void S9xSelectTileRenderers (int BGMode, bool8 sub, bool8 obj)
|
|||||||
if (Memory.FillRAM[0x2130] & 2)
|
if (Memory.FillRAM[0x2130] & 2)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if (IPPU.MaxBrightness != 0xf)
|
||||||
|
{
|
||||||
|
if (i == 1)
|
||||||
|
i = 7;
|
||||||
|
else if (i == 3)
|
||||||
|
i = 8;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GFX.DrawTileMath = DT[i];
|
GFX.DrawTileMath = DT[i];
|
||||||
@ -578,14 +585,9 @@ void S9xSelectTileConverter (int depth, bool8 hires, bool8 sub, bool8 mosaic)
|
|||||||
OFFSET_IN_LINE; \
|
OFFSET_IN_LINE; \
|
||||||
for (l = LineCount; l > 0; l--, bp += 8 * PITCH, Offset += GFX.PPL) \
|
for (l = LineCount; l > 0; l--, bp += 8 * PITCH, Offset += GFX.PPL) \
|
||||||
{ \
|
{ \
|
||||||
DRAW_PIXEL(0, Pix = bp[0]); \
|
for (int x = 0; x < 8; x++) { \
|
||||||
DRAW_PIXEL(1, Pix = bp[1]); \
|
DRAW_PIXEL(x, Pix = bp[x]); \
|
||||||
DRAW_PIXEL(2, Pix = bp[2]); \
|
} \
|
||||||
DRAW_PIXEL(3, Pix = bp[3]); \
|
|
||||||
DRAW_PIXEL(4, Pix = bp[4]); \
|
|
||||||
DRAW_PIXEL(5, Pix = bp[5]); \
|
|
||||||
DRAW_PIXEL(6, Pix = bp[6]); \
|
|
||||||
DRAW_PIXEL(7, Pix = bp[7]); \
|
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
@ -595,14 +597,9 @@ void S9xSelectTileConverter (int depth, bool8 hires, bool8 sub, bool8 mosaic)
|
|||||||
OFFSET_IN_LINE; \
|
OFFSET_IN_LINE; \
|
||||||
for (l = LineCount; l > 0; l--, bp += 8 * PITCH, Offset += GFX.PPL) \
|
for (l = LineCount; l > 0; l--, bp += 8 * PITCH, Offset += GFX.PPL) \
|
||||||
{ \
|
{ \
|
||||||
DRAW_PIXEL(0, Pix = bp[7]); \
|
for (int x = 0; x < 8; x++) { \
|
||||||
DRAW_PIXEL(1, Pix = bp[6]); \
|
DRAW_PIXEL(x, Pix = bp[7 - x]); \
|
||||||
DRAW_PIXEL(2, Pix = bp[5]); \
|
} \
|
||||||
DRAW_PIXEL(3, Pix = bp[4]); \
|
|
||||||
DRAW_PIXEL(4, Pix = bp[3]); \
|
|
||||||
DRAW_PIXEL(5, Pix = bp[2]); \
|
|
||||||
DRAW_PIXEL(6, Pix = bp[1]); \
|
|
||||||
DRAW_PIXEL(7, Pix = bp[0]); \
|
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
@ -612,14 +609,9 @@ void S9xSelectTileConverter (int depth, bool8 hires, bool8 sub, bool8 mosaic)
|
|||||||
OFFSET_IN_LINE; \
|
OFFSET_IN_LINE; \
|
||||||
for (l = LineCount; l > 0; l--, bp -= 8 * PITCH, Offset += GFX.PPL) \
|
for (l = LineCount; l > 0; l--, bp -= 8 * PITCH, Offset += GFX.PPL) \
|
||||||
{ \
|
{ \
|
||||||
DRAW_PIXEL(0, Pix = bp[0]); \
|
for (int x = 0; x < 8; x++) { \
|
||||||
DRAW_PIXEL(1, Pix = bp[1]); \
|
DRAW_PIXEL(x, Pix = bp[x]); \
|
||||||
DRAW_PIXEL(2, Pix = bp[2]); \
|
} \
|
||||||
DRAW_PIXEL(3, Pix = bp[3]); \
|
|
||||||
DRAW_PIXEL(4, Pix = bp[4]); \
|
|
||||||
DRAW_PIXEL(5, Pix = bp[5]); \
|
|
||||||
DRAW_PIXEL(6, Pix = bp[6]); \
|
|
||||||
DRAW_PIXEL(7, Pix = bp[7]); \
|
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
@ -628,14 +620,9 @@ void S9xSelectTileConverter (int depth, bool8 hires, bool8 sub, bool8 mosaic)
|
|||||||
OFFSET_IN_LINE; \
|
OFFSET_IN_LINE; \
|
||||||
for (l = LineCount; l > 0; l--, bp -= 8 * PITCH, Offset += GFX.PPL) \
|
for (l = LineCount; l > 0; l--, bp -= 8 * PITCH, Offset += GFX.PPL) \
|
||||||
{ \
|
{ \
|
||||||
DRAW_PIXEL(0, Pix = bp[7]); \
|
for (int x = 0; x < 8; x++) { \
|
||||||
DRAW_PIXEL(1, Pix = bp[6]); \
|
DRAW_PIXEL(x, Pix = bp[7 - x]); \
|
||||||
DRAW_PIXEL(2, Pix = bp[5]); \
|
} \
|
||||||
DRAW_PIXEL(3, Pix = bp[4]); \
|
|
||||||
DRAW_PIXEL(4, Pix = bp[3]); \
|
|
||||||
DRAW_PIXEL(5, Pix = bp[2]); \
|
|
||||||
DRAW_PIXEL(6, Pix = bp[1]); \
|
|
||||||
DRAW_PIXEL(7, Pix = bp[0]); \
|
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1307,6 +1294,13 @@ static void MAKENAME(NAME1, Add_, NAME2) (ARGS)
|
|||||||
#undef MATH
|
#undef MATH
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void MAKENAME(NAME1, Add_Brightness_, NAME2) (ARGS)
|
||||||
|
{
|
||||||
|
#define MATH(A, B, C) REGMATH(ADD_BRIGHTNESS, A, B, C)
|
||||||
|
DRAW_TILE();
|
||||||
|
#undef MATH
|
||||||
|
}
|
||||||
|
|
||||||
static void MAKENAME(NAME1, AddF1_2_, NAME2) (ARGS)
|
static void MAKENAME(NAME1, AddF1_2_, NAME2) (ARGS)
|
||||||
{
|
{
|
||||||
#define MATH(A, B, C) MATHF1_2(ADD, A, B, C)
|
#define MATH(A, B, C) MATHF1_2(ADD, A, B, C)
|
||||||
@ -1321,6 +1315,13 @@ static void MAKENAME(NAME1, AddS1_2_, NAME2) (ARGS)
|
|||||||
#undef MATH
|
#undef MATH
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void MAKENAME(NAME1, AddS1_2_Brightness_, NAME2) (ARGS)
|
||||||
|
{
|
||||||
|
#define MATH(A, B, C) MATHS1_2(ADD_BRIGHTNESS, A, B, C)
|
||||||
|
DRAW_TILE();
|
||||||
|
#undef MATH
|
||||||
|
}
|
||||||
|
|
||||||
static void MAKENAME(NAME1, Sub_, NAME2) (ARGS)
|
static void MAKENAME(NAME1, Sub_, NAME2) (ARGS)
|
||||||
{
|
{
|
||||||
#define MATH(A, B, C) REGMATH(SUB, A, B, C)
|
#define MATH(A, B, C) REGMATH(SUB, A, B, C)
|
||||||
@ -1342,7 +1343,7 @@ static void MAKENAME(NAME1, SubS1_2_, NAME2) (ARGS)
|
|||||||
#undef MATH
|
#undef MATH
|
||||||
}
|
}
|
||||||
|
|
||||||
static void (*MAKENAME(Renderers_, NAME1, NAME2)[7]) (ARGS) =
|
static void (*MAKENAME(Renderers_, NAME1, NAME2)[9]) (ARGS) =
|
||||||
{
|
{
|
||||||
MAKENAME(NAME1, _, NAME2),
|
MAKENAME(NAME1, _, NAME2),
|
||||||
MAKENAME(NAME1, Add_, NAME2),
|
MAKENAME(NAME1, Add_, NAME2),
|
||||||
@ -1350,7 +1351,9 @@ static void (*MAKENAME(Renderers_, NAME1, NAME2)[7]) (ARGS) =
|
|||||||
MAKENAME(NAME1, AddS1_2_, NAME2),
|
MAKENAME(NAME1, AddS1_2_, NAME2),
|
||||||
MAKENAME(NAME1, Sub_, NAME2),
|
MAKENAME(NAME1, Sub_, NAME2),
|
||||||
MAKENAME(NAME1, SubF1_2_, NAME2),
|
MAKENAME(NAME1, SubF1_2_, NAME2),
|
||||||
MAKENAME(NAME1, SubS1_2_, NAME2)
|
MAKENAME(NAME1, SubS1_2_, NAME2),
|
||||||
|
MAKENAME(NAME1, Add_Brightness_, NAME2),
|
||||||
|
MAKENAME(NAME1, AddS1_2_Brightness_, NAME2)
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef MAKENAME
|
#undef MAKENAME
|
||||||
|
Loading…
Reference in New Issue
Block a user