Subversion Repositories Kolibri OS

Rev

Rev 9237 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9237 leency 1
;TEX_X = 512
2
;TEX_Y = 512
3
;ROUND equ 8
4
;SIZE_X = 512
5
;SIZE_Y = 512
6
;TEX_SHIFT = 9
7
CATMULL_SHIFT equ 8
8
 
9
;------------------------------------------------------------------------
10
;- Procedure drawing textured triangle using Catmull Z-buffer algorithm -
11
;------------------------------------------------------------------------
12
tex_triangle_z:
13
;----------in - eax - x1 shl 16 + y1
14
;-------------- ebx - x2 shl 16 + y2
15
;---------------ecx - x3 shl 16 + y3
16
;---------------edx - pointer to Z-buffer
17
;---------------esi - pointer to texture buffer
18
;---------------edi - pointer to screen buffer
19
;-------------stack - texture coordinates
20
;------------------ - z coordinates
21
.tex_x1 equ  ebp+4
22
.tex_y1 equ  ebp+6
23
.tex_x2 equ  ebp+8
24
.tex_y2 equ  ebp+10
25
.tex_x3 equ  ebp+12
26
.tex_y3 equ  ebp+14
9512 IgorA 27
.z1     equ  word[ebp+16]
28
.z2     equ  word[ebp+18]
29
.z3     equ  word[ebp+20]
9237 leency 30
 
9512 IgorA 31
.tex_ptr equ dword[ebp-4]        ; pointer to texture
32
.z_ptr   equ dword[ebp-8]        ; pointer to z-buffer
33
.x1      equ word[ebp-10]
34
.y1      equ word[ebp-12]
35
.x2      equ word[ebp-14]
36
.y2      equ word[ebp-16]
37
.x3      equ word[ebp-18]
38
.y3      equ word[ebp-20]
9237 leency 39
 
9512 IgorA 40
.dx12     equ dword[ebp-24]
9237 leency 41
.tex_dx12 equ dword[ebp-28]
42
.tex_dy12 equ dword[ebp-32]
9512 IgorA 43
.dz12     equ dword[ebp-36]
9237 leency 44
 
9512 IgorA 45
.dx13     equ dword[ebp-40]
9237 leency 46
.tex_dx13 equ dword[ebp-44]
47
.tex_dy13 equ dword[ebp-48]
9512 IgorA 48
.dz13     equ dword[ebp-52]
9237 leency 49
 
9512 IgorA 50
.dx23     equ dword[ebp-56]
9237 leency 51
.tex_dx23 equ dword[ebp-60]
52
.tex_dy23 equ dword[ebp-64]
9512 IgorA 53
.dz23     equ dword[ebp-68]
9237 leency 54
 
55
.scan_x1  equ dword[ebp-72]
56
.scan_x2  equ dword[ebp-76]
57
.scan_y1  equ dword[ebp-80]
58
.scan_y2  equ dword[ebp-84]
9512 IgorA 59
.cz1      equ dword[ebp-88]
60
.cz2      equ dword[ebp-92]
9237 leency 61
 
9512 IgorA 62
        mov     ebp,esp
63
        push    esi               ; store memory pointers
64
        push    edx
9237 leency 65
.tt_sort3:
9512 IgorA 66
        cmp     ax,bx                     ;sort all parameters
67
        jle     .tt_sort1
68
        xchg    eax,ebx
69
        mov     edx,dword [.tex_x1]
70
        xchg    edx,dword [.tex_x2]
71
        mov     dword[.tex_x1],edx
72
        mov     dx,.z1
73
        xchg    dx,.z2
74
        mov     .z1,dx
9237 leency 75
.tt_sort1:
9512 IgorA 76
        cmp     bx,cx
77
        jle     .tt_sort2
78
        xchg    ebx,ecx
79
        mov     edx,dword [.tex_x2]
80
        xchg    edx,dword [.tex_x3]
81
        mov     dword [.tex_x2],edx
82
        mov     dx,.z2
83
        xchg    dx,.z3
84
        mov     .z2,dx
85
        jmp     .tt_sort3
9237 leency 86
.tt_sort2:
87
 
9512 IgorA 88
        push    eax     ; and store to user friendly variables
89
        push    ebx
90
        push    ecx
9237 leency 91
 
9512 IgorA 92
        mov      edx,80008000h  ; eax,ebx,ecx are ANDd together into edx which means that
93
        and      edx,ebx        ; if *all* of them are negative a sign flag is raised
94
        and      edx,ecx
95
        and      edx,eax
96
        test     edx,80008000h  ; Check both X&Y at once
97
        jne      .tt_loop2_end
9237 leency 98
    ;    cmp      ax,SIZE_Y
99
    ;    jl       @f
100
    ;    cmp      bx,SIZE_Y
101
    ;    jl       @f
102
    ;    cmp      cx,SIZE_Y
103
    ;    jl       @f
9512 IgorA 104
        ror      eax,16
105
        ror      ebx,16
106
        ror      ecx,16
9237 leency 107
    ;    cmp      ax,SIZE_X
108
    ;    jl       @f
109
    ;    cmp      bx,SIZE_X
110
    ;    jl       @f
111
    ;    cmp      cx,SIZE_X
112
    ;    jl       @f
113
    ;    jmp      .tt_loop2_end
114
     @@:
9512 IgorA 115
        mov      eax,dword[.tex_x1] ; texture coords must be in [0..TEX_X(Y)]
116
        mov      ebx,dword[.tex_x2]
117
        mov      ecx,dword[.tex_x3]
118
        mov      edx,eax
119
        or       edx,ebx
120
        or       edx,ecx
121
        test     edx,80008000h
122
        jne      .tt_loop2_end
123
        cmp      ax,TEX_X
124
        jge      .tt_loop2_end
125
        cmp      bx,TEX_X
126
        jge      .tt_loop2_end
127
        cmp      cx,TEX_X
128
        jge      .tt_loop2_end
129
        ror      eax,16
130
        ror      ebx,16
131
        ror      ecx,16
132
        cmp      ax,TEX_Y
133
        jge      .tt_loop2_end
134
        cmp      bx,TEX_Y
135
        jge      .tt_loop2_end
136
        cmp      cx,TEX_Y
137
        jge      .tt_loop2_end
9237 leency 138
 
139
 
9512 IgorA 140
        movsx    ebx,.y2    ; calc delta
141
        sub      bx,.y1
142
        jnz      .tt_dx12_make
143
        xor      edx,edx
144
        mov      ecx,4
9237 leency 145
    @@:
9512 IgorA 146
        push     edx
147
        loop     @b
148
        jmp      .tt_dx12_done
9237 leency 149
    .tt_dx12_make:
9512 IgorA 150
        mov      ax,.x2
151
        sub      ax,.x1
152
        cwde
153
        shl      eax,ROUND
154
        cdq
155
        idiv     ebx
9237 leency 156
       ; mov      .dx12,eax                      ; dx12 = (x2-x1)/(y2-y1)
9512 IgorA 157
        push     eax
9237 leency 158
 
9512 IgorA 159
        mov      ax,word[.tex_x2]
160
        sub      ax,word[.tex_x1]
161
        cwde
162
        shl      eax,ROUND
163
        cdq
164
        idiv     ebx
9237 leency 165
       ; mov     [.tex_dx12],eax               ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1)
9512 IgorA 166
        push     eax
9237 leency 167
 
9512 IgorA 168
        mov      ax,word[.tex_y2]
169
        sub      ax,word[.tex_y1]
170
        cwde
171
        shl      eax,ROUND
172
        cdq
173
        idiv     ebx
9237 leency 174
     ;   mov    [.tex_dy12],eax              ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1)
9512 IgorA 175
        push     eax
9237 leency 176
 
9512 IgorA 177
        mov      ax,.z2
178
        sub      ax,.z1
179
        cwde
180
        shl      eax,CATMULL_SHIFT
181
        cdq
182
        idiv     ebx
183
        push     eax
9237 leency 184
   .tt_dx12_done:
185
 
9512 IgorA 186
        movsx    ebx,.y3    ; calc delta
187
        sub      bx,.y1
188
        jnz      .tt_dx13_make
189
        xor      edx,edx
190
        mov      ecx,4
9237 leency 191
    @@:
9512 IgorA 192
        push     edx
193
        loop     @b
194
        jmp      .tt_dx13_done
9237 leency 195
    .tt_dx13_make:
9512 IgorA 196
        mov      ax,.x3
197
        sub      ax,.x1
198
        cwde
199
        shl      eax,ROUND
200
        cdq
201
        idiv     ebx
9237 leency 202
       ; mov      .dx12,eax                      ; dx13 = (x3-x1)/(y3-y1)
9512 IgorA 203
        push      eax
9237 leency 204
 
9512 IgorA 205
        mov      ax,word[.tex_x3]
206
        sub      ax,word[.tex_x1]
207
        cwde
208
        shl      eax,ROUND
209
        cdq
210
        idiv     ebx
9237 leency 211
       ; mov     [.tex_dx12],eax               ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1)
9512 IgorA 212
        push     eax
9237 leency 213
 
9512 IgorA 214
        mov      ax,word[.tex_y3]
215
        sub      ax,word[.tex_y1]
216
        cwde
217
        shl      eax,ROUND
218
        cdq
219
        idiv     ebx
9237 leency 220
     ;   mov    [.tex_dy12],eax              ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1)
9512 IgorA 221
        push     eax
9237 leency 222
 
9512 IgorA 223
        mov      ax,.z3
224
        sub      ax,.z1
225
        cwde
226
        shl      eax,CATMULL_SHIFT
227
        cdq
228
        idiv     ebx
229
        push     eax
9237 leency 230
   .tt_dx13_done:
231
 
9512 IgorA 232
        mov      bx,.y3    ; calc delta
233
        sub      bx,.y2
234
        jnz      .tt_dx23_make
235
        xor      edx,edx
236
        mov      ecx,4
9237 leency 237
    @@:
9512 IgorA 238
        push     edx
239
        loop     @b
240
        jmp      .tt_dx23_done
9237 leency 241
    .tt_dx23_make:
9512 IgorA 242
        mov      ax,.x3
243
        sub      ax,.x2
244
        cwde
245
        shl      eax,ROUND
246
        cdq
247
        movzx    ebx,bx
248
        idiv     ebx
9237 leency 249
       ; mov      .dx23,eax                      ; dx23 = (x3-x2)/(y3-y2)
9512 IgorA 250
        push      eax
9237 leency 251
 
9512 IgorA 252
        mov      ax,word[.tex_x3]
253
        sub      ax,word[.tex_x2]
254
        cwde
255
        shl      eax,ROUND
256
        cdq
257
        idiv     ebx
9237 leency 258
       ; mov     [.tex_dx23],eax               ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2)
9512 IgorA 259
        push     eax
9237 leency 260
 
9512 IgorA 261
        mov      ax,word[.tex_y3]
262
        sub      ax,word[.tex_y2]
263
        cwde
264
        shl      eax,ROUND
265
        cdq
266
        idiv     ebx
9237 leency 267
     ;   mov    [.tex_dy23],eax              ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2)
9512 IgorA 268
        push     eax
9237 leency 269
 
9512 IgorA 270
        mov      ax,.z3
271
        sub      ax,.z2
272
        cwde
273
        shl      eax,CATMULL_SHIFT
274
        cdq
275
        idiv     ebx
276
        push     eax
9237 leency 277
   .tt_dx23_done:
278
 
9512 IgorA 279
        movsx    eax,.x1     ;eax - cur x1
280
        shl      eax,ROUND   ;ebx - cur x2
281
        mov      ebx,eax
9237 leency 282
 
9512 IgorA 283
        movsx    edx, word[.tex_x1]
284
        shl      edx,ROUND
9237 leency 285
      ;  mov [.scan_x1],edx
286
      ;  mov [.scan_x2],edx
9512 IgorA 287
        push     edx
288
        push     edx
289
        movsx    edx, word[.tex_y1]
290
        shl      edx,ROUND
9237 leency 291
       ; mov [.scan_y1],edx
292
       ; mov [.scan_y2],edx
9512 IgorA 293
        push     edx
294
        push     edx
295
        movsx    edx,.z1
296
        shl      edx,CATMULL_SHIFT
297
        push     edx
298
        push     edx
299
        mov      cx,.y1
300
        cmp      cx,.y2
301
        jge      .tt_loop1_end
9237 leency 302
 
303
   .tt_loop1:
9512 IgorA 304
        pushad
9237 leency 305
 
9512 IgorA 306
        push    .z_ptr
307
        push    .cz1      ; z coords shifted shl catmull_shift
308
        push    .cz2
309
        push    .scan_y2
310
        push    .scan_x2
311
        push    .scan_y1
312
        push    .scan_x1
313
        push    esi               ;[.tex_ptr]
9237 leency 314
 
9512 IgorA 315
        push    cx
316
        sar     ebx,ROUND
317
        push    bx
318
        sar     eax,ROUND
319
        push    ax
320
        call    textured_line_z
9237 leency 321
 
9512 IgorA 322
        popad
323
        mov     edx,.dz13
324
        add     .cz1,edx
325
        mov     edx,.dz12
326
        add     .cz2,edx
9237 leency 327
 
9512 IgorA 328
        mov     edx, .tex_dx13
329
        add     .scan_x1, edx
330
        mov     edx, .tex_dx12
331
        add     .scan_x2, edx
332
        mov     edx, .tex_dy13
333
        add     .scan_y1, edx
334
        mov     edx, .tex_dy12
335
        add     .scan_y2, edx
9237 leency 336
 
9512 IgorA 337
        add     eax, .dx13
338
        add     ebx, .dx12
339
        inc     cx
340
        cmp     cx,.y2
341
        jl      .tt_loop1
9237 leency 342
 
343
  .tt_loop1_end:
344
 
345
 
9512 IgorA 346
        mov     cx,.y2
347
        cmp     cx,.y3
348
        jge     .tt_loop2_end
9237 leency 349
 
9512 IgorA 350
        movsx   ebx,.x2
351
        shl     ebx,ROUND
352
        movsx   edx,.z2
353
        shl     edx,CATMULL_SHIFT
354
        mov     .cz2,edx
355
        movzx   edx, word [.tex_x2]
356
        shl     edx,ROUND
357
        mov     .scan_x2,edx
358
        movzx   edx, word[.tex_y2]
359
        shl     edx,ROUND
360
        mov     .scan_y2,edx
9237 leency 361
 
362
.tt_loop2:
363
 
9512 IgorA 364
        pushad
9237 leency 365
 
9512 IgorA 366
        push    .z_ptr
367
        push    .cz1      ; z coords shifted shl catmull_shift
368
        push    .cz2
9237 leency 369
 
9512 IgorA 370
        push    .scan_y2
371
        push    .scan_x2
372
        push    .scan_y1
373
        push    .scan_x1
374
        push    esi               ;[.tex_ptr]
9237 leency 375
 
9512 IgorA 376
        push    cx
377
        sar     ebx,ROUND
378
        push    bx
379
        sar     eax,ROUND
380
        push    ax
381
        call    textured_line_z
9237 leency 382
 
9512 IgorA 383
        popad
9237 leency 384
 
385
 
9512 IgorA 386
        mov     edx,.dz13
387
        add     .cz1,edx
388
        mov     edx,.dz23
389
        add     .cz2,edx
9237 leency 390
 
9512 IgorA 391
        mov     edx, .tex_dx13
392
        add     .scan_x1, edx
393
        mov     edx, .tex_dx23
394
        add     .scan_x2, edx
395
        mov     edx, .tex_dy13
396
        add     .scan_y1, edx
397
        mov     edx, .tex_dy23
398
        add     .scan_y2, edx
9237 leency 399
 
9512 IgorA 400
        add     eax, .dx13
401
        add     ebx, .dx23
402
        inc     cx
403
        cmp     cx,.y3
404
        jl      .tt_loop2
9237 leency 405
 
406
.tt_loop2_end:
407
 
408
.tt_end:
9512 IgorA 409
        mov esp,ebp
9237 leency 410
ret 18
411
 
412
textured_line_z:
413
;-----in -edi screen buffer pointer
414
;------------ stack:
415
  .x1 equ word [ebp+4]
416
  .x2 equ word [ebp+6]
417
  .y  equ word [ebp+8]
418
 
419
  .tex_ptr equ dword [ebp+10]
420
  .tex_x1  equ ebp+14
421
  .tex_y1  equ ebp+18
422
  .tex_x2  equ ebp+22
423
  .tex_y2  equ ebp+26
9512 IgorA 424
  .z2      equ dword [ebp+30]     ;z1, z2  coords shifted shl CATMULL_SHIFT
425
  .z1      equ dword [ebp+34]
9237 leency 426
  .z_ptr   equ dword [ebp+38]
427
 
428
  .tex_dy  equ dword [ebp-4]
429
  .tex_dx  equ dword [ebp-8]
9512 IgorA 430
  .dz      equ dword [ebp-12]
431
  .cz      equ dword [ebp-16]
9237 leency 432
  .c_tex_x equ dword [ebp-20]  ; current tex x
433
  .m_sft1 equ ebp-28
434
  .m_sft2 equ ebp-32
435
;  .c_tex_xM equ ebp+14
436
  .tex_dxM  equ ebp-8
437
 
9512 IgorA 438
        mov     ebp,esp
9237 leency 439
 
9512 IgorA 440
        mov     ax,.y
441
        or      ax,ax
442
        jl      .tl_quit
443
        mov     bx,[size_y_var]
444
        dec     bx
445
        cmp     ax,bx  ;SIZE_Y
446
        jge     .tl_quit
9237 leency 447
 
9512 IgorA 448
        mov     ax,.x1
449
        cmp     ax,.x2
450
        je      .tl_quit
451
        jl      .tl_ok
9237 leency 452
 
9512 IgorA 453
        xchg    ax,.x2    ; sort params
454
        mov     .x1,ax
455
if Ext >= SSE2
456
        movdqu  xmm0,[.tex_x1]
457
        pshufd  xmm0,xmm0,01001110b
458
        movdqu  [.tex_x1],xmm0
459
else if Ext >= MMX
460
        movq    mm0,[.tex_x1]
461
        movq    mm1,[.tex_x2]
462
        movq    [.tex_x2],mm0
463
        movq    [.tex_x1],mm1
9237 leency 464
 
465
else
9512 IgorA 466
        mov     eax,dword[.tex_x1]
467
        xchg    eax,dword[.tex_x2]
468
        mov     dword[.tex_x1],eax
9237 leency 469
 
9512 IgorA 470
        mov     eax,dword[.tex_y1]
471
        xchg    eax,dword[.tex_y2]
472
        mov     dword[.tex_y1],eax
9237 leency 473
 
474
end if
475
 
9512 IgorA 476
        mov     eax,.z1
477
        xchg    eax,.z2
478
        mov     .z1,eax
9237 leency 479
 
480
     .tl_ok:
9512 IgorA 481
        mov     cx,[size_x_var]
482
        dec     cx
483
        cmp     .x1,cx   ;SIZE_X
484
        jge     .tl_quit
485
        cmp     .x2,0
486
        jle     .tl_quit
9237 leency 487
 
9512 IgorA 488
        mov     bx,.x2
489
        sub     bx,.x1
490
        movsx   ebx,bx
9237 leency 491
 
9512 IgorA 492
        mov     eax,dword[.tex_y2]       ; calc .dty
493
        sub     eax,dword[.tex_y1]
494
        cdq
495
        idiv    ebx
496
        push    eax
9237 leency 497
 
9512 IgorA 498
        mov     eax,dword[.tex_x2]       ; calc .dtx
499
        sub     eax,dword[.tex_x1]
500
        cdq
501
        idiv    ebx
502
        push    eax
9237 leency 503
 
9512 IgorA 504
        mov     eax,.z2       ; calc .dz
505
        sub     eax,.z1
506
        cdq
507
        idiv    ebx
508
        push    eax
9237 leency 509
 
9512 IgorA 510
        cmp    .x1,0          ; clipping
511
        jg     @f
9237 leency 512
 
9512 IgorA 513
        movsx   ebx,.x1
514
        neg     ebx
515
        imul    ebx           ; eax = .dz * abs(.x1)
516
        add     .z1,eax
517
        mov     .x1,0
9237 leency 518
 
9512 IgorA 519
        mov     eax,.tex_dy
520
        imul    ebx
521
        add     dword[.tex_y1],eax
9237 leency 522
 
9512 IgorA 523
        mov     eax,.tex_dx
524
        imul    ebx
525
        add     dword[.tex_x1],eax
9237 leency 526
 
527
      @@:
9512 IgorA 528
        cmp     .x2,cx ;SIZE_X
529
        jl      @f
530
        mov     .x2,cx  ;SIZE_X
9237 leency 531
      @@:
532
 
9512 IgorA 533
        movsx   ebx,.y        ; calc mem begin in buffers
534
        movzx   eax,word[size_x_var]  ;SIZE_X
535
        mul     ebx
536
        movsx   ebx,.x1
537
        add     eax,ebx
538
        mov     ebx,eax
9237 leency 539
 
9512 IgorA 540
        lea     eax,[eax*3]
541
        add     edi,eax               ; edi - scr buff
542
        shl     ebx,2
543
        add     .z_ptr,ebx            ; z buffer pointer
9237 leency 544
 
9512 IgorA 545
        mov     cx,.x2
546
        sub     cx,.x1
547
        movzx   ecx,cx
9237 leency 548
 
549
;if Ext >= MMX
550
;        movq    mm0,[.tex_x1]
551
;        movq    mm4,mm0
552
;        movq    mm1,qword[.tex_dxM]
553
;        mov     ebx,.z1
554
;        mov     eax,.dz
555
;else
9512 IgorA 556
        mov     eax,dword[.tex_x1]
557
        mov     ebx,dword[.tex_y1]
558
        push    .z1           ; .cz
559
        push    eax           ;.c_tex_x
9237 leency 560
;end if
9512 IgorA 561
        mov     edx,.z_ptr
9237 leency 562
 
563
     .tl_loop:
564
 
565
;if Ext >= MMX
566
;        cmp     ebx,[edx]                       ;  ebx - current z
567
;        jge     @f
568
;        movq    mm2,mm0
569
;        psrad   mm2,ROUND
570
;        movq    mm3,mm2
571
;        psrlq   mm2,32-TEX_SHIFT
572
;        paddd   mm3,mm2
573
;        movd    esi,mm3
574
;        mov     dword[edx],ebx    ; renew z buffer
575
;else
9512 IgorA 576
                                                        ;  eax - temp
577
        mov     eax,.cz                         ;  ebx - cur tex y shl ROUND
578
        cmp     eax,[edx]                       ;  ecx - l.lenght
579
        jge     @f         ; ebx - cur tex_y ;  edx - temp
580
        mov     esi,ebx                 ;  edi - scr buff
581
        sar     esi,ROUND               ;  esi - tex_ptr temp
582
        shl     esi,TEX_SHIFT           ;  .z_ptr - cur pointer to z buff
583
        mov     eax,.c_tex_x            ;  .cz - cur z coord shl CATMULL_SHIFT
584
        sar     eax,ROUND
585
        add     esi,eax
586
        mov     eax,.cz
587
        mov     dword[edx],eax    ; renew z buffer
9237 leency 588
;end if
9512 IgorA 589
        and     esi,TEXTURE_SIZE
590
        lea     esi,[esi*3]
591
        add     esi,.tex_ptr
592
        movsd
593
        dec     edi
594
        jmp     .no_skip
9237 leency 595
      @@:
9512 IgorA 596
        add     edi,3
9237 leency 597
     .no_skip:
9512 IgorA 598
        add     edx,4
9237 leency 599
;if Ext >= MMX
600
;        add     ebx,eax
601
;        paddd   mm0,mm1
602
;else
9512 IgorA 603
        mov     eax,.dz
604
        add     .cz,eax
605
        mov     eax,.tex_dx
606
        add     .c_tex_x,eax
607
        add     ebx,.tex_dy
9237 leency 608
;end if
9512 IgorA 609
        loop    .tl_loop
9237 leency 610
 .tl_quit:
611
 
9512 IgorA 612
        mov     esp,ebp
9237 leency 613
 
614
ret 30+8
615