TOBUFF.ASM 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 : Westwood 32 bit Library *
  23. ;* *
  24. ;* File Name : TOBUFFER.ASM *
  25. ;* *
  26. ;* Programmer : Phil W. Gorrow *
  27. ;* *
  28. ;* Start Date : June 8, 1994 *
  29. ;* Last Update : Feb 10, 1995 [jrj] *
  30. ;* *
  31. ;*-------------------------------------------------------------------------*
  32. ;* Functions: *
  33. ;* VVC::TOBUFFER -- Copies a virtual viewport to a linear buffer *
  34. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  35. IDEAL
  36. P386
  37. MODEL USE32 FLAT
  38. LOCALS ??
  39. TRANSP equ 0
  40. INCLUDE ".\drawbuff.inc"
  41. INCLUDE ".\gbuffer.inc"
  42. CODESEG
  43. ;***************************************************************************
  44. ;* VIVC::TOBUFFER -- Copies a virtual viewport to a linear buffer *
  45. ;* *
  46. ;* INPUT: BYTE * dest - buffer to copy to *
  47. ;* size - size of the buffer to copy to *
  48. ;* x_pixel - x pixel on viewport to copy from *
  49. ;* y_pixel - y pixel on viewport to copy from *
  50. ;* pixel_width - the width of copy region *
  51. ;* pixel_height - the height of copy region *
  52. ;* *
  53. ;* OUTPUT: none *
  54. ;* *
  55. ;* WARNINGS: Coordinates and dimensions will be adjusted if they exceed *
  56. ;* the boundaries. In the event that no adjustment is *
  57. ;* possible this routine will abort. If the size of the *
  58. ;* region to copy exceeds the size passed in for the buffer *
  59. ;* the routine will automatically abort. *
  60. ;* *
  61. ;* HISTORY: *
  62. ;* 06/15/1994 PWG : Created. *
  63. ;*=========================================================================*
  64. PROC Buffer_To_Buffer C near
  65. USES ebx,ecx,edx,esi,edi
  66. ;*===================================================================
  67. ;* define the arguements that our function takes.
  68. ;*===================================================================
  69. ARG this_object:DWORD ; this is a class member function
  70. ARG x_pixel:DWORD ; Page X pixel coordinate.
  71. ARG y_pixel:DWORD ; Page Y pixel coordinate.
  72. ARG pixel_width:DWORD ; Width of region in pixels.
  73. ARG pixel_height:DWORD ; Height of region in pixels.
  74. ARG dest:DWORD ; the buffer to copy to
  75. ARG buffer_size:DWORD ; the size of the buffer
  76. ;*===================================================================
  77. ; Define some locals so that we can handle things quickly
  78. ;*===================================================================
  79. LOCAL x1_pixel :dword
  80. LOCAL y1_pixel :dword
  81. LOCAL dest_x1 : dword
  82. LOCAL dest_y1 : dword
  83. LOCAL dest_ajust_width:DWORD
  84. LOCAL scr_ajust_width:DWORD
  85. LOCAL dest_area : dword
  86. ; Clip dest Rectangle against source Window boundaries.
  87. mov [ dest_x1 ] , 0
  88. mov [ dest_y1 ] , 0
  89. mov esi , [ this_object ] ; get ptr to dest
  90. xor ecx , ecx
  91. xor edx , edx
  92. mov edi , [ (GraphicViewPort esi) . GVPWidth ] ; get width into register
  93. mov ebx , [ x_pixel ]
  94. mov eax , [ x_pixel ]
  95. add ebx , [ pixel_width ]
  96. shld ecx , eax , 1
  97. mov [ x1_pixel ] , ebx
  98. inc edi
  99. shld edx , ebx , 1
  100. sub eax , edi
  101. sub ebx , edi
  102. shld ecx , eax , 1
  103. shld edx , ebx , 1
  104. mov edi,[ ( GraphicViewPort esi) . GVPHeight ] ; get height into register
  105. mov ebx , [ y_pixel ]
  106. mov eax , [ y_pixel ]
  107. add ebx , [ pixel_height ]
  108. shld ecx , eax , 1
  109. mov [ y1_pixel ] , ebx
  110. inc edi
  111. shld edx , ebx , 1
  112. sub eax , edi
  113. sub ebx , edi
  114. shld ecx , eax , 1
  115. shld edx , ebx , 1
  116. xor cl , 5
  117. xor dl , 5
  118. mov al , cl
  119. test dl , cl
  120. jnz ??real_out
  121. or al , dl
  122. jz ??do_blit
  123. test cl , 1000b
  124. jz ??scr_left_ok
  125. mov eax , [ x_pixel ]
  126. neg eax
  127. mov [ x_pixel ] , 0
  128. mov [ dest_x1 ] , eax
  129. ??scr_left_ok:
  130. test cl , 0010b
  131. jz ??scr_bottom_ok
  132. mov eax , [ y_pixel ]
  133. neg eax
  134. mov [ y_pixel ] , 0
  135. mov [ dest_y1 ] , eax
  136. ??scr_bottom_ok:
  137. test dl , 0100b
  138. jz ??scr_right_ok
  139. mov eax , [ (GraphicViewPort esi) . GVPWidth ] ; get width into register
  140. mov [ x1_pixel ] , eax
  141. ??scr_right_ok:
  142. test dl , 0001b
  143. jz ??do_blit
  144. mov eax , [ (GraphicViewPort esi) . GVPHeight ] ; get width into register
  145. mov [ y1_pixel ] , eax
  146. ??do_blit:
  147. cld
  148. mov eax , [ (GraphicViewPort esi) . GVPXAdd ]
  149. add eax , [ (GraphicViewPort esi) . GVPWidth ]
  150. add eax , [ (GraphicViewPort esi) . GVPPitch ]
  151. mov esi , [ (GraphicViewPort esi) . GVPOffset ]
  152. mov ecx , eax
  153. mul [ y_pixel ]
  154. add esi , [ x_pixel ]
  155. add esi , eax
  156. add ecx , [ x_pixel ]
  157. sub ecx , [ x1_pixel ]
  158. mov [ scr_ajust_width ] , ecx
  159. mov edi , [ dest ]
  160. mov eax , [ pixel_width ]
  161. sub eax , [ x1_pixel ]
  162. add eax , [ x_pixel ]
  163. mov [ dest_ajust_width ] , eax
  164. mov eax , [ dest_y1 ]
  165. mul [ pixel_width ]
  166. add eax , [ dest_x1 ]
  167. add edi , eax
  168. mov edx , [ y1_pixel ]
  169. mov eax , [ x1_pixel ]
  170. sub edx , [ y_pixel ]
  171. jle ??real_out
  172. sub eax , [ x_pixel ]
  173. jle ??real_out
  174. mov ebx , [ pixel_width ]
  175. imul ebx , edx
  176. cmp ebx , [ buffer_size ]
  177. jg ??real_out
  178. ; ********************************************************************
  179. ; Forward bitblit only
  180. IF TRANSP
  181. cmp [ transp ] , 0
  182. jnz ??forward_Blit_trans
  183. ENDIF
  184. ; the inner loop is so efficient that
  185. ; the optimal consept no longer apply because
  186. ; the optimal byte have to by a number greather than 9 bytes
  187. cmp eax , 10
  188. jl ??forward_loop_bytes
  189. ??forward_loop_dword:
  190. mov ecx , edi
  191. mov ebx , eax
  192. neg ecx
  193. and ecx , 3
  194. sub ebx , ecx
  195. rep movsb
  196. mov ecx , ebx
  197. shr ecx , 2
  198. rep movsd
  199. mov ecx , ebx
  200. and ecx , 3
  201. rep movsb
  202. add esi , [ scr_ajust_width ]
  203. add edi , [ dest_ajust_width ]
  204. dec edx
  205. jnz ??forward_loop_dword
  206. ret
  207. ??forward_loop_bytes:
  208. mov ecx , eax
  209. rep movsb
  210. add esi , [ scr_ajust_width ]
  211. add edi , [ dest_ajust_width ]
  212. dec edx ; decrement the height
  213. jnz ??forward_loop_bytes
  214. ret
  215. IF TRANSP
  216. ??forward_Blit_trans:
  217. mov ecx , eax
  218. and ecx , 01fh
  219. lea ecx , [ ecx + ecx * 4 ]
  220. neg ecx
  221. shr eax , 5
  222. lea ecx , [ ??transp_reference + ecx * 2 ]
  223. mov [ y1_pixel ] , ecx
  224. ??forward_loop_trans:
  225. mov ecx , eax
  226. jmp [ y1_pixel ]
  227. ??forward_trans_line:
  228. REPT 32
  229. local transp_pixel
  230. mov bl , [ esi ]
  231. test bl , bl
  232. jz transp_pixel
  233. mov [ edi ] , bl
  234. transp_pixel:
  235. inc esi
  236. inc edi
  237. ENDM
  238. ??transp_reference:
  239. dec ecx
  240. jge ??forward_trans_line
  241. add esi , [ scr_ajust_width ]
  242. add edi , [ dest_ajust_width ]
  243. dec edx
  244. jnz ??forward_loop_trans
  245. ret
  246. ENDIF
  247. ??real_out:
  248. ret
  249. ENDP Buffer_To_Buffer
  250. END