AUDUNCMP.ASM 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 S T U D I O S **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : Westwood 32 bit Audio Library *
  23. ;* *
  24. ;* File Name : AUDUNCMP.ASM *
  25. ;* *
  26. ;* Programmer : Phil W. Gorrow *
  27. ;* *
  28. ;* Start Date : March 14, 1995 *
  29. ;* *
  30. ;* Last Update : June 26, 1995 [PWG] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* Decompress_Frame_Lock -- locks the JLB audio decompression code *
  35. ;* Decompress_Frame_Unlock -- Unlocks the JLB audio compression code *
  36. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  37. IDEAL
  38. P386
  39. MODEL USE32 FLAT
  40. LOCALS ??
  41. CODESEG
  42. DPMI_INTR equ 31h
  43. LABEL LockedCodeStart BYTE
  44. CODE_2BIT EQU 0
  45. CODE_4BIT EQU 1
  46. CODE_RAW EQU 2
  47. CODE_SILENCE EQU 3
  48. MAGICNUMBER EQU 00000DEAFh
  49. MAGICNUMBER2 EQU 0BABEBABEh
  50. _2bitdecode DB -2,-1,0,1
  51. _4bitdecode DB -9,-8,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,8
  52. ;***************************************************************************
  53. ;* DECOMPRESS_FRAME -- Uncompresses a WW compressed audio frame *
  54. ;* *
  55. ;* INPUT: void * source - pointer to encoded audio data *
  56. ;* void * dest - pointer to decompression area *
  57. ;* long size - the maximum size of destination buffer *
  58. ;* *
  59. ;* OUTPUT: long - the number of bytes we uncompressed *
  60. ;* *
  61. ;* PROTO: long Decompress_Frame(void *, void *, long); *
  62. ;* *
  63. ;* HISTORY: *
  64. ;* 03/14/1995 PWG : Created. *
  65. ;*=========================================================================*
  66. GLOBAL C Decompress_Frame:NEAR
  67. PROC Decompress_Frame C NEAR USES ebx ecx edx esi edi
  68. ARG source:DWORD
  69. ARG dest:DWORD
  70. ARG count:DWORD
  71. LOCAL previous:BYTE
  72. LOCAL incount:DWORD
  73. pushfd
  74. cld
  75. mov [incount],0 ;Bytes read from source
  76. ; Source, Dest and count must be valid.
  77. cmp [source],0
  78. je ??fini
  79. cmp [dest],0
  80. je ??fini
  81. cmp [count],0
  82. je ??fini
  83. mov esi,[source] ;Pointer to source data.
  84. mov edi,[dest] ;Pointer to destination data.
  85. mov ecx,[count] ;Number of bytes to fill dest buffer.
  86. mov dl,080h ;Previous sample (starting value).
  87. ??mainloop:
  88. cmp ecx,0 ;If dest full then exit
  89. jle ??fini
  90. xor eax,eax
  91. mov al,[esi] ;Get code byte
  92. inc [incount]
  93. inc esi
  94. shl eax,2 ;AH contains code.
  95. shr al,2 ;AL contains sub-code data.
  96. cmp ah,CODE_RAW ;Raw sequence?
  97. jne short ??try4bit
  98. ; The code contains either a 5 bit delta or a count of
  99. ; raw samples to dump out.
  100. test al,00100000b
  101. je short ??justraw
  102. ; The lower 5 bits are actually a signed delta.
  103. ; Sign extend the delta and add it to the stream.
  104. shl al,3
  105. sar al,3
  106. add dl,al
  107. mov [edi],dl
  108. dec ecx
  109. inc edi
  110. jmp ??mainloop
  111. ; The lower 5 bits hold a count of the number of raw
  112. ; samples that follow this code. Dump these samples to
  113. ; the output buffer.
  114. ??justraw:
  115. mov ebx,ecx
  116. xor ah,ah
  117. inc al
  118. mov ecx,eax
  119. shr ecx,1
  120. rep movsw
  121. adc ecx,ecx
  122. rep movsb
  123. mov ecx,ebx
  124. add [incount],eax
  125. sub ecx,eax
  126. dec edi
  127. mov dl,[edi] ;Set "previous" value.
  128. inc edi
  129. jmp ??mainloop
  130. ; Check to see if this is a 4 bit delta code sequence.
  131. ??try4bit:
  132. inc al ;Following codes use AL+1
  133. cmp ah,CODE_4BIT
  134. jne short ??try2bit
  135. ; A sequence of 4bit deltas follow. AL equals the
  136. ; number of nibble packed delta bytes to process.
  137. ??bit4loop:
  138. mov ah,[esi] ;Fetch nibble packed delta codes
  139. mov bl,ah
  140. inc [incount]
  141. inc esi
  142. ; Add first delta to 'previous' sample already in DL.
  143. and ebx,00001111b
  144. add dl,[_4bitdecode+ebx]
  145. pushfd
  146. cmp [_4bitdecode+ebx],0
  147. jl short ??neg1
  148. popfd
  149. jnc short ??ok1
  150. mov dl,0FFh
  151. jmp short ??ok1
  152. ??neg1:
  153. popfd
  154. jc short ??ok1
  155. xor dl,dl
  156. ??ok1:
  157. mov dh,dl ;DH now holds new 'previous' sample.
  158. mov bl,ah
  159. shr bl,4
  160. add dh,[_4bitdecode+ebx]
  161. pushfd
  162. cmp [_4bitdecode+ebx],0
  163. jl short ??neg2
  164. popfd
  165. jnc short ??ok2
  166. mov dh,0FFh
  167. jmp short ??ok2
  168. ??neg2:
  169. popfd
  170. jc short ??ok2
  171. xor dh,dh
  172. ??ok2:
  173. mov [edi],dx ;Output the two sample bytes
  174. sub ecx,2
  175. add edi,2
  176. ; Put the correct 'previous' sample in DL where it belongs.
  177. mov dl,dh
  178. ; If there are more deltas to process then loop back.
  179. dec al
  180. jnz short ??bit4loop
  181. jmp ??mainloop
  182. ; Check to see if 2 bit deltas need to be processed.
  183. ??try2bit:
  184. cmp ah,CODE_2BIT
  185. jne ??zerodelta
  186. ; A sequence of 2bit deltas follow. AL equals the number of
  187. ; packed delta bytes to process.
  188. ??bit2loop:
  189. mov ah,[esi] ;Fetch packed delat codes
  190. inc [incount]
  191. inc esi
  192. ; Add first delta to 'previous' sample already in DL.
  193. mov bl,ah
  194. and ebx,000011b
  195. add dl,[_2bitdecode+ebx]
  196. pushfd
  197. cmp [_2bitdecode+ebx],0
  198. jl short ??neg3
  199. popfd
  200. jnc short ??ok3
  201. mov dl,0FFh
  202. jmp short ??ok3
  203. ??neg3:
  204. popfd
  205. jc short ??ok3
  206. xor dl,dl
  207. ??ok3:
  208. mov dh,dl
  209. ror edx,8
  210. mov bl,ah
  211. shr ebx,2
  212. and bl,00000011b
  213. add dl,[_2bitdecode+ebx]
  214. pushfd
  215. cmp [_2bitdecode+ebx],0
  216. jl short ??neg4
  217. popfd
  218. jnc short ??ok4
  219. mov dl,0FFh
  220. jmp short ??ok4
  221. ??neg4:
  222. popfd
  223. jc short ??ok4
  224. xor dl,dl
  225. ??ok4:
  226. mov dh,dl
  227. ror edx,8
  228. mov bl,ah
  229. shr ebx,4
  230. and bl,00000011b
  231. add dl,[_2bitdecode+ebx]
  232. pushfd
  233. cmp [_2bitdecode+ebx],0
  234. jl short ??neg5
  235. popfd
  236. jnc short ??ok5
  237. mov dl,0FFh
  238. jmp short ??ok5
  239. ??neg5:
  240. popfd
  241. jc short ??ok5
  242. xor dl,dl
  243. ??ok5:
  244. mov dh,dl
  245. ror edx,8
  246. mov bl,ah
  247. shr ebx,6
  248. and bl,00000011b
  249. add dl,[_2bitdecode+ebx]
  250. pushfd
  251. cmp [_2bitdecode+ebx],0
  252. jl short ??neg6
  253. popfd
  254. jnc short ??ok6
  255. mov dl,0FFh
  256. jmp short ??ok6
  257. ??neg6:
  258. popfd
  259. jc short ??ok6
  260. xor dl,dl
  261. ??ok6:
  262. ror edx,8
  263. mov [edi],edx ;Output two sample bytes
  264. sub ecx,4
  265. add edi,4
  266. ; Put the correct 'previous' sample in DL where it belongs.
  267. rol edx,8
  268. ; If there are more deltas to process then loop back.
  269. dec al
  270. jnz ??bit2loop
  271. jmp ??mainloop
  272. ; There is a run of zero deltas. Zero deltas merely duplicate
  273. ; the 'previous' sample the requested number of times.
  274. ??zerodelta:
  275. xor ebx,ebx
  276. mov bl,al
  277. mov al,dl
  278. sub ecx,ebx
  279. xchg ecx,ebx
  280. rep stosb
  281. mov ecx,ebx
  282. jmp ??mainloop
  283. ??fini:
  284. popfd
  285. mov eax,[incount]
  286. ret
  287. ENDP Decompress_Frame
  288. LABEL LockedCodeEnd BYTE
  289. END