Subversion Repositories Kolibri OS

Rev

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

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