Subversion Repositories Kolibri OS

Rev

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

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