Support 256-color sprites
Jeffrey Pfau jeffrey@endrift.com
Wed, 01 May 2013 23:27:49 -0700
1 files changed,
42 insertions(+),
17 deletions(-)
M
src/gba/renderers/video-software.c
→
src/gba/renderers/video-software.c
@@ -631,26 +631,51 @@ if (sprite->vflip) {
inY = height - inY - 1; } unsigned charBase = BASE_TILE + sprite->tile * 0x20; - unsigned yBase = (inY & ~0x7) * (renderer->dispcnt.objCharacterMapping ? width >> 1 : 0x80) + (inY & 0x7) * 4; - for (int outX = x >= start ? x : start; outX < x + width && outX < end; ++outX) { - int inX = outX - x; - if (sprite->hflip) { - inX = width - inX - 1; + if (!sprite->multipalette) { + unsigned yBase = (inY & ~0x7) * (renderer->dispcnt.objCharacterMapping ? width >> 1 : 0x80) + (inY & 0x7) * 4; + for (int outX = x >= start ? x : start; outX < x + width && outX < end; ++outX) { + int inX = outX - x; + if (sprite->hflip) { + inX = width - inX - 1; + } + if (renderer->flags[outX].isSprite) { + continue; + } + unsigned xBase = (inX & ~0x7) * 4 + ((inX >> 1) & 2); + uint16_t tileData = renderer->d.vram[(yBase + charBase + xBase) >> 1]; + tileData = (tileData >> ((inX & 3) << 2)) & 0xF; + if (tileData) { + if (renderer->blendEffect == BLEND_NONE || renderer->blendEffect == BLEND_ALPHA || !renderer->target1Obj) { + renderer->spriteLayer[outX] = renderer->normalPalette[0x100 | tileData | (sprite->palette << 4)]; + } else { + renderer->spriteLayer[outX] = renderer->variantPalette[0x100 | tileData | (sprite->palette << 4)]; + } + renderer->flags[outX] = flags; + } } - if (renderer->flags[outX].isSprite) { - continue; - } - unsigned xBase = (inX & ~0x7) * 4 + ((inX >> 1) & 2); - uint16_t tileData = renderer->d.vram[(yBase + charBase + xBase) >> 1]; - tileData = (tileData >> ((inX & 3) << 2)) & 0xF; - if (tileData) { - if (renderer->blendEffect == BLEND_NONE || renderer->blendEffect == BLEND_ALPHA || !renderer->target1Obj) { - renderer->spriteLayer[outX] = renderer->normalPalette[0x100 | tileData | (sprite->palette << 4)]; - } else { - renderer->spriteLayer[outX] = renderer->variantPalette[0x100 | tileData | (sprite->palette << 4)]; + } else { + unsigned yBase = (inY & ~0x7) * (renderer->dispcnt.objCharacterMapping ? width : 0x100) + (inY & 0x7) * 8; + for (int outX = x >= start ? x : start; outX < x + width && outX < end; ++outX) { + int inX = outX - x; + if (sprite->hflip) { + inX = width - inX - 1; + } + if (renderer->flags[outX].isSprite) { + continue; + } + unsigned xBase = (inX & ~0x7) * 8 + (inX & 6); + uint16_t tileData = renderer->d.vram[(yBase + charBase + xBase) >> 1]; + tileData = (tileData >> ((inX & 1) << 3)) & 0xFF; + if (tileData) { + if (renderer->blendEffect == BLEND_NONE || renderer->blendEffect == BLEND_ALPHA || !renderer->target1Obj) { + renderer->spriteLayer[outX] = renderer->normalPalette[0x100 | tileData]; + } else { + renderer->spriteLayer[outX] = renderer->variantPalette[0x100 | tileData]; + } + renderer->flags[outX] = flags; } - renderer->flags[outX] = flags; } + } }