CLEAR.ASM 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ;
  2. ; Command & Conquer Red Alert(tm)
  3. ; Copyright 2025 Electronic Arts Inc.
  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 3 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. ;***************************************************************************
  19. ;** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : Clear the Full Graphics Buffer *
  23. ;* *
  24. ;* File Name : CLEAR.ASM *
  25. ;* *
  26. ;* Programmer : Phil Gorrow *
  27. ;* *
  28. ;* Start Date : June 7, 1994 *
  29. ;* *
  30. ;* Last Update : August 23, 1994 [SKB] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* GVPC::Clear -- Clears a virtual viewport instance *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. IDEAL
  37. P386
  38. MODEL USE32 FLAT
  39. INCLUDE ".\drawbuff.inc"
  40. INCLUDE ".\gbuffer.inc"
  41. CODESEG
  42. ;***************************************************************************
  43. ;* VVPC::CLEAR -- Clears a virtual viewport instance *
  44. ;* *
  45. ;* INPUT: UBYTE the color (optional) to clear the view port to *
  46. ;* *
  47. ;* OUTPUT: none *
  48. ;* *
  49. ;* NOTE: This function is optimized to handle viewport with no XAdd *
  50. ;* value. It also handles DWORD aligning the destination *
  51. ;* when speed can be gained by doing it. *
  52. ;* HISTORY: *
  53. ;* 06/07/1994 PWG : Created. *
  54. ;* 08/23/1994 SKB : Clear the direction flag to always go forward. *
  55. ;*=========================================================================*
  56. PROC Buffer_Clear C near
  57. USES eax,ebx,ecx,edx,esi,edi
  58. ARG this_object:DWORD ; this is a member function
  59. ARG color:BYTE ; what color should we clear to
  60. cld ; always go forward
  61. mov ebx,[this_object] ; get a pointer to viewport
  62. mov edi,[(GraphicViewPort ebx).GVPOffset] ; get the correct offset
  63. mov edx,[(GraphicViewPort ebx).GVPHeight] ; ecx = height of viewport
  64. mov esi,[(GraphicViewPort ebx).GVPWidth] ; edx = width of viewport
  65. push [dword (GraphicViewPort ebx).GVPPitch] ; extra pitch of direct draw surface
  66. mov ebx,[(GraphicViewPort ebx).GVPXAdd] ; esi = add for each line
  67. add ebx,[esp] ; Yes, I know its nasty but
  68. add esp,4 ; it works!
  69. ;*===================================================================
  70. ; Convert the color byte to a DWORD for fast storing
  71. ;*===================================================================
  72. mov al,[color] ; get color to clear to
  73. mov ah,al ; extend across WORD
  74. mov ecx,eax ; extend across DWORD in
  75. shl eax,16 ; several steps
  76. mov ax,cx
  77. ;*===================================================================
  78. ; Find out if we should bother to align the row.
  79. ;*===================================================================
  80. cmp esi , OPTIMAL_BYTE_COPY ; is it worth aligning them?
  81. jl ??byte_by_byte ; if not then skip
  82. ;*===================================================================
  83. ; Figure out the alignment offset if there is any
  84. ;*===================================================================
  85. push ebx
  86. ??dword_aligned_loop:
  87. mov ecx , edi
  88. mov ebx , esi
  89. neg ecx
  90. and ecx , 3
  91. sub ebx , ecx
  92. rep stosb
  93. mov ecx , ebx
  94. shr ecx , 2
  95. rep stosd
  96. mov ecx , ebx
  97. and ecx , 3
  98. rep stosb
  99. add edi , [ esp ]
  100. dec edx ; decrement the height
  101. jnz ??dword_aligned_loop ; if more to do than do it
  102. pop eax
  103. ret
  104. ;*===================================================================
  105. ; If not enough bytes to bother aligning copy each line across a byte
  106. ; at a time.
  107. ;*===================================================================
  108. ??byte_by_byte:
  109. mov ecx,esi ; get total width in bytes
  110. rep stosb ; store the width
  111. add edi,ebx ; handle the xadd
  112. dec edx ; decrement the height
  113. jnz ??byte_by_byte ; if any left then next line
  114. ??exit:
  115. ret
  116. ENDP Buffer_Clear
  117. END