IB_TRD.asm 4.7 KB

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