Subversion Repositories Kolibri OS

Rev

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

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