all repos — mgba @ cff77a3a81434c47c88d02b030a185c8171d0b1f

mGBA Game Boy Advance Emulator

Remove extraneous macros by adding a palette variable
Jeffrey Pfau jeffrey@endrift.com
Thu, 10 Oct 2013 23:33:22 -0700
commit

cff77a3a81434c47c88d02b030a185c8171d0b1f

parent

e789b324dcc2a502dc92d521c139e34584d3a996

1 files changed, 60 insertions(+), 132 deletions(-)

jump to
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -633,42 +633,22 @@ }

} } -#define BACKGROUND_DRAW_PIXEL_16_NORMAL \ - 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 \ +#define BACKGROUND_DRAW_PIXEL_16 \ pixelData = tileData & 0xF; \ current = renderer->row[outX]; \ if (tileData & 0xF && !(current & FLAG_FINALIZED)) { \ 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; -#define BACKGROUND_DRAW_PIXEL_256_NORMAL \ +#define BACKGROUND_DRAW_PIXEL_256 \ pixelData = tileData & 0xFF; \ current = renderer->row[outX]; \ if (pixelData && !(current & FLAG_FINALIZED)) { \ if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \ - _composite(renderer, outX, renderer->normalPalette[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); \ + _composite(renderer, outX, palette[pixelData] | flags, current); \ } \ } \ tileData >>= 8;

@@ -687,7 +667,7 @@ } else { \

localY = 7 - (inY & 0x7); \ } -#define BACKGROUND_MODE_0_TILE_16_LOOP(TYPE) \ +#define BACKGROUND_MODE_0_TILE_16_LOOP \ uint32_t tileData; \ uint32_t current; \ int paletteData, pixelData; \

@@ -698,39 +678,39 @@ charBase = ((background->charBase + (mapData.tile << 5)) >> 2) + localY; \

tileData = ((uint32_t*)renderer->d.vram)[charBase]; \ if (tileData) { \ if (!mapData.hflip) { \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ ++outX; \ } else { \ outX += 7; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ --outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ --outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ --outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ --outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ --outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ --outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ --outX; \ - BACKGROUND_DRAW_PIXEL_16_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_16; \ outX += 8; \ } \ } else { \

@@ -738,7 +718,7 @@ outX += 8; \

} \ } -#define BACKGROUND_MODE_0_TILE_256_LOOP(TYPE) \ +#define BACKGROUND_MODE_0_TILE_256_LOOP \ uint32_t tileData; \ uint32_t current; \ int pixelData; \

@@ -748,26 +728,26 @@ charBase = ((background->charBase + (mapData.tile << 6)) >> 2) + (localY << 1); \

if (!mapData.hflip) { \ tileData = ((uint32_t*)renderer->d.vram)[charBase]; \ if (tileData) { \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ ++outX; \ } else { \ outX += 4; \ } \ tileData = ((uint32_t*)renderer->d.vram)[charBase + 1]; \ if (tileData) { \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ ++outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ ++outX; \ } else { \ outX += 4; \

@@ -776,13 +756,13 @@ } else { \

uint32_t tileData = ((uint32_t*)renderer->d.vram)[charBase + 1]; \ if (tileData) { \ outX += 3; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ --outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ --outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ --outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ outX += 4; \ } else { \ outX += 4; \

@@ -790,13 +770,13 @@ } \

tileData = ((uint32_t*)renderer->d.vram)[charBase]; \ if (tileData) { \ outX += 3; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ --outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ --outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ --outX; \ - BACKGROUND_DRAW_PIXEL_256_ ## TYPE; \ + BACKGROUND_DRAW_PIXEL_256; \ outX += 4; \ } else { \ outX += 4; \

@@ -853,6 +833,10 @@

uint32_t screenBase; uint32_t charBase; 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 tileX = 0;

@@ -871,24 +855,12 @@ charBase = ((background->charBase + (mapData.tile << 5)) >> 2) + localY;

tileData = ((uint32_t*)renderer->d.vram)[charBase]; if (!mapData.hflip) { tileData >>= 4 * mod8; - if (!variant) { - for (; outX < end; ++outX) { - BACKGROUND_DRAW_PIXEL_16_NORMAL; - } - } else { - for (; outX < end; ++outX) { - BACKGROUND_DRAW_PIXEL_16_VARIANT; - } + for (; outX < end; ++outX) { + BACKGROUND_DRAW_PIXEL_16; } } else { - if (!variant) { - for (outX = end - 1; outX >= renderer->start; --outX) { - BACKGROUND_DRAW_PIXEL_16_NORMAL; - } - } else { - for (outX = end - 1; outX >= renderer->start; --outX) { - BACKGROUND_DRAW_PIXEL_16_VARIANT; - } + for (outX = end - 1; outX >= renderer->start; --outX) { + BACKGROUND_DRAW_PIXEL_16; } } } else {

@@ -900,27 +872,15 @@ if (end2 > 0) {

tileData = ((uint32_t*)renderer->d.vram)[charBase]; tileData >>= 8 * shift; shift = 0; - if (!variant) { - for (; outX < end2; ++outX) { - BACKGROUND_DRAW_PIXEL_256_NORMAL; - } - } else { - for (; outX < end2; ++outX) { - BACKGROUND_DRAW_PIXEL_256_VARIANT; - } + for (; outX < end2; ++outX) { + BACKGROUND_DRAW_PIXEL_256; } } tileData = ((uint32_t*)renderer->d.vram)[charBase + 1]; tileData >>= 8 * shift; - if (!variant) { - for (; outX < end; ++outX) { - BACKGROUND_DRAW_PIXEL_256_NORMAL; - } - } else { - for (; outX < end; ++outX) { - BACKGROUND_DRAW_PIXEL_256_VARIANT; - } + for (; outX < end; ++outX) { + BACKGROUND_DRAW_PIXEL_256; } } }

@@ -943,14 +903,8 @@ if (outX < 0) {

tileData >>= 4 * -outX; outX = 0; } - if (!variant) { - for (; outX < renderer->end; ++outX) { - BACKGROUND_DRAW_PIXEL_16_NORMAL; - } - } else { - for (; outX < renderer->end; ++outX) { - BACKGROUND_DRAW_PIXEL_16_VARIANT; - } + for (; outX < renderer->end; ++outX) { + BACKGROUND_DRAW_PIXEL_16; } } else { tileData >>= 4 * (0x8 - mod8);

@@ -958,14 +912,8 @@ int end2 = renderer->end - 8;

if (end2 < -1) { end2 = -1; } - if (!variant) { - for (outX = renderer->end - 1; outX > end2; --outX) { - BACKGROUND_DRAW_PIXEL_16_NORMAL; - } - } else { - for (outX = renderer->end - 1; outX > end2; --outX) { - BACKGROUND_DRAW_PIXEL_16_VARIANT; - } + for (outX = renderer->end - 1; outX > end2; --outX) { + BACKGROUND_DRAW_PIXEL_16; } } } else {

@@ -975,27 +923,15 @@ outX = renderer->end - 8 + end;

int end2 = 4 - end; if (end2 > 0) { tileData = ((uint32_t*)renderer->d.vram)[charBase]; - if (!variant) { - for (; outX < renderer->end - end2; ++outX) { - BACKGROUND_DRAW_PIXEL_256_NORMAL; - } - } else { - for (; outX < renderer->end - end2; ++outX) { - BACKGROUND_DRAW_PIXEL_256_VARIANT; - } + for (; outX < renderer->end - end2; ++outX) { + BACKGROUND_DRAW_PIXEL_256; } ++charBase; } tileData = ((uint32_t*)renderer->d.vram)[charBase]; - if (!variant) { - for (; outX < renderer->end; ++outX) { - BACKGROUND_DRAW_PIXEL_256_NORMAL; - } - } else { - for (; outX < renderer->end; ++outX) { - BACKGROUND_DRAW_PIXEL_256_VARIANT; - } + for (; outX < renderer->end; ++outX) { + BACKGROUND_DRAW_PIXEL_256; } }

@@ -1004,17 +940,9 @@ outX = renderer->start + tileX * 8 - (inX & 0x7);

} if (!background->multipalette) { - if (!variant) { - BACKGROUND_MODE_0_TILE_16_LOOP(NORMAL); - } else { - BACKGROUND_MODE_0_TILE_16_LOOP(VARIANT); - } + BACKGROUND_MODE_0_TILE_16_LOOP; } else { - if (!variant) { - BACKGROUND_MODE_0_TILE_256_LOOP(NORMAL); - } else { - BACKGROUND_MODE_0_TILE_256_LOOP(VARIANT); - } + BACKGROUND_MODE_0_TILE_256_LOOP; } }