I_LINE.asm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 : I_LINE.ASM
  19. ;Description : Draw a line in the image buffer
  20. INCLUDE IMGFUN.inc
  21. .DATA
  22. buf_width dd ?
  23. buf_height dd ?
  24. buf_pitch dd ?
  25. .CODE
  26. ;-------- BEGIN OF FUNCTION IMGline -----------
  27. ;
  28. ; Draw a line on the IMG screen
  29. ;
  30. ; char *imageBuf - the pointer to the display surface buffer
  31. ; int pitch - the pitch of the display surface buffer
  32. ; int w - the width of the display surface buffer
  33. ; int h - the height of the display surface buffer
  34. ; int x1,y1 - the top left vertex of the bar
  35. ; int x2,y2 - the bottom right vertex of the bar
  36. ; int color - the color of the line
  37. ;
  38. PUBLIC IMGline
  39. IMGline PROC imageBuf, pitch, w, h, x1, y1, x2, y2, color
  40. LOCAL cnt, acc, deltax, deltay, dirx, diry
  41. STARTPROC
  42. MOV EAX, imageBuf ; store the address of the image buffer to a variable
  43. MOV image_buf, EAX
  44. MOV EAX, pitch
  45. MOV buf_pitch, EAX
  46. MOV EAX, w
  47. MOV buf_width, EAX
  48. MOV EAX, h
  49. MOV buf_height, EAX
  50. MOV EBX, color
  51. MOV AX, DS
  52. MOV ES, AX
  53. XOR ESI, ESI ; So ESI always = SI and EDI = DI
  54. XOR EDI, EDI
  55. ;---------------------------------;
  56. MOV ESI, x1
  57. MOV EDI, y1
  58. MOV acc, 0
  59. MOV EAX, x2
  60. SUB EAX, ESI
  61. MOV EDX, 1
  62. JNS @@no_sx
  63. NEG EAX
  64. MOV EDX, -1
  65. @@no_sx: MOV dirx, EDX
  66. MOV deltax, EAX
  67. mov EAX, y2
  68. SUB EAX, EDI
  69. MOV EDX, 1
  70. JNS @@no_sy
  71. NEG EAX
  72. MOV EDX, -1
  73. @@no_sy: MOV diry, EDX
  74. MOV deltay, EAX
  75. CMP EAX, deltax
  76. JGE @@y_lp
  77. CALL line_point
  78. MOV EAX, deltax
  79. MOV cnt, EAX
  80. @@lp1:
  81. DEC cnt
  82. JS @@end
  83. ADD ESI, dirx
  84. MOV EAX, deltay
  85. ADD acc, EAX
  86. MOV EAX, acc
  87. CMP EAX, deltax
  88. JB @@no_inc_y
  89. MOV EAX, deltax
  90. SUB acc, EAX
  91. ADD EDI, diry
  92. @@no_inc_y:
  93. CALL line_point
  94. JMP @@lp1
  95. @@y_lp:
  96. CALL line_point
  97. MOV EAX, deltay
  98. MOV cnt, EAX
  99. @@lp2:
  100. DEC cnt
  101. JS @@end
  102. ADD EDI, diry
  103. MOV EAX, deltax
  104. ADD acc, EAX
  105. MOV EAX, acc
  106. CMP EAX, deltay
  107. JB @@no_inc_x
  108. MOV EAX, deltay
  109. SUB acc, EAX
  110. ADD ESI, dirx
  111. @@no_inc_x:
  112. CALL line_point
  113. JMP @@lp2
  114. @@end: ENDPROC
  115. IMGline ENDP
  116. ;------- END OF FUNCTION IMGline ------------
  117. ;------ BEGIN OF FUNCTION line_point -----------
  118. ;
  119. ; It is a private function called by VGAline().
  120. ;
  121. ; Parameter : ESI - x position
  122. ; EDI - y position
  123. ;
  124. line_point PROC
  125. CMP ESI, 0
  126. JL @@end
  127. CMP ESI, buf_width
  128. JGE @@end
  129. CMP EDI, 0
  130. JL @@end
  131. CMP EDI, buf_height
  132. JGE @@end
  133. MOV EAX, buf_pitch
  134. MUL EDI
  135. ADD EAX, ESI
  136. ADD EAX, image_buf
  137. MOV ES:[EAX], BL
  138. @@end: RET
  139. line_point ENDP
  140. ;---------- END OF FUNCTION line_point ------------
  141. END