From 83c538185454996797db736ad8581b252b18b897 Mon Sep 17 00:00:00 2001 From: Jean-Philip Desjardins Date: Tue, 1 Nov 2016 21:09:50 -0400 Subject: [PATCH] Add support for PSMCT16S CLUTs. --- Source/gs/GSH_OpenGL/GSH_OpenGL_Texture.cpp | 4 +- Source/gs/GSHandler.cpp | 106 +++++++++++++------- Source/gs/GSHandler.h | 2 + 3 files changed, 71 insertions(+), 41 deletions(-) diff --git a/Source/gs/GSH_OpenGL/GSH_OpenGL_Texture.cpp b/Source/gs/GSH_OpenGL/GSH_OpenGL_Texture.cpp index 46b2e7a9..f91a1d1c 100644 --- a/Source/gs/GSH_OpenGL/GSH_OpenGL_Texture.cpp +++ b/Source/gs/GSH_OpenGL/GSH_OpenGL_Texture.cpp @@ -222,7 +222,7 @@ GLuint CGSH_OpenGL::PreparePalette(const TEX0& tex0) convertedClut[i] = color; } } - else if(tex0.nCPSM == PSMCT16) + else if(tex0.nCPSM == PSMCT16 || tex0.nCPSM == PSMCT16S) { assert(tex0.nCSA < 32); @@ -250,7 +250,7 @@ GLuint CGSH_OpenGL::PreparePalette(const TEX0& tex0) convertedClut[i] = color; } } - else if(tex0.nCPSM == PSMCT16) + else if(tex0.nCPSM == PSMCT16 || tex0.nCPSM == PSMCT16S) { for(unsigned int i = 0; i < 256; i++) { diff --git a/Source/gs/GSHandler.cpp b/Source/gs/GSHandler.cpp index 842f1930..248bebbe 100644 --- a/Source/gs/GSHandler.cpp +++ b/Source/gs/GSHandler.cpp @@ -988,6 +988,63 @@ void CGSHandler::SyncCLUT(const TEX0& tex0) } } +template +bool CGSHandler::ReadCLUT4_16(const TEX0& tex0) +{ + bool changed = false; + + assert(tex0.nCSA < 32); + + Indexor indexor(m_pRAM, tex0.GetCLUTPtr(), 1); + uint32 clutOffset = tex0.nCSA * 16; + uint16* pDst = m_pCLUT + clutOffset; + + for(unsigned int j = 0; j < 2; j++) + { + for(unsigned int i = 0; i < 8; i++) + { + uint16 color = indexor.GetPixel(i, j); + + if(*pDst != color) + { + changed = true; + } + + (*pDst++) = color; + } + } + + return changed; +} + +template +bool CGSHandler::ReadCLUT8_16(const TEX0& tex0) +{ + bool changed = false; + + Indexor indexor(m_pRAM, tex0.GetCLUTPtr(), 1); + + for(unsigned int j = 0; j < 16; j++) + { + for(unsigned int i = 0; i < 16; i++) + { + uint16 color = indexor.GetPixel(i, j); + + uint8 index = i + (j * 16); + index = (index & ~0x18) | ((index & 0x08) << 1) | ((index & 0x10) >> 1); + + if(m_pCLUT[index] != color) + { + changed = true; + } + + m_pCLUT[index] = color; + } + } + + return changed; +} + void CGSHandler::ReadCLUT4(const TEX0& tex0) { bool updateNeeded = false; @@ -1054,26 +1111,11 @@ void CGSHandler::ReadCLUT4(const TEX0& tex0) } else if(tex0.nCPSM == PSMCT16) { - assert(tex0.nCSA < 32); - - CGsPixelFormats::CPixelIndexorPSMCT16 Indexor(m_pRAM, tex0.GetCLUTPtr(), 1); - uint32 clutOffset = tex0.nCSA * 16; - uint16* pDst = m_pCLUT + clutOffset; - - for(unsigned int j = 0; j < 2; j++) - { - for(unsigned int i = 0; i < 8; i++) - { - uint16 color = Indexor.GetPixel(i, j); - - if(*pDst != color) - { - changed = true; - } - - (*pDst++) = color; - } - } + changed = ReadCLUT4_16(tex0); + } + else if(tex0.nCPSM == PSMCT16S) + { + changed = ReadCLUT4_16(tex0); } else { @@ -1182,25 +1224,11 @@ void CGSHandler::ReadCLUT8(const TEX0& tex0) } else if(tex0.nCPSM == PSMCT16) { - CGsPixelFormats::CPixelIndexorPSMCT16 Indexor(m_pRAM, tex0.GetCLUTPtr(), 1); - - for(unsigned int j = 0; j < 16; j++) - { - for(unsigned int i = 0; i < 16; i++) - { - uint16 color = Indexor.GetPixel(i, j); - - uint8 index = i + (j * 16); - index = (index & ~0x18) | ((index & 0x08) << 1) | ((index & 0x10) >> 1); - - if(m_pCLUT[index] != color) - { - changed = true; - } - - m_pCLUT[index] = color; - } - } + changed = ReadCLUT8_16(tex0); + } + else if(tex0.nCPSM == PSMCT16S) + { + changed = ReadCLUT8_16(tex0); } else { diff --git a/Source/gs/GSHandler.h b/Source/gs/GSHandler.h index 118fb71d..f3a6e7f4 100644 --- a/Source/gs/GSHandler.h +++ b/Source/gs/GSHandler.h @@ -791,6 +791,8 @@ protected: template void TransferReadHandlerGeneric(void*, uint32); void SyncCLUT(const TEX0&); + template bool ReadCLUT4_16(const TEX0&); + template bool ReadCLUT8_16(const TEX0&); void ReadCLUT4(const TEX0&); void ReadCLUT8(const TEX0&);