ASM.ASM 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. MODEL LARGE
  39. GLOBAL C Calculate_CRC:FAR
  40. CODESEG
  41. ; LONG Calculate_CRC(VOID *buffer, LONG length);
  42. PROC Calculate_CRC C far
  43. USES esi,ebx,ecx
  44. ARG buffer:DWORD
  45. ARG length:DWORD
  46. LOCAL crc:DWORD
  47. ; Load pointer to data block.
  48. mov [crc],0
  49. pushf
  50. mov esi,[buffer]
  51. cld
  52. ; Clear CRC to default (NULL) value.
  53. xor ebx,ebx
  54. ; Fetch the length of the data block to CRC.
  55. mov ecx,[length]
  56. jecxz short ??fini
  57. ; Prepare the length counters.
  58. mov edx,ecx
  59. and dl,011b
  60. shr ecx,2
  61. ; Perform the bulk of the CRC scanning.
  62. jecxz short ??remainder
  63. ??accumloop:
  64. lodsd
  65. rol ebx,1
  66. add ebx,eax
  67. loop ??accumloop
  68. ; Handle the remainder bytes.
  69. ??remainder:
  70. or dl,dl
  71. jz short ??fini
  72. mov ecx,edx
  73. xor eax,eax
  74. and ecx,0FFFFh
  75. push ecx
  76. ??nextbyte:
  77. lodsb
  78. ror eax,8
  79. loop ??nextbyte
  80. pop ecx
  81. neg ecx
  82. add ecx,4
  83. shl ecx,3
  84. ror eax,cl
  85. ;??nextbyte:
  86. ; shl eax,8
  87. ; lodsb
  88. ; loop ??nextbyte
  89. rol ebx,1
  90. add ebx,eax
  91. ??fini:
  92. mov [crc],ebx
  93. popf
  94. mov dx,[WORD PTR crc+2]
  95. mov ax,[WORD PTR crc]
  96. ret
  97. ENDP Calculate_CRC
  98. END