TOPAGE.ASM 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 : TOPAGE.ASM *
  25. ;* *
  26. ;* Programmer : Phil W. Gorrow *
  27. ;* *
  28. ;* Start Date : June 8, 1994 *
  29. ;* *
  30. ;* Last Update : June 15, 1994 [PWG] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* Buffer_To_Page -- Copies a linear buffer to a virtual viewport *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. IDEAL
  37. P386
  38. MODEL USE32 FLAT
  39. TRANSP equ 0
  40. INCLUDE ".\drawbuff.inc"
  41. INCLUDE ".\gbuffer.inc"
  42. CODESEG
  43. ;***************************************************************************
  44. ;* VVC::TOPAGE -- Copies a linear buffer to a virtual viewport *
  45. ;* *
  46. ;* INPUT: WORD x_pixel - x pixel on viewport to copy from *
  47. ;* WORD y_pixel - y pixel on viewport to copy from *
  48. ;* WORD pixel_width - the width of copy region *
  49. ;* WORD pixel_height - the height of copy region *
  50. ;* BYTE * src - buffer to copy from *
  51. ;* VVPC * dest - virtual viewport to copy to *
  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_Page C near
  65. USES eax,ebx,ecx,edx,esi,edi
  66. ;*===================================================================
  67. ;* define the arguements that our function takes.
  68. ;*===================================================================
  69. ARG x_pixel :DWORD ; x pixel position in source
  70. ARG y_pixel :DWORD ; y pixel position in source
  71. ARG pixel_width :DWORD ; width of rectangle to blit
  72. ARG pixel_height:DWORD ; height of rectangle to blit
  73. ARG src :DWORD ; this is a member function
  74. ARG dest :DWORD ; what are we blitting to
  75. ; ARG trans :DWORD ; do we deal with transparents?
  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 scr_x : dword
  82. local scr_y : dword
  83. LOCAL dest_ajust_width:DWORD
  84. LOCAL scr_ajust_width:DWORD
  85. LOCAL dest_area : dword
  86. cmp [ src ] , 0
  87. jz ??real_out
  88. ; Clip dest Rectangle against source Window boundaries.
  89. mov [ scr_x ] , 0
  90. mov [ scr_y ] , 0
  91. mov esi , [ dest ] ; get ptr to dest
  92. xor ecx , ecx
  93. xor edx , edx
  94. mov edi , [ (GraphicViewPort esi) . GVPWidth ] ; get width into register
  95. mov ebx , [ x_pixel ]
  96. mov eax , [ x_pixel ]
  97. add ebx , [ pixel_width ]
  98. shld ecx , eax , 1
  99. mov [ x1_pixel ] , ebx
  100. inc edi
  101. shld edx , ebx , 1
  102. sub eax , edi
  103. sub ebx , edi
  104. shld ecx , eax , 1
  105. shld edx , ebx , 1
  106. mov edi,[ ( GraphicViewPort esi) . GVPHeight ] ; get height into register
  107. mov ebx , [ y_pixel ]
  108. mov eax , [ y_pixel ]
  109. add ebx , [ pixel_height ]
  110. shld ecx , eax , 1
  111. mov [ y1_pixel ] , ebx
  112. inc edi
  113. shld edx , ebx , 1
  114. sub eax , edi
  115. sub ebx , edi
  116. shld ecx , eax , 1
  117. shld edx , ebx , 1
  118. xor cl , 5
  119. xor dl , 5
  120. mov al , cl
  121. test dl , cl
  122. jnz ??real_out
  123. or al , dl
  124. jz ??do_blit
  125. test cl , 1000b
  126. jz ??dest_left_ok
  127. mov eax , [ x_pixel ]
  128. neg eax
  129. mov [ x_pixel ] , 0
  130. mov [ scr_x ] , eax
  131. ??dest_left_ok:
  132. test cl , 0010b
  133. jz ??dest_bottom_ok
  134. mov eax , [ y_pixel ]
  135. neg eax
  136. mov [ y_pixel ] , 0
  137. mov [ scr_y ] , eax
  138. ??dest_bottom_ok:
  139. test dl , 0100b
  140. jz ??dest_right_ok
  141. mov eax , [ (GraphicViewPort esi) . GVPWidth ] ; get width into register
  142. mov [ x1_pixel ] , eax
  143. ??dest_right_ok:
  144. test dl , 0001b
  145. jz ??do_blit
  146. mov eax , [ (GraphicViewPort esi) . GVPHeight ] ; get width into register
  147. mov [ y1_pixel ] , eax
  148. ??do_blit:
  149. cld
  150. mov eax , [ (GraphicViewPort esi) . GVPXAdd ]
  151. add eax , [ (GraphicViewPort esi) . GVPWidth ]
  152. add eax , [ (GraphicViewPort esi) . GVPPitch ]
  153. mov edi , [ (GraphicViewPort esi) . GVPOffset ]
  154. mov ecx , eax
  155. mul [ y_pixel ]
  156. add edi , [ x_pixel ]
  157. add edi , eax
  158. add ecx , [ x_pixel ]
  159. sub ecx , [ x1_pixel ]
  160. mov [ dest_ajust_width ] , ecx
  161. mov esi , [ src ]
  162. mov eax , [ pixel_width ]
  163. sub eax , [ x1_pixel ]
  164. add eax , [ x_pixel ]
  165. mov [ scr_ajust_width ] , eax
  166. mov eax , [ scr_y ]
  167. mul [ pixel_width ]
  168. add eax , [ scr_x ]
  169. add esi , eax
  170. mov edx , [ y1_pixel ]
  171. mov eax , [ x1_pixel ]
  172. sub edx , [ y_pixel ]
  173. jle ??real_out
  174. sub eax , [ x_pixel ]
  175. jle ??real_out
  176. ; ********************************************************************
  177. ; Forward bitblit only
  178. IF TRANSP
  179. test [ trans ] , 1
  180. jnz ??forward_Blit_trans
  181. ENDIF
  182. ; the inner loop is so efficient that
  183. ; the optimal consept no longer apply because
  184. ; the optimal byte have to by a number greather than 9 bytes
  185. cmp eax , 10
  186. jl ??forward_loop_bytes
  187. ??forward_loop_dword:
  188. mov ecx , edi
  189. mov ebx , eax
  190. neg ecx
  191. and ecx , 3
  192. sub ebx , ecx
  193. rep movsb
  194. mov ecx , ebx
  195. shr ecx , 2
  196. rep movsd
  197. mov ecx , ebx
  198. and ecx , 3
  199. rep movsb
  200. add esi , [ scr_ajust_width ]
  201. add edi , [ dest_ajust_width ]
  202. dec edx
  203. jnz ??forward_loop_dword
  204. ret
  205. ??forward_loop_bytes:
  206. mov ecx , eax
  207. rep movsb
  208. add esi , [ scr_ajust_width ]
  209. add edi , [ dest_ajust_width ]
  210. dec edx ; decrement the height
  211. jnz ??forward_loop_bytes
  212. ret
  213. IF TRANSP
  214. ??forward_Blit_trans:
  215. mov ecx , eax
  216. and ecx , 01fh
  217. lea ecx , [ ecx + ecx * 4 ]
  218. neg ecx
  219. shr eax , 5
  220. lea ecx , [ ??transp_reference + ecx * 2 ]
  221. mov [ y1_pixel ] , ecx
  222. ??forward_loop_trans:
  223. mov ecx , eax
  224. jmp [ y1_pixel ]
  225. ??forward_trans_line:
  226. REPT 32
  227. local transp_pixel
  228. mov bl , [ esi ]
  229. inc esi
  230. test bl , bl
  231. jz transp_pixel
  232. mov [ edi ] , bl
  233. transp_pixel:
  234. inc edi
  235. ENDM
  236. ??transp_reference:
  237. dec ecx
  238. jge ??forward_trans_line
  239. add esi , [ scr_ajust_width ]
  240. add edi , [ dest_ajust_width ]
  241. dec edx
  242. jnz ??forward_loop_trans
  243. ret
  244. ENDIF
  245. ??real_out:
  246. ret
  247. ENDP Buffer_To_Page
  248. END