Skip to content

Commit

Permalink
NX/VITA: Add crc16 builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
MotoLegacy committed Jan 7, 2024
1 parent 2545fff commit 9b804c4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
21 changes: 21 additions & 0 deletions source/crc.c
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions source/crc.h
Expand Up @@ -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 */

17 changes: 16 additions & 1 deletion source/pr_cmds.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9b804c4

Please sign in to comment.