IC.asm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.ASM
  19. ;Description : copy a rectange from one surface to another
  20. INCLUDE IMGFUN.inc
  21. .CODE
  22. ;--------- BEGIN OF FUNCTION IMGcopy -----------
  23. ;
  24. ; Draw a bar on the VGA screen
  25. ;
  26. ; Note : No border checking is made in this function.
  27. ; Placing an icon outside image buffer will cause serious BUG.
  28. ;
  29. ; char *imageBuf - the pointer to the display surface buffer
  30. ; int imgPitch - pitch of the display surface buffer
  31. ; char *backBuf - the pointer to the source surface buffer
  32. ; int backPitch - pitch of the source display surface buffer
  33. ; int x1,y1 - the top left vertex of the bar ( note : width < 1024)
  34. ; int x2,y2 - the bottom right vertex of the bar
  35. ;
  36. PUBLIC IMGcopy
  37. IMGcopy PROC imageBuf, imgPitch, backBuf, backPitch, x1, y1, x2, y2
  38. STARTPROC
  39. ; ----- calc start of source and destination address ----;
  40. MOV EAX, backBuf
  41. MOV image_buf, EAX
  42. CALC_ADDR ESI, x1, y1, backPitch
  43. MOV EAX, imageBuf ; store the address of the image buffer to a variable
  44. MOV image_buf, EAX
  45. CALC_ADDR EDI, x1, y1, imgPitch ; Get the offset to the image buffer address
  46. ;------ calc bar width and height -----;
  47. MOV AX , DS
  48. MOV ES , AX
  49. MOV EBX, x2
  50. SUB EBX, x1
  51. INC EBX
  52. MOV ECX, y2
  53. SUB ECX, y1
  54. INC ECX
  55. SUB imgPitch,EBX ; lineDiff = image_width - icon_width
  56. SUB backPitch,EBX ; lineDiff = image_width - icon_width
  57. CLD ; clear direction flag for MOVSB
  58. ;------- pixels copying loop --------;
  59. TEST BL,3 ; test if width a multiple of 4
  60. JZ @@putLineDWord
  61. ; width is not a multiple of four
  62. ROR BX, 2 ; BL = width / 4
  63. SHR BH, 6 ; BH = width mod 4, so width must be < 1024
  64. @@putLine:
  65. PUSH ECX
  66. MOVZX ECX, BL
  67. REP MOVSD
  68. MOVZX ECX, BH
  69. REP MOVSB
  70. ADD ESI, backPitch
  71. POP ECX
  72. ADD EDI, imgPitch
  73. LOOP @@putLine ; decrease the remain height and loop
  74. @@end: ENDPROC
  75. @@putLineDWord:
  76. SHR EBX,2
  77. @@putLineDWord1:
  78. PUSH ECX
  79. MOV ECX,EBX
  80. REP MOVSD
  81. ADD ESI,backPitch
  82. POP ECX
  83. ADD EDI,imgPitch
  84. LOOP @@putLineDWord1
  85. @@end2: ENDPROC
  86. IMGcopy ENDP
  87. ;---------- END OF FUNCTION IMGcopy ------------
  88. END