Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1781 yogev_ezra 1
;
2
; application : Deus Caritas Est - app shows three models shading
3
; compiler    : FASM  1.65.13
4
; system      : KolibriOS/MenuetOS
5
; author      : macgub
6
; email       : macgub3@wp.pl
7
; web         : www.menuet.xt.pl
8
; Fell free to use this intro in your own distribution of KolibriOS/MenuetOS.
9
; Special greetings to all MenuetOS maniax in the world.
10
; I hope because my intros Christian Belive will be near to each of You.
11
 
12
 
13
; Some adjustments made by Madis Kalme
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
SIZE_X equ 250
20
SIZE_Y equ 250
21
TIMEOUT equ 4
22
ROUND equ 10
23
TEX_X equ 512	  ; texture width
24
TEX_Y equ 512	  ;         height
25
TEX_SHIFT equ 9  ; texture widith shifting
26
TEX equ  SHIFTING ;  TEX={SHIFTING | FLUENTLY}
27
FLUENTLY = 0
28
SHIFTING = 1
29
;CATMULL_SHIFT equ 8
30
NON   =   0
31
MMX   =   1
32
 
33
Ext   =   MMX			;Ext={ NON | MMX}
34
 
35
use32
36
	org    0x0
37
	db     'MENUET01'	; 8 byte id
38
	dd     0x01		; header version
39
	dd     START		; start of code
40
	dd     I_END		; size of image
41
	dd     I_END		; memory for app
42
	dd     I_END		; esp
43
	dd     0x0 , 0x0	; I_Param , I_Icon
44
 
45
START:	  ; start of execution
46
	cld
47
 ;       call alloc_buffer_mem
48
	call read_from_file
49
	call init_triangles_normals
50
	call init_point_normals
51
	call init_envmap
52
	call draw_window
53
 
54
 
55
still:
56
	mov	eax,23		; wait here for event with timeout
57
	mov	ebx,TIMEOUT
58
	cmp	[speed_flag],1
59
	jne	.skip
60
	mov	eax,11
61
    .skip:
62
	int	0x40
63
 
64
	cmp	eax,1		; redraw request ?
65
	je	red
66
	cmp	eax,2		; key in buffer ?
67
	je	key
68
	cmp	eax,3		; button in buffer ?
69
	je	button
70
 
71
	jmp	noclose
72
 
73
    red:			; redraw
74
	call	draw_window
75
	jmp	noclose
76
 
77
    key:			; key
78
	mov	eax,2		; just read it and ignore
79
	int	0x40
80
	jmp	noclose
81
 
82
    button:			; button
83
	mov	eax,17		; get id
84
	int	0x40
85
 
86
	cmp	ah,1		; button id=1 ?
87
	jne	.ch_another
88
 
89
	mov	eax,-1		; close this program
90
	int	0x40
91
      .ch_another:
92
	cmp	ah,2
93
	jne	.ch_another1
94
	inc	[r_flag]
95
	cmp	[r_flag],3
96
	jne	noclose
97
	mov	[r_flag],0
98
      .ch_another1:
99
	cmp	ah,3
100
	jne	.ch_another2
101
	inc	[dr_flag]
102
	cmp	[dr_flag],3
103
	jne	noclose
104
	mov	[dr_flag],0
105
      .ch_another2:
106
	cmp	ah,4			 ; toggle speed
107
	jne	@f
108
	inc	[speed_flag]
109
	cmp	[speed_flag],2
110
	jne	noclose
111
	mov	[speed_flag],0
112
      @@:
113
	cmp	ah,5
114
	jne	@f			 ;scale-
115
	mov	[scale],0.7
116
	fninit
117
	fld	[sscale]
118
	fmul	[scale]
119
	fstp	[sscale]
120
	call	read_from_file
121
	mov	ax,[vect_x]  ;-- last change
122
	mov	bx,[vect_y]
123
	mov	cx,[vect_z]
124
	call	add_vector
125
;        call    do_scale
126
      @@:
127
	cmp	ah,6
128
	jne	@f			; scale+
129
	mov	[scale],1.3
130
	fninit
131
	fld	[sscale]
132
	fmul	[scale]
133
	fstp	[sscale]
134
	call	read_from_file
135
	mov	ax,[vect_x]
136
	mov	bx,[vect_y]
137
	mov	cx,[vect_z]
138
	call	add_vector
139
	call	init_triangles_normals
140
	call	init_point_normals
141
      @@:
142
	cmp	ah,7
143
	jne	@f
144
	xor	ax,ax		 ;add vector to object and rotary point
145
	mov	bx,-10
146
	xor	cx,cx
147
	call	add_vector
148
	sub	[vect_y],10
149
	sub	[yo],10
150
      @@:
151
	cmp	ah,8
152
	jne	@f
153
	xor	ax,ax
154
	xor	bx,bx
155
	mov	cx,10
156
	call	add_vector
157
	add	[vect_z],10
158
	add	[zo],10
159
      @@:
160
	cmp	ah,9
161
	jne	@f
162
	mov	ax,-10
163
	xor	bx,bx
164
	xor	cx,cx
165
	call	add_vector
166
	sub	[vect_x],10
167
	sub	[xo],10
168
      @@:
169
	cmp	ah,10
170
	jne	@f
171
	mov	ax,10
172
	xor	bx,bx
173
	xor	cx,cx
174
	call	add_vector
175
	add	[vect_x],10
176
	add	[xo],10
177
      @@:
178
	cmp	ah,11
179
	jne	@f
180
	xor	ax,ax
181
	xor	bx,bx
182
	mov	cx,-10
183
	call	add_vector
184
	sub	[vect_z],10
185
	sub	[zo],10
186
      @@:
187
	cmp	ah,12
188
	jne	@f
189
	xor	ax,ax
190
	mov	bx,10
191
	xor	cx,cx
192
	call	add_vector
193
	add	[vect_y],10
194
	add	[yo],10
195
      @@:
196
	cmp	ah,13			 ; change main color -
197
	jne	@f			 ; - lead color setting
198
	cmp	[max_color_r],245
199
	jge	@f
200
	add	[max_color_r],10
201
	call	init_envmap
202
      @@:
203
	cmp	ah,14
204
	jne	@f
205
	cmp	[max_color_g],245
206
	jge	@f
207
	add	[max_color_g],10
208
	call	init_envmap
209
      @@:
210
	cmp	ah,15
211
	jne	@f
212
	cmp	[max_color_b],245
213
	jge	@f
214
	add	[max_color_b],10
215
	call	init_envmap
216
      @@:
217
	cmp	ah,16			 ; change main color
218
	jne	@f
219
	cmp	[max_color_r],10
220
	jle	@f
221
	sub	[max_color_r],10
222
	call	init_envmap
223
      @@:
224
	cmp	ah,17
225
	jne	@f
226
	cmp	[max_color_g],10
227
	jle	@f
228
	sub	[max_color_g],10
229
	call	init_envmap
230
      @@:
231
	cmp	ah,18
232
	jne	@f
233
	cmp	[max_color_b],10
234
	jle	@f
235
	sub	[max_color_b],10
236
	call	init_envmap
237
      @@:
238
	cmp	ah,19
239
	jne	@f
240
	inc	[catmull_flag]
241
	cmp	[catmull_flag],2
242
	jne	@f
243
	mov	[catmull_flag],0
244
      @@:
245
    noclose:
246
 
247
	call	calculate_angle ; calculates sinus and cosinus
248
	call	copy_point_normals
249
   ; copy normals and rotate the copy using sin/cosbeta - best way
250
	call	rotate_point_normals
251
	call	calculate_colors
252
	call	copy_points
253
	call	rotate_points
254
	call	translate_perspective_points; translate from 3d to 2d
255
	call	clrscr		; clear the screen
256
	cmp	[dr_flag],2
257
	je	@f
258
	cmp	[catmull_flag],1  ;if env_mapping sort faces
259
	je	@f
260
      @@:
261
	call	sort_triangles
262
      @@:
263
	call	fill_Z_buffer
264
 
265
    RDTSC
266
    push eax
267
	call	draw_triangles	; draw all triangles from the list
268
 
269
    RDTSC
270
    sub eax,[esp]
271
    sub eax,41
272
    ;    lea     esi,[debug_points]
273
    ;    lea     edi,[debug_points+6]
274
    ;    lea     ebx,[debug_vector1]
275
    ;    call    make_vector
276
    ;    fninit
277
    ;    fld     [sinbeta_one]
278
    ;    fimul   [debug_dwd]
279
    ;    fistp   [debug_dd]
280
    ;    movzx    eax,[debug_dd]
281
 
282
 
283
    mov     ecx,10
284
  .dc:
285
    xor     edx,edx
286
    mov     edi,10
287
    div     edi
288
    add     dl,30h
289
    mov     [STRdata+ecx-1],dl
290
    loop    .dc
291
    pop eax
292
macro show
293
{
294
	mov	eax,7		; put image
295
	mov	ebx,screen
296
	mov	ecx,SIZE_X shl 16 + SIZE_Y
297
	mov	edx,5 shl 16 + 20
298
	int	0x40
299
}
300
    show
301
    mov  eax,4			   ; function 4 : write text to window
302
    mov  ebx,5*65536+23 	   ; [x start] *65536 + [y start]
303
    mov  ecx,-1
304
    mov  edx,STRdata		   ; pointer to text beginning
305
    mov  esi,10 		   ; text length
306
    int  40h
307
 
308
 
309
 
310
	jmp	still
311
 
312
;--------------------------------------------------------------------------------
313
;-------------------------PROCEDURES---------------------------------------------
314
;--------------------------------------------------------------------------------
315
include "../../3DS/TEX3.INC"
316
include "../../3DS/FLAT_CAT.INC"
317
include "../../3DS/GRD_CAT.INC"
318
include "../../3DS/3DMATH.INC"
319
include "../../3DS/GRD3.INC"
320
include "../../3DS/FLAT3.INC"
321
 
1784 yogev_ezra 322
fill_Z_buffer:
323
	mov	eax,0x70000000
324
      ;  mov     edi,Z_buffer
325
	mov	edi,[Zbuffer_ptr]
326
	mov	ecx,SIZE_X*SIZE_Y
327
	rep	stosd
328
ret
1781 yogev_ezra 329
 
1784 yogev_ezra 330
 
1781 yogev_ezra 331
;alloc_buffer_mem:
332
;        mov     eax,68
333
;        mov     ebx,5
334
;        mov     ecx,SIZE_X*SIZE_Y*3
335
;        int     0x40
336
;        mov     [screen],eax
337
;ret
338
init_envmap:
339
 
340
.temp equ word [ebp-2]
341
	 push	  ebp
342
	 mov	  ebp,esp
343
	 sub	  esp,2
344
	 mov	  edi,envmap
345
	 fninit
346
 
347
	 mov	  dx,-256
348
    .ie_ver:
349
	 mov	  cx,-256
350
    .ie_hor:
351
	 mov	  .temp,cx
352
	 fild	  .temp
353
	 fmul	  st,st0
354
	 mov	  .temp,dx
355
	 fild	  .temp
356
	 fmul	  st,st0
357
	 faddp
358
	 fsqrt
359
	 mov	  .temp,254
360
	 fisubr   .temp
361
	 fmul	  [env_const]
362
	 fistp	  .temp
363
	 mov	  ax,.temp
364
 
365
	 or	 ax,ax
366
	 jge	 .ie_ok1
367
	 xor	 ax,ax
368
	 jmp	 .ie_ok2
369
  .ie_ok1:
370
	 cmp	 ax,254
371
	 jle	 .ie_ok2
372
	 mov	 ax,254
373
  .ie_ok2:
374
	 push	 dx
375
	 mov	 bx,ax
376
	 mul	 [max_color_b]
377
	 shr	 ax,8
378
	 stosb
379
	 mov	 ax,bx
380
	 mul	 [max_color_g]
381
	 shr	 ax,8
382
	 stosb
383
	 mov	 ax,bx
384
	 mul	 [max_color_r]
385
	 shr	 ax,8
386
	 stosb
387
	 pop	 dx
388
 
389
	 inc	 cx
390
	 cmp	 cx,256
391
	 jne	 .ie_hor
392
 
393
	 inc	 dx
394
	 cmp	 dx,256
395
	 jne	 .ie_ver
396
 
397
	 mov	 esp,ebp
398
	 pop	 ebp
399
macro debug
400
{
401
	 mov	 edi,envmap
402
	 mov	 ecx,512*512*3/4
403
	 mov	 eax,0xffffffff
404
	 rep	 stosd
405
}
406
ret
407
calculate_colors:
408
	fninit
409
	xor	ebx,ebx
410
	movzx	ecx,[points_count_var]
411
	lea	ecx,[ecx*3]
412
	add	ecx,ecx
413
      .cc_again:
414
	mov	esi,light_vector
415
	lea	edi,[point_normals_rotated+ebx*2]
416
	call	dot_product
417
	fcom	[dot_min]
418
	fstsw	ax
419
	sahf
420
	ja	.cc_ok1
421
	ffree	st
422
	mov	dword[points_color+ebx],0
423
	mov	word[points_color+ebx+4],0
424
	add	ebx,6
425
	cmp	ebx,ecx
426
	jne	.cc_again
427
	jmp	.cc_done
428
      .cc_ok1:
429
	fcom	[dot_max]
430
	fstsw	ax
431
	sahf
432
	jb	.cc_ok2
433
	ffree	st
434
	mov	dword[points_color+ebx],0  ; clear r,g,b
435
	mov	word[points_color+ebx+4],0
436
	add	ebx,6
437
	cmp	ebx,ecx
438
	jne	.cc_again
439
	jmp	.cc_done
440
      .cc_ok2:
441
	fld	st
442
	fld	st
443
	fimul	[max_color_r]
444
	fistp	word[points_color+ebx]	      ;each color as word
445
	fimul	[max_color_g]
446
	fistp	word[points_color+ebx+2]
447
	fimul	[max_color_b]
448
	fistp	word[points_color+ebx+4]
449
	add	ebx,6
450
	cmp	ebx,ecx
451
	jne	.cc_again
452
     .cc_done:
453
ret
454
copy_point_normals:
455
	movzx	ecx,[points_count_var]
456
	shl	ecx,2
457
	inc	ecx
458
	mov	esi,point_normals
459
	mov	edi,point_normals_rotated
460
	rep	movsd
461
ret
462
rotate_point_normals:
463
	movzx	ecx,[points_count_var]
464
	mov	ebx,point_normals_rotated
465
	fninit			   ; for now only rotate around Z axle
466
     .again_r:
467
	cmp	[r_flag],1
468
	je	.z_rot
469
	cmp	[r_flag],2
470
	je	.x_rot
471
 
472
      .y_rot:
473
	fld	dword[ebx]	   ; x
474
	fld	[sinbeta]
475
	fmul	dword[ebx+8]	   ; z * sinbeta
476
	fchs
477
	fld	[cosbeta]
478
	fmul	dword[ebx]	   ; x * cosbeta
479
	faddp
480
	fstp	dword[ebx]	   ; new x
481
	fmul	[sinbeta]	   ; old x * sinbeta
482
	fld	[cosbeta]
483
	fmul	dword[ebx+8]	   ; z * cosbeta
484
	faddp
485
	fstp	dword[ebx+8]	   ; new z
486
	add	ebx,12
487
	loop	.y_rot
488
	jmp	.end_rot
489
      .z_rot:
490
	fld	dword[ebx]	;x
491
	fld	[sinbeta]
492
	fmul	dword[ebx+4]	;y
493
	fld	[cosbeta]
494
	fmul	dword[ebx]	;x
495
	faddp
496
	fstp	dword[ebx]	;new x
497
	fmul	[sinbeta]	; sinbeta * old x
498
	fchs
499
	fld	[cosbeta]
500
	fmul	dword[ebx+4]	     ; cosbeta * y
501
	faddp
502
	fstp	dword[ebx+4]	; new y
503
	add	ebx,12
504
	loop	.z_rot
505
	jmp	.end_rot
506
       .x_rot:
507
	fld	dword[ebx+4]	;y
508
	fld	[sinbeta]
509
	fmul	dword[ebx+8]	;z
510
	fld	[cosbeta]
511
	fmul	dword[ebx+4]	;y
512
	faddp
513
	fstp	dword[ebx+4]	; new y
514
	fmul	[sinbeta]	; sinbeta * old y
515
	fchs
516
	fld	[cosbeta]
517
	fmul	dword[ebx+8]
518
	faddp
519
	fstp	dword[ebx+8]
520
	add	ebx,12
521
	loop	.x_rot
522
       .end_rot:
523
ret
524
init_triangles_normals:
525
	mov	ebx,triangles_normals
526
	mov	ebp,triangles
527
     @@:
528
	push	ebx
529
	mov	ebx,vectors
530
	movzx	esi,word[ebp]	       ; first point index
531
	lea	esi,[esi*3]
532
	lea	esi,[points+esi*2]     ; esi - pointer to 1st 3d point
533
	movzx	edi,word[ebp+2]        ; second point index
534
	lea	edi,[edi*3]
535
	lea	edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
536
	call	make_vector
537
	add	ebx,12
538
	mov	esi,edi
539
	movzx	edi,word[ebp+4]        ; third point index
540
	lea	edi,[edi*3]
541
	lea	edi,[points+edi*2]
542
	call	make_vector
543
	mov	edi,ebx 		; edi - pointer to 2nd vector
544
	mov	esi,ebx
545
	sub	esi,12			; esi - pointer to 1st vector
546
	pop	ebx
547
	call	cross_product
548
	mov	edi,ebx
549
	call	normalize_vector
550
	add	ebp,6
551
	add	ebx,12
552
	cmp	dword[ebp],-1
553
	jne	@b
554
ret
555
 
556
init_point_normals:
557
.x equ dword [ebp-4]
558
.y equ dword [ebp-8]
559
.z equ dword [ebp-12]
560
.point_number equ word [ebp-26]
561
.hit_faces    equ word [ebp-28]
562
 
563
	fninit
564
	mov	  ebp,esp
565
	sub	  esp,28
566
	mov	  edi,point_normals
567
	mov	  .point_number,0
568
    .ipn_loop:
569
	mov	  .hit_faces,0
570
	mov	  .x,0
571
	mov	  .y,0
572
	mov	  .z,0
573
	mov	  esi,triangles
574
	xor	  ecx,ecx	       ; ecx - triangle number
575
    .ipn_check_face:
576
	xor	  ebx,ebx	       ; ebx - 'position' in one triangle
577
    .ipn_check_vertex:
578
	movzx	  eax,word[esi+ebx]    ;  eax - point_number
579
	cmp	  ax,.point_number
580
	jne	  .ipn_next_vertex
581
	push	  esi
582
	mov	  esi,ecx
583
	lea	  esi,[esi*3]
584
	lea	  esi,[triangles_normals+esi*4]
585
       ; shl       esi,2
586
       ; add       esi,triangles_normals
587
 
588
	fld	  .x
589
	fadd	  dword[esi+vec_x]
590
	fstp	  .x
591
	fld	  .y
592
	fadd	  dword[esi+vec_y]
593
	fstp	  .y
594
	fld	  .z
595
	fadd	  dword[esi+vec_z]
596
	fstp	  .z
597
	pop	  esi
598
	inc	  .hit_faces
599
	jmp	  .ipn_next_face
600
    .ipn_next_vertex:
601
	add	  ebx,2
602
	cmp	  ebx,6
603
	jne	  .ipn_check_vertex
604
    .ipn_next_face:
605
	add	  esi,6
606
	inc	  ecx
607
	cmp	  cx,[triangles_count_var]
608
	jne	  .ipn_check_face
609
 
610
	fld	  .x
611
	fidiv	  .hit_faces
612
	fstp	  dword[edi+vec_x]
613
	fld	  .y
614
	fidiv	  .hit_faces
615
	fstp	  dword[edi+vec_y]
616
	fld	  .z
617
	fidiv	  .hit_faces
618
	fstp	  dword[edi+vec_z]
619
	call	  normalize_vector
620
	add	  edi,12  ;type vector 3d
621
	inc	  .point_number
622
	mov	  dx,.point_number
623
	cmp	  dx,[points_count_var]
624
	jne	  .ipn_loop
625
 
626
	mov	  esp,ebp
627
ret
628
 
629
add_vector:
630
	mov ebp,points
631
       @@:
632
	add word[ebp],ax
633
	add word[ebp+2],bx
634
	add word[ebp+4],cx
635
	add ebp,6
636
	cmp dword[ebp],-1
637
	jne @b
638
ret
639
;do_scale:
640
;        fninit
641
;        mov ebp,points
642
;      .next_sc:
643
;        fld1
644
;        fsub [scale]
645
;        fld st
646
;        fimul [xo]
647
;        fld [scale]
648
;        fimul word[ebp] ;x
649
;        faddp
650
;        fistp word[ebp]
651
;        fld st
652
;        fimul [yo]
653
;        fld [scale]
654
;        fimul word[ebp+2]
655
;        faddp
656
;        fistp word[ebp+2]
657
;        fimul [zo]
658
;        fld [scale]
659
;        fimul word[ebp+4]
660
;        faddp
661
;        fistp word[ebp+4]
662
;        add ebp,6
663
;        cmp dword[ebp],-1
664
;        jne .next_sc
665
;ret
666
sort_triangles:
667
	mov	esi,triangles
668
	mov	edi,triangles_with_z
669
	mov	ebp,points_rotated
670
 
671
    make_triangle_with_z:	;makes list with triangles and z position
672
	movzx	eax,word[esi]
673
	lea	eax,[eax*3]
674
	movzx	ecx,word[ebp+eax*2+4]
675
 
676
	movzx	eax,word[esi+2]
677
	lea	eax,[eax*3]
678
	add	cx,word[ebp+eax*2+4]
679
 
680
	movzx	eax,word[esi+4]
681
	lea	eax,[eax*3]
682
	add	cx,word[ebp+eax*2+4]
683
 
684
	mov	ax,cx
685
       ; cwd
686
       ; idiv    word[i3]
687
	movsd			; store vertex coordinates
688
	movsw
689
	stosw			; middle vertex coordinate  'z' in triangles_with_z list
690
	cmp	dword[esi],-1
691
	jne	make_triangle_with_z
692
	movsd			; copy end mark
693
	mov	eax,4
694
	lea	edx,[edi-8-trizdd]
695
	mov	[high],edx
696
	call	quicksort
697
	mov	eax,4
698
	mov	edx,[high]
699
	call	insertsort
700
	jmp	end_sort
701
 
702
    quicksort:
703
	mov	ecx,edx
704
	sub	ecx,eax
705
	cmp	ecx,32
706
	jc	.exit
707
	lea	ecx,[eax+edx]
708
	shr	ecx,4
709
	lea	ecx,[ecx*8-4]; i
710
	mov	ebx,[trizdd+eax]; trizdd[l]
711
	mov	esi,[trizdd+ecx]; trizdd[i]
712
	mov	edi,[trizdd+edx]; trizdd[h]
713
	cmp	ebx,esi
714
	jg	@f		; direction NB! you need to negate these to invert the order
715
      if Ext=NON
716
	mov	[trizdd+eax],esi
717
	mov	[trizdd+ecx],ebx
718
	mov	ebx,[trizdd+eax-4]
719
	mov	esi,[trizdd+ecx-4]
720
	mov	[trizdd+eax-4],esi
721
	mov	[trizdd+ecx-4],ebx
722
	mov	ebx,[trizdd+eax]
723
	mov	esi,[trizdd+ecx]
724
      else
725
	movq	mm0,[trizdq+eax-4]
726
	movq	mm1,[trizdq+ecx-4]
727
	movq	[trizdq+ecx-4],mm0
728
	movq	[trizdq+eax-4],mm1
729
	xchg	ebx,esi
730
      end if
731
      @@:
732
	cmp	ebx,edi
733
	jg	@f		; direction
734
      if Ext=NON
735
	mov	[trizdd+eax],edi
736
	mov	[trizdd+edx],ebx
737
	mov	ebx,[trizdd+eax-4]
738
	mov	edi,[trizdd+edx-4]
739
	mov	[trizdd+eax-4],edi
740
	mov	[trizdd+edx-4],ebx
741
	mov	ebx,[trizdd+eax]
742
	mov	edi,[trizdd+edx]
743
      else
744
	movq	mm0,[trizdq+eax-4]
745
	movq	mm1,[trizdq+edx-4]
746
	movq	[trizdq+edx-4],mm0
747
	movq	[trizdq+eax-4],mm1
748
	xchg	ebx,edi
749
      end if
750
      @@:
751
	cmp	esi,edi
752
	jg	@f		; direction
753
      if Ext=NON
754
	mov	[trizdd+ecx],edi
755
	mov	[trizdd+edx],esi
756
	mov	esi,[trizdd+ecx-4]
757
	mov	edi,[trizdd+edx-4]
758
	mov	[trizdd+ecx-4],edi
759
	mov	[trizdd+edx-4],esi
760
      else
761
	movq	mm0,[trizdq+ecx-4]
762
	movq	mm1,[trizdq+edx-4]
763
	movq	[trizdq+edx-4],mm0
764
	movq	[trizdq+ecx-4],mm1
765
;        xchg    ebx,esi
766
      end if
767
      @@:
768
	mov	ebp,eax 	; direction
769
	add	ebp,8	   ;   j
770
      if Ext=NON
771
	mov	esi,[trizdd+ebp]
772
	mov	edi,[trizdd+ecx]
773
	mov	[trizdd+ebp],edi
774
	mov	[trizdd+ecx],esi
775
	mov	esi,[trizdd+ebp-4]
776
	mov	edi,[trizdd+ecx-4]
777
	mov	[trizdd+ecx-4],esi
778
	mov	[trizdd+ebp-4],edi
779
      else
780
	movq	mm0,[trizdq+ebp-4]
781
	movq	mm1,[trizdq+ecx-4]
782
	movq	[trizdq+ecx-4],mm0
783
	movq	[trizdq+ebp-4],mm1
784
      end if
785
	mov	ecx,edx    ;   i; direction
786
	mov	ebx,[trizdd+ebp]; trizdd[j]
787
      .loop:
788
	sub	ecx,8		; direction
789
	cmp	[trizdd+ecx],ebx
790
	jl	.loop		; direction
791
      @@:
792
	add	ebp,8		; direction
793
	cmp	[trizdd+ebp],ebx
794
	jg	@b		; direction
795
	cmp	ebp,ecx
796
	jge	@f		; direction
797
      if Ext=NON
798
	mov	esi,[trizdd+ecx]
799
	mov	edi,[trizdd+ebp]
800
	mov	[trizdd+ebp],esi
801
	mov	[trizdd+ecx],edi
802
	mov	edi,[trizdd+ecx-4]
803
	mov	esi,[trizdd+ebp-4]
804
	mov	[trizdd+ebp-4],edi
805
	mov	[trizdd+ecx-4],esi
806
      else
807
	movq	mm0,[trizdq+ecx-4]
808
	movq	mm1,[trizdq+ebp-4]
809
	movq	[trizdq+ebp-4],mm0
810
	movq	[trizdq+ecx-4],mm1
811
      end if
812
	jmp	.loop
813
      @@:
814
      if Ext=NON
815
	mov	esi,[trizdd+ecx]
816
	mov	edi,[trizdd+eax+8]
817
	mov	[trizdd+eax+8],esi
818
	mov	[trizdd+ecx],edi
819
	mov	edi,[trizdd+ecx-4]
820
	mov	esi,[trizdd+eax+4]
821
	mov	[trizdd+eax+4],edi
822
	mov	[trizdd+ecx-4],esi
823
      else
824
	movq	mm0,[trizdq+ecx-4]
825
	movq	mm1,[trizdq+eax+4]; dir
826
	movq	[trizdq+eax+4],mm0; dir
827
	movq	[trizdq+ecx-4],mm1
828
      end if
829
	add	ecx,8
830
	push	ecx edx
831
	mov	edx,ebp
832
	call	quicksort
833
	pop	edx eax
834
	call	quicksort
835
      .exit:
836
    ret
837
    insertsort:
838
	mov	esi,eax
839
      .start:
840
	add	esi,8
841
	cmp	esi,edx
842
	ja	.exit
843
	mov	ebx,[trizdd+esi]
844
      if Ext=NON
845
	mov	ecx,[trizdd+esi-4]
846
      else
847
	movq	mm1,[trizdq+esi-4]
848
      end if
849
	mov	edi,esi
850
      @@:
851
	cmp	edi,eax
852
	jna	@f
853
	cmp	[trizdd+edi-8],ebx
854
	jg	@f		   ; direction
855
      if Ext=NON
856
	mov	ebp,[trizdd+edi-8]
857
	mov	[trizdd+edi],ebp
858
	mov	ebp,[trizdd+edi-12]
859
	mov	[trizdd+edi-4],ebp
860
      else
861
	movq	mm0,[trizdq+edi-12]
862
	movq	[trizdq+edi-4],mm0
863
      end if
864
	sub	edi,8
865
	jmp	@b
866
      @@:
867
      if Ext=NON
868
	mov	[trizdd+edi],ebx
869
	mov	[trizdd+edi-4],ecx
870
      else
871
	movq	[trizdq+edi-4],mm1
872
      end if
873
	jmp	.start
874
      .exit:
875
    ret
876
   end_sort:
877
    ; translate triangles_with_z to sorted_triangles
878
	mov	esi,triangles_with_z
879
      ;  mov     edi,sorted_triangles
880
	mov	 edi,triangles
881
    again_copy:
882
      if Ext=NON
883
	movsd
884
	movsw
885
	add	esi,2
886
      else
887
	movq	mm0,[esi]
888
	movq	[edi],mm0
889
	add	esi,8
890
	add	edi,6
891
      end if
892
	cmp	dword[esi],-1
893
	jne	again_copy
894
;      if Ext=MMX
895
;        emms
896
;      end if
897
	movsd  ; copy end mark too
898
ret
899
 
900
clrscr:
901
	mov	edi,screen
902
	mov	ecx,SIZE_X*SIZE_Y*3/4
903
	xor	eax,eax
904
      if Ext=NON
905
	rep	stosd
906
      else
907
	pxor	mm0,mm0
908
      @@:
909
	movq	[edi+00],mm0
910
	movq	[edi+08],mm0
911
	movq	[edi+16],mm0
912
	movq	[edi+24],mm0
913
	add	edi,32
914
	sub	ecx,8
915
	jnc	@b
916
      end if
917
ret
918
 
919
calculate_angle:
920
	fninit
921
;        fldpi
922
;        fidiv   [i180]
923
	fld	[piD180]
924
	fimul	[angle_counter]
925
	fsincos
926
	fstp	[sinbeta]
927
	fstp	[cosbeta]
928
	inc	[angle_counter]
929
	cmp	[angle_counter],360
930
	jne	end_calc_angle
931
	mov	[angle_counter],0
932
    end_calc_angle:
933
ret
934
 
935
rotate_points:
936
	fninit
937
	mov	ebx,points_rotated
938
    again_r:
939
	cmp	[r_flag],1
940
	je	.z_rot
941
	cmp	[r_flag],2
942
	je	.x_rot
943
    .y_rot:
944
	mov	eax,[ebx+2]	;z
945
	mov	ax,word[ebx]	;x
946
	sub	eax,dword[xo]
947
	mov	dword[xsub],eax
948
	fld	[sinbeta]
949
	fimul	[zsub]
950
	fchs
951
	fld	[cosbeta]
952
	fimul	[xsub]
953
	faddp
954
	fiadd	[xo]
955
	fistp	word[ebx]  ;x
956
	fld	[sinbeta]
957
	fimul	[xsub]
958
	fld	[cosbeta]
959
	fimul	[zsub]
960
	faddp
961
	fiadd	[zo]
962
	fistp	word[ebx+4] ;z
963
	jmp	.end_rot
964
   .z_rot:
965
	mov	ax,word[ebx]
966
	sub	ax,word[xo]	  ;need optimization
967
	mov	[xsub],ax
968
	mov	ax,word[ebx+2]
969
	sub	ax,word[yo]
970
	mov	[ysub],ax
971
	fld	[sinbeta]
972
	fimul	[ysub]
973
	fld	[cosbeta]
974
	fimul	[xsub]
975
	faddp
976
	fiadd	[xo]
977
	fistp	word[ebx]
978
	fld	[cosbeta]
979
	fimul	[ysub]
980
	fld	[sinbeta]
981
	fimul	[xsub]
982
	fchs
983
	faddp
984
	fiadd	[yo]
985
	fistp	word[ebx+2]
986
	jmp	.end_rot
987
   .x_rot:
988
	mov	ax,word[ebx+2]
989
	sub	ax,[yo]
990
	mov	[ysub],ax
991
	mov	ax,word[ebx+4]
992
	sub	ax,word[zo]
993
	mov	[zsub],ax
994
	fld	[sinbeta]
995
	fimul	[zsub]
996
	fld	[cosbeta]
997
	fimul	[ysub]
998
	faddp
999
	fiadd	[yo]
1000
	fistp	word[ebx+2];y
1001
	fld	[cosbeta]
1002
	fimul	[zsub]
1003
	fld	[sinbeta]
1004
	fimul	[ysub]
1005
	fchs
1006
	faddp
1007
	fiadd	[zo]
1008
	fistp	word[ebx+4]
1009
     .end_rot:
1010
	add	ebx,6
1011
	cmp	dword[ebx],-1
1012
	jne	again_r
1013
ret
1014
 
1015
draw_triangles:
1016
	mov esi,triangles
1017
    .again_dts:
1018
	mov ebp,points_rotated
1019
      if Ext=NON
1020
	movzx	eax,word[esi]
1021
	mov	[point_index1],ax
1022
	lea	eax,[eax*3]
1023
	add	eax,eax
1024
	push	ebp
1025
	add	ebp,eax
1026
	mov	eax,[ebp]
1027
	mov	dword[xx1],eax
1028
	mov	eax,[ebp+4]
1029
	mov	[zz1],ax
1030
	pop	ebp
1031
 
1032
 
1033
	movzx	eax,word[esi+2]
1034
	mov	[point_index2],ax
1035
	lea	eax,[eax*3]
1036
	add	eax,eax
1037
	push	ebp
1038
	add	ebp,eax
1039
	mov	eax,[ebp]
1040
	mov	dword[xx2],eax
1041
	mov	eax,[ebp+4]
1042
	mov	[zz2],ax
1043
	pop	ebp
1044
 
1045
 
1046
	movzx	eax,word[esi+4]        ; xyz3 = [ebp+[esi+4]*6]
1047
	mov	[point_index3],ax
1048
	lea	eax,[eax*3]
1049
	add	eax,eax
1050
    ;    push    ebp
1051
	add	ebp,eax
1052
	mov	eax,[ebp]
1053
	mov	dword[xx3],eax
1054
	mov	eax,[ebp+4]
1055
	mov	[zz3],ax
1056
      else
1057
	mov	eax,dword[esi]		 ; don't know MMX
1058
	mov	dword[point_index1],eax
1059
       ; shr     eax,16
1060
       ; mov     [point_index2],ax
1061
	mov	ax,word[esi+4]
1062
	mov	[point_index3],ax
1063
	movq	mm0,[esi]
1064
	pmullw	mm0,qword[const6]
1065
	movd	eax,mm0
1066
	psrlq	mm0,16
1067
	movd	ebx,mm0
1068
	psrlq	mm0,16
1069
	movd	ecx,mm0
1070
	and	eax,0FFFFh
1071
	and	ebx,0FFFFh
1072
	and	ecx,0FFFFh
1073
	movq	mm0,[ebp+eax]
1074
	movq	mm1,[ebp+ebx]
1075
	movq	mm2,[ebp+ecx]
1076
	movq	qword[xx1],mm0
1077
	movq	qword[xx2],mm1
1078
	movq	qword[xx3],mm2
1079
;        emms
1080
      end if
1081
	push esi
1082
	; culling
1083
	fninit
1084
	mov	esi,point_index1
1085
	mov	ecx,3
1086
      @@:
1087
	movzx	eax,word[esi]
1088
	lea	eax,[eax*3]
1089
	shl	eax,2
1090
	lea	eax,[eax+point_normals_rotated]
1091
	fld	dword[eax+8]
1092
	ftst
1093
	fstsw	ax
1094
	sahf
1095
	jb     @f
1096
	ffree	st
1097
	loop	@b
1098
	jmp	.end_draw
1099
      @@:
1100
	ffree	st  ;is visable
1101
 
1102
	cmp	[dr_flag],0		  ; draw type flag
1103
	je	.flat_draw
1104
	cmp	[dr_flag],2
1105
	je	.env_mapping
1106
 
1107
	movzx	edi,[point_index3]
1108
	lea	edi,[edi*3]
1109
	lea	edi,[points_color+edi*2]
1110
	cmp	[catmull_flag],0
1111
	je	@f
1112
	push	[zz3]
1113
      @@:
1114
	push	word[edi]
1115
	push	word[edi+2]
1116
	push	word[edi+4]
1117
	movzx	edi,[point_index2]
1118
	lea	edi,[edi*3]
1119
	lea	edi,[points_color+edi*2]
1120
	cmp	[catmull_flag],0
1121
	je	@f
1122
	push	[zz2]
1123
     @@:
1124
	push	word[edi]
1125
	push	word[edi+2]
1126
	push	word[edi+4]
1127
	movzx	edi,[point_index1]
1128
	lea	edi,[edi*3]
1129
	lea	edi,[points_color+edi*2]
1130
	cmp	[catmull_flag],0
1131
	je	@f
1132
	push	[zz1]
1133
      @@:
1134
	push	word[edi]
1135
	push	word[edi+2]
1136
	push	word[edi+4]
1137
 
1138
   ;     movzx   edi,[point_index3]   ;gouraud shading according to light vector
1139
   ;     lea     edi,[edi*3]
1140
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1141
   ;     mov     esi,light_vector
1142
   ;     call    dot_product
1143
   ;     fabs
1144
   ;     fimul   [max_color_r]
1145
   ;     fistp   [temp_col]
1146
   ;     and     [temp_col],0x00ff
1147
   ;     push    [temp_col]
1148
   ;     push    [temp_col]
1149
   ;     push    [temp_col]
1150
 
1151
   ;     movzx   edi,[point_index2]
1152
   ;     lea     edi,[edi*3]
1153
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1154
   ;     mov     esi,light_vector
1155
   ;     call    dot_product
1156
   ;     fabs
1157
   ;     fimul   [max_color_r]
1158
   ;     fistp    [temp_col]
1159
   ;     and     [temp_col],0x00ff
1160
   ;     push    [temp_col]
1161
   ;     push    [temp_col]
1162
   ;     push    [temp_col]
1163
 
1164
   ;     movzx   edi,[point_index1]
1165
   ;     lea     edi,[edi*3]
1166
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1167
   ;     mov     esi,light_vector
1168
   ;     call    dot_product
1169
   ;     fabs
1170
   ;     fimul   [max_color_r]
1171
   ;     fistp   [temp_col]
1172
   ;     and     [temp_col],0x00ff
1173
   ;     push    [temp_col]
1174
   ;     push    [temp_col]
1175
   ;     push    [temp_col]
1176
 
1177
;        xor     edx,edx            ; draw acording to position
1178
;        mov     ax,[zz3]
1179
;        add     ax,128
1180
;        neg     al
1181
;        and     ax,0x00ff
1182
;        push    ax
1183
;        neg     al
1184
;        push    ax
1185
;        mov     dx,[yy3]
1186
;        and     dx,0x00ff
1187
;        push    dx
1188
;        mov     ax,[zz2]
1189
;        add     ax,128
1190
;        neg     al
1191
;        and     ax,0x00ff
1192
;        push    ax
1193
;        neg     al
1194
;        push    ax
1195
;        mov     dx,[yy2]
1196
;        and     dx,0x00ff
1197
;        push    dx
1198
;        mov     ax,[zz1]
1199
;        add     ax,128
1200
;        neg     al
1201
;        and     ax,0x00ff
1202
;        push    ax
1203
;        neg     al
1204
;        push    ax
1205
;        mov     dx,[yy1]
1206
;        and     dx,0x00ff
1207
;        push    dx
1208
	mov	eax,dword[xx1]
1209
	ror	eax,16
1210
	mov	ebx,dword[xx2]
1211
	ror	ebx,16
1212
	mov	ecx,dword[xx3]
1213
	ror	ecx,16
1214
	lea	edi,[screen]
1215
	cmp	[catmull_flag],0
1216
	je	@f
1217
	lea	esi,[Z_buffer]
1218
	call	gouraud_triangle_z
1219
	jmp	.end_draw
1220
       @@:
1221
	call	gouraud_triangle
1222
	jmp	.end_draw
1223
     .flat_draw:
1224
 
1225
	movzx	edi,[point_index3]
1226
	lea	edi,[edi*3]
1227
	lea	edi,[points_color+edi*2]
1228
	movzx	eax,word[edi]
1229
	movzx	ebx,word[edi+2]
1230
	movzx	ecx,word[edi+4]
1231
	movzx	edi,[point_index2]
1232
	lea	edi,[edi*3]
1233
	lea	edi,[points_color+edi*2]
1234
	add	ax,word[edi]
1235
	add	bx,word[edi+2]
1236
	add	cx,word[edi+4]
1237
	movzx	edi,[point_index1]
1238
	lea	edi,[edi*3]
1239
	lea	edi,[points_color+edi*2]
1240
	add	ax,word[edi]
1241
	add	bx,word[edi+2]
1242
	add	cx,word[edi+4]
1243
	cwd
1244
	idiv	[i3]
1245
	mov	di,ax
1246
	shl	edi,16
1247
	mov	ax,bx
1248
	cwd
1249
	idiv	[i3]
1250
	mov	di,ax
1251
	shl	di,8
1252
	mov	ax,cx
1253
	cwd
1254
	idiv	[i3]
1255
	mov	edx,edi
1256
	mov	dl,al
1257
	and	edx,0x00ffffff
1258
 
1259
 
1260
     ;   mov     ax,[zz1]      ; z position depend draw
1261
     ;   add     ax,[zz2]
1262
     ;   add     ax,[zz3]
1263
     ;   cwd
1264
     ;   idiv    [i3] ;    = -((a+b+c)/3+130)
1265
     ;   add     ax,130
1266
     ;   neg     al
1267
     ;   xor     edx,edx
1268
     ;   mov     ah,al           ;set color according to z position
1269
     ;   shl     eax,8
1270
     ;   mov     edx,eax
1271
 
1272
	mov	eax,dword[xx1]
1273
	ror	eax,16
1274
	mov	ebx,dword[xx2]
1275
	ror	ebx,16
1276
	mov	ecx,dword[xx3]
1277
	ror	ecx,16
1278
       ; mov     edi,screen
1279
	lea	edi,[screen]
1280
	cmp	[catmull_flag],0
1281
	je	@f
1282
	lea	esi,[Z_buffer]
1283
	push	word[zz3]
1284
	push	word[zz2]
1285
	push	word[zz1]
1286
	call	flat_triangle_z
1287
	jmp	.end_draw
1288
      @@:
1289
	call	draw_triangle
1290
	jmp	.end_draw
1291
      .env_mapping:
1292
       ; fninit
1293
	mov	esi,point_index1
1294
	sub	esp,12
1295
	mov	edi,esp
1296
	mov	ecx,3
1297
      @@:
1298
	movzx	eax,word[esi]
1299
	lea	eax,[eax*3]
1300
	shl	eax,2
1301
	add	eax,point_normals_rotated
1302
	; texture x=(rotated point normal -> x * 255)+255
1303
	fld	dword[eax]
1304
	fimul	[correct_tex]
1305
	fiadd	[correct_tex]
1306
	fistp	word[edi]
1307
	; texture y=(rotated point normal -> y * 255)+255
1308
	fld	dword[eax+4]
1309
	fimul	[correct_tex]
1310
	fiadd	[correct_tex]
1311
	fistp	word[edi+2]
1312
 
1313
	add	edi,4
1314
	add	esi,2
1315
	loop	@b
1316
 
1317
	mov	eax,dword[xx1]
1318
	ror	eax,16
1319
	mov	ebx,dword[xx2]
1320
	ror	ebx,16
1321
	mov	ecx,dword[xx3]
1322
	ror	ecx,16
1323
	mov	edi,screen
1324
	mov	esi,envmap
1325
	call	tex_triangle
1326
 
1327
      .end_draw:
1328
	pop	esi
1329
	add	esi,6
1330
	cmp	dword[esi],-1
1331
	jne	.again_dts
1332
ret
1782 yogev_ezra 1333
;translate_points:
1781 yogev_ezra 1334
;        fninit
1335
;        mov     ebx,points_rotated
1336
;    again_trans:
1337
;        fild    word[ebx+4] ;z1
1338
;        fmul    [sq]
1339
;        fld     st
1340
;        fiadd   word[ebx]  ;x1
1341
;        fistp   word[ebx]
1342
;        fchs
1343
;        fiadd   word[ebx+2] ;y1
1344
;        fistp   word[ebx+2] ;y1
1345
 
1346
;        add     ebx,6
1347
;        cmp     dword[ebx],-1
1348
;        jne     again_trans
1349
;ret
1350
translate_perspective_points: ;translate points from 3d to 2d using
1351
	fninit		      ;perspective equations
1352
	mov ebx,points_rotated
1353
      .again_trans:
1354
	fild word[ebx]
1355
	fisub [xobs]
1356
	fimul [zobs]
1357
	fild word[ebx+4]
1358
	fisub [zobs]
1359
	fdivp
1360
	fiadd [xobs]
1361
	fistp word[ebx]
1362
	fild word[ebx+2]
1363
	fisub [yobs]
1364
	fimul [zobs]
1365
	fild word[ebx+4]
1366
	fisub [zobs]
1367
	fdivp
1368
	fchs
1369
	fiadd [yobs]
1370
	fistp word[ebx+2]
1371
	add ebx,6
1372
	cmp dword[ebx],-1
1373
	jne .again_trans
1374
ret
1375
 
1376
 
1377
copy_points:
1378
	mov	esi,points
1379
	mov	edi,points_rotated
1380
	mov	ecx,points_count*3+2
1381
	rep	movsw
1382
ret
1383
 
1384
 
1385
 
1386
read_from_file:
1387
	mov	edi,triangles
1388
	xor	ebx,ebx
1389
	xor	ebp,ebp
1390
	mov	esi,SourceFile
1391
	cmp	[esi],word 4D4Dh
1392
	jne	.exit ;Must be legal .3DS file
1393
	cmp	dword[esi+2],EndFile-SourceFile
1394
	jne	.exit ;This must tell the length
1395
	add	esi,6
1396
      @@:
1397
	cmp	[esi],word 3D3Dh
1398
	je	@f
1399
	add	esi,[esi+2]
1400
	jmp	@b
1401
      @@:
1402
	add	esi,6
1403
      .find4k:
1404
	cmp	[esi],word 4000h
1405
	je	@f
1406
	add	esi,[esi+2]
1407
	cmp	esi,EndFile
1408
	jc	.find4k
1409
	jmp	.exit
1410
      @@:
1411
	add	esi,6
1412
      @@:
1413
	cmp	[esi],byte 0
1414
	je	@f
1415
	inc	esi
1416
	jmp	@b
1417
      @@:
1418
	inc	esi
1419
      @@:
1420
	cmp	[esi],word 4100h
1421
	je	@f
1422
	add	esi,[esi+2]
1423
	jmp	@b
1424
      @@:
1425
	add	esi,6
1426
      @@:
1427
	cmp	[esi],word 4110h
1428
	je	@f
1429
	add	esi,[esi+2]
1430
	jmp	@b
1431
      @@:
1432
	movzx	ecx,word[esi+6]
1433
	mov	[points_count_var],cx
1434
	mov	edx,ecx
1435
	add	esi,8
1436
      @@:
1437
	fld	dword[esi+4]
1438
	fmul	[sscale]
1439
	fadd	[xoffset]
1440
	fld	dword[esi+8]
1441
	fchs
1442
	fmul	[sscale]
1443
	fadd	[yoffset]
1444
	fld	dword[esi+0]
1445
	fchs
1446
	fmul	[sscale]
1447
	fistp	word[points+ebx+4]
1448
	fistp	word[points+ebx+2]
1449
	fistp	word[points+ebx+0]
1450
	add	ebx,6
1451
	add	esi,12
1452
	dec	ecx
1453
	jnz	@b
1454
      @@:
1455
	mov	dword[points+ebx],-1
1456
      @@:
1457
	cmp	[esi],word 4120h
1458
	je	@f
1459
	add	esi,[esi+2]
1460
	jmp	@b
1461
      @@:
1462
	movzx	ecx,word[esi+6]
1463
	mov	[triangles_count_var],cx
1464
	add	esi,8
1465
	;mov     edi,triangles
1466
      @@:
1467
	movsd
1468
	movsw
1469
	add	word[edi-6],bp
1470
	add	word[edi-4],bp
1471
	add	word[edi-2],bp
1472
	add	esi,2
1473
	dec	ecx
1474
	jnz	@b
1475
	add	ebp,edx
1476
	jmp	.find4k
1477
 
1478
      .exit:
1479
	mov	dword[edi],-1
1480
ret
1481
 
1482
 
1483
;   *********************************************
1484
;   *******  WINDOW DEFINITIONS AND DRAW ********
1485
;   *********************************************
1486
    draw_window:
1487
	mov	eax,12		; function 12:tell os about windowdraw
1488
	mov	ebx,1		; 1, start of draw
1489
	int	0x40
1490
 
1491
	; DRAW WINDOW
1492
	mov	eax,0		; function 0 : define and draw window
1493
	mov	ebx,100*65536+SIZE_X+80 ; [x start] *65536 + [x size]
1494
	mov	ecx,100*65536+SIZE_Y+30 ; [y start] *65536 + [y size]
1495
	mov	edx,0x02000000	; color of work area RRGGBB,8->color gl
1496
	mov	esi,0x805080d0	; color of grab bar  RRGGBB,8->color gl
1497
	mov	edi,0x005080d0	; color of frames    RRGGBB
1498
	int	0x40
1499
 
1500
	; WINDOW LABEL
1501
	mov	eax,4		; function 4 : write text to window
1502
	mov	ebx,8*65536+8	; [x start] *65536 + [y start]
1503
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1504
	mov	edx,labelt	; pointer to text beginning
1505
	mov	esi,labellen-labelt	; text length
1506
	int	0x40
1507
 
1508
	; CLOSE BUTTON
1509
	mov	eax,8		; function 8 : define and draw button
1510
	mov	ebx,(SIZE_X+80-19)*65536+12	; [x start] *65536 + [x size]
1511
	mov	ecx,5*65536+12	; [y start] *65536 + [y size]
1512
	mov	edx,1		; button id
1513
	mov	esi,0x6688dd	; button color RRGGBB
1514
	int	0x40
1515
 
1516
	 ; ROTARY BUTTON
1517
	mov	eax,8		; function 8 : define and draw button
1518
	mov	ebx,(SIZE_X+10)*65536+62     ; [x start] *65536 + [x size]
1519
	mov	ecx,25*65536+12  ; [y start] *65536 + [y size]
1520
	mov	edx,2		; button id
1521
	mov	esi,0x6688dd	; button color RRGGBB
1522
	int	0x40
1523
	 ; ROTARY  LABEL
1524
	mov	eax,4		; function 4 : write text to window
1525
	mov	ebx,(SIZE_X+12)*65536+28   ; [x start] *65536 + [y start]
1526
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1527
	mov	edx,labelrot	  ; pointer to text beginning
1528
	mov	esi,labelrotend-labelrot     ; text length
1529
	int	0x40
1530
 
1531
	 ; DRAW MODE BUTTON
1532
	mov	eax,8		; function 8 : define and draw button
1533
	mov	ebx,(SIZE_X+10)*65536+62     ; [x start] *65536 + [x size]
1534
	mov	ecx,(25+15)*65536+12  ; [y start] *65536 + [y size]
1535
	mov	edx,3		; button id
1536
	mov	esi,0x6688dd	; button color RRGGBB
1537
	int	0x40
1538
	 ; DRAW MODE LABEL
1539
	mov	eax,4		; function 4 : write text to window
1540
	mov	ebx,(SIZE_X+12)*65536+28+15   ; [x start] *65536 + [y start]
1541
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1542
	mov	edx,labeldrmod	    ; pointer to text beginning
1543
	mov	esi,labeldrmodend-labeldrmod	 ; text length
1544
	int	0x40
1545
 
1546
	 ; SPEED BUTTON
1547
	mov	eax,8		; function 8 : define and draw button
1548
	mov	ebx,(SIZE_X+10)*65536+62     ; [x start] *65536 + [x size]
1549
	mov	ecx,(25+15*2)*65536+12	; [y start] *65536 + [y size]
1550
	mov	edx,4		; button id
1551
	mov	esi,0x6688dd	; button color RRGGBB
1552
	int	0x40
1553
	 ; SPEED MODE LABEL
1554
	mov	eax,4		; function 4 : write text to window
1555
	mov	ebx,(SIZE_X+12)*65536+(28+15*2)   ; [x start] *65536 + [y start]
1556
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1557
	mov	edx,labelspeedmod      ; pointer to text beginning
1558
	mov	esi,labelspeedmodend-labelspeedmod     ; text length
1559
	int	0x40
1560
 
1561
	 ; SCALE- BUTTON
1562
	mov	eax,8		; function 8 : define and draw button
1563
	mov	ebx,(SIZE_X+10)*65536+62     ; [x start] *65536 + [x size]
1564
	mov	ecx,(25+15*3)*65536+12	; [y start] *65536 + [y size]
1565
	mov	edx,5		; button id
1566
	mov	esi,0x6688dd	; button color RRGGBB
1567
	int	0x40
1568
	 ; SCALE- MODE LABEL
1569
	mov	eax,4		; function 4 : write text to window
1570
	mov	ebx,(SIZE_X+12)*65536+(28+15*3)   ; [x start] *65536 + [y start]
1571
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1572
	mov	edx,labelzoomout      ; pointer to text beginning
1573
	mov	esi,labelzoomoutend-labelzoomout     ; text length
1574
	int	0x40
1575
 
1576
	 ; SCALE+ BUTTON
1577
	mov	eax,8		; function 8 : define and draw button
1578
	mov	ebx,(SIZE_X+10)*65536+62     ; [x start] *65536 + [x size]
1579
	mov	ecx,(25+15*4)*65536+12	; [y start] *65536 + [y size]
1580
	mov	edx,6		; button id
1581
	mov	esi,0x6688dd	; button color RRGGBB
1582
	int	0x40
1583
	 ; SCALE+ MODE LABEL
1584
	mov	eax,4		; function 4 : write text to window
1585
	mov	ebx,(SIZE_X+12)*65536+(28+15*4)   ; [x start] *65536 + [y start]
1586
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1587
	mov	edx,labelzoomin      ; pointer to text beginning
1588
	mov	esi,labelzoominend-labelzoomin	   ; text length
1589
	int	0x40
1590
	; ADD VECTOR LABEL
1591
	mov	eax,4		; function 4 : write text to window
1592
	mov	ebx,(SIZE_X+12)*65536+(28+15*5)   ; [x start] *65536 + [y start]
1593
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1594
	mov	edx,labelvector      ; pointer to text beginning
1595
	mov	esi,labelvectorend-labelvector	   ; text length
1596
	int	0x40
1597
	 ; VECTOR Y- BUTTON
1598
	mov	eax,8		; function 8 : define and draw button
1599
	mov	ebx,(SIZE_X+10+20)*65536+62-42	   ; [x start] *65536 + [x size]
1600
	mov	ecx,(25+15*6)*65536+12	; [y start] *65536 + [y size]
1601
	mov	edx,7		; button id
1602
	mov	esi,0x6688dd	; button color RRGGBB
1603
	int	0x40
1604
	;VECTOR Y- LABEL
1605
	mov	eax,4		; function 4 : write text to window
1606
	mov	ebx,(SIZE_X+12+20)*65536+(28+15*6)   ; [x start] *65536 + [y start]
1607
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1608
	mov	edx,labelyminus      ; pointer to text beginning
1609
	mov	esi,labelyminusend-labelyminus	   ; text length
1610
	int	0x40
1611
	; VECTOR Z+ BUTTON
1612
	mov	eax,8		; function 8 : define and draw button
1613
	mov	ebx,(SIZE_X+10+41)*65536+62-41	   ; [x start] *65536 + [x size]
1614
	mov	ecx,(25+15*6)*65536+12	; [y start] *65536 + [y size]
1615
	mov	edx,8		; button id
1616
	mov	esi,0x6688dd	; button color RRGGBB
1617
	int	0x40
1618
	;VECTOR Z+ LABEL
1619
	mov	eax,4		; function 4 : write text to window
1620
	mov	ebx,(SIZE_X+12+41)*65536+(28+15*6)   ; [x start] *65536 + [y start]
1621
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1622
	mov	edx,labelzplus	    ; pointer to text beginning
1623
	mov	esi,labelzplusend-labelzplus	 ; text length
1624
	int	0x40
1625
	; VECTOR x- BUTTON
1626
	mov	eax,8		; function 8 : define and draw button
1627
	mov	ebx,(SIZE_X+10)*65536+62-41	; [x start] *65536 + [x size]
1628
	mov	ecx,(25+15*7)*65536+12	; [y start] *65536 + [y size]
1629
	mov	edx,9		; button id
1630
	mov	esi,0x6688dd	; button color RRGGBB
1631
	int	0x40
1632
	;VECTOR x- LABEL
1633
	mov	eax,4		; function 4 : write text to window
1634
	mov	ebx,(SIZE_X+12)*65536+(28+15*7)   ; [x start] *65536 + [y start]
1635
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1636
	mov	edx,labelxminus      ; pointer to text beginning
1637
	mov	esi,labelxminusend-labelxminus	   ; text length
1638
	int	0x40
1639
	; VECTOR x+ BUTTON
1640
	mov	eax,8		; function 8 : define and draw button
1641
	mov	ebx,(SIZE_X+10+41)*65536+62-41	   ; [x start] *65536 + [x size]
1642
	mov	ecx,(25+15*7)*65536+12	; [y start] *65536 + [y size]
1643
	mov	edx,10		 ; button id
1644
	mov	esi,0x6688dd	; button color RRGGBB
1645
	int	0x40
1646
	;VECTOR x+ LABEL
1647
	mov	eax,4		; function 4 : write text to window
1648
	mov	ebx,(SIZE_X+12+41)*65536+(28+15*7)   ; [x start] *65536 + [y start]
1649
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1650
	mov	edx,labelxplus	    ; pointer to text beginning
1651
	mov	esi,labelxplusend-labelxplus	 ; text length
1652
	int	0x40
1653
	; VECTOR z- BUTTON
1654
	mov	eax,8		; function 8 : define and draw button
1655
	mov	ebx,(SIZE_X+10)*65536+62-41	; [x start] *65536 + [x size]
1656
	mov	ecx,(25+15*8)*65536+12	; [y start] *65536 + [y size]
1657
	mov	edx,11		 ; button id
1658
	mov	esi,0x6688dd	; button color RRGGBB
1659
	int	0x40
1660
	;VECTOR z- LABEL
1661
	mov	eax,4		; function 4 : write text to window
1662
	mov	ebx,(SIZE_X+12)*65536+(28+15*8)   ; [x start] *65536 + [y start]
1663
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1664
	mov	edx,labelzminus      ; pointer to text beginning
1665
	mov	esi,labelzminusend-labelzminus	   ; text length
1666
	int	0x40
1667
       ;VECTOR Y+ BUTTON
1668
	mov	eax,8		; function 8 : define and draw button
1669
	mov	ebx,(SIZE_X+10+20)*65536+62-42	   ; [x start] *65536 + [x size]
1670
	mov	ecx,(25+15*8)*65536+12	; [y start] *65536 + [y size]
1671
	mov	edx,12		 ; button id
1672
	mov	esi,0x6688dd	; button color RRGGBB
1673
	int	0x40
1674
	;VECTOR Y+ LABEL
1675
	mov	eax,4		; function 4 : write text to window
1676
	mov	ebx,(SIZE_X+12+20)*65536+(28+15*8)   ; [x start] *65536 + [y start]
1677
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1678
	mov	edx,labelyplus	    ; pointer to text beginning
1679
	mov	esi,labelyplusend-labelyplus	 ; text length
1680
	int	0x40
1681
	; LEAD COLOR LABEL
1682
	mov	eax,4		; function 4 : write text to window
1683
	mov	ebx,(SIZE_X+12)*65536+(28+15*9)   ; [x start] *65536 + [y start]
1684
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1685
	mov	edx,labelmaincolor	; pointer to text beginning
1686
	mov	esi,labelmaincolorend-labelmaincolor	 ; text length
1687
	int	0x40
1688
 
1689
	;RED+ BUTTON
1690
	mov	eax,8		; function 8 : define and draw button
1691
	mov	ebx,(SIZE_X+10)*65536+62-41	; [x start] *65536 + [x size]
1692
	mov	ecx,(25+15*10)*65536+12  ; [y start] *65536 + [y size]
1693
	mov	edx,13		 ; button id
1694
	mov	esi,0x6688dd	; button color RRGGBB
1695
	int	0x40
1696
	;RED+  LABEL
1697
	mov	eax,4		; function 4 : write text to window
1698
	mov	ebx,(SIZE_X+12)*65536+(28+15*10)   ; [x start] *65536 + [y start]
1699
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1700
	mov	edx,labelredplus      ; pointer to text beginning
1701
	mov	esi,labelredplusend-labelredplus     ; text length
1702
	int	0x40
1703
	;GREEN+ BUTTON
1704
	mov	eax,8		; function 8 : define and draw button
1705
	mov	ebx,(SIZE_X+10+20)*65536+62-42	   ; [x start] *65536 + [x size]
1706
	mov	ecx,(25+15*10)*65536+12  ; [y start] *65536 + [y size]
1707
	mov	edx,14		 ; button id
1708
	mov	esi,0x6688dd	; button color RRGGBB
1709
	int	0x40
1710
	;GREEN+ LABEL
1711
	mov	eax,4		; function 4 : write text to window
1712
	mov	ebx,(SIZE_X+12+20)*65536+(28+15*10)   ; [x start] *65536 + [y start]
1713
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1714
	mov	edx,labelgreenplus	; pointer to text beginning
1715
	mov	esi,labelgreenplusend-labelgreenplus	 ; text length
1716
	int	0x40
1717
	;BLUE+ BUTTON
1718
	mov	eax,8		; function 8 : define and draw button
1719
	mov	ebx,(SIZE_X+10+41)*65536+62-41	   ; [x start] *65536 + [x size]
1720
	mov	ecx,(25+15*10)*65536+12  ; [y start] *65536 + [y size]
1721
	mov	edx,15		 ; button id
1722
	mov	esi,0x6688dd	; button color RRGGBB
1723
	int	0x40
1724
	;BLUE+ LABEL
1725
	mov	eax,4		; function 4 : write text to window
1726
	mov	ebx,(SIZE_X+12+41)*65536+(28+15*10)   ; [x start] *65536 + [y start]
1727
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1728
	mov	edx,labelblueplus      ; pointer to text beginning
1729
	mov	esi,labelblueplusend-labelblueplus     ; text length
1730
	int	0x40
1731
	;RED- BUTTON
1732
	mov	eax,8		; function 8 : define and draw button
1733
	mov	ebx,(SIZE_X+10)*65536+62-41	; [x start] *65536 + [x size]
1734
	mov	ecx,(25+15*11)*65536+12  ; [y start] *65536 + [y size]
1735
	mov	edx,16		 ; button id
1736
	mov	esi,0x6688dd	; button color RRGGBB
1737
	int	0x40
1738
	;RED-  LABEL
1739
	mov	eax,4		; function 4 : write text to window
1740
	mov	ebx,(SIZE_X+12)*65536+(28+15*11)   ; [x start] *65536 + [y start]
1741
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1742
	mov	edx,labelredminus      ; pointer to text beginning
1743
	mov	esi,labelredminusend-labelredminus     ; text length
1744
	int	0x40
1745
	;GREEN- BUTTON
1746
	mov	eax,8		; function 8 : define and draw button
1747
	mov	ebx,(SIZE_X+10+20)*65536+62-42	   ; [x start] *65536 + [x size]
1748
	mov	ecx,(25+15*11)*65536+12  ; [y start] *65536 + [y size]
1749
	mov	edx,17		 ; button id
1750
	mov	esi,0x6688dd	; button color RRGGBB
1751
	int	0x40
1752
	;GREEN- LABEL
1753
	mov	eax,4		; function 4 : write text to window
1754
	mov	ebx,(SIZE_X+12+20)*65536+(28+15*11)   ; [x start] *65536 + [y start]
1755
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1756
	mov	edx,labelgreenminus	 ; pointer to text beginning
1757
	mov	esi,labelgreenminusend-labelgreenminus	   ; text length
1758
	int	0x40
1759
	;BLUE- BUTTON
1760
	mov	eax,8		; function 8 : define and draw button
1761
	mov	ebx,(SIZE_X+10+41)*65536+62-41	   ; [x start] *65536 + [x size]
1762
	mov	ecx,(25+15*11)*65536+12  ; [y start] *65536 + [y size]
1763
	mov	edx,18		 ; button id
1764
	mov	esi,0x6688dd	; button color RRGGBB
1765
	int	0x40
1766
	;BLUE- LABEL
1767
	mov	eax,4		; function 4 : write text to window
1768
	mov	ebx,(SIZE_X+12+41)*65536+(28+15*11)   ; [x start] *65536 + [y start]
1769
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1770
	mov	edx,labelblueminus	; pointer to text beginning
1771
	mov	esi,labelblueminusend-labelblueminus	 ; text length
1772
	int	0x40
1773
	; Catmull  LABEL
1774
	mov	eax,4		; function 4 : write text to window
1775
	mov	ebx,(SIZE_X+12)*65536+(28+15*12)   ; [x start] *65536 + [y start]
1776
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1777
	mov	edx,labelcatmullmod	 ; pointer to text beginning
1778
	mov	esi,labelcatmullmodend-labelcatmullmod	   ; text length
1779
	int	0x40
1780
	; on/off BUTTON
1781
	mov	eax,8		; function 8 : define and draw button
1782
	mov	ebx,(SIZE_X+10)*65536+62     ; [x start] *65536 + [x size]
1783
	mov	ecx,(25+15*13)*65536+12  ; [y start] *65536 + [y size]
1784
	mov	edx,19		 ; button id
1785
	mov	esi,0x6688dd	; button color RRGGBB
1786
	int	0x40
1787
	 ; on/off LABEL
1788
	mov	eax,4		; function 4 : write text to window
1789
	mov	ebx,(SIZE_X+12)*65536+(28+15*13)   ; [x start] *65536 + [y start]
1790
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
1791
	mov	edx,labelonoff	    ; pointer to text beginning
1792
	mov	esi,labelonoffend-labelonoff	 ; text length
1793
	int	0x40
1794
 
1795
 
1796
	mov	eax,12		; function 12:tell os about windowdraw
1797
	mov	ebx,2		; 2, end of draw
1798
	int	0x40
1799
 
1800
	ret
1801
 
1802
 
1803
	; DATA AREA
1804
	i3		dw	3
1805
	light_vector	dd	0.0,0.0,-1.0
1806
     ;  debug_vector    dd      0.0,2.0,2.0   ;--debug
1807
     ;  debug_vector1   dd      0.0,0.0,0.0
1808
     ;  debug_points    dw      1,1,1,3,4,20
1809
     ;  debug_dd        dw      ?
1810
     ;  debug_dwd       dd      65535
1811
     ;  debug_counter   dw      0
1812
	dot_max 	dd	1.0
1813
	dot_min 	dd	0.0
1814
	env_const	dd	1.2
1815
	correct_tex	dw	255
1816
	max_color_r	dw	255
1817
	max_color_g	dw	25
1818
	max_color_b	dw	35
1819
	xobs		dw	SIZE_X / 2 ;200 ;observer
1820
	yobs		dw	SIZE_Y / 2 ;200 ;coordinates
1821
	zobs		dw	-500
1822
 
1823
 
1824
	angle_counter dw 0
1825
	piD180	      dd 0.017453292519943295769236907684886
1826
      ;  sq            dd 0.70710678118654752440084436210485
1827
	const6	      dw 6,6,6,6
1828
	xo	      dw 130;87
1829
	zo	      dw 0
1830
	yo	      dw 100
1831
	xoffset       dd 130.0
1832
	yoffset       dd 150.0
1833
	sscale	      dd 6.0		 ; real scale
1834
	vect_x	      dw 0
1835
	vect_y	      dw 0
1836
	vect_z	      dw 0
1837
 
1838
 
1839
	r_flag	      db 0
1840
	dr_flag       db 2
1841
	speed_flag    db 0
1842
	catmull_flag  db 0
1843
    SourceFile file '../../3DS/HRT.3DS'
1844
    EndFile:
1845
    labelrot:
1846
	db   'rot. mode'
1847
    labelrotend:
1848
    labeldrmod:
1849
	db   'shd. mode'
1850
    labeldrmodend:
1851
    labelspeedmod:
1852
	db   'spd. mode'
1853
    labelspeedmodend:
1854
    labelzoomout:
1855
	db   'zoom out'
1856
    labelzoomoutend:
1857
    labelzoomin:
1858
	db   'zoom in'
1859
    labelzoominend:
1860
    labelvector:
1861
	db   'add vector'
1862
    labelvectorend:
1863
    labelyminus:
1864
	db   'y -'
1865
    labelyminusend:
1866
    labelzplus:
1867
	db   'z +'
1868
    labelzplusend:
1869
    labelxminus:
1870
	db   'x -'
1871
    labelxminusend:
1872
    labelxplus:
1873
	db   'x +'
1874
    labelxplusend:
1875
    labelzminus:
1876
	db   'z -'
1877
    labelzminusend:
1878
    labelyplus:
1879
	db   'y +'
1880
    labelyplusend:
1881
    labelmaincolor:
1882
	db   'main color'
1883
    labelmaincolorend:
1884
    labelredplus:
1885
	db   'r +'
1886
    labelredplusend:
1887
    labelgreenplus:
1888
	db   'g +'
1889
    labelgreenplusend:
1890
    labelblueplus:
1891
	db   'b +'
1892
    labelblueplusend:
1893
    labelredminus:
1894
	db   'r -'
1895
    labelredminusend:
1896
    labelgreenminus:
1897
	db   'g -'
1898
    labelgreenminusend:
1899
    labelblueminus:
1900
	db   'b -'
1901
    labelblueminusend:
1902
    labelcatmullmod:
1903
	db 'catmull'
1904
    labelcatmullmodend:
1905
    labelonoff:
1906
	db 'on/off'
1907
    labelonoffend:
1908
    labelt:
1909
	db   'DEUS CARITAS EST'
1910
      if Ext=MMX
1911
	db   ' (MMX)'
1912
      end if
1913
    labellen:
1914
	STRdata db '-1        '
1915
align 8
1916
	@col	dd	?
1917
	@y1	dw	?
1918
	@x1	dw	?;+8
1919
	@y2	dw	?
1920
	@x2	dw	?
1921
	@y3	dw	?
1922
	@x3	dw	?;+16
1923
 
1924
	@dx12	dd	?
1925
	@dx13	dd	?;+24
1926
	@dx23	dd	?
1927
 
1928
	sinbeta dd	?;+32
1929
	cosbeta dd	?
1930
 
1931
	xsub	dw	?
1932
	zsub	dw	?;+40
1933
	ysub	dw	?
1934
 
1935
	xx1	dw	?
1936
	yy1	dw	?
1937
	zz1	dw	?;+48
1938
	xx2	dw	?
1939
	yy2	dw	?
1940
	zz2	dw	?
1941
	xx3	dw	?;+56
1942
	yy3	dw	?
1943
	zz3	dw	?
1944
	scale	dd	?		  ; help scale variable
1945
	;screen  dd      ?                ;pointer to screen buffer
1946
	triangles_count_var dw ?
1947
	points_count_var    dw ?
1948
 
1949
 
1950
	point_index1	    dw ?   ;-\
1951
	point_index2	    dw ?   ;  }  don't change order
1952
	point_index3	    dw ?   ;-/
1953
	temp_col	    dw ?
1954
	high	dd	?
1955
align 8
1956
	buffer	dq	?
1957
 
1783 yogev_ezra 1958
	err_	dd	?
1781 yogev_ezra 1959
	drr	dd	?
1960
	xx	dd	?
1961
	yy	dd	?
1962
	xst	dd	?
1963
	yst	dd	?
1964
align 16
1965
    points:
1966
	rw (EndFile-SourceFile)/12*3
1967
	points_count = ($-points)/6
1968
    triangles:
1969
	rw (EndFile-SourceFile)/12*3
1970
	triangles_count = ($-triangles)/6
1971
 
1972
align 16
1973
	points_rotated rw points_count*3 + 2
1974
align 16
1975
	label trizdd dword
1976
	label trizdq qword
1977
	triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position
1978
align 16
1979
	triangles_normals rb triangles_count * 12 ;
1980
	point_normals rb points_count * 12  ;one 3dvector - triple float dword x,y,z
1981
align 16
1982
	point_normals_rotated rb points_count * 12
1983
align 16
1984
	vectors rb 24
1985
	points_color rb 6*points_count	  ; each color as word
1986
;        sorted_triangles rw triangles_count*3 + 2
1987
;align 16
1988
	screen rb SIZE_X * SIZE_Y * 3	; screen buffer
1989
	Z_buffer rb SIZE_X * SIZE_Y * 4
1990
	envmap	 rb 512*512*3
1991
	memStack rb 1000 ;memory area for stack
1992
    I_END: