Path: blob/master/libmupen64plus/mupen64plus-video-glide64/src/CRC.h
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013* Copyright (c) 2008 Günther <[email protected]>4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public16* Licence along with this program; if not, write to the Free17* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,18* Boston, MA 02110-1301, USA19*/2021//****************************************************************22//23// Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)24// Project started on December 29th, 200125//26// To modify Glide64:27// * 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.28// * 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.29//30// Official Glide64 development channel: #Glide64 on EFnet31//32// Original author: Dave2001 ([email protected])33// Other authors: Gonetz, Gugaman34//35//****************************************************************36//37// CRC32 calculation functions38//39// Created by Gonetz, 200440//41//****************************************************************4243#if !defined(WIN32) && defined(GCC)44#define Crc32 _Crc3245#define CRCTable _CRCTable46#endif4748extern unsigned int CRCTable[ 256 ];4950void CRC_BuildTable();5152inline unsigned int CRC_Calculate( unsigned int crc, const void *buffer, unsigned int count )53{54#if !defined(__GNUC__) && !defined(NO_ASM)55unsigned int Crc32=crc;56__asm {57mov esi, buffer58mov edx, count59add edx, esi60mov ecx, crc6162loop1:63mov bl, byte ptr [esi]64movzx eax, cl65inc esi66xor al, bl67shr ecx, 868mov ebx, [CRCTable+eax*4]69xor ecx, ebx7071cmp edx, esi72jne loop17374xor Crc32, ecx75}76return Crc32;77#else78unsigned int result = crc;79for (const char * p = (const char*)buffer; p != (const char*)buffer + count; ++p)80{81unsigned char al = result;82al ^= *p;83result >>= 8;84result ^= CRCTable[al];85}86result ^= crc;87return result;88#endif89}90919293