NX/VITA: Add crc16 builtin

This commit is contained in:
cypress 2024-01-07 10:41:52 -05:00
parent 2545fffde3
commit 9b804c4017
3 changed files with 40 additions and 1 deletions

View file

@ -92,3 +92,24 @@ unsigned short CRC_Block (const byte *start, int count)
return crc;
}
//
// taken from darkplaces -- just a shortcut for initialization for
// use with string-hashing (just progs, likely). -- cypress (07 jan 2024)
//
unsigned short CRC_Block2(const unsigned char *data, size_t size)
{
unsigned short crc = CRC_INIT_VALUE;
while (size--)
crc = (crc << 8) ^ crctable[(crc >> 8) ^ (*data++)];
return crc ^ CRC_XOR_VALUE;
}
unsigned short CRC_Block_CaseInsensitive(const unsigned char *data, size_t size)
{
unsigned short crc = CRC_INIT_VALUE;
while (size--)
crc = (crc << 8) ^ crctable[(crc >> 8) ^ (tolower(*data++))];
return crc ^ CRC_XOR_VALUE;
}

View file

@ -29,5 +29,8 @@ void CRC_ProcessByte(unsigned short *crcvalue, byte data);
unsigned short CRC_Value(unsigned short crcvalue);
unsigned short CRC_Block (const byte *start, int count); //johnfitz -- texture crc
unsigned short CRC_Block2(const unsigned char *data, size_t size);
unsigned short CRC_Block_CaseInsensitive(const unsigned char *data, size_t size);
#endif /* _QUAKE_CRC_H */

View file

@ -3241,6 +3241,21 @@ void PF_strtolower (void)
G_INT (OFS_RETURN) = PR_SetEngineString (result);
}
/*
=================
PF_crc16
float crc16 (float, string)
=================
*/
void PF_crc16(void)
{
int insens = G_FLOAT(OFS_PARM0);
char *s = G_STRING(OFS_PARM1);
G_FLOAT(OFS_RETURN) = (unsigned short) ((insens ? CRC_Block_CaseInsensitive : CRC_Block2) ((unsigned char *) s, strlen(s)));
}
/*
=================
PF_strlen
@ -3937,7 +3952,7 @@ static builtin_t pr_builtin[] =
NULL, // #491
NULL, // #492
NULL, // #493
NULL, // #494
PF_crc16, // #494
NULL, // #495
NULL, // #496
NULL, // #497