Subversion Repositories Kolibri OS

Rev

Rev 6769 | 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
 
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 !!!
6619 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
 
6619 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]
6619 leency 65
.dex12 equ dword[ebp-36]
1245 hidnplayr 66
.dey12 equ dword[ebp-40]
67
.dey12q equ	[ebp-40]
6619 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]
6619 leency 74
.dex13 equ dword[ebp-60]
1245 hidnplayr 75
.dey13 equ dword[ebp-64]
76
.dey13q equ	[ebp-64]
6619 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]
6619 leency 83
.dex23 equ dword[ebp-84]
1245 hidnplayr 84
.dey23 equ dword[ebp-88]
85
.dey23q equ	[ebp-88]
6619 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
6619 leency 109
;       push    esi        ; store e. map
1245 hidnplayr 110
     ; sub     esp,120
111
 .sort3:		  ; sort triangle coordinates...
6619 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
6619 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
6619 leency 138
 .sort2:
1245 hidnplayr 139
       push	eax ebx ecx    ; store triangle coords in variables
6619 leency 140
;       push     ebx
1245 hidnplayr 141
;       push     ecx
142
143
 
6619 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
 
6619 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
6619 leency 170
       loop	@b
171
       jmp	.bt_dx12_done
172
 .bt_dx12_make:
1245 hidnplayr 173
       mov	ax,.x2
6619 leency 174
       sub	ax,.x1
175
       cwde
1245 hidnplayr 176
       movsx	ebx,bx
6619 leency 177
       shl	eax,ROUND
178
       cdq
1245 hidnplayr 179
       idiv	ebx
6619 leency 180
;      mov      .dx12,eax
1245 hidnplayr 181
       push	 eax
6619 leency 182
1245 hidnplayr 183
 
184
185
 
6619 leency 186
       cvtsi2ss  xmm3,ebx	     ;rcps
187
    ;   mov       eax,255
1245 hidnplayr 188
       cvtsi2ss  xmm4,[i255d] ;eax
189
       divss	 xmm3,xmm4
6619 leency 190
       rcpss	 xmm3,xmm3
191
    ;   mulss     xmm3,xmm4
1245 hidnplayr 192
       shufps	 xmm3,xmm3,0
6619 leency 193
1245 hidnplayr 194
 
6619 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
6619 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
6619 leency 211
       cvtpi2ps  xmm0,mm2
1245 hidnplayr 212
       cvtpi2ps  xmm1,mm1
213
       movlhps	 xmm1,xmm1
6619 leency 214
       cvtpi2ps  xmm1,mm3
1245 hidnplayr 215
       subps	 xmm1,xmm0
6619 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
6619 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
6619 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]
6619 leency 262
       sub	ax,word[.b_x1]
263
       cwde
1245 hidnplayr 264
       shl	eax,ROUND
6619 leency 265
       cdq
1245 hidnplayr 266
       idiv	ebx
6619 leency 267
 ;     mov      .dbx12,eax
1245 hidnplayr 268
       push	 eax
6619 leency 269
1245 hidnplayr 270
 
6619 leency 271
       sub	ax,word[.b_y1]
272
       cwde
1245 hidnplayr 273
       shl	eax,ROUND
6619 leency 274
       cdq
1245 hidnplayr 275
       idiv	ebx
6619 leency 276
 ;     mov      .dby12,eax
1245 hidnplayr 277
       push	 eax
6619 leency 278
1245 hidnplayr 279
 
280
 ;     mov       ebx,.dby12
281
 ;     int3
282
283
 
6619 leency 284
       sub	ax,word[.e_x1]
285
       cwde
1245 hidnplayr 286
       shl	eax,ROUND
6619 leency 287
       cdq
1245 hidnplayr 288
       idiv	ebx
6619 leency 289
 ;      mov      .dex12,eax
1245 hidnplayr 290
       push	 eax
6619 leency 291
1245 hidnplayr 292
 
6619 leency 293
       sub	ax,word[.e_y1]
294
       cwde
1245 hidnplayr 295
       shl	eax,ROUND
6619 leency 296
       cdq
1245 hidnplayr 297
       idiv	ebx
6619 leency 298
 ;      mov      .dey12,eax
1245 hidnplayr 299
       push	 eax
6619 leency 300
1245 hidnplayr 301
 
302
	mov	ax,.z2
6619 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
 
6619 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
6619 leency 318
       loop	@b
319
       jmp	.bt_dx13_done
320
 .bt_dx13_make:
1245 hidnplayr 321
       mov	ax,.x3
6619 leency 322
       sub	ax,.x1
323
       cwde
1245 hidnplayr 324
       movsx	ebx,bx
6619 leency 325
       shl	eax,ROUND
326
       cdq
1245 hidnplayr 327
       idiv	ebx
6619 leency 328
 ;      mov      .dx13,eax
1245 hidnplayr 329
       push	 eax
6619 leency 330
1245 hidnplayr 331
 
332
333
 
334
  ;     mov       eax,255
335
       cvtsi2ss  xmm4,[i255d]
336
       divss	 xmm3,xmm4
6619 leency 337
       rcpss	 xmm3,xmm3
338
;       mulss     xmm3,xmm4
1245 hidnplayr 339
       shufps	 xmm3,xmm3,0
6619 leency 340
       sub	 esp,16
341
1245 hidnplayr 342
 
6619 leency 343
       movd	 mm1,[.b_x3]
344
       movd	 mm2,[.e_x1]
345
       movd	 mm3,[.e_x3]
346
1245 hidnplayr 347
 
6619 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
6619 leency 355
       cvtpi2ps  xmm0,mm2
1245 hidnplayr 356
       cvtpi2ps  xmm1,mm1
357
       movlhps	 xmm1,xmm1
6619 leency 358
       cvtpi2ps  xmm1,mm3
1245 hidnplayr 359
       subps	 xmm1,xmm0
6619 leency 360
1245 hidnplayr 361
 
362
       mulps	 xmm1,xmm3
6619 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
6619 leency 368
       movq	 .dby13q,mm1
369
1245 hidnplayr 370
 
371
372
 
6619 leency 373
       sub	ax,word[.b_x1]
374
       cwde
1245 hidnplayr 375
       shl	eax,ROUND
6619 leency 376
       cdq
1245 hidnplayr 377
       idiv	ebx
6619 leency 378
 ;      mov      .dbx13,eax
1245 hidnplayr 379
       push	 eax
6619 leency 380
1245 hidnplayr 381
 
6619 leency 382
       sub	ax,word[.b_y1]
383
       cwde
1245 hidnplayr 384
       shl	eax,ROUND
6619 leency 385
       cdq
1245 hidnplayr 386
       idiv	ebx
6619 leency 387
 ;      mov      .dby13,eax
1245 hidnplayr 388
       push	 eax
6619 leency 389
1245 hidnplayr 390
 
6619 leency 391
       sub	ax,word[.e_x1]
392
       cwde
1245 hidnplayr 393
       shl	eax,ROUND
6619 leency 394
       cdq
1245 hidnplayr 395
       idiv	ebx
6619 leency 396
 ;      mov      .dex13,eax
1245 hidnplayr 397
       push	 eax
6619 leency 398
1245 hidnplayr 399
 
6619 leency 400
       sub	ax,word[.e_y1]
401
       cwde
1245 hidnplayr 402
       shl	eax,ROUND
6619 leency 403
       cdq
1245 hidnplayr 404
       idiv	ebx
6619 leency 405
 ;      mov      .dey13,eax
1245 hidnplayr 406
       push	 eax
6619 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
 
6619 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
6619 leency 427
       loop	@b
428
       jmp	.bt_dx23_done
429
 .bt_dx23_make:
1245 hidnplayr 430
       mov	ax,.x3
6619 leency 431
       sub	ax,.x2
432
       cwde
1245 hidnplayr 433
       movsx	ebx,bx
6619 leency 434
       shl	eax,ROUND
435
       cdq
1245 hidnplayr 436
       idiv	ebx
6619 leency 437
 ;      mov      .dx23,eax
1245 hidnplayr 438
       push	 eax
6619 leency 439
1245 hidnplayr 440
 
441
442
 
443
     ;  mov       eax,255
444
       cvtsi2ss  xmm4,[i255d] ;eax
445
       divss	 xmm3,xmm4
6619 leency 446
       shufps	 xmm3,xmm3,0
447
       sub	 esp,16
448
1245 hidnplayr 449
 
6619 leency 450
       movd	 mm1,[.b_x3]
451
       movd	 mm2,[.e_x2]
452
       movd	 mm3,[.e_x3]
453
1245 hidnplayr 454
 
6619 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
6619 leency 462
       cvtpi2ps  xmm0,mm2
1245 hidnplayr 463
       cvtpi2ps  xmm1,mm1
464
       movlhps	 xmm1,xmm1
6619 leency 465
       cvtpi2ps  xmm1,mm3
1245 hidnplayr 466
       subps	 xmm1,xmm0
6619 leency 467
1245 hidnplayr 468
 
6619 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
6619 leency 474
       movq	 .dby23q,mm1
475
1245 hidnplayr 476
 
477
478
 
6619 leency 479
       sub	ax,word[.b_x2]
480
       cwde
1245 hidnplayr 481
       shl	eax,ROUND
6619 leency 482
       cdq
1245 hidnplayr 483
       idiv	ebx
6619 leency 484
 ;      mov      .dbx23,eax
1245 hidnplayr 485
       push	 eax
6619 leency 486
1245 hidnplayr 487
 
6619 leency 488
       sub	ax,word[.b_y2]
489
       cwde
1245 hidnplayr 490
       shl	eax,ROUND
6619 leency 491
       cdq
1245 hidnplayr 492
       idiv	ebx
6619 leency 493
 ;      mov      .dby23,eax
1245 hidnplayr 494
       push	 eax
6619 leency 495
1245 hidnplayr 496
 
6619 leency 497
       sub	ax,word[.e_x2]
498
       cwde
1245 hidnplayr 499
       shl	eax,ROUND
6619 leency 500
       cdq
1245 hidnplayr 501
       idiv	ebx
6619 leency 502
 ;      mov      .dex23,eax
1245 hidnplayr 503
       push	 eax
6619 leency 504
1245 hidnplayr 505
 
6619 leency 506
       sub	ax,word[.e_y2]
507
       cwde
1245 hidnplayr 508
       shl	eax,ROUND
6619 leency 509
       cdq
1245 hidnplayr 510
       idiv	ebx
6619 leency 511
 ;      mov      .dey23,eax
1245 hidnplayr 512
       push	 eax
6619 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
6619 leency 525
       shl	eax,ROUND
526
     ;  mov      .cx1,eax
1245 hidnplayr 527
     ;  mov      .cx2,eax
528
       push	eax eax
6619 leency 529
     ; push     eax
1245 hidnplayr 530
531
 
6619 leency 532
       shl	eax,ROUND
533
       mov	.cbx1,eax
534
       mov	.cbx2,eax
535
     ;  push     eax eax
1245 hidnplayr 536
     ; push     eax
537
538
 
6619 leency 539
       shl	eax,ROUND
540
       mov	.cby1,eax
541
       mov	.cby2,eax
542
     ;  push     eax eax
1245 hidnplayr 543
     ; push     eax
544
545
 
6619 leency 546
       shl	eax,ROUND
547
       mov	.cex1,eax
548
       mov	.cex2,eax
549
      ; push     eax eax
1245 hidnplayr 550
      ;push     eax
551
552
 
6619 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
 
6619 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
 
6619 leency 568
       cmp	cx,.y2
569
       jge	.loop12_done
570
  .loop12:
1245 hidnplayr 571
       call	.call_line
6619 leency 572
1245 hidnplayr 573
 
6619 leency 574
       add	.cx1,eax
575
       mov	ebx,.dx12
576
       add	.cx2,ebx
577
if Ext>= SSE2
2192 leency 578
       movups	xmm0,.cey1
6619 leency 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)
2192 leency 587
       movq	mm0,.cby2	; with this optimization object
6619 leency 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
6619 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
 
6619 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
6619 leency 620
       add	.cz1,ebx
621
       mov	edx,.dz12
622
       add	.cz2,edx
623
1245 hidnplayr 624
 
6619 leency 625
       cmp	cx,.y2
626
       jl	.loop12
627
    .loop12_done:
1245 hidnplayr 628
629
 
6619 leency 630
       cmp	cx,.y3
631
       jge	.loop23_done
632
1245 hidnplayr 633
 
6619 leency 634
       shl	eax,CATMULL_SHIFT
635
       mov	.cz2,eax
636
1245 hidnplayr 637
 
6619 leency 638
       shl	eax,ROUND
639
       mov	.cx2,eax
640
1245 hidnplayr 641
 
6619 leency 642
       shl	eax,ROUND
643
       mov	.cbx2,eax
644
1245 hidnplayr 645
 
6619 leency 646
       shl	eax,ROUND
647
       mov	.cby2,eax
648
1245 hidnplayr 649
 
6619 leency 650
       shl	eax,ROUND
651
       mov	.cex2,eax
652
1245 hidnplayr 653
 
6619 leency 654
       shl	eax,ROUND
655
       mov	.cey2,eax
656
1245 hidnplayr 657
 
658
       call	.call_line
6619 leency 659
;if Ext = NON
1245 hidnplayr 660
       mov	eax,.dx13
6619 leency 661
       add	.cx1,eax
662
       mov	ebx,.dx23
663
       add	.cx2,ebx
664
if Ext>= SSE2
2192 leency 665
       movups	xmm0,.cey1
6619 leency 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)
2192 leency 674
       movq	mm0,.cby2	 ;    with this mmx optimization object looks bit
6619 leency 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
6619 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
 
6619 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
 
6619 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
 
6619 leency 716
       cmp	cx,.y3
717
       jl	.loop23
718
    .loop23_done:
1245 hidnplayr 719
720
 
6619 leency 721
ret   34
1245 hidnplayr 722
723
 
724
725
 
726
727
 
6619 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
 
6619 leency 743
       sar	eax,ROUND
744
       mov	ebx,.cx2
745
       sar	ebx,ROUND
746
1245 hidnplayr 747
 
6619 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]
6619 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
6619 leency 769
.z1	equ dword [ebp+56]  ;   --       shl  CATMULL_SHIFT
770
1245 hidnplayr 771
 
6619 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
 
6619 leency 786
1245 hidnplayr 787
 
6619 leency 788
	or	ecx,ecx
789
	jl	.bl_end
790
	mov	dx,word[size_y_var]
6769 IgorA 791
	dec	dx
792
	cmp	cx,dx	;word[size_y_var]  ;SIZE_Y
793
	jge	.bl_end
6619 leency 794
1245 hidnplayr 795
 
6619 leency 796
	jl	@f
797
	je	.bl_end
798
1245 hidnplayr 799
 
6619 leency 800
if Ext=NON
1245 hidnplayr 801
	mov	edx,.bx1
6619 leency 802
	xchg	edx,.bx2
803
	mov	.bx1,edx
804
	mov	edx,.by1
805
	xchg	edx,.by2
806
	mov	.by1,edx
807
1245 hidnplayr 808
 
6619 leency 809
	xchg	edx,.ex2
810
	mov	.ex1,edx
811
	mov	edx,.ey1
812
	xchg	edx,.ey2
813
	mov	.ey1,edx
814
else
1245 hidnplayr 815
	movq	mm0,.bx1
6619 leency 816
	movq	mm1,.ex1
817
	movq	mm2,.bx2
818
	movq	mm3,.ex2
819
	movq	.bx2,mm0
820
	movq	.ex2,mm1
821
	movq	.bx1,mm2
822
	movq	.ex1,mm3
823
end if
1245 hidnplayr 824
	mov	edx,.z1
6619 leency 825
	xchg	edx,.z2
826
	mov	.z1,edx
827
    @@:
1245 hidnplayr 828
	push	eax ebx    ;store x1, x2
6619 leency 829
	mov	ebx,.x1
830
	movzx	edx,word[size_x_var]
831
	dec	edx
6769 IgorA 832
	cmp	ebx,edx
6619 leency 833
  ;      cmp     bx,word[size_x_var]  ;SIZE_X
834
	jg	.bl_end
835
	cmp	.x2,0
836
	jle	.bl_end
837
1245 hidnplayr 838
 
6619 leency 839
	sub	ebx,.x1
840
1245 hidnplayr 841
 
6769 IgorA 842
1245 hidnplayr 843
 
6619 leency 844
       cvtsi2ss  xmm3,ebx	     ;rcps
845
       shufps	 xmm3,xmm3,0
846
1245 hidnplayr 847
 
848
  ;     movq      mm1,.bx2q
849
  ;     movq      mm2,.ex1q
850
  ;     movq      mm3,.ex2q
851
  ;     psubd     mm1,mm0
852
  ;     psubd     mm3,mm2
853
  ;     cvtpi2ps  xmm1,mm1
854
  ;     movlhps   xmm1,xmm1
855
  ;     cvtpi2ps  xmm1,mm3
856
857
 
1931 yogev_ezra 858
       movlhps	 xmm0,xmm0
6619 leency 859
       cvtpi2ps  xmm0,.ex1 ;mm2     ; ex1; ey1
1931 yogev_ezra 860
       cvtpi2ps  xmm1,.bx2 ;mm1     ; bx2; by2
861
       movlhps	 xmm1,xmm1
6619 leency 862
       cvtpi2ps  xmm1,.ex2 ;mm3     ; ex2; ey2
1931 yogev_ezra 863
       subps	 xmm1,xmm0
6619 leency 864
				    ; hi             lo
865
       divps	 xmm1,xmm3 ; xmm1 -> dby; dbx; dey; dex
866
1245 hidnplayr 867
 
6619 leency 868
       cvtps2pi  mm0,xmm1	   ; mm0 -> 2 delta dwords
869
       movhlps	 xmm1,xmm1
870
       cvtps2pi  mm1,xmm1
1245 hidnplayr 871
       movq	 .dex,mm0 ; hi - lo  ->  dbx, dex
6619 leency 872
       movq	 .dey,mm1 ; hi - lo  ->  dby, dey
873
1245 hidnplayr 874
 
875
876
 
6619 leency 877
	sub	eax,.bx1
878
	cdq
879
	idiv	ebx
880
	push	eax
881
1245 hidnplayr 882
 
6619 leency 883
	sub	eax,.ex1
884
	cdq
885
	idiv	ebx
886
	push	eax
887
1245 hidnplayr 888
 
6619 leency 889
	sub	eax,.by1
890
	cdq
891
	idiv	ebx
892
	push	eax
893
1245 hidnplayr 894
 
6619 leency 895
	sub	eax,.ey1
896
	cdq
897
	idiv	ebx
898
	push	eax
899
1245 hidnplayr 900
 
901
902
 
6619 leency 903
	sub	eax,.z1
904
	cdq
905
	idiv	ebx
906
	push	eax
907
1245 hidnplayr 908
 
6619 leency 909
	jge	@f	      ; CLIPPING ON FUNCTION
910
			      ; cutting triangle exceedes screen
911
	mov	ebx,.x1
912
	neg	ebx
913
	imul	ebx	      ; eax = .dz * abs(.x1)
914
	add	.z1,eax
915
	mov	.x1,0
916
1245 hidnplayr 917
 
6619 leency 918
	imul	ebx
919
	add    .bx1,eax
920
1245 hidnplayr 921
 
6619 leency 922
	imul	ebx
923
	add	.by1,eax
924
1245 hidnplayr 925
 
6619 leency 926
	imul	ebx
927
	add	.ex1,eax
928
1245 hidnplayr 929
 
6619 leency 930
	imul	ebx
931
	add	.ey1,eax
932
      @@:
1245 hidnplayr 933
	movzx	eax,word[size_x_var] ;SIZE_X  ;word[size_x_var]
6619 leency 934
	mov	ebx,.x2
935
	cmp	eax,ebx
936
	jg	@f
937
	mov	.x2,eax
938
      @@:
1245 hidnplayr 939
      ;  movd    mm0,eax
6619 leency 940
      ;  movd    mm1,.x2
941
      ;  pminsw  mm0,mm1
942
      ;  movd    .x2,mm0
943
 ;       cmp     .x2,SIZE_X  ;eax   |
944
 ;       jl      @f                 |>       this dont work idk cause
945
 ;       mov     .x2,SIZE_X ;eax    |
946
      @@:
947
      ;  movzx   eax,word[size_x_var]       ;calc memory begin in buffers
948
	mov	ebx,.y
949
	mul	ebx
950
	mov	ebx,.x1
951
	add	eax,ebx
952
	mov	ebx,eax
953
	lea	eax,[eax*3]
954
	add	edi,eax 	  ; edi - screen
955
	mov	esi,.z_buff	  ; z-buffer filled with dd variables
956
	shl	ebx,2
957
	add	esi,ebx 	  ; esi - Z buffer
958
1245 hidnplayr 959
 
6619 leency 960
	sub	ecx,.x1
961
	; init current variables
962
	push	dword .bx1 ;.by1 .ex1 .ey1 .z1 esi
963
	push	dword .ex1
964
	push	dword .by1
965
	push	dword .ey1
966
1245 hidnplayr 967
 
6619 leency 968
	push	esi
969
1245 hidnplayr 970
 
971
     pxor   mm0,mm0
972
     movq   mm3,.cex   ; hi - lo -> cbx; cex
1931 yogev_ezra 973
     movq   mm4,.cey   ; hi - lo -> cby; cey
974
;     movq   mm5,mm3
1245 hidnplayr 975
;     movq   mm6,mm4
976
;     psrad  mm5,ROUND
977
;     psrad  mm6,ROUND
978
;     movq   .ceyq,mm5
979
;     movq   .cbyq,mm6
980
     mov    edx,.czbuff
981
else
982
     cld
983
end if
984
     .draw:
985
    ; if TEX = SHIFTING   ;bump drawing only in shifting mode
986
if Ext=NON
987
	mov	esi,.czbuff	 ; .czbuff current address in buffer
6619 leency 988
	mov	ebx,.cz 	 ; .cz - cur z position
989
	cmp	ebx,dword[esi]
990
else
1245 hidnplayr 991
	mov	ebx,.cz
6619 leency 992
	cmp	ebx,dword[edx]
993
end if
1245 hidnplayr 994
	jge	.skip
6619 leency 995
1245 hidnplayr 996
 
1931 yogev_ezra 997
	mov	eax,.cby
6619 leency 998
	mov	esi,.cbx
999
	sar	eax,ROUND
1000
	sar	esi,ROUND
1001
	shl	eax,TEX_SHIFT	;-
1002
	add	esi,eax
1003
	lea	esi,[esi*3]	    ;-  ; esi - current b. texture addres
1004
	add	esi,.bmap
1005
1245 hidnplayr 1006
 
6619 leency 1007
	mov	eax,.cey       ;.cey - current  env map y
1008
	sar	ebx,ROUND
1009
	sar	eax,ROUND
1010
1931 yogev_ezra 1011
 
6619 leency 1012
	add	ebx,eax
1013
	lea	ebx,[ebx*3]
1014
	add	ebx,.emap
1015
1931 yogev_ezra 1016
 
1017
 
1018
	movq	mm5,mm4 ;.cey
6619 leency 1019
	psrad	mm5,ROUND
1020
	pslld	mm5,TEX_SHIFT
1021
	movq	mm6,mm3 ;.cex
1022
	psrad	mm6,ROUND
1023
	paddd	mm5,mm6
1024
	movq	mm6,mm5
1025
	paddd	mm5,mm5
1026
	paddd	mm5,mm6
1027
	paddd	mm5,.emap
1028
	movd	esi,mm5
1029
	psrlq	mm5,32
1030
	movd	ebx,mm5
1031
end if
1931 yogev_ezra 1032
if Ext>=MMX
1245 hidnplayr 1033
	movd	  mm1,[esi]
6619 leency 1034
	movd	  mm2,[ebx]
1035
	punpcklbw mm1,mm0
1036
	punpcklbw mm2,mm0
1037
	pmullw	  mm1,mm2
1038
	psrlw	  mm1,8
1039
	packuswb  mm1,mm0
1040
	movd	  [edi],mm1
1041
	mov	  ebx,.cz
1042
	mov	  dword[edx],ebx
1043
else
1245 hidnplayr 1044
	cld			; esi - tex e.
6619 leency 1045
	lodsb			; ebx - tex b.
1046
	mov	dl,[ebx]
1047
	mul	dl
1048
	shr	ax,8
1049
	stosb
1050
	inc	ebx
1051
	lodsb
1052
	mov	dl,[ebx]
1053
	mul	dl
1054
	shr	ax,8
1055
	stosb
1056
	inc	ebx
1057
	lodsb
1058
	mov	dl,[ebx]
1059
	mul	dl
1060
	shr	ax,8
1061
	stosb
1062
	mov	ebx,.cz
1063
	mov	esi,.czbuff
1064
	mov	dword[esi],ebx
1065
	jmp	.no_skip
1066
end if
1245 hidnplayr 1067
     .skip:
1068
	add	edi,3
6619 leency 1069
1245 hidnplayr 1070
 
1071
     .no_skip:
1072
	add	.czbuff,4
6619 leency 1073
	mov	eax,.dbx
1074
	add	.cbx,eax
1075
	mov	eax,.dby
1076
	add	.cby,eax
1077
	mov	eax,.dex
1078
	add	.cex,eax
1079
	mov	eax,.dey
1080
	add	.cey,eax
1081
    else
1245 hidnplayr 1082
	add	edx,4
6619 leency 1083
	paddd	mm3,.dex
1084
	paddd	mm4,.dey
1085
  ;      movq    mm5,mm3
1245 hidnplayr 1086
  ;      movq    mm6,mm4
1087
  ;      psrad   mm5,ROUND
1088
  ;      psrad   mm6,ROUND
1089
     ;   movq    .cex,mm3
1979 yogev_ezra 1090
     ;   movq    .cey,mm4
1091
    end if
1245 hidnplayr 1092
	mov	eax,.dz
6619 leency 1093
	add	.cz,eax
1094
    if Ext = NON
1245 hidnplayr 1095
	dec	ecx
6619 leency 1096
	jnz	.draw
1097
    else
1245 hidnplayr 1098
	loop	.draw
6619 leency 1099
    end if
1245 hidnplayr 1100
1101
 
1102
	mov	esp,ebp
6619 leency 1103
ret 56
1245 hidnplayr 1104