Subversion Repositories Kolibri OS

Rev

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

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