LCWUNCMP.ASM 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. ; $Header: g:/library/wwlib32/misc/rcs/lcwuncmp.asm 1.1 1994/04/11 15:31:21 jeff_wilson Exp $
  19. ;***************************************************************************
  20. ;** 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 **
  21. ;***************************************************************************
  22. ;* *
  23. ;* Project Name : Library routine *
  24. ;* *
  25. ;* File Name : UNCOMP.ASM *
  26. ;* *
  27. ;* Programmer : Christopher Yates *
  28. ;* *
  29. ;* Last Update : 20 August, 1990 [CY] *
  30. ;* *
  31. ;*-------------------------------------------------------------------------*
  32. ;* Functions: *
  33. ;* *
  34. ; ULONG LCW_Uncompress(BYTE *source, BYTE *dest, ULONG length); *
  35. ;* *
  36. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  37. IDEAL
  38. P386
  39. MODEL USE32 FLAT
  40. GLOBAL LCW_Uncompress :NEAR
  41. CODESEG
  42. ; ----------------------------------------------------------------
  43. ;
  44. ; Here are prototypes for the routines defined within this module:
  45. ;
  46. ; ULONG LCW_Uncompress(BYTE *source, BYTE *dest, ULONG length);
  47. ;
  48. ; ----------------------------------------------------------------
  49. PROC LCW_Uncompress C near
  50. USES ebx,ecx,edx,edi,esi
  51. ARG source:DWORD
  52. ARG dest:DWORD
  53. ARG length:DWORD
  54. ;LOCALS
  55. LOCAL a1stdest:DWORD
  56. LOCAL maxlen:DWORD
  57. LOCAL lastbyte:DWORD
  58. LOCAL lastcom:DWORD
  59. LOCAL lastcom1:DWORD
  60. mov edi,[dest]
  61. mov esi,[source]
  62. mov edx,[length]
  63. ;
  64. ;
  65. ; uncompress data to the following codes in the format b = byte, w = word
  66. ; n = byte code pulled from compressed data
  67. ; Bit field of n command description
  68. ; n=0xxxyyyy,yyyyyyyy short run back y bytes and run x+3
  69. ; n=10xxxxxx,n1,n2,...,nx+1 med length copy the next x+1 bytes
  70. ; n=11xxxxxx,w1 med run run x+3 bytes from offset w1
  71. ; n=11111111,w1,w2 long copy copy w1 bytes from offset w2
  72. ; n=11111110,w1,b1 long run run byte b1 for w1 bytes
  73. ; n=10000000 end end of data reached
  74. ;
  75. mov [a1stdest],edi
  76. add edx,edi
  77. mov [lastbyte],edx
  78. cld ; make sure all lod and sto are forward
  79. mov ebx,esi ; save the source offset
  80. ??loop:
  81. mov eax,[lastbyte]
  82. sub eax,edi ; get the remaining byte to uncomp
  83. jz short ??out ; were done
  84. mov [maxlen],eax ; save for string commands
  85. mov esi,ebx ; mov in the source index
  86. sub eax,eax
  87. lodsb
  88. or al,al ; see if its a short run
  89. js short ??notshort
  90. mov ah,al ; put rel offset high nibble in ah
  91. and ah,0Fh ; only 4 bits count
  92. sub ecx,ecx
  93. mov cl,al ; put count nibble in ch
  94. shr cl,4 ; get run -3
  95. add ecx,3 ; get actual run length
  96. cmp ecx,[maxlen] ; is it too big to fit?
  97. jbe short ??rsok ; if not, its ok
  98. mov ecx,[maxlen] ; if so, max it out so it dosen't overrun
  99. ??rsok:
  100. lodsb ; get rel offset low byte
  101. mov ebx,esi ; save the source offset
  102. mov esi,edi ; get the current dest
  103. sub esi,eax ; get relative offset
  104. rep movsb
  105. jmp ??loop
  106. ??notshort:
  107. test al,40h ; is it a length?
  108. jne short ??notlength ; if not it could be med or long run
  109. cmp al,80h ; is it the end?
  110. je short ??out ; if so its over
  111. mov cl,al ; put the byte in count register
  112. and ecx,3Fh ; and off the extra bits
  113. cmp ecx,[maxlen] ; is it too big to fit?
  114. jbe short ??lenok ; if not, its ok
  115. mov ecx,[maxlen] ; if so, max it out so it dosen't overrun
  116. ??lenok:
  117. rep movsb
  118. mov ebx,esi ; save the source offset
  119. jmp ??loop
  120. ??out:
  121. mov eax,edi
  122. sub eax,[a1stdest]
  123. jmp short ??exit
  124. ??notlength:
  125. mov cl,al ; get the entire code
  126. and ecx,3Fh ; and off all but the size -3
  127. add ecx,3 ; add 3 for byte count
  128. cmp al,0FEh
  129. jne short ??notrunlength
  130. sub eax,eax
  131. lodsw
  132. mov ecx,eax
  133. sub eax,eax
  134. lodsb
  135. mov ebx,esi ; save the source offset
  136. cmp ecx,[maxlen] ; is it too big to fit?
  137. jbe short ??runlenok ; if not, its ok
  138. mov ecx,[maxlen] ; if so, max it out so it dosen't overrun
  139. ??runlenok:
  140. rep stosb
  141. jmp ??loop
  142. ??notrunlength:
  143. cmp al,0FFh ; is it a long run?
  144. jne short ??notlong ; if not use the code as the size
  145. sub eax,eax
  146. lodsw ; if so, get the size
  147. mov ecx,eax ; put int the count byte
  148. ??notlong:
  149. lodsw ; get the rel index
  150. mov ebx,esi ; save the source offset
  151. add eax,[a1stdest] ; add in the first index
  152. mov esi,eax ; use this as a source
  153. cmp ecx,[maxlen] ; is it too big to fit?
  154. jbe short ??runok ; if not, its ok
  155. mov ecx,[maxlen] ; if so, max it out so it dosen't overrun
  156. ??runok:
  157. rep movsb
  158. jmp ??loop
  159. ??exit:
  160. mov eax,edi
  161. mov ebx,[dest]
  162. sub eax,ebx
  163. ret
  164. ENDP LCW_Uncompress
  165. ;***********************************************************
  166. END
  167.