VLBTOVE.ASM 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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 : BITBLIT.ASM *
  25. ;* *
  26. ;* Programmer : Phil W. Gorrow *
  27. ;* *
  28. ;* Start Date : June 8, 1994 *
  29. ;* *
  30. ;* Last Update : December 13, 1994 [PWG] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  35. IDEAL
  36. P386
  37. MODEL USE32 FLAT
  38. LOCALS ??
  39. INCLUDE "svgaprim.inc"
  40. INCLUDE "gbuffer.inc"
  41. TRANSP equ 0
  42. CODESEG
  43. ;***************************************************************************
  44. ;* GVC::BLIT -- Copies a buffer to a graphic page non-linearly *
  45. ;* *
  46. ;* NOTE: All coordinate values are expressed in pixels *
  47. ;* *
  48. ;* INPUT: VideoViewPortClass *dest - Video View Port to copy to *
  49. ;* WORD src_x - Src x position to copy from *
  50. ;* WORD src_y - Src y position to copy from *
  51. ;* WORD dst_x - Dest x position to copy to *
  52. ;* WORD dst_y - Dest y position to copy to *
  53. ;* WORD w - Width of region to copy *
  54. ;* WORD h - Height of region to copy *
  55. ;* *
  56. ;* OUTPUT: none *
  57. ;* *
  58. ;* WARNINGS: Coordinates and dimensions will be adjusted if they exceed *
  59. ;* the boundaries. In the event that no adjustment is *
  60. ;* possible this routine will abort. *
  61. ;* *
  62. ;* HISTORY: *
  63. ;* 05/11/1994 PWG : Created. *
  64. ;* 08/05/1994 PWG : Fixed clipping problem *
  65. ;*=========================================================================*
  66. PROC Linear_Blit_To_Vesa C near
  67. USES ebx,ecx,edx,esi,edi
  68. ;*===================================================================
  69. ;* define the arguements that our function takes.
  70. ;*===================================================================
  71. ARG this :DWORD ; this is a member function
  72. ARG dest :DWORD ; what are we blitting to
  73. ARG x_pixel :DWORD ; x pixel position in source
  74. ARG y_pixel :DWORD ; y pixel position in source
  75. ARG dest_x0 :dword
  76. ARG dest_y0 :dword
  77. ARG pixel_width :DWORD ; width of rectangle to blit
  78. ARG pixel_height:DWORD ; height of rectangle to blit
  79. ARG trans :DWORD ; do we deal with transparents?
  80. ;*===================================================================
  81. ; Define some locals so that we can handle things quickly
  82. ;*===================================================================
  83. LOCAL x1_pixel :dword
  84. LOCAL y1_pixel :dword
  85. LOCAL dest_x1 : dword
  86. LOCAL dest_y1 : dword
  87. LOCAL scr_ajust_width:DWORD
  88. LOCAL dest_ajust_width:DWORD
  89. LOCAL source_area : dword
  90. LOCAL dest_area : dword
  91. ; Clip Source Rectangle against source Window boundaries.
  92. mov esi , [ this ] ; get ptr to src
  93. xor ecx , ecx
  94. xor edx , edx
  95. mov edi , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  96. mov ebx , [ x_pixel ]
  97. mov eax , [ x_pixel ]
  98. add ebx , [ pixel_width ]
  99. shld ecx , eax , 1
  100. mov [ x1_pixel ] , ebx
  101. inc edi
  102. shld edx , ebx , 1
  103. sub eax , edi
  104. sub ebx , edi
  105. shld ecx , eax , 1
  106. shld edx , ebx , 1
  107. mov edi,[ ( VideoViewPort esi) . VIVPHeight ] ; get height into register
  108. mov ebx , [ y_pixel ]
  109. mov eax , [ y_pixel ]
  110. add ebx , [ pixel_height ]
  111. shld ecx , eax , 1
  112. mov [ y1_pixel ] , ebx
  113. inc edi
  114. shld edx , ebx , 1
  115. sub eax , edi
  116. sub ebx , edi
  117. shld ecx , eax , 1
  118. shld edx , ebx , 1
  119. xor cl , 5
  120. xor dl , 5
  121. mov al , cl
  122. test dl , cl
  123. jnz ??real_out
  124. or al , dl
  125. jz ??clip_against_dest
  126. test cl , 1000b
  127. jz ??scr_left_ok
  128. mov [ x_pixel ] , 0
  129. ??scr_left_ok:
  130. test cl , 0010b
  131. jz ??scr_bottom_ok
  132. mov [ y_pixel ] , 0
  133. ??scr_bottom_ok:
  134. test dl , 0100b
  135. jz ??scr_right_ok
  136. mov eax , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  137. mov [ x1_pixel ] , eax
  138. ??scr_right_ok:
  139. test dl , 0001b
  140. jz ??clip_against_dest
  141. mov eax , [ (VideoViewPort esi) . VIVPHeight ] ; get width into register
  142. mov [ y1_pixel ] , eax
  143. ; Clip Source Rectangle against destination Window boundaries.
  144. ??clip_against_dest:
  145. mov eax , [ dest_x0 ]
  146. mov ebx , [ dest_y0 ]
  147. sub eax , [ x_pixel ]
  148. sub ebx , [ y_pixel ]
  149. add eax , [ x1_pixel ]
  150. add ebx , [ y1_pixel ]
  151. mov [ dest_x1 ] , eax
  152. mov [ dest_y1 ] , ebx
  153. mov esi , [ dest ] ; get ptr to src
  154. xor ecx , ecx
  155. xor edx , edx
  156. mov edi , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  157. mov eax , [ dest_x0 ]
  158. mov ebx , [ dest_x1 ]
  159. shld ecx , eax , 1
  160. inc edi
  161. shld edx , ebx , 1
  162. sub eax , edi
  163. sub ebx , edi
  164. shld ecx , eax , 1
  165. shld edx , ebx , 1
  166. mov edi,[ ( VideoViewPort esi) . VIVPHeight ] ; get height into register
  167. mov eax , [ dest_y0 ]
  168. mov ebx , [ dest_y1 ]
  169. shld ecx , eax , 1
  170. inc edi
  171. shld edx , ebx , 1
  172. sub eax , edi
  173. sub ebx , edi
  174. shld ecx , eax , 1
  175. shld edx , ebx , 1
  176. xor cl , 5
  177. xor dl , 5
  178. mov al , cl
  179. test dl , cl
  180. jnz ??real_out
  181. or al , dl
  182. jz ??do_blit
  183. test cl , 1000b
  184. jz ??dest_left_ok
  185. mov eax , [ dest_x0 ]
  186. mov [ dest_x0 ] , 0
  187. sub [ x_pixel ] , eax
  188. ??dest_left_ok:
  189. test cl , 0010b
  190. jz ??dest_bottom_ok
  191. mov eax , [ dest_y0 ]
  192. mov [ dest_y0 ] , 0
  193. sub [ y_pixel ] , eax
  194. ??dest_bottom_ok:
  195. test dl , 0100b
  196. jz ??dest_right_ok
  197. mov ebx , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  198. mov eax , [ dest_x1 ]
  199. mov [ dest_x1 ] , ebx
  200. sub eax , ebx
  201. sub [ x1_pixel ] , eax
  202. ??dest_right_ok:
  203. test dl , 0001b
  204. jz ??do_blit
  205. mov ebx , [ (VideoViewPort esi) . VIVPHeight ] ; get width into register
  206. mov eax , [ dest_y1 ]
  207. mov [ dest_y1 ] , ebx
  208. sub eax , ebx
  209. sub [ y1_pixel ] , eax
  210. ??do_blit:
  211. cld
  212. mov ebx , [ this ]
  213. mov esi , [ (VideoViewPort ebx) . VIVPOffset ]
  214. mov eax , [ (VideoViewPort ebx) . VIVPXAdd ]
  215. add eax , [ (VideoViewPort ebx) . VIVPWidth ]
  216. mov ecx , eax
  217. mul [ y_pixel ]
  218. add esi , [ x_pixel ]
  219. mov [ source_area ] , ecx
  220. add esi , eax
  221. add ecx , [ x_pixel ]
  222. sub ecx , [ x1_pixel ]
  223. mov [ scr_ajust_width ] , ecx
  224. mov ebx , [ dest ]
  225. mov edi , [ (VideoViewPort ebx) . VIVPOffset ]
  226. mov eax , [ (VideoViewPort ebx) . VIVPXAdd ]
  227. add eax , [ (VideoViewPort ebx) . VIVPWidth ]
  228. mov ecx , eax
  229. mul [ dest_y0 ]
  230. add edi , [ dest_x0 ]
  231. mov [ dest_area ] , ecx
  232. add edi , eax
  233. Call Vesa_Asm_Set_Win ; set the window
  234. mov eax , [ dest_x1 ]
  235. sub eax , [ dest_x0 ]
  236. jz ??real_out
  237. sub ecx , eax
  238. mov [ dest_ajust_width ] , ecx
  239. mov edx , [ dest_y1 ]
  240. sub edx , [ dest_y0 ]
  241. jz ??real_out
  242. ; ********************************************************************
  243. ; Forward bitblit only
  244. IF TRANSP
  245. test [ trans ] , 1
  246. jnz ??forward_Blit_trans
  247. ENDIF
  248. ; the inner loop is so efficient that
  249. ; the optimal consept no longer apply because
  250. ; the optimal byte have to by a number greather than 9 bytes
  251. cmp eax , 10
  252. jl ??forward_loop_bytes
  253. ??forward_loop_dword:
  254. lea ebx , [ edi + eax ]
  255. add ebx , [ cpu_video_page ]
  256. cmp ebx , [ cpu_page_limit ]
  257. jl ??in_range
  258. xor ecx , ecx
  259. mov ebx , eax
  260. cmp edi , 0b0000h
  261. jge ??no_trailing
  262. mov ecx , 0b0000h
  263. sub ecx , edi
  264. sub ebx , ecx
  265. rep movsb
  266. ??no_trailing:
  267. add edi , [ cpu_video_page ]
  268. Call Vesa_Asm_Set_Win ; set the window
  269. mov ecx , ebx
  270. rep movsb
  271. add esi , [ scr_ajust_width ]
  272. add edi , [ dest_ajust_width ]
  273. dec edx ; decrement the height
  274. jnz ??forward_loop_dword
  275. ret
  276. ??in_range:
  277. mov ecx , edi
  278. mov ebx , eax
  279. neg ecx
  280. and ecx , 3
  281. sub ebx , ecx
  282. rep movsb
  283. mov ecx , ebx
  284. shr ecx , 2
  285. rep movsd
  286. mov ecx , ebx
  287. and ecx , 3
  288. rep movsb
  289. add esi , [ scr_ajust_width ]
  290. add edi , [ dest_ajust_width ]
  291. dec edx
  292. jnz ??forward_loop_dword
  293. ret
  294. ??forward_loop_bytes:
  295. lea ebx , [ edi + eax ]
  296. add ebx , [ cpu_video_page ]
  297. cmp ebx , [ cpu_page_limit ]
  298. mov ebx , eax
  299. jl ??in_range_bytes
  300. xor ecx , ecx
  301. cmp edi , 0b0000h
  302. jge ??no_trailing_bytes
  303. mov ecx , 0b0000h
  304. sub ecx , edi
  305. sub ebx , ecx
  306. rep movsb
  307. ??no_trailing_bytes:
  308. add edi , [ cpu_video_page ]
  309. Call Vesa_Asm_Set_Win ; set the window
  310. ??in_range_bytes:
  311. mov ecx , ebx
  312. rep movsb
  313. add esi , [ scr_ajust_width ]
  314. add edi , [ dest_ajust_width ]
  315. dec edx ; decrement the height
  316. jnz ??forward_loop_bytes
  317. ret
  318. IF TRANSP
  319. ??forward_Blit_trans:
  320. mov ecx , eax
  321. and ecx , 01fh
  322. lea ecx , [ ecx + ecx * 4 ]
  323. neg ecx
  324. shr eax , 5
  325. lea ecx , [ ??transp_reference + ecx * 2 ]
  326. mov [ y1_pixel ] , ecx
  327. ??forward_loop_trans:
  328. mov ecx , eax
  329. jmp [ y1_pixel ]
  330. ??forward_trans_line:
  331. REPT 32
  332. local transp_pixel
  333. mov bl , [ esi ]
  334. test bl , bl
  335. jz transp_pixel
  336. mov [ edi ] , bl
  337. transp_pixel:
  338. inc esi
  339. inc edi
  340. ENDM
  341. ??transp_reference:
  342. dec ecx
  343. jge ??forward_trans_line
  344. add esi , [ scr_ajust_width ]
  345. add edi , [ dest_ajust_width ]
  346. dec edx
  347. jnz ??forward_loop_trans
  348. ret
  349. ENDIF
  350. ??real_out:
  351. ret
  352. ENDP Linear_Blit_To_Vesa
  353. END