Subversion Repositories Kolibri OS

Rev

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