aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-03-01 20:23:41 +0100
committerStapleButter <thetotalworm@gmail.com>2017-03-01 20:23:41 +0100
commitc4d9d27e6ee830d57c229cd1f7a9eb5f7c3071e2 (patch)
treefaa7046a1dd5c6880af3e1a2f2224573ac9496ed
parentbc335e31cb16252c89daf4e4fa4d3bf5b3f79e03 (diff)
master brightness
-rw-r--r--GPU2D.cpp48
-rw-r--r--GPU2D.h2
-rw-r--r--NDS.cpp4
-rw-r--r--melonDS.depend8
4 files changed, 56 insertions, 6 deletions
diff --git a/GPU2D.cpp b/GPU2D.cpp
index de3636e..90064d1 100644
--- a/GPU2D.cpp
+++ b/GPU2D.cpp
@@ -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) |
diff --git a/GPU2D.h b/GPU2D.h
index 0230802..89694e8 100644
--- a/GPU2D.h
+++ b/GPU2D.h
@@ -64,6 +64,8 @@ private:
u32 BlendFunc;
+ u16 MasterBrightness;
+
u16 BGExtPalCache[4][16*256];
u16 OBJExtPalCache[16*256];
u32 BGExtPalStatus[4];
diff --git a/NDS.cpp b/NDS.cpp
index 0bba278..1bb758c 100644
--- a/NDS.cpp
+++ b/NDS.cpp
@@ -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;
diff --git a/melonDS.depend b/melonDS.depend
index adc1947..fe0d65e 100644
--- a/melonDS.depend
+++ b/melonDS.depend
@@ -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"