Quake II RTX doxygen  1.0 dev
crc.c File Reference
#include "shared/shared.h"

Go to the source code of this file.

Macros

#define CRC_INIT_VALUE   0xffff
 
#define CRC_XOR_VALUE   0x0000
 

Functions

static uint16_t CRC_Block (byte *start, size_t count)
 
byte COM_BlockSequenceCRCByte (byte *base, size_t length, int sequence)
 

Variables

static const uint16_t crctable [256]
 
static const byte chktbl [1024]
 

Macro Definition Documentation

◆ CRC_INIT_VALUE

#define CRC_INIT_VALUE   0xffff

Definition at line 26 of file crc.c.

◆ CRC_XOR_VALUE

#define CRC_XOR_VALUE   0x0000

Definition at line 27 of file crc.c.

Function Documentation

◆ COM_BlockSequenceCRCByte()

byte COM_BlockSequenceCRCByte ( byte *  base,
size_t  length,
int  sequence 
)

Definition at line 148 of file crc.c.

149 {
150  int n;
151  const byte *p;
152  int x;
153  byte chkb[60 + 4];
154  unsigned short crc;
155 
156  if (sequence < 0)
157  Com_Error(ERR_DROP, "%s: sequence < 0", __func__);
158 
159  p = chktbl + (sequence % (sizeof(chktbl) - 4));
160 
161  if (length > 60)
162  length = 60;
163  memcpy(chkb, base, length);
164 
165  chkb[length] = p[0];
166  chkb[length + 1] = p[1];
167  chkb[length + 2] = p[2];
168  chkb[length + 3] = p[3];
169 
170  length += 4;
171 
172  crc = CRC_Block(chkb, length);
173 
174  for (x = 0, n = 0; n < length; n++)
175  x += chkb[n];
176 
177  crc = (crc ^ x) & 0xff;
178 
179  return crc;
180 }

Referenced by CL_SendDefaultCmd().

◆ CRC_Block()

static uint16_t CRC_Block ( byte *  start,
size_t  count 
)
static

Definition at line 64 of file crc.c.

65 {
66  uint16_t crc = CRC_INIT_VALUE;
67 
68  while (count--)
69  crc = (crc << 8) ^ crctable[(crc >> 8) ^ *start++];
70 
71  return crc;
72 }

Referenced by COM_BlockSequenceCRCByte().

Variable Documentation

◆ chktbl

const byte chktbl[1024]
static

Definition at line 74 of file crc.c.

Referenced by COM_BlockSequenceCRCByte().

◆ crctable

const uint16_t crctable[256]
static

Definition at line 29 of file crc.c.

Referenced by CRC_Block().

CRC_Block
static uint16_t CRC_Block(byte *start, size_t count)
Definition: crc.c:64
CRC_INIT_VALUE
#define CRC_INIT_VALUE
Definition: crc.c:26
chktbl
static const byte chktbl[1024]
Definition: crc.c:74
crctable
static const uint16_t crctable[256]
Definition: crc.c:29
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258