fixes to tiled extended BGs. support for 256color/direct bitmap BGs.

This commit is contained in:
StapleButter 2017-02-03 23:49:37 +01:00
parent 399e30017a
commit 4b3f635c9f
3 changed files with 117 additions and 61 deletions

108
GPU2D.cpp
View File

@ -303,7 +303,6 @@ void GPU2D::DrawBG_Text(u32 line, u16* dst, u32 bgnum)
u16 yoff = BGYPos[bgnum] + line;
u32 widexmask = (bgcnt & 0x4000) ? 0x100 : 0;
//u32 ymask = (bgcnt & 0x8000) ? 0x1FF : 0xFF;
extpal = (bgcnt & 0x0080) && (DispCnt & 0x40000000);
@ -455,16 +454,89 @@ void GPU2D::DrawBG_Extended(u32 line, u16* dst, u32 bgnum)
u32 extpal;
u32 coordmask;
u32 yshift;
switch (bgcnt & 0xC000)
{
case 0x0000: coordmask = 0x07800; break;
case 0x4000: coordmask = 0x0F800; break;
case 0x8000: coordmask = 0x1F800; break;
case 0xC000: coordmask = 0x3F800; break;
case 0x0000: coordmask = 0x07800; yshift = 7; break;
case 0x4000: coordmask = 0x0F800; yshift = 8; break;
case 0x8000: coordmask = 0x1F800; yshift = 9; break;
case 0xC000: coordmask = 0x3F800; yshift = 10; break;
}
u32 overflowmask;
if (bgcnt & 0x2000) overflowmask = 0;
else overflowmask = ~(coordmask | 0x7FF);
extpal = (DispCnt & 0x40000000);
s16 rotA = BGRotA[bgnum-2];
s16 rotB = BGRotB[bgnum-2];
s16 rotC = BGRotC[bgnum-2];
s16 rotD = BGRotD[bgnum-2];
s32 rotX = BGXCenter[bgnum-2];
s32 rotY = BGYCenter[bgnum-2];
// hax
rotX += line*rotB;
rotY += line*rotD;
if (bgcnt & 0x0080)
{
// bitmap modes
if (Num) tileset = (u8*)GPU::VRAM_BBG[((bgcnt & 0x003C) >> 2)];
else tileset = (u8*)GPU::VRAM_ABG[((bgcnt & 0x003C) >> 2)];
if (!tileset) return;
coordmask |= 0x7FF;
if (bgcnt & 0x0004)
{
// direct color bitmap
u16* bitmap = (u16*)tileset;
for (int i = 0; i < 256; i++)
{
if (!((rotX|rotY) & overflowmask))
{
u16 color = bitmap[(((rotY & coordmask) >> 8) << yshift) + ((rotX & coordmask) >> 8)];
if (color & 0x8000)
dst[i] = color;
}
rotX += rotA;
rotY += rotC;
}
}
else
{
// 256-color bitmap
if (Num) pal = (u16*)&GPU::Palette[0x400];
else pal = (u16*)&GPU::Palette[0];
for (int i = 0; i < 256; i++)
{
if (!((rotX|rotY) & overflowmask))
{
u8 color = tileset[(((rotY & coordmask) >> 8) << yshift) + ((rotX & coordmask) >> 8)];
if (color)
dst[i] = pal[color];
}
rotX += rotA;
rotY += rotC;
}
}
}
else
{
// shitty mode
if (Num)
{
tileset = (u8*)GPU::VRAM_BBG[((bgcnt & 0x003C) >> 2)];
@ -504,30 +576,13 @@ void GPU2D::DrawBG_Extended(u32 line, u16* dst, u32 bgnum)
u16* curpal;
u8* pixels;
s16 rotA = BGRotA[bgnum-2];
s16 rotB = BGRotB[bgnum-2];
s16 rotC = BGRotC[bgnum-2];
s16 rotD = BGRotD[bgnum-2];
s32 rotX = BGXCenter[bgnum-2];
s32 rotY = BGYCenter[bgnum-2];
// hax
rotX += line*rotB;
rotY += line*rotD;
if (bgcnt & 0x0080)
{
// bitmap modes
// TODO
}
else
{
// shitty mode
yshift -= 3;
for (int i = 0; i < 256; i++)
{
curtile = tilemap[((rotY & coordmask) >> 5) + ((rotX & coordmask) >> 11)];
if (!((rotX|rotY) & overflowmask))
{
curtile = tilemap[(((rotY & coordmask) >> 11) << yshift) + ((rotX & coordmask) >> 11)];
curpal = pal;
if (extpal) curpal += ((curtile & 0xF000) >> 4);
pixels = tileset + ((curtile & 0x03FF) << 6);
@ -544,6 +599,7 @@ void GPU2D::DrawBG_Extended(u32 line, u16* dst, u32 bgnum)
if (color)
dst[i] = curpal[color];
}
rotX += rotA;
rotY += rotC;

View File

@ -274,7 +274,7 @@ void Reset()
// test
//LoadROM();
//LoadFirmware();
NDSCart::LoadROM("rom/nsmb.nds");
NDSCart::LoadROM("rom/raving.nds");
Running = true; // hax
}

View File

@ -10,7 +10,7 @@
1481161027 c:\documents\sources\melonds\types.h
1486143063 source:c:\documents\sources\melonds\nds.cpp
1486162025 source:c:\documents\sources\melonds\nds.cpp
<stdio.h>
<string.h>
"NDS.h"
@ -86,7 +86,7 @@
"NDS.h"
"SPI.h"
1486144037 source:c:\documents\sources\melonds\gpu2d.cpp
1486162082 source:c:\documents\sources\melonds\gpu2d.cpp
<stdio.h>
<string.h>
"NDS.h"