VVETOLB.ASM 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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: VirtualViewPortClass *dest - Virtual 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 Vesa_Blit_To_Linear 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 edi , [ (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 edi , [ x_pixel ]
  219. mov [ source_area ] , ecx
  220. add edi , eax
  221. call Vesa_Asm_Set_Win ; set the window
  222. mov esi , edi
  223. add ecx , [ x_pixel ]
  224. sub ecx , [ x1_pixel ]
  225. mov [ scr_ajust_width ] , ecx
  226. mov ebx , [ dest ]
  227. mov edi , [ (VideoViewPort ebx) . VIVPOffset ]
  228. mov eax , [ (VideoViewPort ebx) . VIVPXAdd ]
  229. add eax , [ (VideoViewPort ebx) . VIVPWidth ]
  230. mov ecx , eax
  231. mul [ dest_y0 ]
  232. add edi , [ dest_x0 ]
  233. mov [ dest_area ] , ecx
  234. add edi , eax
  235. mov eax , [ dest_x1 ]
  236. sub eax , [ dest_x0 ]
  237. jz ??real_out
  238. sub ecx , eax
  239. mov [ dest_ajust_width ] , ecx
  240. mov edx , [ dest_y1 ]
  241. sub edx , [ dest_y0 ]
  242. jz ??real_out
  243. ; ********************************************************************
  244. ; Forward bitblit only
  245. IF TRANSP
  246. test [ trans ] , 1
  247. jnz ??forward_Blit_trans
  248. ENDIF
  249. ; the inner loop is so efficient that
  250. ; the optimal consept no longer apply because
  251. ; the optimal byte have to by a number greather than 9 bytes
  252. cmp eax , 10
  253. jl ??forward_loop_bytes
  254. ??forward_loop_dword:
  255. lea ebx , [ esi + eax ]
  256. add ebx , [ cpu_video_page ]
  257. cmp ebx , [ cpu_page_limit ]
  258. jl ??in_range
  259. xor ecx , ecx
  260. mov ebx , eax
  261. cmp esi , 0b0000h
  262. jge ??no_trailing
  263. mov ecx , 0b0000h
  264. sub ecx , esi
  265. sub ebx , ecx
  266. rep movsb
  267. ??no_trailing:
  268. add esi , [ cpu_video_page ]
  269. xchg edi , esi
  270. Call Vesa_Asm_Set_Win ; set the window
  271. xchg edi , esi
  272. mov ecx , ebx
  273. rep movsb
  274. add esi , [ scr_ajust_width ]
  275. add edi , [ dest_ajust_width ]
  276. dec edx ; decrement the height
  277. jnz ??forward_loop_dword
  278. ret
  279. ??in_range:
  280. mov ecx , edi
  281. mov ebx , eax
  282. neg ecx
  283. and ecx , 3
  284. sub ebx , ecx
  285. rep movsb
  286. mov ecx , ebx
  287. shr ecx , 2
  288. rep movsd
  289. mov ecx , ebx
  290. and ecx , 3
  291. rep movsb
  292. add esi , [ scr_ajust_width ]
  293. add edi , [ dest_ajust_width ]
  294. dec edx
  295. jnz ??forward_loop_dword
  296. ret
  297. ??forward_loop_bytes:
  298. lea ebx , [ esi + eax ]
  299. add ebx , [ cpu_video_page ]
  300. cmp ebx , [ cpu_page_limit ]
  301. mov ebx , eax
  302. jl ??in_range_bytes
  303. xor ecx , ecx
  304. cmp esi , 0b0000h
  305. jge ??no_trailing_bytes
  306. mov ecx , 0b0000h
  307. sub ecx , esi
  308. sub ebx , ecx
  309. rep movsb
  310. ??no_trailing_bytes:
  311. add esi , [ cpu_video_page ]
  312. xchg edi , esi
  313. Call Vesa_Asm_Set_Win ; set the window
  314. xchg edi , esi
  315. ??in_range_bytes:
  316. mov ecx , ebx
  317. rep movsb
  318. add esi , [ scr_ajust_width ]
  319. add edi , [ dest_ajust_width ]
  320. dec edx ; decrement the height
  321. jnz ??forward_loop_bytes
  322. ret
  323. IF TRANSP
  324. ??forward_Blit_trans:
  325. mov ecx , eax
  326. and ecx , 01fh
  327. lea ecx , [ ecx + ecx * 4 ]
  328. neg ecx
  329. shr eax , 5
  330. lea ecx , [ ??transp_reference + ecx * 2 ]
  331. mov [ y1_pixel ] , ecx
  332. ??forward_loop_trans:
  333. mov ecx , eax
  334. jmp [ y1_pixel ]
  335. ??forward_trans_line:
  336. REPT 32
  337. local transp_pixel
  338. mov bl , [ esi ]
  339. test bl , bl
  340. jz transp_pixel
  341. mov [ edi ] , bl
  342. transp_pixel:
  343. inc esi
  344. inc edi
  345. ENDM
  346. ??transp_reference:
  347. dec ecx
  348. jge ??forward_trans_line
  349. add esi , [ scr_ajust_width ]
  350. add edi , [ dest_ajust_width ]
  351. dec edx
  352. jnz ??forward_loop_trans
  353. ret
  354. ENDIF
  355. ??real_out:
  356. ret
  357. ENDP Vesa_Blit_To_Linear
  358. END