diff --git a/nds/arm9/source/gfx.cpp b/nds/arm9/source/gfx.cpp index 33fea6e..c6e70e7 100644 --- a/nds/arm9/source/gfx.cpp +++ b/nds/arm9/source/gfx.cpp @@ -67,7 +67,7 @@ extern int bg3Main; extern int bg3Sub; extern u16* colorTable; -extern void applyColorLut(u16 *palette, int size); +extern void applyColorLutBitmap(u16 *palette, int size); extern void copyPalette16(u16 *dst, const u16 *src, int size); extern bool showCursor; @@ -158,7 +158,7 @@ void GFX::loadSheets() { for(unsigned i=0;i>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15); } - applyColorLut(charSpriteMem, image.size()/4); + applyColorLutBitmap(charSpriteMem, image.size()/4); image.clear(); lodepng::decode(image, width, height, "nitro:/graphics/gui/title.png"); bool alternatePixel = false; @@ -188,7 +188,7 @@ void GFX::loadSheets() { } bmpImageBuffer[1][i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15); if (colorTable) { - bmpImageBuffer[1][i] = colorTable[bmpImageBuffer[1][i] % 0x8000]; + bmpImageBuffer[1][i] = colorTable[bmpImageBuffer[1][i] % 0x8000] | BIT(15); } if (charSpriteAlpha[i] == 255) { bmpImageBuffer[0][i] = bmpImageBuffer[1][i]; @@ -221,7 +221,7 @@ void GFX::loadSheets() { } bmpImageBuffer2[1][i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15); if (colorTable) { - bmpImageBuffer2[1][i] = colorTable[bmpImageBuffer2[1][i] % 0x8000]; + bmpImageBuffer2[1][i] = colorTable[bmpImageBuffer2[1][i] % 0x8000] | BIT(15); } if (charSpriteAlpha[i] == 255) { bmpImageBuffer2[0][i] = bmpImageBuffer2[1][i]; @@ -306,14 +306,10 @@ void GFX::loadBgSprite(void) { animateTitle = false; if (dsiFeatures()) { + const u16 white = colorTable ? (colorTable[0xFFFF % 0x8000] | BIT(15)) : 0xFFFF; swiWaitForVBlank(); // Prevent screen tearing - if (colorTable) { - dmaFillHalfWords(colorTable[0xFFFF % 0x8000], bgGetGfxPtr(bg2Main), 0x18000); - dmaFillHalfWords(colorTable[0xFFFF % 0x8000], bgGetGfxPtr(bg3Main), 0x18000); - } else { - dmaFillHalfWords(0xFFFF, bgGetGfxPtr(bg2Main), 0x18000); - dmaFillHalfWords(0xFFFF, bgGetGfxPtr(bg3Main), 0x18000); - } + dmaFillHalfWords(white, bgGetGfxPtr(bg2Main), 0x18000); + dmaFillHalfWords(white, bgGetGfxPtr(bg3Main), 0x18000); } timeOutside = 2; // Default is Nighttime @@ -685,9 +681,9 @@ void GFX::loadBgSprite(void) { if ((i % 256) == 255) alternatePixel = !alternatePixel; alternatePixel = !alternatePixel; } - applyColorLut(bgSpriteMem, image.size()/4); + applyColorLutBitmap(bgSpriteMem, image.size()/4); if (dsiFeatures()) { - applyColorLut(bgSpriteMem2, image.size()/4); + applyColorLutBitmap(bgSpriteMem2, image.size()/4); } bgSpriteLoaded = true; @@ -766,9 +762,9 @@ void GFX::loadBgSprite(void) { if ((p % 256) == 255) alternatePixel = !alternatePixel; alternatePixel = !alternatePixel; } - applyColorLut(bgSpriteMemExt[i-1], image.size()/4); + applyColorLutBitmap(bgSpriteMemExt[i-1], image.size()/4); if (dsiFeatures()) { - applyColorLut(bgSpriteMemExt2[i-1], image.size()/4); + applyColorLutBitmap(bgSpriteMemExt2[i-1], image.size()/4); } } if (studioBg == 64) { @@ -898,9 +894,9 @@ bool GFX::loadCharSprite(int num, const char* t3xPathPose, const char* t3xPathAl if ((i % 256) == 255) alternatePixel = !alternatePixel; alternatePixel = !alternatePixel; } - applyColorLut(usePageFile ? charSpriteMem : charSpriteMem5, image.size()/4); + applyColorLutBitmap(usePageFile ? charSpriteMem : charSpriteMem5, image.size()/4); if (dsiFeatures()) { - applyColorLut(charSpriteMem5_2, image.size()/4); + applyColorLutBitmap(charSpriteMem5_2, image.size()/4); } if (usePageFile) { FILE* pageFile = fopen("fat:/_nds/pagefile.sys", "r+"); @@ -971,9 +967,9 @@ bool GFX::loadCharSprite(int num, const char* t3xPathPose, const char* t3xPathAl if ((i % 256) == 255) alternatePixel = !alternatePixel; alternatePixel = !alternatePixel; } - applyColorLut(usePageFile ? charSpriteMem : charSpriteMem4, image.size()/4); + applyColorLutBitmap(usePageFile ? charSpriteMem : charSpriteMem4, image.size()/4); if (dsiFeatures()) { - applyColorLut(charSpriteMem4_2, image.size()/4); + applyColorLutBitmap(charSpriteMem4_2, image.size()/4); } if (usePageFile) { FILE* pageFile = fopen("fat:/_nds/pagefile.sys", "r+"); @@ -1044,9 +1040,9 @@ bool GFX::loadCharSprite(int num, const char* t3xPathPose, const char* t3xPathAl if ((i % 256) == 255) alternatePixel = !alternatePixel; alternatePixel = !alternatePixel; } - applyColorLut(usePageFile ? charSpriteMem : charSpriteMem3, image.size()/4); + applyColorLutBitmap(usePageFile ? charSpriteMem : charSpriteMem3, image.size()/4); if (dsiFeatures()) { - applyColorLut(charSpriteMem3_2, image.size()/4); + applyColorLutBitmap(charSpriteMem3_2, image.size()/4); } if (usePageFile) { FILE* pageFile = fopen("fat:/_nds/pagefile.sys", "r+"); @@ -1131,9 +1127,9 @@ bool GFX::loadCharSprite(int num, const char* t3xPathPose, const char* t3xPathAl if ((i % 256) == 255) alternatePixel = !alternatePixel; alternatePixel = !alternatePixel; } - applyColorLut(usePageFile ? charSpriteMem : charSpriteMem2, image.size()/4); + applyColorLutBitmap(usePageFile ? charSpriteMem : charSpriteMem2, image.size()/4); if (dsiFeatures()) { - applyColorLut(charSpriteMem2_2, image.size()/4); + applyColorLutBitmap(charSpriteMem2_2, image.size()/4); } if (usePageFile) { FILE* pageFile = fopen("fat:/_nds/pagefile.sys", "r+"); @@ -1196,9 +1192,9 @@ bool GFX::loadCharSprite(int num, const char* t3xPathPose, const char* t3xPathAl if ((i % 256) == 255) alternatePixel = !alternatePixel; alternatePixel = !alternatePixel; } - applyColorLut(charSpriteMem, image.size()/4); + applyColorLutBitmap(charSpriteMem, image.size()/4); if (dsiFeatures()) { - applyColorLut(charSpriteMem_2, image.size()/4); + applyColorLutBitmap(charSpriteMem_2, image.size()/4); } if (usePageFile && chracterSpriteFound[1]) { FILE* pageFile = fopen("fat:/_nds/pagefile.sys", "r+"); diff --git a/nds/arm9/source/gui.cpp b/nds/arm9/source/gui.cpp index c26ef01..1e1b7c9 100644 --- a/nds/arm9/source/gui.cpp +++ b/nds/arm9/source/gui.cpp @@ -59,9 +59,15 @@ int bg3Sub; u16* gfxSub; u16* colorTable = NULL; +bool invertedColors = false; +bool noWhiteFade = false; // Ported from PAlib (obsolete) void SetBrightness(u8 screen, s8 bright) { + if ((invertedColors && bright != 0) || (noWhiteFade && bright > 0)) { + bright -= bright*2; // Invert brightness to match the inverted colors + } + u16 mode = 1 << 14; if (bright < 0) { @@ -70,7 +76,7 @@ void SetBrightness(u8 screen, s8 bright) { } if (bright > 31) bright = 31; - *(vu16 *)(0x0400006C + (0x1000 * screen)) = bright + mode; + *(vu16*)(0x0400006C + (0x1000 * screen)) = bright + mode; } // Clear Text. @@ -90,13 +96,22 @@ void Gui__ChangeBrightness() { SetBrightness(1, (fadecolor==255 ? fadealpha : -fadealpha)/8); } -void applyColorLut(u16 *palette, int size) { +/* void applyColorLut(u16 *palette, int size) { if (!colorTable) { return; } for (int i = 0; i < size; i++) { palette[i] = colorTable[palette[i] % 0x8000]; } +} */ + +void applyColorLutBitmap(u16 *palette, int size) { + if (!colorTable) { + return; + } + for (int i = 0; i < size; i++) { + palette[i] = colorTable[palette[i] % 0x8000] | BIT(15); + } } // Copies a palette and applies color LUT if loaded @@ -156,6 +171,14 @@ void Gui::init(void) { fread(colorTable, 1, 0x10000, file); fclose(file); + invertedColors = + (colorTable[0] >= 0xF000 && colorTable[0] <= 0xFFFF + && colorTable[0x7FFF] >= 0x8000 && colorTable[0x7FFF] <= 0x8FFF); + if (!invertedColors) noWhiteFade = (colorTable[0x7FFF] < 0xF000); + + SetBrightness(0, 31); + SetBrightness(1, 31); + tonccpy(VRAM_D, colorTable, 0x10000); // Copy LUT to VRAM delete[] colorTable; // Free up RAM space colorTable = VRAM_D; diff --git a/nds/arm9/source/screens/productIdent.cpp b/nds/arm9/source/screens/productIdent.cpp index 2666c17..1f0be74 100644 --- a/nds/arm9/source/screens/productIdent.cpp +++ b/nds/arm9/source/screens/productIdent.cpp @@ -30,7 +30,7 @@ void ProductIdent::Logic(u32 hDown, u32 hHeld, touchPosition touch) { u16* bgLoc = new u16[256*192]; extern int bg2Main; extern int bg3Main; - extern void applyColorLut(u16 *palette, int size); + extern void applyColorLutBitmap(u16 *palette, int size); std::vector image; unsigned width, height; @@ -45,9 +45,9 @@ void ProductIdent::Logic(u32 hDown, u32 hHeld, touchPosition touch) { while (dmaBusy(0)); delete[] bgLoc; } - applyColorLut(bgGetGfxPtr(bg2Main), 0x18000/sizeof(u16)); + applyColorLutBitmap(bgGetGfxPtr(bg2Main), 0x18000/sizeof(u16)); if (dsiFeatures()) { - applyColorLut(bgGetGfxPtr(bg3Main), 0x18000/sizeof(u16)); + applyColorLutBitmap(bgGetGfxPtr(bg3Main), 0x18000/sizeof(u16)); } graphicLoaded = true; } diff --git a/source/screens/rocketRobz.cpp b/source/screens/rocketRobz.cpp index 859ac8d..421e7f9 100644 --- a/source/screens/rocketRobz.cpp +++ b/source/screens/rocketRobz.cpp @@ -137,7 +137,7 @@ void RocketRobz::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if (!graphicLoaded) { extern int bg2Main; extern int bg3Main; - extern void applyColorLut(u16 *palette, int size); + extern void applyColorLutBitmap(u16 *palette, int size); std::vector image; unsigned width, height; @@ -187,9 +187,9 @@ void RocketRobz::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if ((i % 256) == 255) alternatePixel = !alternatePixel; alternatePixel = !alternatePixel; } - applyColorLut(bgGetGfxPtr(bg2Main), 0x18000/sizeof(u16)); + applyColorLutBitmap(bgGetGfxPtr(bg2Main), 0x18000/sizeof(u16)); if (dsiFeatures()) { - applyColorLut(bgGetGfxPtr(bg3Main), 0x18000/sizeof(u16)); + applyColorLutBitmap(bgGetGfxPtr(bg3Main), 0x18000/sizeof(u16)); } graphicLoaded = true; }