Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1245 hidnplayr 1
 
2
;SIZE_Y equ 350
3
;ROUND equ 8
4
;TEX_X equ 512
5
;TEX_Y equ 512
6
;TEXTURE_SIZE EQU (512*512)-1
7
;TEX_SHIFT EQU 9
8
9
 
10
;TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1
11
;Ext = SSE
12
;SSE = 3
13
;MMX = 1
14
;NON = 0
15
;use32
16
;------- Big thanks to Majuma (www.majuma.xt.pl) for absolutely great---
17
;------- DOS 13h mode demos --------------------------------------------
18
;------- Procedure draws triangle with two overlapped textures, I use --
19
;--------Catmull Z-buffer algorithm- (Z coordinate interpolation)-------
20
;--------I calc texture pixel by this way: col1*col2/256 ---------------
21
two_tex_triangle_z:
22
;------------------in - eax - x1 shl 16 + y1 -----------
23
;---------------------- ebx - x2 shl 16 + y2 -----------
24
;---------------------- ecx - x3 shl 16 + y3 -----------
25
;---------------------- edx - pointer to b. texture-----
26
;---------------------- esi - pointer to e. texture-----
27
;---------------------- edi - pointer to screen buffer--
28
;---------------------- stack : b. tex coordinates------
29
;----------------------         e. tex coordinates------
30
;----------------------         Z position coordinates--
31
;----------------------         pointer io Z buffer-----
32
;-- Z-buffer - filled with coordinates as dword --------
33
;-- (Z coor. as word) shl CATMULL_SHIFT ----------------
34
.b_x1   equ ebp+4   ; procedure don't save registers !!!
2192 leency 35
.b_y1   equ ebp+6   ; each coordinate as word
36
.b_x2   equ ebp+8
37
.b_y2   equ ebp+10       ; b - first texture
38
.b_x3   equ ebp+12
39
.b_y3   equ ebp+14       ; e - second texture
40
.e_x1   equ ebp+16
41
.e_y1   equ ebp+18
42
.e_x2   equ ebp+20
43
.e_y2   equ ebp+22
44
.e_x3   equ ebp+24
45
.e_y3   equ ebp+26
46
.z1     equ word[ebp+28]
47
.z2     equ word[ebp+30]
48
.z3     equ word[ebp+32]
49
.z_buff equ dword[ebp+34]       ; pointer to Z-buffer
50
1245 hidnplayr 51
 
52
 
2192 leency 53
.t_emap equ dword[ebp-8]        ; pointer to e. texture
54
.x1     equ word[ebp-10]
55
.y1     equ word[ebp-12]
56
.x2     equ word[ebp-14]
57
.y2     equ word[ebp-16]
58
.x3     equ word[ebp-18]
59
.y3     equ word[ebp-20]
60
1245 hidnplayr 61
 
62
.dbx12 equ dword[ebp-28]
63
.dby12 equ dword[ebp-32]
64
.dby12q equ     [ebp-32]
2192 leency 65
.dex12 equ dword[ebp-36]
1245 hidnplayr 66
.dey12 equ dword[ebp-40]
67
.dey12q equ     [ebp-40]
2192 leency 68
.dz12  equ dword[ebp-44]
1245 hidnplayr 69
70
 
71
.dbx13 equ dword[ebp-52]
72
.dby13 equ dword[ebp-56]
73
.dby13q equ     [ebp-56]
2192 leency 74
.dex13 equ dword[ebp-60]
1245 hidnplayr 75
.dey13 equ dword[ebp-64]
76
.dey13q equ     [ebp-64]
2192 leency 77
.dz13  equ dword[ebp-68]
1245 hidnplayr 78
79
 
80
.dbx23 equ dword[ebp-76]
81
.dby23 equ dword[ebp-80]
82
.dby23q equ     [ebp-80]
2192 leency 83
.dex23 equ dword[ebp-84]
1245 hidnplayr 84
.dey23 equ dword[ebp-88]
85
.dey23q equ     [ebp-88]
2192 leency 86
.dz23  equ dword[ebp-92]
1245 hidnplayr 87
88
 
89
.cx2   equ dword[ebp-100]
90
.cbx1  equ dword[ebp-104]
91
.cby1  equ [ebp-108]
92
.cex1  equ dword[ebp-112]
2192 leency 93
.cey1  equ [ebp-116]
94
.cbx2  equ dword[ebp-120]
95
.cby2  equ [ebp-124]
96
.cex2  equ dword[ebp-128]
1245 hidnplayr 97
.cey2  equ [ebp-132]
98
99
 
100
.cz2   equ dword[ebp-140]
101
102
 
103
       emms
104
    else
105
       cld
106
    end if
107
       mov     ebp,esp
108
       push    edx esi       ; store bump map
2192 leency 109
;       push    esi        ; store e. map
1245 hidnplayr 110
     ; sub     esp,120
111
 .sort3:                  ; sort triangle coordinates...
2192 leency 112
       cmp     ax,bx
1245 hidnplayr 113
       jle     .sort1
114
       xchg    eax,ebx
115
       mov     edx,dword[.b_x1]
116
       xchg    edx,dword[.b_x2]
117
       mov     dword[.b_x1],edx
118
       mov     edx,dword[.e_x1]
119
       xchg    edx,dword[.e_x2]
120
       mov     dword[.e_x1],edx
121
       mov     dx,.z1
122
       xchg    dx,.z2
123
       mov     .z1,dx
124
 .sort1:
125
       cmp      bx,cx
2192 leency 126
       jle      .sort2
127
       xchg     ebx,ecx
128
       mov      edx,dword[.b_x2]
129
       xchg     edx,dword[.b_x3]
130
       mov      dword[.b_x2],edx
131
       mov      edx,dword[.e_x2]
132
       xchg     edx,dword[.e_x3]
133
       mov      dword[.e_x2],edx
134
       mov     dx,.z2
1245 hidnplayr 135
       xchg    dx,.z3
136
       mov     .z2,dx
137
       jmp      .sort3
2192 leency 138
 .sort2:
1245 hidnplayr 139
       push     eax ebx ecx    ; store triangle coords in variables
2192 leency 140
;       push     ebx
1245 hidnplayr 141
;       push     ecx
142
143
 
2192 leency 144
         and      edx,ebx        ; if *all* of them are negative a sign flag is raised
145
         and      edx,ecx
146
         and      edx,eax
147
         test     edx,80008000h  ; Check both X&Y at once
148
         jne      .loop23_done
149
    ;   mov     edx,eax         ; eax,ebx,ecx are ORd together into edx which means that
1245 hidnplayr 150
    ;   or      edx,ebx         ; if any *one* of them is negative a sign flag is raised
151
    ;   or      edx,ecx
152
    ;   test    edx,80000000h   ; Check only X
153
    ;   jne     .loop23_done
154
155
 
156
    ;   jg      .loop23_done
157
    ;   cmp     .x2,SIZE_X     ; This can be optimized with effort
158
    ;   jg      .loop23_done
159
    ;   cmp     .x3,SIZE_X
160
    ;   jg      .loop23_done    ; {
161
162
 
163
 
2192 leency 164
       sub      bx,.y1
165
       jnz      .bt_dx12_make
166
       mov      ecx,6
167
       xor      edx,edx
168
     @@:
1245 hidnplayr 169
       push     edx   ;dword 0
2192 leency 170
       loop     @b
171
       jmp      .bt_dx12_done
172
 .bt_dx12_make:
1245 hidnplayr 173
       mov      ax,.x2
2192 leency 174
       sub      ax,.x1
175
       cwde
1245 hidnplayr 176
       movsx    ebx,bx
2192 leency 177
       shl      eax,ROUND
178
       cdq
1245 hidnplayr 179
       idiv     ebx
2192 leency 180
;      mov      .dx12,eax
1245 hidnplayr 181
       push      eax
2192 leency 182
1245 hidnplayr 183
 
184
185
 
2192 leency 186
       cvtsi2ss  xmm3,ebx            ;rcps
187
    ;   mov       eax,255
1245 hidnplayr 188
       cvtsi2ss  xmm4,[i255d] ;eax
189
       divss     xmm3,xmm4
2192 leency 190
       rcpss     xmm3,xmm3
191
    ;   mulss     xmm3,xmm4
1245 hidnplayr 192
       shufps    xmm3,xmm3,0
2192 leency 193
1245 hidnplayr 194
 
2192 leency 195
       movd      mm1,[.b_x2]
196
       movd      mm2,[.e_x1]
197
       movd      mm3,[.e_x2]
198
     ;  psubsw    mm3,mm2
1245 hidnplayr 199
     ;  psubsw    mm1,mm0
200
       pxor      mm4,mm4
2192 leency 201
       punpcklwd mm0,mm4
1245 hidnplayr 202
       punpcklwd mm1,mm4
203
       punpcklwd mm2,mm4
204
       punpcklwd mm3,mm4
205
   ;    pslld     mm0,ROUND
206
   ;    pslld     mm1,ROUND
207
   ;    pslld     mm2,ROUND
208
   ;    pslld     mm3,ROUND
209
       cvtpi2ps  xmm0,mm0
210
       movlhps   xmm0,xmm0
2192 leency 211
       cvtpi2ps  xmm0,mm2
1245 hidnplayr 212
       cvtpi2ps  xmm1,mm1
213
       movlhps   xmm1,xmm1
2192 leency 214
       cvtpi2ps  xmm1,mm3
1245 hidnplayr 215
       subps     xmm1,xmm0
2192 leency 216
1245 hidnplayr 217
 
218
     ;  movq      mm5,mm1
219
     ;  movq      mm6,mm1
220
     ;  pcmpeqb   mm5,mm4
221
;       psubd     mm1,mm0
222
;       psubd     mm3,mm2
223
224
 
225
    ;   movq      mm1,[.e_x1]      ; ex1  ey1   ex2    ey2
226
    ;   pxor
227
    ;   punpcklhd mm0,mm1   ; lwd  ;
228
    ;   psubw     mm1,mm0   ; mm1, mm0
229
    ;   pxor      mm2,mm2
230
  ;     pmovmaskb eax,mm1
231
  ;     and       eax,10101010b
232
    ;   pcmpgtw   mm2,mm1
233
    ;   punpcklwd mm1,mm2
234
 ;      psllw     mm0,ROUND
235
 ;      psllw     mm1,ROUND
236
 ;      movq      mm2,mm0
237
 ;      psrlq     mm0,32
238
239
 
240
;       movlhps   xmm0,xmm0
241
;       cvtpi2ps  xmm0,mm3
242
  ;     divps     xmm1,xmm3
243
       mulps     xmm1,xmm3
2192 leency 244
       shufps    xmm1,xmm1,10110001b
245
       cvtps2pi  mm0,xmm1          ; mm0 -> 2 delta dwords
246
       movhlps   xmm1,xmm1
247
       cvtps2pi  mm1,xmm1
1245 hidnplayr 248
       movq      .dey12q,mm0
2192 leency 249
       movq      .dby12q,mm1
250
1245 hidnplayr 251
 
252
;       psrlq     mm0,32
253
;       movd      .dey12,mm0
254
;       movhlps   xmm1,xmm1
255
;       cvtps2pi  mm0,xmm1
256
;       movd      .dbx12,mm0
257
;       psrlq     mm0,32
258
;       movd      .dby12,mm0
259
260
 
261
       mov      ax,word[.b_x2]
2192 leency 262
       sub      ax,word[.b_x1]
263
       cwde
1245 hidnplayr 264
       shl      eax,ROUND
2192 leency 265
       cdq
1245 hidnplayr 266
       idiv     ebx
2192 leency 267
 ;     mov      .dbx12,eax
1245 hidnplayr 268
       push      eax
2192 leency 269
1245 hidnplayr 270
 
2192 leency 271
       sub      ax,word[.b_y1]
272
       cwde
1245 hidnplayr 273
       shl      eax,ROUND
2192 leency 274
       cdq
1245 hidnplayr 275
       idiv     ebx
2192 leency 276
 ;     mov      .dby12,eax
1245 hidnplayr 277
       push      eax
2192 leency 278
1245 hidnplayr 279
 
280
 ;     mov       ebx,.dby12
281
 ;     int3
282
283
 
2192 leency 284
       sub      ax,word[.e_x1]
285
       cwde
1245 hidnplayr 286
       shl      eax,ROUND
2192 leency 287
       cdq
1245 hidnplayr 288
       idiv     ebx
2192 leency 289
 ;      mov      .dex12,eax
1245 hidnplayr 290
       push      eax
2192 leency 291
1245 hidnplayr 292
 
2192 leency 293
       sub      ax,word[.e_y1]
294
       cwde
1245 hidnplayr 295
       shl      eax,ROUND
2192 leency 296
       cdq
1245 hidnplayr 297
       idiv     ebx
2192 leency 298
 ;      mov      .dey12,eax
1245 hidnplayr 299
       push      eax
2192 leency 300
1245 hidnplayr 301
 
302
        mov     ax,.z2
2192 leency 303
        sub     ax,.z1
304
        cwde
305
        shl     eax,CATMULL_SHIFT
306
        cdq
307
        idiv    ebx
308
        push    eax
309
   .bt_dx12_done:
1245 hidnplayr 310
311
 
2192 leency 312
       sub      bx,.y1
313
       jnz      .bt_dx13_make
314
       mov      ecx,6
315
       xor      edx,edx
316
     @@:
1245 hidnplayr 317
       push     edx   ;dword 0
2192 leency 318
       loop     @b
319
       jmp      .bt_dx13_done
320
 .bt_dx13_make:
1245 hidnplayr 321
       mov      ax,.x3
2192 leency 322
       sub      ax,.x1
323
       cwde
1245 hidnplayr 324
       movsx    ebx,bx
2192 leency 325
       shl      eax,ROUND
326
       cdq
1245 hidnplayr 327
       idiv     ebx
2192 leency 328
 ;      mov      .dx13,eax
1245 hidnplayr 329
       push      eax
2192 leency 330
1245 hidnplayr 331
 
332
333
 
334
  ;     mov       eax,255
335
       cvtsi2ss  xmm4,[i255d]
336
       divss     xmm3,xmm4
2192 leency 337
       rcpss     xmm3,xmm3
338
;       mulss     xmm3,xmm4
1245 hidnplayr 339
       shufps    xmm3,xmm3,0
2192 leency 340
       sub       esp,16
341
1245 hidnplayr 342
 
2192 leency 343
       movd      mm1,[.b_x3]
344
       movd      mm2,[.e_x1]
345
       movd      mm3,[.e_x3]
346
1245 hidnplayr 347
 
2192 leency 348
       punpcklwd mm0,mm4
1245 hidnplayr 349
       punpcklwd mm1,mm4
350
       punpcklwd mm2,mm4
351
       punpcklwd mm3,mm4
352
353
 
354
       movlhps   xmm0,xmm0
2192 leency 355
       cvtpi2ps  xmm0,mm2
1245 hidnplayr 356
       cvtpi2ps  xmm1,mm1
357
       movlhps   xmm1,xmm1
2192 leency 358
       cvtpi2ps  xmm1,mm3
1245 hidnplayr 359
       subps     xmm1,xmm0
2192 leency 360
1245 hidnplayr 361
 
362
       mulps     xmm1,xmm3
2192 leency 363
       shufps    xmm1,xmm1,10110001b
364
       cvtps2pi  mm0,xmm1          ; mm0 -> 2 delta dwords
365
       movhlps   xmm1,xmm1
366
       cvtps2pi  mm1,xmm1
1245 hidnplayr 367
       movq      .dey13q,mm0
2192 leency 368
       movq      .dby13q,mm1
369
1245 hidnplayr 370
 
371
372
 
2192 leency 373
       sub      ax,word[.b_x1]
374
       cwde
1245 hidnplayr 375
       shl      eax,ROUND
2192 leency 376
       cdq
1245 hidnplayr 377
       idiv     ebx
2192 leency 378
 ;      mov      .dbx13,eax
1245 hidnplayr 379
       push      eax
2192 leency 380
1245 hidnplayr 381
 
2192 leency 382
       sub      ax,word[.b_y1]
383
       cwde
1245 hidnplayr 384
       shl      eax,ROUND
2192 leency 385
       cdq
1245 hidnplayr 386
       idiv     ebx
2192 leency 387
 ;      mov      .dby13,eax
1245 hidnplayr 388
       push      eax
2192 leency 389
1245 hidnplayr 390
 
2192 leency 391
       sub      ax,word[.e_x1]
392
       cwde
1245 hidnplayr 393
       shl      eax,ROUND
2192 leency 394
       cdq
1245 hidnplayr 395
       idiv     ebx
2192 leency 396
 ;      mov      .dex13,eax
1245 hidnplayr 397
       push      eax
2192 leency 398
1245 hidnplayr 399
 
2192 leency 400
       sub      ax,word[.e_y1]
401
       cwde
1245 hidnplayr 402
       shl      eax,ROUND
2192 leency 403
       cdq
1245 hidnplayr 404
       idiv     ebx
2192 leency 405
 ;      mov      .dey13,eax
1245 hidnplayr 406
       push      eax
2192 leency 407
1245 hidnplayr 408
 
409
410
 
411
       sub     ax,.z1
412
       cwde
413
       shl     eax,CATMULL_SHIFT
414
       cdq
415
       idiv    ebx
416
  ;    mov    .dz13,eax
417
       push    eax
418
   .bt_dx13_done:
419
420
 
2192 leency 421
       sub      bx,.y2
422
       jnz      .bt_dx23_make
423
       mov      ecx,6
424
       xor      edx,edx
425
     @@:
1245 hidnplayr 426
       push     edx   ;dword 0
2192 leency 427
       loop     @b
428
       jmp      .bt_dx23_done
429
 .bt_dx23_make:
1245 hidnplayr 430
       mov      ax,.x3
2192 leency 431
       sub      ax,.x2
432
       cwde
1245 hidnplayr 433
       movsx    ebx,bx
2192 leency 434
       shl      eax,ROUND
435
       cdq
1245 hidnplayr 436
       idiv     ebx
2192 leency 437
 ;      mov      .dx23,eax
1245 hidnplayr 438
       push      eax
2192 leency 439
1245 hidnplayr 440
 
441
442
 
443
     ;  mov       eax,255
444
       cvtsi2ss  xmm4,[i255d] ;eax
445
       divss     xmm3,xmm4
2192 leency 446
       shufps    xmm3,xmm3,0
447
       sub       esp,16
448
1245 hidnplayr 449
 
2192 leency 450
       movd      mm1,[.b_x3]
451
       movd      mm2,[.e_x2]
452
       movd      mm3,[.e_x3]
453
1245 hidnplayr 454
 
2192 leency 455
       punpcklwd mm0,mm4
1245 hidnplayr 456
       punpcklwd mm1,mm4
457
       punpcklwd mm2,mm4
458
       punpcklwd mm3,mm4
459
460
 
461
       movlhps   xmm0,xmm0
2192 leency 462
       cvtpi2ps  xmm0,mm2
1245 hidnplayr 463
       cvtpi2ps  xmm1,mm1
464
       movlhps   xmm1,xmm1
2192 leency 465
       cvtpi2ps  xmm1,mm3
1245 hidnplayr 466
       subps     xmm1,xmm0
2192 leency 467
1245 hidnplayr 468
 
2192 leency 469
       shufps    xmm1,xmm1,10110001b
470
       cvtps2pi  mm0,xmm1          ; mm0 -> 2 delta dwords
471
       movhlps   xmm1,xmm1
472
       cvtps2pi  mm1,xmm1
1245 hidnplayr 473
       movq      .dey23q,mm0
2192 leency 474
       movq      .dby23q,mm1
475
1245 hidnplayr 476
 
477
478
 
2192 leency 479
       sub      ax,word[.b_x2]
480
       cwde
1245 hidnplayr 481
       shl      eax,ROUND
2192 leency 482
       cdq
1245 hidnplayr 483
       idiv     ebx
2192 leency 484
 ;      mov      .dbx23,eax
1245 hidnplayr 485
       push      eax
2192 leency 486
1245 hidnplayr 487
 
2192 leency 488
       sub      ax,word[.b_y2]
489
       cwde
1245 hidnplayr 490
       shl      eax,ROUND
2192 leency 491
       cdq
1245 hidnplayr 492
       idiv     ebx
2192 leency 493
 ;      mov      .dby23,eax
1245 hidnplayr 494
       push      eax
2192 leency 495
1245 hidnplayr 496
 
2192 leency 497
       sub      ax,word[.e_x2]
498
       cwde
1245 hidnplayr 499
       shl      eax,ROUND
2192 leency 500
       cdq
1245 hidnplayr 501
       idiv     ebx
2192 leency 502
 ;      mov      .dex23,eax
1245 hidnplayr 503
       push      eax
2192 leency 504
1245 hidnplayr 505
 
2192 leency 506
       sub      ax,word[.e_y2]
507
       cwde
1245 hidnplayr 508
       shl      eax,ROUND
2192 leency 509
       cdq
1245 hidnplayr 510
       idiv     ebx
2192 leency 511
 ;      mov      .dey23,eax
1245 hidnplayr 512
       push      eax
2192 leency 513
end if
1245 hidnplayr 514
       mov     ax,.z3
515
       sub     ax,.z2
516
       cwde
517
       shl     eax,CATMULL_SHIFT
518
       cdq
519
       idiv    ebx
520
      ; mov     .dz23,eax
521
       push    eax
522
      ;  sub     esp,40
523
   .bt_dx23_done:
524
       movsx    eax,.x1
2192 leency 525
       shl      eax,ROUND
526
     ;  mov      .cx1,eax
1245 hidnplayr 527
     ;  mov      .cx2,eax
528
       push     eax eax
2192 leency 529
     ; push     eax
1245 hidnplayr 530
531
 
2192 leency 532
       shl      eax,ROUND
533
       mov      .cbx1,eax
534
       mov      .cbx2,eax
535
     ;  push     eax eax
1245 hidnplayr 536
     ; push     eax
537
538
 
2192 leency 539
       shl      eax,ROUND
540
       mov      .cby1,eax
541
       mov      .cby2,eax
542
     ;  push     eax eax
1245 hidnplayr 543
     ; push     eax
544
545
 
2192 leency 546
       shl      eax,ROUND
547
       mov      .cex1,eax
548
       mov      .cex2,eax
549
      ; push     eax eax
1245 hidnplayr 550
      ;push     eax
551
552
 
2192 leency 553
       shl      eax,ROUND
554
       mov      .cey1,eax
555
       mov      .cey2,eax
556
       sub      esp,32
557
      ; push     eax eax
1245 hidnplayr 558
      ;push     eax
559
560
 
2192 leency 561
       shl      eax,CATMULL_SHIFT
562
      ; mov      .cz1,eax
1245 hidnplayr 563
      ; mov      .cz2,eax
564
      push     eax eax
565
      ;push     eax
566
567
 
2192 leency 568
       cmp      cx,.y2
569
       jge      .loop12_done
570
  .loop12:
1245 hidnplayr 571
       call     .call_line
2192 leency 572
1245 hidnplayr 573
 
2192 leency 574
       add      .cx1,eax
575
       mov      ebx,.dx12
576
       add      .cx2,ebx
577
if Ext>= SSE2
578
       movups   xmm0,.cey1
579
       movups   xmm1,.cey2
580
       movups   xmm2,.dey12q
581
       movups   xmm3,.dey13q
582
       paddd    xmm0,xmm3
583
       paddd    xmm1,xmm2
584
       movups   .cey1,xmm0
585
       movups   .cey2,xmm1
586
else if (Ext = MMX) | (Ext=SSE)
587
       movq     mm0,.cby2       ; with this optimization object
588
       movq     mm1,.cby1       ; looks bit annoying
589
       movq     mm2,.cey2
590
       movq     mm3,.cey1
591
       paddd    mm0,.dby12q
592
       paddd    mm1,.dby13q
593
       paddd    mm2,.dey12q
594
       paddd    mm3,.dey13q
595
       movq     .cby2,mm0
596
       movq     .cby1,mm1
597
       movq     .cey1,mm3
598
       movq     .cey2,mm2
599
else
1245 hidnplayr 600
       mov      edx,.dbx13
2192 leency 601
       add      .cbx1,edx
602
       mov      eax,.dbx12
603
       add      .cbx2,eax
604
       mov      ebx,.dby13
605
       add      .cby1,ebx
606
       mov      edx,.dby12
607
       add      .cby2,edx
608
1245 hidnplayr 609
 
2192 leency 610
       add      .cex1,eax
611
       mov      ebx,.dex12
612
       add      .cex2,ebx
613
       mov      edx,.dey13
614
       add      .cey1,edx
615
       mov      eax,.dey12
616
       add      .cey2,eax
617
1245 hidnplayr 618
 
619
       mov      ebx,.dz13
2192 leency 620
       add      .cz1,ebx
621
       mov      edx,.dz12
622
       add      .cz2,edx
623
1245 hidnplayr 624
 
2192 leency 625
       cmp      cx,.y2
626
       jl       .loop12
627
    .loop12_done:
1245 hidnplayr 628
629
 
2192 leency 630
       cmp      cx,.y3
631
       jge      .loop23_done
632
1245 hidnplayr 633
 
2192 leency 634
       shl      eax,CATMULL_SHIFT
635
       mov      .cz2,eax
636
1245 hidnplayr 637
 
2192 leency 638
       shl      eax,ROUND
639
       mov      .cx2,eax
640
1245 hidnplayr 641
 
2192 leency 642
       shl      eax,ROUND
643
       mov      .cbx2,eax
644
1245 hidnplayr 645
 
2192 leency 646
       shl      eax,ROUND
647
       mov      .cby2,eax
648
1245 hidnplayr 649
 
2192 leency 650
       shl      eax,ROUND
651
       mov      .cex2,eax
652
1245 hidnplayr 653
 
2192 leency 654
       shl      eax,ROUND
655
       mov      .cey2,eax
656
1245 hidnplayr 657
 
658
       call     .call_line
2192 leency 659
;if Ext = NON
1245 hidnplayr 660
       mov      eax,.dx13
2192 leency 661
       add      .cx1,eax
662
       mov      ebx,.dx23
663
       add      .cx2,ebx
664
if Ext>= SSE2
665
       movups   xmm0,.cey1
666
       movups   xmm1,.cey2
667
       movups   xmm2,.dey23q
668
       movups   xmm3,.dey13q
669
       paddd    xmm0,xmm3
670
       paddd    xmm1,xmm2
671
       movups   .cey1,xmm0
672
       movups   .cey2,xmm1
673
else if (Ext = MMX) | ( Ext = SSE)
674
       movq     mm0,.cby2        ;    with this mmx optimization object looks bit
675
       movq     mm1,.cby1        ;    annoying
676
       movq     mm2,.cey2
677
       movq     mm3,.cey1
678
       paddd    mm0,.dby23q
679
       paddd    mm1,.dby13q
680
       paddd    mm2,.dey23q
681
       paddd    mm3,.dey13q
682
       movq     .cby2,mm0
683
       movq     .cby1,mm1
684
       movq     .cey2,mm2
685
       movq     .cey1,mm3
686
1245 hidnplayr 687
 
688
       mov      edx,.dbx13
2192 leency 689
       add      .cbx1,edx
690
       mov      eax,.dbx23
691
       add      .cbx2,eax
692
       mov      ebx,.dby13
693
       add      .cby1,ebx
694
       mov      edx,.dby23
695
       add      .cby2,edx
696
1245 hidnplayr 697
 
2192 leency 698
       add      .cex1,eax
699
       mov      ebx,.dex23
700
       add      .cex2,ebx
701
       mov      edx,.dey13
702
       add      .cey1,edx
703
       mov      eax,.dey23
704
       add      .cey2,eax
705
end if
1245 hidnplayr 706
707
 
2192 leency 708
       add      .cz1,ebx
709
       mov      edx,.dz23
710
       add      .cz2,edx
711
;else
1245 hidnplayr 712
;       movq     mm0,.db13q
713
;       movq     mm1,.cbx1q
714
715
 
2192 leency 716
       cmp      cx,.y3
717
       jl       .loop23
718
    .loop23_done:
1245 hidnplayr 719
720
 
2192 leency 721
ret   34
1245 hidnplayr 722
723
 
724
725
 
726
727
 
2192 leency 728
       push     .cz2
729
       push     .z_buff
730
       push     .t_bmap
731
       push     .t_emap
732
       push     dword .cey2
733
       push     .cex2
734
       push     dword .cey1
735
       push     .cex1
736
       push     dword .cby2
737
       push     .cbx2
738
       push     dword .cby1
739
       push     .cbx1
740
       push     ecx
741
1245 hidnplayr 742
 
2192 leency 743
       sar      eax,ROUND
744
       mov      ebx,.cx2
745
       sar      ebx,ROUND
746
1245 hidnplayr 747
 
2192 leency 748
1245 hidnplayr 749
 
750
ret
751
two_tex_line_z:
752
;--------------in: eax - x1
753
;--------------    ebx - x2
754
;--------------    edi - pointer to screen buffer
755
;stack - another parameters :
756
.y      equ dword [ebp+4]
2192 leency 757
.bx1    equ  [ebp+8]   ;   ---
758
.by1    equ  [ebp+12]  ;       |
759
.bx2    equ  [ebp+16]  ;       |
760
.by2    equ  [ebp+20]  ;       |>   b. texture and e. texture coords
761
.ex1    equ  [ebp+24]  ;       |>   shifted shl ROUND
762
.ey1    equ  [ebp+28]  ;       |
763
.ex2    equ  [ebp+32]  ;       |
764
.ey2    equ  [ebp+36]  ;   ---
765
.emap   equ  [ebp+40]  ; b texture offset
766
.bmap   equ  [ebp+44]  ; e texture offset
767
.z_buff equ dword [ebp+48]
1245 hidnplayr 768
.z2     equ dword [ebp+52]  ;   -- |>   z coords shifted
2192 leency 769
.z1     equ dword [ebp+56]  ;   --       shl  CATMULL_SHIFT
770
1245 hidnplayr 771
 
2192 leency 772
.x2     equ dword [ebp-8]
773
.dbx    equ [ebp-12]
774
.dex    equ [ebp-16]
775
.dby    equ [ebp-20]
776
.dey    equ [ebp-24]
777
.dz     equ dword [ebp-28]
778
.cbx    equ [ebp-32]
779
.cex    equ [ebp-36]
780
.cby    equ [ebp-40]
781
.cey    equ [ebp-44]
782
.cz     equ dword [ebp-48]
783
.czbuff equ dword [ebp-52]
1245 hidnplayr 784
785
 
2192 leency 786
1245 hidnplayr 787
 
2192 leency 788
        or      ecx,ecx
789
        jl      .bl_end
790
        cmp     ecx,SIZE_Y
791
        jge     .bl_end
792
1245 hidnplayr 793
 
2192 leency 794
        jl      @f
795
        je      .bl_end
796
1245 hidnplayr 797
 
2192 leency 798
if Ext=NON
1245 hidnplayr 799
        mov     edx,.bx1
2192 leency 800
        xchg    edx,.bx2
801
        mov     .bx1,edx
802
        mov     edx,.by1
803
        xchg    edx,.by2
804
        mov     .by1,edx
805
1245 hidnplayr 806
 
2192 leency 807
        xchg    edx,.ex2
808
        mov     .ex1,edx
809
        mov     edx,.ey1
810
        xchg    edx,.ey2
811
        mov     .ey1,edx
812
else
1245 hidnplayr 813
        movq    mm0,.bx1
2192 leency 814
        movq    mm1,.ex1
815
        movq    mm2,.bx2
816
        movq    mm3,.ex2
817
        movq    .bx2,mm0
818
        movq    .ex2,mm1
819
        movq    .bx1,mm2
820
        movq    .ex1,mm3
821
end if
1245 hidnplayr 822
        mov     edx,.z1
2192 leency 823
        xchg    edx,.z2
824
        mov     .z1,edx
825
    @@:
1245 hidnplayr 826
        push    eax ebx
2192 leency 827
;        push    ebx           ;store x1, x2
1245 hidnplayr 828
829
 
2192 leency 830
        jge     .bl_end
831
        cmp     .x2,0
832
        jle     .bl_end
833
1245 hidnplayr 834
 
2192 leency 835
        sub     ebx,.x1
836
1245 hidnplayr 837
 
1931 yogev_ezra 838
1245 hidnplayr 839
 
2192 leency 840
       cvtsi2ss  xmm3,ebx            ;rcps
841
       shufps    xmm3,xmm3,0
842
1245 hidnplayr 843
 
844
  ;     movq      mm1,.bx2q
845
  ;     movq      mm2,.ex1q
846
  ;     movq      mm3,.ex2q
847
  ;     psubd     mm1,mm0
848
  ;     psubd     mm3,mm2
849
  ;     cvtpi2ps  xmm1,mm1
850
  ;     movlhps   xmm1,xmm1
851
  ;     cvtpi2ps  xmm1,mm3
852
853
 
1931 yogev_ezra 854
       movlhps   xmm0,xmm0
2192 leency 855
       cvtpi2ps  xmm0,.ex1 ;mm2     ; ex1; ey1
1931 yogev_ezra 856
       cvtpi2ps  xmm1,.bx2 ;mm1     ; bx2; by2
857
       movlhps   xmm1,xmm1
2192 leency 858
       cvtpi2ps  xmm1,.ex2 ;mm3     ; ex2; ey2
1931 yogev_ezra 859
       subps     xmm1,xmm0
2192 leency 860
                                    ; hi             lo
861
       divps     xmm1,xmm3 ; xmm1 -> dby; dbx; dey; dex
862
1245 hidnplayr 863
 
2192 leency 864
       cvtps2pi  mm0,xmm1          ; mm0 -> 2 delta dwords
865
       movhlps   xmm1,xmm1
866
       cvtps2pi  mm1,xmm1
1245 hidnplayr 867
       movq      .dex,mm0 ; hi - lo  ->  dbx, dex
2192 leency 868
       movq      .dey,mm1 ; hi - lo  ->  dby, dey
869
1245 hidnplayr 870
 
871
872
 
2192 leency 873
        sub     eax,.bx1
874
        cdq
875
        idiv    ebx
876
        push    eax
877
1245 hidnplayr 878
 
2192 leency 879
        sub     eax,.ex1
880
        cdq
881
        idiv    ebx
882
        push    eax
883
1245 hidnplayr 884
 
2192 leency 885
        sub     eax,.by1
886
        cdq
887
        idiv    ebx
888
        push    eax
889
1245 hidnplayr 890
 
2192 leency 891
        sub     eax,.ey1
892
        cdq
893
        idiv    ebx
894
        push    eax
895
1245 hidnplayr 896
 
897
898
 
2192 leency 899
        sub     eax,.z1
900
        cdq
901
        idiv    ebx
902
        push    eax
903
1245 hidnplayr 904
 
2192 leency 905
        jge     @f            ; CLIPPING ON FUNCTION
906
                              ; cutting triangle exceedes screen
907
        mov     ebx,.x1
908
        neg     ebx
909
        imul    ebx           ; eax = .dz * abs(.x1)
910
        add     .z1,eax
911
        mov     .x1,0
912
1245 hidnplayr 913
 
2192 leency 914
        imul    ebx
915
        add    .bx1,eax
916
1245 hidnplayr 917
 
2192 leency 918
        imul    ebx
919
        add     .by1,eax
920
1245 hidnplayr 921
 
2192 leency 922
        imul    ebx
923
        add     .ex1,eax
924
1245 hidnplayr 925
 
2192 leency 926
        imul    ebx
927
        add     .ey1,eax
928
      @@:
1245 hidnplayr 929
        cmp     .x2,SIZE_X
2192 leency 930
        jl      @f
931
        mov     .x2,SIZE_X
932
      @@:
1245 hidnplayr 933
        mov     eax,SIZE_X       ;calc memory begin in buffers
2192 leency 934
        mov     ebx,.y
935
        mul     ebx
936
        mov     ebx,.x1
937
        add     eax,ebx
938
        mov     ebx,eax
939
        lea     eax,[eax*3]
940
        add     edi,eax           ; edi - screen
941
        mov     esi,.z_buff       ; z-buffer filled with dd variables
942
        shl     ebx,2
943
        add     esi,ebx           ; esi - Z buffer
944
1245 hidnplayr 945
 
2192 leency 946
        sub     ecx,.x1
947
        ; init current variables
948
        push    dword .bx1 ;.by1 .ex1 .ey1 .z1 esi
949
        push    dword .ex1
950
        push    dword .by1
951
        push    dword .ey1
952
1245 hidnplayr 953
 
2192 leency 954
        push    esi
955
1245 hidnplayr 956
 
957
     pxor   mm0,mm0
958
     movq   mm3,.cex   ; hi - lo -> cbx; cex
1931 yogev_ezra 959
     movq   mm4,.cey   ; hi - lo -> cby; cey
960
;     movq   mm5,mm3
1245 hidnplayr 961
;     movq   mm6,mm4
962
;     psrad  mm5,ROUND
963
;     psrad  mm6,ROUND
964
;     movq   .ceyq,mm5
965
;     movq   .cbyq,mm6
966
     mov    edx,.czbuff
967
else
968
     cld
969
end if
970
     .draw:
971
    ; if TEX = SHIFTING   ;bump drawing only in shifting mode
972
if Ext=NON
973
        mov     esi,.czbuff      ; .czbuff current address in buffer
2192 leency 974
        mov     ebx,.cz          ; .cz - cur z position
975
        cmp     ebx,dword[esi]
976
else
1245 hidnplayr 977
        mov     ebx,.cz
2192 leency 978
        cmp     ebx,dword[edx]
979
end if
1245 hidnplayr 980
        jge     .skip
2192 leency 981
1245 hidnplayr 982
 
1931 yogev_ezra 983
        mov     eax,.cby
2192 leency 984
        mov     esi,.cbx
985
        sar     eax,ROUND
986
        sar     esi,ROUND
987
        shl     eax,TEX_SHIFT   ;-
988
        add     esi,eax
989
        lea     esi,[esi*3]         ;-  ; esi - current b. texture addres
990
        add     esi,.bmap
991
1245 hidnplayr 992
 
2192 leency 993
        mov     eax,.cey       ;.cey - current  env map y
994
        sar     ebx,ROUND
995
        sar     eax,ROUND
996
1931 yogev_ezra 997
 
2192 leency 998
        add     ebx,eax
999
        lea     ebx,[ebx*3]
1000
        add     ebx,.emap
1001
1931 yogev_ezra 1002
 
1003
 
1004
        movq    mm5,mm4 ;.cey
2192 leency 1005
        psrad   mm5,ROUND
1006
        pslld   mm5,TEX_SHIFT
1007
        movq    mm6,mm3 ;.cex
1008
        psrad   mm6,ROUND
1009
        paddd   mm5,mm6
1010
        movq    mm6,mm5
1011
        paddd   mm5,mm5
1012
        paddd   mm5,mm6
1013
        paddd   mm5,.emap
1014
        movd    esi,mm5
1015
        psrlq   mm5,32
1016
        movd    ebx,mm5
1017
end if
1931 yogev_ezra 1018
if Ext>=MMX
1245 hidnplayr 1019
        movd      mm1,[esi]
2192 leency 1020
        movd      mm2,[ebx]
1021
        punpcklbw mm1,mm0
1022
        punpcklbw mm2,mm0
1023
        pmullw    mm1,mm2
1024
        psrlw     mm1,8
1025
        packuswb  mm1,mm0
1026
        movd      [edi],mm1
1027
        mov       ebx,.cz
1028
        mov       dword[edx],ebx
1029
else
1245 hidnplayr 1030
        cld                     ; esi - tex e.
2192 leency 1031
        lodsb                   ; ebx - tex b.
1032
        mov     dl,[ebx]
1033
        mul     dl
1034
        shr     ax,8
1035
        stosb
1036
        inc     ebx
1037
        lodsb
1038
        mov     dl,[ebx]
1039
        mul     dl
1040
        shr     ax,8
1041
        stosb
1042
        inc     ebx
1043
        lodsb
1044
        mov     dl,[ebx]
1045
        mul     dl
1046
        shr     ax,8
1047
        stosb
1048
        mov     ebx,.cz
1049
        mov     esi,.czbuff
1050
        mov     dword[esi],ebx
1051
        jmp     .no_skip
1052
end if
1245 hidnplayr 1053
     .skip:
1054
        add     edi,3
2192 leency 1055
1245 hidnplayr 1056
 
1057
     .no_skip:
1058
        add     .czbuff,4
2192 leency 1059
        mov     eax,.dbx
1060
        add     .cbx,eax
1061
        mov     eax,.dby
1062
        add     .cby,eax
1063
        mov     eax,.dex
1064
        add     .cex,eax
1065
        mov     eax,.dey
1066
        add     .cey,eax
1067
    else
1245 hidnplayr 1068
        add     edx,4
2192 leency 1069
        paddd   mm3,.dex
1070
        paddd   mm4,.dey
1071
  ;      movq    mm5,mm3
1245 hidnplayr 1072
  ;      movq    mm6,mm4
1073
  ;      psrad   mm5,ROUND
1074
  ;      psrad   mm6,ROUND
1075
     ;   movq    .cex,mm3
1979 yogev_ezra 1076
     ;   movq    .cey,mm4
1077
    end if
1245 hidnplayr 1078
        mov     eax,.dz
2192 leency 1079
        add     .cz,eax
1080
    if Ext = NON
1245 hidnplayr 1081
        dec     ecx
2192 leency 1082
        jnz     .draw
1083
    else
1245 hidnplayr 1084
        loop    .draw
2192 leency 1085
    end if
1245 hidnplayr 1086
1087
 
1088
        mov     esp,ebp
2192 leency 1089
ret 56
1245 hidnplayr 1090