Subversion Repositories Kolibri OS

Rev

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

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