Remove extraneous macros by adding a palette variable

This commit is contained in:
Jeffrey Pfau 2013-10-10 23:33:22 -07:00
parent e789b324dc
commit cff77a3a81
1 changed files with 60 additions and 132 deletions

View File

@ -633,42 +633,22 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
} }
} }
#define BACKGROUND_DRAW_PIXEL_16_NORMAL \ #define BACKGROUND_DRAW_PIXEL_16 \
pixelData = tileData & 0xF; \
current = renderer->row[outX]; \
if (pixelData && !(current & FLAG_FINALIZED)) { \
if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \
_composite(renderer, outX, renderer->normalPalette[pixelData | paletteData] | flags, current); \
} \
} \
tileData >>= 4;
#define BACKGROUND_DRAW_PIXEL_16_VARIANT \
pixelData = tileData & 0xF; \ pixelData = tileData & 0xF; \
current = renderer->row[outX]; \ current = renderer->row[outX]; \
if (tileData & 0xF && !(current & FLAG_FINALIZED)) { \ if (tileData & 0xF && !(current & FLAG_FINALIZED)) { \
if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \ if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \
_composite(renderer, outX, renderer->variantPalette[pixelData | paletteData] | flags, current); \ _composite(renderer, outX, palette[pixelData | paletteData] | flags, current); \
} \ } \
} \ } \
tileData >>= 4; tileData >>= 4;
#define BACKGROUND_DRAW_PIXEL_256_NORMAL \ #define BACKGROUND_DRAW_PIXEL_256 \
pixelData = tileData & 0xFF; \ pixelData = tileData & 0xFF; \
current = renderer->row[outX]; \ current = renderer->row[outX]; \
if (pixelData && !(current & FLAG_FINALIZED)) { \ if (pixelData && !(current & FLAG_FINALIZED)) { \
if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \ if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \
_composite(renderer, outX, renderer->normalPalette[pixelData] | flags, current); \ _composite(renderer, outX, palette[pixelData] | flags, current); \
} \
} \
tileData >>= 8;
#define BACKGROUND_DRAW_PIXEL_256_VARIANT \
pixelData = tileData & 0xFF; \
current = renderer->row[outX]; \
if (pixelData && !(renderer->row[outX] & FLAG_FINALIZED)) { \
if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \
_composite(renderer, outX, renderer->variantPalette[pixelData] | flags, current); \
} \ } \
} \ } \
tileData >>= 8; tileData >>= 8;
@ -687,7 +667,7 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
localY = 7 - (inY & 0x7); \ localY = 7 - (inY & 0x7); \
} }
#define BACKGROUND_MODE_0_TILE_16_LOOP(TYPE) \ #define BACKGROUND_MODE_0_TILE_16_LOOP \
uint32_t tileData; \ uint32_t tileData; \
uint32_t current; \ uint32_t current; \
int paletteData, pixelData; \ int paletteData, pixelData; \
@ -698,39 +678,39 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
tileData = ((uint32_t*)renderer->d.vram)[charBase]; \ tileData = ((uint32_t*)renderer->d.vram)[charBase]; \
if (tileData) { \ if (tileData) { \
if (!mapData.hflip) { \ if (!mapData.hflip) { \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
++outX; \ ++outX; \
} else { \ } else { \
outX += 7; \ outX += 7; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_16; \
outX += 8; \ outX += 8; \
} \ } \
} else { \ } else { \
@ -738,7 +718,7 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
} \ } \
} }
#define BACKGROUND_MODE_0_TILE_256_LOOP(TYPE) \ #define BACKGROUND_MODE_0_TILE_256_LOOP \
uint32_t tileData; \ uint32_t tileData; \
uint32_t current; \ uint32_t current; \
int pixelData; \ int pixelData; \
@ -748,26 +728,26 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
if (!mapData.hflip) { \ if (!mapData.hflip) { \
tileData = ((uint32_t*)renderer->d.vram)[charBase]; \ tileData = ((uint32_t*)renderer->d.vram)[charBase]; \
if (tileData) { \ if (tileData) { \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
++outX; \ ++outX; \
} else { \ } else { \
outX += 4; \ outX += 4; \
} \ } \
tileData = ((uint32_t*)renderer->d.vram)[charBase + 1]; \ tileData = ((uint32_t*)renderer->d.vram)[charBase + 1]; \
if (tileData) { \ if (tileData) { \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
++outX; \ ++outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
++outX; \ ++outX; \
} else { \ } else { \
outX += 4; \ outX += 4; \
@ -776,13 +756,13 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
uint32_t tileData = ((uint32_t*)renderer->d.vram)[charBase + 1]; \ uint32_t tileData = ((uint32_t*)renderer->d.vram)[charBase + 1]; \
if (tileData) { \ if (tileData) { \
outX += 3; \ outX += 3; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
outX += 4; \ outX += 4; \
} else { \ } else { \
outX += 4; \ outX += 4; \
@ -790,13 +770,13 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
tileData = ((uint32_t*)renderer->d.vram)[charBase]; \ tileData = ((uint32_t*)renderer->d.vram)[charBase]; \
if (tileData) { \ if (tileData) { \
outX += 3; \ outX += 3; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
--outX; \ --outX; \
BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ BACKGROUND_DRAW_PIXEL_256; \
outX += 4; \ outX += 4; \
} else { \ } else { \
outX += 4; \ outX += 4; \
@ -853,6 +833,10 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
uint32_t screenBase; uint32_t screenBase;
uint32_t charBase; uint32_t charBase;
int variant = background->target1 && renderer->currentWindow.blendEnable && (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN); int variant = background->target1 && renderer->currentWindow.blendEnable && (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN);
color_t* palette = renderer->normalPalette;
if (variant) {
palette = renderer->variantPalette;
}
int outX = renderer->start; int outX = renderer->start;
int tileX = 0; int tileX = 0;
@ -871,24 +855,12 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
tileData = ((uint32_t*)renderer->d.vram)[charBase]; tileData = ((uint32_t*)renderer->d.vram)[charBase];
if (!mapData.hflip) { if (!mapData.hflip) {
tileData >>= 4 * mod8; tileData >>= 4 * mod8;
if (!variant) { for (; outX < end; ++outX) {
for (; outX < end; ++outX) { BACKGROUND_DRAW_PIXEL_16;
BACKGROUND_DRAW_PIXEL_16_NORMAL;
}
} else {
for (; outX < end; ++outX) {
BACKGROUND_DRAW_PIXEL_16_VARIANT;
}
} }
} else { } else {
if (!variant) { for (outX = end - 1; outX >= renderer->start; --outX) {
for (outX = end - 1; outX >= renderer->start; --outX) { BACKGROUND_DRAW_PIXEL_16;
BACKGROUND_DRAW_PIXEL_16_NORMAL;
}
} else {
for (outX = end - 1; outX >= renderer->start; --outX) {
BACKGROUND_DRAW_PIXEL_16_VARIANT;
}
} }
} }
} else { } else {
@ -900,27 +872,15 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
tileData = ((uint32_t*)renderer->d.vram)[charBase]; tileData = ((uint32_t*)renderer->d.vram)[charBase];
tileData >>= 8 * shift; tileData >>= 8 * shift;
shift = 0; shift = 0;
if (!variant) { for (; outX < end2; ++outX) {
for (; outX < end2; ++outX) { BACKGROUND_DRAW_PIXEL_256;
BACKGROUND_DRAW_PIXEL_256_NORMAL;
}
} else {
for (; outX < end2; ++outX) {
BACKGROUND_DRAW_PIXEL_256_VARIANT;
}
} }
} }
tileData = ((uint32_t*)renderer->d.vram)[charBase + 1]; tileData = ((uint32_t*)renderer->d.vram)[charBase + 1];
tileData >>= 8 * shift; tileData >>= 8 * shift;
if (!variant) { for (; outX < end; ++outX) {
for (; outX < end; ++outX) { BACKGROUND_DRAW_PIXEL_256;
BACKGROUND_DRAW_PIXEL_256_NORMAL;
}
} else {
for (; outX < end; ++outX) {
BACKGROUND_DRAW_PIXEL_256_VARIANT;
}
} }
} }
} }
@ -943,14 +903,8 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
tileData >>= 4 * -outX; tileData >>= 4 * -outX;
outX = 0; outX = 0;
} }
if (!variant) { for (; outX < renderer->end; ++outX) {
for (; outX < renderer->end; ++outX) { BACKGROUND_DRAW_PIXEL_16;
BACKGROUND_DRAW_PIXEL_16_NORMAL;
}
} else {
for (; outX < renderer->end; ++outX) {
BACKGROUND_DRAW_PIXEL_16_VARIANT;
}
} }
} else { } else {
tileData >>= 4 * (0x8 - mod8); tileData >>= 4 * (0x8 - mod8);
@ -958,14 +912,8 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
if (end2 < -1) { if (end2 < -1) {
end2 = -1; end2 = -1;
} }
if (!variant) { for (outX = renderer->end - 1; outX > end2; --outX) {
for (outX = renderer->end - 1; outX > end2; --outX) { BACKGROUND_DRAW_PIXEL_16;
BACKGROUND_DRAW_PIXEL_16_NORMAL;
}
} else {
for (outX = renderer->end - 1; outX > end2; --outX) {
BACKGROUND_DRAW_PIXEL_16_VARIANT;
}
} }
} }
} else { } else {
@ -975,27 +923,15 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
int end2 = 4 - end; int end2 = 4 - end;
if (end2 > 0) { if (end2 > 0) {
tileData = ((uint32_t*)renderer->d.vram)[charBase]; tileData = ((uint32_t*)renderer->d.vram)[charBase];
if (!variant) { for (; outX < renderer->end - end2; ++outX) {
for (; outX < renderer->end - end2; ++outX) { BACKGROUND_DRAW_PIXEL_256;
BACKGROUND_DRAW_PIXEL_256_NORMAL;
}
} else {
for (; outX < renderer->end - end2; ++outX) {
BACKGROUND_DRAW_PIXEL_256_VARIANT;
}
} }
++charBase; ++charBase;
} }
tileData = ((uint32_t*)renderer->d.vram)[charBase]; tileData = ((uint32_t*)renderer->d.vram)[charBase];
if (!variant) { for (; outX < renderer->end; ++outX) {
for (; outX < renderer->end; ++outX) { BACKGROUND_DRAW_PIXEL_256;
BACKGROUND_DRAW_PIXEL_256_NORMAL;
}
} else {
for (; outX < renderer->end; ++outX) {
BACKGROUND_DRAW_PIXEL_256_VARIANT;
}
} }
} }
@ -1004,17 +940,9 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
} }
if (!background->multipalette) { if (!background->multipalette) {
if (!variant) { BACKGROUND_MODE_0_TILE_16_LOOP;
BACKGROUND_MODE_0_TILE_16_LOOP(NORMAL);
} else {
BACKGROUND_MODE_0_TILE_16_LOOP(VARIANT);
}
} else { } else {
if (!variant) { BACKGROUND_MODE_0_TILE_256_LOOP;
BACKGROUND_MODE_0_TILE_256_LOOP(NORMAL);
} else {
BACKGROUND_MODE_0_TILE_256_LOOP(VARIANT);
}
} }
} }