2024-05-25 16:41:17 +00:00
|
|
|
#include "PCTex.h"
|
|
|
|
#include "validate.h"
|
2024-08-19 10:37:19 +00:00
|
|
|
#include "mem.h"
|
|
|
|
#include "dcfileio.h"
|
|
|
|
|
|
|
|
#include <cstring>
|
2024-05-25 16:41:17 +00:00
|
|
|
|
2024-08-19 21:07:05 +00:00
|
|
|
EXPORT SPCTexture gGlobalTextures[1024];
|
2024-08-04 16:09:01 +00:00
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void CheckValidTexture(i32)
|
|
|
|
{
|
|
|
|
printf("CheckValidTexture(i32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void ConvertPSXPaletteToPC(u16 const *,u16 *,u32,u32)
|
|
|
|
{
|
|
|
|
printf("ConvertPSXPaletteToPC(u16 const *,u16 *,u32,u32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void PCTEX_Init(void)
|
|
|
|
{
|
|
|
|
printf("PCTEX_Init(void)");
|
|
|
|
}
|
|
|
|
|
2024-08-19 10:37:19 +00:00
|
|
|
// @Ok
|
|
|
|
// @Matching
|
|
|
|
void* PCTex_BufferPVR(const char * a1, char * a2)
|
2024-08-04 16:09:01 +00:00
|
|
|
{
|
2024-08-19 10:37:19 +00:00
|
|
|
char nameBuf[128];
|
|
|
|
|
|
|
|
const char* fileName = a1;
|
|
|
|
if (!strchr(a1, '.'))
|
|
|
|
{
|
|
|
|
strcpy(nameBuf, a1);
|
|
|
|
strcat(nameBuf, ".pvr");
|
|
|
|
fileName = nameBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
i32* buf = reinterpret_cast<i32*>(a2);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
i32 size = FileIO_Open(fileName);
|
|
|
|
if (size <= 0)
|
|
|
|
{
|
|
|
|
print_if_false(0, "Can't find texture file!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = static_cast<i32*>(DCMem_New(size, 0, 1, 0, 1));
|
|
|
|
print_if_false(buf != 0, "out of memory");
|
|
|
|
|
|
|
|
FileIO_Load(buf);
|
|
|
|
FileIO_Sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
print_if_false(buf[4] == 0x54525650, "corrupted PVR file");
|
|
|
|
return buf;
|
2024-08-04 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_CountActiveTextures(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_CountActiveTextures(void)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_CreateClut(i32)
|
|
|
|
{
|
|
|
|
printf("PCTex_CreateClut(i32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void PCTex_CreateTexture16(i32,i32,void const *,u16 const *,char const *,i32,i32,u32)
|
|
|
|
{
|
|
|
|
printf("PCTex_CreateTexture16(i32,i32,void const *,u16 const *,char const *,i32,i32,u32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void PCTex_CreateTexture256(i32,i32,void const *,u16 const *,u32,char const *,i32,i32)
|
|
|
|
{
|
|
|
|
printf("PCTex_CreateTexture256(i32,i32,void const *,u16 const *,u32,char const *,i32,i32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
2024-08-19 11:05:00 +00:00
|
|
|
i32 PCTex_CreateTexturePVR(i32,i32,u32,void *,u32, const char *,u32)
|
2024-08-04 16:09:01 +00:00
|
|
|
{
|
|
|
|
printf("PCTex_CreateTexturePVR(i32,i32,u32,void const *,u32,char const *,u32)");
|
2024-08-19 11:05:00 +00:00
|
|
|
return 0x19082024;
|
2024-08-04 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void PCTex_CreateTexturePVRInId(i32,i32,i32,u32,void const *,u32,char const *,u32)
|
|
|
|
{
|
|
|
|
printf("PCTex_CreateTexturePVRInId(i32,i32,i32,u32,void const *,u32,char const *,u32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_FindUnusedTextureId(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_FindUnusedTextureId(void)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_FreePcIcons(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_FreePcIcons(void)");
|
|
|
|
}
|
|
|
|
|
2024-08-19 21:19:20 +00:00
|
|
|
// @Ok
|
|
|
|
IDirectDrawSurface7* PCTex_GetDirect3DTexture(i32 index)
|
2024-08-04 16:09:01 +00:00
|
|
|
{
|
2024-08-19 21:19:20 +00:00
|
|
|
return gGlobalTextures[index].mD3DTex;
|
2024-08-04 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_GetInvTextureSize(i32,float *,float *)
|
|
|
|
{
|
|
|
|
printf("PCTex_GetInvTextureSize(i32,float *,float *)");
|
|
|
|
}
|
|
|
|
|
2024-08-19 21:10:23 +00:00
|
|
|
// @Ok
|
|
|
|
void PCTex_GetTextureSize(
|
|
|
|
i32 index,
|
|
|
|
i32* pOne,
|
|
|
|
i32* pTwo)
|
2024-08-04 16:09:01 +00:00
|
|
|
{
|
2024-08-19 21:10:23 +00:00
|
|
|
*pOne = gGlobalTextures[index].mSizeOne;
|
|
|
|
*pTwo = gGlobalTextures[index].mSizeTwo;
|
2024-08-04 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_GetTextureSplitCount(i32)
|
|
|
|
{
|
|
|
|
printf("PCTex_GetTextureSplitCount(i32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_InitSystemTextures(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_InitSystemTextures(void)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void PCTex_LoadLtiTexture(char const *,u32,i32,u32)
|
|
|
|
{
|
|
|
|
printf("PCTex_LoadLtiTexture(char const *,u32,i32,u32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_LoadPcIcons(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_LoadPcIcons(void)");
|
|
|
|
}
|
|
|
|
|
2024-08-19 11:05:00 +00:00
|
|
|
// @Ok
|
|
|
|
void* PCTex_LoadTexturePVR(const char* a1, char* a2)
|
2024-08-04 16:09:01 +00:00
|
|
|
{
|
2024-08-19 11:05:00 +00:00
|
|
|
PVRHeader* pHeader = static_cast<PVRHeader*>(PCTex_BufferPVR(a1, a2));
|
|
|
|
i32 texRes = PCTex_CreateTexturePVR(
|
|
|
|
pHeader->field_1C,
|
|
|
|
pHeader->field_1E,
|
|
|
|
pHeader->field_18,
|
|
|
|
&pHeader->pTextureData,
|
|
|
|
0,
|
|
|
|
a1,
|
|
|
|
0);
|
|
|
|
|
|
|
|
print_if_false(texRes != -1, "texture cannot be smallvq: %s", a1);
|
|
|
|
if (!a2)
|
|
|
|
PCTex_UnbufferPVR(pHeader);
|
|
|
|
|
|
|
|
return reinterpret_cast<void*>(texRes);
|
2024-08-04 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_ReleaseAllTextures(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_ReleaseAllTextures(void)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_ReleaseSysTexture(i32,bool)
|
|
|
|
{
|
|
|
|
printf("PCTex_ReleaseSysTexture(i32,bool)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_ReleaseTexture(i32,bool)
|
|
|
|
{
|
|
|
|
printf("PCTex_ReleaseTexture(i32,bool)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void PCTex_ReloadTextures(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_ReloadTextures(void)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_TextureHasAlpha(i32)
|
|
|
|
{
|
|
|
|
printf("PCTex_TextureHasAlpha(i32)");
|
|
|
|
}
|
|
|
|
|
2024-08-19 10:43:07 +00:00
|
|
|
// @Ok
|
|
|
|
// @Matching
|
|
|
|
void PCTex_UnbufferPVR(PVRHeader* pPvrHeader)
|
2024-08-04 16:09:01 +00:00
|
|
|
{
|
2024-08-19 10:43:07 +00:00
|
|
|
Mem_Delete(pPvrHeader);
|
2024-08-04 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_UnloadTextures(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_UnloadTextures(void)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void PCTex_UpdateForSoftwareRenderer(void)
|
|
|
|
{
|
|
|
|
printf("PCTex_UpdateForSoftwareRenderer(void)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void clutToClutPc(u16 const *)
|
|
|
|
{
|
|
|
|
printf("clutToClutPc(u16 const *)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void copyBitmap(void const *,i32,void *,i32,i32,i32,i32)
|
|
|
|
{
|
|
|
|
printf("copyBitmap(void const *,i32,void *,i32,i32,i32,i32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void copyConvertBitmap(void const *,i32,i32,void *,i32,i32,i32,i32,bool)
|
|
|
|
{
|
|
|
|
printf("copyConvertBitmap(void const *,i32,i32,void *,i32,i32,i32,i32,bool)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void countLeadingZeroBits(u32)
|
|
|
|
{
|
|
|
|
printf("countLeadingZeroBits(u32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @MEDIUMTODO
|
|
|
|
void downloadTexture(PCTexture *,u16 *,i32,i32)
|
|
|
|
{
|
|
|
|
printf("downloadTexture(PCTexture *,u16 *,i32,i32)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void enumPixelFormatsCB(_DDPIXELFORMAT *,void *)
|
|
|
|
{
|
|
|
|
printf("enumPixelFormatsCB(_DDPIXELFORMAT *,void *)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void releaseClutPc(_ClutPC *)
|
|
|
|
{
|
|
|
|
printf("releaseClutPc(_ClutPC *)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @SMALLTODO
|
|
|
|
void shouldForceBlend(u16 *,i32,i32,i32)
|
|
|
|
{
|
|
|
|
printf("shouldForceBlend(u16 *,i32,i32,i32)");
|
|
|
|
}
|
2024-05-25 16:41:17 +00:00
|
|
|
|
|
|
|
// @NotOk
|
|
|
|
// globals
|
|
|
|
void PCTex_SetTextureUserData(int index, Bitmap256* texture)
|
|
|
|
{
|
2024-08-19 21:07:05 +00:00
|
|
|
gGlobalTextures[index].mTexture = texture;
|
2024-05-25 16:41:17 +00:00
|
|
|
}
|
|
|
|
|
2024-08-19 21:07:05 +00:00
|
|
|
// @Ok
|
2024-05-25 16:52:55 +00:00
|
|
|
float PCTex_GetTextureWScale(int index)
|
|
|
|
{
|
|
|
|
return gGlobalTextures[index].wScale;
|
|
|
|
}
|
|
|
|
|
2024-08-19 21:07:05 +00:00
|
|
|
// @Ok
|
2024-05-25 16:52:55 +00:00
|
|
|
float PCTex_GetTextureHScale(int index)
|
|
|
|
{
|
|
|
|
return gGlobalTextures[index].hScale;
|
|
|
|
}
|
|
|
|
|
2024-08-19 21:07:05 +00:00
|
|
|
// @Ok
|
2024-05-25 17:07:37 +00:00
|
|
|
int PCTex_GetTextureFlags(int index)
|
|
|
|
{
|
2024-08-19 21:07:05 +00:00
|
|
|
return gGlobalTextures[index].mFlags;
|
2024-05-25 17:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Ok
|
|
|
|
int __inline countBits(unsigned int value)
|
|
|
|
{
|
|
|
|
int bits = 0;
|
|
|
|
|
|
|
|
while (value)
|
|
|
|
{
|
|
|
|
bits += value & 1;
|
|
|
|
value >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
2024-05-25 17:10:49 +00:00
|
|
|
// @Ok
|
|
|
|
int __inline countLeadingBits(unsigned int value)
|
|
|
|
{
|
|
|
|
int bits = 0;
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while(!(value & 1))
|
|
|
|
{
|
|
|
|
value >>= 1;
|
|
|
|
bits++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
2024-08-19 21:07:05 +00:00
|
|
|
// @Ok
|
|
|
|
// @Matching
|
2024-05-27 16:58:37 +00:00
|
|
|
int PCTex_GetTextureSplitID(int index, int id)
|
|
|
|
{
|
2024-08-19 21:07:05 +00:00
|
|
|
return gGlobalTextures[index].mSplit[id];
|
2024-05-27 16:58:37 +00:00
|
|
|
}
|
|
|
|
|
2024-08-19 21:07:05 +00:00
|
|
|
void validate_SPCTexture(void)
|
2024-05-25 16:41:17 +00:00
|
|
|
{
|
2024-08-19 21:07:05 +00:00
|
|
|
VALIDATE_SIZE(SPCTexture, 0x68);
|
|
|
|
|
|
|
|
VALIDATE(SPCTexture, mSizeOne, 0x0);
|
|
|
|
VALIDATE(SPCTexture, mSizeTwo, 0x2);
|
2024-05-25 16:41:17 +00:00
|
|
|
|
2024-08-19 21:07:05 +00:00
|
|
|
VALIDATE(SPCTexture, wScale, 0x4);
|
|
|
|
VALIDATE(SPCTexture, hScale, 0x8);
|
|
|
|
VALIDATE(SPCTexture, mTexture, 0x14);
|
2024-08-19 21:19:20 +00:00
|
|
|
VALIDATE(SPCTexture, mD3DTex, 0x1C);
|
2024-08-19 21:07:05 +00:00
|
|
|
VALIDATE(SPCTexture, mFlags, 0x20);
|
|
|
|
VALIDATE(SPCTexture, mSplit, 0x58);
|
2024-05-25 16:41:17 +00:00
|
|
|
}
|
2024-08-19 10:43:07 +00:00
|
|
|
|
|
|
|
void validate_PVRHeader(void)
|
|
|
|
{
|
2024-08-19 11:05:00 +00:00
|
|
|
VALIDATE_SIZE(PVRHeader, 0x24);
|
|
|
|
|
|
|
|
VALIDATE(PVRHeader, field_18, 0x18);
|
|
|
|
VALIDATE(PVRHeader, field_1C, 0x1C);
|
|
|
|
VALIDATE(PVRHeader, field_1E, 0x1E);
|
|
|
|
VALIDATE(PVRHeader, pTextureData, 0x20);
|
2024-08-19 10:43:07 +00:00
|
|
|
}
|