TOBUFF.ASM 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. ;
  2. ; Copyright 2020 Electronic Arts Inc.
  3. ;
  4. ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. ; software: you can redistribute it and/or modify it under the terms of
  6. ; the GNU General Public License as published by the Free Software Foundation,
  7. ; either version 3 of the License, or (at your option) any later version.
  8. ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. ; in the hope that it will be useful, but with permitted additional restrictions
  10. ; under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. ; distributed with this program. You should have received a copy of the
  12. ; GNU General Public License along with permitted additional restrictions
  13. ; with this program. If not, see [https://github.com/electronicarts/CnC_Remastered_Collection]>.
  14. ;***************************************************************************
  15. ;** 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 **
  16. ;***************************************************************************
  17. ;* *
  18. ;* Project Name : Westwood 32 bit Library *
  19. ;* *
  20. ;* File Name : TOBUFFER.ASM *
  21. ;* *
  22. ;* Programmer : Phil W. Gorrow *
  23. ;* *
  24. ;* Start Date : June 8, 1994 *
  25. ;* Last Update : Feb 10, 1995 [jrj] *
  26. ;* *
  27. ;*-------------------------------------------------------------------------*
  28. ;* Functions: *
  29. ;* VVC::TOBUFFER -- Copies a virtual viewport to a linear buffer *
  30. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  31. ;IDEAL
  32. ;P386
  33. ;MODEL USE32 FLAT
  34. ;LOCALS ??
  35. .model flat
  36. TRANSP equ 0
  37. ;INCLUDE "drawbuff.inc"
  38. INCLUDE gbuffer.inc
  39. ;CODESEG
  40. .code
  41. ;***************************************************************************
  42. ;* VIVC::TOBUFFER -- Copies a virtual viewport to a linear buffer *
  43. ;* *
  44. ;* INPUT: BYTE * dest - buffer to copy to *
  45. ;* size - size of the buffer to copy to *
  46. ;* x_pixel - x pixel on viewport to copy from *
  47. ;* y_pixel - y pixel on viewport to copy from *
  48. ;* pixel_width - the width of copy region *
  49. ;* pixel_height - the height of copy region *
  50. ;* *
  51. ;* OUTPUT: none *
  52. ;* *
  53. ;* WARNINGS: Coordinates and dimensions will be adjusted if they exceed *
  54. ;* the boundaries. In the event that no adjustment is *
  55. ;* possible this routine will abort. If the size of the *
  56. ;* region to copy exceeds the size passed in for the buffer *
  57. ;* the routine will automatically abort. *
  58. ;* *
  59. ;* HISTORY: *
  60. ;* 06/15/1994 PWG : Created. *
  61. ;*=========================================================================*
  62. Buffer_To_Buffer proc C public USES ebx ecx edx esi edi this_object:DWORD, x_pixel:DWORD, y_pixel:DWORD, pixel_width:DWORD, pixel_height:DWORD, dest:DWORD, buffer_size:DWORD
  63. ;PROC Buffer_To_Buffer C near
  64. ;USES ebx,ecx,edx,esi,edi
  65. ;*===================================================================
  66. ;* define the arguements that our function takes.
  67. ;*===================================================================
  68. ;ARG this_object:DWORD ; this is a class member function
  69. ;ARG x_pixel:DWORD ; Page X pixel coordinate.
  70. ;ARG y_pixel:DWORD ; Page Y pixel coordinate.
  71. ;ARG pixel_width:DWORD ; Width of region in pixels.
  72. ;ARG pixel_height:DWORD ; Height of region in pixels.
  73. ;ARG dest:DWORD ; the buffer to copy to
  74. ;ARG buffer_size:DWORD ; the size of the buffer
  75. ;*===================================================================
  76. ; Define some locals so that we can handle things quickly
  77. ;*===================================================================
  78. LOCAL x1_pixel :dword
  79. LOCAL y1_pixel :dword
  80. LOCAL dest_x1 : dword
  81. LOCAL dest_y1 : dword
  82. LOCAL dest_ajust_width:DWORD
  83. LOCAL scr_ajust_width:DWORD
  84. ;LOCAL dest_area : dword
  85. ; Clip dest Rectangle against source Window boundaries.
  86. mov [ dest_x1 ] , 0
  87. mov [ dest_y1 ] , 0
  88. mov esi , [ this_object ] ; get ptr to dest
  89. xor ecx , ecx
  90. xor edx , edx
  91. mov edi , [esi].GraphicViewPort.GVPWidth ; get width into register
  92. mov ebx , [ x_pixel ]
  93. mov eax , [ x_pixel ]
  94. add ebx , [ pixel_width ]
  95. shld ecx , eax , 1
  96. mov [ x1_pixel ] , ebx
  97. inc edi
  98. shld edx , ebx , 1
  99. sub eax , edi
  100. sub ebx , edi
  101. shld ecx , eax , 1
  102. shld edx , ebx , 1
  103. mov edi,[esi].GraphicViewPort.GVPHeight ; get height into register
  104. mov ebx , [ y_pixel ]
  105. mov eax , [ y_pixel ]
  106. add ebx , [ pixel_height ]
  107. shld ecx , eax , 1
  108. mov [ y1_pixel ] , ebx
  109. inc edi
  110. shld edx , ebx , 1
  111. sub eax , edi
  112. sub ebx , edi
  113. shld ecx , eax , 1
  114. shld edx , ebx , 1
  115. xor cl , 5
  116. xor dl , 5
  117. mov al , cl
  118. test dl , cl
  119. jnz real_out
  120. or al , dl
  121. jz do_blit
  122. test cl , 1000b
  123. jz scr_left_ok
  124. mov eax , [ x_pixel ]
  125. neg eax
  126. mov [ x_pixel ] , 0
  127. mov [ dest_x1 ] , eax
  128. scr_left_ok:
  129. test cl , 0010b
  130. jz scr_bottom_ok
  131. mov eax , [ y_pixel ]
  132. neg eax
  133. mov [ y_pixel ] , 0
  134. mov [ dest_y1 ] , eax
  135. scr_bottom_ok:
  136. test dl , 0100b
  137. jz scr_right_ok
  138. mov eax , [esi].GraphicViewPort.GVPWidth ; get width into register
  139. mov [ x1_pixel ] , eax
  140. scr_right_ok:
  141. test dl , 0001b
  142. jz do_blit
  143. mov eax , [esi].GraphicViewPort.GVPHeight ; get width into register
  144. mov [ y1_pixel ] , eax
  145. do_blit:
  146. cld
  147. mov eax , [esi].GraphicViewPort.GVPXAdd
  148. add eax , [esi].GraphicViewPort.GVPWidth
  149. add eax , [esi].GraphicViewPort.GVPPitch
  150. mov esi , [esi].GraphicViewPort.GVPOffset
  151. mov ecx , eax
  152. mul [ y_pixel ]
  153. add esi , [ x_pixel ]
  154. add esi , eax
  155. add ecx , [ x_pixel ]
  156. sub ecx , [ x1_pixel ]
  157. mov [ scr_ajust_width ] , ecx
  158. mov edi , [ dest ]
  159. mov eax , [ pixel_width ]
  160. sub eax , [ x1_pixel ]
  161. add eax , [ x_pixel ]
  162. mov [ dest_ajust_width ] , eax
  163. mov eax , [ dest_y1 ]
  164. mul [ pixel_width ]
  165. add eax , [ dest_x1 ]
  166. add edi , eax
  167. mov edx , [ y1_pixel ]
  168. mov eax , [ x1_pixel ]
  169. sub edx , [ y_pixel ]
  170. jle real_out
  171. sub eax , [ x_pixel ]
  172. jle real_out
  173. mov ebx , [ pixel_width ]
  174. imul ebx , edx
  175. cmp ebx , [ buffer_size ]
  176. jg real_out
  177. ; ********************************************************************
  178. ; Forward bitblit only
  179. IF TRANSP
  180. cmp [ transp ] , 0
  181. jnz forward_Blit_trans
  182. ENDIF
  183. ; the inner loop is so efficient that
  184. ; the optimal consept no longer apply because
  185. ; the optimal byte have to by a number greather than 9 bytes
  186. cmp eax , 10
  187. jl forward_loop_bytes
  188. forward_loop_dword:
  189. mov ecx , edi
  190. mov ebx , eax
  191. neg ecx
  192. and ecx , 3
  193. sub ebx , ecx
  194. rep movsb
  195. mov ecx , ebx
  196. shr ecx , 2
  197. rep movsd
  198. mov ecx , ebx
  199. and ecx , 3
  200. rep movsb
  201. add esi , [ scr_ajust_width ]
  202. add edi , [ dest_ajust_width ]
  203. dec edx
  204. jnz forward_loop_dword
  205. ret
  206. forward_loop_bytes:
  207. mov ecx , eax
  208. rep movsb
  209. add esi , [ scr_ajust_width ]
  210. add edi , [ dest_ajust_width ]
  211. dec edx ; decrement the height
  212. jnz forward_loop_bytes
  213. ret
  214. IF TRANSP
  215. forward_Blit_trans:
  216. mov ecx , eax
  217. and ecx , 01fh
  218. lea ecx , [ ecx + ecx * 4 ]
  219. neg ecx
  220. shr eax , 5
  221. lea ecx , [ transp_reference + ecx * 2 ]
  222. mov [ y1_pixel ] , ecx
  223. forward_loop_trans:
  224. mov ecx , eax
  225. jmp [ y1_pixel ]
  226. forward_trans_line:
  227. REPT 32
  228. local transp_pixel
  229. mov bl , [ esi ]
  230. test bl , bl
  231. jz transp_pixel
  232. mov [ edi ] , bl
  233. transp_pixel:
  234. inc esi
  235. inc edi
  236. ENDM
  237. transp_reference:
  238. dec ecx
  239. jge forward_trans_line
  240. add esi , [ scr_ajust_width ]
  241. add edi , [ dest_ajust_width ]
  242. dec edx
  243. jnz forward_loop_trans
  244. ret
  245. ENDIF
  246. real_out:
  247. ret
  248. ;ENDP Buffer_To_Buffer
  249. Buffer_To_Buffer endp
  250. END