|
|
1.1 ! root 1: /* ! 2: * Hatari - utils.c ! 3: * ! 4: * This file is distributed under the GNU Public License, version 2 or at ! 5: * your option any later version. Read the file gpl.txt for details. ! 6: * ! 7: * Utils functions : ! 8: * - CRC32 ! 9: * ! 10: * This file contains various utility functions used by different parts of Hatari. ! 11: */ ! 12: const char Utils_rcsid[] = "Hatari $Id: utils.c,v 1.2 2008/10/05 20:41:50 npomarede Exp $"; ! 13: ! 14: ! 15: /* 2008/07/08 [NP] File creation, CRC32 functions. */ ! 16: ! 17: ! 18: #include "utils.h" ! 19: ! 20: ! 21: ! 22: ! 23: /************************************************************************/ ! 24: /* Functions used to compute the CRC32 of a stream of bytes. */ ! 25: /* These functions require a pointer to an unsigned int (Uint32) to */ ! 26: /* store the resulting CRC. */ ! 27: /* crc32_reset : call this once to reset the CRC, before adding */ ! 28: /* some bytes. */ ! 29: /* crc32_add_byte : update the current CRC with a new byte. */ ! 30: /************************************************************************/ ! 31: ! 32: /*--------------------------------------------------------------*/ ! 33: /* Reset the crc32 value. This should be done before calling */ ! 34: /* crc32_add_byte(). */ ! 35: /*--------------------------------------------------------------*/ ! 36: ! 37: void crc32_reset ( Uint32 *crc ) ! 38: { ! 39: *crc = 0xffffffff; ! 40: } ! 41: ! 42: ! 43: /*--------------------------------------------------------------*/ ! 44: /* Update the current value of crc with a new byte. */ ! 45: /* Call crc32_reset() first to init the crc value. */ ! 46: /*--------------------------------------------------------------*/ ! 47: ! 48: void crc32_add_byte ( Uint32 *crc , Uint8 c ) ! 49: { ! 50: int bit; ! 51: ! 52: for ( bit=0 ; bit<8; bit++ ) ! 53: { ! 54: if ( ( c & 0x80 ) ^ ( *crc & 0x80000000 ) ) ! 55: *crc = ( *crc << 1 ) ^ CRC32_POLY; ! 56: ! 57: else ! 58: *crc = *crc << 1; ! 59: ! 60: c <<= 1; ! 61: } ! 62: } ! 63: ! 64: ! 65: /************************************************************************/ ! 66: ! 67:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.