IB_TR.asm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_TR.ASM
  19. ;Description : Blt a bitmap to the display surface buffer with color key transparency and color remapping handling
  20. INCLUDE IMGFUN.inc
  21. INCLUDE COLCODE.inc
  22. .CODE
  23. ;-------- BEGIN OF FUNCTION IMBbltTransRemap ----------
  24. ;
  25. ; Put an non-compressed bitmap on image buffer.
  26. ; It handles color key transparency. The color key code is 255.
  27. ;
  28. ; T - Transparency key
  29. ; C - color remapping
  30. ;
  31. ; Syntax : IMBbltTransRemap( imageBuf, pitch, x, y, bitmapBuf, colorTable )
  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. ; char *colorTable - a 256-entry color remapping table
  38. ;
  39. ;-------------------------------------------------
  40. ;
  41. ; Format of the bitmap data :
  42. ;
  43. ; <short> width
  44. ; <short> height
  45. ; <char..> bitmap image
  46. ;
  47. ;-------------------------------------------------
  48. PUBLIC IMGbltTransRemap
  49. IMGbltTransRemap PROC imageBuf, pitch, x, y, bitmapPtr, colorTable
  50. LOCAL bitmapWidth
  51. STARTPROC
  52. MOV EAX, imageBuf ; store the address of the image buffer to a variable
  53. MOV image_buf, EAX
  54. ;------ get the bitmap width and height -----;
  55. MOV AX , DS
  56. MOV ES , AX
  57. MOV ESI, bitmapPtr
  58. XOR EAX, EAX
  59. LODSW ; get bitmap width
  60. MOV EBX, EAX
  61. LODSW ; get bitmap height
  62. MOV ECX, EAX
  63. MOV EDX, pitch ; EDX = lineDiff
  64. SUB EDX, EBX ; lineDiff = pitch - bitmap_width
  65. MOV bitmapWidth, EBX
  66. MOV EBX, colorTable ; store it in register for fast access
  67. CLD ; clear direction flag for MOVSB
  68. ;------- pixels copying loop --------;
  69. CALC_ADDR EDI, x, y, pitch ; Get the offset to the image buffer address
  70. @@moreLines:
  71. PUSH ECX
  72. MOV ECX, bitmapWidth ; ECX is the line pixel counter
  73. XOR EAX, EAX ; clear EAX as it will be used below
  74. SHR ECX, 2
  75. JZ SHORT @@nextScan
  76. ;-----------------------------------------------------------------------//
  77. ; The idea here is to not branch very often so we unroll the loop by four
  78. ; and try to not branch when a whole run of pixels is either transparent
  79. ; or not transparent.
  80. ;
  81. ; There are two loops. One loop is for a run of pixels equal to the
  82. ; transparent color, the other is for runs of pixels we need to store.
  83. ;
  84. ; When we detect a "bad" pixel we jump to the same position in the
  85. ; other loop.
  86. ;
  87. ; Here is the loop we will stay in as long as we encounter a "transparent"
  88. ; pixel in the source.
  89. ;-----------------------------------------------------------------------//
  90. align 4
  91. @@same:
  92. mov al, ds:[esi]
  93. PRE_REMAP
  94. cmp al, TRANSPARENT_CODE
  95. jne short @@diff0
  96. @@same0:
  97. mov al, ds:[esi+1]
  98. PRE_REMAP
  99. cmp al, TRANSPARENT_CODE
  100. jne short @@diff1
  101. @@same1:
  102. mov al, ds:[esi+2]
  103. PRE_REMAP
  104. cmp al, TRANSPARENT_CODE
  105. jne short @@diff2
  106. @@same2:
  107. mov al, ds:[esi+3]
  108. PRE_REMAP
  109. cmp al, TRANSPARENT_CODE
  110. jne short @@diff3
  111. @@same3:
  112. add edi,4
  113. add esi,4
  114. dec ecx
  115. jnz short @@same
  116. jz short @@nextScan
  117. ;-----------------------------------------------------------------------//
  118. ; Here is the loop we will stay in as long as
  119. ; we encounter a "non transparent" pixel in the source.
  120. ;-----------------------------------------------------------------------//
  121. align 4
  122. @@diff:
  123. mov al, ds:[esi]
  124. PRE_REMAP
  125. cmp al, TRANSPARENT_CODE
  126. je short @@same0
  127. @@diff0:
  128. POST_REMAP
  129. mov es:[edi], al
  130. mov al, ds:[esi+1]
  131. PRE_REMAP
  132. cmp al, TRANSPARENT_CODE
  133. je short @@same1
  134. @@diff1:
  135. POST_REMAP
  136. mov es:[edi+1], al
  137. mov al, ds:[esi+2]
  138. PRE_REMAP
  139. cmp al, TRANSPARENT_CODE
  140. je short @@same2
  141. @@diff2:
  142. POST_REMAP
  143. mov es:[edi+2], al
  144. mov al, ds:[esi+3]
  145. PRE_REMAP
  146. cmp al, TRANSPARENT_CODE
  147. je short @@same3
  148. @@diff3:
  149. POST_REMAP
  150. mov es:[edi+3], al
  151. add edi,4
  152. add esi,4
  153. dec ecx
  154. jnz short @@diff
  155. jz short @@nextScan
  156. ;-----------------------------------------------------------------------//
  157. ; We are at the end of a scan, check for odd leftover pixels to do
  158. ; and go to the next scan.
  159. ;-----------------------------------------------------------------------//
  160. align 4
  161. @@nextScan:
  162. mov ecx,bitmapWidth ; bitmap width
  163. and ecx,11b ; if its pixel count is an odd number
  164. jnz short @@oddStuff
  165. ;-----------------------------------------------------------------------//
  166. ; move on to the start of the next line
  167. ;-----------------------------------------------------------------------//
  168. @@nextScan1:
  169. add edi, edx ; edx = lineDiff
  170. pop ecx
  171. dec ecx
  172. jz @@end
  173. jmp @@moreLines
  174. ;-----------------------------------------------------------------------//
  175. ; If the width is not a multiple of 4 we will come here to clean up
  176. ; the last few pixels
  177. ;-----------------------------------------------------------------------//
  178. @@oddStuff:
  179. inc ecx
  180. @@oddLoop:
  181. dec ecx
  182. jz short @@nextScan1
  183. mov al, ds:[esi]
  184. inc esi
  185. PRE_REMAP
  186. inc edi
  187. cmp al, TRANSPARENT_CODE
  188. je short @@oddLoop
  189. POST_REMAP
  190. mov es:[edi-1], al
  191. jmp short @@oddLoop
  192. @@end: ENDPROC
  193. IMGbltTransRemap ENDP
  194. ;----------- END OF FUNCTION IMGbltTransRemap ----------
  195. END