Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
661 | ataualpa | 1 | ROUND equ 8 |
2 | CATMULL_SHIFT equ 8 |
||
3 | gouraud_triangle_z: |
||
4 | ;----procedure drawing gouraud triangle with z coordinate |
||
5 | ;----interpolation ( Catmull alghoritm )----------------- |
||
6 | ;------------------in - eax - x1 shl 16 + y1 ------------ |
||
7 | ;---------------------- ebx - x2 shl 16 + y2 ------------ |
||
8 | ;---------------------- ecx - x3 shl 16 + y3 ------------ |
||
9 | ;---------------------- esi - pointer to Z-buffer-------- |
||
10 | ;---------------------- Z-buffer filled with dd variables |
||
11 | ;---------------------- shifted CATMULL_SHIFT------------ |
||
12 | ;---------------------- edi - pointer to screen buffer--- |
||
13 | ;---------------------- stack : colors------------------- |
||
14 | ;----------------- procedure don't save registers !!----- |
||
15 | .col1r equ ebp+4 ; each color as word |
||
16 | .col1g equ ebp+6 ; each z coordinate as word |
||
17 | .col1b equ ebp+8 |
||
18 | .z1 equ ebp+10 |
||
19 | .col2r equ ebp+12 |
||
20 | .col2g equ ebp+14 |
||
21 | .col2b equ ebp+16 |
||
22 | .z2 equ ebp+18 |
||
23 | .col3r equ ebp+20 |
||
24 | .col3g equ ebp+22 |
||
25 | .col3b equ ebp+24 |
||
26 | .z3 equ ebp+26 |
||
27 | |||
28 | .x1 equ word[ebp-2] |
||
29 | .y1 equ word[ebp-4] |
||
30 | .x2 equ word[ebp-6] |
||
31 | .y2 equ word[ebp-8] |
||
32 | .x3 equ word[ebp-10] |
||
33 | .y3 equ word[ebp-12] |
||
34 | |||
35 | .dx12 equ dword[ebp-16] |
||
36 | .dz12 equ dword[ebp-20] |
||
37 | .dc12r equ dword[ebp-24] |
||
38 | .dc12g equ dword[ebp-28] |
||
39 | .dc12b equ dword[ebp-32] |
||
40 | |||
41 | .dx13 equ dword[ebp-36] |
||
42 | .dz13 equ dword[ebp-40] |
||
43 | .dc13r equ dword[ebp-44] |
||
44 | .dc13g equ dword[ebp-48] |
||
45 | .dc13b equ dword[ebp-52] |
||
46 | |||
47 | .dx23 equ dword[ebp-56] |
||
48 | .dz23 equ dword[ebp-60] |
||
49 | .dc23r equ dword[ebp-64] |
||
50 | .dc23g equ dword[ebp-68] |
||
51 | .dc23b equ dword[ebp-72] |
||
52 | |||
53 | .c1r equ dword[ebp-76] |
||
54 | .c1g equ dword[ebp-80] |
||
55 | .c1b equ dword[ebp-84] |
||
56 | .c2r equ dword[ebp-88] |
||
57 | .c2g equ dword[ebp-92] |
||
58 | .c2b equ dword[ebp-96] |
||
59 | .zz1 equ dword[ebp-100] |
||
60 | .zz2 equ dword[ebp-104] |
||
61 | |||
62 | mov ebp,esp |
||
63 | ; sub esp,84 |
||
64 | .sort3: ; sort triangle coordinates... |
||
65 | cmp ax,bx |
||
66 | jle .sort1 |
||
67 | xchg eax,ebx |
||
68 | mov edx,dword[.col1r] |
||
69 | xchg edx,dword[.col2r] |
||
70 | mov dword[.col1r],edx |
||
71 | mov edx,dword[.col1b] |
||
72 | xchg edx,dword[.col2b] |
||
73 | mov dword[.col1b],edx |
||
74 | .sort1: |
||
75 | cmp bx,cx |
||
76 | jle .sort2 |
||
77 | xchg ebx,ecx |
||
78 | mov edx,dword[.col2r] |
||
79 | xchg edx,dword[.col3r] |
||
80 | mov dword[.col2r],edx |
||
81 | mov edx,dword[.col2b] |
||
82 | xchg edx,dword[.col3b] |
||
83 | mov dword[.col2b],edx |
||
84 | jmp .sort3 |
||
85 | .sort2: |
||
86 | push eax ; store in variables |
||
87 | push ebx |
||
88 | push ecx |
||
89 | mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that |
||
90 | and edx,ebx ; if *all* of them are negative a sign flag is raised |
||
91 | and edx,ecx |
||
92 | and edx,eax |
||
93 | test edx,80008000h ; Check both X&Y at once |
||
94 | jne .gt_loop2_end |
||
95 | |||
96 | mov bx,.y2 ; calc deltas |
||
97 | sub bx,.y1 |
||
98 | jnz .gt_dx12_make |
||
99 | ; mov .dx12,0 |
||
100 | ; mov .dz12,0 |
||
101 | ; mov .dc12r,0 |
||
102 | ; mov .dc12g,0 |
||
103 | ; mov .dc12b,0 |
||
104 | mov ecx,5 |
||
105 | @@: |
||
106 | push dword 0 |
||
107 | loop @b |
||
108 | jmp .gt_dx12_done |
||
109 | .gt_dx12_make: |
||
110 | mov ax,.x2 |
||
111 | sub ax,.x1 |
||
112 | cwde |
||
113 | movsx ebx,bx |
||
114 | shl eax,ROUND |
||
115 | cdq |
||
116 | idiv ebx |
||
117 | ; mov .dx12,eax |
||
118 | push eax |
||
119 | |||
120 | mov ax,word[.z2] |
||
121 | sub ax,word[.z1] |
||
122 | cwde |
||
123 | shl eax,CATMULL_SHIFT |
||
124 | cdq |
||
125 | idiv ebx |
||
126 | push eax |
||
127 | |||
128 | mov ax,word[.col2r] |
||
129 | sub ax,word[.col1r] |
||
130 | cwde |
||
131 | shl eax,ROUND |
||
132 | cdq |
||
133 | idiv ebx |
||
134 | ; mov .dc12r,eax |
||
135 | push eax |
||
136 | mov ax,word[.col2g] |
||
137 | sub ax,word[.col1g] |
||
138 | cwde |
||
139 | shl eax,ROUND |
||
140 | cdq |
||
141 | idiv ebx |
||
142 | ; mov .dc12g,eax |
||
143 | push eax |
||
144 | mov ax,word[.col2b] |
||
145 | sub ax,word[.col1b] |
||
146 | cwde |
||
147 | shl eax,ROUND |
||
148 | cdq |
||
149 | idiv ebx |
||
150 | ; mov .dc12b,eax |
||
151 | push eax |
||
152 | .gt_dx12_done: |
||
153 | |||
154 | mov bx,.y3 ; calc deltas |
||
155 | sub bx,.y1 |
||
156 | jnz .gt_dx13_make |
||
157 | ; mov .dx13,0 |
||
158 | ; mov .dz13,0 |
||
159 | ; mov .dc13r,0 |
||
160 | ; mov .dc13g,0 |
||
161 | ; mov .dc13b,0 |
||
162 | mov ecx,5 |
||
163 | @@: |
||
164 | push dword 0 |
||
165 | loop @b |
||
166 | jmp .gt_dx13_done |
||
167 | .gt_dx13_make: |
||
168 | mov ax,.x3 |
||
169 | sub ax,.x1 |
||
170 | cwde |
||
171 | movsx ebx,bx |
||
172 | shl eax,ROUND |
||
173 | cdq |
||
174 | idiv ebx |
||
175 | ; mov .dx13,eax |
||
176 | push eax |
||
177 | |||
178 | mov ax,word[.z3] |
||
179 | sub ax,word[.z1] |
||
180 | cwde |
||
181 | shl eax,CATMULL_SHIFT |
||
182 | cdq |
||
183 | idiv ebx |
||
184 | push eax |
||
185 | |||
186 | mov ax,word[.col3r] |
||
187 | sub ax,word[.col1r] |
||
188 | cwde |
||
189 | shl eax,ROUND |
||
190 | cdq |
||
191 | idiv ebx |
||
192 | ; mov .dc13r,eax |
||
193 | push eax |
||
194 | mov ax,word[.col3g] |
||
195 | sub ax,word[.col1g] |
||
196 | cwde |
||
197 | shl eax,ROUND |
||
198 | cdq |
||
199 | idiv ebx |
||
200 | ; mov .dc13g,eax |
||
201 | push eax |
||
202 | mov ax,word[.col3b] |
||
203 | sub ax,word[.col1b] |
||
204 | cwde |
||
205 | shl eax,ROUND |
||
206 | cdq |
||
207 | idiv ebx |
||
208 | ; mov .dc13b,eax |
||
209 | push eax |
||
210 | .gt_dx13_done: |
||
211 | |||
212 | mov bx,.y3 ; calc deltas |
||
213 | sub bx,.y2 |
||
214 | jnz .gt_dx23_make |
||
215 | ; mov .dx23,0 |
||
216 | ; mov .dz23,0 |
||
217 | ; mov .dc23r,0 |
||
218 | ; mov .dc23g,0 |
||
219 | ; mov .dc23b,0 |
||
220 | mov ecx,5 |
||
221 | @@: |
||
222 | push dword 0 |
||
223 | loop @b |
||
224 | jmp .gt_dx23_done |
||
225 | .gt_dx23_make: |
||
226 | mov ax,.x3 |
||
227 | sub ax,.x2 |
||
228 | cwde |
||
229 | movsx ebx,bx |
||
230 | shl eax,ROUND |
||
231 | cdq |
||
232 | idiv ebx |
||
233 | ; mov .dx23,eax |
||
234 | push eax |
||
235 | |||
236 | mov ax,word[.z3] |
||
237 | sub ax,word[.z2] |
||
238 | cwde |
||
239 | shl eax,CATMULL_SHIFT |
||
240 | cdq |
||
241 | idiv ebx |
||
242 | push eax |
||
243 | |||
244 | mov ax,word[.col3r] |
||
245 | sub ax,word[.col2r] |
||
246 | cwde |
||
247 | shl eax,ROUND |
||
248 | cdq |
||
249 | idiv ebx |
||
250 | ; mov .dc23r,eax |
||
251 | push eax |
||
252 | mov ax,word[.col3g] |
||
253 | sub ax,word[.col2g] |
||
254 | cwde |
||
255 | shl eax,ROUND |
||
256 | cdq |
||
257 | idiv ebx |
||
258 | ; mov .dc23g,eax |
||
259 | push eax |
||
260 | mov ax,word[.col3b] |
||
261 | sub ax,word[.col2b] |
||
262 | cwde |
||
263 | shl eax,ROUND |
||
264 | cdq |
||
265 | idiv ebx |
||
266 | ; mov .dc23b,eax |
||
267 | push eax |
||
268 | .gt_dx23_done: |
||
269 | sub esp,32 |
||
270 | |||
271 | movsx eax,.x1 ; eax - cur x1 |
||
272 | shl eax,ROUND ; ebx - cur x2 |
||
273 | mov ebx,eax |
||
274 | movsx edx,word[.z1] |
||
275 | shl edx,CATMULL_SHIFT |
||
276 | mov .zz1,edx |
||
277 | mov .zz2,edx |
||
278 | movzx edx,word[.col1r] |
||
279 | shl edx,ROUND |
||
280 | mov .c1r,edx |
||
281 | mov .c2r,edx |
||
282 | movzx edx,word[.col1g] |
||
283 | shl edx,ROUND |
||
284 | mov .c1g,edx |
||
285 | mov .c2g,edx |
||
286 | movzx edx,word[.col1b] |
||
287 | shl edx,ROUND |
||
288 | mov .c1b,edx |
||
289 | mov .c2b,edx |
||
290 | mov cx,.y1 |
||
291 | cmp cx,.y2 |
||
292 | jge .gt_loop1_end |
||
293 | |||
294 | .gt_loop1: |
||
295 | pushad |
||
296 | ; macro .debug |
||
297 | |||
298 | mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors |
||
299 | sar edx,ROUND |
||
300 | push dx |
||
301 | mov edx,.c2g |
||
302 | sar edx,ROUND |
||
303 | push dx |
||
304 | mov edx,.c2b |
||
305 | sar edx,ROUND |
||
306 | push dx |
||
307 | sar ebx,ROUND ; x2 |
||
308 | push bx |
||
309 | mov edx,.c1r |
||
310 | sar edx,ROUND |
||
311 | push dx |
||
312 | mov edx,.c1g |
||
313 | sar edx,ROUND |
||
314 | push dx |
||
315 | mov edx,.c1b |
||
316 | sar edx,ROUND |
||
317 | push dx |
||
318 | sar eax,ROUND |
||
319 | push ax ; x1 |
||
320 | push cx ; y |
||
321 | push .zz2 |
||
322 | push .zz1 |
||
323 | call gouraud_line_z |
||
324 | |||
325 | popad |
||
326 | |||
327 | mov edx,.dc13r |
||
328 | add .c1r,edx |
||
329 | mov edx,.dc13g |
||
330 | add .c1g,edx |
||
331 | mov edx,.dc13b |
||
332 | add .c1b,edx |
||
333 | mov edx,.dc12r |
||
334 | add .c2r,edx |
||
335 | mov edx,.dc12g |
||
336 | add .c2g,edx |
||
337 | mov edx,.dc12b |
||
338 | add .c2b,edx |
||
339 | mov edx,.dz13 |
||
340 | add .zz1,edx |
||
341 | mov edx,.dz12 |
||
342 | add .zz2,edx |
||
343 | |||
344 | add eax,.dx13 |
||
345 | add ebx,.dx12 |
||
346 | inc cx |
||
347 | cmp cx,.y2 |
||
348 | jl .gt_loop1 |
||
349 | |||
350 | .gt_loop1_end: |
||
351 | mov cx,.y2 |
||
352 | cmp cx,.y3 |
||
353 | jge .gt_loop2_end |
||
354 | |||
355 | movsx ebx,.x2 ; eax - cur x1 |
||
356 | shl ebx,ROUND ; ebx - cur x2 |
||
357 | movsx edx,word[.z2] |
||
358 | shl edx,CATMULL_SHIFT |
||
359 | mov .zz2,edx |
||
360 | movzx edx,word[.col2r] |
||
361 | shl edx,ROUND |
||
362 | mov .c2r,edx |
||
363 | movzx edx,word[.col2g] |
||
364 | shl edx,ROUND |
||
365 | mov .c2g,edx |
||
366 | movzx edx,word[.col2b] |
||
367 | shl edx,ROUND |
||
368 | mov .c2b,edx |
||
369 | |||
370 | .gt_loop2: |
||
371 | pushad |
||
372 | ; macro .debug |
||
373 | |||
374 | mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors |
||
375 | sar edx,ROUND |
||
376 | push dx |
||
377 | mov edx,.c2g |
||
378 | sar edx,ROUND |
||
379 | push dx |
||
380 | mov edx,.c2b |
||
381 | sar edx,ROUND |
||
382 | push dx |
||
383 | sar ebx,ROUND ; x2 |
||
384 | push bx |
||
385 | mov edx,.c1r |
||
386 | sar edx,ROUND |
||
387 | push dx |
||
388 | mov edx,.c1g |
||
389 | sar edx,ROUND |
||
390 | push dx |
||
391 | mov edx,.c1b |
||
392 | sar edx,ROUND |
||
393 | push dx |
||
394 | sar eax,ROUND |
||
395 | push ax ; x1 |
||
396 | push cx ; y |
||
397 | push .zz2 |
||
398 | push .zz1 |
||
399 | call gouraud_line_z |
||
400 | |||
401 | popad |
||
402 | |||
403 | mov edx,.dc13r |
||
404 | add .c1r,edx |
||
405 | mov edx,.dc13g |
||
406 | add .c1g,edx |
||
407 | mov edx,.dc13b |
||
408 | add .c1b,edx |
||
409 | mov edx,.dc23r |
||
410 | add .c2r,edx |
||
411 | mov edx,.dc23g |
||
412 | add .c2g,edx |
||
413 | mov edx,.dc23b |
||
414 | add .c2b,edx |
||
415 | mov edx,.dz13 |
||
416 | add .zz1,edx |
||
417 | mov edx,.dz23 |
||
418 | add .zz2,edx |
||
419 | |||
420 | add eax,.dx13 |
||
421 | add ebx,.dx23 |
||
422 | inc cx |
||
423 | cmp cx,.y3 |
||
424 | jl .gt_loop2 |
||
425 | .gt_loop2_end: |
||
426 | |||
427 | mov esp,ebp |
||
428 | ret 24 |
||
429 | gouraud_line_z: |
||
430 | ;----------------- procedure drawing gouraud line |
||
431 | ;----------------- with z coordinate interpolation |
||
432 | ;----------------- esi - pointer to Z_buffer |
||
433 | ;----------------- edi - pointer to screen buffer |
||
434 | ;----------------- stack: |
||
435 | .z1 equ dword[ebp+4] ; z coordiunate shifted left CATMULL_SHIFT |
||
436 | .z2 equ dword[ebp+8] |
||
437 | .y equ word[ebp+12] |
||
438 | .x1 equ ebp+14 |
||
439 | .c1b equ ebp+16 |
||
440 | .c1g equ ebp+18 |
||
441 | .c1r equ ebp+20 |
||
442 | .x2 equ ebp+22 |
||
443 | .c2b equ ebp+24 |
||
444 | .c2g equ ebp+26 |
||
445 | .c2r equ ebp+28 |
||
446 | .dz equ dword[ebp-4] |
||
447 | .dc_r equ dword[ebp-8] |
||
448 | .dc_g equ dword[ebp-12] |
||
449 | .dc_b equ dword[ebp-14] |
||
450 | .cr equ dword[ebp-18] |
||
451 | .cg equ dword[ebp-22] |
||
452 | .cb equ dword[ebp-26] |
||
453 | mov ebp,esp |
||
454 | |||
455 | mov ax,.y |
||
456 | or ax,ax |
||
457 | jl .gl_quit |
||
458 | cmp ax,SIZE_Y |
||
459 | jge .gl_quit |
||
460 | |||
461 | mov eax,dword[.x1] |
||
462 | cmp ax,word[.x2] |
||
463 | je .gl_quit |
||
464 | jl @f |
||
465 | |||
466 | xchg eax,dword[.x2] |
||
467 | mov dword[.x1],eax |
||
468 | mov eax,dword[.c1g] |
||
469 | xchg eax,dword[.c2g] |
||
470 | mov dword[.c1g],eax |
||
471 | mov eax,.z1 |
||
472 | xchg eax,.z2 |
||
473 | mov .z1,eax |
||
474 | @@: |
||
475 | cmp word[.x1],SIZE_X |
||
476 | jge .gl_quit |
||
477 | cmp word[.x2],0 |
||
478 | jle .gl_quit |
||
479 | |||
480 | mov eax,.z2 |
||
481 | sub eax,.z1 |
||
482 | cdq |
||
483 | mov bx,word[.x2] ; dz = z2-z1/x2-x1 |
||
484 | sub bx,word[.x1] |
||
485 | movsx ebx,bx |
||
486 | idiv ebx |
||
487 | push eax |
||
488 | |||
489 | mov ax,word[.c2r] |
||
490 | sub ax,word[.c1r] |
||
491 | cwde |
||
492 | shl eax,ROUND ; dc_r = c2r-c1r/x2-x1 |
||
493 | cdq |
||
494 | idiv ebx |
||
495 | push eax |
||
496 | |||
497 | mov ax,word[.c2g] |
||
498 | sub ax,word[.c1g] |
||
499 | cwde |
||
500 | shl eax,ROUND |
||
501 | cdq |
||
502 | idiv ebx |
||
503 | push eax |
||
504 | |||
505 | mov ax,word[.c2b] |
||
506 | sub ax,word[.c1b] |
||
507 | cwde |
||
508 | shl eax,ROUND |
||
509 | cdq |
||
510 | idiv ebx |
||
511 | push eax |
||
512 | |||
513 | cmp word[.x1],0 |
||
514 | jg @f |
||
515 | mov eax,.dz |
||
516 | movsx ebx,word[.x1] |
||
517 | neg ebx |
||
518 | imul ebx |
||
519 | add .z1,eax |
||
520 | mov word[.x1],0 |
||
521 | |||
522 | mov eax,.dc_r |
||
523 | imul ebx |
||
524 | sar eax,ROUND |
||
525 | add word[.c1r],ax |
||
526 | |||
527 | mov eax,.dc_g |
||
528 | imul ebx |
||
529 | sar eax,ROUND |
||
530 | add word[.c1g],ax |
||
531 | |||
532 | mov eax,.dc_b |
||
533 | imul ebx |
||
534 | sar eax,ROUND |
||
535 | add word[.c1b],ax |
||
536 | |||
537 | @@: |
||
538 | cmp word[.x2],SIZE_X |
||
539 | jl @f |
||
540 | mov word[.x2],SIZE_X |
||
541 | @@: |
||
542 | sub esp,12 ; calculate memory begin |
||
543 | mov edx,SIZE_X ; in buffers |
||
544 | movzx eax,.y |
||
545 | mul edx |
||
546 | movzx edx,word[.x1] |
||
547 | add eax,edx |
||
548 | push eax |
||
549 | lea eax,[eax*3] |
||
550 | add edi,eax |
||
551 | pop eax |
||
552 | shl eax,2 |
||
553 | add esi,eax |
||
554 | |||
555 | mov cx,word[.x2] |
||
556 | sub cx,word[.x1] |
||
557 | movzx ecx,cx |
||
558 | mov ebx,.z1 ; ebx - currrent z shl CATMULL_SIFT |
||
559 | mov edx,.dz ; edx - delta z |
||
560 | movzx eax,word[.c1r] |
||
561 | shl eax,ROUND |
||
562 | mov .cr,eax |
||
563 | movzx eax,word[.c1g] |
||
564 | shl eax,ROUND |
||
565 | mov .cg,eax |
||
566 | movzx eax,word[.c1b] |
||
567 | shl eax,ROUND |
||
568 | mov .cb,eax |
||
569 | .ddraw: |
||
570 | cmp ebx,dword[esi] |
||
571 | jge .skip |
||
572 | mov eax,.cr |
||
573 | sar eax,ROUND |
||
574 | stosb |
||
575 | mov eax,.cg |
||
576 | sar eax,ROUND |
||
577 | stosb |
||
578 | mov eax,.cb |
||
579 | sar eax,ROUND |
||
580 | stosb |
||
581 | mov dword[esi],ebx |
||
582 | jmp .no_skip |
||
583 | .skip: |
||
584 | add edi,3 |
||
585 | .no_skip: |
||
586 | add esi,4 |
||
587 | add ebx,edx |
||
588 | mov eax,.dc_r |
||
589 | add .cr,eax |
||
590 | mov eax,.dc_g |
||
591 | add .cg,eax |
||
592 | mov eax,.dc_b |
||
593 | add .cb,eax |
||
594 | loop .ddraw |
||
595 | |||
596 | .gl_quit: |
||
597 | mov esp,ebp |
||
598 | ret 26 |