IB_TD.asm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_TD.ASM
  19. ;Description : Blt a bitmap to the display surface buffer
  20. ; with decompression, transparency handling
  21. INCLUDE IMGFUN.inc
  22. INCLUDE COLCODE.inc
  23. .CODE
  24. ;----------- BEGIN OF FUNCTION IMGbltTransDecompress ------
  25. ;
  26. ; Put a compressed bitmap on image buffer.
  27. ; It does handle color key transparency.
  28. ;
  29. ; Syntax : IMGbltTransDecompress( imageBuf, pitch, x, y, bitmapBuf)
  30. ;
  31. ; char *imageBuf - the pointer to 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. ; two counters are maintained, EDX and ECX for counting no. of rows
  36. ; and no. of columns remaining to draw
  37. ; if the counter reach zero, exit the loop
  38. ;
  39. ; ESI initally points to the start of bitmap data
  40. ; EDI initally points to the top left hand cornder of the destination
  41. ; in video memory
  42. ;
  43. ; compressed data is loaded from ESI, into AL
  44. ; If AL is non-transparent, blit the point to video memory.
  45. ; If AL is transparent, seek EDI forward. If the right side of the
  46. ; destination is passed,
  47. ; 1. seek EDI to the left side of the next line
  48. ; 2. if run-length is still very long, seek one more line
  49. ; 3. residue (of run-length) is added to EDI, ECX will count from a number
  50. ; lower than the width of bitmap
  51. ;
  52. ;-------------------------------------------------
  53. ;
  54. ; Format of the bitmap data :
  55. ;
  56. ; <short> width
  57. ; <short> height
  58. ; <char..> bitmap image
  59. ;
  60. ;-------------------------------------------------
  61. PUBLIC IMGbltTransDecompress
  62. IMGbltTransDecompress PROC imageBuf,pitch,x,y,bitmapPtr
  63. LOCAL bitmapWidth:DWORD, bitmapHeight:DWORD
  64. STARTPROC
  65. MOV EAX, imageBuf ; store the address of the image buffer to a variable
  66. MOV image_buf, EAX
  67. ;------ get the bitmap width and height -----;
  68. MOV AX , DS
  69. MOV ES , AX
  70. MOV ESI, bitmapPtr
  71. CLD
  72. ;------ calculate destination on the video memory ----;
  73. CALC_ADDR EDI, x, y, pitch ; Get the address to the destination buffer
  74. ;------ calculate bitmapWidth - no. of points ploted on each row --;
  75. XOR EAX, EAX
  76. LODSW ; get bitmap width
  77. MOV bitmapWidth, EAX
  78. ;----- calculate number of rows to be ploted on the screen
  79. LODSW ; get bitmap height
  80. MOV bitmapHeight, EAX
  81. MOV EDX, EAX ; EDX contains no. of rows remain
  82. @@loopY:
  83. MOV ECX, bitmapWidth
  84. @@loopX:
  85. LODSB
  86. JUMP_IF_TRANS al, @@compressed1
  87. @@nonTrans:
  88. ; ----- 00-F7, simply blit the point on video memory ----
  89. STOSB
  90. ; ---------- test end of line ------------
  91. ; (pass the right of clipping window)
  92. LOOP @@loopX
  93. ADD EDI, pitch
  94. SUB EDI, bitmapWidth
  95. ; JMP @@endloopY ; reduce jump
  96. DEC EDX
  97. JNE @@loopY
  98. JMP @@end
  99. ALIGN 4
  100. @@compressed1:
  101. JUMP_IF_NOT_MANY_TRANS al, @@compress1a ; equal to F8
  102. ; F8
  103. LODSB
  104. ENCODE_FEW_TRANS_CODE al
  105. @@compress1a:
  106. ; F7-FF
  107. DECODE_FEW_TRANS_CODE al
  108. MOVZX AX,AL
  109. CMP ECX, EAX
  110. JBE @@compress2
  111. ; ECX > EAX
  112. ; meaning the run-length is still within output bitmap
  113. ADD EDI, EAX ; skip the number of points
  114. SUB ECX, EAX
  115. JMP @@loopX
  116. ALIGN 4
  117. @@compress2:
  118. ; run-length is outside clip window
  119. ; adjust EDI to point to left of next line
  120. SUB EAX, ECX
  121. ADD EDI, pitch
  122. ADD EDI, ECX
  123. SUB EDI, bitmapWidth
  124. @@compress3a:
  125. ; if EAX is longer than width of bitmap,
  126. ; position to EDI one line below
  127. CMP EAX, bitmapWidth
  128. JB @@compress4
  129. ADD EDI, pitch
  130. SUB EAX, bitmapWidth
  131. DEC EDX ; minus y remain by 1
  132. JNE @@compress3a
  133. JMP @@end
  134. ALIGN 4
  135. @@compress4:
  136. ; add remainder to EDI
  137. ; ECX has another initial value other than bitmapWidth
  138. ADD EDI, EAX
  139. MOV ECX, bitmapWidth
  140. SUB ECX, EAX
  141. DEC EDX
  142. JNE @@loopX
  143. JMP @@end
  144. ALIGN 4
  145. @@endloopY:
  146. DEC EDX
  147. JNE @@loopY
  148. @@end: ENDPROC
  149. IMGbltTransDecompress ENDP
  150. ;----------- END OF FUNCTION IMGbltTransDecompress ----------
  151. END