From 6486d0e10d0af2f806676a8957d16350a4780e76 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Thu, 2 Feb 2017 00:09:40 +0100 Subject: [PATCH] BG extended palettes! --- GPU.cpp | 52 +++++++++++++++++++++++++++++++++----------------- GPU.h | 5 +++++ GPU2D.cpp | 35 +++++++++++++++++++++++++++++---- melonDS.depend | 8 ++++---- 4 files changed, 74 insertions(+), 26 deletions(-) diff --git a/GPU.cpp b/GPU.cpp index c1d9de0f..9222ce3a 100644 --- a/GPU.cpp +++ b/GPU.cpp @@ -56,6 +56,11 @@ u8* VRAM_BOBJ[128]; u8* VRAM_LCD[128]; u8* VRAM_ARM7[2]; +u8* VRAM_ABGExtPal[4]; +u8* VRAM_AOBJExtPal; +u8* VRAM_BBGExtPal[4]; +u8* VRAM_BOBJExtPal; + u16 Framebuffer[256*192*2]; GPU2D* GPU2D_A; @@ -100,6 +105,11 @@ void Reset() memset(VRAM_LCD, 0, sizeof(u8*)*128); memset(VRAM_ARM7, 0, sizeof(u8*)*2); + memset(VRAM_ABGExtPal, 0, sizeof(u8*)*4); + VRAM_AOBJExtPal = NULL; + memset(VRAM_BBGExtPal, 0, sizeof(u8*)*4); + VRAM_BOBJExtPal = NULL; + for (int i = 0; i < 256*192*2; i++) { Framebuffer[i] = 0x7FFF; @@ -370,11 +380,10 @@ void MapVRAM_E(u32 bank, u8 cnt) break; case 4: - // BG EXTPAL -- TODO - break; - - case 5: - // OBJ EXTPAL -- TODO + VRAM_ABGExtPal[0] = NULL; + VRAM_ABGExtPal[1] = NULL; + VRAM_ABGExtPal[2] = NULL; + VRAM_ABGExtPal[3] = NULL; break; } @@ -421,11 +430,10 @@ void MapVRAM_E(u32 bank, u8 cnt) break; case 4: - // BG EXTPAL -- TODO - break; - - case 5: - // OBJ EXTPAL -- TODO + VRAM_ABGExtPal[0] = &vram[0x0000]; + VRAM_ABGExtPal[1] = &vram[0x2000]; + VRAM_ABGExtPal[2] = &vram[0x4000]; + VRAM_ABGExtPal[3] = &vram[0x6000]; break; } @@ -479,11 +487,12 @@ void MapVRAM_FG(u32 bank, u8 cnt) break; case 4: - // BG EXTPAL TODO + VRAM_ABGExtPal[(oldofs<<1)+0] = NULL; + VRAM_ABGExtPal[(oldofs<<1)+1] = NULL; break; case 5: - // OBJ EXTPAL TODO + VRAM_AOBJExtPal = NULL; break; } @@ -523,11 +532,12 @@ void MapVRAM_FG(u32 bank, u8 cnt) break; case 4: - // BG EXTPAL TODO + VRAM_ABGExtPal[(ofs<<1)+0] = &vram[0x0000]; + VRAM_ABGExtPal[(ofs<<1)+1] = &vram[0x2000]; break; case 5: - // OBJ EXTPAL TODO + VRAM_AOBJExtPal = vram; break; } @@ -573,7 +583,10 @@ void MapVRAM_H(u32 bank, u8 cnt) break; case 2: - // BG EXTPAL TODO + VRAM_BBGExtPal[0] = NULL; + VRAM_BBGExtPal[1] = NULL; + VRAM_BBGExtPal[2] = NULL; + VRAM_BBGExtPal[3] = NULL; break; } @@ -615,7 +628,10 @@ void MapVRAM_H(u32 bank, u8 cnt) break; case 2: - // BG EXTPAL TODO + VRAM_BBGExtPal[0] = &vram[0x0000]; + VRAM_BBGExtPal[1] = &vram[0x2000]; + VRAM_BBGExtPal[2] = &vram[0x4000]; + VRAM_BBGExtPal[3] = &vram[0x6000]; break; } @@ -665,7 +681,7 @@ void MapVRAM_I(u32 bank, u8 cnt) break; case 3: - // not mapped to memory + VRAM_BOBJExtPal = NULL; break; } @@ -701,7 +717,7 @@ void MapVRAM_I(u32 bank, u8 cnt) break; case 3: - // not mapped to memory + VRAM_BOBJExtPal = vram; break; } diff --git a/GPU.h b/GPU.h index c7149e6c..ee852b9f 100644 --- a/GPU.h +++ b/GPU.h @@ -42,6 +42,11 @@ extern u8* VRAM_BOBJ[128]; extern u8* VRAM_LCD[128]; extern u8* VRAM_ARM7[2]; +extern u8* VRAM_ABGExtPal[4]; +extern u8* VRAM_AOBJExtPal; +extern u8* VRAM_BBGExtPal[4]; +extern u8* VRAM_BOBJExtPal; + extern u16 Framebuffer[256*192*2]; extern GPU2D* GPU2D_A; diff --git a/GPU2D.cpp b/GPU2D.cpp index 6c73d940..2d048dba 100644 --- a/GPU2D.cpp +++ b/GPU2D.cpp @@ -265,6 +265,7 @@ void GPU2D::DrawBG_Text_4bpp(u32 line, u16* dst, u32 bgnum) u8* tileset; u16* tilemap; u16* pal; + u32 extpal; u16 xoff = BGXPos[bgnum]; u16 yoff = BGYPos[bgnum] + line; @@ -272,6 +273,8 @@ void GPU2D::DrawBG_Text_4bpp(u32 line, u16* dst, u32 bgnum) u32 widexmask = (bgcnt & 0x4000) ? 0x100 : 0; //u32 ymask = (bgcnt & 0x8000) ? 0x1FF : 0xFF; + extpal = (bgcnt & 0x0080) && (DispCnt & 0x40000000); + if (Num) { tileset = (u8*)GPU::VRAM_BBG[((bgcnt & 0x003C) >> 2)]; @@ -279,7 +282,18 @@ void GPU2D::DrawBG_Text_4bpp(u32 line, u16* dst, u32 bgnum) if (!tileset || !tilemap) return; tilemap += ((bgcnt & 0x0700) << 2); - pal = (u16*)&GPU::Palette[0x400]; + if (extpal) + { + if ((bgnum<2) && (bgcnt&0x2000)) + pal = (u16*)GPU::VRAM_BBGExtPal[2+bgnum]; + else + pal = (u16*)GPU::VRAM_BBGExtPal[bgnum]; + + // derp + if (!pal) pal = (u16*)&GPU::Palette[0x400]; + } + else + pal = (u16*)&GPU::Palette[0x400]; } else { @@ -288,7 +302,18 @@ void GPU2D::DrawBG_Text_4bpp(u32 line, u16* dst, u32 bgnum) if (!tileset || !tilemap) return; tilemap += ((bgcnt & 0x0700) << 2); - pal = (u16*)&GPU::Palette[0]; + if (extpal) + { + if ((bgnum<2) && (bgcnt&0x2000)) + pal = (u16*)GPU::VRAM_ABGExtPal[2+bgnum]; + else + pal = (u16*)GPU::VRAM_ABGExtPal[bgnum]; + + // derp + if (!pal) pal = (u16*)&GPU::Palette[0]; + } + else + pal = (u16*)&GPU::Palette[0]; } // adjust Y position in tilemap @@ -314,7 +339,8 @@ void GPU2D::DrawBG_Text_4bpp(u32 line, u16* dst, u32 bgnum) { // load a new tile curtile = tilemap[((xoff & 0xFF) >> 3) + ((xoff & widexmask) << 2)]; - curpal = pal;// + ((curtile & 0xF000) >> 8); // TODO: this applies to ext palettes + curpal = pal; + if (extpal) curpal += ((curtile & 0xF000) >> 4); pixels = tileset + ((curtile & 0x03FF) << 6); pixels += (((curtile & 0x0800) ? (7-(yoff&0x7)) : (yoff&0x7)) << 3); } @@ -325,7 +351,8 @@ void GPU2D::DrawBG_Text_4bpp(u32 line, u16* dst, u32 bgnum) { // load a new tile curtile = tilemap[((xoff & 0xFF) >> 3) + ((xoff & widexmask) << 2)]; - curpal = pal;// + ((curtile & 0xF000) >> 8); + curpal = pal; + if (extpal) curpal += ((curtile & 0xF000) >> 4); pixels = tileset + ((curtile & 0x03FF) << 6); pixels += (((curtile & 0x0800) ? (7-(yoff&0x7)) : (yoff&0x7)) << 3); } diff --git a/melonDS.depend b/melonDS.depend index 66d5ae20..c918c7e6 100644 --- a/melonDS.depend +++ b/melonDS.depend @@ -10,7 +10,7 @@ 1481161027 c:\documents\sources\melonds\types.h -1485988849 source:c:\documents\sources\melonds\nds.cpp +1485988923 source:c:\documents\sources\melonds\nds.cpp "NDS.h" @@ -86,7 +86,7 @@ "NDS.h" "SPI.h" -1485988879 source:c:\documents\sources\melonds\gpu2d.cpp +1485990245 source:c:\documents\sources\melonds\gpu2d.cpp "NDS.h" @@ -117,13 +117,13 @@ 1484698068 c:\documents\sources\melonds\dma.h "types.h" -1485982457 source:c:\documents\sources\melonds\gpu.cpp +1485989904 source:c:\documents\sources\melonds\gpu.cpp "NDS.h" "GPU.h" -1485982310 c:\documents\sources\melonds\gpu.h +1485989497 c:\documents\sources\melonds\gpu.h "GPU2D.h" 1484848282 c:\documents\sources\melonds\rtc.h