VTOBUFF.ASM 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 : TOBUFFER.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. ;* VVC::TOBUFFER -- Copies a virtual viewport to a linear buffer *
  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. ;* VIVC::TOBUFFER -- Copies a virtual viewport to a linear buffer *
  46. ;* *
  47. ;* INPUT: BYTE * dest - buffer to copy to *
  48. ;* size - size of the buffer to copy to *
  49. ;* x_pixel - x pixel on viewport to copy from *
  50. ;* y_pixel - y pixel on viewport to copy from *
  51. ;* pixel_width - the width of copy region *
  52. ;* pixel_height - the height of copy region *
  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. ;*=========================================================================*
  65. PROC Vesa_To_Buffer C near
  66. USES ebx,ecx,edx,esi,edi
  67. ;*===================================================================
  68. ;* define the arguements that our function takes.
  69. ;*===================================================================
  70. ARG this:DWORD ; this is a class member function
  71. ARG x_pixel:DWORD ; Page X pixel coordinate.
  72. ARG y_pixel:DWORD ; Page Y pixel coordinate.
  73. ARG pixel_width:DWORD ; Width of region in pixels.
  74. ARG pixel_height:DWORD ; Height of region in pixels.
  75. ARG dest:DWORD ; the buffer to copy to
  76. ARG size:DWORD ; the size of the buffer
  77. ;*===================================================================
  78. ; Define some locals so that we can handle things quickly
  79. ;*===================================================================
  80. LOCAL x1_pixel :dword
  81. LOCAL y1_pixel :dword
  82. LOCAL dest_x1 : dword
  83. LOCAL dest_y1 : dword
  84. LOCAL dest_ajust_width:DWORD
  85. LOCAL scr_ajust_width:DWORD
  86. LOCAL dest_area : dword
  87. ; Clip dest Rectangle against source Window boundaries.
  88. mov [ dest_x1 ] , 0
  89. mov [ dest_y1 ] , 0
  90. mov esi , [ this ] ; get ptr to dest
  91. xor ecx , ecx
  92. xor edx , edx
  93. mov edi , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  94. mov ebx , [ x_pixel ]
  95. mov eax , [ x_pixel ]
  96. add ebx , [ pixel_width ]
  97. shld ecx , eax , 1
  98. mov [ x1_pixel ] , ebx
  99. inc edi
  100. shld edx , ebx , 1
  101. sub eax , edi
  102. sub ebx , edi
  103. shld ecx , eax , 1
  104. shld edx , ebx , 1
  105. mov edi,[ ( VideoViewPort esi) . VIVPHeight ] ; get height into register
  106. mov ebx , [ y_pixel ]
  107. mov eax , [ y_pixel ]
  108. add ebx , [ pixel_height ]
  109. shld ecx , eax , 1
  110. mov [ y1_pixel ] , ebx
  111. inc edi
  112. shld edx , ebx , 1
  113. sub eax , edi
  114. sub ebx , edi
  115. shld ecx , eax , 1
  116. shld edx , ebx , 1
  117. xor cl , 5
  118. xor dl , 5
  119. mov al , cl
  120. test dl , cl
  121. jnz ??real_out
  122. or al , dl
  123. jz ??do_blit
  124. test cl , 1000b
  125. jz ??scr_left_ok
  126. mov eax , [ x_pixel ]
  127. neg eax
  128. mov [ x_pixel ] , 0
  129. mov [ dest_x1 ] , eax
  130. ??scr_left_ok:
  131. test cl , 0010b
  132. jz ??scr_bottom_ok
  133. mov eax , [ y_pixel ]
  134. neg eax
  135. mov [ y_pixel ] , 0
  136. mov [ dest_y1 ] , eax
  137. ??scr_bottom_ok:
  138. test dl , 0100b
  139. jz ??scr_right_ok
  140. mov eax , [ (VideoViewPort esi) . VIVPWidth ] ; get width into register
  141. mov [ x1_pixel ] , eax
  142. ??scr_right_ok:
  143. test dl , 0001b
  144. jz ??do_blit
  145. mov eax , [ (VideoViewPort esi) . VIVPHeight ] ; get width into register
  146. mov [ y1_pixel ] , eax
  147. ??do_blit:
  148. cld
  149. mov eax , [ (VideoViewPort esi) . VIVPXAdd ]
  150. add eax , [ (VideoViewPort esi) . VIVPWidth ]
  151. mov edi , [ (VideoViewPort esi) . VIVPOffset ]
  152. mov ecx , eax
  153. mul [ y_pixel ]
  154. add edi , [ x_pixel ]
  155. add edi , eax
  156. Call Vesa_Asm_Set_Win ; set the window
  157. mov esi , edi
  158. add ecx , [ x_pixel ]
  159. sub ecx , [ x1_pixel ]
  160. mov [ scr_ajust_width ] , ecx
  161. mov edi , [ dest ]
  162. mov eax , [ pixel_width ]
  163. sub eax , [ x1_pixel ]
  164. add eax , [ x_pixel ]
  165. mov [ dest_ajust_width ] , eax
  166. mov eax , [ dest_y1 ]
  167. mul [ pixel_width ]
  168. add eax , [ dest_x1 ]
  169. add edi , eax
  170. mov edx , [ y1_pixel ]
  171. sub edx , [ y_pixel ]
  172. jz ??real_out
  173. mov eax , [ x1_pixel ]
  174. sub eax , [ x_pixel ]
  175. jz ??real_out
  176. mov ebx , [ pixel_width ]
  177. imul ebx , edx
  178. cmp ebx , [ size ]
  179. jg ??real_out
  180. ; ********************************************************************
  181. ; Forward bitblit only
  182. IF TRANSP
  183. test [ trans ] , 1
  184. jnz ??forward_Blit_trans
  185. ENDIF
  186. ; the inner loop is so efficient that
  187. ; the optimal consept no longer apply because
  188. ; the optimal byte have to by a number greather than 9 bytes
  189. cmp eax , 10
  190. jl ??forward_loop_bytes
  191. ??forward_loop_dword:
  192. lea ebx , [ esi + eax ]
  193. add ebx , [ cpu_video_page ]
  194. cmp ebx , [ cpu_page_limit ]
  195. jl ??in_range
  196. xor ecx , ecx
  197. cmp esi , 0b0000h
  198. mov ebx , eax
  199. jge ??no_trailing
  200. mov ecx , 0b0000h
  201. sub ecx , esi
  202. sub ebx , ecx
  203. rep movsb
  204. ??no_trailing:
  205. add esi , [ cpu_video_page ]
  206. xchg edi , esi
  207. Call Vesa_Asm_Set_Win ; set the window
  208. xchg edi , esi
  209. mov ecx , ebx
  210. rep movsb
  211. add esi , [ scr_ajust_width ]
  212. add edi , [ dest_ajust_width ]
  213. dec edx ; decrement the height
  214. jnz ??forward_loop_dword
  215. ret
  216. ??in_range:
  217. mov ecx , edi
  218. mov ebx , eax
  219. neg ecx
  220. and ecx , 3
  221. sub ebx , ecx
  222. rep movsb
  223. mov ecx , ebx
  224. shr ecx , 2
  225. rep movsd
  226. mov ecx , ebx
  227. and ecx , 3
  228. rep movsb
  229. add esi , [ scr_ajust_width ]
  230. add edi , [ dest_ajust_width ]
  231. dec edx
  232. jnz ??forward_loop_dword
  233. ret
  234. ??forward_loop_bytes:
  235. lea ebx , [ esi + eax ]
  236. add ebx , [ cpu_video_page ]
  237. cmp ebx , [ cpu_page_limit ]
  238. mov ebx , eax
  239. jl ??in_range_bytes
  240. xor ecx , ecx
  241. cmp esi , 0b0000h
  242. jge ??no_trailing_bytes
  243. mov ecx , 0b0000h
  244. sub ecx , esi
  245. sub ebx , ecx
  246. rep movsb
  247. ??no_trailing_bytes:
  248. add esi , [ cpu_video_page ]
  249. xchg edi , esi
  250. Call Vesa_Asm_Set_Win ; set the window
  251. xchg edi , esi
  252. ??in_range_bytes:
  253. mov ecx , ebx
  254. rep movsb
  255. add esi , [ scr_ajust_width ]
  256. add edi , [ dest_ajust_width ]
  257. dec edx ; decrement the height
  258. jnz ??forward_loop_bytes
  259. ret
  260. IF TRANSP
  261. ??forward_Blit_trans:
  262. mov ecx , eax
  263. and ecx , 01fh
  264. lea ecx , [ ecx + ecx * 4 ]
  265. neg ecx
  266. shr eax , 5
  267. lea ecx , [ ??transp_reference + ecx * 2 ]
  268. mov [ y1_pixel ] , ecx
  269. ??forward_loop_trans:
  270. mov ecx , eax
  271. jmp [ y1_pixel ]
  272. ??forward_trans_line:
  273. REPT 32
  274. local transp_pixel
  275. mov bl , [ esi ]
  276. test bl , bl
  277. jz transp_pixel
  278. mov [ edi ] , bl
  279. transp_pixel:
  280. inc esi
  281. inc edi
  282. ENDM
  283. ??transp_reference:
  284. dec ecx
  285. jge ??forward_trans_line
  286. add esi , [ scr_ajust_width ]
  287. add edi , [ dest_ajust_width ]
  288. dec edx
  289. jnz ??forward_loop_trans
  290. ret
  291. ENDIF
  292. ??real_out:
  293. ret
  294. ENDP Vesa_To_Buffer
  295. END