IB_TM2.asm 5.5 KB

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