IB_TM1.asm 5.8 KB

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