1 ; $Id: tmap_ll.asm,v 1.3 2004-08-28 23:17:46 schaffner 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.
20 global _asm_tmap_scanline_lin_lighted
21 global asm_tmap_scanline_lin_lighted
25 %include "tmap_inc.asm"
37 ; --------------------------------------------------------------------------------------------------
39 ; _xleft fixed point left x coordinate
40 ; _xright fixed point right x coordinate
41 ; _y fixed point y coordinate
42 ; _pixptr address of source pixel map
43 ; _u fixed point initial u coordinate
44 ; _v fixed point initial v coordinate
45 ; _du_dx fixed point du/dx
46 ; _dv_dx fixed point dv/dx
48 ; for (x = (int) xleft; x <= (int) xright; x++) {
49 ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
58 _asm_tmap_scanline_lin_lighted:
59 asm_tmap_scanline_lin_lighted:
60 ; push es ; DPH: No selectors in windows :-(
64 ; mov es,[_pixel_data_selector] ; selector[0*2] ; DPH: No... :-)
65 ; mov fs,[_gr_fade_table_selector] ; selector[1*2] ; fs = bmd_fade_table
67 ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
68 ; esi source pixel pointer = pixptr
69 ; edi initial row pointer = y*320+x
71 ; set esi = pointer to start of texture map data
74 ; set edi = address of first pixel to modify
75 mov edi,[_fx_y] ; this is actually an int
76 cmp edi,[_window_bottom]
79 imul edi,[_bytes_per_row]
86 add edi,[_write_buffer]
88 ; set _loop_count = # of iterations
90 cmp eax,[_window_right]
92 mov eax,[_window_right]
93 eax_ok1: cmp eax,[_window_left]
95 mov eax,[_window_left]
100 cmp eax,[_window_width]
102 mov eax,[_window_width]
104 mov [_loop_count],eax
106 ; edi destination pixel pointer
109 mov ecx,_gr_fade_table ;originally offset _lighting_tables
110 mov eax,[_fx_u] ; get 32 bit u coordinate
111 shr eax,6 ; get 6:10 int:frac u coordinate into low word
112 mov ebp,[_fx_v] ; get 32 bit v coordinate
113 shl ebp,10 ; put 6:10 int:frac into high word
114 mov bp,ax ; put u coordinate in low word
116 mov eax,[_fx_du_dx] ; get 32 bit delta u
117 shr eax,6 ; get 6:10 int:frac delta u into low word
118 mov edx,[_fx_dv_dx] ; get 32 bit delta v
119 shl edx,10 ; put 6:10 int:frac into high word
120 mov dx,ax ; put delta u in low word
122 sar dword [_fx_dl_dx],8
124 inc dword [_fx_dl_dx] ; round towards 0 for negative deltas
128 ; do dithering, use lighting values which are .5 less than and .5 more than actual value
129 mov ebx,80h ; assume dithering on
130 test dword [_dither_intensity_lighting],-1
132 sub ebx,ebx ; no dithering
135 add eax,ebx ; add 1/2
144 xchg eax,[_fx_dl_dx1]
145 dith_1: mov [_fx_dl_dx2],eax
150 ; lighting values are passed in fixed point, but need to be in 8 bit integer, 8 bit fraction so we can easily
151 ; get the integer by reading %bh
154 test dword [_Transparency_on],-1
155 jne do_transparency_ll
157 ;; esi, ecx should be free
158 loop_test equ 1 ; set to 1 to run as loop for better profiling
162 mov ecx,[_loop_count]
171 mov eax,ebp ; get u, v
172 shr eax,26 ; shift out all but int(v)
173 shld ax,bp,6 ; shift in u, shifting up v
175 add ebp,edx ; u += du, v += dv
177 add eax,[_pixptr] ; DPH: No selectors in windows
178 movzx eax,byte [eax] ; get pixel from source bitmap
179 mov ah,bh ; get lighting table
180 add ebx,esi ; _fx_dl_dx ; update lighting value
181 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
182 mov [edi],al ; write pixel...
183 inc edi ; ...and advance
187 mov eax,ebp ; get u, v
188 shr eax,26 ; shift out all but int(v)
189 shld ax,bp,6 ; shift in u, shifting up v
191 add ebp,edx ; u += du, v += dv
193 add eax,[_pixptr] ; DPH:
194 movzx eax,byte [eax] ; get pixel from source bitmap
195 mov ah,bh ; get lighting table
196 add ebx,esi ; _fx_dl_dx ; update lighting value
197 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
198 mov [edi],al ; write pixel...
199 inc edi ; ...and advance
201 dec ecx ; _loop_count
207 one_more_pix: mov eax,ebp ; get u, v
208 shr eax,26 ; shift out all but int(v)
209 shld ax,bp,6 ; shift in u, shifting up v
211 add eax,[_pixptr] ; DPH:
212 movzx eax,byte [eax] ; get pixel from source bitmap
213 mov ah,bh ; get lighting table
214 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
215 mov [edi],al ; write pixel...
228 ; ecx _lighting_tables
229 ; edx du, dv 6:10:6:10
230 ; ebp u, v coordinates 6:10:6:10
231 ; esi pointer to source bitmap
234 ;_size = (_end1 - _start1)/num_iters
235 ; note: if eax is odd, you will not be writing the last pixel, you must clean up at the end
237 mov eax,[_loop_count]
243 sub eax,[_loop_count]
246 imul eax,eax,(_end1 - _start1)/num_iters
247 add eax,_start1 ;originally offset _start1
256 ; ecx _lighting_tables
257 ; edx du, dv 6:10:6:10
258 ; ebp u, v coordinates 6:10:6:10
259 ; esi pointer to source bitmap
262 ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
266 ;**; inner loop if lighting value is constant
267 ;**; can be optimized if source bitmap pixels are stored as words, then the mov ah,bh is not necessary
268 ;** mov eax,ebp ; get u, v
269 ;** shr eax,26 ; shift out all but int(v)
270 ;** shld ax,bp,6 ; shift in u, shifting up v
272 ;** add ebp,edx ; u += du, v += dv
274 ;** mov al,[esi+eax] ; get pixel from source bitmap
275 ;** mov ah,bh ; get lighting table
276 ;** mov al,[ecx+eax] ; xlat pixel through lighting tables
277 ;** mov [edi],al ; write pixel...
278 ;** inc edi ; ...and advance
284 ; loop contains two iterations which must be the same length
285 mov eax,ebp ; get u, v
286 shr eax,26 ; shift out all but int(v)
287 shld ax,bp,6 ; shift in u, shifting up v
289 add ebp,edx ; u += du, v += dv
291 mov al,[esi+eax] ; get pixel from source bitmap
292 mov ah,bh ; get lighting table
293 add ebx,[_fx_dl_dx1] ; update lighting value
294 mov al,[ecx+eax] ; xlat pixel through lighting tables
295 mov [edi],al ; write pixel...
296 inc edi ; ...and advance
299 mov eax,ebp ; get u, v
300 shr eax,26 ; shift out all but int(v)
301 shld ax,bp,6 ; shift in u, shifting up v
303 add ebp,edx ; u += du, v += dv
305 mov al,[esi+eax] ; get pixel from source bitmap
306 mov ah,bh ; get lighting table
307 add ebx,[_fx_dl_dx2] ; update lighting value
308 mov al,[ecx+eax] ; xlat pixel through lighting tables
309 mov [edi],al ; write pixel...
310 inc edi ; ...and advance
312 mov eax,ebp ; get u, v
313 shr eax,26 ; shift out all but int(v)
314 shld ax,bp,6 ; shift in u, shifting up v
316 add ebp,edx ; u += du, v += dv
318 mov al,[esi+eax] ; get pixel from source bitmap
319 mov ah,bh ; get lighting table
320 add ebx,[_fx_dl_dx] ; update lighting value
321 mov al,[ecx+eax] ; xlat pixel through lighting tables
322 mov [edi],al ; write pixel...
323 inc edi ; ...and advance
329 ;obsolete: ; version which assumes segment overrides are in place (which they are obviously not)
330 ;obsolete: mov eax,ebp ; get u, v
331 ;obsolete: shr eax,26 ; shift out all but int(v)
332 ;obsolete: shld ax,bp,6 ; shift in u, shifting up v
334 ;obsolete: add ebp,edx ; u += du, v += dv
336 ;obsolete: mov al,[eax] ; get pixel from source bitmap
337 ;obsolete: mov ah,bh ; get lighting table
338 ;obsolete: add ebx,esi ; update lighting value
339 ;obsolete: mov al,[eax] ; xlat pixel through lighting tables
340 ;obsolete: mov [edi],al ; write pixel...
341 ;obsolete: inc edi ; ...and advance
347 ; now do the leftover pixel
349 shr eax,26 ; shift in v coordinate
350 shld ax,bp,6 ; shift in u coordinate while shifting up v coordinate
351 mov al,[esi+eax] ; get pixel from source bitmap
352 mov ah,bh ; get lighting table
357 mov al,[_gr_fade_table+eax] ; xlat pixel through lighting tables
358 mov [edi],al ; write pixel...
366 ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
367 ; suitable for inverse color lookup
370 ;**; rrrrrfffffrrrrrfffffxxbbbbbfffff
371 ;** mov eax,11111001001010101110101101110111b
372 ;** and eax,11111000001111100000001111100000b
377 ;; esi, ecx should be free
381 mov ecx,[_loop_count]
390 mov eax,ebp ; get u, v
391 shr eax,26 ; shift out all but int(v)
392 shld ax,bp,6 ; shift in u, shifting up v
394 add ebp,edx ; u += du, v += dv
396 add eax,[_pixptr] ; DPH:
397 movzx eax,byte [eax] ; get pixel from source bitmap
400 mov ah,bh ; get lighting table
401 add ebx,esi ; _fx_dl_dx ; update lighting value
402 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
403 mov [edi],al ; write pixel...
404 skip1a: inc edi ; ...and advance
408 mov eax,ebp ; get u, v
409 shr eax,26 ; shift out all but int(v)
410 shld ax,bp,6 ; shift in u, shifting up v
412 add ebp,edx ; u += du, v += dv
414 add eax,[_pixptr] ; DPH:
415 movzx eax,byte [eax] ; get pixel from source bitmap
418 mov ah,bh ; get lighting table
419 add ebx,esi ; _fx_dl_dx ; update lighting value
420 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
421 mov [edi],al ; write pixel...
422 skip2a: inc edi ; ...and advance
424 dec ecx ; _loop_count
430 one_more_pix2: 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 eax,[_pixptr] ; DPH:
435 movzx eax,byte [eax] ; get pixel from source bitmap
438 mov ah,bh ; get lighting table
439 mov al,[_gr_fade_table + eax] ; xlat pixel through lighting tables
440 mov [edi],al ; write pixel...