IB_ATD.asm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. ; Seven Kingdoms: Ancient Adversaries
  2. ;
  3. ; Copyright 1997,1998 Enlight Software Ltd.
  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 2 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. ;Filename : IB_ATD.ASM
  19. ;Description : Blt a bitmap to the display surface buffer
  20. ; with decompression, transparency handling
  21. INCLUDE IMGFUN.inc
  22. INCLUDE COLCODE.inc
  23. .CODE
  24. ;----------- BEGIN OF FUNCTION IMGbltAreaTransDecompress ------
  25. ;
  26. ; Put a compressed bitmap on image buffer.
  27. ; It does handle color key transparency.
  28. ;
  29. ; Syntax : IMGbltAreaTransDecompress( imageBuf, pitch, x, y, bitmapBuf,
  30. ; x1, y1, x2, y2)
  31. ;
  32. ; char *imageBuf - the pointer to the display surface buffer
  33. ; int pitch - pitch of the display surface buffer
  34. ; int x,y - where to put the image on the surface buffer
  35. ; char *bitmapPtr - the pointer to the bitmap buffer
  36. ; int x1,y1,x2,y2 - clipping window from left, top of the bitmap
  37. ;
  38. ; the area to be blit to the screen is called clip window
  39. ; the width of clip window is stored in clipWindow
  40. ;
  41. ; ESI and AH points to a point in the bitmap data
  42. ; if ESI points to a compression key (i.e. F8-FF),
  43. ; AH refer to how many of points are passed.
  44. ; i.e. [esi] = F8 21, AH may to 0 to 20
  45. ;
  46. ; SeekForward function move the (ESI,AH) pointer
  47. ; to forward ECX points (decompressed)
  48. ;
  49. ; ESI and AH are positioned to the top left hand corner of clip window
  50. ; and move right, and then downward
  51. ;
  52. ; After the cursor moved right, it checks for three cases:
  53. ; 1. non-transparent data
  54. ; 2. transparent data, but do not pass the right of the clip window
  55. ; 3. transparent data, and will pass the right of the clip window
  56. ;
  57. ; for case 1, blit the point and move one point right. If the right
  58. ; side of the clip window is passed, position EDI and (ESI,AH) to the
  59. ; left side of the clip window on next line.
  60. ;
  61. ; for case 2, simply move the EDI and (ESI,AH) forward by the run-length
  62. ; count
  63. ;
  64. ; for case 3, skip EDI and (ESI,AH) to the left side of the clip window
  65. ; on the next line
  66. ;
  67. ;-------------------------------------------------
  68. ;
  69. ; Format of the bitmap data :
  70. ;
  71. ; <short> width
  72. ; <short> height
  73. ; <char..> bitmap image
  74. ;
  75. ;-------------------------------------------------
  76. PUBLIC IMGbltAreaTransDecompress
  77. SeekForward PROTO STDCALL ; see IB_ATRD.ASM
  78. IMGbltAreaTransDecompress PROC imageBuf,pitch,x,y,bitmapPtr,x1,y1,x2,y2
  79. LOCAL clipWidth:DWORD, bitmapWidth:DWORD, bitmapHeight:DWORD
  80. LOCAL tempESI:DWORD
  81. STARTPROC
  82. MOV EAX, imageBuf ; store the address of the image buffer to a variable
  83. MOV image_buf, EAX
  84. ;------ get the bitmap width and height -----;
  85. MOV AX , DS
  86. MOV ES , AX
  87. MOV ESI, bitmapPtr
  88. ;------ calculate destination on the video memory ----;
  89. CALC_ADDR_2 EDI, x, y, x1, y1,pitch ; Get the address to the destination buffer
  90. ;------ calculate clipWidth - no. of points ploted on each row --;
  91. XOR EAX, EAX
  92. LODSW ; get bitmap width
  93. MOV bitmapWidth, EAX
  94. MOV EAX, x2
  95. SUB EAX, x1
  96. INC EAX
  97. MOV clipWidth, EAX
  98. ;----- calculate number of rows to be ploted on the screen
  99. LODSW ; get bitmap height
  100. MOV bitmapHeight, EAX
  101. MOV ECX, EAX
  102. MOV ECX, y2
  103. SUB ECX, y1
  104. ; INC ECX ; leave last line less to @@last_line
  105. ; last line is handled separately to avoid seekForward
  106. JC @@end ; if negative, skip the procedure
  107. ; ----- position ESI to the first point to draw -------
  108. ; AH contain the bytes remained in decompression
  109. ; position to row y1 and column x1
  110. PUSH ECX
  111. ; ECX = y1 * bitmapWidth + x1
  112. MOV EAX, y1
  113. MUL bitmapWidth
  114. ADD EAX, x1 ; DROP EDX
  115. MOV ECX, EAX
  116. MOV AH,0
  117. CALL SeekForward
  118. POP ECX ; ECX is now the height of clipping window
  119. JECXZ @@lastLine
  120. @@loopY: ; --------- start of each line ------------
  121. PUSH ECX
  122. MOV ECX, clipWidth
  123. @@loopX:
  124. ; -------- start of each point -----------
  125. LODSB
  126. JUMP_IF_TRANS al, @@clipCompress1
  127. @@nonTrans:
  128. ; ------- non-transparent data -----------
  129. ; 00-F7, simply blit the point on video memory
  130. STOSB
  131. ; ------- test end of line ----------------
  132. ; (pass the right of clipping window)
  133. LOOP @@loopX
  134. ADD EDI, pitch
  135. SUB EDI, clipWidth
  136. ; ------- seek source(ESI) to next line -----
  137. MOV ECX, bitmapWidth
  138. SUB ECX, clipWidth
  139. MOV AH,0
  140. CALL SeekForward
  141. JMP @@endloopY
  142. ALIGN 4
  143. @@clipCompress1:
  144. ; ------ transparent data -------------
  145. MOV tempESI, ESI ; save ESI
  146. ; note: run-length is now in [ESI]-AH
  147. JUMP_IF_NOT_MANY_TRANS al, @@clipCompress1a
  148. LODSB ; load the run-length count
  149. ENCODE_FEW_TRANS_CODE al
  150. @@clipCompress1a:
  151. MOV DL,AL
  152. DECODE_FEW_TRANS_CODE dl
  153. SUB DL,AH
  154. MOVZX DX,DL
  155. CMP ECX, EDX
  156. JBE @@clipCompress2
  157. ; ECX > EDX
  158. ; meaning the run-length is still within clip window
  159. ADD EDI, EDX ; skip the number of points
  160. SUB ECX, EDX
  161. MOV AH,0
  162. JMP @@loopX
  163. ALIGN 4
  164. @@clipCompress2:
  165. ; ------- run-length is outside clip window --------
  166. ; EDI seek the the start of the next line
  167. ; EDI += ECX - clipWidth + pitch
  168. ADD EDI, pitch
  169. SUB ECX, clipWidth
  170. ADD EDI, ECX
  171. ; find out the no. of byte to call SeekForward
  172. ; to seek the left side of clip window of next line
  173. ; ECX = (ECX - clipWidth) + bitmapWidth
  174. ADD ECX, bitmapWidth
  175. MOV ESI, tempESI ; restore ESI to compresion key (f8-ff)
  176. DEC ESI
  177. CALL SeekForward
  178. @@endloopY: POP ECX
  179. LOOP @@loopY
  180. ;------- similarly blit the last line -------;
  181. @@lastLine:
  182. MOV ECX, clipWidth
  183. @@lastLoopX:
  184. LODSB
  185. JUMP_IF_TRANS al, @@lastClipCompress1
  186. @@lastNonTrans:
  187. STOSB
  188. ; --------- test end of line ----------
  189. LOOP @@lastLoopX
  190. JMP @@endLast
  191. ALIGN 4
  192. @@lastClipCompress1:
  193. ; note: run-length is now in AH not [ESI]
  194. JUMP_IF_NOT_MANY_TRANS al, @@lastClipCompress1a
  195. ; F8
  196. LODSB
  197. ENCODE_FEW_TRANS_CODE al
  198. @@lastClipCompress1a:
  199. MOV DL,AL
  200. DECODE_FEW_TRANS_CODE al
  201. SUB DL,AH
  202. MOVZX DX,DL
  203. CMP ECX, EDX
  204. JBE @@endLast
  205. ; ECX > EDX
  206. ; meaning the run-length is still within clip window
  207. ADD EDI, EDX ; skip the number of points
  208. SUB ECX, EDX
  209. MOV AH,0
  210. JMP @@lastLoopX
  211. ALIGN 4
  212. @@endLast:
  213. @@end: ENDPROC
  214. IMGbltAreaTransDecompress ENDP
  215. ;----------- END OF FUNCTION IMGbltAreaTransRemapDecompress ----------
  216. END