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