GBA Video: Mode 2 optimizations

This commit is contained in:
Jeffrey Pfau 2015-09-20 22:05:05 -07:00
parent 7f2ab299f5
commit 320033e724
1 changed files with 39 additions and 32 deletions

View File

@ -7,6 +7,35 @@
#include "gba/gba.h" #include "gba/gba.h"
#define DRAW_BACKGROUND_MODE_2(BLEND, OBJWIN) \
for (outX = renderer->start, pixel = &renderer->row[outX]; outX < renderer->end; ++outX, ++pixel) { \
x += background->dx; \
y += background->dy; \
\
if (!mosaicWait) { \
if (background->overflow) { \
localX = x & (sizeAdjusted - 1); \
localY = y & (sizeAdjusted - 1); \
} else if ((x | y) & ~(sizeAdjusted - 1)) { \
continue; \
} else { \
localX = x; \
localY = y; \
} \
mapData = ((uint8_t*)renderer->d.vram)[screenBase + (localX >> 11) + (((localY >> 7) & 0x7F0) << background->size)]; \
pixelData = ((uint8_t*)renderer->d.vram)[charBase + (mapData << 6) + ((localY & 0x700) >> 5) + ((localX & 0x700) >> 8)]; \
\
mosaicWait = mosaicH; \
} else { \
--mosaicWait; \
} \
\
uint32_t current = *pixel; \
if (pixelData && IS_WRITABLE(current)) { \
COMPOSITE_256_ ## OBJWIN (BLEND); \
} \
}
void GBAVideoSoftwareRendererDrawBackgroundMode2(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int inY) { void GBAVideoSoftwareRendererDrawBackgroundMode2(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int inY) {
int sizeAdjusted = 0x8000 << background->size; int sizeAdjusted = 0x8000 << background->size;
@ -15,44 +44,22 @@ void GBAVideoSoftwareRendererDrawBackgroundMode2(struct GBAVideoSoftwareRenderer
uint32_t screenBase = background->screenBase; uint32_t screenBase = background->screenBase;
uint32_t charBase = background->charBase; uint32_t charBase = background->charBase;
uint8_t mapData; uint8_t mapData;
uint8_t tileData = 0; uint8_t pixelData = 0;
int outX; int outX;
uint32_t* pixel; uint32_t* pixel;
for (outX = renderer->start, pixel = &renderer->row[outX]; outX < renderer->end; ++outX, ++pixel) {
x += background->dx;
y += background->dy;
if (!mosaicWait) { if (!objwinSlowPath) {
if (background->overflow) { if (!(flags & FLAG_TARGET_2) && renderer->blendEffect != BLEND_ALPHA) {
localX = x & (sizeAdjusted - 1); DRAW_BACKGROUND_MODE_2(NoBlend, NO_OBJWIN);
localY = y & (sizeAdjusted - 1);
} else if ((x | y) & ~(sizeAdjusted - 1)) {
continue;
} else {
localX = x;
localY = y;
}
mapData = ((uint8_t*)renderer->d.vram)[screenBase + (localX >> 11) + (((localY >> 7) & 0x7F0) << background->size)];
tileData = ((uint8_t*)renderer->d.vram)[charBase + (mapData << 6) + ((localY & 0x700) >> 5) + ((localX & 0x700) >> 8)];
mosaicWait = mosaicH;
} else { } else {
--mosaicWait; DRAW_BACKGROUND_MODE_2(Blend, NO_OBJWIN);
} }
} else {
uint32_t current = *pixel; if (!(flags & FLAG_TARGET_2) && renderer->blendEffect != BLEND_ALPHA) {
if (tileData && IS_WRITABLE(current)) { DRAW_BACKGROUND_MODE_2(NoBlend, OBJWIN);
if (!objwinSlowPath) { } else {
_compositeBlendNoObjwin(renderer, pixel, palette[tileData] | flags, current); DRAW_BACKGROUND_MODE_2(Blend, OBJWIN);
} else if (objwinForceEnable || !(current & FLAG_OBJWIN) == objwinOnly) {
color_t* currentPalette = (current & FLAG_OBJWIN) ? objwinPalette : palette;
unsigned mergedFlags = flags;
if (current & FLAG_OBJWIN) {
mergedFlags = objwinFlags;
}
_compositeBlendObjwin(renderer, pixel, currentPalette[tileData] | mergedFlags, current);
}
} }
} }
} }