VTOPAGE.ASM 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 : December 9, 1994 [PWG] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* Buffer_To_Page(GVC) -- Copies a linear buffer to a graphic viewport *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. IDEAL
  37. P386
  38. MODEL USE32 FLAT
  39. LOCALS ??
  40. TRANSP equ 0
  41. INCLUDE "svgaprim.inc"
  42. INCLUDE "gbuffer.inc"
  43. CODESEG
  44. ;***************************************************************************
  45. ;* VVC::TOPAGE -- Copies a linear buffer to a virtual viewport *
  46. ;* *
  47. ;* INPUT: WORD x_pixel - x pixel on viewport to copy from *
  48. ;* WORD y_pixel - y pixel on viewport to copy from *
  49. ;* WORD pixel_width - the width of copy region *
  50. ;* WORD pixel_height - the height of copy region *
  51. ;* BYTE * src - buffer to copy from *
  52. ;* VVPC * dest - virtual viewport to copy to *
  53. ;* *
  54. ;* OUTPUT: none *
  55. ;* *
  56. ;* WARNINGS: Coordinates and dimensions will be adjusted if they exceed *
  57. ;* the boundaries. In the event that no adjustment is *
  58. ;* possible this routine will abort. If the size of the *
  59. ;* region to copy exceeds the size passed in for the buffer *
  60. ;* the routine will automatically abort. *
  61. ;* *
  62. ;* HISTORY: *
  63. ;* 06/15/1994 PWG : Created. *
  64. ;* 12/09/1994 PWG : Made SVGA Modifications *
  65. ;*=========================================================================*
  66. PROC Vesa_Buffer_To_Page C near
  67. USES ebx,ecx,edx,esi,edi
  68. ;*===================================================================
  69. ;* define the arguements that our function takes.
  70. ;*===================================================================
  71. ARG x_pixel :DWORD ; x pixel position in source
  72. ARG y_pixel :DWORD ; y pixel position in source
  73. ARG pixel_width :DWORD ; width of rectangle to blit
  74. ARG pixel_height:DWORD ; height of rectangle to blit
  75. ARG src :DWORD ; this is a member function
  76. ARG dest :DWORD ; what are we blitting to
  77. ; ARG trans :DWORD ; do we deal with transparents?
  78. ;*===================================================================
  79. ; Define some locals so that we can handle things quickly
  80. ;*===================================================================
  81. LOCAL x1_pixel :dword
  82. LOCAL y1_pixel :dword
  83. LOCAL scr_x1 : dword
  84. LOCAL scr_y1 : dword
  85. LOCAL dest_ajust_width:DWORD
  86. LOCAL scr_ajust_width:DWORD
  87. LOCAL dest_area : dword
  88. cmp [ src ] , 0
  89. jz ??real_out
  90. ; Clip dest Rectangle against source Window boundaries.
  91. mov [ scr_x1 ] , 0
  92. mov [ scr_y1 ] , 0
  93. mov esi , [ dest ] ; get ptr to dest
  94. xor ecx , ecx
  95. xor edx , edx
  96. mov edi , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  97. mov ebx , [ x_pixel ]
  98. mov eax , [ x_pixel ]
  99. add ebx , [ pixel_width ]
  100. shld ecx , eax , 1
  101. mov [ x1_pixel ] , ebx
  102. inc edi
  103. shld edx , ebx , 1
  104. sub eax , edi
  105. sub ebx , edi
  106. shld ecx , eax , 1
  107. shld edx , ebx , 1
  108. mov edi,[ ( VideoViewPort esi) . VIVPHeight ] ; get height into register
  109. mov ebx , [ y_pixel ]
  110. mov eax , [ y_pixel ]
  111. add ebx , [ pixel_height ]
  112. shld ecx , eax , 1
  113. mov [ y1_pixel ] , ebx
  114. inc edi
  115. shld edx , ebx , 1
  116. sub eax , edi
  117. sub ebx , edi
  118. shld ecx , eax , 1
  119. shld edx , ebx , 1
  120. xor cl , 5
  121. xor dl , 5
  122. mov al , cl
  123. test dl , cl
  124. jnz ??real_out
  125. or al , dl
  126. jz ??do_blit
  127. test cl , 1000b
  128. jz ??dest_left_ok
  129. mov eax , [ x_pixel ]
  130. neg eax
  131. mov [ x_pixel ] , 0
  132. mov [ scr_x1 ] , eax
  133. ??dest_left_ok:
  134. test cl , 0010b
  135. jz ??dest_bottom_ok
  136. mov eax , [ y_pixel ]
  137. neg eax
  138. mov [ y_pixel ] , 0
  139. mov [ scr_y1 ] , eax
  140. ??dest_bottom_ok:
  141. test dl , 0100b
  142. jz ??dest_right_ok
  143. mov eax , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  144. mov [ x1_pixel ] , eax
  145. ??dest_right_ok:
  146. test dl , 0001b
  147. jz ??do_blit
  148. mov eax , [ (VideoViewPort esi) . VIVPHeight ] ; get width into register
  149. mov [ y1_pixel ] , eax
  150. ??do_blit:
  151. cld
  152. mov eax , [ (VideoViewPort esi) . VIVPXAdd ]
  153. add eax , [ (VideoViewPort esi) . VIVPWidth ]
  154. mov edi , [ (VideoViewPort esi) . VIVPOffset ]
  155. mov ecx , eax
  156. mul [ y_pixel ]
  157. add edi , [ x_pixel ]
  158. add edi , eax
  159. call Vesa_Asm_Set_Win ; set the window
  160. add ecx , [ x_pixel ]
  161. sub ecx , [ x1_pixel ]
  162. mov [ dest_ajust_width ] , ecx
  163. mov esi , [ src ]
  164. mov eax , [ pixel_width ]
  165. sub eax , [ x1_pixel ]
  166. add eax , [ x_pixel ]
  167. mov [ scr_ajust_width ] , eax
  168. mov eax , [ scr_y1 ]
  169. mul [ pixel_width ]
  170. add eax , [ scr_x1 ]
  171. add esi , eax
  172. mov edx , [ y1_pixel ]
  173. sub edx , [ y_pixel ]
  174. jz ??real_out
  175. mov eax , [ x1_pixel ]
  176. sub eax , [ x_pixel ]
  177. jz ??real_out
  178. ; ********************************************************************
  179. ; Forward bitblit only
  180. IF TRANSP
  181. test [ trans ] , 1
  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. lea ebx , [ edi + eax ]
  191. add ebx , [ cpu_video_page ]
  192. cmp ebx , [ cpu_page_limit ]
  193. jl ??in_range
  194. xor ecx , ecx
  195. mov ebx , eax
  196. cmp edi , 0b0000h
  197. jge ??no_trailing
  198. mov ecx , 0b0000h
  199. sub ecx , edi
  200. sub ebx , ecx
  201. rep movsb
  202. ??no_trailing:
  203. add edi , [ cpu_video_page ]
  204. call Vesa_Asm_Set_Win ; set the window
  205. mov ecx , ebx
  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_dword
  211. ret
  212. ??in_range:
  213. mov ecx , edi
  214. mov ebx , eax
  215. neg ecx
  216. and ecx , 3
  217. sub ebx , ecx
  218. rep movsb
  219. mov ecx , ebx
  220. shr ecx , 2
  221. rep movsd
  222. mov ecx , ebx
  223. and ecx , 3
  224. rep movsb
  225. add esi , [ scr_ajust_width ]
  226. add edi , [ dest_ajust_width ]
  227. dec edx
  228. jnz ??forward_loop_dword
  229. ret
  230. ??forward_loop_bytes:
  231. lea ebx , [ edi + eax ]
  232. add ebx , [ cpu_video_page ]
  233. cmp ebx , [ cpu_page_limit ]
  234. mov ebx , eax
  235. jl ??in_range_bytes
  236. xor ecx , ecx
  237. cmp edi , 0b0000h
  238. jge ??no_trailing_bytes
  239. mov ecx , 0b0000h
  240. sub ecx , edi
  241. sub ebx , ecx
  242. rep movsb
  243. ??no_trailing_bytes:
  244. add edi , [ cpu_video_page ]
  245. Call Vesa_Asm_Set_Win ; set the window
  246. ??in_range_bytes:
  247. mov ecx , ebx
  248. rep movsb
  249. add esi , [ scr_ajust_width ]
  250. add edi , [ dest_ajust_width ]
  251. dec edx ; decrement the height
  252. jnz ??forward_loop_bytes
  253. ret
  254. IF TRANSP
  255. ??forward_Blit_trans:
  256. mov ecx , eax
  257. and ecx , 01fh
  258. lea ecx , [ ecx + ecx * 4 ]
  259. neg ecx
  260. shr eax , 5
  261. lea ecx , [ ??transp_reference + ecx * 2 ]
  262. mov [ y1_pixel ] , ecx
  263. ??forward_loop_trans:
  264. mov ecx , eax
  265. jmp [ y1_pixel ]
  266. ??forward_trans_line:
  267. REPT 32
  268. local transp_pixel
  269. mov bl , [ esi ]
  270. test bl , bl
  271. jz transp_pixel
  272. mov [ edi ] , bl
  273. transp_pixel:
  274. inc esi
  275. inc edi
  276. ENDM
  277. ??transp_reference:
  278. dec ecx
  279. jge ??forward_trans_line
  280. add esi , [ scr_ajust_width ]
  281. add edi , [ dest_ajust_width ]
  282. dec edx
  283. jnz ??forward_loop_trans
  284. ret
  285. ENDIF
  286. ??real_out:
  287. ret
  288. ENDP Vesa_Buffer_To_Page
  289. END