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

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

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

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