1 ; $Id: tmap_ll.asm,v 1.2 2003-02-18 20:15:48 btb Exp $
2 ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
14 ; Linear, lighted texture mapper inner loop.
17 ; Revision 1.10 1995/02/20 18:22:54 john
18 ; Put all the externs in the assembly modules into tmap_inc.asm.
19 ; Also, moved all the C versions of the inner loops into a new module,
22 ; Revision 1.9 1995/02/20 17:09:06 john
23 ; Added code so that you can build the tmapper with no assembly!
25 ; Revision 1.8 1994/11/19 23:52:56 mike
26 ; rip out big unrolled loop to save 25K....remember when we cared more about speed?
28 ; Revision 1.7 1994/11/12 16:39:41 mike
31 ; Revision 1.6 1994/03/14 15:45:08 mike
34 ; Revision 1.5 1994/01/24 13:13:12 mike
37 ; Revision 1.4 1994/01/14 14:02:47 mike
38 ; *** empty log message ***
40 ; Revision 1.3 1993/12/17 20:00:16 mike
41 ; Change default setting of dither_intensity_lighting from 1 to 0
43 ; Revision 1.2 1993/11/22 10:24:50 mike
44 ; *** empty log message ***
46 ; Revision 1.1 1993/09/08 17:29:52 mike
54 global _asm_tmap_scanline_lin_lighted
55 global asm_tmap_scanline_lin_lighted
59 %include "tmap_inc.asm"
71 ; --------------------------------------------------------------------------------------------------
73 ; _xleft fixed point left x coordinate
74 ; _xright fixed point right x coordinate
75 ; _y fixed point y coordinate
76 ; _pixptr address of source pixel map
77 ; _u fixed point initial u coordinate
78 ; _v fixed point initial v coordinate
79 ; _du_dx fixed point du/dx
80 ; _dv_dx fixed point dv/dx
82 ; for (x = (int) xleft; x <= (int) xright; x++) {
83 ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
92 _asm_tmap_scanline_lin_lighted:
93 asm_tmap_scanline_lin_lighted:
94 ; push es ; DPH: No selectors in windows :-(
98 ; mov es,[_pixel_data_selector] ; selector[0*2] ; DPH: No... :-)
99 ; mov fs,[_gr_fade_table_selector] ; selector[1*2] ; fs = bmd_fade_table
101 ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
102 ; esi source pixel pointer = pixptr
103 ; edi initial row pointer = y*320+x
105 ; set esi = pointer to start of texture map data
108 ; set edi = address of first pixel to modify
109 mov edi,[_fx_y] ; this is actually an int
110 cmp edi,[_window_bottom]
113 imul edi,[_bytes_per_row]
120 add edi,[_write_buffer]
122 ; set _loop_count = # of iterations
124 cmp eax,[_window_right]
126 mov eax,[_window_right]
127 eax_ok1: cmp eax,[_window_left]
129 mov eax,[_window_left]
134 cmp eax,[_window_width]
136 mov eax,[_window_width]
138 mov [_loop_count],eax
140 ; edi destination pixel pointer
143 mov ecx,_gr_fade_table ;originally offset _lighting_tables
144 mov eax,[_fx_u] ; get 32 bit u coordinate
145 shr eax,6 ; get 6:10 int:frac u coordinate into low word
146 mov ebp,[_fx_v] ; get 32 bit v coordinate
147 shl ebp,10 ; put 6:10 int:frac into high word
148 mov bp,ax ; put u coordinate in low word
150 mov eax,[_fx_du_dx] ; get 32 bit delta u
151 shr eax,6 ; get 6:10 int:frac delta u into low word
152 mov edx,[_fx_dv_dx] ; get 32 bit delta v
153 shl edx,10 ; put 6:10 int:frac into high word
154 mov dx,ax ; put delta u in low word
156 sar dword [_fx_dl_dx],8
158 inc dword [_fx_dl_dx] ; round towards 0 for negative deltas
162 ; do dithering, use lighting values which are .5 less than and .5 more than actual value
163 mov ebx,80h ; assume dithering on
164 test dword [_dither_intensity_lighting],-1
166 sub ebx,ebx ; no dithering
169 add eax,ebx ; add 1/2
178 xchg eax,[_fx_dl_dx1]
179 dith_1: mov [_fx_dl_dx2],eax
184 ; lighting values are passed in fixed point, but need to be in 8 bit integer, 8 bit fraction so we can easily
185 ; get the integer by reading %bh
188 test dword [_Transparency_on],-1
189 jne do_transparency_ll
191 ;; esi, ecx should be free
192 loop_test equ 1 ; set to 1 to run as loop for better profiling
196 mov ecx,[_loop_count]
205 mov eax,ebp ; get u, v
206 shr eax,26 ; shift out all but int(v)
207 shld ax,bp,6 ; shift in u, shifting up v
209 add ebp,edx ; u += du, v += dv
211 add eax,[_pixptr] ; DPH: No selectors in windows
212 movzx eax,byte [eax] ; get pixel from source bitmap
213 mov ah,bh ; get lighting table
214 add ebx,esi ; _fx_dl_dx ; update lighting value
215 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
216 mov [edi],al ; write pixel...
217 inc edi ; ...and advance
221 mov eax,ebp ; get u, v
222 shr eax,26 ; shift out all but int(v)
223 shld ax,bp,6 ; shift in u, shifting up v
225 add ebp,edx ; u += du, v += dv
227 add eax,[_pixptr] ; DPH:
228 movzx eax,byte [eax] ; get pixel from source bitmap
229 mov ah,bh ; get lighting table
230 add ebx,esi ; _fx_dl_dx ; update lighting value
231 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
232 mov [edi],al ; write pixel...
233 inc edi ; ...and advance
235 dec ecx ; _loop_count
241 one_more_pix: mov eax,ebp ; get u, v
242 shr eax,26 ; shift out all but int(v)
243 shld ax,bp,6 ; shift in u, shifting up v
245 add eax,[_pixptr] ; DPH:
246 movzx eax,byte [eax] ; get pixel from source bitmap
247 mov ah,bh ; get lighting table
248 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
249 mov [edi],al ; write pixel...
262 ; ecx _lighting_tables
263 ; edx du, dv 6:10:6:10
264 ; ebp u, v coordinates 6:10:6:10
265 ; esi pointer to source bitmap
268 ;_size = (_end1 - _start1)/num_iters
269 ; note: if eax is odd, you will not be writing the last pixel, you must clean up at the end
271 mov eax,[_loop_count]
277 sub eax,[_loop_count]
280 imul eax,eax,(_end1 - _start1)/num_iters
281 add eax,_start1 ;originally offset _start1
290 ; ecx _lighting_tables
291 ; edx du, dv 6:10:6:10
292 ; ebp u, v coordinates 6:10:6:10
293 ; esi pointer to source bitmap
296 ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
300 ;**; inner loop if lighting value is constant
301 ;**; can be optimized if source bitmap pixels are stored as words, then the mov ah,bh is not necessary
302 ;** mov eax,ebp ; get u, v
303 ;** shr eax,26 ; shift out all but int(v)
304 ;** shld ax,bp,6 ; shift in u, shifting up v
306 ;** add ebp,edx ; u += du, v += dv
308 ;** mov al,[esi+eax] ; get pixel from source bitmap
309 ;** mov ah,bh ; get lighting table
310 ;** mov al,[ecx+eax] ; xlat pixel through lighting tables
311 ;** mov [edi],al ; write pixel...
312 ;** inc edi ; ...and advance
318 ; loop contains two iterations which must be the same length
319 mov eax,ebp ; get u, v
320 shr eax,26 ; shift out all but int(v)
321 shld ax,bp,6 ; shift in u, shifting up v
323 add ebp,edx ; u += du, v += dv
325 mov al,[esi+eax] ; get pixel from source bitmap
326 mov ah,bh ; get lighting table
327 add ebx,[_fx_dl_dx1] ; update lighting value
328 mov al,[ecx+eax] ; xlat pixel through lighting tables
329 mov [edi],al ; write pixel...
330 inc edi ; ...and advance
333 mov eax,ebp ; get u, v
334 shr eax,26 ; shift out all but int(v)
335 shld ax,bp,6 ; shift in u, shifting up v
337 add ebp,edx ; u += du, v += dv
339 mov al,[esi+eax] ; get pixel from source bitmap
340 mov ah,bh ; get lighting table
341 add ebx,[_fx_dl_dx2] ; update lighting value
342 mov al,[ecx+eax] ; xlat pixel through lighting tables
343 mov [edi],al ; write pixel...
344 inc edi ; ...and advance
346 mov eax,ebp ; get u, v
347 shr eax,26 ; shift out all but int(v)
348 shld ax,bp,6 ; shift in u, shifting up v
350 add ebp,edx ; u += du, v += dv
352 mov al,[esi+eax] ; get pixel from source bitmap
353 mov ah,bh ; get lighting table
354 add ebx,[_fx_dl_dx] ; update lighting value
355 mov al,[ecx+eax] ; xlat pixel through lighting tables
356 mov [edi],al ; write pixel...
357 inc edi ; ...and advance
363 ;obsolete: ; version which assumes segment overrides are in place (which they are obviously not)
364 ;obsolete: mov eax,ebp ; get u, v
365 ;obsolete: shr eax,26 ; shift out all but int(v)
366 ;obsolete: shld ax,bp,6 ; shift in u, shifting up v
368 ;obsolete: add ebp,edx ; u += du, v += dv
370 ;obsolete: mov al,[eax] ; get pixel from source bitmap
371 ;obsolete: mov ah,bh ; get lighting table
372 ;obsolete: add ebx,esi ; update lighting value
373 ;obsolete: mov al,[eax] ; xlat pixel through lighting tables
374 ;obsolete: mov [edi],al ; write pixel...
375 ;obsolete: inc edi ; ...and advance
381 ; now do the leftover pixel
383 shr eax,26 ; shift in v coordinate
384 shld ax,bp,6 ; shift in u coordinate while shifting up v coordinate
385 mov al,[esi+eax] ; get pixel from source bitmap
386 mov ah,bh ; get lighting table
391 mov al,[_gr_fade_table+eax] ; xlat pixel through lighting tables
392 mov [edi],al ; write pixel...
400 ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
401 ; suitable for inverse color lookup
404 ;**; rrrrrfffffrrrrrfffffxxbbbbbfffff
405 ;** mov eax,11111001001010101110101101110111b
406 ;** and eax,11111000001111100000001111100000b
411 ;; esi, ecx should be free
415 mov ecx,[_loop_count]
424 mov eax,ebp ; get u, v
425 shr eax,26 ; shift out all but int(v)
426 shld ax,bp,6 ; shift in u, shifting up v
428 add ebp,edx ; u += du, v += dv
430 add eax,[_pixptr] ; DPH:
431 movzx eax,byte [eax] ; get pixel from source bitmap
434 mov ah,bh ; get lighting table
435 add ebx,esi ; _fx_dl_dx ; update lighting value
436 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
437 mov [edi],al ; write pixel...
438 skip1a: inc edi ; ...and advance
442 mov eax,ebp ; get u, v
443 shr eax,26 ; shift out all but int(v)
444 shld ax,bp,6 ; shift in u, shifting up v
446 add ebp,edx ; u += du, v += dv
448 add eax,[_pixptr] ; DPH:
449 movzx eax,byte [eax] ; get pixel from source bitmap
452 mov ah,bh ; get lighting table
453 add ebx,esi ; _fx_dl_dx ; update lighting value
454 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
455 mov [edi],al ; write pixel...
456 skip2a: inc edi ; ...and advance
458 dec ecx ; _loop_count
464 one_more_pix2: mov eax,ebp ; get u, v
465 shr eax,26 ; shift out all but int(v)
466 shld ax,bp,6 ; shift in u, shifting up v
468 add eax,[_pixptr] ; DPH:
469 movzx eax,byte [eax] ; get pixel from source bitmap
472 mov ah,bh ; get lighting table
473 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
474 mov [edi],al ; write pixel...