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