master brightness

This commit is contained in:
StapleButter 2017-03-01 20:23:41 +01:00
parent bc335e31cb
commit c4d9d27e6e
4 changed files with 56 additions and 6 deletions

View File

@ -83,6 +83,8 @@ void GPU2D::Reset()
memset(BGRotC, 0, 2*2);
memset(BGRotD, 0, 2*2);
MasterBrightness = 0;
BGExtPalStatus[0] = 0;
BGExtPalStatus[1] = 0;
BGExtPalStatus[2] = 0;
@ -170,6 +172,8 @@ void GPU2D::Write16(u32 addr, u16 val)
case 0x032: BGRotB[1] = val; return;
case 0x034: BGRotC[1] = val; return;
case 0x036: BGRotD[1] = val; return;
case 0x06C: MasterBrightness = val; return;
}
//printf("unknown GPU write16 %08X %04X\n", addr, val);
@ -265,6 +269,50 @@ void GPU2D::DrawScanline(u32 line)
break;
}
// master brightness
if ((MasterBrightness >> 14) == 1)
{
// up
u32 factor = MasterBrightness & 0x1F;
if (factor > 16) factor = 16;
for (int i = 0; i < 256; i++)
{
u32 val = dst[i];
u32 r = val & 0x00003F;
u32 g = val & 0x003F00;
u32 b = val & 0x3F0000;
r += (((0x00003F - r) * factor) >> 4);
g += ((((0x003F00 - g) * factor) >> 4) & 0x003F00);
b += ((((0x3F0000 - b) * factor) >> 4) & 0x3F0000);
dst[i] = r | g | b;
}
}
else if ((MasterBrightness >> 14) == 2)
{
// down
u32 factor = MasterBrightness & 0x1F;
if (factor > 16) factor = 16;
for (int i = 0; i < 256; i++)
{
u32 val = dst[i];
u32 r = val & 0x00003F;
u32 g = val & 0x003F00;
u32 b = val & 0x3F0000;
r -= ((r * factor) >> 4);
g -= (((g * factor) >> 4) & 0x003F00);
b -= (((b * factor) >> 4) & 0x3F0000);
dst[i] = r | g | b;
}
}
// convert to 32-bit RGBA
for (int i = 0; i < 256; i++)
dst[i] = ((dst[i] & 0x003F3F3F) << 2) |

View File

@ -64,6 +64,8 @@ private:
u32 BlendFunc;
u16 MasterBrightness;
u16 BGExtPalCache[4][16*256];
u16 OBJExtPalCache[16*256];
u32 BGExtPalStatus[4];

View File

@ -1624,12 +1624,12 @@ void ARM9IOWrite16(u32 addr, u16 val)
return;
}
if (addr >= 0x04000000 && addr < 0x04000060)
if ((addr >= 0x04000000 && addr < 0x04000060) || (addr == 0x0400006C))
{
GPU::GPU2D_A->Write16(addr, val);
return;
}
if (addr >= 0x04001000 && addr < 0x04001060)
if ((addr >= 0x04001000 && addr < 0x04001060) || (addr == 0x0400106C))
{
GPU::GPU2D_B->Write16(addr, val);
return;

View File

@ -10,7 +10,7 @@
1481161027 c:\documents\sources\melonds\types.h
1488281931 source:c:\documents\sources\melonds\nds.cpp
1488393021 source:c:\documents\sources\melonds\nds.cpp
<stdio.h>
<string.h>
"NDS.h"
@ -87,13 +87,13 @@
"NDS.h"
"SPI.h"
1488281814 source:c:\documents\sources\melonds\gpu2d.cpp
1488396037 source:c:\documents\sources\melonds\gpu2d.cpp
<stdio.h>
<string.h>
"NDS.h"
"GPU.h"
1488225922 c:\documents\sources\melonds\gpu2d.h
1488392627 c:\documents\sources\melonds\gpu2d.h
1481040524 c:\documents\sources\melonds\wifi.h
@ -155,7 +155,7 @@
"GPU.h"
"FIFO.h"
1488244847 source:c:\documents\sources\melonds\gpu3d_soft.cpp
1488390544 source:c:\documents\sources\melonds\gpu3d_soft.cpp
<stdio.h>
<string.h>
"NDS.h"