Subversion Repositories Kolibri OS

Rev

Rev 6619 | Rev 9237 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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