Subversion Repositories Kolibri OS

Rev

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

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