From 0010e296bd6d5e12c93791c7481bc04430a58ab5 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 5 Sep 2019 11:42:08 +0200 Subject: GPU2D: delay palette lookup for sprites --- src/GPU2D.cpp | 129 +++++++++++++++++++++++++++++++++++----------------------- src/GPU2D.h | 2 +- 2 files changed, 80 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 288ee58..ef9be41 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -1193,33 +1193,33 @@ u16* GPU2D::GetBGExtPal(u32 slot, u32 pal) return dst; } -u16* GPU2D::GetOBJExtPal(u32 pal) +u16* GPU2D::GetOBJExtPal() { - u16* dst = &OBJExtPalCache[pal << 8]; + u16* dst = OBJExtPalCache; - if (!(OBJExtPalStatus & (1< void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 boundheight, u32 width, u32 height, s32 xpos, s32 ypos) { - u32 prio = ((attrib[2] & 0x0C00) << 6) | 0x8000; + u32 pixelattr = ((attrib[2] & 0x0C00) << 6) | 0x40000; u32 tilenum = attrib[2] & 0x03FF; u32 spritemode = window ? 0 : ((attrib[0] >> 10) & 0x3); u32 xmos = 0, xmossize = 0; @@ -2337,7 +2374,7 @@ void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 if (!alpha) return; alpha++; - prio |= (0xC0000000 | (alpha << 24)); + pixelattr |= (0xC0000000 | (alpha << 24)); if (DispCnt & 0x40) { @@ -2387,7 +2424,7 @@ void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 if (color & 0x8000) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = color | prio; + else OBJLine[xpos] = color | pixelattr; } } else @@ -2414,8 +2451,8 @@ void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 ytilefactor = 0x20; } - if (spritemode == 1) prio |= 0x80000000; - else prio |= 0x10000000; + if (spritemode == 1) pixelattr |= 0x80000000; + else pixelattr |= 0x10000000; if (attrib[0] & 0x2000) { @@ -2424,13 +2461,9 @@ void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 ytilefactor <<= 5; u32 pixelsaddr = (Num ? 0x06600000 : 0x06400000) + tilenum; - u32 extpal = (DispCnt & 0x80000000); - - u16* pal; if (!window) { - if (extpal) pal = GetOBJExtPal(attrib[2] >> 12); - else pal = (u16*)&GPU::Palette[Num ? 0x600 : 0x200]; + if (!(DispCnt & 0x80000000)) pixelattr |= 0x1000; } if (xmos && !(attrib[0]&0x0200)) @@ -2451,7 +2484,7 @@ void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 if (color) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = pal[color] | prio; + else OBJLine[xpos] = color | pixelattr; } } else @@ -2473,11 +2506,10 @@ void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 ytilefactor <<= 5; u32 pixelsaddr = (Num ? 0x06600000 : 0x06400000) + tilenum; - u16* pal; if (!window) { - pal = (u16*)&GPU::Palette[Num ? 0x600 : 0x200]; - pal += (attrib[2] & 0xF000) >> 8; + pixelattr |= 0x1000; + pixelattr |= ((attrib[2] & 0xF000) >> 8); } if (xmos && !(attrib[0]&0x0200)) @@ -2509,7 +2541,7 @@ void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 if (color) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = pal[color] | prio; + else OBJLine[xpos] = color | pixelattr; } } else @@ -2530,7 +2562,7 @@ void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 template void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) { - u32 prio = ((attrib[2] & 0x0C00) << 6) | 0x8000; + u32 pixelattr = ((attrib[2] & 0x0C00) << 6) | 0x40000; u32 tilenum = attrib[2] & 0x03FF; u32 spritemode = window ? 0 : ((attrib[0] >> 10) & 0x3); u32 xmos = 0, xmossize = 0; @@ -2572,7 +2604,7 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) if (!alpha) return; alpha++; - prio |= (0xC0000000 | (alpha << 24)); + pixelattr |= (0xC0000000 | (alpha << 24)); if (DispCnt & 0x40) { @@ -2625,7 +2657,7 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) if (color & 0x8000) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = color | prio; + else OBJLine[xpos] = color | pixelattr; } xoff++; @@ -2652,7 +2684,7 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) if (color & 0x8000) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = color | prio; + else OBJLine[xpos] = color | pixelattr; } xoff++; @@ -2672,8 +2704,8 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) tilenum += ((ypos >> 3) * 0x20); } - if (spritemode == 1) prio |= 0x80000000; - else prio |= 0x10000000; + if (spritemode == 1) pixelattr |= 0x80000000; + else pixelattr |= 0x10000000; if (attrib[0] & 0x2000) { @@ -2682,13 +2714,9 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) u32 pixelsaddr = (Num ? 0x06600000 : 0x06400000) + tilenum; pixelsaddr += ((ypos & 0x7) << 3); - u32 extpal = (DispCnt & 0x80000000); - - u16* pal; if (!window) { - if (extpal) pal = GetOBJExtPal(attrib[2] >> 12); - else pal = (u16*)&GPU::Palette[Num ? 0x600 : 0x200]; + if (!(DispCnt & 0x80000000)) pixelattr |= 0x1000; } if (attrib[1] & 0x1000) // xflip. TODO: do better? oh well for now this works @@ -2712,7 +2740,7 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) if (color) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = pal[color] | prio; + else OBJLine[xpos] = color | pixelattr; } xoff++; @@ -2741,7 +2769,7 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) if (color) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = pal[color] | prio; + else OBJLine[xpos] = color | pixelattr; } xoff++; @@ -2757,13 +2785,14 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) u32 pixelsaddr = (Num ? 0x06600000 : 0x06400000) + tilenum; pixelsaddr += ((ypos & 0x7) << 2); - u16* pal; if (!window) { - pal = (u16*)&GPU::Palette[Num ? 0x600 : 0x200]; - pal += (attrib[2] & 0xF000) >> 8; + pixelattr |= 0x1000; + pixelattr |= ((attrib[2] & 0xF000) >> 8); } + // TODO: optimize VRAM access!! + if (attrib[1] & 0x1000) // xflip. TODO: do better? oh well for now this works { pixelsaddr += (((width-1 - xoff) & wmask) << 2); @@ -2790,7 +2819,7 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) if (color) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = pal[color] | prio; + else OBJLine[xpos] = color | pixelattr; } xoff++; @@ -2824,7 +2853,7 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, s32 ypos) if (color) { if (window) OBJWindow[xpos] = 1; - else OBJLine[xpos] = pal[color] | prio; + else OBJLine[xpos] = color | pixelattr; } xoff++; diff --git a/src/GPU2D.h b/src/GPU2D.h index 6ad9783..9184215 100644 --- a/src/GPU2D.h +++ b/src/GPU2D.h @@ -63,7 +63,7 @@ public: void OBJExtPalDirty(); u16* GetBGExtPal(u32 slot, u32 pal); - u16* GetOBJExtPal(u32 pal); + u16* GetOBJExtPal(); private: u32 Num; -- cgit v1.2.3