Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-video-glide64/src/CRC.h
2 views
1
/*
2
* Glide64 - Glide video plugin for Nintendo 64 emulators.
3
* Copyright (c) 2002 Dave2001
4
* Copyright (c) 2008 Günther <[email protected]>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public
17
* Licence along with this program; if not, write to the Free
18
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA
20
*/
21
22
//****************************************************************
23
//
24
// Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)
25
// Project started on December 29th, 2001
26
//
27
// To modify Glide64:
28
// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.
29
// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.
30
//
31
// Official Glide64 development channel: #Glide64 on EFnet
32
//
33
// Original author: Dave2001 ([email protected])
34
// Other authors: Gonetz, Gugaman
35
//
36
//****************************************************************
37
//
38
// CRC32 calculation functions
39
//
40
// Created by Gonetz, 2004
41
//
42
//****************************************************************
43
44
#if !defined(WIN32) && defined(GCC)
45
#define Crc32 _Crc32
46
#define CRCTable _CRCTable
47
#endif
48
49
extern unsigned int CRCTable[ 256 ];
50
51
void CRC_BuildTable();
52
53
inline unsigned int CRC_Calculate( unsigned int crc, const void *buffer, unsigned int count )
54
{
55
#if !defined(__GNUC__) && !defined(NO_ASM)
56
unsigned int Crc32=crc;
57
__asm {
58
mov esi, buffer
59
mov edx, count
60
add edx, esi
61
mov ecx, crc
62
63
loop1:
64
mov bl, byte ptr [esi]
65
movzx eax, cl
66
inc esi
67
xor al, bl
68
shr ecx, 8
69
mov ebx, [CRCTable+eax*4]
70
xor ecx, ebx
71
72
cmp edx, esi
73
jne loop1
74
75
xor Crc32, ecx
76
}
77
return Crc32;
78
#else
79
unsigned int result = crc;
80
for (const char * p = (const char*)buffer; p != (const char*)buffer + count; ++p)
81
{
82
unsigned char al = result;
83
al ^= *p;
84
result >>= 8;
85
result ^= CRCTable[al];
86
}
87
result ^= crc;
88
return result;
89
#endif
90
}
91
92
93