Subversion Repositories Kolibri OS

Rev

Rev 8047 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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