convert line ends
[canaan.git] / prj / cam / libsrc / portal / ptmap.asm
blobd7e388c6e6c64ec218a1348dc1c6616565c5ffcf
1 ; $Header: r:/t2repos/thief2/libsrc/portold/ptmap.asm,v 1.5 1996/12/07 20:31:14 buzzard Exp $
3 ; PORTAL Texture Mappers
5 ; ptmap.asm
6 ; support functions
9 .486
10 .nolist
12 include macros.inc
13 include lg.inc
14 include fix.inc
16 .list
18 assume cs:_TEXT, ds:_DATA
20 extd _pt_buffer
21 extd _pt_lit_buffer
22 extd _pt_tmap_mask,_pt_tmap_row,_pt_tmap_ptr
23 extd _pt_row_table
24 extd _pt_light
25 extd _pt_dlight
26 extd _pt_toggle
27 extd _dither
28 extd _scanline
29 extd _pt_step_table
30 extb _pt_arb_size
32 _DATA segment para public USE32 'DATA'
34 align 8
36 float_buf dq 0
37 float_buf2 dq 0
39 dlight_8 dd 0
40 externdef dlight_8:dword
42 flat_flag dd 0
44 scanline_count dd 0
46 dest_save dd 0
47 count_save dd 0
48 pixel_save dd 0
50 save_eax dd 0
51 save_ebx dd 0
52 save_esi dd 0
54 pt_dest dd 0
55 externdef pt_dest:dword
57 start_len_table db 8,7,6,9,8,7,6,9
59 externdef _gda:qword
60 externdef _gdb:qword
61 externdef _gdc:qword
62 externdef _u_step_data:qword
63 externdef _v_step_data:qword
64 externdef _one:qword
65 externdef _dc_table:dword
66 externdef float_buf:qword
67 externdef float_buf2:qword
69 _DATA ends
72 _TEXT segment para public USE32 'CODE'
75 extn compute_light_8
76 extn compute_light_n
77 extn ptmap_float_uv
78 extn ptmap_float_duv
79 extn ptmap_float_duv_b
80 extn ptmap_float_duv_c
81 extn ptmap_float_duv_d
82 extn ptmap_setup_uv
83 extn ptmap_setup_duv ; currently desupported
84 extn ptmap_setup_uvduv
87 ; PTMAP_FLOAT_UV
88 ; get u,v values from our iterative process
89 ; and arrange them in registers for mapping
91 ptmap_float_uv:
92 mov ebx,dword ptr float_buf
93 mov ecx,dword ptr float_buf2
95 ; fall through
98 ; PTMAP_SETUP_UV
99 ; arrange u,v values into registers
100 ; ebx = u
101 ; ecx = v
102 ; we output into ebx, esi, eax
104 ptmap_setup_uv:
105 mov al,_pt_arb_size
106 cmp al,0
107 jne pt_setup_arb_uv
109 ror ebx,16 ; align fraction high and integer low
110 mov eax,ecx
112 shr ecx,16
113 mov esi,ebx
115 shl eax,16
116 mov bh,cl
118 mov ecx,_pt_tmap_mask
120 and ebx,ecx ; mask to stay wrapped in texture map
123 pt_setup_arb_uv:
124 mov eax,ecx ; eax = v
125 mov esi,_pt_tmap_row ; esi = row
127 sar eax,16 ; eax = v_hi
129 imul eax,esi ; eax = v_hi * row
131 shl ecx,16 ; ecx = v_lo
132 mov esi,ebx ; esi = u
134 sar ebx,16 ; ebx = u_hi
136 shl esi,16 ; esi = u_lo
137 add ebx,eax ; ebx = u_hi + v_hi*row
139 mov eax,ecx ; eax = v_lo
140 mov ecx,_pt_tmap_ptr ; ecx = texture
142 add ebx,ecx ; ebx = texture + u_hi + v_hi*row
146 ; PTMAP_FLOAT_DUV
147 ; get results of last FP computation
148 ; and use them to compute our deltas
149 ; and arrange them in registers
151 ptmap_float_duv:
152 mov dl,_pt_arb_size
153 cmp dl,0
154 jnz pt_float_arb_duv
156 mov edx,dword ptr float_buf
157 mov ebp,dword ptr float_buf2
159 ror edx,16
161 shl ebp,16
162 mov ecx,dword ptr float_buf2
164 sar ecx,16
166 mov dh,cl
169 ; output:
170 ; pt_step_table[0] = ((dv_hi+1) * row) + (du_hi)
171 ; pt_step_table[1] = ((dv_hi * row) + (du_hi)
173 ; EAX = v_lo << 16
174 ; ESI = u_lo << 16
175 ; EBP = dv_lo << 16
176 ; EDX = du_lo << 16
177 ; EBX = source + u_hi + v_hi * source_row
179 pt_float_arb_duv:
180 push eax
181 mov edx,dword ptr float_buf2 ; edx = dv
183 sar edx,16 ; edx = dv_hi
184 mov eax,dword ptr float_buf ; eax = du
186 sar eax,16 ; eax = du_hi
187 mov ebp,_pt_tmap_row ; ebp = row
189 mov edx,_pt_row_table[edx*4+32*4] ; edx = dv_hi * row
191 add edx,eax ; edx = dv_hi * row + du_hi
192 pop eax
194 mov _pt_step_table+4,edx ; pt_step_table[1] = dv*row+du
195 add edx,ebp ; edx = (dv_hi+1) * row + du_hi
197 mov _pt_step_table,edx ; pt_step_table[0] = ...
198 mov edx,dword ptr float_buf ; edx = du
200 shl edx,16 ; edx = du_lo
201 mov ebp,dword ptr float_buf2 ; ebp = dv
203 shl ebp,16 ; ebp = dv_lo
207 ; PTMAP_SETUP_DUV
208 ; arrange du,dv values into registers
209 ; edx = du
210 ; ecx = dv
211 ; we output into edx, edx, ebp
212 ptmap_setup_duv:
213 ror edx,16
214 mov ebp,ecx
216 ror ecx,16
218 shl ebp,16
219 mov dh,cl
224 ; PTMAP_SETUP_UVDUV
225 ; arrange u,v,du,dv values into registers
226 ; ebx = u
227 ; eax = v
228 ; edx = du
229 ; ecx = dv
231 ptmap_setup_uvduv:
232 ror ecx,16
234 ror edx,16
235 mov ebp,ecx
237 ror ebx,16
238 mov dh,cl
240 ror eax,16
241 mov esi,ebx
243 mov ecx,_pt_tmap_mask
244 mov bh,al
246 and ebp,0ffff0000h
247 and ebx,ecx ; mask to stay wrapped in texture map
253 ; compute lighting values
256 ; COMPUTE_LIGHT_N
257 ; computes n values of lighting found in al
258 ; preserves all registers except ecx
260 compute_light_n:
261 push ebx
262 push eax
264 push edi
265 push esi
267 mov esi,_dither
269 test esi,esi
270 jnz compute_light_dither_n
272 mov ebx,_pt_light
274 ror ebx,16
275 mov ecx,_pt_dlight
277 shr ecx,16
278 mov esi,_pt_dlight
280 shl esi,16
281 lea edi,_pt_lit_buffer
283 ptmap_cn_loop:
284 mov [edi],bl
285 add ebx,esi
287 adc ebx,ecx
288 inc edi
290 dec al
291 jnz ptmap_cn_loop
293 ; clean up to compute final value
294 ror ebx,16
295 mov _pt_light,ebx
297 pop esi
298 pop edi
300 pop eax
301 pop ebx
306 compute_light_dither_n:
307 push edx
308 mov ebx,_pt_light
310 mov esi,_pt_dlight
311 mov ecx,_pt_toggle
313 lea edi,_pt_lit_buffer
316 ptmap_cdn_loop:
317 mov edx,ebx
318 add ebx,esi
320 shr edx,17
321 xor esi,ecx
323 mov [edi],dl
324 inc edi
326 dec al
327 jnz ptmap_cdn_loop
329 mov _pt_light,ebx
330 mov _pt_dlight,esi
332 pop edx
333 pop esi
335 pop edi
336 pop eax
338 pop ebx
342 ; COMPUTE_LIGHT_8
343 ; computes 8 values of lighting
344 ; stomps ebp,edx,ecx
346 compute_light_8:
347 mov ebp,_pt_light
348 mov edx,_pt_toggle
350 test edx,edx
351 jnz compute_light_dither_8
353 mov edx,_pt_dlight
356 mov ecx,ebp
357 shr ecx,16
358 add ebp,edx
359 mov byte ptr _pt_lit_buffer,cl
361 mov ecx,ebp
362 shr ecx,16
363 add ebp,edx
364 mov byte ptr _pt_lit_buffer+1,cl
366 mov ecx,ebp
367 shr ecx,16
368 add ebp,edx
369 mov byte ptr _pt_lit_buffer+2,cl
371 mov ecx,ebp
372 shr ecx,16
373 add ebp,edx
374 mov byte ptr _pt_lit_buffer+3,cl
376 mov ecx,ebp
377 shr ecx,16
378 add ebp,edx
379 mov byte ptr _pt_lit_buffer+4,cl
381 mov ecx,ebp
382 shr ecx,16
383 add ebp,edx
384 mov byte ptr _pt_lit_buffer+5,cl
386 mov ecx,ebp
387 shr ecx,16
388 add ebp,edx
389 mov byte ptr _pt_lit_buffer+6,cl
391 mov ecx,ebp
392 shr ecx,16
393 add ebp,edx
394 mov byte ptr _pt_lit_buffer+7,cl
396 mov _pt_light,ebp
399 compute_light_dither_8:
400 push eax
401 mov eax,_pt_dlight
403 xor edx,eax
405 mov ecx,ebp
406 shr ecx,17
407 add ebp,eax
408 mov byte ptr _pt_lit_buffer,cl
410 mov ecx,ebp
411 shr ecx,17
412 add ebp,edx
413 mov byte ptr _pt_lit_buffer+1,cl
415 mov ecx,ebp
416 shr ecx,17
417 add ebp,eax
418 mov byte ptr _pt_lit_buffer+2,cl
420 mov ecx,ebp
421 shr ecx,17
422 add ebp,edx
423 mov byte ptr _pt_lit_buffer+3,cl
425 mov ecx,ebp
426 shr ecx,17
427 add ebp,eax
428 mov byte ptr _pt_lit_buffer+4,cl
430 mov ecx,ebp
431 shr ecx,17
432 add ebp,edx
433 mov byte ptr _pt_lit_buffer+5,cl
435 mov ecx,ebp
436 shr ecx,17
437 add ebp,eax
438 mov byte ptr _pt_lit_buffer+6,cl
440 mov ecx,ebp
441 shr ecx,17
442 add ebp,edx
443 mov byte ptr _pt_lit_buffer+7,cl
445 mov _pt_light,ebp
446 pop eax
451 _TEXT ends