DS_DN.ASM 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 A S S O C I A T E S **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : Draw Shape Routines for library. *
  23. ;* *
  24. ;* File Name : DS_DN.ASM *
  25. ;* *
  26. ;* Programmer : Scott K. Bowen *
  27. ;* *
  28. ;* Start Date : August 24, 1993 *
  29. ;* *
  30. ;* Last Update : September 6, 1994 [IML] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* Draw_Normal -- Draws a normal row of pixels to the viewport *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. IDEAL
  37. P386
  38. MODEL USE32 FLAT
  39. ;******************************** Includes *********************************
  40. INCLUDE "shape.inc"
  41. ;********************************* Code ************************************
  42. CODESEG
  43. ;***************************************************************************
  44. ;* Draw_Normal -- Draws a normal row of pixels to the viewport *
  45. ;* *
  46. ;* INPUT: *
  47. ;* ECX = number of pixels (not bytes) to draw *
  48. ;* EDX = XTotal initializer value *
  49. ;* ESI = shape (source) buffer address *
  50. ;* EDI = viewport (destination) address *
  51. ;* [WidthCount] = remaining bytes on the line *
  52. ;* *
  53. ;* OUTPUT: *
  54. ;* ESI - updated to current location in the shape data *
  55. ;* EDI - incr/decr by # pixels (not bytes) drawn/skipped *
  56. ;* [WidthCount] - bytes remaining on the line *
  57. ;* *
  58. ;* WARNINGS: none *
  59. ;* *
  60. ;* HISTORY: *
  61. ;* 04/14/1992 PWG : Created. *
  62. ;* 08/19/1993 SKB : Split drawshp.asm into several modules. *
  63. ;* 06/02/1994 BR : Converted to 32-bit. *
  64. ;* 08/09/1994 IML : Optimized for 32-bit. *
  65. ;* 09/06/1994 IML : Integrated p_* and ds_* routines. *
  66. ;*=========================================================================*
  67. PROC Draw_Normal NOLANGUAGE NEAR
  68. mov [StashEDX],edx ; save edx
  69. mov edx,[Flags]
  70. mov eax,0 ; init to zero
  71. sub [WidthCount],ecx ; decrement bytes remaining by pixels
  72. ; to draw
  73. ;--------------------------------------------------------------------
  74. ; Drawing Loop:
  75. ; - Get a data byte
  76. ; - If it's a 0, handle the run:
  77. ; - get repetition value
  78. ; - add it to EDI
  79. ; - subtract it from [WidthCount]
  80. ; - subtract it from ECX
  81. ; - if ECX>0, draw again, else exit
  82. ; - Otherwise:
  83. ; - draw the pixel
  84. ; - increment EDI to next pixel location
  85. ; - decrement [WidthCount]
  86. ; - loop until ECX is 0
  87. ;--------------------------------------------------------------------
  88. test edx,SHAPE_EFFECTS ; are any effects flags set?
  89. jnz short ??general_draw_continue ; if so use the general purpose loop
  90. ;--------------------------------------------------------------------
  91. ; Extra fast draw loop for shapes with no flags set.
  92. ;--------------------------------------------------------------------
  93. ??fast_draw_loop:
  94. mov al,[esi] ; get a byte of the source
  95. inc esi
  96. or eax,eax ; is the byte a transparent run?
  97. jz short ??fast_is_run ; if yes then handle the run
  98. mov [edi],al ; store color value to viewport
  99. inc edi ; point to next viewport pixel
  100. dec ecx ; any source pixels left?
  101. jnz short ??fast_draw_loop ; if not then go home
  102. jmp ??out
  103. ??fast_is_run:
  104. mov al,[esi]
  105. inc esi
  106. add edi,eax ; move the viewport pointer
  107. sub ecx,eax ; chop down the width to do
  108. jg short ??fast_draw_loop ; while more to do, loop back up
  109. jmp ??out
  110. ;--------------------------------------------------------------------
  111. ; General purpose draw loop for shapes with one or more flags set.
  112. ;--------------------------------------------------------------------
  113. ??general_draw_loop:
  114. test edx,SHAPE_FADING ; if fading is enabled test for
  115. jz short ??no_fading_draw_loop ; transparency
  116. or eax,eax
  117. jz short ??is_transparent
  118. ??no_fading_draw_loop:
  119. mov [edi],al ; store color value to viewport
  120. ??is_transparent:
  121. inc edi ; point to next viewport pixel
  122. dec ecx ; any source pixels left?
  123. jz ??out ; if not then go home
  124. ??general_draw_continue:
  125. mov al,[esi] ; get a byte of the source
  126. inc esi
  127. or eax,eax ; is the byte a transparent run?
  128. jz ??general_is_run ; if yes then handle the run
  129. ??test_priority:
  130. test edx,SHAPE_PRIORITY
  131. jnz short ??priority
  132. ??test_predator:
  133. test edx,SHAPE_PREDATOR
  134. jnz short ??predator
  135. ??test_compact:
  136. test edx,SHAPE_COMPACT
  137. jnz ??compact
  138. ??test_shadow:
  139. test edx,SHAPE_SHADOW
  140. jnz ??shadow
  141. ??test_translucency:
  142. test edx,SHAPE_GHOST
  143. jz short ??test_fading
  144. mov ebx,[IsTranslucent] ; is it a translucent color?
  145. mov bh,[BYTE PTR ebx + eax]
  146. or bh,bh
  147. js short ??test_fading
  148. and ebx,0FF00h ; clear all of ebx except bh
  149. ; we have the index to the translation table
  150. ; ((trans_colour * 256) + dest colour)
  151. mov al,[edi] ; mov pixel at destination to al
  152. add ebx,[Translucent] ; get the ptr to it!
  153. ; Add the (trans_color * 256) of the translation equ.
  154. mov al,[BYTE PTR ebx + eax] ; get new pixel in al
  155. jmp short ??test_fading
  156. ??test_fading:
  157. test edx,SHAPE_FADING
  158. jnz ??fading
  159. jmp short ??general_draw_loop
  160. ??priority:
  161. mov ebx,[MaskAdjust] ; get mask page offset
  162. mov bl,[BYTE PTR ebx + edi] ; get mask value
  163. and bl,CLEAR_UNUSED_BITS ; clear unused bits
  164. cmp [PriLevel],bl ; are we in front of
  165. jge short ??test_predator ; background?
  166. mov ebx,[BackAdjust] ; get background page offset
  167. mov al,[BYTE PTR ebx + edi] ; get background pixel
  168. jmp ??general_draw_loop
  169. ??predator:
  170. mov ebx,[PartialCount]
  171. add ebx,[PartialPred]
  172. or bh,bh
  173. jnz short ??draw_pred ; is this a predator pixel?
  174. mov [PartialCount],ebx
  175. jmp short ??test_compact
  176. ??draw_pred:
  177. xor bh,bh
  178. mov [PartialCount],ebx
  179. mov ebx,[PredValue] ; pick up a color offset a pseudo-
  180. ; random amount from the current
  181. mov al,[edi + ebx] ; viewport address
  182. jmp ??general_draw_loop
  183. ??compact:
  184. mov ebx,[ColorTable] ; get the address of the color table
  185. mov al,[BYTE PTR ebx + eax] ; convert it into the proper byte
  186. jmp ??test_shadow
  187. ??shadow:
  188. cmp al,SHADOW_COL
  189. jne ??test_translucency ; is the table value a magic number?
  190. mov al,[edi] ; get the destination color and
  191. mov ebx,[ShadowingTable] ; index into the shadow table
  192. mov al,[BYTE PTR ebx + eax]
  193. jmp ??general_draw_loop
  194. ??fading:
  195. mov [StashECX],ecx ; preserve ecx for later
  196. mov ebx,[FadingTable] ; run color through fading table
  197. mov ecx,[FadingNum]
  198. ??fade_loop:
  199. mov al, [BYTE PTR ebx + eax]
  200. dec ecx
  201. jnz short ??fade_loop
  202. mov ecx,[StashECX] ; restore ecx for main draw loop
  203. jmp ??general_draw_loop
  204. ??general_is_run:
  205. mov al,[esi]
  206. inc esi
  207. add edi,eax ; move the viewport pointer
  208. sub ecx,eax ; chop down the width to do
  209. jg ??general_draw_continue ; while more to do, loop back up
  210. ??out:
  211. add [WidthCount],ecx ; adjust for source ending in a run
  212. mov edx,[StashEDX]
  213. ret
  214. ENDP Draw_Normal
  215. END
  216. ;**************************** End of ds_dn.asm *****************************