diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-01-21 17:06:54 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-01-21 17:06:54 +0100 |
commit | 62ed28d5c8a6af554f4af9d3dd5853b656174e55 (patch) | |
tree | 9876ff7384213831ff8ab41538e5d3f5e6739554 | |
parent | 14f1cec955980752604cb573927ed04e8a31673c (diff) |
rotscaled 16color sprites. about fucking time I get this shit working.
-rw-r--r-- | GPU2D.cpp | 89 | ||||
-rw-r--r-- | GPU2D.h | 1 | ||||
-rw-r--r-- | melonDS.depend | 4 |
3 files changed, 90 insertions, 4 deletions
@@ -357,7 +357,7 @@ void GPU2D::DrawSprites(u32 line, u32* dst) boundwidth <<= 1; boundheight <<= 1; } -//printf("sprite%d %04X %04X %04X %dx%d\n", sprnum, attrib[0], attrib[1], attrib[2], boundwidth, boundheight); + u32 ypos = attrib[0] & 0xFF; ypos = (line - ypos) & 0xFF; if (ypos >= (u32)boundheight) @@ -367,7 +367,10 @@ void GPU2D::DrawSprites(u32 line, u32* dst) if (xpos <= -boundwidth) continue; + u32 rotparamgroup = (attrib[1] >> 9) & 0x1F; + //DrawSprite_Normal(attrib, width, xpos, ypos, dst); + DrawSprite_Rotscale(attrib, &oam[(rotparamgroup*16) + 3], boundwidth, boundheight, width, height, xpos, ypos, dst); } else { @@ -397,6 +400,89 @@ void GPU2D::DrawSprites(u32 line, u32* dst) } } +void GPU2D::DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 boundheight, u32 width, u32 height, s32 xpos, u32 ypos, u32* dst) +{ + u32 prio = ((attrib[2] & 0x0C00) << 6) | 0x8000; + u32 tilenum = attrib[2] & 0x03FF; + u32 ytilefactor; + if (DispCnt & 0x10) + { + tilenum <<= ((DispCnt >> 20) & 0x3); + ytilefactor = (width >> 3); + } + else + { + ytilefactor = 0x20; + } + + s32 centerX = boundwidth >> 1; + s32 centerY = boundheight >> 1; + + u32 xoff; + if (xpos >= 0) + { + xoff = 0; + if ((xpos+boundwidth) > 256) + boundwidth = 256-xpos; + } + else + { + xoff = -xpos; + xpos = 0; + } + + s16 rotA = (s16)rotparams[0]; + s16 rotB = (s16)rotparams[4]; + s16 rotC = (s16)rotparams[8]; + s16 rotD = (s16)rotparams[12]; + + s32 rotX = ((xoff-centerX) * rotA) + ((ypos-centerY) * rotB) + (width << 7); + s32 rotY = ((xoff-centerX) * rotC) + ((ypos-centerY) * rotD) + (height << 7); + + width <<= 8; + height <<= 8; + + if (attrib[0] & 0x2000) + { + // 256-color + } + else + { + // 16-color + tilenum <<= 5; + ytilefactor <<= 5; + u8* pixels = (Num ? GPU::VRAM_BOBJ : GPU::VRAM_AOBJ)[tilenum >> 14]; + pixels += (tilenum & 0x3FFF); + + u16* pal = (u16*)&GPU::Palette[Num ? 0x600 : 0x200]; + pal += (attrib[2] & 0xF000) >> 8; + + for (; xoff < boundwidth;) + { + if ((u32)rotX < width && (u32)rotY < height) + { + u8 color; + + // blaaaarg + color = pixels[((rotY>>11)*ytilefactor) + ((rotY&0x700)>>6) + ((rotX>>11)*32) + ((rotX&0x700)>>9)]; + + if (rotX & 0x100) + color >>= 4; + else + color &= 0x0F; + + if (color) + dst[xpos] = pal[color] | prio; + } + + rotX += rotA; + rotY += rotC; + xoff++; + xpos++; + } + } +} + void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, u32 ypos, u32* dst) { u32 prio = ((attrib[2] & 0x0C00) << 6) | 0x8000; @@ -438,7 +524,6 @@ void GPU2D::DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, u32 ypos, u32* d pixels += (tilenum & 0x3FFF); pixels += ((ypos & 0x7) << 2); - u16* curpal; u16* pal = (u16*)&GPU::Palette[Num ? 0x600 : 0x200]; pal += (attrib[2] & 0xF000) >> 8; @@ -54,6 +54,7 @@ private: void InterleaveSprites(u32* buf, u32 prio, u16* dst); void DrawSprites(u32 line, u32* dst); + void DrawSprite_Rotscale(u16* attrib, u16* rotparams, u32 boundwidth, u32 boundheight, u32 width, u32 height, s32 xpos, u32 ypos, u32* dst); void DrawSprite_Normal(u16* attrib, u32 width, s32 xpos, u32 ypos, u32* dst); }; diff --git a/melonDS.depend b/melonDS.depend index 1a93329..b32f606 100644 --- a/melonDS.depend +++ b/melonDS.depend @@ -83,13 +83,13 @@ "NDS.h" "SPI.h" -1484962517 source:c:\documents\sources\melonds\gpu2d.cpp +1485012361 source:c:\documents\sources\melonds\gpu2d.cpp <stdio.h> <string.h> "NDS.h" "GPU.h" -1484960542 c:\documents\sources\melonds\gpu2d.h +1484969589 c:\documents\sources\melonds\gpu2d.h 1481040524 c:\documents\sources\melonds\wifi.h |