diff --git a/GPU2D.cpp b/GPU2D.cpp index de3636e7..90064d18 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 0230802d..89694e88 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 0bba278a..1bb758c8 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 adc19479..fe0d65e8 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 "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 "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 "NDS.h"