VCLEAR.ASM 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 Mcga Screen *
  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. ;* VVPC::Clear -- Clears a virtual viewport instance *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. IDEAL
  37. P386
  38. MODEL USE32 FLAT
  39. LOCALS ??
  40. INCLUDE "svgaprim.inc"
  41. INCLUDE "gbuffer.inc"
  42. CODESEG
  43. PROC Vesa_Clear C near
  44. USES eax,ebx,ecx,edx,esi,edi
  45. ARG this:DWORD ; this is a member function
  46. ARG color:BYTE ; what color should we clear to
  47. cld ; always go forward
  48. mov ebx,[this] ; get a pointer to viewport
  49. mov esi,[(GraphicViewPort ebx).GVPXAdd] ; esi = add for each line
  50. mov edi,[(GraphicViewPort ebx).GVPOffset] ; get the correct offset
  51. push esi
  52. mov edx,[(GraphicViewPort ebx).GVPHeight] ; ecx = height of viewport
  53. mov esi,[(GraphicViewPort ebx).GVPWidth] ; edx = width of viewport
  54. ;*===================================================================
  55. ; Convert the color byte to a DWORD for fast storing
  56. ;*===================================================================
  57. mov al,[color] ; get color to clear to
  58. mov ah,al ; extend across WORD
  59. mov ecx,eax ; extend across DWORD in
  60. shl eax,16 ; several steps
  61. mov ax,cx
  62. Call Vesa_Asm_Set_Win ; set the window
  63. ;*===================================================================
  64. ; Find out if we should bother to align the row.
  65. ;*===================================================================
  66. ??row_by_row_aligned:
  67. cmp esi , OPTIMAL_BYTE_COPY ; is it worth aligning them?
  68. jl ??row_by_row ; if not then skip
  69. ;*===================================================================
  70. ; Now that we have the alignment offset copy each row
  71. ;*===================================================================
  72. ??aligned_loop:
  73. lea ebx , [ edi + esi ]
  74. add ebx , [ cpu_video_page ]
  75. cmp ebx , [ cpu_page_limit ]
  76. jl ??in_range
  77. xor ecx , ecx
  78. mov ebx , esi
  79. cmp edi , 0b0000h
  80. jge ??no_trailing
  81. mov ecx , 0b0000h
  82. sub ecx , edi
  83. sub ebx , ecx
  84. rep stosb
  85. ??no_trailing:
  86. add edi , [ cpu_video_page ]
  87. Call Vesa_Asm_Set_Win ; set the window
  88. mov ecx , ebx
  89. rep stosb
  90. add edi , [ esp ]
  91. dec edx ; decrement the height
  92. jnz ??aligned_loop ; if more to do than do it
  93. pop eax
  94. ret
  95. ??in_range:
  96. mov ecx , edi
  97. mov ebx , esi
  98. neg ecx
  99. and ecx , 3
  100. sub ebx , ecx
  101. rep stosb
  102. mov ecx , ebx
  103. shr ecx , 2
  104. rep stosd
  105. mov ecx , ebx
  106. and ecx , 3
  107. rep stosb
  108. add edi , [ esp ]
  109. dec edx ; decrement the height
  110. jnz ??aligned_loop ; if more to do than do it
  111. pop eax
  112. ret
  113. ;*===================================================================
  114. ; If not enough bytes to bother aligning copy each line across a byte
  115. ; at a time.
  116. ;*===================================================================
  117. ??row_by_row:
  118. lea ebx , [ edi + esi ]
  119. add ebx , [ cpu_video_page ]
  120. cmp ebx , [ cpu_page_limit ]
  121. mov ebx , esi
  122. jl ??in_range_bytes
  123. xor ecx , ecx
  124. mov ebx , esi
  125. cmp edi , 0b0000h
  126. jge ??no_trailing_bytes
  127. mov ecx , 0b0000h
  128. sub ecx , edi
  129. sub ebx , ecx
  130. rep stosb
  131. ??no_trailing_bytes:
  132. add edi , [ cpu_video_page ]
  133. Call Vesa_Asm_Set_Win ; set the window
  134. ??in_range_bytes:
  135. mov ecx , ebx
  136. rep stosb
  137. add edi , [ esp ]
  138. dec edx ; decrement the height
  139. jnz ??row_by_row ; if more to do than do it
  140. pop eax
  141. ret
  142. ENDP Vesa_Clear
  143. END