Annotation of previous_trunk/src/utils.c, revision 1.1

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_fileid[] = "Hatari utils.c : " __DATE__ " " __TIME__;
        !            13: 
        !            14: #include "utils.h"
        !            15: 
        !            16: 
        !            17: /************************************************************************/
        !            18: /* Functions used to compute the CRC32 of a stream of bytes.           */
        !            19: /* These functions require a pointer to an unsigned int (Uint32) to    */
        !            20: /* store the resulting CRC.                                            */
        !            21: /*     crc32_reset : call this once to reset the CRC, before adding    */
        !            22: /*             some bytes.                                             */
        !            23: /*     crc32_add_byte : update the current CRC with a new byte.        */
        !            24: /************************************************************************/
        !            25: 
        !            26: /*--------------------------------------------------------------*/
        !            27: /* Reset the crc32 value. This should be done before calling   */
        !            28: /* crc32_add_byte().                                           */
        !            29: /*--------------------------------------------------------------*/
        !            30: 
        !            31: void   crc32_reset ( Uint32 *crc )
        !            32: {
        !            33:        *crc = 0xffffffff;
        !            34: }
        !            35: 
        !            36: 
        !            37: /*--------------------------------------------------------------*/
        !            38: /* Update the current value of crc with a new byte.            */
        !            39: /* Call crc32_reset() first to init the crc value.             */
        !            40: /*--------------------------------------------------------------*/
        !            41: 
        !            42: void   crc32_add_byte ( Uint32 *crc , Uint8 c )
        !            43: {
        !            44:        int     bit;
        !            45:     
        !            46:        for ( bit=0 ; bit<8; bit++ )
        !            47:        {
        !            48:                if ( ( c & 0x80 ) ^ ( *crc & 0x80000000 ) )
        !            49:                        *crc = ( *crc << 1 ) ^ CRC32_POLY;
        !            50: 
        !            51:                else
        !            52:                        *crc = *crc << 1;
        !            53: 
        !            54:             c <<= 1;
        !            55:         }
        !            56: }
        !            57: 
        !            58: 
        !            59: /************************************************************************/
        !            60: 
        !            61: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.