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.
12 ; $Source: /cvs/cvsroot/d2x/texmap/tmap_ll.asm,v $
13 ; $Revision: 1.1.1.1 $
15 ; $Date: 2001-01-19 03:30:16 $
17 ; Linear, lighted texture mapper inner loop.
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.1.1.1 1999/06/14 22:13:55 donut
21 ; Import of d1x 1.37 source.
23 ; Revision 1.10 1995/02/20 18:22:54 john
24 ; Put all the externs in the assembly modules into tmap_inc.asm.
25 ; Also, moved all the C versions of the inner loops into a new module,
28 ; Revision 1.9 1995/02/20 17:09:06 john
29 ; Added code so that you can build the tmapper with no assembly!
31 ; Revision 1.8 1994/11/19 23:52:56 mike
32 ; rip out big unrolled loop to save 25K....remember when we cared more about speed?
34 ; Revision 1.7 1994/11/12 16:39:41 mike
37 ; Revision 1.6 1994/03/14 15:45:08 mike
40 ; Revision 1.5 1994/01/24 13:13:12 mike
43 ; Revision 1.4 1994/01/14 14:02:47 mike
44 ; *** empty log message ***
46 ; Revision 1.3 1993/12/17 20:00:16 mike
47 ; Change default setting of dither_intensity_lighting from 1 to 0
49 ; Revision 1.2 1993/11/22 10:24:50 mike
50 ; *** empty log message ***
52 ; Revision 1.1 1993/09/08 17:29:52 mike
60 global _asm_tmap_scanline_lin_lighted
61 global asm_tmap_scanline_lin_lighted
65 %include "tmap_inc.asm"
77 ; --------------------------------------------------------------------------------------------------
79 ; _xleft fixed point left x coordinate
80 ; _xright fixed point right x coordinate
81 ; _y fixed point y coordinate
82 ; _pixptr address of source pixel map
83 ; _u fixed point initial u coordinate
84 ; _v fixed point initial v coordinate
85 ; _du_dx fixed point du/dx
86 ; _dv_dx fixed point dv/dx
88 ; for (x = (int) xleft; x <= (int) xright; x++) {
89 ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
98 _asm_tmap_scanline_lin_lighted:
99 asm_tmap_scanline_lin_lighted:
100 ; push es ; DPH: No selectors in windows :-(
104 ; mov es,[_pixel_data_selector] ; selector[0*2] ; DPH: No... :-)
105 ; mov fs,[_gr_fade_table_selector] ; selector[1*2] ; fs = bmd_fade_table
107 ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
108 ; esi source pixel pointer = pixptr
109 ; edi initial row pointer = y*320+x
111 ; set esi = pointer to start of texture map data
114 ; set edi = address of first pixel to modify
115 mov edi,[_fx_y] ; this is actually an int
116 cmp edi,[_window_bottom]
119 imul edi,[_bytes_per_row]
126 add edi,[_write_buffer]
128 ; set _loop_count = # of iterations
130 cmp eax,[_window_right]
132 mov eax,[_window_right]
133 eax_ok1: cmp eax,[_window_left]
135 mov eax,[_window_left]
140 cmp eax,[_window_width]
142 mov eax,[_window_width]
144 mov [_loop_count],eax
146 ; edi destination pixel pointer
149 mov ecx,_gr_fade_table ;originally offset _lighting_tables
150 mov eax,[_fx_u] ; get 32 bit u coordinate
151 shr eax,6 ; get 6:10 int:frac u coordinate into low word
152 mov ebp,[_fx_v] ; get 32 bit v coordinate
153 shl ebp,10 ; put 6:10 int:frac into high word
154 mov bp,ax ; put u coordinate in low word
156 mov eax,[_fx_du_dx] ; get 32 bit delta u
157 shr eax,6 ; get 6:10 int:frac delta u into low word
158 mov edx,[_fx_dv_dx] ; get 32 bit delta v
159 shl edx,10 ; put 6:10 int:frac into high word
160 mov dx,ax ; put delta u in low word
162 sar dword [_fx_dl_dx],8
164 inc dword [_fx_dl_dx] ; round towards 0 for negative deltas
168 ; do dithering, use lighting values which are .5 less than and .5 more than actual value
169 mov ebx,80h ; assume dithering on
170 test dword [_dither_intensity_lighting],-1
172 sub ebx,ebx ; no dithering
175 add eax,ebx ; add 1/2
184 xchg eax,[_fx_dl_dx1]
185 dith_1: mov [_fx_dl_dx2],eax
190 ; lighting values are passed in fixed point, but need to be in 8 bit integer, 8 bit fraction so we can easily
191 ; get the integer by reading %bh
194 test dword [_Transparency_on],-1
195 jne do_transparency_ll
197 ;; esi, ecx should be free
198 loop_test equ 1 ; set to 1 to run as loop for better profiling
202 mov ecx,[_loop_count]
211 mov eax,ebp ; get u, v
212 shr eax,26 ; shift out all but int(v)
213 shld ax,bp,6 ; shift in u, shifting up v
215 add ebp,edx ; u += du, v += dv
217 add eax,[_pixptr] ; DPH: No selectors in windows
218 movzx eax,byte [eax] ; get pixel from source bitmap
219 mov ah,bh ; get lighting table
220 add ebx,esi ; _fx_dl_dx ; update lighting value
221 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
222 mov [edi],al ; write pixel...
223 inc edi ; ...and advance
227 mov eax,ebp ; get u, v
228 shr eax,26 ; shift out all but int(v)
229 shld ax,bp,6 ; shift in u, shifting up v
231 add ebp,edx ; u += du, v += dv
233 add eax,[_pixptr] ; DPH:
234 movzx eax,byte [eax] ; get pixel from source bitmap
235 mov ah,bh ; get lighting table
236 add ebx,esi ; _fx_dl_dx ; update lighting value
237 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
238 mov [edi],al ; write pixel...
239 inc edi ; ...and advance
241 dec ecx ; _loop_count
247 one_more_pix: mov eax,ebp ; get u, v
248 shr eax,26 ; shift out all but int(v)
249 shld ax,bp,6 ; shift in u, shifting up v
251 add eax,[_pixptr] ; DPH:
252 movzx eax,byte [eax] ; get pixel from source bitmap
253 mov ah,bh ; get lighting table
254 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
255 mov [edi],al ; write pixel...
268 ; ecx _lighting_tables
269 ; edx du, dv 6:10:6:10
270 ; ebp u, v coordinates 6:10:6:10
271 ; esi pointer to source bitmap
274 ;_size = (_end1 - _start1)/num_iters
275 ; note: if eax is odd, you will not be writing the last pixel, you must clean up at the end
277 mov eax,[_loop_count]
283 sub eax,[_loop_count]
286 imul eax,eax,(_end1 - _start1)/num_iters
287 add eax,_start1 ;originally offset _start1
296 ; ecx _lighting_tables
297 ; edx du, dv 6:10:6:10
298 ; ebp u, v coordinates 6:10:6:10
299 ; esi pointer to source bitmap
302 ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
306 ;**; inner loop if lighting value is constant
307 ;**; can be optimized if source bitmap pixels are stored as words, then the mov ah,bh is not necessary
308 ;** mov eax,ebp ; get u, v
309 ;** shr eax,26 ; shift out all but int(v)
310 ;** shld ax,bp,6 ; shift in u, shifting up v
312 ;** add ebp,edx ; u += du, v += dv
314 ;** mov al,[esi+eax] ; get pixel from source bitmap
315 ;** mov ah,bh ; get lighting table
316 ;** mov al,[ecx+eax] ; xlat pixel through lighting tables
317 ;** mov [edi],al ; write pixel...
318 ;** inc edi ; ...and advance
324 ; loop contains two iterations which must be the same length
325 mov eax,ebp ; get u, v
326 shr eax,26 ; shift out all but int(v)
327 shld ax,bp,6 ; shift in u, shifting up v
329 add ebp,edx ; u += du, v += dv
331 mov al,[esi+eax] ; get pixel from source bitmap
332 mov ah,bh ; get lighting table
333 add ebx,[_fx_dl_dx1] ; update lighting value
334 mov al,[ecx+eax] ; xlat pixel through lighting tables
335 mov [edi],al ; write pixel...
336 inc edi ; ...and advance
339 mov eax,ebp ; get u, v
340 shr eax,26 ; shift out all but int(v)
341 shld ax,bp,6 ; shift in u, shifting up v
343 add ebp,edx ; u += du, v += dv
345 mov al,[esi+eax] ; get pixel from source bitmap
346 mov ah,bh ; get lighting table
347 add ebx,[_fx_dl_dx2] ; update lighting value
348 mov al,[ecx+eax] ; xlat pixel through lighting tables
349 mov [edi],al ; write pixel...
350 inc edi ; ...and advance
352 mov eax,ebp ; get u, v
353 shr eax,26 ; shift out all but int(v)
354 shld ax,bp,6 ; shift in u, shifting up v
356 add ebp,edx ; u += du, v += dv
358 mov al,[esi+eax] ; get pixel from source bitmap
359 mov ah,bh ; get lighting table
360 add ebx,[_fx_dl_dx] ; update lighting value
361 mov al,[ecx+eax] ; xlat pixel through lighting tables
362 mov [edi],al ; write pixel...
363 inc edi ; ...and advance
369 ;obsolete: ; version which assumes segment overrides are in place (which they are obviously not)
370 ;obsolete: mov eax,ebp ; get u, v
371 ;obsolete: shr eax,26 ; shift out all but int(v)
372 ;obsolete: shld ax,bp,6 ; shift in u, shifting up v
374 ;obsolete: add ebp,edx ; u += du, v += dv
376 ;obsolete: mov al,[eax] ; get pixel from source bitmap
377 ;obsolete: mov ah,bh ; get lighting table
378 ;obsolete: add ebx,esi ; update lighting value
379 ;obsolete: mov al,[eax] ; xlat pixel through lighting tables
380 ;obsolete: mov [edi],al ; write pixel...
381 ;obsolete: inc edi ; ...and advance
387 ; now do the leftover pixel
389 shr eax,26 ; shift in v coordinate
390 shld ax,bp,6 ; shift in u coordinate while shifting up v coordinate
391 mov al,[esi+eax] ; get pixel from source bitmap
392 mov ah,bh ; get lighting table
397 mov al,[_gr_fade_table+eax] ; xlat pixel through lighting tables
398 mov [edi],al ; write pixel...
406 ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
407 ; suitable for inverse color lookup
410 ;**; rrrrrfffffrrrrrfffffxxbbbbbfffff
411 ;** mov eax,11111001001010101110101101110111b
412 ;** and eax,11111000001111100000001111100000b
417 ;; esi, ecx should be free
421 mov ecx,[_loop_count]
430 mov eax,ebp ; get u, v
431 shr eax,26 ; shift out all but int(v)
432 shld ax,bp,6 ; shift in u, shifting up v
434 add ebp,edx ; u += du, v += dv
436 add eax,[_pixptr] ; DPH:
437 movzx eax,byte [eax] ; get pixel from source bitmap
440 mov ah,bh ; get lighting table
441 add ebx,esi ; _fx_dl_dx ; update lighting value
442 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
443 mov [edi],al ; write pixel...
444 skip1a: inc edi ; ...and advance
448 mov eax,ebp ; get u, v
449 shr eax,26 ; shift out all but int(v)
450 shld ax,bp,6 ; shift in u, shifting up v
452 add ebp,edx ; u += du, v += dv
454 add eax,[_pixptr] ; DPH:
455 movzx eax,byte [eax] ; get pixel from source bitmap
458 mov ah,bh ; get lighting table
459 add ebx,esi ; _fx_dl_dx ; update lighting value
460 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
461 mov [edi],al ; write pixel...
462 skip2a: inc edi ; ...and advance
464 dec ecx ; _loop_count
470 one_more_pix2: mov eax,ebp ; get u, v
471 shr eax,26 ; shift out all but int(v)
472 shld ax,bp,6 ; shift in u, shifting up v
474 add eax,[_pixptr] ; DPH:
475 movzx eax,byte [eax] ; get pixel from source bitmap
478 mov ah,bh ; get lighting table
479 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
480 mov [edi],al ; write pixel...