Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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