Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1245 | hidnplayr | 1 | gouraud_triangle: |
2 | ;------------------in - eax - x1 shl 16 + y1 --------- |
||
3 | ;---------------------- ebx - x2 shl 16 + y2 --------- |
||
4 | ;---------------------- ecx - x3 shl 16 + y3 --------- |
||
5 | ;---------------------- edi - pointer to screen buffer |
||
6 | ;---------------------- stack : colors---------------- |
||
7 | ;----------------- procedure don't save registers !!-- |
||
8 | .col1r equ ebp+4 ; each color as word |
||
9 | .col1g equ ebp+6 |
||
10 | .col1b equ ebp+8 |
||
11 | .col2r equ ebp+10 |
||
12 | .col2g equ ebp+12 |
||
13 | .col2b equ ebp+14 |
||
14 | .col3r equ ebp+16 |
||
15 | .col3g equ ebp+18 |
||
16 | .col3b equ ebp+20 |
||
17 | |||
18 | .x1 equ word[ebp-2] |
||
19 | .y1 equ word[ebp-4] |
||
20 | .x2 equ word[ebp-6] |
||
21 | .y2 equ word[ebp-8] |
||
22 | .x3 equ word[ebp-10] |
||
23 | .y3 equ word[ebp-12] |
||
24 | |||
25 | .dc12r equ dword[ebp-16] |
||
26 | .dc12g equ dword[ebp-20] |
||
27 | .dc12b equ dword[ebp-24] |
||
28 | .dc13r equ dword[ebp-28] |
||
29 | .dc13g equ dword[ebp-32] |
||
30 | .dc13b equ dword[ebp-36] |
||
31 | .dc23r equ dword[ebp-40] |
||
32 | .dc23g equ dword[ebp-44] |
||
33 | .dc23b equ dword[ebp-48] |
||
34 | |||
35 | .c1r equ dword[ebp-52] |
||
36 | .c1g equ dword[ebp-56] |
||
37 | .c1b equ dword[ebp-60] |
||
38 | .c2r equ dword[ebp-64] |
||
39 | .c2g equ dword[ebp-68] |
||
40 | .c2b equ dword[ebp-72] |
||
41 | |||
42 | .dx12 equ dword[ebp-76] |
||
43 | .dx13 equ dword[ebp-80] |
||
44 | .dx23 equ dword[ebp-84] |
||
45 | |||
46 | |||
47 | |||
48 | mov ebp,esp |
||
49 | ; sub esp,72 |
||
50 | |||
51 | .sort3: ; sort triangle coordinates... |
||
52 | cmp ax,bx |
||
53 | jle .sort1 |
||
54 | xchg eax,ebx |
||
55 | mov edx,dword[.col1r] |
||
56 | xchg edx,dword[.col2r] |
||
57 | mov dword[.col1r],edx |
||
58 | mov dx,word[.col1b] |
||
59 | xchg dx,word[.col2b] |
||
60 | mov word[.col1b],dx |
||
61 | .sort1: |
||
62 | cmp bx,cx |
||
63 | jle .sort2 |
||
64 | xchg ebx,ecx |
||
65 | mov edx,dword[.col2r] |
||
66 | xchg edx,dword[.col3r] |
||
67 | mov dword[.col2r],edx |
||
68 | mov dx,word[.col2b] |
||
69 | xchg dx,word[.col3b] |
||
70 | mov word[.col2b],dx |
||
71 | jmp .sort3 |
||
72 | .sort2: |
||
73 | push eax ;store triangle coordinates in user friendly variables |
||
74 | push ebx |
||
75 | push ecx |
||
76 | sub esp,72 ; set correctly value of esp |
||
77 | |||
78 | mov edx,eax ; check only X triangle coordinate |
||
79 | or edx,ebx |
||
80 | or edx,ecx |
||
81 | test edx,80000000h |
||
82 | jne .gt_loop2_end |
||
83 | shr eax,16 |
||
84 | cmp ax,SIZE_X-1 |
||
85 | jg .gt_loop2_end |
||
86 | shr ebx,16 |
||
87 | cmp bx,SIZE_X-1 |
||
88 | jg .gt_loop2_end |
||
89 | shr ecx,16 |
||
90 | cmp cx,SIZE_X-1 |
||
91 | jg .gt_loop2_end |
||
92 | |||
93 | |||
94 | mov bx,.y2 ; calc deltas |
||
95 | sub bx,.y1 |
||
96 | jnz .gt_dx12_make |
||
97 | mov .dx12,0 |
||
98 | mov .dc12r,0 |
||
99 | mov .dc12g,0 |
||
100 | mov .dc12b,0 |
||
101 | jmp .gt_dx12_done |
||
102 | .gt_dx12_make: |
||
103 | |||
104 | mov ax,.x2 |
||
105 | sub ax,.x1 |
||
106 | cwde |
||
107 | movsx ebx,bx |
||
108 | shl eax,ROUND |
||
109 | cdq |
||
110 | idiv ebx |
||
111 | mov .dx12,eax |
||
112 | |||
113 | mov ax,word[.col2r] |
||
114 | sub ax,word[.col1r] |
||
115 | cwde |
||
116 | shl eax,ROUND |
||
117 | cdq |
||
118 | idiv ebx |
||
119 | mov .dc12r,eax |
||
120 | mov ax,word[.col2g] |
||
121 | sub ax,word[.col1g] |
||
122 | cwde |
||
123 | shl eax,ROUND |
||
124 | cdq |
||
125 | idiv ebx |
||
126 | mov .dc12g,eax |
||
127 | mov ax,word[.col2b] |
||
128 | sub ax,word[.col1b] |
||
129 | cwde |
||
130 | shl eax,ROUND |
||
131 | cdq |
||
132 | idiv ebx |
||
133 | mov .dc12b,eax |
||
134 | .gt_dx12_done: |
||
135 | |||
136 | mov bx,.y3 |
||
137 | sub bx,.y1 |
||
138 | jnz .gt_dx13_make |
||
139 | mov .dx13,0 |
||
140 | mov .dc13r,0 |
||
141 | mov .dc13g,0 |
||
142 | mov .dc13b,0 |
||
143 | jmp .gt_dx13_done |
||
144 | .gt_dx13_make: |
||
145 | mov ax,.x3 |
||
146 | sub ax,.x1 |
||
147 | cwde |
||
148 | movsx ebx,bx |
||
149 | shl eax,ROUND |
||
150 | cdq |
||
151 | idiv ebx |
||
152 | mov .dx13,eax |
||
153 | |||
154 | mov ax,word[.col3r] |
||
155 | sub ax,word[.col1r] |
||
156 | cwde |
||
157 | shl eax,ROUND |
||
158 | cdq |
||
159 | idiv ebx |
||
160 | mov .dc13r,eax |
||
161 | mov ax,word[.col3g] |
||
162 | sub ax,word[.col1g] |
||
163 | cwde |
||
164 | shl eax,ROUND |
||
165 | cdq |
||
166 | idiv ebx |
||
167 | mov .dc13g,eax |
||
168 | mov ax,word[.col3b] |
||
169 | sub ax,word[.col1b] |
||
170 | cwde |
||
171 | shl eax,ROUND |
||
172 | cdq |
||
173 | idiv ebx |
||
174 | mov .dc13b,eax |
||
175 | .gt_dx13_done: |
||
176 | |||
177 | mov bx,.y3 |
||
178 | sub bx,.y2 |
||
179 | jnz .gt_dx23_make |
||
180 | mov .dx23,0 |
||
181 | mov .dc23r,0 |
||
182 | mov .dc23g,0 |
||
183 | mov .dc23b,0 |
||
184 | jmp .gt_dx23_done |
||
185 | .gt_dx23_make: |
||
186 | mov ax,.x3 |
||
187 | sub ax,.x2 |
||
188 | cwde |
||
189 | movsx ebx,bx |
||
190 | shl eax,ROUND |
||
191 | cdq |
||
192 | idiv ebx |
||
193 | mov .dx23,eax |
||
194 | |||
195 | mov ax,word[.col3r] |
||
196 | sub ax,word[.col2r] |
||
197 | cwde |
||
198 | shl eax,ROUND |
||
199 | cdq |
||
200 | idiv ebx |
||
201 | mov .dc23r,eax |
||
202 | mov ax,word[.col3g] |
||
203 | sub ax,word[.col2g] |
||
204 | cwde |
||
205 | shl eax,ROUND |
||
206 | cdq |
||
207 | idiv ebx |
||
208 | mov .dc23g,eax |
||
209 | mov ax,word[.col3b] |
||
210 | sub ax,word[.col2b] |
||
211 | cwde |
||
212 | shl eax,ROUND |
||
213 | cdq |
||
214 | idiv ebx |
||
215 | mov .dc23b,eax |
||
216 | .gt_dx23_done: |
||
217 | |||
218 | movsx eax,.x1 |
||
219 | shl eax,ROUND |
||
220 | mov ebx,eax |
||
221 | movsx edx,word[.col1r] |
||
222 | shl edx,ROUND |
||
223 | mov .c1r,edx |
||
224 | mov .c2r,edx |
||
225 | movsx edx,word[.col1g] |
||
226 | shl edx,ROUND |
||
227 | mov .c1g,edx |
||
228 | mov .c2g,edx |
||
229 | movsx edx,word[.col1b] |
||
230 | shl edx,ROUND |
||
231 | mov .c1b,edx |
||
232 | mov .c2b,edx |
||
233 | mov cx,.y1 |
||
234 | cmp cx,.y2 |
||
235 | jge .gt_loop1_end |
||
236 | .gt_loop1: |
||
237 | push eax ; eax - cur x1 |
||
238 | push ebx ; ebx - cur x2 |
||
239 | push cx ; cx - cur y |
||
240 | push edi |
||
241 | push ebp |
||
242 | |||
243 | mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors |
||
244 | sar edx,ROUND |
||
245 | push dx |
||
246 | mov edx,.c2g |
||
247 | sar edx,ROUND |
||
248 | push dx |
||
249 | mov edx,.c2b |
||
250 | sar edx,ROUND |
||
251 | push dx |
||
252 | mov edx,.c1r |
||
253 | sar edx,ROUND |
||
254 | push dx |
||
255 | mov edx,.c1g |
||
256 | sar edx,ROUND |
||
257 | push dx |
||
258 | mov edx,.c1b |
||
259 | sar edx,ROUND |
||
260 | push dx |
||
261 | push cx |
||
262 | sar ebx,ROUND |
||
263 | push bx |
||
264 | sar eax,ROUND |
||
265 | push ax |
||
266 | call gouraud_line |
||
267 | |||
268 | pop ebp |
||
269 | pop edi |
||
270 | pop cx |
||
271 | pop ebx |
||
272 | pop eax |
||
273 | |||
274 | mov edx,.dc13r |
||
275 | add .c1r,edx |
||
276 | mov edx,.dc13g |
||
277 | add .c1g,edx |
||
278 | mov edx,.dc13b |
||
279 | add .c1b,edx |
||
280 | mov edx,.dc12r |
||
281 | add .c2r,edx |
||
282 | mov edx,.dc12g |
||
283 | add .c2g,edx |
||
284 | mov edx,.dc12b |
||
285 | add .c2b,edx |
||
286 | |||
287 | add eax,.dx13 |
||
288 | add ebx,.dx12 |
||
289 | inc cx |
||
290 | cmp cx,.y2 |
||
291 | jl .gt_loop1 |
||
292 | .gt_loop1_end: |
||
293 | |||
294 | mov cx,.y2 |
||
295 | cmp cx,.y3 |
||
296 | jge .gt_loop2_end |
||
297 | movsx ebx,.x2 |
||
298 | shl ebx,ROUND |
||
299 | |||
300 | movsx edx,word[.col2r] |
||
301 | shl edx,ROUND |
||
302 | mov .c2r,edx |
||
303 | movsx edx,word[.col2g] |
||
304 | shl edx,ROUND |
||
305 | mov .c2g,edx |
||
306 | movsx edx,word[.col2b] |
||
307 | shl edx,ROUND |
||
308 | mov .c2b,edx |
||
309 | .gt_loop2: |
||
310 | push eax ; eax - cur x1 |
||
311 | push ebx ; ebx - cur x2 |
||
312 | push cx |
||
313 | push edi |
||
314 | push ebp |
||
315 | |||
316 | mov edx,.c2r |
||
317 | sar edx,ROUND |
||
318 | push dx |
||
319 | mov edx,.c2g |
||
320 | sar edx,ROUND |
||
321 | push dx |
||
322 | mov edx,.c2b |
||
323 | sar edx,ROUND |
||
324 | push dx |
||
325 | mov edx,.c1r |
||
326 | sar edx,ROUND |
||
327 | push dx |
||
328 | mov edx,.c1g |
||
329 | sar edx,ROUND |
||
330 | push dx |
||
331 | mov edx,.c1b |
||
332 | sar edx,ROUND |
||
333 | push dx |
||
334 | push cx |
||
335 | sar ebx,ROUND |
||
336 | push bx |
||
337 | sar eax,ROUND |
||
338 | push ax |
||
339 | call gouraud_line |
||
340 | |||
341 | pop ebp |
||
342 | pop edi |
||
343 | pop cx |
||
344 | pop ebx |
||
345 | pop eax |
||
346 | |||
347 | mov edx,.dc13r |
||
348 | add .c1r,edx |
||
349 | mov edx,.dc13g |
||
350 | add .c1g,edx |
||
351 | mov edx,.dc13b |
||
352 | add .c1b,edx |
||
353 | mov edx,.dc23r |
||
354 | add .c2r,edx |
||
355 | mov edx,.dc23g |
||
356 | add .c2g,edx |
||
357 | mov edx,.dc23b |
||
358 | add .c2b,edx |
||
359 | |||
360 | add eax,.dx13 |
||
361 | add ebx,.dx23 |
||
362 | inc cx |
||
363 | cmp cx,.y3 |
||
364 | jl .gt_loop2 |
||
365 | .gt_loop2_end: |
||
366 | |||
367 | ; add esp,84 |
||
368 | mov esp,ebp |
||
369 | ret 18 |
||
370 | gouraud_line: |
||
371 | ;-------------in - edi - pointer to screen buffer |
||
372 | ;----------------- stack - another parameters |
||
373 | .x1 equ word [ebp+4] |
||
374 | .x2 equ word [ebp+6] |
||
375 | .y equ word [ebp+8] |
||
376 | .col1b equ ebp+10 |
||
377 | .col1g equ ebp+12 |
||
378 | .col1r equ ebp+14 |
||
379 | .col2b equ ebp+16 |
||
380 | .col2g equ ebp+18 |
||
381 | .col2r equ ebp+20 |
||
382 | .dc_r equ dword[ebp-4] |
||
383 | .dc_g equ dword[ebp-8] |
||
384 | .dc_b equ dword[ebp-12] |
||
385 | mov ebp,esp |
||
386 | |||
387 | mov ax,.y |
||
388 | or ax,ax |
||
389 | jl .gl_quit |
||
390 | cmp ax,SIZE_Y-1 |
||
391 | jg .gl_quit |
||
392 | |||
393 | mov ax,.x1 |
||
394 | cmp ax,.x2 |
||
395 | je .gl_quit |
||
396 | jl .gl_ok |
||
397 | |||
398 | xchg ax,.x2 |
||
399 | mov .x1,ax |
||
400 | mov eax,dword[.col1b] |
||
401 | xchg eax,dword[.col2b] |
||
402 | mov dword[.col1b],eax |
||
403 | mov ax,word[.col1r] |
||
404 | xchg ax,word[.col2r] |
||
405 | mov word[.col1r],ax |
||
406 | .gl_ok: |
||
407 | ; cmp .x1,SIZE_X-1 ;check |
||
408 | ; jg .gl_quit |
||
409 | ; cmp .x2,SIZE_X-1 |
||
410 | ; jl @f |
||
411 | ; mov .x2,SIZE_X-1 |
||
412 | ; @@: |
||
413 | ; cmp .x1,0 |
||
414 | ; jg @f |
||
415 | ; mov .x1,0 |
||
416 | ; @@: |
||
417 | ; cmp .x2,0 |
||
418 | ; jl .gl_quit |
||
419 | |||
420 | movsx ecx,.y |
||
421 | mov eax,SIZE_X*3 |
||
422 | mul ecx |
||
423 | movsx ebx,.x1 |
||
424 | lea ecx,[ebx*2+eax] |
||
425 | add edi,ecx |
||
426 | add edi,ebx |
||
427 | |||
428 | mov ax,word[.col2r] |
||
429 | sub ax,word[.col1r] |
||
430 | cwde |
||
431 | shl eax,ROUND |
||
432 | cdq |
||
433 | mov cx,.x2 |
||
434 | sub cx,.x1 |
||
435 | movsx ecx,cx |
||
436 | idiv ecx |
||
437 | ;mov .dc_r,eax ;first delta |
||
438 | push eax |
||
439 | |||
440 | mov ax,word[.col2g] |
||
441 | sub ax,word[.col1g] |
||
442 | cwde |
||
443 | shl eax,ROUND |
||
444 | cdq |
||
445 | idiv ecx |
||
446 | ;mov .dc_g,eax |
||
447 | push eax |
||
448 | |||
449 | mov ax,word[.col2b] |
||
450 | sub ax,word[.col1b] |
||
451 | cwde |
||
452 | shl eax,ROUND |
||
453 | cdq |
||
454 | idiv ecx |
||
455 | ; mov .dc_b,eax |
||
456 | push eax |
||
457 | |||
458 | movsx ebx,word[.col1r] |
||
459 | shl ebx,ROUND |
||
460 | movsx edx,word[.col1g] |
||
461 | shl edx,ROUND |
||
462 | movsx esi,word[.col1b] |
||
463 | shl esi,ROUND |
||
464 | .gl_draw: |
||
465 | mov eax,ebx |
||
466 | sar eax,ROUND |
||
467 | stosb |
||
468 | mov eax,edx |
||
469 | sar eax,ROUND |
||
470 | stosb |
||
471 | mov eax,esi |
||
472 | sar eax,ROUND |
||
473 | stosb |
||
474 | add ebx,.dc_r |
||
475 | add edx,.dc_g |
||
476 | add esi,.dc_b |
||
477 | loop .gl_draw |
||
478 | .gl_quit: |
||
479 | ; add esp,12 |
||
480 | mov esp,ebp |
||
481 | ret 18 |