IB_TRDM.asm 4.9 KB

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