1 ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
2 ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
3 ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
4 ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
5 ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
6 ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
7 ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
8 ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
9 ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
10 ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
13 ; Linear, lighted texture mapper inner loop.
19 global _asm_tmap_scanline_lin_lighted
20 global asm_tmap_scanline_lin_lighted
24 %include "tmap_inc.asm"
36 ; --------------------------------------------------------------------------------------------------
38 ; _xleft fixed point left x coordinate
39 ; _xright fixed point right x coordinate
40 ; _y fixed point y coordinate
41 ; _pixptr address of source pixel map
42 ; _u fixed point initial u coordinate
43 ; _v fixed point initial v coordinate
44 ; _du_dx fixed point du/dx
45 ; _dv_dx fixed point dv/dx
47 ; for (x = (int) xleft; x <= (int) xright; x++) {
48 ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
57 _asm_tmap_scanline_lin_lighted:
58 asm_tmap_scanline_lin_lighted:
59 ; push es ; DPH: No selectors in windows :-(
63 ; mov es,[_pixel_data_selector] ; selector[0*2] ; DPH: No... :-)
64 ; mov fs,[_gr_fade_table_selector] ; selector[1*2] ; fs = bmd_fade_table
66 ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
67 ; esi source pixel pointer = pixptr
68 ; edi initial row pointer = y*320+x
70 ; set esi = pointer to start of texture map data
73 ; set edi = address of first pixel to modify
74 mov edi,[_fx_y] ; this is actually an int
75 cmp edi,[_window_bottom]
78 imul edi,[_bytes_per_row]
85 add edi,[_write_buffer]
87 ; set _loop_count = # of iterations
89 cmp eax,[_window_right]
91 mov eax,[_window_right]
92 eax_ok1: cmp eax,[_window_left]
94 mov eax,[_window_left]
99 cmp eax,[_window_width]
101 mov eax,[_window_width]
103 mov [_loop_count],eax
105 ; edi destination pixel pointer
108 mov ecx,_gr_fade_table ;originally offset _lighting_tables
109 mov eax,[_fx_u] ; get 32 bit u coordinate
110 shr eax,6 ; get 6:10 int:frac u coordinate into low word
111 mov ebp,[_fx_v] ; get 32 bit v coordinate
112 shl ebp,10 ; put 6:10 int:frac into high word
113 mov bp,ax ; put u coordinate in low word
115 mov eax,[_fx_du_dx] ; get 32 bit delta u
116 shr eax,6 ; get 6:10 int:frac delta u into low word
117 mov edx,[_fx_dv_dx] ; get 32 bit delta v
118 shl edx,10 ; put 6:10 int:frac into high word
119 mov dx,ax ; put delta u in low word
121 sar dword [_fx_dl_dx],8
123 inc dword [_fx_dl_dx] ; round towards 0 for negative deltas
127 ; do dithering, use lighting values which are .5 less than and .5 more than actual value
128 mov ebx,80h ; assume dithering on
129 test dword [_dither_intensity_lighting],-1
131 sub ebx,ebx ; no dithering
134 add eax,ebx ; add 1/2
143 xchg eax,[_fx_dl_dx1]
144 dith_1: mov [_fx_dl_dx2],eax
149 ; lighting values are passed in fixed point, but need to be in 8 bit integer, 8 bit fraction so we can easily
150 ; get the integer by reading %bh
153 test dword [_Transparency_on],-1
154 jne do_transparency_ll
156 ;; esi, ecx should be free
157 loop_test equ 1 ; set to 1 to run as loop for better profiling
161 mov ecx,[_loop_count]
170 mov eax,ebp ; get u, v
171 shr eax,26 ; shift out all but int(v)
172 shld ax,bp,6 ; shift in u, shifting up v
174 add ebp,edx ; u += du, v += dv
176 add eax,[_pixptr] ; DPH: No selectors in windows
177 movzx eax,byte [eax] ; get pixel from source bitmap
178 mov ah,bh ; get lighting table
179 add ebx,esi ; _fx_dl_dx ; update lighting value
180 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
181 mov [edi],al ; write pixel...
182 inc edi ; ...and advance
186 mov eax,ebp ; get u, v
187 shr eax,26 ; shift out all but int(v)
188 shld ax,bp,6 ; shift in u, shifting up v
190 add ebp,edx ; u += du, v += dv
192 add eax,[_pixptr] ; DPH:
193 movzx eax,byte [eax] ; get pixel from source bitmap
194 mov ah,bh ; get lighting table
195 add ebx,esi ; _fx_dl_dx ; update lighting value
196 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
197 mov [edi],al ; write pixel...
198 inc edi ; ...and advance
200 dec ecx ; _loop_count
206 one_more_pix: mov eax,ebp ; get u, v
207 shr eax,26 ; shift out all but int(v)
208 shld ax,bp,6 ; shift in u, shifting up v
210 add eax,[_pixptr] ; DPH:
211 movzx eax,byte [eax] ; get pixel from source bitmap
212 mov ah,bh ; get lighting table
213 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
214 mov [edi],al ; write pixel...
227 ; ecx _lighting_tables
228 ; edx du, dv 6:10:6:10
229 ; ebp u, v coordinates 6:10:6:10
230 ; esi pointer to source bitmap
233 ;_size = (_end1 - _start1)/num_iters
234 ; note: if eax is odd, you will not be writing the last pixel, you must clean up at the end
236 mov eax,[_loop_count]
242 sub eax,[_loop_count]
245 imul eax,eax,(_end1 - _start1)/num_iters
246 add eax,_start1 ;originally offset _start1
255 ; ecx _lighting_tables
256 ; edx du, dv 6:10:6:10
257 ; ebp u, v coordinates 6:10:6:10
258 ; esi pointer to source bitmap
261 ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
265 ;**; inner loop if lighting value is constant
266 ;**; can be optimized if source bitmap pixels are stored as words, then the mov ah,bh is not necessary
267 ;** mov eax,ebp ; get u, v
268 ;** shr eax,26 ; shift out all but int(v)
269 ;** shld ax,bp,6 ; shift in u, shifting up v
271 ;** add ebp,edx ; u += du, v += dv
273 ;** mov al,[esi+eax] ; get pixel from source bitmap
274 ;** mov ah,bh ; get lighting table
275 ;** mov al,[ecx+eax] ; xlat pixel through lighting tables
276 ;** mov [edi],al ; write pixel...
277 ;** inc edi ; ...and advance
283 ; loop contains two iterations which must be the same length
284 mov eax,ebp ; get u, v
285 shr eax,26 ; shift out all but int(v)
286 shld ax,bp,6 ; shift in u, shifting up v
288 add ebp,edx ; u += du, v += dv
290 mov al,[esi+eax] ; get pixel from source bitmap
291 mov ah,bh ; get lighting table
292 add ebx,[_fx_dl_dx1] ; update lighting value
293 mov al,[ecx+eax] ; xlat pixel through lighting tables
294 mov [edi],al ; write pixel...
295 inc edi ; ...and advance
298 mov eax,ebp ; get u, v
299 shr eax,26 ; shift out all but int(v)
300 shld ax,bp,6 ; shift in u, shifting up v
302 add ebp,edx ; u += du, v += dv
304 mov al,[esi+eax] ; get pixel from source bitmap
305 mov ah,bh ; get lighting table
306 add ebx,[_fx_dl_dx2] ; update lighting value
307 mov al,[ecx+eax] ; xlat pixel through lighting tables
308 mov [edi],al ; write pixel...
309 inc edi ; ...and advance
311 mov eax,ebp ; get u, v
312 shr eax,26 ; shift out all but int(v)
313 shld ax,bp,6 ; shift in u, shifting up v
315 add ebp,edx ; u += du, v += dv
317 mov al,[esi+eax] ; get pixel from source bitmap
318 mov ah,bh ; get lighting table
319 add ebx,[_fx_dl_dx] ; update lighting value
320 mov al,[ecx+eax] ; xlat pixel through lighting tables
321 mov [edi],al ; write pixel...
322 inc edi ; ...and advance
328 ;obsolete: ; version which assumes segment overrides are in place (which they are obviously not)
329 ;obsolete: mov eax,ebp ; get u, v
330 ;obsolete: shr eax,26 ; shift out all but int(v)
331 ;obsolete: shld ax,bp,6 ; shift in u, shifting up v
333 ;obsolete: add ebp,edx ; u += du, v += dv
335 ;obsolete: mov al,[eax] ; get pixel from source bitmap
336 ;obsolete: mov ah,bh ; get lighting table
337 ;obsolete: add ebx,esi ; update lighting value
338 ;obsolete: mov al,[eax] ; xlat pixel through lighting tables
339 ;obsolete: mov [edi],al ; write pixel...
340 ;obsolete: inc edi ; ...and advance
346 ; now do the leftover pixel
348 shr eax,26 ; shift in v coordinate
349 shld ax,bp,6 ; shift in u coordinate while shifting up v coordinate
350 mov al,[esi+eax] ; get pixel from source bitmap
351 mov ah,bh ; get lighting table
356 mov al,[_gr_fade_table+eax] ; xlat pixel through lighting tables
357 mov [edi],al ; write pixel...
365 ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
366 ; suitable for inverse color lookup
369 ;**; rrrrrfffffrrrrrfffffxxbbbbbfffff
370 ;** mov eax,11111001001010101110101101110111b
371 ;** and eax,11111000001111100000001111100000b
376 ;; esi, ecx should be free
380 mov ecx,[_loop_count]
389 mov eax,ebp ; get u, v
390 shr eax,26 ; shift out all but int(v)
391 shld ax,bp,6 ; shift in u, shifting up v
393 add ebp,edx ; u += du, v += dv
395 add eax,[_pixptr] ; DPH:
396 movzx eax,byte [eax] ; get pixel from source bitmap
399 mov ah,bh ; get lighting table
400 add ebx,esi ; _fx_dl_dx ; update lighting value
401 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
402 mov [edi],al ; write pixel...
403 skip1a: inc edi ; ...and advance
407 mov eax,ebp ; get u, v
408 shr eax,26 ; shift out all but int(v)
409 shld ax,bp,6 ; shift in u, shifting up v
411 add ebp,edx ; u += du, v += dv
413 add eax,[_pixptr] ; DPH:
414 movzx eax,byte [eax] ; get pixel from source bitmap
417 mov ah,bh ; get lighting table
418 add ebx,esi ; _fx_dl_dx ; update lighting value
419 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
420 mov [edi],al ; write pixel...
421 skip2a: inc edi ; ...and advance
423 dec ecx ; _loop_count
429 one_more_pix2: mov eax,ebp ; get u, v
430 shr eax,26 ; shift out all but int(v)
431 shld ax,bp,6 ; shift in u, shifting up v
433 add eax,[_pixptr] ; DPH:
434 movzx eax,byte [eax] ; get pixel from source bitmap
437 mov ah,bh ; get lighting table
438 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
439 mov [edi],al ; write pixel...