Subversion Repositories Kolibri OS

Rev

Rev 8232 | Rev 8719 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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