all repos — mgba @ 320033e72427cc07075ce48d3b0bf7e936a2d20d

mGBA Game Boy Advance Emulator

GBA Video: Mode 2 optimizations
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Sep 2015 22:05:05 -0700
commit

320033e72427cc07075ce48d3b0bf7e936a2d20d

parent

7f2ab299f58b49b1b98953f9f30e28604aeb7611

1 files changed, 39 insertions(+), 32 deletions(-)

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

@@ -7,6 +7,35 @@ #include "software-private.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) { int sizeAdjusted = 0x8000 << background->size;

@@ -15,44 +44,22 @@

uint32_t screenBase = background->screenBase; uint32_t charBase = background->charBase; uint8_t mapData; - uint8_t tileData = 0; + uint8_t pixelData = 0; int outX; 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 (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)]; - tileData = ((uint8_t*)renderer->d.vram)[charBase + (mapData << 6) + ((localY & 0x700) >> 5) + ((localX & 0x700) >> 8)]; - - mosaicWait = mosaicH; + if (!objwinSlowPath) { + if (!(flags & FLAG_TARGET_2) && renderer->blendEffect != BLEND_ALPHA) { + DRAW_BACKGROUND_MODE_2(NoBlend, NO_OBJWIN); } else { - --mosaicWait; + DRAW_BACKGROUND_MODE_2(Blend, NO_OBJWIN); } - - uint32_t current = *pixel; - if (tileData && IS_WRITABLE(current)) { - if (!objwinSlowPath) { - _compositeBlendNoObjwin(renderer, pixel, palette[tileData] | flags, current); - } 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); - } + } else { + if (!(flags & FLAG_TARGET_2) && renderer->blendEffect != BLEND_ALPHA) { + DRAW_BACKGROUND_MODE_2(NoBlend, OBJWIN); + } else { + DRAW_BACKGROUND_MODE_2(Blend, OBJWIN); } } }