IB_T.asm 5.4 KB

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