IB_ATDM.asm 6.8 KB

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