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