Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1245 hidnplayr 1
 
6619 leency 2
;		with a few graphics effects demonstration.
3
; compiler    : FASM
1819 yogev_ezra 4
; system      : KolibriOS
5
; author      : Macgub aka Maciej Guba
1245 hidnplayr 6
; email       : macgub3@wp.pl
7
; web	      : www.macgub.hekko.pl
6619 leency 8
; Fell free to use this intro in your own distribution of KolibriOS.
9
; Special greetings to KolibriOS team .
10
; I hope because my intros Christian Belive will be near to each of You.
1245 hidnplayr 11
12
 
13
 
14
; madis.kalme@mail.ee
15
; I tried optimizing it a bit, but don't know if it was successful. The objects
16
; can be:
17
; 1) Read from a file (*.3DS standard)
18
; 2) Written in manually (at the end of the code)
19
20
 
6619 leency 21
 
1245 hidnplayr 22
SIZE_Y equ 512				     ;	    /////     I want definitely
6619 leency 23
TIMEOUT equ 10				     ;	   ------     say:
24
ROUND equ 10				     ;	   \ @ @/     keep smiling every
25
TEX_X equ 512	 ; texture width	     ;	    \ ./    / day.
26
TEX_Y equ 512	 ;	   height	     ;	     \/    /
27
TEX_SHIFT equ 9  ; texture width shifting    ;	   __||__ /
28
TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1	     ;	 /|	 |
29
TEX equ SHIFTING ; TEX={SHIFTING | FLUENTLY} ;	/ \	 /
30
FLUENTLY = 0				     ; /   |	|
31
SHIFTING = 1				     ;	   ------
32
CATMULL_SHIFT equ 8			     ;	    |  |
33
LIGHT_SIZE equ 22			     ;	    |  |
34
NON   =   0				     ;	   -/  \-
35
MMX   =   1
1245 hidnplayr 36
SSE   =   2
37
SSE2  =   3
1979 yogev_ezra 38
Ext   =   SSE2		 ;Ext={ NON | MMX | SSE | SSE2 }
2881 leency 39
1245 hidnplayr 40
 
41
USE_LFN = 1
42
43
 
44
	org    0x0
45
	db     'MENUET01'	; 8 byte id
46
	dd     0x01		; header version
47
	dd     START		; start of code
48
	dd     I_END		; size of image
49
	dd     MEM_END		; memory for app
50
	dd     MEM_END		; esp
51
	dd     I_Param		; I_Param
52
	dd     0x0		; I_Icon
53
54
 
55
	cld
56
	mov    eax,14
6619 leency 57
	int    0x40
58
	sub    eax,150 shl 16 + 150
59
	mov    [size_y_var],ax
60
	shr    ax,1
61
	mov    [vect_y],ax
62
63
 
64
	movzx  ebx,ax
65
	push   ebx
66
	fninit
67
	fild   dword[esp]
68
	fstp   [rsscale]
69
	pop    ebx
70
71
 
72
	mov    [size_x_var],ax
73
	shr    ax,1
74
	mov    [vect_x],ax
75
76
 
77
 
1245 hidnplayr 78
	call   read_param
79
	call   read_from_disk	 ; read, if all is ok eax = 0
80
	cmp    eax,0
81
	jne    .gen
82
	mov    esi,[fptr]
5486 leency 83
	cmp    [esi],word 4D4Dh
84
	jne    .asc
85
	call   read_tp_variables ; init points and triangles count variables
1245 hidnplayr 86
	cmp    eax,0
87
	je     .gen
88
	jmp    .malloc
89
    .gen:
90
     if USE_LFN
91
	mov    [triangles_count_var],1000
92
	mov    [points_count_var],1000
93
	call   alloc_mem_for_tp
94
     end if
95
	call   generate_object
96
	jmp    .opt
97
    .asc:
5486 leency 98
	mov    [triangles_count_var],10000
99
	mov    [points_count_var],10000
100
	call   alloc_mem_for_tp
101
	call   read_asc
102
	jmp    .opt
103
    .malloc:
1245 hidnplayr 104
     if USE_LFN
105
	call   alloc_mem_for_tp
106
     end if
107
	call   read_from_file
108
    .opt:
109
	call   optimize_object1     ;  proc in file b_procs.asm
110
				    ;  set point(0,0,0) in center and  calc all coords
111
				    ;  to be in <-1.0,1.0>
112
	call   normalize_all_light_vectors
113
	call   init_triangles_normals2
114
	call   init_point_normals
115
	call   init_envmap2
1931 yogev_ezra 116
	call   init_envmap_cub
1245 hidnplayr 117
	call   generate_texture2
118
	call   init_sincos_tab
119
120
 
121
	mov    edi,bumpmap
122
	call   calc_bumpmap
123
	call   calc_bumpmap_coords   ; bump and texture mapping
124
	call   draw_window
125
126
 
127
128
 
129
	mov	ebx,TIMEOUT
130
	cmp	[speed_flag],1
131
	jne	.skip
132
	mov	eax,11
133
    .skip:
134
	int	0x40
135
136
 
137
	je	red
138
	cmp	eax,2		; key in buffer ?
139
	je	key
140
	cmp	eax,3		; button in buffer ?
141
	je	button
142
143
 
144
145
 
146
	call	draw_window
147
148
 
149
150
 
151
	mov	eax,2		; just read it and ignore
152
	int	0x40
153
	jmp	noclose
154
155
 
156
	mov	eax,17		; get id
157
	int	0x40
158
159
 
160
	jne	@f
161
162
 
163
	int	0x40
164
    @@:
165
	cmp	ah,30
166
	jge	add_vec_buttons
167
	call	update_flags	      ; update flags and write labels of flags
168
169
 
170
	cmp	ah,3		      ; ah = 3 -> shading model
171
	jne	.next_m6
172
	cmp	[dr_flag],2
173
	jne	@f
174
   ;	 call	 init_envmap2	 ;   <----! this don't works in env mode
6619 leency 175
				 ;	    and more than ~18 kb objects
176
 ;	 call	 init_envmap_cub2
177
     @@:
1245 hidnplayr 178
	cmp	[dr_flag],4
179
	jne	@f
180
	call	generate_texture2
181
182
 
183
     .next_m6:
184
				      ; ah = 5 -> scale-
185
	cmp	ah,5
186
	jne	@f
187
	mov	[scale],0.7
188
	fninit
189
	fld	[rsscale]
190
	fmul	[scale]
191
	fstp	[rsscale]
192
193
 
194
	cmp	ah,6		     ; ah = 6 ->  scale+
195
	jne	@f
196
	mov	[scale],1.3
197
	fninit
198
	fld	[rsscale]
199
	fmul	[scale]
200
	fstp	[rsscale]
201
202
 
203
	cmp	ah,9	; lights random 		;    'flat'  0
6619 leency 204
	jne	.next_m5				;    'grd '  1
1245 hidnplayr 205
	call	make_random_lights			;    'env '  2
206
	call	normalize_all_light_vectors		;    'bump'  3
207
	call	do_color_buffer   ; intit color_map	;    'tex '  4
6619 leency 208
      ;  cmp	 [emboss_flag],1			 ;    'pos '  5
209
      ;  je	 @f					 ;    'dots'  6
210
      ;  cmp	 [dr_flag],8
211
      ;  jge	 @f
212
      ;  cmp	 [dr_flag],2				 ;    'txgr'  7
213
      ;  jl	 .next_m5			     ;	  '2tex'  8
214
      ;  cmp	 [dr_flag],3				 ;    'btex'  9
215
      ;  jg	 .next_m5
216
    ; @@:
1931 yogev_ezra 217
	call	init_envmap2	; update env map if shading model = environment or bump
1245 hidnplayr 218
    .next_m5:
219
	cmp	 ah,11
220
	je	 @f
221
	cmp	 ah,12
222
	je	 @f
223
	cmp	 ah,13
224
	jne	 .next_m4
225
      @@:
226
	call	 mirror
227
     .next_m4:
228
	cmp	 ah,14
229
	jne	 @f
230
	call	 exchange
231
     @@:
232
	cmp	 ah,15
233
	jne	 @f
234
	cmp	 [emboss_flag],1
235
	call	 init_envmap2
236
     @@:
237
;	 cmp	  ah,17
6619 leency 238
;	 jne	  .next_m
239
;	 cmp	  [move_flag],2
240
;	 jne	  @f
241
;	 call	  draw_window		  ; redraw other labels to navigation buttons
242
;      @@:
1245 hidnplayr 243
;	 cmp	  [move_flag],0
6619 leency 244
;	 jne	  .next_m
245
;	 call	  draw_window		  ; redraw other labels to navigation buttons
246
     .next_m:
1245 hidnplayr 247
	cmp	 ah,18
248
	jne	 .next_m2
249
     if USE_LFN
1776 yogev_ezra 250
	mov	 [re_alloc_flag],1	 ; reallocate memory
251
	mov	 [triangles_count_var],1000
252
	mov	 [points_count_var],1000
253
	call	 alloc_mem_for_tp
254
	mov	 [re_alloc_flag],0
255
     end if
256
	mov	 bl,[generator_flag]
1245 hidnplayr 257
	or	 bl,bl
258
	jz	 .next_m2
259
	cmp	 bl,1
260
	jne	 @f
261
	call	 generate_object
262
	jmp	 .calc_norm
263
      @@:
264
	cmp	 bl,4
265
	jg	 @f
266
	movzx	 ax,bl		      ; ax < - object number
267
	call	 generate_object2
268
	jmp	.calc_norm
269
      @@:
270
	call	generate_object3
271
      .calc_norm:
272
	call	optimize_object1
273
	call	init_triangles_normals2
274
	call	init_point_normals
275
	call	calc_bumpmap_coords   ; bump and texture mapping
276
277
 
278
	cmp	 ah,19
279
	je	 @f
280
	cmp	 ah,20
281
	jne	 .next_m3
282
     @@:
283
	mov	 edi,bumpmap
284
	call	 calc_bumpmap
285
     .next_m3:
1776 yogev_ezra 286
	cmp	ah,21		 ; re map bumps, texture coordinates
287
	jne	@f
288
	call	calc_bumpmap_coords
289
      @@:
290
	jmp	noclose
1245 hidnplayr 291
292
 
293
 
294
   add_vec_buttons:	       ; can move: object, camera,.. list is open
295
			       ;
296
	cmp	ah,30
297
	jne	.next
298
	cmp	[move_flag],0
2984 leency 299
	jne	@f
300
;	 cmp	 [move_flag],2
6619 leency 301
;	 je	 .set_light1
302
	sub	[vect_y],10
1245 hidnplayr 303
	jmp	.next
304
      @@:
305
	cmp	[move_flag],1
2984 leency 306
	jne	@f
307
	sub	[yobs],10   ;  observator = camera position
1245 hidnplayr 308
	jmp	.next
309
      @@:
2984 leency 310
	sub	[sin_amplitude],10
311
;--------------------------------------------------
1245 hidnplayr 312
;      .set_light1:	     ;	r -
6619 leency 313
;	 movzx	 ebx,[light_no_flag]  ; * 22
314
;	 mov	 ecx,ebx
315
;	 shl	 ebx,4
316
;	 shl	 ecx,1
317
;	 add	 ebx,ecx
318
;	 shl	 ecx,1
319
;	 add	 ebx,ecx
320
;	 add	 ebx,lights+6	 ; 6 -> light vector size
321
;
1245 hidnplayr 322
;	 movzx	 ecx,[light_comp_flag]
6619 leency 323
;	 lea	 ecx,[ecx*3}
324
;	 add	 ebx,ecx	 ; ebx ->  color to set
325
1245 hidnplayr 326
 
327
      .next:
328
	cmp	ah,31
329
	jne	.next1
330
	cmp	[move_flag],1
331
	je	@f
332
	add	[vect_z],10
333
	jmp	.next1
334
      @@:
335
	add	[zobs],10	  ;  observator = camera position
336
     .next1:
337
	cmp	ah,33
338
	jne	.next2
339
	cmp	[move_flag],0
2984 leency 340
	jne	@f
341
	sub	[vect_x],10
1245 hidnplayr 342
	jmp	.next2
343
      @@:
344
	cmp	[move_flag],1
2984 leency 345
	jne	@f
346
	sub	[xobs],10	  ;  observator = camera position
1245 hidnplayr 347
	jmp	.next2
2984 leency 348
      @@:
349
	fninit
350
	fld	[sin_frq]
351
	fsub	[sin_delta]
352
	fstp	[sin_frq]
353
      .next2:
1245 hidnplayr 354
	cmp	ah,32
355
	jne	.next3
356
	cmp	[move_flag],0
2984 leency 357
	jne	@f
358
	add	[vect_x],10
1245 hidnplayr 359
	jmp	.next3
360
      @@:
361
	cmp	[move_flag],1
2984 leency 362
	jne	@f
363
	add	[xobs],10	  ;  observator = camera position
1245 hidnplayr 364
	jmp	.next3
2984 leency 365
      @@:
366
	fninit
367
	fld	[sin_frq]      ; change wave effect frequency
368
	fadd	[sin_delta]
369
	fstp	[sin_frq]
370
      .next3:
1245 hidnplayr 371
	cmp	ah,34
372
	jne	.next4
373
	cmp	[move_flag],1
374
	je	@f
375
376
 
377
	jmp	.next4
378
      @@:
379
	sub	[zobs],10	  ;  observator = camera position
380
      .next4:
381
	cmp	ah,35
382
	jne	.next5
383
	cmp	[move_flag],0
2984 leency 384
	jne	 @f
385
      ;  call	 add_vector
6619 leency 386
	add	[vect_y],10
1245 hidnplayr 387
	jmp	.next5
388
      @@:
389
	cmp	[move_flag],1
2984 leency 390
	jne	@f
391
	add	[yobs],10	  ;  observator = camera position
1245 hidnplayr 392
	jmp	.next5
2984 leency 393
      @@:
394
	add	[sin_amplitude],10
395
      .next5:
1245 hidnplayr 396
397
 
398
 
399
 
400
401
 
402
	jne	.no_x
403
	inc	[angle_x]
404
	and	[angle_x],0xff
405
	mov	[angle_z],0
406
	jmp	.end_rot
407
408
 
409
	cmp	[r_flag],0
410
	jne	.no_y
411
	inc	[angle_y]
412
	and	[angle_y],0xff
413
	mov	[angle_z],0
414
	jmp	.end_rot
415
416
 
417
	cmp	[r_flag],1
418
	jne	.end_rot
419
	mov	cx,[angle_x]
420
	inc	cx
421
	and	cx,0xff
422
	mov	[angle_z],0
423
	mov	[angle_y],cx
424
	mov	[angle_x],cx
425
     .end_rot:
426
427
 
428
	mov	edi,matrix
429
	call	make_rotation_matrix
430
    RDTSC
1931 yogev_ezra 431
    push eax
432
	mov	esi,[points_normals_ptr]
1245 hidnplayr 433
	mov	edi,[points_normals_rot_ptr]
434
	mov	ebx,matrix
435
	movzx	ecx,[points_count_var]
436
	call	rotary
437
438
 
439
	call	add_scale_to_matrix
440
441
 
442
	mov	edi,[points_rotated_ptr]
443
	mov	ebx,matrix
444
	movzx	ecx,[points_count_var]
445
	call	rotary
446
447
 
448
;    pop    ebx
449
;    sub    eax,ebx
450
;    sub    eax,41
451
;    push   eax
452
453
 
454
	mov	edi,[points_translated_ptr]
455
	movzx	ecx,[points_count_var]
456
	call	translate_points
457
458
 
6619 leency 459
;	 jne	 @f
460
;	 call	 calc_attenuation_light
461
;     @@:
1245 hidnplayr 462
	cmp	[fire_flag],0
463
	jne	@f
464
	call	clrscr		; clear the screen
465
     @@:
466
	cmp	[catmull_flag],1  ;non sort if Catmull = on
467
	je	.no_sort
468
	call	sort_triangles
469
      .no_sort:
470
	cmp	[dr_flag],7	  ; fill if 2tex and texgrd
471
	jge	@f
472
	cmp	[catmull_flag],0  ;non fill if Catmull = off
473
	je	.non_f
474
	cmp	[dr_flag],6	  ; non fill if dots
475
	je	.non_f
476
      @@:
477
	call	fill_Z_buffer	  ; make background
478
     .non_f:
479
;    RDTSC
1931 yogev_ezra 480
;    push eax
481
	cmp	[dr_flag],6
1245 hidnplayr 482
	jne	@f
483
	call	 draw_dots
484
	jmp	 .blurrr
485
      @@:
486
	call	draw_triangles	; draw all triangles from the list
487
      .blurrr:
488
	cmp  [sinus_flag],0
2984 leency 489
	je   @f
490
	call do_sinus
491
      @@:
492
	cmp	[fire_flag],0
1245 hidnplayr 493
	jne	@f
494
	cmp	[blur_flag],0
495
	je	.no_blur  ; no blur, no fire
496
	movzx	ecx,[blur_flag]
497
	call	blur_screen    ; blur and fire
498
	jmp	.no_blur
499
    @@:
500
	cmp	[emboss_flag],0
501
	jne	.emb	       ; if emboss=true -> no fire
502
	movzx	ecx,[fire_flag]
503
	call	blur_screen    ; blur and fire
504
    .no_blur:		       ; no blur, no fire
505
	cmp	[emboss_flag],0
506
	je	@f
507
     .emb:
508
	call	do_emboss
509
510
 
511
512
 
513
 
2736 leency 514
    je	    .no_inc_bright
515
    movzx   ebx,[inc_bright_flag]
516
    shl     ebx,4
517
    mov     esi,[screen_ptr]
6619 leency 518
    movzx   ecx,word[size_y_var]
519
    movzx   eax,word[size_x_var]
520
    mul     ecx
521
    lea     ecx,[eax*3]
522
if (Ext = MMX)|(Ext = SSE)
2736 leency 523
    mov      bh,bl
524
    push     bx
525
    shl      ebx,16
526
    pop      bx
527
    push     ebx
528
    push     ebx
529
    movq     mm0,[esp]
530
    add      esp,8
531
else if Ext >= SSE2
532
    mov      bh,bl
533
    push     bx
534
    shl      ebx,16
535
    pop      bx
536
    movd     xmm0,ebx
537
    shufps   xmm0,xmm0,0
538
end if
539
  .oop:
540
if Ext=NON
541
    lodsb
542
    add     al,bl
543
    jnc     @f
544
    mov     byte[esi-1],255
545
    loop    .oop
546
   @@:
547
    mov     [esi-1],al
548
    loop    .oop
549
else if (Ext=MMX)|(Ext=SSE)
550
    movq    mm1,[esi]
551
    movq    mm2,[esi+8]
552
    paddusb mm1,mm0
553
    paddusb mm2,mm0
554
    movq    [esi],mm1
555
    movq    [esi+8],mm2
556
    add     esi,16
557
    sub     ecx,16
558
    jnz     .oop
559
else
560
    movaps  xmm1,[esi]
561
    paddusb xmm1,xmm0
562
    movaps  [esi],xmm1
563
    add     esi,16
564
    sub     ecx,16
565
    jnc     .oop
6619 leency 566
end if
2736 leency 567
568
 
569
570
 
571
 
572
    je	    .no_dec_bright
573
    movzx   ebx,[dec_bright_flag]
574
    shl     ebx,4
575
    mov     esi,[screen_ptr]
6619 leency 576
    movzx   eax,word[size_x_var]
577
    movzx   ecx,word[size_y_var]
578
    mul     ecx
579
    lea     ecx,[eax*3]
580
 if (Ext = MMX)|(Ext = SSE)
581
    mov      bh,bl
2736 leency 582
    push     bx
583
    shl      ebx,16
584
    pop      bx
585
    push     ebx
586
    push     ebx
587
    movq     mm0,[esp]
588
    add      esp,8
589
else if Ext >=SSE2
590
    mov      bh,bl
591
    push     bx
592
    shl      ebx,16
593
    pop      bx
594
    movd     xmm0,ebx
595
    shufps   xmm0,xmm0,0
596
end if
597
 .oop1:
598
if Ext=NON
599
    lodsb
600
    sub     al,bl
601
    jb	    @f
602
    mov     [esi-1],al
603
    loop    .oop1
604
   @@:
605
    mov     byte[esi-1],0
606
    loop    .oop1
607
else if (Ext = MMX)|(Ext=SSE)
608
    movq    mm1,[esi]
609
    psubusb mm1,mm0
610
    movq    [esi],mm1
611
    add     esi,8
612
    sub     ecx,8
613
    jnz     .oop1
614
else
615
    movaps  xmm1,[esi]
616
    psubusb xmm1,xmm0
617
    movaps  [esi],xmm1
618
    add     esi,16
619
    sub     ecx,16
620
    jnc     .oop1
6619 leency 621
end if
2736 leency 622
  .no_dec_bright:
623
;======================================commmented====================
624
if 0
625
if Ext >= SSE
626
    cmp     [max_flag],0
627
    je	    .no_max
628
    ;movzx   ebx,[max_flag]
629
 .again_max:
630
;    push	ecx
6619 leency 631
    mov        edi,screen
2736 leency 632
    mov        ecx,SIZE_X*3/4
633
  ;   ;    pxor       mm5,mm5
634
    xor        eax,eax
635
    rep        stosd
636
637
 
638
  .calc_max:
639
  @@:
640
    movq       mm0,[edi+SIZE_X*3]
641
    movq       mm1,[edi-SIZE_X*3]
642
    movq       mm2,[edi-3]
643
    movq       mm3,[edi+3]
644
645
 
646
    pmaxub	mm2,mm3
647
    pmaxub	mm0,mm2
648
649
 
650
    add 	edi,8
651
    loop	@b
652
653
 
654
    mov        ecx,SIZE_X*3/4
655
    rep        stosd
656
end if
657
658
 
659
660
 
661
    cmp     [min_flag],0
662
    je	    .no_min
663
;    push	ecx
6619 leency 664
    mov        edi,screen
2736 leency 665
    mov        ecx,SIZE_X*3/4
666
  ;   ;    pxor       mm5,mm5
667
    xor        eax,eax
668
    rep        stosd
669
670
 
671
  @@:
672
    movq       mm0,[edi+SIZE_X*3]
673
    movq       mm1,[edi-SIZE_X*3]
674
    movq       mm2,[edi-3]
675
    movq       mm3,[edi+3]
676
677
 
678
    pminub	mm2,mm3
679
    pminub	mm0,mm2
680
681
 
682
    add 	edi,8
683
    loop	@b
684
685
 
686
687
 
688
    rep        stosd
689
end if
690
.no_min:
691
end if
692
2984 leency 693
 
1245 hidnplayr 694
    sub eax,[esp]
695
    sub eax,41
696
;    pop     eax
697
698
 
699
  .dc:
700
    xor     edx,edx
701
    mov     edi,10
702
    div     edi
703
    add     dl,30h
704
    mov     [STRdata+ecx-1],dl
705
    loop    .dc
706
    pop eax
707
708
 
709
    mov     ebx,screen
710
    mov     ecx,[size_y_var]
6619 leency 711
  ;  mov     ecx,SIZE_X shl 16 + SIZE_Y
712
    mov     edx,5 shl 16 + 25
2984 leency 713
    int     0x40
1245 hidnplayr 714
715
 
6619 leency 716
    mov  bx,[size_x_var]
717
    add  ebx,18
718
    shl  ebx,16
719
    mov  bx,60
720
    mov  cx,[size_y_var]
721
    sub  cx,2
722
    shl  ecx,16
723
    mov  cx,9
724
    xor  edx,edx
2736 leency 725
    int  40h
726
6619 leency 727
 
1245 hidnplayr 728
    mov  bx,[size_x_var]
6619 leency 729
    add  ebx,18
730
    shl  ebx,16
731
    mov  bx,[size_y_var]
732
    sub  bx,2	      ; [x start] *65536 + [y start]
733
    mov  ecx,0x00888888
2736 leency 734
    mov  edx,STRdata		   ; pointer to text beginning
1245 hidnplayr 735
    mov  esi,10 		   ; text length
736
    int  40h
737
738
 
739
 
2881 leency 740
1245 hidnplayr 741
 
2881 leency 742
 
1245 hidnplayr 743
744
 
745
;-------------------------PROCEDURES---------------------------------------------
746
;--------------------------------------------------------------------------------
747
include "TEX3.INC"
1728 clevermous 748
include "FLAT_CAT.INC"
749
include "TEX_CAT.INC"
750
include "BUMP_CAT.INC"
751
include "3DMATH.INC"
752
include "GRD_LINE.INC"
2881 leency 753
include "GRD3.INC"
1728 clevermous 754
include "FLAT3.INC"
755
include "BUMP3.INC"
756
include "B_PROCS.INC"
757
include "A_PROCS.INC"
758
include "GRD_CAT.INC"
759
include "BUMP_TEX.INC"
760
include "GRD_TEX.INC"
761
include "TWO_TEX.INC"
762
include "ASC.INC"
5486 leency 763
1245 hidnplayr 764
 
2736 leency 765
 
2881 leency 766
 
1245 hidnplayr 767
    movzx    ecx,word[size_x_var]
6619 leency 768
    movzx    eax,word[size_y_var]
769
    mul      ecx
1245 hidnplayr 770
    lea      ecx,[eax*3]
771
    add      ecx,16
6619 leency 772
    and      ecx,0xfffffff0
773
    push     ecx
1245 hidnplayr 774
    shl      eax,2
775
    add      ecx,eax
776
    add      ecx,MEM_END
777
    mov      ebx,1
778
    mov      eax,64	; allocate mem	- resize app mem
6619 leency 779
    int      0x40
1245 hidnplayr 780
    mov      [screen_ptr],MEM_END
781
    mov      [Zbuffer_ptr],MEM_END
782
    pop      ecx
783
    add      [Zbuffer_ptr],ecx
784
ret
785
786
 
787
; updates flags and writing flag description
788
; in	ah - button number
6619 leency 789
	push	ax
1245 hidnplayr 790
	mov	edi,menu
791
      .ch_another:
792
	cmp	ah,byte[edi]	 ; ah = button id
793
	jne	@f
794
	mov	bl,byte[edi+11]  ; max_flag + 1
795
	cmp	bl,255
796
	je	.no_write
797
	inc	byte[edi+12]	 ; flag
798
	cmp	byte[edi+12],bl
799
	jne	.write
800
	mov	byte[edi+12],0
801
	jmp	.write
802
      @@:
803
	add	edi,17
804
	cmp	byte[edi],-1
805
	jne	.ch_another
806
     .write:
807
;     clreol   {pascal never dies}
808
;	   * eax = 13 - function number
6619 leency 809
;  * ebx = [coordinate on axis x]*65536 + [size on axis x]
1245 hidnplayr 810
;  * ecx = [coordinate on axis y]*65536 + [size on axis y]
811
;  * edx = color 0xRRGGBB or 0x80RRGGBB for gradient fill
812
813
 
814
	movzx	ecx,byte[edi]
815
	sub	cl,2
816
	lea	ecx,[ecx*3]
817
	lea	ecx,[ecx*5]
818
	add	ecx,28
819
	shl	ecx,16
820
	add	ecx,14	 ;  ecx = [coord y]*65536 + [size y]
6619 leency 821
	mov	bx,[size_x_var]
822
	shl	ebx,16
823
	add	ebx,(12+70)*65536+25	 ; [x start] *65536 + [size x]
824
	mov	edx,0x00000000			;  color  0x00RRGGBB
1245 hidnplayr 825
	int	0x40
826
827
 
828
	movzx	ebx,byte[edi]
829
	sub	bl,2
830
	lea	ebx,[ebx*3]
831
	lea	ebx,[ebx*5]
832
	mov	cx,[size_x_var]
6619 leency 833
	shl	ecx,16
834
	add	ebx,ecx
835
	add	ebx,(12+70)*65536+28	 ; [x start] *65536 + [y start]
836
	mov	ecx,0x00ddeeff			; font 1 & color ( 0xF0RRGGBB )
5763 leency 837
	movzx	edx,byte[edi+12]		; current flag
1245 hidnplayr 838
	shl	edx,2				; * 4 = text length
839
	add	edx,dword[edi+13]		; pointer to text beginning
840
	mov	esi,4				; text length -
841
						; flag description 4 characters
842
	int	0x40
843
844
 
845
	pop	ax
846
ret
847
normalize_all_light_vectors:
848
	mov	edi,lights
849
     @@:
850
	call	normalize_vector	   ;	   3dmath.inc
6619 leency 851
	add	edi,LIGHT_SIZE
1245 hidnplayr 852
	cmp	edi,lightsend	;ecx
853
	jl	@b
854
ret
855
856
 
857
;macro .comment222
858
;				 ; planar mapping
6619 leency 859
;	 mov	 esi,points
860
;	 mov	 edi,tex_points
861
;      @@:
1245 hidnplayr 862
;	  add	  esi,2
6619 leency 863
;	  movsd
864
;	  cmp	  dword[esi],dword -1
865
;	  jne	  @b
866
1245 hidnplayr 867
 
868
869
 
870
;      sub   esp,4
871
872
 
1776 yogev_ezra 873
      fldpi
1245 hidnplayr 874
      fadd	st,st
875
      mov	esi,[points_ptr]
876
      mov	edi,tex_points
877
      movzx	ecx,[points_count_var]
878
      inc	ecx
879
;      cmp	 [map_tex_flag],1
6619 leency 880
;      jne	 .cylindric
881
      ; spherical mapping around y axle
1776 yogev_ezra 882
1245 hidnplayr 883
 
884
      fld	dword[esi]     ; x coord
885
      fld	dword[esi+8]   ; z coord
886
      fpatan		       ; arctg(st1/st)
887
;      fdiv	 .Pi2
6619 leency 888
      fdiv	st0,st1
1245 hidnplayr 889
      fimul	[tex_x_div2]
890
      fiadd	[tex_x_div2]
891
      fistp	word[edi]      ; x
892
893
 
894
      fld	dword[esi]     ; x
895
      fmul	st,st0
896
      fld	dword[esi+4]   ; y
897
      fmul	st,st0
898
      fld	dword[esi+8]   ; z
899
      fmul	st,st0
900
      faddp
901
      faddp
902
      fsqrt
903
      fpatan
904
      fldpi
905
      fdivp
906
      fimul    [tex_y_div2]
907
      fiadd    [tex_y_div2]
908
      fistp    word[edi+2]     ; y
909
910
 
911
      add      edi,4
912
      loop     @b
913
      ffree    st0
914
;      jmp	.end_map
6619 leency 915
;  .cylindric:
1776 yogev_ezra 916
;	fld	dword[esi]     ; around y axle
6619 leency 917
;	fld	dword[esi+8]
918
;	fpatan
919
;	fdiv	st0,st1
920
;	fimul	[tex_x_div2]
921
;	fiadd	[tex_x_div2]
922
;	fistp	word[edi]
923
1245 hidnplayr 924
 
6619 leency 925
;	fimul	[tex_y_div2]
926
;	fiadd	[tex_y_div2]
927
;	fistp	word[edi+2]
928
1776 yogev_ezra 929
 
6619 leency 930
;	add	edi,4
931
;	loop	.cylindric
932
;	ffree	 st0
933
;;	mov	 esp,ebp
934
;   .end_map:
1776 yogev_ezra 935
ret
1245 hidnplayr 936
937
 
938
 
939
;env_map 512 x 512 x 3 bytes
940
.temp  equ word   [ebp-2]
941
.nEy   equ word  [ebp-4]
942
.nEx   equ word  [ebp-6]
943
.col_r equ    [ebp-8]
944
.col_g equ    [ebp-9]
945
.col_b equ    [ebp-10]
946
947
 
948
	 mov	  ebp,esp
949
	 sub	  esp,20
950
	 mov	  edi,envmap
951
	 fninit
952
953
 
6619 leency 954
    .ie_ver:
1245 hidnplayr 955
	 mov	  cx,- TEX_X / 2 ;256	; cx - horizontal coord = x
6619 leency 956
    .ie_hor:
1245 hidnplayr 957
	 xor	  ebx,ebx
958
	 mov	  dword .col_b, 0
959
     .light:
960
	 lea	  esi,[lights+ebx]
961
	 fld	  dword[esi]	 ; light vector x cooficient
962
	 fimul	  [tex_x_div2] ;[i256]
963
	 mov	  .temp,cx
964
	 fisubr   .temp
965
	 fistp	  .nEx
966
	 fld	  dword[esi+4]	 ; light vector y cooficient
967
	 fimul	  [tex_y_div2] ;[i256]
968
	 mov	  .temp,dx
969
	 fisubr   .temp
970
	 fistp	  .nEy
971
972
 
973
	 jl	  .update_counters
974
	 cmp	  .nEy,- TEX_Y / 2 ;256
975
	 jl	  .update_counters
976
	 cmp	  .nEx,TEX_X / 2 ;256
977
	 jg	  .update_counters
978
	 cmp	  .nEy,TEX_Y / 2 ;256
979
	 jg	  .update_counters
980
981
 
982
	 fmul	  st,st0
983
	 fild	  .nEy
984
	 fmul	  st,st0
985
	 faddp
986
	 fsqrt
987
	 fisubr   [i256]
988
	 fmul	  [env_const]
989
	 fidiv	  [i256]   ; st - 'virtual' dot product
990
991
 
992
	 fstsw	  ax
993
	 sahf
994
	 jb	  @f
995
	 ffree	  st
996
	 fld1	  ;[dot_max]
997
      @@:
998
	 fcom	  [dot_min]
999
	 fstsw	  ax
1000
	 sahf
1001
	 ja	  @f
1002
	 ffree	  st
1003
	 fldz	  ;[dot_min]
1004
      @@:
1005
	 push	  ebp
1006
	 movzx	  ax,byte[esi+21]
1007
	 push	  ax  ;- shines
1008
	 mov	  al,byte[esi+14]   ; b    orginal color
1009
	 push	  ax
1010
	 mov	  al,byte[esi+13]   ; g
1011
	 push	  ax
1012
	 mov	  al,byte[esi+12]   ; r
1013
	 push	  ax
1014
	 mov	  al,byte[esi+20]   ; b     max color
1015
	 push	  ax
1016
	 mov	  al,byte[esi+19]   ; g
1017
	 push	  ax
1018
	 mov	  al,byte[esi+18]   ; r
1019
	 push	  ax
1020
	 mov	  al,byte[esi+17]   ; b    min col
1021
	 push	  ax
1022
	 mov	  al,byte[esi+16]   ; g
1023
	 push	  ax
1024
	 mov	  al,byte[esi+15]   ; r
1025
	 push	  ax
1026
	 push	  eax	      ; earlier - dot pr
1027
      ;  fstp	  .dot_product
6619 leency 1028
      ;  push	  .dot_product
1029
	 call	  calc_one_col
1245 hidnplayr 1030
	 pop	  ebp
1031
	 ; eax-0x00rrggbb
1032
	 cmp	  al,.col_b
1033
	 jbe	  @f
1034
	 mov	  .col_b,al
1035
   @@:			      ;  eax - ggbb00rr
1036
	 shr	  ax,8
1037
	 cmp	  al,.col_g
1038
	 jbe	  @f
1039
	 mov	  .col_g,al
1040
   @@:			      ;  eax - bb0000gg
1041
	 shr	  eax,16
1042
	 cmp	  al,.col_r
1043
	 jbe	  @f
1044
	 mov	  .col_r,al
1045
   @@:
1046
   .update_counters:			 ; update and jump when neccesery
1047
	 add	  ebx,LIGHT_SIZE
1048
	 cmp	  bx,[all_lights_size]
1049
	 jl	  .light    ; next_light
1050
	 mov	  eax,dword .col_b
1051
	 stosd
1052
	 dec	  edi
1053
1054
 
1055
	 cmp	  cx,TEX_X / 2 ;256
1056
	 jne	  .ie_hor
1057
1058
 
1059
	 cmp	  dx,TEX_Y / 2 ;256
1060
	 jne	 .ie_ver
1061
1062
 
1063
	 pop	 ebp
1064
ret
1065
1066
 
1931 yogev_ezra 1067
 
1068
 
1245 hidnplayr 1069
;env_map 512 x 512 x 3 bytes	; many lights using
6619 leency 1070
.temp  equ word   [ebp-2]
1245 hidnplayr 1071
.nz    equ dword  [ebp-6]  ; dword
1072
.ny    equ dword  [ebp-10]
1073
.nx    equ dword  [ebp-14]
1074
.col_r equ    [ebp-16]
1075
.col_g equ    [ebp-17]
1076
.col_b equ    [ebp-18]
1077
1078
 
1079
	 mov	  ebp,esp
1080
	 sub	  esp,20
1081
	 mov	  edi,color_map
1082
	 fninit
1083
1084
 
6619 leency 1085
    .ie_ver:
1245 hidnplayr 1086
	 mov	  cx,- TEX_X / 2 ;256	; cx - horizontal coord = x
6619 leency 1087
    .ie_hor:
1245 hidnplayr 1088
	 mov	  .temp,cx
1089
	 fild	  .temp
1090
	 fidiv	  [i256]   ;st = Nx - vector normal x cooficient
1091
	 fst	  .nx
1092
	 fmul	  st,st0
1093
	 mov	  .temp,dx
1094
	 fild	  .temp
1095
	 fidiv	  [i256]   ; st = Ny - vector normal y coeficient
1096
	 fst	  .ny
1097
	 fmul	  st,st0
1098
	 faddp
1099
	 fld1
1100
	 fchs
1101
	 faddp
1102
	 fabs
1103
	 fsqrt
1104
	 fchs
1105
	 fstp	  .nz		   ; st - Nz - vect normal z coeficient
1106
	 xor	  ebx,ebx
1107
	 mov	  dword .col_b, 0
1108
     .light:
1109
	 push	  edi	;env_map
1110
	 lea	  esi,[lights+ebx]
1111
	 lea	  edi,.nx
1112
	 call	  dot_product
1113
	 pop	  edi
1114
	 fcom	  [dot_min]
1115
	 fstsw	  ax
1116
	 sahf
1117
	 ja	  .env_ok1  ;compare with dot_max
1118
	 ffree	  st
1119
1120
 
1121
      .env_ok1:
1122
	 fcom	 [dot_max]
1123
	 fstsw	 ax
1124
	 sahf
1125
	 jb	 .env_ok2     ; calc col
1126
	 ffree	 st
1127
	 jmp	 .update_counters
1128
      .env_ok2: 	   ;calc col
1129
	 push	  ebp
1130
	 movzx	  ax,byte[esi+21]
1131
	 push	  ax  ;- shines
1132
	 mov	  al,byte[esi+14]   ; b    orginal color
1133
	 push	  ax
1134
	 mov	  al,byte[esi+13]   ; g
1135
	 push	  ax
1136
	 mov	  al,byte[esi+12]   ; r
1137
	 push	  ax
1138
	 mov	  al,byte[esi+20]   ; b     max color
1139
	 push	  ax
1140
	 mov	  al,byte[esi+19]   ; g
1141
	 push	  ax
1142
	 mov	  al,byte[esi+18]   ; r
1143
	 push	  ax
1144
	 mov	  al,byte[esi+17]   ; b    min col
1145
	 push	  ax
1146
	 mov	  al,byte[esi+16]   ; g
1147
	 push	  ax
1148
	 mov	  al,byte[esi+15]   ; r
1149
	 push	  ax
1150
	 push	  eax	      ; earlier - dot pr
1151
      ;  fstp	  .dot_product
6619 leency 1152
      ;  push	  .dot_product
1153
	 call	  calc_one_col
1245 hidnplayr 1154
	 pop	  ebp
1155
	 ; eax-0x00rrggbb
1156
	 cmp	  al,.col_b
1157
	 jbe	  @f
1158
	 mov	  .col_b,al
1159
   @@:
1160
	 shr	  ax,8
1161
	 cmp	  al,.col_g
1162
	 jbe	  @f
1163
	 mov	  .col_g,al
1164
   @@:
1165
	 shr	  eax,16
1166
	 cmp	  al,.col_r
1167
	 jbe	  @f
1168
	 mov	  .col_r,al
1169
  @@:
1170
 .update_counters:				    ; update and jump when neccesery
1171
	add	ebx,LIGHT_SIZE
1172
	cmp	bx,[all_lights_size]
1173
	jl	.light	  ; next_light
1174
	mov	eax,dword .col_b
1175
	stosd
1176
	dec	edi
1177
1178
 
1179
	cmp	cx,TEX_X / 2 ;256
1180
	jne	.ie_hor
1181
1182
 
1183
	cmp	dx,TEX_X / 2 ;256
1184
	jne	.ie_ver
1185
1186
 
1187
	 mov	 esp,ebp
1188
	 pop	 ebp
1189
ret
1190
if 0
1191
init_triangles_normals:
1192
	mov	ebx,triangles_normals
1193
	mov	ebp,triangles
1194
     @@:
1195
	push	ebx
1196
	mov	ebx,vectors
1197
	movzx	esi,word[ebp]	       ; first point index
1198
	lea	esi,[esi*3]
1199
	lea	esi,[points+esi*2]     ; esi - pointer to 1st 3d point
1200
	movzx	edi,word[ebp+2]        ; second point index
1201
	lea	edi,[edi*3]
1202
	lea	edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
1203
	call	make_vector
1204
	add	ebx,12
1205
	mov	esi,edi
1206
	movzx	edi,word[ebp+4]        ; third point index
1207
	lea	edi,[edi*3]
1208
	lea	edi,[points+edi*2]
1209
	call	make_vector
1210
	mov	edi,ebx 		; edi - pointer to 2nd vector
1211
	mov	esi,ebx
1212
	sub	esi,12			; esi - pointer to 1st vector
1213
	pop	ebx
1214
	call	cross_product
1215
	mov	edi,ebx
1216
	call	normalize_vector
1217
	add	ebp,6
1218
	add	ebx,12
1219
	cmp	dword[ebp],-1
1220
	jne	@b
1221
ret
1222
end if
1223
init_point_normals:
1224
.x equ dword [ebp-4]
1225
.y equ dword [ebp-8]
1226
.z equ dword [ebp-12]
1227
.point_number equ word [ebp-26]
1228
.hit_faces    equ word [ebp-28]
1229
1230
 
1231
	mov	  ebp,esp
1232
	sub	  esp,28
1233
	mov	  edi,[points_normals_ptr]
1234
	mov	  .point_number,0
1235
    .ipn_loop:
1236
	mov	  .hit_faces,0
1237
	mov	  .x,0
1238
	mov	  .y,0
1239
	mov	  .z,0
1240
	mov	  esi,[triangles_ptr]
1241
	xor	  ecx,ecx	       ; ecx - triangle number
1242
    .ipn_check_face:
1243
	xor	  ebx,ebx	       ; ebx - 'position' in one triangle
1244
    .ipn_check_vertex:
1245
	movzx	  eax,word[esi+ebx]    ;  eax - point_number
1246
	cmp	  ax,.point_number
1247
	jne	  .ipn_next_vertex
1248
	push	  esi
1249
	mov	  esi,ecx
1250
	lea	  esi,[esi*3]
1251
       ; lea	   esi,[triangles_normals+esi*4]
6619 leency 1252
	shl	  esi,2
1245 hidnplayr 1253
	add	  esi,[triangles_normals_ptr]
1254
1255
 
1256
	fadd	  dword[esi+vec_x]	 ; vec_x this defined in 3dmath.asm - x cooficient
1257
	fstp	  .x			 ; of normal vactor
1258
	fld	  .y
1259
	fadd	  dword[esi+vec_y]
1260
	fstp	  .y
1261
	fld	  .z
1262
	fadd	  dword[esi+vec_z]
1263
	fstp	  .z
1264
	pop	  esi
1265
	inc	  .hit_faces
1266
	jmp	  .ipn_next_face
1267
    .ipn_next_vertex:
1268
	add	  ebx,2
1269
	cmp	  ebx,6
1270
	jne	  .ipn_check_vertex
1271
    .ipn_next_face:
1272
	add	  esi,6
1273
	inc	  ecx
1274
	cmp	  cx,[triangles_count_var]
1275
	jne	  .ipn_check_face
1276
1277
 
1278
	fidiv	  .hit_faces
1279
	fstp	  dword[edi+vec_x]
1280
	fld	  .y
1281
	fidiv	  .hit_faces
1282
	fstp	  dword[edi+vec_y]
1283
	fld	  .z
1284
	fidiv	  .hit_faces
1285
	fstp	  dword[edi+vec_z]
1286
	call	  normalize_vector
1287
	add	  edi,12  ;type vector 3d
1288
	inc	  .point_number
1289
	mov	  dx,.point_number
1290
	cmp	  dx,[points_count_var]
1291
	jne	  .ipn_loop
1292
1293
 
1294
ret
1295
;===============================================================
1296
1297
 
1298
	mov	ebx,[triangles_normals_ptr]
1299
	mov	ebp,[triangles_ptr]
1300
     @@:
1301
	push	ebx
1302
	mov	ebx,vectors
1303
	movzx	esi,word[ebp]	       ; first point index
1304
	lea	esi,[esi*3]
1305
;	 lea	 esi,[points+esi*2]	; esi - pointer to 1st 3d point
6619 leency 1306
	shl	esi,2
1245 hidnplayr 1307
	add	esi,[points_ptr]
1308
	movzx	edi,word[ebp+2] 	 ; first point index
1309
	lea	edi,[edi*3]
1310
	shl	edi,2
1311
	add	edi,[points_ptr]
1312
;	 movzx	 edi,word[ebp+2]	; second point index
6619 leency 1313
;	 lea	 edi,[edi*3]
1314
;	 lea	 edi,[points+edi*2]	; edi - pointer to 2nd 3d point
1315
	call	make_vector_r
1245 hidnplayr 1316
	add	ebx,12
1317
	mov	esi,edi
1318
	movzx	edi,word[ebp+4]        ; third point index
1319
	lea	edi,[edi*3]
1320
	shl	edi,2
1321
	add	edi,[points_ptr]
1322
;	 lea	 edi,[points+edi*2]
6619 leency 1323
	call	make_vector_r
1245 hidnplayr 1324
	mov	edi,ebx 		; edi - pointer to 2nd vector
1325
	mov	esi,ebx
1326
	sub	esi,12			; esi - pointer to 1st vector
1327
	pop	ebx
1328
	call	cross_product
1329
	mov	edi,ebx
1330
	call	normalize_vector
1331
	add	ebp,6
1332
	add	ebx,12
1333
	cmp	dword[ebp],-1
1334
	jne	@b
1335
ret
1336
1337
 
1338
 
1339
sort_triangles:
1340
	mov	esi,[triangles_ptr]
1341
	mov	edi,triangles_with_z
1342
	mov	ebp,[points_translated_ptr]
1343
1344
 
1345
	movzx	eax,word[esi]
1346
	lea	eax,[eax*3]
1347
	movzx	ecx,word[ebp+eax*2+4]
1348
1349
 
1350
	lea	eax,[eax*3]
1351
	add	cx,word[ebp+eax*2+4]
1352
1353
 
1354
	lea	eax,[eax*3]
1355
	add	cx,word[ebp+eax*2+4]
1356
1357
 
1358
       ; cwd
1359
       ; idiv	 word[i3]
6619 leency 1360
	movsd			; store vertex coordinates
1245 hidnplayr 1361
	movsw
1362
	stosw			; middle vertex coordinate  'z' in triangles_with_z list
1363
	cmp	dword[esi],-1
1364
	jne	make_triangle_with_z
1365
	movsd			; copy end mark
1366
	mov	eax,4
1367
	lea	edx,[edi-8-trizdd]
1368
     ;	 lea	 edx, [edi-8]
6619 leency 1369
     ;	 sub	 edx,[triangles_w_z_ptr]
1370
	mov	[high],edx
1245 hidnplayr 1371
	call	quicksort
1372
	mov	eax,4
1373
	mov	edx,[high]
1374
	call	insertsort
1375
	jmp	end_sort
1376
1377
 
1378
	mov	ecx,edx
1379
	sub	ecx,eax
1380
	cmp	ecx,32
1381
	jc	.exit
1382
	lea	ecx,[eax+edx]
1383
	shr	ecx,4
1384
	lea	ecx,[ecx*8-4];
1385
;	 mov	 edi,[triangles_w_z_ptr]
6619 leency 1386
;	 mov	 ebx,[edi+eax]
1387
;	 mov	 esi,[edi+ecx]
1388
;	 mov	 edi,[edi+edx]
1389
	mov	ebx,[trizdd+eax]; trizdd[l]
1245 hidnplayr 1390
	mov	esi,[trizdd+ecx]; trizdd[i]
1391
	mov	edi,[trizdd+edx]; trizdd[h]
1392
	cmp	ebx,esi
1393
	jg	@f		; direction NB! you need to negate these to invert the order
1394
      if Ext=NON
1395
	mov	[trizdd+eax],esi
1396
	mov	[trizdd+ecx],ebx
1397
	mov	ebx,[trizdd+eax-4]
1398
	mov	esi,[trizdd+ecx-4]
1399
	mov	[trizdd+eax-4],esi
1400
	mov	[trizdd+ecx-4],ebx
1401
	mov	ebx,[trizdd+eax]
1402
	mov	esi,[trizdd+ecx]
1403
      else
1404
;	 push	 ebx
6619 leency 1405
;	 mov	 ebx,[triangles_w_z_ptr]
1406
;	 movq	 mm0,[ebx+eax-4]
1407
;	 movq	 mm1,[ebx+ecx-4]
1408
;	 movq	 [ebx+ecx-4],mm0
1409
;	 movq	 [ebx+eax-4],mm1
1410
;	 pop	 ebx
1411
	movq	mm0,[trizdq+eax-4]
1245 hidnplayr 1412
	movq	mm1,[trizdq+ecx-4]
1413
	movq	[trizdq+ecx-4],mm0
1414
	movq	[trizdq+eax-4],mm1
1415
	xchg	ebx,esi
1416
      end if
1417
      @@:
1418
	cmp	ebx,edi
1419
	jg	@f		; direction
1420
      if Ext=NON
1421
	mov	[trizdd+eax],edi
1422
	mov	[trizdd+edx],ebx
1423
	mov	ebx,[trizdd+eax-4]
1424
	mov	edi,[trizdd+edx-4]
1425
	mov	[trizdd+eax-4],edi
1426
	mov	[trizdd+edx-4],ebx
1427
	mov	ebx,[trizdd+eax]
1428
	mov	edi,[trizdd+edx]
1429
      else
1430
;	 push	 ebx
6619 leency 1431
;	 mov	 ebx,[triangles_w_z_ptr]
1432
;	 movq	 mm0,[ebx+eax-4]
1433
;	 movq	 mm1,[ebx+edx-4]
1434
;	 movq	 [ebx+edx-4],mm0
1435
;	 movq	 [ebx+eax-4],mm1
1436
	movq	mm0,[trizdq+eax-4]
1245 hidnplayr 1437
	movq	mm1,[trizdq+edx-4]
1438
	movq	[trizdq+edx-4],mm0
1439
	movq	[trizdq+eax-4],mm1
1440
;	 pop	 ebx
6619 leency 1441
	xchg	ebx,edi
1245 hidnplayr 1442
      end if
1443
      @@:
1444
	cmp	esi,edi
1445
	jg	@f		; direction
1446
      if Ext=NON
1447
	mov	[trizdd+ecx],edi
1448
	mov	[trizdd+edx],esi
1449
	mov	esi,[trizdd+ecx-4]
1450
	mov	edi,[trizdd+edx-4]
1451
	mov	[trizdd+ecx-4],edi
1452
	mov	[trizdd+edx-4],esi
1453
      else
1454
;	 push	 ebx
6619 leency 1455
;	 mov	 ebx,[triangles_w_z_ptr]
1456
;	 movq	 mm0,[ebx+ecx-4]
1457
;	 movq	 mm1,[ebx+edx-4]
1458
;	 movq	 [ebx+edx-4],mm0
1459
;	 movq	 [ebx+ecx-4],mm1
1460
;	 pop	 ebx
1461
1245 hidnplayr 1462
 
1463
	movq	mm1,[trizdq+edx-4]
1464
	movq	[trizdq+edx-4],mm0
1465
	movq	[trizdq+ecx-4],mm1
1466
	xchg	ebx,esi
1467
      end if
1468
      @@:
1469
	mov	ebp,eax 	; direction
1470
	add	ebp,8	   ;   j
1471
      if Ext=NON
1472
	mov	esi,[trizdd+ebp]
1473
	mov	edi,[trizdd+ecx]
1474
	mov	[trizdd+ebp],edi
1475
	mov	[trizdd+ecx],esi
1476
	mov	esi,[trizdd+ebp-4]
1477
	mov	edi,[trizdd+ecx-4]
1478
	mov	[trizdd+ecx-4],esi
1479
	mov	[trizdd+ebp-4],edi
1480
      else
1481
;	 push	 ebx
6619 leency 1482
;	 mov	 ebx,[triangles_w_z_ptr]
1483
;	 movq	 mm0,[ebx+ebp-4]
1484
;	 movq	 mm1,[ebx+ecx-4]
1485
;	 movq	 [ebx+ecx-4],mm0
1486
;	 movq	 [ebx+ebp-4],mm1
1487
;	 pop	 ebx
1488
1245 hidnplayr 1489
 
1490
	movq	mm1,[trizdq+ecx-4]
1491
	movq	[trizdq+ecx-4],mm0
1492
	movq	[trizdq+ebp-4],mm1
1493
      end if
1494
	mov	ecx,edx    ;   i; direction
1495
	mov	ebx,[trizdd+ebp]; trizdd[j]
1496
;	 mov	 ebx, [triangles_w_z_ptr]
6619 leency 1497
;	 add	 ebx, ebp
1498
1245 hidnplayr 1499
 
6619 leency 1500
 ;	 mov	 eax, [triangles_w_z_ptr]
1501
      .loop:
1245 hidnplayr 1502
	sub	ecx,8		; direction
1503
	cmp	[trizdd+ecx],ebx
1504
;	 cmp	 [eax+ecx],ebx
6619 leency 1505
	jl	.loop		; direction
1245 hidnplayr 1506
      @@:
1507
	add	ebp,8		; direction
1508
	cmp	[trizdd+ebp],ebx
1509
;	 cmp	 [eax+ebp],ebx
6619 leency 1510
	jg	@b		; direction
1245 hidnplayr 1511
	cmp	ebp,ecx
1512
	jge	@f		; direction
1513
      if Ext=NON
1514
	mov	esi,[trizdd+ecx]
1515
	mov	edi,[trizdd+ebp]
1516
	mov	[trizdd+ebp],esi
1517
	mov	[trizdd+ecx],edi
1518
	mov	edi,[trizdd+ecx-4]
1519
	mov	esi,[trizdd+ebp-4]
1520
	mov	[trizdd+ebp-4],edi
1521
	mov	[trizdd+ecx-4],esi
1522
      else
1523
;	 movq	 mm0,[eax+ecx-4]
6619 leency 1524
;	 movq	 mm1,[eax+ebp-4]
1525
;	 movq	 [eax+ebp-4],mm0
1526
;	 movq	 [eax+ecx-4],mm1
1527
	movq	mm0,[trizdq+ecx-4]
1245 hidnplayr 1528
	movq	mm1,[trizdq+ebp-4]
1529
	movq	[trizdq+ebp-4],mm0
1530
	movq	[trizdq+ecx-4],mm1
1531
      end if
1532
	jmp	.loop
1533
;	 pop	 eax
6619 leency 1534
      @@:
1245 hidnplayr 1535
      if Ext=NON
1536
	mov	esi,[trizdd+ecx]
1537
	mov	edi,[trizdd+eax+8]
1538
	mov	[trizdd+eax+8],esi
1539
	mov	[trizdd+ecx],edi
1540
	mov	edi,[trizdd+ecx-4]
1541
	mov	esi,[trizdd+eax+4]
1542
	mov	[trizdd+eax+4],edi
1543
	mov	[trizdd+ecx-4],esi
1544
      else
1545
;	 push	 edx
6619 leency 1546
;	 mov	 edx,[triangles_w_z_ptr]
1547
;	 movq	 mm0,[edx+ecx-4]
1548
;	 movq	 mm1,[edx+eax+4]; dir
1549
;	 movq	 [edx+eax+4],mm0; dir
1550
;	 movq	 [edx+ecx-4],mm1
1551
;	 pop	 edx
1552
1245 hidnplayr 1553
 
1554
	movq	mm1,[trizdq+eax+4]; dir
1555
	movq	[trizdq+eax+4],mm0; dir
1556
	movq	[trizdq+ecx-4],mm1
1557
      end if
1558
	add	ecx,8
1559
	push	ecx edx
1560
	mov	edx,ebp
1561
	call	quicksort
1562
	pop	edx eax
1563
	call	quicksort
1564
      .exit:
1565
    ret
1566
    insertsort:
1567
	mov	esi,eax
1568
      .start:
1569
	add	esi,8
1570
	cmp	esi,edx
1571
	ja	.exit
1572
	mov	ebx,[trizdd+esi]
1573
;	 mov	 ebx,[triangles_w_z_ptr]
6619 leency 1574
;	 add	 ebx,esi
1575
      if Ext=NON
1245 hidnplayr 1576
	mov	ecx,[trizdd+esi-4]
1577
      else
1578
;	 push	 ebx
6619 leency 1579
;	 mov	 ebx,[triangles_w_z_ptr]
1580
;	 movq	 mm1,[ebx+esi-4]
1581
	movq	mm1,[trizdq+esi-4]
1245 hidnplayr 1582
;	 pop	 ebx
6619 leency 1583
      end if
1245 hidnplayr 1584
	mov	edi,esi
1585
      @@:
1586
	cmp	edi,eax
1587
	jna	@f
1588
;	 push	 eax
6619 leency 1589
;	 mov	 eax,[triangles_w_z_ptr]
1590
;	 cmp	 [eax+edi-8],ebx
1591
;	 pop	 eax
1592
       cmp     [trizdd+edi-8],ebx
1245 hidnplayr 1593
	jg	@f		   ; direction
1594
      if Ext=NON
1595
	mov	ebp,[trizdd+edi-8]
1596
	mov	[trizdd+edi],ebp
1597
	mov	ebp,[trizdd+edi-12]
1598
	mov	[trizdd+edi-4],ebp
1599
      else
1600
;	 push	 eax
6619 leency 1601
;	 mov	 eax,[triangles_w_z_ptr]
1602
;	 movq	 mm0,[eax+edi-12]
1603
;	 movq	 [eax+edi-4],mm0
1604
	movq	mm0,[trizdq+edi-12]
1245 hidnplayr 1605
	movq	[trizdq+edi-4],mm0
1606
;	 pop	 eax
6619 leency 1607
      end if
1245 hidnplayr 1608
	sub	edi,8
1609
	jmp	@b
1610
      @@:
1611
      if Ext=NON
1612
	mov	[trizdd+edi],ebx
1613
	mov	[trizdd+edi-4],ecx
1614
      else
1615
;	 push	 eax
6619 leency 1616
;	 mov	 eax,[triangles_w_z_ptr]
1617
;	 movq	 [eax+edi-4],mm1
1618
	movq	[trizdq+edi-4],mm1
1245 hidnplayr 1619
;	 pop	 eax
6619 leency 1620
      end if
1245 hidnplayr 1621
	jmp	.start
1622
      .exit:
1623
    ret
1624
   end_sort:
1625
    ; translate triangles_with_z to sorted_triangles
1626
	mov	esi,triangles_with_z
1627
;	 mov	  esi,[triangles_w_z_ptr]
6619 leency 1628
      ;  mov	 edi,sorted_triangles
1629
	mov	 edi,[triangles_ptr]
1245 hidnplayr 1630
    again_copy:
1631
      if Ext=NON
1632
	movsd
1633
	movsw
1634
	add	esi,2
1635
      else
1636
	movq	mm0,[esi]
1637
	movq	[edi],mm0
1638
	add	esi,8
1639
	add	edi,6
1640
      end if
1641
	cmp	dword[esi],-1
1642
	jne	again_copy
1643
;      if Ext=MMX
1644
;	 emms
6619 leency 1645
;      end if
1245 hidnplayr 1646
	movsd  ; copy end mark too
1647
ret
1648
1649
 
1650
	mov	edi,screen
1651
	movzx	ecx,word[size_x_var]
6619 leency 1652
	movzx	eax,word[size_y_var]
1653
	imul	ecx,eax
1654
	lea	ecx,[ecx*3]
1655
	shr	ecx,2
1656
	xor	eax,eax
1245 hidnplayr 1657
      if Ext=NON
1658
	rep	stosd
1659
      else if Ext = MMX
6619 leency 1660
	pxor	mm0,mm0
1245 hidnplayr 1661
      @@:
1662
	movq	[edi+00],mm0
1663
	movq	[edi+08],mm0
1664
	movq	[edi+16],mm0
1665
	movq	[edi+24],mm0
1666
	add	edi,32
1667
	sub	ecx,8
1668
	jnc	@b
1669
      else
6619 leency 1670
	push	ecx
1671
	mov	ecx,edi
1672
	and	ecx,0x0000000f
1673
	rep	stosb
1674
	pop	ecx
1675
	and	ecx,0xfffffff0
1676
	xorps	xmm0,xmm0
1677
      @@:
1678
	movaps	[edi],xmm0
1679
	movaps	[edi+16],xmm0
1680
	movaps	[edi+32],xmm0
1681
	movaps	[edi+48],xmm0
1682
	add	edi,64
1683
	sub	ecx,16
1684
	jnz	@b
1685
      end if
1245 hidnplayr 1686
6619 leency 1687
 
1245 hidnplayr 1688
1689
 
1690
 
1691
	mov esi,[triangles_ptr]
1692
	mov [edges_counter],0
2881 leency 1693
    .again_dts:
1245 hidnplayr 1694
	mov ebp,[points_translated_ptr]
1695
      if Ext=NON
1696
	movzx	eax,word[esi]
1697
	mov	[point_index1],ax
1698
	lea	eax,[eax*3]
1699
	add	eax,eax
1700
	push	ebp
1701
	add	ebp,eax
1702
	mov	eax,[ebp]
1703
	mov	dword[xx1],eax
1704
	mov	eax,[ebp+4]
1705
	mov	[zz1],ax
1706
	pop	ebp
1707
1708
 
1709
 
1710
	mov	[point_index2],ax
1711
	lea	eax,[eax*3]
1712
	add	eax,eax
1713
	push	ebp
1714
	add	ebp,eax
1715
	mov	eax,[ebp]
1716
	mov	dword[xx2],eax
1717
	mov	eax,[ebp+4]
1718
	mov	[zz2],ax
1719
	pop	ebp
1720
1721
 
1722
 
1723
	mov	[point_index3],ax
1724
	lea	eax,[eax*3]
1725
	add	eax,eax
1726
    ;	 push	 ebp
6619 leency 1727
	add	ebp,eax
1245 hidnplayr 1728
	mov	eax,[ebp]
1729
	mov	dword[xx3],eax
1730
	mov	eax,[ebp+4]
1731
	mov	[zz3],ax
1732
      else
1733
	mov	eax,dword[esi]		 ; don't know MMX
1734
	mov	dword[point_index1],eax
1735
       ; shr	 eax,16
6619 leency 1736
       ; mov	 [point_index2],ax
1737
	mov	ax,word[esi+4]
1245 hidnplayr 1738
	mov	[point_index3],ax
1739
	movq	mm0,[esi]
1740
	pmullw	mm0,qword[const6]
1741
	movd	eax,mm0
1742
	psrlq	mm0,16
1743
	movd	ebx,mm0
1744
	psrlq	mm0,16
1745
	movd	ecx,mm0
1746
	and	eax,0FFFFh
1747
	and	ebx,0FFFFh
1748
	and	ecx,0FFFFh
1749
	movq	mm0,[ebp+eax]
1750
	movq	mm1,[ebp+ebx]
1751
	movq	mm2,[ebp+ecx]
1752
	movq	qword[xx1],mm0
1753
	movq	qword[xx2],mm1
1754
	movq	qword[xx3],mm2
1755
;	 emms
6619 leency 1756
      end if				  ; *********************************
1245 hidnplayr 1757
	push esi			  ;
1758
	fninit				  ; DO culling AT FIRST
1759
	cmp	[culling_flag],1	  ; (if culling_flag = 1)
1760
	jne	.no_culling
1761
	mov	esi,point_index1	  ; *********************************
1762
	mov	ecx,3			  ;
1763
      @@:
1764
	movzx	eax,word[esi]
1765
	lea	eax,[eax*3]
1766
	shl	eax,2
1767
	add	eax,[points_normals_rot_ptr]
1768
;	 lea	 eax,[eax+point_normals_rotated]
6619 leency 1769
	fld	dword[eax+8]		 ; *****************************
1245 hidnplayr 1770
	ftst				 ; CHECKING OF Z COOFICIENT OF
1771
	fstsw	ax			 ; NORMAL VECTOR
1772
	sahf
1773
	jb	@f
1774
	ffree	st
1775
	loop	@b
1776
	jmp	.end_draw   ; non visable
1777
      @@:
1778
	ffree	st  ;is visable
1779
      .no_culling:
1780
	cmp	[dr_flag],0		  ; draw type flag
1781
	je	.flat_draw
1782
	cmp	[dr_flag],2
1783
	je	.env_mapping
1784
	cmp	[dr_flag],3
1785
	je	.bump_mapping
1786
	cmp	[dr_flag],4
1787
	je	.tex_mapping
1788
	cmp	[dr_flag],5
1789
	je	.rainbow
1790
	cmp	[dr_flag],7
1791
	je	.grd_tex
1792
	cmp	[dr_flag],8
1793
	je	.two_tex
1794
	cmp	[dr_flag],9
1795
	je	.bump_tex
1796
	cmp	[dr_flag],10
1797
	je	.cubic_env_mapping
1798
	cmp	[dr_flag],11
2881 leency 1799
	je	.draw_smooth_line
1800
				      ; ****************
1245 hidnplayr 1801
	mov	esi,point_index3      ; do Gouraud shading
1802
	mov	ecx,3
1803
      .again_grd_draw:
1804
	movzx	eax,word[esi]
1805
	shl	eax,2
1806
	lea	eax,[eax*3]
1807
	add	eax,[points_normals_rot_ptr]
1808
	; texture x=(rotated point normal -> x * 255)+255
1809
	fld	dword[eax]	 ; x cooficient of normal vector
1810
	fimul	[correct_tex]
1811
	fiadd	[correct_tex]
1812
	fistp	word[esp-2]
1813
	; texture y=(rotated point normal -> y * 255)+255
1814
	fld	dword[eax+4]	  ; y cooficient
1815
	fimul	[correct_tex]
1816
	fiadd	[correct_tex]
1817
	fistp	word[esp-4]
1818
1819
 
1820
	movzx	 ebx,word[esp-2]
1821
	shl	 eax,TEX_SHIFT
1822
	add	 eax,ebx
1823
	lea	 eax,[eax*3+color_map]
1824
	mov	 eax,dword[eax]
1825
	cmp	[catmull_flag],1      ; put on stack z coordinate if necessary
1826
	jne	 @f
1827
	lea	 edx,[ecx*3]
1828
	push	 word[edx*2+xx1-2]    ; zz1 ,2 ,3
1829
      @@:
1830
	ror	 eax,16 	      ; eax -0xxxrrggbb -> 0xggbbxxrr
1831
	xor	 ah,ah
1832
	push	 ax	    ;r
1833
	rol	 eax,8		      ; eax-0xggbb00rr -> 0xbb00rrgg
1834
	xor	 ah,ah
1835
	push	 ax	    ;g
1836
	shr	 eax,24
1837
	push	 ax	    ;b
1838
1839
 
1840
	dec	 cx
1841
	jnz	 .again_grd_draw
1842
	jmp	 .both_draw
1843
1844
 
6619 leency 1845
   ;	 lea	 edi,[edi*3]
1846
   ;	 lea	 edi,[4*edi+point_normals_rotated] ; edi - normal
1847
   ;	 mov	 esi,light_vector
1848
   ;	 call	 dot_product
1849
   ;	 fabs
1850
   ;	 fimul	 [orginal_color_r]
1851
   ;	 fistp	 [temp_col]
1852
   ;	 and	 [temp_col],0x00ff
1853
   ;	 push	 [temp_col]
1854
   ;	 push	 [temp_col]
1855
   ;	 push	 [temp_col]
1856
1245 hidnplayr 1857
 
6619 leency 1858
   ;	 lea	 edi,[edi*3]
1859
   ;	 lea	 edi,[4*edi+point_normals_rotated] ; edi - normal
1860
   ;	 mov	 esi,light_vector
1861
   ;	 call	 dot_product
1862
   ;	 fabs
1863
   ;	 fimul	 [orginal_color_r]
1864
   ;	 fistp	  [temp_col]
1865
   ;	 and	 [temp_col],0x00ff
1866
   ;	 push	 [temp_col]
1867
   ;	 push	 [temp_col]
1868
   ;	 push	 [temp_col]
1869
1245 hidnplayr 1870
 
6619 leency 1871
   ;	 lea	 edi,[edi*3]
1872
   ;	 lea	 edi,[4*edi+point_normals_rotated] ; edi - normal
1873
   ;	 mov	 esi,light_vector
1874
   ;	 call	 dot_product
1875
   ;	 fabs
1876
   ;	 fimul	 [orginal_color_r]
1877
   ;	 fistp	 [temp_col]
1878
   ;	 and	 [temp_col],0x00ff
1879
   ;	 push	 [temp_col]
1880
   ;	 push	 [temp_col]
1881
   ;	 push	 [temp_col]
1882
   .rainbow:
1245 hidnplayr 1883
	cmp	[catmull_flag],1      ; put on stack z coordinate if necessary
1884
	jne	 @f
1885
	push	 [zz3]
1886
      @@:
1887
	mov	 eax,dword[yy3]
1888
	mov	 ebx,0x00ff00ff
1889
	and	 eax,ebx
1890
	push	 eax
1891
	neg	 al
1892
	push	 ax
1893
	cmp	[catmull_flag],1
1894
	jne	 @f
1895
	push	 [zz2]
1896
      @@:
1897
	mov	 eax,dword[yy2]
1898
	and	 eax,ebx
1899
	push	 eax
1900
	neg	 al
1901
	push	 ax
1902
	cmp	[catmull_flag],1
1903
	jne	 @f
1904
	push	 [zz1]
1905
      @@:
1906
	mov	 eax,dword[yy1]
1907
	and	 eax,ebx
1908
	push	 eax
1909
	neg	 al
1910
	push	 ax
1911
    .both_draw:
1912
	mov	eax,dword[xx1]
1913
	ror	eax,16
1914
	mov	ebx,dword[xx2]
1915
	ror	ebx,16
1916
	mov	ecx,dword[xx3]
1917
	ror	ecx,16
1918
	lea	edi,[screen]
1919
	cmp	[catmull_flag],0
1920
	je	@f
1921
  ;	 lea	 esi,[Z_buffer]
6619 leency 1922
	mov	esi,[Zbuffer_ptr]
1245 hidnplayr 1923
	call	gouraud_triangle_z
1924
	jmp	.end_draw
1925
       @@:
1926
	call	gouraud_triangle
1927
	jmp	.end_draw
1928
1929
 
1930
				     ; FLAT DRAWING
1931
	movzx	eax,[point_index1]
1932
	movzx	ebx,[point_index2]
1933
	movzx	ecx,[point_index3]
1934
	shl	eax,2
1935
	shl	ebx,2
1936
	shl	ecx,2
1937
	lea	eax,[eax*3]  ;+point_normals_rotated]
1938
	add	eax,[points_normals_rot_ptr]
1939
	lea	ebx,[ebx*3]  ;+point_normals_rotated]
1940
	add	ebx,[points_normals_rot_ptr]
1941
	lea	ecx,[ecx*3]  ;+point_normals_rotated]
1942
	add	ecx,[points_normals_rot_ptr]
1943
	fld	dword[eax]	; x cooficient of normal vector
1944
	fadd	dword[ebx]
1945
	fadd	dword[ecx]
1946
	fidiv	[i3]
1947
	fimul	[correct_tex]
1948
	fiadd	[correct_tex]
1949
	fistp	dword[esp-4]	; x temp variables
1950
	fld	dword[eax+4]	; y cooficient of normal vector
1951
	fadd	dword[ebx+4]
1952
	fadd	dword[ecx+4]
1953
	fidiv	[i3]
1954
	fimul	[correct_tex]
1955
	fiadd	[correct_tex]
1956
	fistp	dword[esp-8]   ;  y
1957
	mov	edx,dword[esp-8]
1958
	shl	edx,TEX_SHIFT
1959
	add	edx,dword[esp-4]
1960
	lea	eax,[3*edx+color_map]
1961
	mov	edx,dword[eax]
1962
1963
 
1964
1965
 
1966
 
1967
 
6619 leency 1968
     ;	 add	 ax,[zz2]
1969
     ;	 add	 ax,[zz3]
1970
     ;	 cwd
1971
     ;	 idiv	 [i3] ;    = -((a+b+c)/3+130)
1972
     ;	 add	 ax,130
1973
     ;	 neg	 al
1974
     ;	 xor	 edx,edx
1975
     ;	 mov	 ah,al		 ;set color according to z position
1976
     ;	 shl	 eax,8
1977
     ;	 mov	 edx,eax
1978
1245 hidnplayr 1979
 
1980
	ror	eax,16
1981
	mov	ebx,dword[xx2]
1982
	ror	ebx,16
1983
	mov	ecx,dword[xx3]
1984
	ror	ecx,16
1985
       ; mov	 edi,screen
6619 leency 1986
	lea	edi,[screen]
1245 hidnplayr 1987
	cmp	[catmull_flag],0
1988
	je	@f
1989
   ;	 lea	 esi,[Z_buffer]
6619 leency 1990
	mov	esi,[Zbuffer_ptr]
1245 hidnplayr 1991
	push	word[zz3]
1992
	push	word[zz2]
1993
	push	word[zz1]
1994
	call	flat_triangle_z
1995
	jmp	.end_draw
1996
      @@:
1997
	call	draw_triangle
1998
	jmp	.end_draw
1999
      .env_mapping:
2000
       ; fninit
2001
	cmp	[catmull_flag],0
2002
	je	@f
2003
	push	[zz3]
2004
	push	[zz2]
2005
	push	[zz1]
2006
      @@:
2007
	mov	esi,point_index1
2008
	sub	esp,12
2009
	mov	edi,esp
2010
	mov	ecx,3
2011
      @@:
2012
	movzx	eax,word[esi]
2013
	lea	eax,[eax*3]
2014
	shl	eax,2
2015
	add	eax,[points_normals_rot_ptr]	   ;point_normals_rotated
2016
; #
2017
;	 fld	 dword[eax]
6619 leency 2018
;	 fmul	 dword[eax+4]
2019
;	 fld1
2020
;	 fld1
2021
;	 faddp
2022
;	 fmulp
2023
;	 fimul	 [correct_tex]
2024
;	 fiadd	 [correct_tex]
2025
;	 fistp	 word[edi]
2026
;	 mov	 word[edi+2],0
2027
;;	  fistp   word[edi+2]
2028
; # last change
1245 hidnplayr 2029
	; texture x=(rotated point normal -> x * 255)+255
2030
	fld	dword[eax]
2031
	fimul	[correct_tex]
2032
	fiadd	[correct_tex]
2033
	fistp	word[edi]
2034
	; texture y=(rotated point normal -> y * 255)+255
2035
	fld	dword[eax+4]
2036
	fimul	[correct_tex]
2037
	fiadd	[correct_tex]
2038
	fistp	word[edi+2]
2039
; # end of last ch.
2040
	add	edi,4
2041
	add	esi,2
2042
	loop	@b
2043
2044
 
2045
	ror	eax,16
2046
	mov	ebx,dword[xx2]
2047
	ror	ebx,16
2048
	mov	ecx,dword[xx3]
2049
	ror	ecx,16
2050
	mov	edi,screen
2051
	mov	esi,envmap
2052
	cmp	[catmull_flag],0
2053
	je	@f
2054
  ;	 mov	 edx,Z_buffer
6619 leency 2055
	mov	edx,[Zbuffer_ptr]
1245 hidnplayr 2056
	call	tex_triangle_z
2057
	jmp	.end_draw
2058
      @@:
2059
	call	tex_triangle
2060
	jmp	.end_draw
2061
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2062
     .cubic_env_mapping:
2063
       ; fninit
2064
	cmp	[catmull_flag],0
2065
	je	@f
2066
	push	[zz3]
2067
	push	[zz2]
2068
	push	[zz1]
2069
      @@:
2070
	mov	esi,point_index1
2071
	sub	esp,12
2072
	mov	edi,esp
2073
	mov	ecx,3
2074
      @@:
2075
	movzx	eax,word[esi]
2076
	lea	eax,[eax*3]
2077
	shl	eax,2
2078
	add	eax,[points_normals_rot_ptr]  ;point_normals_rotated
2079
; #
2080
	fld	dword[eax]
2081
	fmul	dword[eax+4]
2082
	fld1
2083
	fld1
2084
	faddp
2085
	fmulp
2086
	fimul	[correct_tex]
2087
	fiadd	[correct_tex]
2088
	fistp	word[edi]
2089
	mov	word[edi+2],0
2090
;	 fistp	 word[edi+2]
6619 leency 2091
; # last change
1245 hidnplayr 2092
;	 ; texture x=(rotated point normal -> x * 255)+255
6619 leency 2093
;	 fld	 dword[eax]
2094
;	 fimul	 [correct_tex]
2095
;	 fiadd	 [correct_tex]
2096
;	 fistp	 word[edi]
2097
;	 ; texture y=(rotated point normal -> y * 255)+255
2098
;	 fld	 dword[eax+4]
2099
;	 fimul	 [correct_tex]
2100
;	 fiadd	 [correct_tex]
2101
;	 fistp	 word[edi+2]
2102
; # end of last ch.
1245 hidnplayr 2103
	add	edi,4
2104
	add	esi,2
2105
	loop	@b
2106
2107
 
2108
	ror	eax,16
2109
	mov	ebx,dword[xx2]
2110
	ror	ebx,16
2111
	mov	ecx,dword[xx3]
2112
	ror	ecx,16
2113
	mov	edi,[screen_ptr]
6619 leency 2114
	mov	esi,envmap_cub
1245 hidnplayr 2115
	cmp	[catmull_flag],0
2116
	je	@f
2117
  ;	 mov	 edx,Z_buffer
6619 leency 2118
	mov	edx,[Zbuffer_ptr]
1245 hidnplayr 2119
	call	tex_triangle_z
2120
	jmp	.end_draw
2121
      @@:
2122
	call	tex_triangle
2123
	jmp	.end_draw
2124
2125
 
2126
2127
 
2128
	; fninit
2129
	cmp	[catmull_flag],0
2130
	je	@f
2131
;	 push	 Z_buffer
6619 leency 2132
	push	[Zbuffer_ptr]
1245 hidnplayr 2133
	push	[zz3]
2134
	push	[zz2]
2135
	push	[zz1]
2136
      @@:
2137
	mov	esi,point_index1
2138
	sub	esp,12
2139
	mov	edi,esp
2140
	mov	ecx,3
2141
      @@:
2142
	movzx	eax,word[esi]
2143
	lea	eax,[eax*3]
2144
	shl	eax,2
2145
	add	eax,[points_normals_rot_ptr]  ;point_normals_rotated
2146
	; texture x=(rotated point normal -> x * 255)+255
2147
	fld	dword[eax]
2148
	fimul	[correct_tex]
2149
	fiadd	[correct_tex]
2150
	fistp	word[edi]
2151
	; texture y=(rotated point normal -> y * 255)+255
2152
	fld	dword[eax+4]
2153
	fimul	[correct_tex]
2154
	fiadd	[correct_tex]
2155
	fistp	word[edi+2]
2156
2157
 
2158
	add	esi,2
2159
	loop	@b
2160
2161
 
2162
	shl    esi,2
2163
	add    esi,tex_points
2164
	push   dword[esi]
2165
	movzx  esi,[point_index2]
2166
	shl    esi,2
2167
	add    esi,tex_points
2168
;	lea    esi,[esi*3]
6619 leency 2169
;	lea    esi,[points+2+esi*2]
2170
	push   dword[esi]
1245 hidnplayr 2171
  ;	push   dword[xx2]
6619 leency 2172
	movzx  esi,[point_index1]
1245 hidnplayr 2173
	shl    esi,2
2174
	add    esi,tex_points
2175
;	lea	esi,[esi*3]
6619 leency 2176
;	lea	esi,[points+2+esi*2]
2177
	push   dword[esi]
1245 hidnplayr 2178
   ;	push	 dword[xx1]
6619 leency 2179
1245 hidnplayr 2180
 
2181
	ror	eax,16
2182
	mov	ebx,dword[xx2]
2183
	ror	ebx,16
2184
	mov	ecx,dword[xx3]
2185
	ror	ecx,16
2186
	mov	edi,screen
2187
	mov	esi,envmap
2188
	mov	edx,bumpmap	       ;BUMP_MAPPING
2189
2190
 
2191
	je	@f
2192
	call	bump_triangle_z
2193
	jmp	.end_draw
2194
      @@:
2195
	call	bump_triangle
2196
	jmp	.end_draw
2197
2198
 
2199
2200
 
2201
	cmp	[catmull_flag],0
2202
	je	@f
2203
	push	[zz3]
2204
	push	[zz2]
2205
	push	[zz1]
2206
      @@:
2207
	movzx  esi,[point_index3]      ; tex map coords
2208
	shl    esi,2
2209
	add    esi,tex_points
2210
	push   dword[esi]
2211
	movzx  esi,[point_index2]
2212
	shl    esi,2
2213
	add    esi,tex_points
2214
	push   dword[esi]
2215
	movzx  esi,[point_index1]
2216
	shl    esi,2
2217
	add    esi,tex_points
2218
	push   dword[esi]
2219
2220
 
2221
	ror	eax,16
2222
	mov	ebx,dword[xx2]
2223
	ror	ebx,16
2224
	mov	ecx,dword[xx3]
2225
	ror	ecx,16
2226
	mov	edi,screen
2227
	mov	esi,texmap
2228
	cmp	[catmull_flag],0
2229
	je	@f
2230
   ;	 mov	 edx,Z_buffer
6619 leency 2231
	mov	edx,[Zbuffer_ptr]
1245 hidnplayr 2232
	call	tex_triangle_z
2233
 ;	 call	 tex_plus_grd_trianlgle
6619 leency 2234
	jmp	.end_draw
1245 hidnplayr 2235
      @@:
2236
	call	tex_triangle
2237
	jmp	.end_draw
2238
;      .ray:
2239
;	 grd_triangle according to points index
6619 leency 2240
;	 cmp	 [catmull_flag],0
2241
;	 je	 @f
2242
;	 push	 [zz3]			 ; spot light with attenuation
2243
;     @@:
1245 hidnplayr 2244
;	 movzx	 eax,[point_index3]	 ; env_map - points color list
6619 leency 2245
;	 shl	 eax,1			 ; each color as word, 0x00rr00gg00bb..
2246
;	 lea	 eax,[3*eax+bumpmap]
2247
;	 push	 word[eax]
2248
;	 push	 word[eax+2]
2249
;	 push	 word[eax+4]
2250
;	 cmp	 [catmull_flag],0
2251
;	 je	 @f
2252
;	 push	 [zz2]
2253
;    @@:
1245 hidnplayr 2254
;	 movzx	 eax,[point_index2]	 ; env_map - points color list
6619 leency 2255
;	 shl	 eax,1			 ; each color as word, 0x00rr00gg00bb..
2256
;	 lea	 eax,[eax*3+bumpmap]
2257
;	 push	 word[eax]
2258
;	 push	 word[eax+2]
2259
;	 push	 word[eax+4]
2260
;	 cmp	 [catmull_flag],0
2261
;	 je	 @f
2262
;	 push	 [zz1]
2263
;     @@:
1245 hidnplayr 2264
;	 movzx	 eax,[point_index1]	 ; env_map - points color list
6619 leency 2265
;	 shl	 eax,1			 ; each color as word, 0xrr00gg00bb00..
2266
;	 lea	 eax,[eax*3+bumpmap]
2267
;	 push	 word[eax]
2268
;	 push	 word[eax+2]
2269
;	 push	 word[eax+4]
2270
;	 jmp	 .both_draw
2271
1245 hidnplayr 2272
 
2273
	 push	ebp
2274
	 mov	ebp,esp
2275
	 sub	esp,4
2276
	 push	ebp
2277
2278
 
2279
	 shl	esi,2
2280
	 add	esi,tex_points
2281
	 push	dword[esi]		; texture coords as first
2282
	 movzx	esi,[point_index2]	; group of parameters
2283
	 shl	esi,2
2284
	 add	esi,tex_points
2285
	 push	dword[esi]
2286
	 movzx	esi,[point_index1]
2287
	 shl	esi,2
2288
	 add	esi,tex_points
2289
	 push	dword[esi]
2290
2291
 
2292
	 mov	 ecx,3
2293
2294
 
2295
2296
 
2297
	push	 word[edx*2+xx1-2]    ; zz1 ,2 ,3
2298
2299
 
2300
	shl	eax,2
2301
	lea	eax,[eax*3] ;+point_normals_rotated]
2302
	add	eax,[points_normals_rot_ptr]
2303
	; texture x=(rotated point normal -> x * 255)+255
2304
	fld	dword[eax]	 ; x cooficient of normal vector
2305
	fimul	[correct_tex]
2306
	fiadd	[correct_tex]
2307
	fistp	word[ebp-2]
2308
	; texture y=(rotated point normal -> y * 255)+255
2309
	fld	dword[eax+4]	  ; y cooficient
2310
	fimul	[correct_tex]
2311
	fiadd	[correct_tex]
2312
	fistp	word[ebp-4]
2313
2314
 
2315
	movzx	 ebx,word[ebp-2]
2316
	shl	 eax,TEX_SHIFT
2317
	add	 eax,ebx
2318
	lea	 eax,[eax*3+color_map]
2319
	mov	 eax,dword[eax]
2320
2321
 
2322
	xor	 ah,ah
2323
	push	 ax	    ;r
2324
	rol	 eax,8		      ; eax-0xggbb00rr -> 0xbb00rrgg
2325
	xor	 ah,ah
2326
	push	 ax	    ;g
2327
	shr	 eax,24
2328
	push	 ax	    ;b
2329
2330
 
2331
	dec	 cx
2332
	jnz	 .aagain_grd_draw
2333
2334
 
2335
	ror	eax,16
2336
	mov	ebx,dword[xx2]
2337
	ror	ebx,16
2338
	mov	ecx,dword[xx3]
2339
	ror	ecx,16
2340
	mov	edi,screen
2341
	mov	edx,texmap
2342
	mov	esi,[Zbuffer_ptr]
2343
2344
 
2345
2346
 
2347
	mov	esp,ebp
2348
	pop	ebp
2349
	jmp	.end_draw
2350
2351
 
2352
	push	[Zbuffer_ptr]
2353
2354
 
2355
	push	word[zz2]
2356
	push	word[zz1]
2357
2358
 
2359
	shl    esi,2
2360
	add    esi,tex_points
2361
	push   dword[esi]
2362
	movzx  esi,[point_index2]
2363
	shl    esi,2
2364
	add    esi,tex_points
2365
	push   dword[esi]
2366
	movzx  esi,[point_index1]
2367
	shl    esi,2
2368
	add    esi,tex_points
2369
	push   dword[esi]
2370
2371
 
2372
	sub	esp,12
2373
	mov	edi,esp
2374
	mov	ecx,3
2375
      @@:
2376
	movzx	eax,word[esi]
2377
	lea	eax,[eax*3]
2378
	shl	eax,2
2379
	add	eax,[points_normals_rot_ptr]
2380
	; texture x=(rotated point normal -> x * 255)+255
2381
	fld	dword[eax]
2382
	fimul	[correct_tex]
2383
	fiadd	[correct_tex]
2384
	fistp	word[edi]
2385
	; texture y=(rotated point normal -> y * 255)+255
2386
	fld	dword[eax+4]
2387
	fimul	[correct_tex]
2388
	fiadd	[correct_tex]
2389
	fistp	word[edi+2]
2390
2391
 
2392
	add	esi,2
2393
	loop	@b
2394
2395
 
2396
	ror	eax,16
2397
	mov	ebx,dword[xx2]
2398
	ror	ebx,16
2399
	mov	ecx,dword[xx3]
2400
	ror	ecx,16
2401
	mov	edi,screen
2402
	mov	esi,texmap
2403
	mov	edx,envmap
2404
2405
 
2406
	jmp	.end_draw
2407
2408
 
2409
	movzx  esi,[point_index3]      ; tex map coords
2410
	shl    esi,2
2411
	add    esi,tex_points
2412
	push   dword[esi]
2413
	movzx  esi,[point_index2]
2414
	shl    esi,2
2415
	add    esi,tex_points
2416
	push   dword[esi]
2417
	movzx  esi,[point_index1]
2418
	shl    esi,2
2419
	add    esi,tex_points
2420
	push   dword[esi]
2421
2422
 
2423
2424
 
2425
	xor   edi,edi
2426
2427
 
2428
	push	word[zz2]
2429
	push	word[zz1]
2430
2431
 
2432
	sub	esp,12
2433
	mov	edi,esp
2434
	mov	ecx,3
2435
      @@:
2436
	movzx	eax,word[esi]
2437
	lea	eax,[eax*3]
2438
	shl	eax,2
2439
	add	eax,[points_normals_rot_ptr]
2440
	; texture x=(rotated point normal -> x * 255)+255
2441
	fld	dword[eax]
2442
	fimul	[correct_tex]
2443
	fiadd	[correct_tex]
2444
	fistp	word[edi]
2445
	; texture y=(rotated point normal -> y * 255)+255
2446
	fld	dword[eax+4]
2447
	fimul	[correct_tex]
2448
	fiadd	[correct_tex]
2449
	fistp	word[edi+2]
2450
2451
 
2452
	add	esi,2
2453
	loop	@b
2454
2455
 
6619 leency 2456
;	 push  dword 127 shl 16 + 1
2457
;	 push  dword 127 shl 16 + 127
2458
1245 hidnplayr 2459
 
2460
	shl    esi,2
2461
	add    esi,tex_points
2462
	push   dword[esi]
2463
	movzx  esi,[point_index2]
2464
	shl    esi,2
2465
	add    esi,tex_points
2466
	push   dword[esi]
2467
2468
 
2469
	shl    esi,2
2470
	add    esi,tex_points
2471
	push   dword[esi]
2472
2473
 
6619 leency 2474
;	 push  dword 127 shl 16 + 127
2475
;	 push  dword 1 shl 16 + 1  ; bump coords
2476
1245 hidnplayr 2477
 
2478
	ror	eax,16
2479
	mov	ebx,dword[xx2]
2480
	ror	ebx,16
2481
	mov	ecx,dword[xx3]
2482
	ror	ecx,16
2483
	mov	edi,screen
2484
	mov	esi,envmap
2485
	mov	edx,bumpmap
2486
2487
 
2488
2489
 
2881 leency 2490
2491
 
2492
	mov	esi,point_index3
2493
	mov	ecx,3
2494
      .again_line_param:
2495
	movzx	eax,word[esi]
2496
	shl	eax,2
2497
	lea	eax,[eax*3]
2498
	add	eax,[points_normals_rot_ptr]
2499
	; texture ;x=(rotated point normal -> x * 255)+255
2500
	fld	dword[eax]	 ; x cooficient of normal vector
2501
	fimul	[correct_tex]
2502
	fiadd	[correct_tex]
2503
	fistp	word[esp-2]
2504
	; texture y=(rotated point normal -> y * 255)+255
2505
	fld	dword[eax+4]	  ; y cooficient
2506
	fimul	[correct_tex]
2507
	fiadd	[correct_tex]
2508
	fistp	word[esp-4]
2509
2510
 
2511
	movzx	 ebx,word[esp-2]
2512
	shl	 eax,TEX_SHIFT
2513
	add	 eax,ebx
2514
	lea	 eax,[eax*3+color_map]
2515
	mov	 eax,dword[eax]
2516
	lea	 ebx,[ecx-1]
2517
	shl	 ebx,2
2518
	mov	 [ebx+col1],eax
2519
2520
 
2521
	dec	 ecx
2522
	jnz	 .again_line_param
2523
2524
 
6619 leency 2525
;	 add	 eax,[edges_counter]	 ;   I mean chosing overlapped	edges.
2526
;	 mov	 bl,[eax]		 ;
2527
;	 test	 bl,00000001b		 ;
2528
;	 jz	 @f			 ;
2529
	mov	edi,screen
2881 leency 2530
	mov	esi,[Zbuffer_ptr]
2531
2532
 
2533
	movzx	bx,al
2534
	push	bx		  ; b
2535
	movzx	bx,ah
2536
	push	bx
2537
	rol	eax,16
2538
	xor	ah,ah
2539
	push	ax
2540
	push	[zz1]
2541
	push	[yy1]
2542
	push	[xx1]
2543
2544
 
2545
	movzx	bx,al
2546
	push	bx		  ; b
2547
	movzx	bx,ah
2548
	push	bx
2549
	rol	eax,16
2550
	xor	ah,ah
2551
	push	ax
2552
	push	[zz2]
2553
	push	[yy2]
2554
	push	[xx2]
2555
2556
 
2557
     @@:
2558
;	 mov	 eax,[edges_ptr]       ;  this not works correctly
6619 leency 2559
;	 add	 eax,[edges_counter]
2560
;	 mov	 bl,[eax]
2561
;	 test	 bl,00000010b
2562
;	 jz	 @f
2563
2881 leency 2564
 
2565
	mov	esi,[Zbuffer_ptr]
2566
2567
 
2568
	movzx	bx,al
2569
	push	bx		  ; b
2570
	movzx	bx,ah
2571
	push	bx
2572
	rol	eax,16
2573
	xor	ah,ah
2574
	push	ax
2575
	push	[zz1]
2576
	push	[yy1]
2577
	push	[xx1]
2578
2579
 
2580
	movzx	bx,al
2581
	push	bx		  ; b
2582
	movzx	bx,ah
2583
	push	bx
2584
	rol	eax,16
2585
	xor	ah,ah
2586
	push	ax
2587
	push	[zz3]
2588
	push	[yy3]
2589
	push	[xx3]
2590
2591
 
2592
      @@:
2593
2594
 
6619 leency 2595
;	 add	 eax,[edges_counter]	;
2596
;	 mov	 bl,[eax]		;
2597
;	 test	 bl,00000100b		;
2598
;	 jz	 @f			;
2599
2881 leency 2600
 
2601
	mov	esi,[Zbuffer_ptr]
2602
2603
 
2604
	movzx	bx,al
2605
	push	bx		  ; b
2606
	movzx	bx,ah
2607
	push	bx
2608
	rol	eax,16
2609
	xor	ah,ah
2610
	push	ax
2611
	push	[zz3]
2612
	push	[yy3]
2613
	push	[xx3]
2614
2615
 
2616
	movzx	bx,al
2617
	push	bx		  ; b
2618
	movzx	bx,ah
2619
	push	bx
2620
	rol	eax,16
2621
	xor	ah,ah
2622
	push	ax
2623
	push	[zz2]
2624
	push	[yy2]
2625
	push	[xx2]
2626
2627
 
2628
      @@:
2629
2630
 
1245 hidnplayr 2631
	pop	esi
2632
	add	esi,6
2633
	inc	[edges_counter]
2881 leency 2634
	cmp	dword[esi],-1
1245 hidnplayr 2635
	jne	.again_dts
2636
ret
2637
2638
 
2639
 
2640
	mov	eax,0x70000000
2641
	mov	edi,[Zbuffer_ptr]
2642
	movzx	ecx,word[size_x_var]
6619 leency 2643
	movzx	ebx,word[size_y_var]
2644
	imul	ecx,ebx
2645
      if     Ext>=SSE2
2646
	movd	xmm0,eax
2647
	shufps	xmm0,xmm0,0
2648
	push	ecx
2649
	mov	ecx,edi
2650
	and	edi,0xffffff00
2651
	and	ecx,0x000000ff
2652
	mov	edx,ecx
2653
	rep	stosd
1245 hidnplayr 2654
	pop	ecx
6619 leency 2655
	sub	ecx,edx
2656
      @@:
2657
	movaps	[edi],xmm0
2658
	movaps	[edi+16],xmm0
2659
	movaps	[edi+32],xmm0
2660
	movaps	[edi+48],xmm0
2661
	add	edi,64
2662
	sub	ecx,16
2663
	jnc	@b
2664
      else
2665
	rep	stosd
2666
      end if
2667
ret
1245 hidnplayr 2668
2669
 
6619 leency 2670
			      ; and  allocate memory
3066 leency 2671
	xor	ebx,ebx
1245 hidnplayr 2672
	xor	ebp,ebp
2673
	mov	[points_count_var],bx
3066 leency 2674
	mov	[triangles_count_var],bx
2675
   if USE_LFN = 0
1245 hidnplayr 2676
	mov	esi,SourceFile
2677
   else
2678
	mov	esi,[fptr]
2679
   end if
2680
3066 leency 2681
 
1245 hidnplayr 2682
	je	@f ;Must be legal .3DS file
3066 leency 2683
	xor	eax,eax
2684
	ret
2685
    @@:
2686
	mov	eax,dword[esi+2]
1245 hidnplayr 2687
	cmp	eax,[fsize] ;This must tell the length
3066 leency 2688
	je	@f
2689
	xor	eax,eax
2690
	ret
2691
     @@:
2692
	add	eax,esi
1245 hidnplayr 2693
	mov	[EndFile],eax	 ;
2694
2695
 
2696
      @@:
2697
	cmp	[esi],word 3D3Dh
2698
	je	@f
2699
	add	esi,[esi+2]
2700
	jmp	@b
2701
      @@:
2702
	add	esi,6
2703
      .find4k:
2704
	cmp	[esi],word 4000h
2705
	je	@f
2706
	add	esi,[esi+2]
2707
	cmp	esi,[EndFile]
2708
	jc	.find4k
2709
	jmp	.exit
2710
      @@:
2711
	add	esi,6
2712
      @@:
2713
	cmp	[esi],byte 0
2714
	je	@f
2715
	inc	esi
2716
	jmp	@b
2717
      @@:
2718
	inc	esi
2719
      @@:
2720
	cmp	[esi],word 4100h
2721
	je	@f
2722
	add	esi,[esi+2]
2723
	jmp	@b
2724
      @@:
2725
	add	esi,6
2726
      @@:
2727
	cmp	[esi],word 4110h
2728
	je	@f
2729
	add	esi,[esi+2]
2730
	jmp	@b
2731
      @@:
2732
	movzx	ecx,word[esi+6]
2733
	add	[points_count_var],cx
2734
2735
 
2736
	add	esi,8
2737
     @@:
2738
2739
 
2740
	add	esi,12
2741
     ;	 dec	 ecx
6619 leency 2742
	loop	 @b
3066 leency 2743
      @@:
1245 hidnplayr 2744
3066 leency 2745
 
1245 hidnplayr 2746
	cmp	[esi],word 4120h
2747
	je	@f
2748
	add	esi,[esi+2]
2749
	jmp	@b
2750
      @@:
2751
	movzx	ecx,word[esi+6]
2752
	add	[triangles_count_var],cx
2753
	add	esi,8
2754
3066 leency 2755
 
1245 hidnplayr 2756
	add	esi,8
3066 leency 2757
	dec	ecx
1245 hidnplayr 2758
	jnz	@b
2759
;	 xor	 ecx,ecx
6619 leency 2760
	add	ebp,edx
1245 hidnplayr 2761
	jmp	.find4k
2762
	mov	eax,-1 ;<---mark if OK
2763
      .exit:
2764
ret
2765
2766
 
3066 leency 2767
	fninit
2768
	mov	edi,[triangles_ptr]
2769
	xor	ebx,ebx
1245 hidnplayr 2770
	xor	ebp,ebp
2771
	mov	[points_count_var],0
3066 leency 2772
	mov	[triangles_count_var],0
2773
   if USE_LFN = 0
1245 hidnplayr 2774
	mov	esi,SourceFile
2775
   else
2776
	mov	esi,[fptr]
2777
   end if
2778
	cmp	[esi],word 4D4Dh
2779
	jne	.exit ;Must be legal .3DS file
3066 leency 2780
;	 cmp	 dword[esi+2],EndFile-SourceFile
6619 leency 2781
;	 jne	 .exit ;This must tell the length
2782
	mov	eax,dword[esi+2]
1245 hidnplayr 2783
  ;	 cmp	 eax,[fsize]
6619 leency 2784
  ;	 jne	 .exit
2785
3066 leency 2786
 
1245 hidnplayr 2787
	mov	[EndFile],eax	 ;
2788
2789
 
2790
      @@:
2791
	cmp	[esi],word 3D3Dh
2792
	je	@f
2793
	add	esi,[esi+2]
2794
	jmp	@b
2795
      @@:
2796
	add	esi,6
2797
      .find4k:
2798
	cmp	[esi],word 4000h
2799
	je	@f
2800
	add	esi,[esi+2]
2801
	cmp	esi,[EndFile]
2802
	jc	.find4k
2803
	jmp	.exit
2804
      @@:
2805
	add	esi,6
2806
      @@:
2807
	cmp	[esi],byte 0
2808
	je	@f
2809
	inc	esi
2810
	jmp	@b
2811
      @@:
2812
	inc	esi
2813
      @@:
2814
	cmp	[esi],word 4100h
2815
	je	@f
2816
	add	esi,[esi+2]
2817
	jmp	@b
2818
      @@:
2819
	add	esi,6
2820
      @@:
2821
	cmp	[esi],word 4110h
2822
	je	@f
2823
	add	esi,[esi+2]
2824
	jmp	@b
2825
      @@:
2826
	movzx	ecx,word[esi+6]
2827
	add	[points_count_var],cx
2828
2829
 
2830
	add	esi,8
2831
     @@:
2832
	push	edi
3066 leency 2833
	mov	edi,[points_ptr]
2834
	push	dword[esi+4]
2835
	pop	dword[edi+ebx*2+0]
2836
	push	dword[esi+8]
2837
	pop	dword[edi+ebx*2+4]
2838
	push	dword[esi+0]
2839
	pop	dword[edi+ebx*2+8]
2840
	pop	edi
2841
;	 fld	 dword[esi+4]
6619 leency 2842
;	 fstp	 dword[real_points+ebx*2+0]  ; x
2843
;	 fld	 dword[esi+8]
2844
;	 fstp	dword[real_points+ebx*2+4]  ; y
2845
;	 fld	 dword[esi+0]
2846
;	 fstp	dword[real_points+ebx*2+8]  ; z
2847
1245 hidnplayr 2848
 
2849
	add	esi,12
2850
	dec	ecx
3066 leency 2851
	jnz	@b
2852
      @@:
1245 hidnplayr 2853
  ;	 mov	 dword[points+ebx],-1
6619 leency 2854
	push	edi
3066 leency 2855
	mov	edi,[points_ptr]
2856
	mov	dword[edi+ebx*2],-1	   ; end mark (not always in use)
2857
	pop	edi
2858
      @@:
1245 hidnplayr 2859
	cmp	[esi],word 4120h
2860
	je	@f
2861
	add	esi,[esi+2]
2862
	jmp	@b
2863
      @@:
2864
	movzx	ecx,word[esi+6]
2865
	add	[triangles_count_var],cx
2866
	add	esi,8
2867
	;mov	 edi,triangles
6619 leency 2868
      @@:
1245 hidnplayr 2869
	movsd
3066 leency 2870
	movsw
2871
	add	word[edi-6],bp
2872
	add	word[edi-4],bp
2873
	add	word[edi-2],bp
2874
	add	esi,2
2875
	dec	ecx
1245 hidnplayr 2876
	jnz	@b
2877
	add	ebp,edx
2878
	jmp	.find4k
2879
	mov	eax,-1 ;<---mark if OK
2880
      .exit:
2881
	mov	dword[edi],-1
3066 leency 2882
ret
1245 hidnplayr 2883
2884
 
2885
alloc_mem_for_tp:
2886
	mov	eax, 68
2887
	cmp	[re_alloc_flag],1
1776 yogev_ezra 2888
	jz	@f
2889
	mov	ebx, 12
1245 hidnplayr 2890
	jmp	.alloc
1776 yogev_ezra 2891
    @@:
2892
	mov	ebx,20
2893
    .alloc:
2894
2881 leency 2895
 
1245 hidnplayr 2896
	inc	ecx
2897
	lea	ecx, [ecx*3]
2898
	add	ecx, ecx
2899
	mov	edx,[triangles_ptr]
1776 yogev_ezra 2900
	int	0x40		       ;  -> allocate memory to triangles
1245 hidnplayr 2901
	mov	[triangles_ptr], eax   ;  -> eax = pointer to allocated mem
2902
2903
 
6619 leency 2904
;	 movzx	 ecx, [triangles_count_var]
2905
;	 inc	 ecx
2906
;	 mov	 edx,[edges_ptr]
2907
;	 int	 0x40			;  -> allocate memory to edges
2908
;	 mov	 [edges_ptr], eax   ;  -> eax = pointer to allocated mem
2909
2881 leency 2910
 
6619 leency 2911
;	 movzx	 ecx,[triangles_count_var]    ; importand if object generated
2912
;	 shr	 ecx,2
2913
;	 inc	 ecx
2914
;	 mov	 edi,[edges_ptr]
2915
;	 cld
2916
;	 rep	 stosd
2917
2881 leency 2918
 
2984 leency 2919
 
6619 leency 2920
;	 mov	 ebx, 12
2921
;	 movzx	 ecx, [triangles_count_var]
2922
;	 shl	 ecx, 4
2923
;	 int	 0x40
2924
;	 mov	 [triangles_w_z_ptr], eax   ; for trainagles_with_z list
2925
					    ; ststic  memory
1245 hidnplayr 2926
2927
 
2928
	movzx	ecx, [triangles_count_var]
2929
	lea	ecx, [3+ecx*3]
2930
	shl	ecx, 2
2931
	mov	edx,[triangles_normals_ptr]
1776 yogev_ezra 2932
	int	0x40			       ;  -> allocate memory for triangles normals
1245 hidnplayr 2933
	mov	[triangles_normals_ptr], eax   ;  -> eax = pointer to allocated mem
2934
2935
 
2936
	movzx	ecx, [points_count_var]
2937
	lea	ecx,[3+ecx*3]
2938
	shl	ecx, 2
2939
	mov	edx,[points_normals_ptr]
1776 yogev_ezra 2940
	int	0x40
1245 hidnplayr 2941
	mov	[points_normals_ptr], eax
2942
2943
 
2944
    ;	 mov	 ebx, 12
6619 leency 2945
	movzx	ecx, [points_count_var]
1245 hidnplayr 2946
	lea	ecx,[3+ecx*3]
2947
	shl	ecx, 2
2948
	mov	edx,[points_normals_rot_ptr]
1776 yogev_ezra 2949
	int	0x40
1245 hidnplayr 2950
	mov	[points_normals_rot_ptr], eax
2951
2952
 
2953
	mov	edx,[points_ptr]
1776 yogev_ezra 2954
	int	0x40
1245 hidnplayr 2955
	mov	[points_ptr], eax
2956
2957
 
2958
	mov	edx,[points_rotated_ptr]
1776 yogev_ezra 2959
	int	0x40
1245 hidnplayr 2960
	mov	[points_rotated_ptr], eax
2961
2962
 
2963
	movzx	ecx, [points_count_var]
2964
	inc	ecx
2965
	shl	ecx, 3
2966
	mov	edx,[points_translated_ptr]
1776 yogev_ezra 2967
	int	0x40
1245 hidnplayr 2968
	mov	[points_translated_ptr], eax
2969
ret
2970
end if
2971
2972
 
2973
 
2974
if USE_LFN
2975
;-
2976
    mov     eax, 70
2977
    mov     ebx, file_info
2978
    mov     dword[ebx], 5	   ;  -> subfunction number
2979
    int     0x40		   ;  -> read file size
2980
    mov     ebx, [fptr]
2981
    mov     ebx, dword[ebx+32]
2982
    inc     ebx
2983
    mov     [fsize], ebx
2984
2985
 
2986
    mov     ebx, 11
2987
    int     0x40		   ;  -> create heap
2988
2989
 
2990
    mov     ebx, 12
2991
    mov     ecx, [fsize]
2992
    int     0x40		   ;  -> allocate memory for file
2993
    mov     [fptr], eax 	   ;  -> eax = pointer to allocated mem
2994
2995
 
2996
    mov     ebx, file_info
2997
    mov     dword[ebx],0
2998
    int     0x40		   ; -> read file
2999
3000
 
3001
3002
 
3003
    jnz     @f
3004
    xor     eax,eax	;;;;---
3005
  @@:
3006
else
3007
    mov      eax,58
3008
    mov      ebx,file_info
3009
    int      0x40
3010
3011
 
3012
    shr      eax,9
3013
    inc      eax
3014
    mov      [fsize],eax
3015
;    mov      ecx,ebx
3016
;    add      ecx,MEM_END
3017
;    mov      ebx,1
3018
;    mov      eax,64	 ; allocate mem  - resize app mem
6619 leency 3019
			; for points and  triangles
1245 hidnplayr 3020
    int      0x40
3021
3022
 
3023
    mov      ebx,file_info
3024
    int      0x40
3025
end if
3026
  ;  eax = 0   -> ok file loaded
3027
ret
3028
read_param:
3029
    mov        esi,I_Param
3030
    cmp        dword[esi],0
3031
    je	       .end
3032
    cmp        byte[esi],'/'
3033
    je	       .copy
3034
    mov        edi,esi
3035
    mov        ecx,25	; 25 - would be enought
3036
    repe       scasb
3037
    jne        .end
3038
    dec        edi
3039
    mov        esi,edi
3040
 .copy:
3041
    mov 	edi,file_name
3042
    mov 	ecx,50
3043
    rep 	movsd
3044
 .end:
3045
ret
3046
buttons:				      ; draw some buttons (all but navigation and close )
3047
	mov	edi,menu
3048
      .again:
3049
	mov	eax,8		  ; function 8 : define and draw button
6619 leency 3050
	mov	bx,[size_x_var]
3051
	shl	ebx,16
3052
	add	ebx,(10)*65536+62      ; [x start] *65536 + [x size]
3053
	movzx	ecx,byte[edi]		      ; button id = position+2
1245 hidnplayr 3054
	sub	cl,2
3055
	lea	ecx,[ecx*5]
3056
	lea	ecx,[ecx*3]
3057
	add	ecx,25
3058
	shl	ecx,16
3059
	add	ecx,12
3060
	movzx	edx,byte[edi]			; button id
3061
	mov	esi,0x6688dd			; button color RRGGBB
3062
	int	0x40
3063
	 ; BUTTON  LABEL
3064
	mov	eax,4				; function 4 : write text to window
3065
	movzx	ebx,byte[edi]
3066
	sub	bl,2				; button id, according to position
3067
	lea	ebx,[ebx*3]
3068
	lea	ebx,[ebx*5]
3069
	mov	cx,[size_x_var]
6619 leency 3070
	shl	ecx,16
3071
	add	ebx,ecx
3072
	add	ebx,(12)*65536+28	 ; [x start] *65536 + [y start]
3073
	mov	ecx,0x00ddeeff			; font 1 & color ( 0xF0RRGGBB )
5763 leency 3074
	lea	edx,[edi+1]			; pointer to text beginning
1245 hidnplayr 3075
	mov	esi,10				; text length
3076
	int	0x40
3077
	cmp	byte[edi+11],255		; if max_flag=255
3078
	je	@f				; skip
3079
	; flag description
3080
;	mov	eax,4				; function 4 : write text to window
6619 leency 3081
;	movzx	ebx,byte[edi]
3082
;	sub	bl,2
3083
;	lea	ebx,[ebx*3]
3084
;	lea	ebx,[ebx*5]
3085
;	add	ebx,(SIZE_X+12+70)*65536+28	; [x start] *65536 + [y start]
3086
	add	ebx,70*65536
1245 hidnplayr 3087
;	mov	ecx,0x00ddeeff			; font 1 & color ( 0xF0RRGGBB )
6619 leency 3088
	movzx	edx,byte[edi+12]		; current flag
1245 hidnplayr 3089
	shl	edx,2				; * 4 = text length
3090
	add	edx,dword[edi+13]		; pointer to text beginning
3091
	mov	esi,4				; text length
3092
	int	0x40
3093
3094
 
3095
	add	edi,17
3096
	cmp	byte[edi],-1
3097
	jnz	.again
3098
ret
3099
;   *********************************************
3100
;   *******  WINDOW DEFINITIONS AND DRAW ********
3101
;   *********************************************
3102
    draw_window:
3103
	mov	eax,12		; function 12:tell os about windowdraw
3104
	mov	ebx,1		; 1, start of draw
3105
	int	0x40
3106
3107
 
3108
	mov	eax,0		; function 0 : define and draw window
3109
	mov	ebx,50*65536;+SIZE_X;+80+30 ; [x start] *65536 + [x size]
6619 leency 3110
	mov	ecx,50*65536;+SIZE_Y;+30    ; [y start] *65536 + [y size]
3111
	mov	bx,[size_x_var]
3112
	add	bx,115
2984 leency 3113
	mov	cx,[size_y_var]
6619 leency 3114
	add	cx,30
1245 hidnplayr 3115
	mov	edx,0x14000000	; color of work area RRGGBB,8->color gl
1776 yogev_ezra 3116
	mov	edi,labelt	; WINDOW LABEL
2024 leency 3117
	int	0x40
1245 hidnplayr 3118
3119
 
3120
3121
 
3122
3123
 
6619 leency 3124
	mov	eax,4		; function 4 : write text to window
1245 hidnplayr 3125
	movzx	ebx,word[size_x_var]
6619 leency 3126
	shl	ebx,16
3127
	add	ebx,(12)*65536+(168+15*(13+.Y_ADD))   ; [x start] *65536 + [y start]
3128
	mov	ecx,0x00ddeeff	; font 1 & color ( 0xF0RRGGBB )
5763 leency 3129
	mov	edx,labelvector      ; pointer to text beginning
1245 hidnplayr 3130
	mov	esi,labelvectorend-labelvector	   ; text length
3131
    ;	 cmp	 [move_flag],2
6619 leency 3132
    ;	 jne	 @f
3133
    ;	 add	 edx,navigation_size
3134
    ;  @@:
1245 hidnplayr 3135
	int	0x40
3136
	 ; VECTOR Y- BUTTON
3137
	mov	eax,8		; function 8 : define and draw button
3138
	movzx	ebx,word[size_x_var]
6619 leency 3139
	shl	ebx,16
3140
	add	ebx,30*65536+20     ; [x start] *65536 + [x size]
3141
	mov	ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
1245 hidnplayr 3142
	mov	edx,30		 ; button id
3143
	mov	esi,0x6688dd	; button color RRGGBB
3144
	int	0x40
3145
	;VECTOR Y- LABEL
3146
	mov	eax,4		; function 4 : write text to window
3147
	movzx	ebx,word[size_x_var]
6619 leency 3148
	shl	ebx,16
3149
	add	ebx,(32)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
3150
	mov	ecx,0x00ddeeff	; font 1 & color ( 0xF0RRGGBB )
5763 leency 3151
	mov	edx,labelyminus      ; pointer to text beginning
1245 hidnplayr 3152
	mov	esi,labelyminusend-labelyminus	   ; text length
3153
	cmp	[move_flag],2
3154
   ;	 jne	 @f
6619 leency 3155
   ;	 add	 edx,navigation_size
3156
   ;   @@:
1245 hidnplayr 3157
	int	0x40
3158
	; VECTOR Z+ BUTTON
3159
	mov	eax,8		; function 8 : define and draw button
3160
	movzx	ebx,word[size_x_var]
6619 leency 3161
	shl	ebx,16
3162
	add	ebx,(51)*65536+21     ; [x start] *65536 + [x size]
3163
	mov	ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
1245 hidnplayr 3164
	mov	edx,31		 ; button id
3165
	mov	esi,0x6688dd	; button color RRGGBB
3166
	int	0x40
3167
	;VECTOR Z+ LABEL
3168
	mov	eax,4		; function 4 : write text to window
3169
	movzx	ebx,word[size_x_var]
6619 leency 3170
	shl	ebx,16
3171
	add	ebx,(53)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
3172
	mov	ecx,0x00ddeeff	; font 1 & color ( 0xF0RRGGBB )
5763 leency 3173
	mov	edx,labelzplus	    ; pointer to text beginning
1245 hidnplayr 3174
	mov	esi,labelzplusend-labelzplus	 ; text length
3175
   ;	 cmp	 [move_flag],2
6619 leency 3176
   ;	 jne	 @f
3177
   ;	 add	 edx,navigation_size
3178
   ;   @@:
1245 hidnplayr 3179
3180
 
3181
	; VECTOR x- BUTTON
3182
	mov	eax,8		; function 8 : define and draw button
3183
	movzx	ebx,word[size_x_var]
6619 leency 3184
	shl	ebx,16
3185
	add	ebx,(10)*65536+21     ; [x start] *65536 + [x size]
3186
	mov	ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
1245 hidnplayr 3187
	mov	edx,32		 ; button id
3188
	mov	esi,0x6688dd	; button color RRGGBB
3189
	int	0x40
3190
	;VECTOR x- LABEL
3191
	mov	eax,4		; function 4 : write text to window
3192
	movzx	ebx,word[size_x_var]
6619 leency 3193
	shl	ebx,16
3194
	add	ebx,(12)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
3195
	mov	ecx,0x00ddeeff	; font 1 & color ( 0xF0RRGGBB )
5763 leency 3196
	mov	edx,labelxminus      ; pointer to text beginning
1245 hidnplayr 3197
	mov	esi,labelxminusend-labelxminus	   ; text length
3198
   ;	 cmp	 [move_flag],2
6619 leency 3199
   ;	 jne	 @f
3200
   ;	 add	 edx,navigation_size
3201
   ;   @@:
1245 hidnplayr 3202
	int	0x40
3203
	; VECTOR x+ BUTTON
3204
	mov	eax,8		; function 8 : define and draw button
3205
	movzx	ebx,word[size_x_var]
6619 leency 3206
	shl	ebx,16
3207
	add	ebx,(51)*65536+21     ; [x start] *65536 + [x size]
3208
	mov	ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
1245 hidnplayr 3209
	mov	edx,33		 ; button id
3210
	mov	esi,0x6688dd	; button color RRGGBB
3211
	int	0x40
3212
	;VECTOR x+ LABEL
3213
	mov	eax,4		; function 4 : write text to window
3214
	movzx	ebx,word[size_x_var]
6619 leency 3215
	shl	ebx,16
3216
	add	ebx,(53)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
3217
	mov	ecx,0x00ddeeff	; font 1 & color ( 0xF0RRGGBB )
5763 leency 3218
	mov	edx,labelxplus	    ; pointer to text beginning
1245 hidnplayr 3219
	mov	esi,labelxplusend-labelxplus	 ; text length
3220
   ;	 cmp	 [move_flag],2
6619 leency 3221
   ;	 jne	 @f
3222
   ;	 add	 edx,navigation_size
3223
   ;   @@:
1245 hidnplayr 3224
	int	0x40
3225
	; VECTOR z- BUTTON
3226
	mov	eax,8		; function 8 : define and draw button
3227
	movzx	ebx,word[size_x_var]
6619 leency 3228
	shl	ebx,16
3229
	add	ebx,(10)*65536+62-41	 ; [x start] *65536 + [x size]
3230
	mov	ecx,(25+140+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
1245 hidnplayr 3231
	mov	edx,34		 ; button id
3232
	mov	esi,0x6688dd	; button color RRGGBB
3233
	int	0x40
3234
	;VECTOR z- LABEL
3235
	mov	eax,4		; function 4 : write text to window
3236
	movzx	ebx,word[size_x_var]
6619 leency 3237
	shl	ebx,16
3238
	add	ebx,(12)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
3239
	mov	ecx,0x00ddeeff	; font 1 & color ( 0xF0RRGGBB )
5763 leency 3240
	mov	edx,labelzminus      ; pointer to text beginning
1245 hidnplayr 3241
	mov	esi,labelzminusend-labelzminus	   ; text length
3242
   ;	 cmp	 [move_flag],2
6619 leency 3243
   ;	 jne	 @f
3244
   ;	 add	 edx,navigation_size
3245
   ;   @@:
1245 hidnplayr 3246
	int	0x40
3247
       ;VECTOR Y+ BUTTON
3248
	mov	eax,8		; function 8 : define and draw button
3249
	movzx	ebx,word[size_x_var]
6619 leency 3250
	shl	ebx,16
3251
	add	ebx,(10+20)*65536+20	 ; [x start] *65536 + [x size]
3252
	mov	ecx,(165+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
1245 hidnplayr 3253
	mov	edx,35		 ; button id
3254
	mov	esi,0x6688dd	; button color RRGGBB
3255
	int	0x40
3256
	;VECTOR Y+ LABEL
3257
	mov	eax,4		; function 4 : write text to window
3258
	movzx	ebx,word[size_x_var]
6619 leency 3259
	shl	ebx,16
3260
	add	ebx,(32)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
3261
	mov	ecx,0x00ddeeff	; font 1 & color ( 0xF0RRGGBB )
5763 leency 3262
	mov	edx,labelyplus	    ; pointer to text beginning
1245 hidnplayr 3263
	mov	esi,labelyplusend-labelyplus	 ; text length
3264
   ;	 cmp	 [move_flag],2
6619 leency 3265
   ;	 jne	 @f
3266
   ;	 add	 edx,navigation_size
3267
   ;   @@:
1245 hidnplayr 3268
	int	0x40
3269
3270
 
3271
	mov	ebx,2		; 2, end of draw
3272
	int	0x40
3273
	ret
3274
3275
 
3276
 
6619 leency 3277
1245 hidnplayr 3278
 
1979 yogev_ezra 3279
   align 16
6619 leency 3280
MEM_END:
1245 hidnplayr 3281