Subversion Repositories Kolibri OS

Rev

Rev 180 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; mov [pointer_to_screen],eax
  2. ; mov [output_array],ebx
  3. ; mov [screen_size_x],ecx
  4. ;setpixel (pixel_x,pixel_y)
  5. setpixel:
  6.  
  7.   mov ecx,[output_array]
  8.   mov eax,[pixel_y]
  9.   mov ebx,[screen_size_x]
  10.   imul eax,ebx
  11.   add eax,[pixel_x]
  12.   lea eax,[eax+eax*2]
  13.   add eax,[pointer_to_screen]
  14.   mov [ecx],eax
  15.   add [output_array],4
  16.   ret
  17. ; procedure <<<<<<PutPixel>>>>>>
  18. ; IN
  19. ; eax - pointer to picture
  20. ; ebx - picture size x
  21. ; ecx - color of pixel
  22. ; esi - x coordinat of pixel
  23. ; edi - y coordinat of pixel
  24. ; OUT
  25. ; not returned value
  26. PutPixel:
  27.  
  28.   imul ebx,edi
  29.   add ebx,esi
  30.   lea ebx,[ebx+ebx*2]
  31.   add eax,ebx
  32.   mov ebx,ecx
  33.   shr ebx,16
  34.   mov [eax],cx
  35.   mov [eax+2],bl
  36.   ret
  37. ; function <<<<<<GetColorOfPixel>>>>>>
  38. ; IN
  39. ; eax - pointer to picture
  40. ; ebx - picture size x
  41. ; esi - x coordinat of pixel
  42. ; edi - y coordinat of pixel
  43. ; OUT
  44. ; eax - color of pixel in coordinats (x,y)
  45. GetColorOfPixel:
  46.  
  47.   cmp esi,ebx
  48.   jb @f
  49.     xor eax,eax
  50.         dec eax
  51.         ret
  52.   @@:
  53.   imul ebx,edi
  54.   add ebx,esi
  55.   lea ebx,[ebx+ebx*2]
  56.   mov eax,[eax+ebx]
  57.   and eax,0xffffff
  58.   ret
  59.  
  60. ;procedure <<<<calculate line>>>>
  61. ; IN
  62. ;eax - pointer to screen
  63. ;ebx - output array
  64. ;ecx - (screen size x)*bytes per pixel
  65. ;edx - x1*65536+y1
  66. ;esi   x2
  67. ;edi - y2
  68. ; OUT
  69. ;eax - number of pixels
  70. calculate_line:
  71.  
  72.   mov [pointer_to_screen],eax
  73.   mov [output_array],ebx
  74.   mov [screen_size_x],ecx
  75.   mov eax,edx
  76.   and eax,0xffff
  77.   shr edx,16
  78.   mov [x_l],edx     ;x=x1
  79.   mov [y_l],eax     ;y=y1
  80.   mov [sx],1
  81.   mov [sy],1
  82.  
  83.   mov edx,[output_array]
  84.  
  85.   sub esi,[x_l]     ;esi=x2-x1
  86.   jnz no_0_x
  87.   and esi,0
  88.   jmp x_no_minus
  89.   no_0_x:
  90.   jns x_no_minus
  91.   neg esi
  92.   mov [sx],-1     ;sx=-sx
  93.   x_no_minus:
  94.  
  95.   sub edi,[y_l]     ;edi=y2-y1
  96.   jnz no_0_y
  97.   and edi,0
  98.   jmp y_no_minus
  99.   no_0_y:
  100.   jns y_no_minus
  101.   neg edi
  102.   mov [sy],-1     ;sy=-sy
  103.   y_no_minus:
  104.  
  105.   mov [_dx],esi
  106.   mov [_dy],edi
  107.  
  108.   cmp [_dx],0      ;if (dx=0 & dy=0) {  }
  109.   jnz no_null_d
  110.   cmp [_dy],0
  111.   jnz no_null_d
  112.   mov eax,[x_l]
  113.   mov ebx,[y_l]
  114.   mov [pixel_x],eax
  115.   mov [pixel_y],ebx
  116.   call setpixel    ;setpixel(x1,y1)
  117.   mov eax,1
  118.   ret
  119.   no_null_d:
  120.  
  121.   cmp edi,esi      ;if (dy>dx) {  }
  122.   jle no_bigger
  123.   mov eax,[_dx]
  124.   mov [z],eax      ;z=dx
  125.   mov eax,[_dy]
  126.   mov [_dx],eax    ;dx=dy
  127.   mov eax,[z]
  128.   mov [_dy],eax    ;dy=z
  129.   mov [_ch],dword 1 ;ch=true
  130.   jmp exit_if2
  131.   no_bigger:       ;else {}
  132.   and [_ch],0
  133.   exit_if2:
  134.  
  135.   mov eax,[_dy]
  136.   shl eax,1
  137.   sub eax,[_dx]
  138.   mov [e],eax    ;e=2*dy-dx
  139.  
  140.   mov esi,1      ;counter
  141.   mov edi,[sx]
  142.   mov ebp,[sy]
  143.   do:
  144.  
  145.      mov eax,[x_l]
  146.      mov ebx,[y_l]
  147.      mov [pixel_x],eax
  148.      mov [pixel_y],ebx
  149.      call setpixel
  150.  
  151.      cmp [e],0
  152.      js while_e
  153.  
  154.        mov eax,[_ch]
  155.        test eax,eax
  156.        jz ch_else
  157.        add [x_l],edi
  158.        jmp exit_if3
  159.        ch_else:
  160.        add [y_l],ebp
  161.        exit_if3:
  162.  
  163.        mov eax,[_dx]
  164.        shl eax,1
  165.        sub [e],eax    ;e=e-2*dx
  166.  
  167.      while_e:
  168.  
  169.      mov eax,[_ch]
  170.      test eax,eax
  171.      jz ch_else2
  172.      add [y_l],ebp
  173.      jmp exit_if4
  174.      ch_else2:
  175.      add [x_l],edi
  176.      exit_if4:
  177.  
  178.      mov eax,[_dy]
  179.      shl eax,1
  180.      add [e],eax ;e=e+2*dy
  181.      inc esi
  182.  
  183.      mov ecx,[_dx]
  184.      cmp esi,ecx
  185.      jle do          ;while (i<=dx)
  186.  
  187.      mov eax,[x_l]
  188.      mov ebx,[y_l]
  189.      mov [pixel_x],eax
  190.      mov [pixel_y],ebx
  191.      call setpixel
  192.  
  193.      mov eax,[output_array]
  194.      sub eax,edx
  195.      shr eax,2
  196.  
  197.   ret
  198. ;---------------------------
  199. ;procedure calculate <<<<<rectangle>>>>>>>
  200. ; IN
  201. ;eax - pointer to screen
  202. ;ebx - output array
  203. ;ecx - (screen size x)
  204. ;edx - x1*65536+y1
  205. ;esi   x2
  206. ;edi - y2
  207. ; OUT
  208. ;eax - number of pixels
  209.  
  210. calculate_rectangle:
  211.  
  212.   mov [pointer_to_screen],eax
  213.   mov [output_array],ebx
  214.   mov [screen_size_x],ecx
  215.   mov eax,edx
  216.   and eax,0xffff
  217.   shr edx,16
  218.   mov [x_l],edx     ;x=x1
  219.   mov [y_l],eax     ;y=y1
  220.   mov [x2],esi      ;x2
  221.   mov [y2],edi      ;y2
  222.   mov [sx],1
  223.   mov [sy],1
  224.  
  225.   mov edx,[output_array]
  226.  
  227.   sub esi,[x_l]     ;esi=x2-x1
  228.   jnz no_0_x_r
  229.   and esi,0
  230.   jmp x_no_minus_r
  231.   no_0_x_r:
  232.   jns x_no_minus_r
  233.   neg esi
  234.   mov [sx],-1     ;sx=-sx
  235.   x_no_minus_r:
  236.  
  237.   sub edi,[y_l]     ;edi=y2-y1
  238.   jnz no_0_y_r
  239.   and edi,0
  240.   jmp y_no_minus_r
  241.   no_0_y_r:
  242.   jns y_no_minus_r
  243.   neg edi
  244.   mov [sy],-1     ;sy=-sy
  245.   y_no_minus_r:
  246.  
  247.   mov [_dx],esi
  248.   mov [_dy],edi
  249.  
  250.   cmp [_dx],0      ;if (dx=0 & dy=0) {  }
  251.   jnz no_null_r
  252.   cmp [_dy],0
  253.   jnz no_null_r
  254.   mov eax,[x_l]
  255.   mov ebx,[y_l]
  256.   mov [pixel_x],eax
  257.   mov [pixel_y],ebx
  258.   call setpixel    ;setpixel(x1,y1)
  259.   mov eax,1
  260.   ret
  261.   no_null_r:
  262.  
  263.   mov edi,[_dx]
  264.   mov esi,[x_l]       ;x1
  265.  
  266.   horizontal_lines:
  267.  
  268.   mov eax,esi         ;x
  269.   mov ebx,[y_l]       ;y1
  270.   mov [pixel_x],eax
  271.   mov [pixel_y],ebx
  272.   call setpixel
  273.  
  274.   mov eax,esi         ;x
  275.   mov ebx,[y2]        ;y2
  276.   mov [pixel_x],eax
  277.   mov [pixel_y],ebx
  278.   call setpixel
  279.  
  280.   add esi,[sx]
  281.   dec edi
  282.   jns horizontal_lines
  283.  
  284.   mov edi,[_dy]
  285.   mov esi,[y_l]       ;y1
  286.   vertical_lines:
  287.  
  288.   mov eax,[x_l]       ;x1
  289.   mov ebx,esi         ;y
  290.   mov [pixel_x],eax
  291.   mov [pixel_y],ebx
  292.   call setpixel
  293.  
  294.   mov eax,[x2]         ;x2
  295.   mov ebx,esi          ;y
  296.   mov [pixel_x],eax
  297.   mov [pixel_y],ebx
  298.   call setpixel
  299.  
  300.   add esi,[sy]
  301.   dec edi
  302.   jns vertical_lines
  303.  
  304.   mov eax,[output_array]
  305.   sub eax,edx
  306.   shr eax,2
  307.  
  308.   ret
  309. ;procedure <<<<<<calculate_circle>>>>>>
  310. ; IN
  311. ;eax - pointer to screen
  312. ;ebx - output array
  313. ;ecx - (screen size x)*bytes per pixel
  314. ;edx - x_c*65536+y_c
  315. ;esi   r
  316. ; OUT
  317. ;eax - number of pixels
  318.  
  319. calculate_circle:
  320.  
  321.   mov [pointer_to_screen],eax
  322.   mov [output_array],ebx
  323.   mov [screen_size_x],ecx
  324.   mov eax,edx
  325.   and eax,0xffff
  326.   shr edx,16
  327.   mov [x2],edx     ;circle centr x
  328.   mov [y2],eax     ;circle centr y
  329.   mov [r],esi      ;radius of cicrle
  330.  
  331.   mov edx,[output_array]
  332.  
  333.   mov [x_l],0      ;x=0
  334.   mov [y_l],esi    ;y=r
  335.   mov [d],3
  336.   mov eax,[r]
  337.   shl eax,1
  338.   sub [d],eax      ;d=3-2*r
  339.  
  340.  
  341.   while_circle:
  342.  
  343.   mov esi,[y_l]
  344.   mov edi,[x_l]
  345.  
  346.   sub esi,edi      ;while y>=x
  347.   js exit_while_circle
  348.  
  349.  
  350.   mov eax,[x_l] ;x
  351.   mov ebx,[y_l] ;y
  352.   add eax,[x2]  ;x+xc
  353.   add ebx,[y2]  ;y+yc
  354.   mov [pixel_x],eax
  355.   mov [pixel_y],ebx
  356.   call setpixel
  357.  
  358.   mov eax,[x_l] ;x
  359.   mov ebx,[y2]  ;yc
  360.   add eax,[x2]  ;x+xc
  361.   sub ebx,[y_l] ;yc-y
  362.   mov [pixel_x],eax
  363.   mov [pixel_y],ebx
  364.   call setpixel
  365.  
  366.   mov eax,[x2]  ;xc
  367.   mov ebx,[y2]  ;yc
  368.   sub eax,[x_l] ;xc-x
  369.   add ebx,[y_l] ;yc+y
  370.   mov [pixel_x],eax
  371.   mov [pixel_y],ebx
  372.   call setpixel
  373.  
  374.   mov eax,[x2]  ;xc
  375.   mov ebx,[y2]  ;yc
  376.   sub eax,[x_l] ;xc-x
  377.   sub ebx,[y_l] ;yc-y
  378.   mov [pixel_x],eax
  379.   mov [pixel_y],ebx
  380.   call setpixel
  381.  
  382.   mov eax,[x2]  ;xc
  383.   mov ebx,[y2]  ;yc
  384.   add eax,[y_l] ;xc+y
  385.   add ebx,[x_l] ;yc+x
  386.   mov [pixel_x],eax
  387.   mov [pixel_y],ebx
  388.   call setpixel
  389.  
  390.   mov eax,[x2]  ;xc
  391.   mov ebx,[y2]  ;yc
  392.   add eax,[y_l] ;xc+y
  393.   sub ebx,[x_l] ;yc-x
  394.   mov [pixel_x],eax
  395.   mov [pixel_y],ebx
  396.   call setpixel
  397.  
  398.   mov eax,[x2]  ;xc
  399.   mov ebx,[y2]  ;yc
  400.   sub eax,[y_l] ;xc-y
  401.   add ebx,[x_l] ;x+yc
  402.   mov [pixel_x],eax
  403.   mov [pixel_y],ebx
  404.   call setpixel
  405.  
  406.   mov eax,[x2]  ;xc
  407.   mov ebx,[y2]  ;yc
  408.   sub eax,[y_l] ;xc-y
  409.   sub ebx,[x_l] ;yc-x
  410.   mov [pixel_x],eax
  411.   mov [pixel_y],ebx
  412.   call setpixel
  413.  
  414.   cmp [d],0
  415.   jns if1_d
  416.   mov eax,[x_l]
  417.   shl eax,2
  418.   add eax,6
  419.   add [d],eax  ;d=d+4*x+6
  420.   jmp exit_if1_d
  421.   if1_d:
  422.   mov eax,[x_l]
  423.   sub eax,[y_l]
  424.   shl eax,2
  425.   add eax,10
  426.   add [d],eax    ;d=d+4*(x-y)+10
  427.   dec [y_l]
  428.   exit_if1_d:
  429.   inc [x_l]
  430.  
  431.   jmp while_circle
  432.  
  433.   exit_while_circle:
  434.  
  435.   mov eax,[output_array]
  436.   sub eax,edx
  437.   shr eax,2
  438.  
  439.   ret
  440. ;procedure <<<<<<flood fill>>>>>
  441. ;IN
  442. ;eax - pointer to screen
  443. ;ebx - pointer to output array
  444. ;ecx - picture size x
  445. ;edx - x0*65536+y0
  446. ;esi - x_max*65536+y_max
  447. ;edi - color of flood fill arrea
  448. flood_fill:
  449.  
  450.   mov [pointer_to_screen],eax
  451.   mov [output_array],ebx
  452.   mov [screen_size_x],ecx
  453.  
  454.   mov eax,edx
  455.   and edx,0xffff
  456.   shr eax,16
  457.   mov [sx],eax   ;x0
  458.   mov [sy],edx   ;y0
  459.  
  460.   mov eax,esi
  461.   and esi,0xffff
  462.   shr eax,16
  463.   mov [m_x],eax  ;maximum x size of picture
  464.   mov [m_y],esi  ;maximum y size of picture
  465.  
  466.   mov [c_f],edi    ;color of feel
  467.  
  468.   mov eax,[output_array] ; stek
  469.   mov [eax],dword 1      ; number of pointes in stek
  470.   mov esi,[sx]
  471.   mov edi,[sy]
  472.   mov [eax+4],si        ;x0
  473.   mov [eax+4+2],di        ;y0
  474.  
  475.   mov eax,[pointer_to_screen]
  476.   mov ebx,[screen_size_x]
  477.   call GetColorOfPixel
  478.   mov [c],eax
  479.  
  480.   cmp eax,[c_f]
  481.   jne can_flood_fill
  482.   mov eax,[output_array]
  483.   mov [eax],dword 0
  484.   ret
  485.   can_flood_fill:
  486.  
  487.   while_no_null:
  488.   ;¨§¢«¥ª ¥¬ ª®®à¤¨­ âë ¨§ á⥪ 
  489.   mov eax,[output_array]
  490.   mov ebx,[eax]
  491.   dec ebx
  492.   shl ebx,2               ;ebx=ebx*8
  493.   add ebx,4               ;ebx=ebx*8+4
  494.   xor esi,esi
  495.   xor edi,edi
  496.   mov si,[eax+ebx]       ;x
  497.   mov di,[eax+ebx+2]     ;y
  498.   mov [x2],esi
  499.   mov [y2],edi
  500.  
  501.   mov [sy],edi
  502.  
  503.   mov eax,[output_array]
  504.   mov ebx,[eax]
  505.   dec ebx
  506.   mov [eax],ebx           ;
  507.  
  508.   ; go to right until color=c or until x<MaxXPicture
  509.   mov edx,[x2]
  510.   go_to_right:
  511.  
  512.   mov eax,[pointer_to_screen]
  513.   mov ebx,[screen_size_x]
  514.   mov esi,edx;
  515.   mov edi,[sy]
  516.   call GetColorOfPixel
  517.  
  518.   cmp eax,[c]
  519.   jne not_color_of_feeling_arrea_right
  520.  
  521.   mov eax,[pointer_to_screen]
  522.   mov ebx,[screen_size_x]
  523.   mov ecx,[c_f]    ;color of filinf flood
  524.   mov esi,edx
  525.   mov edi,[sy]
  526.   call PutPixel
  527.  
  528.   inc edx
  529.  
  530.   mov eax,edx
  531.   cmp eax,[m_x]
  532.   jle go_to_right
  533.  
  534.   not_color_of_feeling_arrea_right:
  535.  
  536.   mov eax,edx
  537.   dec eax                ;----------------------------------
  538.   mov [x_r],eax      ; save right absciss
  539.  
  540.  
  541.   ; go to left until color=c or until x>0
  542.   mov esi,[x2]
  543.   mov edi,[y2]
  544.   dec esi
  545.   mov edx,esi
  546.   mov [sy],edi
  547.  
  548.   go_to_left:
  549.  
  550.   mov eax,[pointer_to_screen]
  551.   mov ebx,[screen_size_x]
  552.   mov esi,edx
  553.   mov edi,[sy]
  554.   call GetColorOfPixel
  555.  
  556.   cmp eax,[c]
  557.   jne not_color_of_feeling_arrea_left
  558.  
  559.   mov eax,[pointer_to_screen]
  560.   mov ebx,[screen_size_x]
  561.   mov ecx,[c_f]    ;color of filing flood
  562.   mov esi,edx
  563.   mov edi,[sy]
  564.   call PutPixel
  565.  
  566.   dec edx
  567.   jns go_to_left
  568.  
  569.   not_color_of_feeling_arrea_left:
  570.  
  571.   mov eax,edx
  572.   inc eax           ;----------------------------------------
  573.   mov [x_l],eax      ; save left absciss
  574.  
  575.   mov edi,[y2]
  576.   dec edi
  577.   jns no_null_1_floodfill
  578.   mov edi,1
  579.   no_null_1_floodfill:
  580.   mov [sy],edi
  581.  
  582.   mov eax,[output_array]
  583.   mov ebx,[eax]
  584.   mov [l_s],ebx         ; save total number of points in stek
  585.   mov [l_c],-1          ; last color = -1
  586.   mov edx,[x_l]
  587.   analizing_from_left_to_right_upper:
  588.   ; ­ «¨§¨à㥬 ¯¨ªá¥«¨ ­ ¤ «¨­¨¥© á «¥¢®£® ªà ï
  589.   mov eax,[pointer_to_screen]
  590.   mov ebx,[screen_size_x]
  591.   mov esi,edx
  592.   mov edi,[sy]
  593.   call GetColorOfPixel
  594.   push eax
  595.  
  596.   cmp eax,[c]    ;¥á«¨ 梥⠯஢¥àאַ£® ¯¨ªá¥«ï ­¥ à ¢¥­ á, â® ­¥ § ­®á¨¬ ¥£® ¢ á⥪
  597.   jne no_fill_1
  598.   mov ebx,[l_c]
  599.   cmp ebx,[c]
  600.   jne no_fill_1
  601.   mov edi,[sy]
  602.   mov eax,[output_array]
  603.   mov ebx,[eax]
  604.   inc ebx
  605.   mov [eax],ebx
  606.   dec ebx
  607.   shl ebx,2
  608.   add ebx,4
  609.   mov esi,edx
  610.   dec esi
  611.   mov [eax+ebx],si
  612.   mov [eax+ebx+2],di
  613.   no_fill_1:
  614.  
  615.   pop [l_c]
  616.   inc edx
  617.   cmp edx,[x_r]
  618.   jle analizing_from_left_to_right_upper
  619.  
  620.   mov ebx,[l_c]
  621.   cmp ebx,[c]       ;last color is c(color of filing arrea) ?
  622.   jne have_changes_in_stek_1
  623.   ;save last color in stek
  624.   mov edi,[sy]
  625.   mov eax,[output_array]
  626.   mov ebx,[eax]
  627.   inc ebx
  628.   mov [eax],ebx
  629.   dec ebx
  630.   shl ebx,2
  631.   add ebx,4
  632.   mov esi,edx
  633.   dec esi
  634.   mov [eax+ebx],si
  635.   mov [eax+ebx+2],di
  636.  
  637.   have_changes_in_stek_1:
  638.  
  639.   mov edi,[y2]
  640.   inc edi
  641.   cmp edi,[m_y]
  642.   jle no_max_1_floodfill
  643.   mov edi,[m_y]
  644.   no_max_1_floodfill:
  645.   mov [sy],edi
  646.  
  647.   mov eax,[output_array]
  648.   mov ebx,[eax]
  649.   mov [l_s],ebx         ; save total number of points in stek
  650.   mov [l_c],-1          ; last color = -1
  651.   mov edx,[x_l]
  652.   analizing_from_left_to_right_down:
  653.  
  654.   ; ­ «¨§¨à㥬 ¯¨ªá¥«¨ ¯®¤ «¨­¨¥© á «¥¢®£® ªà ï
  655.   mov eax,[pointer_to_screen]
  656.   mov ebx,[screen_size_x]
  657.   mov esi,edx
  658.   mov edi,[sy]
  659.   call GetColorOfPixel
  660.   push eax
  661.  
  662.   cmp eax,[c]    ;¥á«¨ 梥⠯஢¥àאַ£® ¯¨ªá¥«ï ­¥ à ¢¥­ á, â® ­¥ § ­®á¨¬ ¥£® ¢ á⥪
  663.   je no_fill_3
  664.   mov ebx,[l_c]
  665.   cmp ebx,[c]
  666.   jne no_fill_3
  667.   mov edi,[sy]
  668.   mov eax,[output_array]
  669.   mov ebx,[eax]
  670.   inc ebx
  671.   mov [eax],ebx
  672.   dec ebx
  673.   shl ebx,2
  674.   add ebx,4
  675.   mov esi,edx
  676.   dec esi
  677.   mov [eax+ebx],si
  678.   mov [eax+ebx+2],di
  679.   no_fill_3:
  680.  
  681.   pop [l_c]
  682.   inc edx
  683.   cmp edx,[x_r]
  684.   jle analizing_from_left_to_right_down
  685.  
  686.   mov ebx,[l_c]
  687.   cmp ebx,[c]       ;last color is c(color of filing arrea) ?
  688.   jne have_changes_in_stek_2
  689.   ;save last color in stek
  690.   mov edi,[sy]
  691.   mov eax,[output_array]
  692.   mov ebx,[eax]
  693.   inc ebx
  694.   mov [eax],ebx
  695.   dec ebx
  696.   shl ebx,2
  697.   add ebx,4
  698.   mov esi,edx
  699.   dec esi
  700.   mov [eax+ebx],si
  701.   mov [eax+ebx+2],di
  702.  
  703.   have_changes_in_stek_2:
  704.  
  705.   mov ebx,[output_array] ;while stek have points  Â¯Â®ÂªÂ  ¢ á⥪¥ ¥áâì â®çª¨(ª®®à¤¨­ âë)
  706.   mov ecx,[ebx]
  707.   test ecx,ecx
  708.   jnz while_no_null
  709.  
  710.  
  711.   ret
  712. ; procedure <<<<<<calculate ellips>>>>>>
  713. ; IN
  714. ; eax - pointer to picture
  715. ; ebx - output array
  716. ; ecx - picture size x
  717. ; edx - x0*65536+y0
  718. ; esi - a*65536+b
  719. ; edi - color
  720. ; OUT
  721. ; procedure not return value
  722. calculate_ellips:
  723.  
  724.   mov [pointer_to_screen],eax
  725.   mov [output_array],ebx
  726.   mov [screen_size_x],ecx
  727.   mov [e],ebx
  728.  
  729.   mov eax,edx
  730.   and eax,0xffff
  731.   shr edx,16
  732.   mov [x2],edx     ; centr x
  733.   mov [y2],eax     ; centr y
  734.  
  735.   mov eax,esi
  736.   and eax,0xffff   ;eax=b
  737.   shr esi,16       ;esi=a
  738.   mov [a],esi
  739.   mov [b],eax
  740.  
  741.   mov [c],edi      ;color
  742.   mov [row],eax ;b
  743.  
  744.   imul esi,esi ;a*a
  745.   imul eax,eax ;b*b
  746.  
  747.   mov [a_square],esi
  748.   mov [b_square],eax
  749.   and [col],0
  750.  
  751.   shl esi,1
  752.   shl eax,1
  753.   mov [two_a_square],esi
  754.   mov [two_b_square],eax
  755.   shl esi,1
  756.   shl eax,1
  757.   mov [four_a_square],esi
  758.   mov [four_b_square],eax
  759.  
  760.   mov eax,[row]              ;eax=row
  761.   mov ebx,eax
  762.   dec ebx                    ;ebx=(row-1)
  763.   imul ebx,eax               ;ebx=(row-1)*row
  764.   imul ebx,[two_a_square]    ;ebx=two_a_square*((row-1)*row)
  765.   mov ecx,[a_square]         ;ecx=a_square
  766.   mov eax,1
  767.   sub eax,ecx                ;eax=(1-a_square)
  768.   imul eax,[two_b_square]    ;eax=two_b_square*(1-a_square)
  769.   add ebx,[a_square]         ;ebx=two_a_square*((row-1)*row)+a_square
  770.   add eax,ebx                ;eax=two_a_square*((row-1)*row)+a_square+two_b_square*(1-a_square)
  771.   mov [d],eax
  772.  
  773.   mov edx,[x2]               ;x
  774.   mov ebp,[y2]               ;y
  775.  
  776.   while_ellips_1:
  777.   mov esi,[a_square]
  778.   mov edi,[b_square]
  779.   imul esi,[row]
  780.   imul edi,[col]
  781.   cmp esi,edi
  782.   jle no_while_ellips_1
  783.  
  784.   mov eax,edx        ;x
  785.   mov ebx,ebp        ;y
  786.   add eax,[col]      ;x+col
  787.   add ebx,[row]      ;y+row
  788.   mov [pixel_x],eax
  789.   mov [pixel_y],ebx
  790.   call setpixel
  791.  
  792.   mov eax,edx        ;x
  793.   mov ebx,ebp        ;y
  794.   add eax,[col]      ;x+col
  795.   sub ebx,[row]      ;y-row
  796.   mov [pixel_x],eax
  797.   mov [pixel_y],ebx
  798.   call setpixel
  799.  
  800.   mov eax,edx        ;x
  801.   mov ebx,ebp        ;y
  802.   sub eax,[col]      ;x-col
  803.   add ebx,[row]      ;y+row
  804.   mov [pixel_x],eax
  805.   mov [pixel_y],ebx
  806.   call setpixel
  807.  
  808.   mov eax,edx        ;x
  809.   mov ebx,ebp        ;y
  810.   sub eax,[col]      ;x-col
  811.   sub ebx,[row]      ;y-row
  812.   mov [pixel_x],eax
  813.   mov [pixel_y],ebx
  814.   call setpixel
  815.  
  816.   mov eax,[d]
  817.   cmp eax,0
  818.   js  lab33              ;>=0
  819.   dec [row]
  820.   mov ebx,[four_a_square]
  821.   mov ecx,[row]
  822.   imul ebx,ecx          ;ebx=four_a_square*(row)
  823.   sub [d],ebx           ;d=d-four_a_square*(row)
  824.   lab33:
  825.  
  826.   mov eax,[col]
  827.   shl eax,1
  828.   add eax,3
  829.   imul eax,[two_b_square]
  830.   add [d],eax           ;d=d+two_b_square*(3+(col*2))
  831.  
  832.   inc [col]
  833.   jmp while_ellips_1
  834.  
  835.   no_while_ellips_1:
  836.  
  837.   mov eax,[col]
  838.   inc eax
  839.   imul eax,[col]
  840.   imul eax,[two_b_square] ;eax=two_b_square*((col+1)*col)
  841.   mov ebx,[row]
  842.   sub ebx,2
  843.   imul ebx,[row]
  844.   inc ebx
  845.   imul ebx,[two_a_square] ;ebx=two_a_square*((row-2)*row+1)
  846.   mov ecx,1
  847.   sub ecx,[two_a_square]
  848.   imul ecx,[b_square]     ;ecx=(1-two_a_square)*b_square
  849.   add eax,ebx
  850.   add eax,ecx
  851.   mov [d],eax             ;two_b_square*(col+1)*col+two_a_square*(row*(row-2)+1)+(1-two_a_square)*b_square
  852.  
  853.   mov edx,[x2]               ;x
  854.   mov ebp,[y2]               ;y
  855.  
  856.   while_ellips_2:
  857.   mov esi,[row]
  858.   inc esi
  859.   test esi,esi
  860.   jz no_while_ellips_2
  861.  
  862.   mov eax,edx        ;x
  863.   mov ebx,ebp        ;y
  864.   add eax,[col]      ;x+col
  865.   add ebx,[row]      ;y+row
  866.   mov [pixel_x],eax
  867.   mov [pixel_y],ebx
  868.   call setpixel
  869.  
  870.   mov eax,edx        ;x
  871.   mov ebx,ebp        ;y
  872.   add eax,[col]      ;x+col
  873.   sub ebx,[row]      ;y-row
  874.   mov [pixel_x],eax
  875.   mov [pixel_y],ebx
  876.   call setpixel
  877.  
  878.   mov eax,edx        ;x
  879.   mov ebx,ebp        ;y
  880.   sub eax,[col]      ;x-col
  881.   add ebx,[row]      ;y+row
  882.   mov [pixel_x],eax
  883.   mov [pixel_y],ebx
  884.   call setpixel
  885.  
  886.   mov eax,edx        ;x
  887.   mov ebx,ebp        ;y
  888.   sub eax,[col]      ;x-col
  889.   sub ebx,[row]      ;y-row
  890.   mov [pixel_x],eax
  891.   mov [pixel_y],ebx
  892.   call setpixel
  893.  
  894.   mov eax,[d]
  895.   cmp eax,0
  896.   jns lab34
  897.  
  898.   inc [col]
  899.   mov ebx,[col]
  900.   imul ebx,[four_b_square]
  901.   add [d],ebx            ;d=d+four_b_square*col
  902.   lab34:
  903.   dec [row]
  904.   mov ebx,[row]
  905.   shl ebx,1
  906.   mov eax,3
  907.   sub eax,ebx
  908.   imul eax,[two_a_square]
  909.   add [d],eax           ;d=d+two_b_square*(3-(row*2))
  910.  
  911.   jmp while_ellips_2
  912.   no_while_ellips_2:
  913.  
  914.   mov eax,[output_array]
  915.   sub eax,[e]
  916.   shr eax,2
  917.  
  918.   ret
  919. ;---------------------------
  920.   x_l dd ?
  921.   y_l dd ?
  922.   x_r dd ?
  923.   y_r dd ?
  924.   _dx dd ?
  925.   _dy dd ?
  926.   sx  dd ?
  927.   sy  dd ?
  928.   z   dd ?
  929.   e   dd ?
  930.   i   dd ?
  931.   _ch dd ?
  932.   x2  dd ?
  933.   y2  dd ?
  934.   d   dd ?
  935.   r   dd ?
  936.   m_x dd ?
  937.   m_y dd ?
  938.   c   dd ?
  939.   c_f dd ?
  940.   l_c dd ?
  941.   l_s dd ?
  942. ;---------------------------
  943. pointer_to_screen      dd 0
  944. screen_size_x          dd 0
  945. output_array           dd 0
  946. pixel_x                dd 0
  947. pixel_y                dd 0
  948. ;---------------------------
  949. a                      dd 0
  950. b                      dd 0
  951. col                    dd 0
  952. row                    dd 0
  953. bnew                   dd 0
  954. a_square               dd 0
  955. b_square               dd 0
  956. two_a_square           dd 0
  957. two_b_square           dd 0
  958. four_a_square          dd 0
  959. four_b_square          dd 0
  960. ;-----------------------------