source: abuse/trunk/src/crc.cpp @ 494

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

File size: 1.0 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include "crc.h"
14
15uint16_t calc_crc(uint8_t *buf, int len)
16{
17  uint8_t c1=0,c2=0;
18  while (len)
19  {
20    len--;
21    c1+=*buf;
22    c2+=c1;
23    buf++;
24  }
25  return (c2<<8)|c1;
26}
27
28
29
30uint32_t crc_file(bFILE *fp)
31{
32  uint8_t crc1=0,crc2=0,crc3=0,crc4=0;
33
34  int size=0x1000;
35  uint8_t *buffer=(uint8_t *)malloc(size),*c;
36  long l=fp->file_size();
37  long cur_pos=fp->tell();
38  fp->seek(0,0);
39  while (l)
40  {
41    int nr=fp->read(buffer,size);
42    if (nr==0) l=0;
43    else
44    {
45      l-=nr;
46      for (c=buffer; nr; nr--,c++)
47      {
48    crc1+=*c;
49    crc2+=crc1;
50    crc3+=crc2;
51    crc4+=crc3;
52      }
53    }
54  }
55  fp->seek(cur_pos,0);
56  free(buffer);
57  return (crc1|(crc2<<8)|(crc3<<16)|(crc4<<24));
58}
Note: See TracBrowser for help on using the repository browser.