update crc
This commit is contained in:
+21
-22
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
Copyright (C) 1996-2001 Id Software, Inc.
|
||||
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||
Copyright (C) 2026 iikorni
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@@ -18,7 +19,6 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
/* crc.c */
|
||||
|
||||
#include "quakedef.hpp"
|
||||
#include "crc.hpp"
|
||||
@@ -27,10 +27,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
// and the initial and final xor values shown below... in other words, the
|
||||
// CCITT standard CRC used by XMODEM
|
||||
|
||||
#define CRC_INIT_VALUE 0xffff
|
||||
#define CRC_XOR_VALUE 0x0000
|
||||
constexpr unsigned short CRC_INIT_VALUE = 0xFFFF;
|
||||
constexpr unsigned short CRC_XOR_VALUE = 0x0000;
|
||||
|
||||
static const unsigned short crctable[256] =
|
||||
constexpr unsigned short CRC_TABLE[256] =
|
||||
{
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
||||
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
||||
@@ -66,29 +66,28 @@ static const unsigned short crctable[256] =
|
||||
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
||||
};
|
||||
|
||||
void CRC_Init(unsigned short *crcvalue)
|
||||
{
|
||||
*crcvalue = CRC_INIT_VALUE;
|
||||
}
|
||||
namespace crc {
|
||||
void init(unsigned short *val) {
|
||||
*val = CRC_INIT_VALUE;
|
||||
}
|
||||
|
||||
void CRC_ProcessByte(unsigned short *crcvalue, byte data)
|
||||
{
|
||||
*crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
|
||||
}
|
||||
void process_byte(unsigned short *val, const byte data) {
|
||||
*val = (*val << 8) ^ CRC_TABLE[(*val >> 8) ^ data];
|
||||
}
|
||||
|
||||
unsigned short CRC_Value(unsigned short crcvalue)
|
||||
{
|
||||
return crcvalue ^ CRC_XOR_VALUE;
|
||||
}
|
||||
unsigned short value(const unsigned short val) {
|
||||
return val ^ CRC_XOR_VALUE;
|
||||
}
|
||||
|
||||
//johnfitz -- texture crc
|
||||
unsigned short CRC_Block (const byte *start, int count)
|
||||
{
|
||||
unsigned short block(const byte *start, int count) {
|
||||
unsigned short crc;
|
||||
|
||||
CRC_Init (&crc);
|
||||
while (count--)
|
||||
crc = (crc << 8) ^ crctable[(crc >> 8) ^ *start++];
|
||||
init(&crc);
|
||||
while (count--) {
|
||||
crc = (crc << 8) ^ CRC_TABLE[(crc >> 8) ^ *start++];
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-11
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
Copyright (C) 1996-2001 Id Software, Inc.
|
||||
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||
Copyright (C) 2026 iikorni
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@@ -19,15 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _QUAKE_CRC_H
|
||||
#define _QUAKE_CRC_H
|
||||
|
||||
/* crc.h */
|
||||
|
||||
void CRC_Init(unsigned short *crcvalue);
|
||||
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
|
||||
|
||||
#endif /* _QUAKE_CRC_H */
|
||||
#pragma once
|
||||
|
||||
namespace crc {
|
||||
void init(unsigned short *val);
|
||||
void process_byte(unsigned short *val, byte data);
|
||||
unsigned short value(unsigned short val);
|
||||
unsigned short block(const byte *start, int count);
|
||||
}
|
||||
Reference in New Issue
Block a user