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 "mcgaprim.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 MCGA_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 , [ (VideoViewPort esi) . VIVPWidth ] ; 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,[ ( VideoViewPort esi) . VIVPHeight ] ; 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 , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  142. mov [ x1_pixel ] , eax
  143. ??dest_right_ok:
  144. test dl , 0001b
  145. jz ??do_blit
  146. mov eax , [ (VideoViewPort esi) . VIVPHeight ] ; get width into register
  147. mov [ y1_pixel ] , eax
  148. ??do_blit:
  149. cld
  150. mov eax , [ (VideoViewPort esi) . VIVPXAdd ]
  151. add eax , [ (VideoViewPort esi) . VIVPWidth ]
  152. mov edi , [ (VideoViewPort esi) . VIVPOffset ]
  153. mov ecx , eax
  154. mul [ y_pixel ]
  155. add edi , [ x_pixel ]
  156. add edi , eax
  157. add ecx , [ x_pixel ]
  158. sub ecx , [ x1_pixel ]
  159. mov [ dest_ajust_width ] , ecx
  160. mov esi , [ src ]
  161. mov eax , [ pixel_width ]
  162. sub eax , [ x1_pixel ]
  163. add eax , [ x_pixel ]
  164. mov [ scr_ajust_width ] , eax
  165. mov eax , [ scr_y ]
  166. mul [ pixel_width ]
  167. add eax , [ scr_x ]
  168. add esi , eax
  169. mov edx , [ y1_pixel ]
  170. mov eax , [ x1_pixel ]
  171. sub edx , [ y_pixel ]
  172. jle ??real_out
  173. sub eax , [ x_pixel ]
  174. jle ??real_out
  175. ; ********************************************************************
  176. ; Forward bitblit only
  177. IF TRANSP
  178. test [ trans ] , 1
  179. jnz ??forward_Blit_trans
  180. ENDIF
  181. ; the inner loop is so efficient that
  182. ; the optimal consept no longer apply because
  183. ; the optimal byte have to by a number greather than 9 bytes
  184. cmp eax , 10
  185. jl ??forward_loop_bytes
  186. ??forward_loop_dword:
  187. mov ecx , edi
  188. mov ebx , eax
  189. neg ecx
  190. and ecx , 3
  191. sub ebx , ecx
  192. rep movsb
  193. mov ecx , ebx
  194. shr ecx , 2
  195. rep movsd
  196. mov ecx , ebx
  197. and ecx , 3
  198. rep movsb
  199. add esi , [ scr_ajust_width ]
  200. add edi , [ dest_ajust_width ]
  201. dec edx
  202. jnz ??forward_loop_dword
  203. ret
  204. ??forward_loop_bytes:
  205. mov ecx , eax
  206. rep movsb
  207. add esi , [ scr_ajust_width ]
  208. add edi , [ dest_ajust_width ]
  209. dec edx ; decrement the height
  210. jnz ??forward_loop_bytes
  211. ret
  212. IF TRANSP
  213. ??forward_Blit_trans:
  214. mov ecx , eax
  215. and ecx , 01fh
  216. lea ecx , [ ecx + ecx * 4 ]
  217. neg ecx
  218. shr eax , 5
  219. lea ecx , [ ??transp_reference + ecx * 2 ]
  220. mov [ y1_pixel ] , ecx
  221. ??forward_loop_trans:
  222. mov ecx , eax
  223. jmp [ y1_pixel ]
  224. ??forward_trans_line:
  225. REPT 32
  226. local transp_pixel
  227. mov bl , [ esi ]
  228. inc esi
  229. test bl , bl
  230. jz transp_pixel
  231. mov [ edi ] , bl
  232. transp_pixel:
  233. inc edi
  234. ENDM
  235. ??transp_reference:
  236. dec ecx
  237. jge ??forward_trans_line
  238. add esi , [ scr_ajust_width ]
  239. add edi , [ dest_ajust_width ]
  240. dec edx
  241. jnz ??forward_loop_trans
  242. ret
  243. ENDIF
  244. ??real_out:
  245. ret
  246. ENDP MCGA_Buffer_To_Page
  247. END