Files
fail/bochs/iodev/crc32.cc
hsc b70b6fb43a another directory rename: failstar -> fail
"failstar" sounds like a name for a cruise liner from the 80s.  As "*" isn't a
desirable part of directory names, just name the whole thing "fail/", the core
parts being stored in "fail/core/".

Additionally fixing two build system dependency issues:
 - missing jobserver -> protomessages dependency
 - broken bochs -> fail dependency (add_custom_target DEPENDS only allows plain
   file dependencies ... cmake for the win)


git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@956 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
2012-03-08 19:43:02 +00:00

53 lines
1.1 KiB
C++

/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
/* CRC-32 calculator
* Adapted from http://www.createwindow.org/programming/crc32/
*/
#include "crc32.h"
CRC_Generator::CRC_Generator() {
init();
}
void CRC_Generator::init(void)
{
Bit32u POLYNOMIAL = 0x04c11db7;
int i;
for(i = 0; i<0xFF; i++) {
int j;
crc32_table[i]=reflect(i,8) << 24;
for(j=0; j<8; j++)
crc32_table[i] = (crc32_table[i]<<1)^(crc32_table[i] & (1<<31) ? POLYNOMIAL : 0);
crc32_table[i] = reflect(crc32_table[i], 32);
}
}
Bit32u CRC_Generator::reflect(Bit32u ref, Bit8u ch)
{
Bit32u value(0);
int i;
for(i=1; i<(ch+1); i++) {
if(ref & 1)
value |= 1 << (ch-i);
ref >>= 1;
}
return value;
}
Bit32u CRC_Generator::get_CRC(Bit8u * buf, Bit32u buflen)
{
Bit32u ulCRC(0xFFFFFFFF);
Bit32u len(buflen);
Bit8u * buffer=(Bit8u *) buf;
while(len--)
ulCRC=(ulCRC>>8)^crc32_table[(ulCRC & 0xFF)^*buffer++];
return ulCRC ^ 0xFFFFFFFF;
}