Subversion Repositories Kolibri OS

Rev

Rev 2192 | 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
	cmp	cx,word[size_y_var]  ;SIZE_Y
791
	jge	.bl_end
792
1245 hidnplayr 793
 
6619 leency 794
	jl	@f
795
	je	.bl_end
796
1245 hidnplayr 797
 
6619 leency 798
if Ext=NON
1245 hidnplayr 799
	mov	edx,.bx1
6619 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
 
6619 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
6619 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
6619 leency 823
	xchg	edx,.z2
824
	mov	.z1,edx
825
    @@:
1245 hidnplayr 826
	push	eax ebx    ;store x1, x2
6619 leency 827
	mov	ebx,.x1
828
	movzx	edx,word[size_x_var]
829
	cmp	ebx,edx
830
  ;      cmp     bx,word[size_x_var]  ;SIZE_X
831
	jg	.bl_end
832
	cmp	.x2,0
833
	jle	.bl_end
834
1245 hidnplayr 835
 
6619 leency 836
	sub	ebx,.x1
837
1245 hidnplayr 838
 
1931 yogev_ezra 839
1245 hidnplayr 840
 
6619 leency 841
       cvtsi2ss  xmm3,ebx	     ;rcps
842
       shufps	 xmm3,xmm3,0
843
1245 hidnplayr 844
 
845
  ;     movq      mm1,.bx2q
846
  ;     movq      mm2,.ex1q
847
  ;     movq      mm3,.ex2q
848
  ;     psubd     mm1,mm0
849
  ;     psubd     mm3,mm2
850
  ;     cvtpi2ps  xmm1,mm1
851
  ;     movlhps   xmm1,xmm1
852
  ;     cvtpi2ps  xmm1,mm3
853
854
 
1931 yogev_ezra 855
       movlhps	 xmm0,xmm0
6619 leency 856
       cvtpi2ps  xmm0,.ex1 ;mm2     ; ex1; ey1
1931 yogev_ezra 857
       cvtpi2ps  xmm1,.bx2 ;mm1     ; bx2; by2
858
       movlhps	 xmm1,xmm1
6619 leency 859
       cvtpi2ps  xmm1,.ex2 ;mm3     ; ex2; ey2
1931 yogev_ezra 860
       subps	 xmm1,xmm0
6619 leency 861
				    ; hi             lo
862
       divps	 xmm1,xmm3 ; xmm1 -> dby; dbx; dey; dex
863
1245 hidnplayr 864
 
6619 leency 865
       cvtps2pi  mm0,xmm1	   ; mm0 -> 2 delta dwords
866
       movhlps	 xmm1,xmm1
867
       cvtps2pi  mm1,xmm1
1245 hidnplayr 868
       movq	 .dex,mm0 ; hi - lo  ->  dbx, dex
6619 leency 869
       movq	 .dey,mm1 ; hi - lo  ->  dby, dey
870
1245 hidnplayr 871
 
872
873
 
6619 leency 874
	sub	eax,.bx1
875
	cdq
876
	idiv	ebx
877
	push	eax
878
1245 hidnplayr 879
 
6619 leency 880
	sub	eax,.ex1
881
	cdq
882
	idiv	ebx
883
	push	eax
884
1245 hidnplayr 885
 
6619 leency 886
	sub	eax,.by1
887
	cdq
888
	idiv	ebx
889
	push	eax
890
1245 hidnplayr 891
 
6619 leency 892
	sub	eax,.ey1
893
	cdq
894
	idiv	ebx
895
	push	eax
896
1245 hidnplayr 897
 
898
899
 
6619 leency 900
	sub	eax,.z1
901
	cdq
902
	idiv	ebx
903
	push	eax
904
1245 hidnplayr 905
 
6619 leency 906
	jge	@f	      ; CLIPPING ON FUNCTION
907
			      ; cutting triangle exceedes screen
908
	mov	ebx,.x1
909
	neg	ebx
910
	imul	ebx	      ; eax = .dz * abs(.x1)
911
	add	.z1,eax
912
	mov	.x1,0
913
1245 hidnplayr 914
 
6619 leency 915
	imul	ebx
916
	add    .bx1,eax
917
1245 hidnplayr 918
 
6619 leency 919
	imul	ebx
920
	add	.by1,eax
921
1245 hidnplayr 922
 
6619 leency 923
	imul	ebx
924
	add	.ex1,eax
925
1245 hidnplayr 926
 
6619 leency 927
	imul	ebx
928
	add	.ey1,eax
929
      @@:
1245 hidnplayr 930
	movzx	eax,word[size_x_var] ;SIZE_X  ;word[size_x_var]
6619 leency 931
	mov	ebx,.x2
932
	cmp	eax,ebx
933
	jg	@f
934
	mov	.x2,eax
935
      @@:
1245 hidnplayr 936
      ;  movd    mm0,eax
6619 leency 937
      ;  movd    mm1,.x2
938
      ;  pminsw  mm0,mm1
939
      ;  movd    .x2,mm0
940
 ;       cmp     .x2,SIZE_X  ;eax   |
941
 ;       jl      @f                 |>       this dont work idk cause
942
 ;       mov     .x2,SIZE_X ;eax    |
943
      @@:
944
      ;  movzx   eax,word[size_x_var]       ;calc memory begin in buffers
945
	mov	ebx,.y
946
	mul	ebx
947
	mov	ebx,.x1
948
	add	eax,ebx
949
	mov	ebx,eax
950
	lea	eax,[eax*3]
951
	add	edi,eax 	  ; edi - screen
952
	mov	esi,.z_buff	  ; z-buffer filled with dd variables
953
	shl	ebx,2
954
	add	esi,ebx 	  ; esi - Z buffer
955
1245 hidnplayr 956
 
6619 leency 957
	sub	ecx,.x1
958
	; init current variables
959
	push	dword .bx1 ;.by1 .ex1 .ey1 .z1 esi
960
	push	dword .ex1
961
	push	dword .by1
962
	push	dword .ey1
963
1245 hidnplayr 964
 
6619 leency 965
	push	esi
966
1245 hidnplayr 967
 
968
     pxor   mm0,mm0
969
     movq   mm3,.cex   ; hi - lo -> cbx; cex
1931 yogev_ezra 970
     movq   mm4,.cey   ; hi - lo -> cby; cey
971
;     movq   mm5,mm3
1245 hidnplayr 972
;     movq   mm6,mm4
973
;     psrad  mm5,ROUND
974
;     psrad  mm6,ROUND
975
;     movq   .ceyq,mm5
976
;     movq   .cbyq,mm6
977
     mov    edx,.czbuff
978
else
979
     cld
980
end if
981
     .draw:
982
    ; if TEX = SHIFTING   ;bump drawing only in shifting mode
983
if Ext=NON
984
	mov	esi,.czbuff	 ; .czbuff current address in buffer
6619 leency 985
	mov	ebx,.cz 	 ; .cz - cur z position
986
	cmp	ebx,dword[esi]
987
else
1245 hidnplayr 988
	mov	ebx,.cz
6619 leency 989
	cmp	ebx,dword[edx]
990
end if
1245 hidnplayr 991
	jge	.skip
6619 leency 992
1245 hidnplayr 993
 
1931 yogev_ezra 994
	mov	eax,.cby
6619 leency 995
	mov	esi,.cbx
996
	sar	eax,ROUND
997
	sar	esi,ROUND
998
	shl	eax,TEX_SHIFT	;-
999
	add	esi,eax
1000
	lea	esi,[esi*3]	    ;-  ; esi - current b. texture addres
1001
	add	esi,.bmap
1002
1245 hidnplayr 1003
 
6619 leency 1004
	mov	eax,.cey       ;.cey - current  env map y
1005
	sar	ebx,ROUND
1006
	sar	eax,ROUND
1007
1931 yogev_ezra 1008
 
6619 leency 1009
	add	ebx,eax
1010
	lea	ebx,[ebx*3]
1011
	add	ebx,.emap
1012
1931 yogev_ezra 1013
 
1014
 
1015
	movq	mm5,mm4 ;.cey
6619 leency 1016
	psrad	mm5,ROUND
1017
	pslld	mm5,TEX_SHIFT
1018
	movq	mm6,mm3 ;.cex
1019
	psrad	mm6,ROUND
1020
	paddd	mm5,mm6
1021
	movq	mm6,mm5
1022
	paddd	mm5,mm5
1023
	paddd	mm5,mm6
1024
	paddd	mm5,.emap
1025
	movd	esi,mm5
1026
	psrlq	mm5,32
1027
	movd	ebx,mm5
1028
end if
1931 yogev_ezra 1029
if Ext>=MMX
1245 hidnplayr 1030
	movd	  mm1,[esi]
6619 leency 1031
	movd	  mm2,[ebx]
1032
	punpcklbw mm1,mm0
1033
	punpcklbw mm2,mm0
1034
	pmullw	  mm1,mm2
1035
	psrlw	  mm1,8
1036
	packuswb  mm1,mm0
1037
	movd	  [edi],mm1
1038
	mov	  ebx,.cz
1039
	mov	  dword[edx],ebx
1040
else
1245 hidnplayr 1041
	cld			; esi - tex e.
6619 leency 1042
	lodsb			; ebx - tex b.
1043
	mov	dl,[ebx]
1044
	mul	dl
1045
	shr	ax,8
1046
	stosb
1047
	inc	ebx
1048
	lodsb
1049
	mov	dl,[ebx]
1050
	mul	dl
1051
	shr	ax,8
1052
	stosb
1053
	inc	ebx
1054
	lodsb
1055
	mov	dl,[ebx]
1056
	mul	dl
1057
	shr	ax,8
1058
	stosb
1059
	mov	ebx,.cz
1060
	mov	esi,.czbuff
1061
	mov	dword[esi],ebx
1062
	jmp	.no_skip
1063
end if
1245 hidnplayr 1064
     .skip:
1065
	add	edi,3
6619 leency 1066
1245 hidnplayr 1067
 
1068
     .no_skip:
1069
	add	.czbuff,4
6619 leency 1070
	mov	eax,.dbx
1071
	add	.cbx,eax
1072
	mov	eax,.dby
1073
	add	.cby,eax
1074
	mov	eax,.dex
1075
	add	.cex,eax
1076
	mov	eax,.dey
1077
	add	.cey,eax
1078
    else
1245 hidnplayr 1079
	add	edx,4
6619 leency 1080
	paddd	mm3,.dex
1081
	paddd	mm4,.dey
1082
  ;      movq    mm5,mm3
1245 hidnplayr 1083
  ;      movq    mm6,mm4
1084
  ;      psrad   mm5,ROUND
1085
  ;      psrad   mm6,ROUND
1086
     ;   movq    .cex,mm3
1979 yogev_ezra 1087
     ;   movq    .cey,mm4
1088
    end if
1245 hidnplayr 1089
	mov	eax,.dz
6619 leency 1090
	add	.cz,eax
1091
    if Ext = NON
1245 hidnplayr 1092
	dec	ecx
6619 leency 1093
	jnz	.draw
1094
    else
1245 hidnplayr 1095
	loop	.draw
6619 leency 1096
    end if
1245 hidnplayr 1097
1098
 
1099
	mov	esp,ebp
6619 leency 1100
ret 56
1245 hidnplayr 1101