IB_TDM.asm 4.7 KB

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