Subversion Repositories Kolibri OS

Rev

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