IC_R.asm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 : IC_R.ASM
  19. ;Description : Remap a display surface to another display
  20. ; surface on the same place
  21. INCLUDE IMGFUN.inc
  22. .CODE
  23. ;--------- BEGIN OF FUNCTION IMGcopyRemap -----------
  24. ;
  25. ; Remap a rectangle of a display surface, but the result is
  26. ; put into another display surface
  27. ;
  28. ; Note : No border checking is made in this function.
  29. ; Placing an icon outside image buffer will cause serious BUG.
  30. ;
  31. ; char *imageBuf - the pointer to the display surface buffer
  32. ; int imgPitch - pitch of the destination display surface buffer
  33. ; char *backBuf - the pointer to the back buffer
  34. ; int backPitch - pitch of the back buffer
  35. ; int x1,y1 - the top left vertex of the bar
  36. ; int x2,y2 - the bottom right vertex of the bar
  37. ; char *colorTable - the pointer to the remap table
  38. ;
  39. PUBLIC IMGcopyRemap
  40. IMGcopyRemap PROC imageBuf, imgPitch, backBuf, backPitch, x1, y1, x2, y2, colorTable
  41. LOCAL barWidth:DWORD
  42. STARTPROC
  43. MOV EAX, backBuf
  44. MOV image_buf, EAX
  45. CALC_ADDR ESI, x1, y1, backPitch ; Get the offset to the back buffer address
  46. MOV EAX, imageBuf ; store the address of the image buffer to a variable
  47. MOV image_buf, EAX
  48. CALC_ADDR EDI, x1, y1, imgPitch ; Get the offset to the image buffer address
  49. ;------ calc bar width and height -----;
  50. MOV AX , DS
  51. MOV ES , AX
  52. MOV EBX, x2
  53. SUB EBX, x1
  54. INC EBX
  55. MOV barWidth, EBX
  56. MOV ECX, y2
  57. SUB ECX, y1
  58. INC ECX
  59. SUB imgPitch, EBX ; lineDiff = image_width - barWidth
  60. SUB backPitch, EBX ; lineDiff = image_width - barWidth
  61. MOV EBX, colorTable
  62. CLD ; clear direction flag for MOVSB
  63. ;------- pixels copying loop --------;
  64. TEST barWidth,3
  65. JZ @@quadWidth ; barWidth is multiple of 4 use dword copy
  66. TEST barWidth,1
  67. JZ @@evenWidth ; barWidth is even, use word copy
  68. ; -------- odd width ----------;
  69. @@oddWidth: SHR barWidth,1
  70. @@startY: PUSH ECX
  71. MOV ECX, barWidth
  72. JECXZ @@startX1
  73. @@startX:
  74. LODSW
  75. XLATB [EBX]
  76. XCHG AL,AH
  77. XLATB [EBX]
  78. XCHG AL,AH
  79. STOSW
  80. LOOP @@startX
  81. @@startX1: LODSB
  82. XLATB [EBX]
  83. STOSB
  84. POP ECX
  85. ADD ESI, backPitch
  86. ADD EDI, imgPitch
  87. LOOP @@startY
  88. JMP @@end
  89. ; ------ even width -------;
  90. @@evenWidth: SHR barWidth,1
  91. @@evenStartY: PUSH ECX
  92. MOV ECX, barWidth
  93. @@evenStartX:
  94. LODSW
  95. XLATB [EBX]
  96. XCHG AL,AH
  97. XLATB [EBX]
  98. XCHG AL,AH
  99. STOSW
  100. LOOP @@evenStartX
  101. POP ECX
  102. ADD ESI, backPitch
  103. ADD EDI, imgPitch
  104. LOOP @@evenStartY
  105. JMP @@end
  106. ; -------- quad width --------;
  107. @@quadWidth: SHR barWidth,2
  108. @@quadStartY: PUSH ECX
  109. MOV ECX, barWidth
  110. @@quadStartX:
  111. LODSD
  112. XLATB [EBX]
  113. ROR EAX,8
  114. XLATB [EBX]
  115. ROR EAX,8
  116. XLATB [EBX]
  117. ROR EAX,8
  118. XLATB [EBX]
  119. ROR EAX,8
  120. STOSD
  121. LOOP @@quadStartX
  122. POP ECX
  123. ADD ESI, backPitch
  124. ADD EDI, imgPitch
  125. LOOP @@quadStartY
  126. @@end: ENDPROC
  127. IMGcopyRemap ENDP
  128. ;---------- END OF FUNCTION IMGcopyRemap ------------
  129. END