Subversion Repositories Kolibri OS

Rev

Rev 1245 | Blame | Last modification | View Log | Download | RSS feed

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