CRC.ASM 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. ;*
  20. ;* C O N F I D E N T I A L --- W E S T W O O D S T U D I O S
  21. ;*
  22. ;*---------------------------------------------------------------------------
  23. ;*
  24. ;* FILE
  25. ;* crc.asm
  26. ;*
  27. ;* DESCRIPTION
  28. ;* CRC checksum calculation.
  29. ;*
  30. ;* PROGRAMMER
  31. ;* Joe L. Bostic
  32. ;*
  33. ;* DATE
  34. ;* January 26, 1995
  35. ;*
  36. ;*---------------------------------------------------------------------------
  37. ;*
  38. ;* PUBLIC
  39. ;* Calculate_CRC - Calculate CRC checksum.
  40. ;*
  41. ;****************************************************************************
  42. IDEAL
  43. P386
  44. MODEL USE32 FLAT
  45. LOCALS ??
  46. CODESEG
  47. ;****************************************************************************
  48. ;*
  49. ;* NAME
  50. ;* Calculate_CRC - Calculate CRC checksum.
  51. ;*
  52. ;* SYNOPSIS
  53. ;* CRC = Calculate_CRC(Buffer, Length)
  54. ;*
  55. ;* long Calculate_CRC(void *, long);
  56. ;*
  57. ;* FUNCTION
  58. ;* Compute a CRC checksum for a block of memory.
  59. ;*
  60. ;* INPUTS
  61. ;* Buffer - Pointer to buffer to calculate CRC for.
  62. ;* Length - Length of buffer.
  63. ;*
  64. ;* RESULT
  65. ;* CRC - CRC value.
  66. ;*
  67. ;****************************************************************************
  68. GLOBAL C Calculate_CRC:NEAR
  69. PROC Calculate_CRC C NEAR USES esi ebx ecx edx
  70. ARG buffer:NEAR PTR
  71. ARG length:DWORD
  72. mov esi,[buffer]
  73. cld
  74. ; Clear CRC to default (NULL) value.
  75. xor ebx,ebx
  76. mov ecx,[length] ;Get length of data block
  77. or ecx,ecx
  78. jz short ??fini
  79. ; Prepare the length counters.
  80. mov edx,ecx
  81. and dl,011b
  82. shr ecx,2
  83. ; Perform the bulk of the CRC scanning.
  84. or ecx,ecx
  85. jz short ??remainder
  86. ??accumloop:
  87. lodsd
  88. rol ebx,1
  89. add ebx,eax
  90. loop ??accumloop
  91. ; Handle the remainder bytes.
  92. ??remainder:
  93. or dl,dl
  94. jz short ??fini
  95. mov ecx,edx
  96. xor eax,eax
  97. push ecx
  98. ??nextbyte:
  99. lodsb
  100. ror eax,8
  101. loop ??nextbyte
  102. pop ecx
  103. neg ecx
  104. add ecx,4
  105. shl ecx,3
  106. ror eax,cl
  107. ;??nextbyte:
  108. ; shl eax,8
  109. ; lodsb
  110. ; loop ??nextbyte
  111. rol ebx,1
  112. add ebx,eax
  113. ??fini:
  114. mov eax,ebx
  115. ret
  116. ENDP Calculate_CRC
  117. END