Subversion Repositories Kolibri OS

Rev

Rev 5763 | Blame | Last modification | View Log | Download | RSS feed

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