CRC.ASM 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ;
  2. ; Command & Conquer Red Alert(tm)
  3. ; Copyright 2025 Electronic Arts Inc.
  4. ;
  5. ; This program is free software: you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation, either version 3 of the License, or
  8. ; (at your option) 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 of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ; GNU General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;
  18. ;***************************************************************************
  19. ;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : Westwood Library *
  23. ;* *
  24. ;* File Name : CRC.ASM *
  25. ;* *
  26. ;* Programmer : Joe L. Bostic *
  27. ;* *
  28. ;* Start Date : June 12, 1992 *
  29. ;* *
  30. ;* Last Update : February 10, 1995 [BWG] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  35. IDEAL
  36. P386
  37. MODEL USE32 FLAT
  38. GLOBAL Calculate_CRC :NEAR
  39. CODESEG
  40. ; LONG Calculate_CRC(VOID *buffer, LONG length);
  41. PROC Calculate_CRC C near
  42. USES esi
  43. ARG buffer:DWORD
  44. ARG length:DWORD
  45. LOCAL crc:DWORD
  46. ; Load pointer to data block.
  47. mov [crc],0
  48. pushad
  49. mov esi,[buffer]
  50. cld
  51. ; Clear CRC to default (NULL) value.
  52. xor ebx,ebx
  53. ; Fetch the length of the data block to CRC.
  54. mov ecx,[length]
  55. jecxz short ??fini
  56. ; Prepare the length counters.
  57. mov edx,ecx
  58. and dl,011b
  59. shr ecx,2
  60. ; Perform the bulk of the CRC scanning.
  61. jecxz short ??remainder
  62. ??accumloop:
  63. lodsd
  64. rol ebx,1
  65. add ebx,eax
  66. loop ??accumloop
  67. ; Handle the remainder bytes.
  68. ??remainder:
  69. or dl,dl
  70. jz short ??fini
  71. mov ecx,edx
  72. xor eax,eax
  73. and ecx,0FFFFh
  74. push ecx
  75. ??nextbyte:
  76. lodsb
  77. ror eax,8
  78. loop ??nextbyte
  79. pop ecx
  80. neg ecx
  81. add ecx,4
  82. shl ecx,3
  83. ror eax,cl
  84. ;??nextbyte:
  85. ; shl eax,8
  86. ; lodsb
  87. ; loop ??nextbyte
  88. rol ebx,1
  89. add ebx,eax
  90. ??fini:
  91. mov [crc],ebx
  92. popad
  93. mov eax,[crc]
  94. ret
  95. ENDP Calculate_CRC
  96. END
  97.