OLSOSDEC.ASM 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. ;* Copyright (c) 1994, HMI, INC. All Rights Reserved
  21. ;*
  22. ;*---------------------------------------------------------------------------
  23. ;*
  24. ;* FILE
  25. ;* soscodec.asm
  26. ;*
  27. ;* DESCRIPTION
  28. ;* HMI SOS ADPCM compression/decompression.
  29. ;*
  30. ;* PROGRAMMER
  31. ;* Nick Skrepetos
  32. ;* Denzil E. Long, Jr. (Fixed bugs, rewrote for watcom)
  33. ;* Bill Petro (Added stereo support)
  34. ;* DATE
  35. ;* Febuary 15, 1995
  36. ;*
  37. ;*---------------------------------------------------------------------------
  38. ;*
  39. ;* PUBLIC
  40. ;*
  41. ;****************************************************************************
  42. IDEAL
  43. P386
  44. MODEL USE32 FLAT
  45. LOCALS ??
  46. DPMI_INTR equ 31h
  47. IF_LOCKED_PM_CODE equ 1h ; Locked PM code for DPMI.
  48. IF_LOCKED_PM_DATA equ 2h ; Locked PM code for DPMI.
  49. STRUC sCompInfo
  50. lpSource DD ? ;Compressed data pointer
  51. lpDest DD ? ;Uncompressed data pointer
  52. dwCompSize DD ? ;Compressed size
  53. dwUnCompSize DD ? ;Uncompressed size
  54. dwSampleIndex DD ? ;Index into sample
  55. dwPredicted DD ? ;Next predicted value
  56. dwDifference DD ? ;Difference from last sample
  57. wCodeBuf DW ? ;Holds 2 nibbles for decompression
  58. wCode DW ? ;Current 4 bit code
  59. wStep DW ? ;Step value in table
  60. wIndex DW ? ;Index into step table
  61. dwSampleIndex2 DD ? ;Index into sample
  62. dwPredicted2 DD ? ;Next predicted value
  63. dwDifference2 DD ? ;Difference from last sample
  64. wCodeBuf2 DW ? ;Holds 2 nibbles for decompression
  65. wCode2 DW ? ;Current 4 bit code
  66. wStep2 DW ? ;Step value in table
  67. wIndex2 DW ? ;Index into step table
  68. wBitSize DW ? ;Bit size for decompression
  69. wChannels DW ? ;number of channels
  70. ENDS sCompInfo
  71. DATASEG
  72. InitFlags DD 0 ; Flags to indicate what has been initialized.
  73. LABEL LockedDataStart BYTE
  74. ;* Index table for stepping into step table
  75. wCODECIndexTab DW -1,-1,-1,-1,2,4,6,8
  76. DW -1,-1,-1,-1,2,4,6,8
  77. ;Lookup table of replacement values
  78. ;The actual sound value is replaced with an index to lookup in this table
  79. ;The index only takes up a nibble(4bits) and represents an int(16bits)
  80. ;Essentially:
  81. ;Get a value
  82. ;compare it with the value before it
  83. ;find closest value in table and store the index into the table
  84. ;if i'm going down then negitize it
  85. ;go to next byte.
  86. ;Theory for stereo:
  87. ;1)handle stereo and mono in two seperate loops. cleaner...
  88. ;start at byte 0 and skip every other byte(or word) both write and read
  89. ;when we get done
  90. ; set start byte to 1 and do it again
  91. ;This table essentialy round off to closes values in 3 distinct bands
  92. ; precalculated and optimized(i guess) for human hearing.
  93. wCODECStepTab DW 7, 8, 9, 10, 11, 12, 13,14
  94. DW 16, 17, 19, 21, 23, 25, 28, 31
  95. DW 34, 37, 41, 45, 50, 55, 60, 66
  96. DW 73, 80, 88, 97, 107, 118, 130, 143
  97. DW 157, 173, 190, 209, 230, 253, 279, 307
  98. DW 337, 371, 408, 449, 494, 544, 598, 658
  99. DW 724, 796, 876, 963, 1060, 1166, 1282, 1411
  100. DW 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024
  101. DW 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484
  102. DW 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899
  103. DW 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794
  104. DW 32767
  105. ;dwCODECByteIndex DD 0 ; this is when to stop compressing
  106. ;dwCODECTempStep DD 0 ; tempory storage for step value
  107. ;wCODECMask DW 0 ; Current mask
  108. LABEL LockedDataEnd BYTE
  109. CODESEG
  110. LABEL LockedCodeStart BYTE
  111. ;****************************************************************************
  112. ;*
  113. ;* NAME
  114. ;* sosCODECInitStream - Initialize compression stream.
  115. ;*
  116. ;* SYNOPSIS
  117. ;* sosCODECInitStream(CompInfo)
  118. ;*
  119. ;* void sosCODECInitStream(_SOS_COMPRESS_INFO *);
  120. ;*
  121. ;* FUNCTION
  122. ;* Initialize compression stream for compression and decompression.
  123. ;*
  124. ;* INPUTS
  125. ;* CompInfo - Compression information structure.
  126. ;*
  127. ;* RESULT
  128. ;* NONE
  129. ;*
  130. ;****************************************************************************
  131. GLOBAL C sosCODECInitStream:NEAR
  132. PROC sosCODECInitStream C NEAR
  133. ARG sSOSInfo:NEAR PTR
  134. mov eax,[sSOSInfo]
  135. mov [(sCompInfo eax).wIndex],0 ; starting index 0
  136. mov [(sCompInfo eax).wStep],7 ; start with a step of 7
  137. mov [(sCompInfo eax).dwPredicted],0 ; no predicted value
  138. mov [(sCompInfo eax).dwSampleIndex],0 ;start at head of index
  139. mov [(sCompInfo eax).wIndex2],0 ; starting index 0
  140. mov [(sCompInfo eax).wStep2],7 ; start with a step of 7
  141. mov [(sCompInfo eax).dwPredicted2],0 ; no predicted value
  142. mov [(sCompInfo eax).dwSampleIndex2],0 ;start at head of index
  143. ret
  144. ENDP sosCODECInitStream
  145. ;****************************************************************************
  146. ;*
  147. ;* NAME
  148. ;* sosCODECDecompressData - Decompress audio data.
  149. ;*
  150. ;* SYNOPSIS
  151. ;* Size = sosCODECDecompressData(CompInfo, NumBytes)
  152. ;*
  153. ;* long sosCODECDecompressData(_SOS_COMPRESS_INFO *, long);
  154. ;*
  155. ;* FUNCTION
  156. ;* Decompress data from a 4:1 ADPCM compressed stream. The number of
  157. ;* bytes decompressed is returned.
  158. ;*
  159. ;* INPUTS
  160. ;* CompInfo - Compress information structure.
  161. ;* NumBytes - Number of bytes to compress.
  162. ;*
  163. ;* RESULT
  164. ;* Size - Size of decompressed data.
  165. ;*
  166. ;****************************************************************************
  167. GLOBAL C General_sosCODECDecompressData:NEAR
  168. PROC General_sosCODECDecompressData C NEAR
  169. ARG sSOSInfo:NEAR PTR
  170. ARG wBytes:DWORD
  171. local dwCODECBytesProcessed:dword ;bytes to decompress
  172. local dwCODECByteIndex:dword ;this is when to stop compressing
  173. ; these need to be local if the function is to be reenterant
  174. push esi
  175. push edi
  176. push ebx
  177. push ecx
  178. push edx
  179. ;*---------------------------------------------------------------------------
  180. ;* Initialize
  181. ;*---------------------------------------------------------------------------
  182. mov ebx,[sSOSInfo]
  183. mov eax,[wBytes]
  184. mov [dwCODECBytesProcessed],eax
  185. mov [(sCompInfo ebx).dwSampleIndex],0 ;start at head of index
  186. mov [(sCompInfo ebx).dwSampleIndex2],0 ;start at head of index
  187. ;Check for 16 bit decompression
  188. cmp [(sCompInfo ebx).wBitSize],16
  189. jne short ??skipByteDivide
  190. shr eax,1 ;Divide size by two
  191. ??skipByteDivide:
  192. mov [dwCODECByteIndex],eax
  193. mov esi,[(sCompInfo ebx).lpSource]
  194. mov edi,[(sCompInfo ebx).lpDest]
  195. cmp [(sCompInfo ebx).wChannels],2 ;stereo check
  196. je ??mainloopl ;do left side first
  197. ; Determine if sample index is even or odd. This will determine
  198. ; if we need to get a new token or not.
  199. ;---------------------------------------------------------------------------
  200. ;Main Mono Loop
  201. ;---------------------------------------------------------------------------
  202. ??mainloop:
  203. test [(sCompInfo ebx).dwSampleIndex],1 ;odd ??
  204. je short ??fetchToken ; if so get new token
  205. xor eax,eax ;else shift int codebuf
  206. mov ax,[(sCompInfo ebx).wCodeBuf] ;ored with Code
  207. shr eax,4
  208. and eax,000Fh
  209. mov [(sCompInfo ebx).wCode],ax
  210. jmp short ??calcDifference
  211. ??fetchToken:
  212. xor eax,eax ;get a new token
  213. mov al,[esi] ;put in codebuf
  214. mov [(sCompInfo ebx).wCodeBuf],ax
  215. inc esi
  216. and eax,000Fh
  217. mov [(sCompInfo ebx).wCode],ax ;and then code
  218. ??calcDifference:
  219. mov [(sCompInfo ebx).dwDifference],0 ;reset diff
  220. xor ecx,ecx
  221. mov cx,[(sCompInfo ebx).wStep] ;cx is step value
  222. test eax,4 ;Check for wCode & 4
  223. je short ??no4
  224. add [(sCompInfo ebx).dwDifference],ecx ;Add wStep
  225. ??no4:
  226. test eax,2 ;Check for wCode & 2
  227. je short ??no2
  228. mov edx,ecx ;Add wStep >> 1
  229. shr edx,1
  230. add [(sCompInfo ebx).dwDifference],edx
  231. ??no2:
  232. test eax,1 ;Check for wCode & 1
  233. je short ??no1
  234. mov edx,ecx ;Add wStep >> 2
  235. shr edx,2
  236. add [(sCompInfo ebx).dwDifference],edx
  237. ??no1:
  238. mov edx,ecx ;Add in wStep >> 3
  239. shr edx,3
  240. add [(sCompInfo ebx).dwDifference],edx
  241. test eax,8 ;Check for wCode & 8
  242. je short ??no8
  243. neg [(sCompInfo ebx).dwDifference] ;Negate diff
  244. ??no8:
  245. ; add difference to predicted value.
  246. mov eax,[(sCompInfo ebx).dwPredicted]
  247. add eax,[(sCompInfo ebx).dwDifference]
  248. ; make sure there is no under or overflow.
  249. cmp eax,7FFFh
  250. jl short ??noOverflow
  251. mov eax,7FFFh
  252. ??noOverflow:
  253. cmp eax,0FFFF8000h
  254. jg short ??noUnderflow
  255. mov eax,0FFFF8000h
  256. ??noUnderflow:
  257. mov [(sCompInfo ebx).dwPredicted],eax
  258. cmp [(sCompInfo ebx).wBitSize],16
  259. jne short ??output8Bit
  260. mov [edi],ax ;Output 16bit sample
  261. add edi,2
  262. jmp short ??adjustIndex
  263. ??output8Bit:
  264. ; output 8 bit sample
  265. xor ah,80h
  266. mov [edi],ah
  267. inc edi
  268. ??adjustIndex:
  269. xor ecx,ecx
  270. mov cx,[(sCompInfo ebx).wCode]
  271. xor eax,eax
  272. shl ecx,1
  273. mov ax,[wCODECIndexTab + ecx]
  274. add [(sCompInfo ebx).wIndex],ax ;check if wIndex < 0
  275. cmp [(sCompInfo ebx).wIndex],8000h
  276. jb short ??checkOverflow
  277. mov [(sCompInfo ebx).wIndex],0 ;reset index to zero
  278. jmp short ??adjustStep
  279. ??checkOverflow:
  280. cmp [(sCompInfo ebx).wIndex],88 ;check if wIndex > 88
  281. jbe short ??adjustStep
  282. mov [(sCompInfo ebx).wIndex],88 ;reset index to 88
  283. ??adjustStep:
  284. ; fetch wIndex so we can fetch new step value
  285. xor ecx,ecx
  286. mov cx,[(sCompInfo ebx).wIndex]
  287. xor eax,eax
  288. shl ecx,1
  289. mov ax,[wCODECStepTab + ecx]
  290. ; advance index and store step value
  291. add [(sCompInfo ebx).dwSampleIndex],1
  292. mov [(sCompInfo ebx).wStep],ax
  293. ; decrement bytes processed and loop back.
  294. dec [dwCODECByteIndex]
  295. jne ??mainloop
  296. jmp ??exitout
  297. ;--------------------------------------------------------------------------
  298. ;Left Channel Start
  299. ;--------------------------------------------------------------------------
  300. ??mainloopl:
  301. test [(sCompInfo ebx).dwSampleIndex],1
  302. je short ??fetchTokenl
  303. xor eax,eax
  304. mov ax,[(sCompInfo ebx).wCodeBuf]
  305. shr eax,4
  306. and eax,000Fh
  307. mov [(sCompInfo ebx).wCode],ax
  308. jmp short ??calcDifferencel
  309. ??fetchTokenl:
  310. xor eax,eax
  311. mov al,[esi]
  312. mov [(sCompInfo ebx).wCodeBuf],ax
  313. add esi,2 ;2 for stereo
  314. and eax,000Fh
  315. mov [(sCompInfo ebx).wCode],ax
  316. ??calcDifferencel:
  317. ; reset difference
  318. mov [(sCompInfo ebx).dwDifference],0
  319. xor ecx,ecx
  320. mov cx,[(sCompInfo ebx).wStep]
  321. test eax,4 ;Check for wCode & 4
  322. je short ??no4l
  323. add [(sCompInfo ebx).dwDifference],ecx ;Add wStep
  324. ??no4l:
  325. test eax,2 ;Check for wCode & 2
  326. je short ??no2l
  327. mov edx,ecx ;Add wStep >> 1
  328. shr edx,1
  329. add [(sCompInfo ebx).dwDifference],edx
  330. ??no2l:
  331. test eax,1 ;Check for wCode & 1
  332. je short ??no1l
  333. mov edx,ecx ;Add wStep >> 2
  334. shr edx,2
  335. add [(sCompInfo ebx).dwDifference],edx
  336. ??no1l:
  337. mov edx,ecx ;Add in wStep >> 3
  338. shr edx,3
  339. add [(sCompInfo ebx).dwDifference],edx
  340. test eax,8 ;Check for wCode & 8
  341. je short ??no8l
  342. neg [(sCompInfo ebx).dwDifference] ;Negate diff
  343. ??no8l:
  344. ; add difference to predicted value.
  345. mov eax,[(sCompInfo ebx).dwPredicted]
  346. add eax,[(sCompInfo ebx).dwDifference]
  347. ; make sure there is no under or overflow.
  348. cmp eax,7FFFh
  349. jl short ??noOverflowl
  350. mov eax,7FFFh
  351. ??noOverflowl:
  352. cmp eax,0FFFF8000h
  353. jg short ??noUnderflowl
  354. mov eax,0FFFF8000h
  355. ??noUnderflowl:
  356. mov [(sCompInfo ebx).dwPredicted],eax
  357. cmp [(sCompInfo ebx).wBitSize],16
  358. jne short ??output8Bitl
  359. mov [edi],ax ;Output 16bit sample
  360. add edi,4 ;4 for stereo
  361. jmp short ??adjustIndexl
  362. ??output8Bitl:
  363. ; output 8 bit sample
  364. xor ah,80h
  365. mov [edi],ah
  366. add edi,2 ;2 for stereo
  367. ??adjustIndexl:
  368. xor ecx,ecx
  369. mov cx,[(sCompInfo ebx).wCode]
  370. xor eax,eax
  371. shl ecx,1
  372. mov ax,[wCODECIndexTab + ecx]
  373. add [(sCompInfo ebx).wIndex],ax
  374. ; check if wIndex < 0
  375. cmp [(sCompInfo ebx).wIndex],8000h
  376. jb short ??checkOverflowl
  377. mov [(sCompInfo ebx).wIndex],0
  378. jmp short ??adjustStepl ;reset index to zero
  379. ??checkOverflowl:
  380. cmp [(sCompInfo ebx).wIndex],88 ; check if wIndex > 88
  381. jbe short ??adjustStepl
  382. mov [(sCompInfo ebx).wIndex],88 ; reset index to 88
  383. ??adjustStepl:
  384. ; fetch wIndex so we can fetch new step value
  385. xor ecx,ecx
  386. mov cx,[(sCompInfo ebx).wIndex]
  387. xor eax,eax
  388. shl ecx,1
  389. mov ax,[wCODECStepTab + ecx]
  390. ; advance index and store step value
  391. add [(sCompInfo ebx).dwSampleIndex],1
  392. mov [(sCompInfo ebx).wStep],ax
  393. ; decrement bytes processed and loop back.
  394. sub [dwCODECByteIndex],2
  395. jne ??mainloopl
  396. ;----------------------------------------------------------------------------
  397. ; Right Side Setup
  398. ;----------------------------------------------------------------------------
  399. mov eax,[wBytes]
  400. mov [dwCODECBytesProcessed],eax
  401. mov esi,[(sCompInfo ebx).lpSource]
  402. mov edi,[(sCompInfo ebx).lpDest]
  403. inc esi ; skip left channel
  404. inc edi ; skip left channel
  405. cmp [(sCompInfo ebx).wBitSize],16 ;16 bit ??
  406. je short ??doByteDivide
  407. mov [dwCODECByteIndex],eax
  408. jmp short ??mainloopr
  409. ??doByteDivide:
  410. shr eax,1 ;Divide size by two
  411. inc edi ; 16 bit so skip 1 more
  412. mov [dwCODECByteIndex],eax
  413. ;--------------------------------------------------------------------------
  414. ;Right Channel Start
  415. ;--------------------------------------------------------------------------
  416. ??mainloopr:
  417. test [(sCompInfo ebx).dwSampleIndex2],1
  418. je short ??fetchTokenr
  419. xor eax,eax
  420. mov ax,[(sCompInfo ebx).wCodeBuf2]
  421. shr eax,4
  422. and eax,000Fh
  423. mov [(sCompInfo ebx).wCode2],ax
  424. jmp short ??calcDifferencer
  425. ??fetchTokenr:
  426. xor eax,eax
  427. mov al,[esi]
  428. mov [(sCompInfo ebx).wCodeBuf2],ax
  429. add esi,2 ;2 for stereo
  430. and eax,000Fh
  431. mov [(sCompInfo ebx).wCode2],ax
  432. ??calcDifferencer:
  433. ; reset difference
  434. mov [(sCompInfo ebx).dwDifference2],0
  435. xor ecx,ecx
  436. mov cx,[(sCompInfo ebx).wStep2]
  437. test eax,4 ;Check for wCode & 4
  438. je short ??no4r
  439. add [(sCompInfo ebx).dwDifference2],ecx ;Add wStep
  440. ??no4r:
  441. test eax,2 ;Check for wCode & 2
  442. je short ??no2r
  443. mov edx,ecx ;Add wStep >> 1
  444. shr edx,1
  445. add [(sCompInfo ebx).dwDifference2],edx
  446. ??no2r:
  447. test eax,1 ;Check for wCode & 1
  448. je short ??no1r
  449. mov edx,ecx ;Add wStep >> 2
  450. shr edx,2
  451. add [(sCompInfo ebx).dwDifference2],edx
  452. ??no1r:
  453. mov edx,ecx ;Add in wStep >> 3
  454. shr edx,3
  455. add [(sCompInfo ebx).dwDifference2],edx
  456. test eax,8 ;Check for wCode & 8
  457. je short ??no8r
  458. neg [(sCompInfo ebx).dwDifference2] ;Negate diff
  459. ??no8r:
  460. ; add difference to predicted value.
  461. mov eax,[(sCompInfo ebx).dwPredicted2]
  462. add eax,[(sCompInfo ebx).dwDifference2]
  463. cmp eax,7FFFh
  464. jl short ??noOverflowr
  465. mov eax,7FFFh
  466. ??noOverflowr:
  467. cmp eax,0FFFF8000h
  468. jg short ??noUnderflowr
  469. mov eax,0FFFF8000h
  470. ??noUnderflowr:
  471. mov [(sCompInfo ebx).dwPredicted2],eax
  472. cmp [(sCompInfo ebx).wBitSize],16
  473. jne short ??output8Bitr
  474. mov [edi],ax ;Output 16bit sample
  475. add edi,4 ;4 for stereo ***
  476. jmp short ??adjustIndexr
  477. ??output8Bitr:
  478. ; output 8 bit sample
  479. xor ah,80h
  480. mov [edi],ah
  481. add edi,2 ;2 for stereo
  482. ??adjustIndexr:
  483. xor ecx,ecx
  484. mov cx,[(sCompInfo ebx).wCode2]
  485. xor eax,eax
  486. shl ecx,1
  487. mov ax,[wCODECIndexTab + ecx]
  488. add [(sCompInfo ebx).wIndex2],ax
  489. ; check if wIndex < 0
  490. cmp [(sCompInfo ebx).wIndex2],8000h
  491. jb short ??checkOverflowr
  492. ; reset index to zero
  493. mov [(sCompInfo ebx).wIndex2],0
  494. jmp short ??adjustStepr
  495. ??checkOverflowr:
  496. ; check if wIndex > 88
  497. cmp [(sCompInfo ebx).wIndex2],88
  498. jbe short ??adjustStepr
  499. mov [(sCompInfo ebx).wIndex2],88 ; reset index to 88
  500. ??adjustStepr:
  501. ; fetch wIndex so we can fetch new step value
  502. xor ecx,ecx
  503. mov cx,[(sCompInfo ebx).wIndex2]
  504. xor eax,eax
  505. shl ecx,1
  506. mov ax,[wCODECStepTab + ecx]
  507. ; advance index and store step value
  508. add [(sCompInfo ebx).dwSampleIndex2],1
  509. mov [(sCompInfo ebx).wStep2],ax
  510. ; decrement bytes processed and loop back.
  511. sub [dwCODECByteIndex],2
  512. jne ??mainloopr
  513. ??exitout:
  514. ; don't think we need this but just in case i'll leave it here!!
  515. ; mov [(sCompInfo ebx).lpSource],esi
  516. ; mov [(sCompInfo ebx).lpDest],edi
  517. ; set up return value for number of bytes processed.
  518. mov eax,[dwCODECBytesProcessed]
  519. pop edx
  520. pop ecx
  521. pop ebx
  522. pop edi
  523. pop esi
  524. ret
  525. ENDP General_sosCODECDecompressData
  526. LABEL LockedCodeEnd BYTE
  527. ;***************************************************************************
  528. ;* sosCODEC_LOCK -- locks the JLB audio decompression code *
  529. ;* *
  530. ;* INPUT: none *
  531. ;* *
  532. ;* OUTPUT: BOOL true is lock sucessful, false otherwise *
  533. ;* *
  534. ;* PROTO: BOOL sosCODEC_Lock(void); *
  535. ;* *
  536. ;* HISTORY: *
  537. ;* 06/26/1995 PWG : Created. *
  538. ;*=========================================================================*
  539. GLOBAL C sosCODEC_Lock:NEAR
  540. PROC sosCODEC_Lock C NEAR USES ebx ecx edx esi edi
  541. ;
  542. ; Lock the code that is used by the sos decompression method.
  543. ;
  544. mov eax,0600h ; function number.
  545. mov ecx,OFFSET LockedCodeStart ; ecx must have start of memory.
  546. mov edi,OFFSET LockedCodeEnd ; edi will have size of region in bytes.
  547. shld ebx,ecx,16
  548. sub edi, ecx
  549. shld esi,edi,16
  550. int DPMI_INTR ; do call.
  551. jc ??error
  552. or [InitFlags], IF_LOCKED_PM_CODE
  553. ;
  554. ; Lock the data used by the sos decompression method.
  555. ;
  556. mov eax,0600h ; function number.
  557. mov ecx,OFFSET LockedDataStart ; ecx must have start of memory.
  558. mov edi,OFFSET LockedDataEnd ; edi will have size of region in bytes.
  559. shld ebx,ecx,16
  560. sub edi, ecx
  561. shld esi,edi,16
  562. int DPMI_INTR ; do call.
  563. jc ??error ; eax = 8 if mem err, eax = 9 if invalid mem region.
  564. or [InitFlags], IF_LOCKED_PM_DATA
  565. mov eax,1
  566. jmp ??exit
  567. ??error:
  568. xor eax,eax
  569. ??exit:
  570. ret
  571. ENDP sosCODEC_Lock
  572. ;***************************************************************************
  573. ;* DECOMPRESS_FRAME_UNLOCK -- Unlocks the JLB audio compression code *
  574. ;* *
  575. ;* INPUT: none *
  576. ;* *
  577. ;* OUTPUT: BOOL true is unlock sucessful, false otherwise *
  578. ;* *
  579. ;* PROTO: BOOL sosCODEC_Unlock(void); *
  580. ;* *
  581. ;* HISTORY: *
  582. ;* 06/26/1995 PWG : Created. *
  583. ;*=========================================================================*
  584. GLOBAL C sosCODEC_Unlock:NEAR
  585. PROC sosCODEC_Unlock C NEAR USES ebx ecx edx esi edi
  586. test [InitFlags],IF_LOCKED_PM_CODE
  587. jz ??code_not_locked
  588. mov eax , 0601h
  589. mov ecx,OFFSET LockedCodeStart ; ecx must have start of memory.
  590. mov edi,OFFSET LockedCodeEnd ; edx will have size of region in bytes.
  591. sub edi,ecx ; - figure size.
  592. shld ebx , ecx , 16
  593. shld esi , edi , 16
  594. int DPMI_INTR ; do call.
  595. jc ??error
  596. ??code_not_locked:
  597. test [InitFlags],IF_LOCKED_PM_DATA
  598. jz ??data_not_locked
  599. mov ax,0601h ; set es to descriptor of data.
  600. mov ecx,OFFSET LockedDataStart ; ecx must have start of memory.
  601. mov edi,OFFSET LockedDataEnd ; edx will have size of region in bytes.
  602. sub edi,ecx ; - figure size.
  603. shld ebx , ecx , 16
  604. shld esi , edi , 16
  605. int DPMI_INTR ; do call.
  606. jc ??error ; eax = 8 if mem err, eax = 9 if invalid mem region.
  607. ??data_not_locked:
  608. mov [InitFlags],0
  609. mov eax,1
  610. jmp ??exit
  611. ??error:
  612. xor eax,eax
  613. ??exit:
  614. ret
  615. ENDP sosCODEC_Unlock
  616. END