Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.8 KiB

  1. /***************************************************************************
  2. Name : CRC.C
  3. Comment : HDLC encoding routines
  4. Functions: (see Prototypes just below)
  5. Copyright (c) Microsoft Corp. 1991 1992 1993
  6. Revision Log
  7. Date Name Description
  8. -------- ----- ---------------------------------------------------------
  9. ***************************************************************************/
  10. #include "prep.h"
  11. #include "decoder.h"
  12. #include "debug.h"
  13. #include "glbproto.h"
  14. #define FILEID FILEID_CRC
  15. WORD CODEBASED CRCTab[16] =
  16. { 0x0000, 0x1081, 0x2102, 0x3183,
  17. 0x4204, 0x5285, 0x6306, 0x7387,
  18. 0x8408, 0x9489, 0xa50a, 0xb58b,
  19. 0xc60c, 0xd68d, 0xe70e, 0xf78f };
  20. WORD SWECMEXP CalcCRC(PThrdGlbl pTG, LPBYTE lpbSrc, USHORT cbSrc)
  21. {
  22. #if !defined(PORTABLE_CODE) || defined(CLASS1_TEST_HOOKS)
  23. WORD wRet;
  24. #endif
  25. #ifdef PORTABLE_CODE
  26. USHORT wTempChar=0, j=0, wTempCRC=(USHORT)-1;
  27. USHORT SourceIndex;
  28. LPBYTE SourceAddress;
  29. SourceAddress = lpbSrc;
  30. for(SourceIndex = cbSrc;SourceIndex > 0; SourceIndex--) {
  31. wTempChar = (USHORT) *SourceAddress++;
  32. j = (wTempCRC ^ wTempChar) & 0x0f;
  33. wTempCRC = (wTempCRC >> 4) ^ CRCTab[j];
  34. wTempChar >>= 4;
  35. j = (wTempCRC ^ wTempChar) & 0x0f;
  36. wTempCRC = (wTempCRC >> 4) ^ CRCTab[j];
  37. }
  38. wTempCRC = ~wTempCRC;
  39. #endif
  40. #ifdef CLASS1_TEST_HOOKS
  41. if (wRet == wTempCRC) {
  42. // DEBUGMSG(1,("CalcCRC: Assembly and C CRC both = %X\n", wTempCRC));
  43. }
  44. else
  45. ERRORMSG(("CalcCRC: Assembly CRC = %X; C CRC = %X\n", wRet, wTempCRC));
  46. #endif
  47. #ifdef PORTABLE_CODE
  48. return wTempCRC;
  49. #else
  50. return wRet;
  51. #endif
  52. }