Subversion Repositories Kolibri OS

Rev

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

  1. ;-----------------------------------------------------------------------------
  2. func check_cur_vis_inv ;//////////////////////////////////////////////////////
  3. ;-----------------------------------------------------------------------------
  4.         push    eax ebx
  5.         xor     bl,bl
  6.   .chk_y:
  7.         mov     eax,[cur_editor.Caret.Y] ;! eax,[pos.y]
  8.         or      eax,eax
  9.         jge     @f
  10.         mov     [cur_editor.Caret.Y],0 ;! [pos.y],0
  11.         jmp     .chk_dy
  12.     @@: cmp     eax,[cur_editor.Lines.Count] ;! eax,[lines]
  13.         jl      .chk_dy
  14.         mov     eax,[cur_editor.Lines.Count] ;! eax,[lines]
  15.         dec     eax
  16.         mov     [cur_editor.Caret.Y],eax ;! [pos.y],eax
  17.   .chk_dy:
  18.         mov     eax,[cur_editor.TopLeft.Y] ;! eax,[top_line]
  19.         cmp     eax,[cur_editor.Caret.Y] ;! eax,[pos.y]
  20.         jle     @f
  21.         m2m     [cur_editor.TopLeft.Y],[cur_editor.Caret.Y]
  22. ;!      push    [pos.y]
  23. ;!      pop     [top_line]
  24.         inc     bl
  25.     @@: add     eax,[lines.scr]
  26.         cmp     eax,[cur_editor.Caret.Y] ;! eax,[pos.y]
  27.         jg      .chk_x
  28.         mov     eax,[cur_editor.Caret.Y] ;! eax,[pos.y]
  29.         sub     eax,[lines.scr]
  30.         inc     eax
  31.         mov     [cur_editor.TopLeft.Y],eax ;! [top_line],eax
  32.         inc     bl
  33.   .chk_x:
  34.         mov     eax,[cur_editor.Caret.X] ;! eax,[pos.x]
  35.         or      eax,eax
  36.         jge     @f
  37.         mov     [cur_editor.Caret.X],0 ;! [pos.x],0
  38.         jmp     .chk_dx
  39.     @@: cmp     eax,[cur_editor.Columns.Count] ;! eax,[columns]
  40.         jl      .chk_dx
  41.         mov     eax,[cur_editor.Columns.Count] ;! eax,[columns]
  42.         mov     [cur_editor.Caret.X],eax ;! [pos.x],eax
  43.   .chk_dx:
  44.         mov     eax,[cur_editor.TopLeft.X] ;! eax,[left_col]
  45.         cmp     eax,[cur_editor.Caret.X] ;! eax,[pos.x]
  46.         jle     @f
  47.         m2m     [cur_editor.TopLeft.X],[cur_editor.Caret.X]
  48. ;!      push    [pos.x]
  49. ;!      pop     [left_col]
  50.         inc     bl
  51.     @@: add     eax,[columns.scr]
  52.         cmp     eax,[cur_editor.Caret.X] ;! eax,[pos.x]
  53.         jg      @f
  54.         mov     eax,[cur_editor.Caret.X] ;! eax,[pos.x]
  55.         sub     eax,[columns.scr]
  56.         inc     eax
  57.         mov     [cur_editor.TopLeft.X],eax ;! [left_col],eax
  58.         inc     bl
  59.     @@: cmp     [mev],MEV_LDOWN
  60.         jne     .exit
  61.         push    [cur_editor.Caret.X] [cur_editor.Caret.Y] ;! [pos.x] [pos.y]
  62.         pop     [cur_editor.SelStart.Y] [cur_editor.SelStart.X] ;! [sel.y] [sel.x]
  63.   .exit:
  64.         or      bl,bl
  65.         clc
  66.         jz      @f
  67.         call    draw_file
  68.         stc
  69.     @@: pop     ebx eax
  70.         ret
  71. endf
  72.  
  73. ;-----------------------------------------------------------------------------
  74. func clear_selection ;////////////////////////////////////////////////////////
  75. ;-----------------------------------------------------------------------------
  76.         push    eax ebx
  77.         mov     eax,[cur_editor.SelStart.Y] ;! eax,[sel.y]
  78.         mov     ebx,[cur_editor.Caret.Y] ;! ebx,[pos.y]
  79.         cmp     eax,ebx
  80.         jle     @f
  81.         xchg    eax,ebx
  82.     @@: push    [cur_editor.Caret.X] [cur_editor.Caret.Y] ;! [pos.x] [pos.y]
  83.         pop     [cur_editor.SelStart.Y] [cur_editor.SelStart.X] ;! [sel.y] [sel.x]
  84.         call    draw_file.ex
  85.         pop     ebx eax
  86.         ret
  87. endf
  88.  
  89. ;-----------------------------------------------------------------------------
  90. func pt_in_rect ;/////////////////////////////////////////////////////////////
  91. ;-----------------------------------------------------------------------------
  92.         cmp     eax,[ecx+0x0]
  93.         jl      @f
  94.         cmp     ebx,[ecx+0x4]
  95.         jl      @f
  96.         cmp     eax,[ecx+0x8]
  97.         jg      @f
  98.         cmp     ebx,[ecx+0xC]
  99.         jg      @f
  100.         stc
  101.         ret
  102.     @@: clc
  103.         ret
  104. endf
  105.  
  106. ;-----------------------------------------------------------------------------
  107. func check_bottom_right ;/////////////////////////////////////////////////////
  108. ;-----------------------------------------------------------------------------
  109.         push    eax
  110.         mov     eax,[cur_editor.TopLeft.Y] ;! eax,[top_line]
  111.         add     eax,[lines.scr]
  112.         cmp     eax,[cur_editor.Lines.Count] ;! eax,[lines]
  113.         jbe     .lp1
  114.         mov     eax,[cur_editor.Lines.Count] ;! eax,[lines]
  115.         sub     eax,[lines.scr]
  116.         jns     @f
  117.         xor     eax,eax
  118.     @@: mov     [cur_editor.TopLeft.Y],eax ;! [top_line],eax
  119.   .lp1: mov     eax,[cur_editor.TopLeft.X] ;! eax,[left_col]
  120.         add     eax,[columns.scr]
  121.         cmp     eax,[cur_editor.Columns.Count] ;! eax,[columns]
  122.         jbe     .exit
  123.         mov     eax,[cur_editor.Columns.Count] ;! eax,[columns]
  124.         sub     eax,[columns.scr]
  125.         jns     @f
  126.         xor     eax,eax
  127.     @@: mov     [cur_editor.TopLeft.X],eax ;! [left_col],eax
  128.   .exit:
  129.         pop     eax
  130.         ret
  131. endf
  132.  
  133. ;-----------------------------------------------------------------------------
  134. func check_inv_str ;//////////////////////////////////////////////////////////
  135. ;-----------------------------------------------------------------------------
  136. @^
  137.         mov     eax,[pos.y]
  138.         mov     ecx,[top_line]
  139.   .skip_init:
  140.         call    check_cur_vis
  141.         mov     [pos.y],eax
  142.         mov     [top_line],ecx
  143.   .skip_check:
  144. ;       call    invalidate_string
  145.         call    drawfile
  146.         ret
  147. ^@
  148. endf
  149.  
  150. ;-----------------------------------------------------------------------------
  151. func check_inv_all ;//////////////////////////////////////////////////////////
  152. ;-----------------------------------------------------------------------------
  153.         mov     eax,[cur_editor.Caret.Y] ;! eax,[pos.y]
  154.         mov     ecx,[cur_editor.TopLeft.Y] ;! ecx,[top_line]
  155.   .skip_init:
  156.         call    check_cur_vis
  157.         mov     [cur_editor.Caret.Y],eax ;! [pos.y],eax
  158.         mov     [cur_editor.TopLeft.Y],ecx ;! [top_line],ecx
  159.   .skip_check:
  160. ;       call    clear_screen
  161.         call    draw_file
  162.         ret
  163. endf
  164.  
  165. ;-----------------------------------------------------------------------------
  166. func check_cur_vis ;//////////////////////////////////////////////////////////
  167. ;-----------------------------------------------------------------------------
  168.         cmp     eax,ecx
  169.         jb      .low
  170.         mov     edx,ecx
  171.         add     edx,[lines.scr]
  172.         cmp     edx,[cur_editor.Lines.Count] ;! edx,[lines]
  173.         jbe     @f
  174.         mov     edx,[cur_editor.Lines.Count] ;! edx,[lines]
  175.     @@: cmp     eax,edx
  176.         jb      @f
  177.         lea     ecx,[eax+1]
  178.         sub     ecx,[lines.scr]
  179.         jns     @f
  180.         xor     ecx,ecx
  181.         jmp     @f
  182.   .low: mov     ecx,eax
  183.     @@: mov     edx,ecx
  184.         add     edx,[lines.scr]
  185.         cmp     edx,[cur_editor.Lines.Count] ;! edx,[lines]
  186.         jbe     @f
  187.         mov     ecx,[cur_editor.Lines.Count] ;! ecx,[lines]
  188.         sub     ecx,[lines.scr]
  189.         jns     @f
  190.         xor     ecx,ecx
  191.     @@:;mov     [top_line],ecx
  192.  
  193.         pushad
  194.         mov     eax,[cur_editor.Caret.X] ;! eax,[pos.x]
  195.         mov     ebx,[cur_editor.TopLeft.X] ;! ebx,[left_col]
  196.         mov     ecx,ebx
  197.         add     ecx,[columns.scr]
  198.         cmp     eax,ebx
  199.         jb      .lp1
  200.         cmp     eax,ecx
  201.         jb      .exit
  202.         lea     ebx,[eax]
  203.         sub     ebx,[columns.scr]
  204.         jmp     @f
  205.   .lp1: mov     ebx,eax
  206.     @@: mov     [cur_editor.TopLeft.X],ebx ;! [left_col],ebx
  207.  
  208.   .exit:
  209.         mov     [cur_editor.Caret.X],eax ;! [pos.x],eax
  210.         popad
  211.  
  212.         ret
  213. endf
  214.  
  215. ;-----------------------------------------------------------------------------
  216. func get_real_length ;////////////////////////////////////////////////////////
  217. ;-----------------------------------------------------------------------------
  218.         movzx   eax,word[esi]
  219.     @@: cmp     byte[esi+eax+4-1],' '
  220.         jne     @f
  221.         dec     eax
  222.         jnz     @b
  223.     @@: ret
  224. endf
  225.  
  226. ;-----------------------------------------------------------------------------
  227. func get_line_offset ;////////////////////////////////////////////////////////
  228. ;-----------------------------------------------------------------------------
  229. ; Input:
  230. ;  ECX = line number
  231. ; Output:
  232. ;  ESI = line data offset
  233. ;-----------------------------------------------------------------------------
  234.         push    eax ecx
  235.         mov     esi,[cur_editor.Lines] ;! AREA_EDIT
  236.     @@: dec     ecx
  237.         js      .exit
  238.         movzx   eax,word[esi]
  239.         lea     esi,[esi+eax+4]
  240.         jmp     @b
  241.   .exit:
  242.         pop     ecx eax
  243.         ret
  244. endf
  245.  
  246. ;-----------------------------------------------------------------------------
  247. func init_sel_vars ;//////////////////////////////////////////////////////////
  248. ;-----------------------------------------------------------------------------
  249.         pushad
  250.         mov     [sel.selected],1
  251.         mov     eax,[cur_editor.SelStart.X] ;! eax,[sel.x]
  252.         mov     ebx,[cur_editor.SelStart.Y] ;! ebx,[sel.y]
  253.         mov     ecx,[cur_editor.Caret.X] ;! ecx,[pos.x]
  254.         mov     edx,[cur_editor.Caret.Y] ;! edx,[pos.y]
  255.         cmp     ebx,edx
  256.         jl      .lp2
  257.         jne     @f
  258.         cmp     eax,ecx
  259.         jl      .lp2
  260.         jne     .lp1
  261.         dec     [sel.selected]
  262.         jmp     .lp2
  263.     @@: xchg    ebx,edx
  264.   .lp1: xchg    eax,ecx
  265.   .lp2: mov     [sel.begin.x],eax
  266.         mov     [sel.begin.y],ebx
  267.         mov     [sel.end.x],ecx
  268.         mov     [sel.end.y],edx
  269.         popad
  270.         ret
  271. endf
  272.  
  273. ;-----------------------------------------------------------------------------
  274. func get_scroll_vars ;////////////////////////////////////////////////////////
  275. ;-----------------------------------------------------------------------------
  276. ; Input:
  277. ;  EAX = maximum data size      (units)
  278. ;  EBX = visible data size      (units)
  279. ;  ECX = current data position  (units)
  280. ;  EDX = scrolling area size    (pixels)
  281. ; Output:
  282. ;  EAX = srcoller offset        (pixels)
  283. ;  EBX = scroller size          (pixels)
  284. ;-----------------------------------------------------------------------------
  285.         push    eax ebx edx
  286. ;       sub     eax,ebx
  287.         mov     esi,eax
  288.         mov     eax,edx
  289.         imul    ebx
  290.         idiv    esi
  291.         cmp     eax,[esp]
  292.         jge     .null
  293.         cmp     eax,AMINS
  294.         jge     @f
  295.         neg     eax
  296.         add     eax,AMINS
  297.         sub     [esp],eax
  298.         mov     eax,AMINS
  299.     @@: mov     [esp+4],eax     ; scroller size
  300.         mov     eax,[esp]
  301.         imul    ecx
  302.         idiv    esi
  303.         or      eax,eax
  304.         jns     @f
  305.         xor     eax,eax
  306.    @@:  mov     [esp+8],eax    ; scroller offset
  307.         add     eax,[esp+4]
  308.         cmp     eax,[esp]
  309.         jle     @f
  310. ;        mov     eax,[esp]
  311. ;        sub     eax,[esp+4]
  312. ;        js      @f
  313. ;        mov     [esp+8],eax
  314.     @@:
  315.         pop     edx ebx eax
  316.         ret
  317.   .null:
  318.         mov     dword[esp+4],0
  319.         mov     dword[esp+8],0
  320.         jmp     @b
  321. endf
  322.  
  323. ;-----------------------------------------------------------------------------
  324. func uint2strz ;//////////////////////////////////////////////////////////////
  325. ;-----------------------------------------------------------------------------
  326.         dec     ebx
  327.         jz      @f
  328.         xor     edx,edx
  329.         div     ecx
  330.         push    edx
  331.         call    uint2strz
  332.         pop     eax
  333.     @@: cmp     al,10
  334.         sbb     al,$69
  335.         das
  336.         stosb
  337.         ret
  338. endf
  339.  
  340. ;-----------------------------------------------------------------------------
  341. func uint2str ;///////////////////////////////////////////////////////////////
  342. ;-----------------------------------------------------------------------------
  343.         cmp     eax,ecx
  344.         jb      @f
  345.         xor     edx,edx
  346.         div     ecx
  347.         push    edx
  348.         call    uint2str
  349.         pop     eax
  350.     @@: cmp     al,10
  351.         sbb     al,$69
  352.         das
  353.         stosb
  354.         ret
  355. endf
  356.  
  357. ;-----------------------------------------------------------------------------
  358. func strlen ;/////////////////////////////////////////////////////////////////
  359. ;-----------------------------------------------------------------------------
  360.         push    ebx
  361.         mov     ebx,eax
  362.         xor     eax,eax
  363.     @@: cmp     byte[ebx+eax],0
  364.         je      @f
  365.         inc     eax
  366.         jmp     @b
  367.     @@: pop     ebx
  368.         ret
  369. endf
  370.  
  371. ;-----------------------------------------------------------------------------
  372. func rgb_to_gray ;////////////////////////////////////////////////////////////
  373. ;-----------------------------------------------------------------------------
  374.         push    0 eax
  375.         and     dword[esp],0x000000FF
  376.         fild    dword[esp]
  377.         fmul    [float_gray_b]
  378.         shr     eax,8
  379.         mov     [esp],eax
  380.         and     dword[esp],0x000000FF
  381.         fild    dword[esp]
  382.         fmul    [float_gray_g]
  383.         faddp
  384.         shr     eax,8
  385.         and     eax,0x000000FF
  386.         mov     [esp],eax
  387.         fild    dword[esp]
  388.         fmul    [float_gray_r]
  389.         faddp
  390.         frndint
  391.         fist    dword[esp]
  392.         fist    dword[esp+1]
  393.         fistp   dword[esp+2]
  394.         pop     eax
  395.         add     esp,4
  396.         ret
  397. endf
  398.  
  399. ;float_gray_r dd 0.30f
  400. ;float_gray_g dd 0.59f
  401. ;float_gray_b dd 0.11f
  402.  
  403. ;-----------------------------------------------------------------------------
  404. func get_active_menu_item ;///////////////////////////////////////////////////
  405. ;-----------------------------------------------------------------------------
  406.         pushad
  407.         mov     [mi_cur],0
  408.         mcall   37,1
  409.         movsx   ebx,ax
  410.         sar     eax,16
  411.         mov     ecx,__rc
  412.         pushd   2 0 (main_menu.width+7) (ATOPH-2)
  413.         popd    [__rc+0xC] [__rc+0x8] [__rc+0x4] [__rc+0x0]
  414. ;       add     [__rc+0xC],ATOPH-2
  415.         call    pt_in_rect
  416.         jnc     .outside_menu
  417.         m2m     dword[ecx+0x8],dword[ecx+0x0]
  418.         mov     edx,main_menu
  419.     @@: inc     [mi_cur]
  420.         movzx   esi,word[edx+0]
  421.         add     [ecx+0x8],esi
  422.         call    pt_in_rect
  423.         jc      .exit
  424.         m2m     dword[ecx+0x0],dword[ecx+0x8]
  425.         add     edx,8+1
  426.         movzx   esi,byte[edx-1]
  427.         add     edx,esi
  428.         cmp     byte[edx+8],0
  429.         jne     @b
  430.         mov     [mi_cur],0
  431.   .exit:
  432.         popad
  433.         ret
  434.   .outside_menu:
  435.         or      [mi_cur],-1
  436.     @@: popad
  437.         ret
  438. endf
  439.  
  440. ;-----------------------------------------------------------------------------
  441. func get_active_popup_item ;//////////////////////////////////////////////////
  442. ;-----------------------------------------------------------------------------
  443.         pushad
  444.         mov     [pi_cur],0
  445.         mcall   37,1
  446.         movsx   ebx,ax
  447.         sar     eax,16
  448.         mov     ecx,__rc
  449.         mov     dword[ecx+0x0],0
  450.         mov     dword[ecx+0x4],0
  451.         movzx   edx,[ebp+POPUP.width]
  452.         mov     dword[ecx+0x8],edx;POP_WIDTH
  453.         movzx   edx,[ebp+POPUP.height]
  454.         mov     dword[ecx+0xC],edx;POP_HEIGHT
  455.         call    pt_in_rect
  456.         jnc     .outside_window
  457.         inc     dword[ecx+0x0]
  458.         mov     dword[ecx+0x4],3
  459.         dec     dword[ecx+0x8]
  460.         mov     dword[ecx+0xC],3+POP_IHEIGHT-1
  461.         mov     edx,[ebp+POPUP.data];popup_text.data
  462.     @@: inc     [pi_cur]
  463.         inc     edx
  464.         movzx   esi,byte[edx-1]
  465.         cmp     byte[edx],'-'
  466.         jne     .lp1
  467.         pushd   [ecx+0xC]
  468.         sub     dword[ecx+0xC],POP_IHEIGHT-4
  469.         call    pt_in_rect
  470.         popd    [ecx+0xC]
  471.         jc      .separator
  472.         add     dword[ecx+0x4],4
  473.         add     dword[ecx+0xC],4
  474.         jmp     .lp3
  475.   .lp1: call    pt_in_rect
  476.         jnc     .lp2
  477.         mov     eax,[pi_cur]
  478.         test    byte[ebp+eax-1],1;byte[popup_text+eax-1],1
  479.         jnz     .exit
  480.         jmp     .separator
  481.   .lp2: add     dword[ecx+0x4],POP_IHEIGHT
  482.         add     dword[ecx+0xC],POP_IHEIGHT
  483.         add     edx,esi
  484.         inc     edx
  485.         movzx   esi,byte[edx-1]
  486.   .lp3: add     edx,esi
  487.         cmp     byte[edx],0
  488.         jne     @b
  489.   .separator:
  490.         mov     [pi_cur],0
  491.   .exit:
  492.         popad
  493.         ret
  494.   .outside_window:
  495.         or      [pi_cur],-1
  496.         jmp     .exit
  497. endf
  498.  
  499. ;-----------------------------------------------------------------------------
  500. func line_add_spaces ;////////////////////////////////////////////////////////
  501. ;-----------------------------------------------------------------------------
  502. ; Input:
  503. ;  ESI = line offset
  504. ;  ECX = needed line length
  505. ; Output:
  506. ;  EAX = delta
  507. ;-----------------------------------------------------------------------------
  508.         xor     eax,eax
  509.         pushad
  510.         movzx   edx,word[esi]
  511.         cmp     ecx,edx
  512.         jbe     .exit
  513.         sub     ecx,edx
  514.         lea     eax,[ecx+4]
  515.         call    editor_realloc_lines
  516.         mov     [esp+4*7],eax
  517.         add     esi,eax
  518.         push    ecx
  519.         mov     edi,[cur_editor.Lines] ;! AREA_TEMP2
  520.         add     edi,[edi-4]
  521.         dec     edi
  522.         mov     eax,esi
  523.         mov     esi,edi
  524.         sub     esi,ecx
  525.         lea     ecx,[eax+4]
  526.         add     ecx,edx;[eax]
  527.         push    ecx
  528.         neg     ecx
  529.         lea     ecx,[esi+ecx+1]
  530.         std
  531.         rep     movsb
  532.         pop     edi ecx
  533.         add     [eax],cx
  534.         mov     al,' '
  535.         cld
  536.         rep     stosb
  537.   .exit:
  538.         popad
  539.         ret
  540. endf
  541.  
  542. ;-----------------------------------------------------------------------------
  543. func delete_selection ;///////////////////////////////////////////////////////
  544. ;-----------------------------------------------------------------------------
  545. ;       call    init_sel_vars
  546.  
  547.         cmp     [sel.selected],0
  548.         je      .exit.2
  549.  
  550.         pushad
  551.         mov     ecx,[sel.begin.y]
  552.         cmp     ecx,[sel.end.y]
  553.         je      .single_line
  554.         call    get_line_offset
  555.         and     dword[esi],not 0x00020000
  556.         or      dword[esi],0x00010000
  557.         mov     ecx,[sel.begin.x]
  558.         call    line_add_spaces
  559.         add     esi,eax
  560.         lea     edi,[esi+4]
  561.         mov     ecx,[sel.end.y]
  562.         call    get_line_offset
  563.         call    get_real_length
  564.         cmp     eax,[sel.end.x]
  565.         jbe     @f
  566.         mov     eax,[sel.end.x]
  567.     @@: movzx   ecx,word[esi]
  568.         sub     ecx,eax
  569.         mov     ebx,[sel.begin.x]
  570.         add     ebx,ecx
  571.         mov     [edi-4],bx
  572.         add     edi,[sel.begin.x]
  573.         lea     esi,[esi+eax+4]
  574.         mov     ecx,[cur_editor.Lines] ;! AREA_TEMP2
  575.         add     ecx,[ecx-4]
  576.         sub     ecx,esi
  577.         cld
  578.         rep     movsb
  579.         mov     eax,[sel.end.y]
  580.         sub     eax,[sel.begin.y]
  581.         sub     [cur_editor.Lines.Count],eax ;! [lines],eax
  582.         jmp     .exit
  583.  
  584.   .single_line:
  585.         call    get_line_offset
  586.         and     dword[esi],not 0x00020000
  587.         or      dword[esi],0x00010000
  588.         call    get_real_length
  589.         cmp     eax,[sel.begin.x]
  590.         jbe     .exit
  591.         mov     ecx,[sel.end.x]
  592.         cmp     ecx,eax
  593.         jbe     @f
  594.         mov     ecx,eax
  595.     @@: sub     ecx,[sel.begin.x]
  596.         sub     [esi],cx
  597.         lea     edi,[esi+4]
  598.         add     edi,[sel.begin.x]
  599.         lea     esi,[edi+ecx]
  600.         mov     ecx,[cur_editor.Lines] ;! AREA_TEMP2
  601.         add     ecx,[ecx-4]
  602.         sub     ecx,esi
  603.         cld
  604.         rep     movsb
  605.  
  606.   .exit:
  607.         mov     eax,[sel.begin.x]
  608.         mov     [cur_editor.Caret.X],eax ;! [pos.x],eax
  609.         mov     [cur_editor.SelStart.X],eax ;! [sel.x],eax
  610.         mov     eax,[sel.begin.y]
  611.         mov     [cur_editor.Caret.Y],eax ;! [pos.y],eax
  612.         mov     [cur_editor.SelStart.Y],eax ;! [sel.y],eax
  613.  
  614.         mov     ecx,[cur_editor.Lines.Count]
  615.         call    get_line_offset
  616.         movzx   eax,word[esi]
  617.         lea     esi,[esi+eax+4]
  618.         mov     eax,[cur_editor.Lines]
  619.         add     eax,[eax-4]
  620.         sub     esi,eax
  621.         lea     eax,[esi+4096]
  622.         call    editor_realloc_lines
  623.  
  624.         popad
  625.         mov     [cur_editor.Modified],1 ;! [modified],1
  626.         clc
  627.         ret
  628.  
  629.   .exit.2:
  630.         stc
  631.         ret
  632. endf
  633.  
  634. ;-----------------------------------------------------------------------------
  635. func get_selection_size ;/////////////////////////////////////////////////////
  636. ;-----------------------------------------------------------------------------
  637.         push    ecx esi
  638.         mov     ecx,[sel.end.y]
  639.         inc     ecx
  640.         call    get_line_offset
  641.         mov     eax,esi
  642.         mov     ecx,[sel.begin.y]
  643.         call    get_line_offset
  644.         sub     eax,esi
  645.         pop     esi ecx
  646.         ret
  647. endf
  648.  
  649. ;-----------------------------------------------------------------------------
  650. func get_lines_in_file ;//////////////////////////////////////////////////////
  651. ;-----------------------------------------------------------------------------
  652. ; Input:
  653. ;  ESI = data pointer
  654. ;  ECX = data length
  655. ; Output:
  656. ;  EAX = lines number
  657. ;  EBX = extra length after tabs expansion
  658. ;-----------------------------------------------------------------------------
  659.         push    ecx edx esi 0
  660.         or      ebx,-1
  661.         xor     edx,edx
  662.   .lp0: inc     ebx
  663.   .lp1: dec     ecx
  664.         jle     .lp2
  665.         lodsb
  666.         cmp     al,0
  667.         je      .lp2
  668.         cmp     al,9
  669.         je      .TB
  670.         cmp     al,10
  671.         je      .LF
  672.         cmp     al,13
  673.         je      .CR
  674.         inc     edx
  675.         jmp     .lp1
  676.   .lp2: lea     eax,[ebx+1]
  677.         pop     ebx esi edx ecx
  678.         ret
  679.  
  680.    .CR: cmp     byte[esi],10
  681.         jne     .LF
  682.         lodsb
  683.    .LF: xor     edx,edx
  684.         jmp     .lp0
  685.    .TB: and     edx,00000111b
  686.         add     dword[esp],ATABW
  687.         sub     [esp],edx
  688.         xor     edx,edx
  689.         jmp     .lp1
  690. endf
  691.  
  692. ;-----------------------------------------------------------------------------
  693. func mem.Alloc ;//////////////////////////////////////////////////////////////
  694. ;-----------------------------------------------------------------------------
  695.         push    ebx ecx
  696.         lea     ecx,[eax+4+4095]
  697.         and     ecx,not 4095
  698.         mcall   68,12
  699.         add     ecx,-4
  700.         mov     [eax],ecx
  701.         add     eax,4
  702.         pop     ecx ebx
  703.         ret
  704. endf
  705.  
  706. ;-----------------------------------------------------------------------------
  707. func mem.ReAlloc ;////////////////////////////////////////////////////////////
  708. ;-----------------------------------------------------------------------------
  709.         push    ebx ecx esi edi eax
  710.         or      eax,eax
  711.         jz      @f
  712.         lea     ecx,[ebx+4+4095]
  713.         and     ecx,not 4095
  714.         add     ecx,-4
  715.         cmp     ecx,[eax-4]
  716.         je      .exit
  717.     @@: mov     eax,ebx
  718.         call    mem.Alloc
  719.         xchg    eax,[esp]
  720.         or      eax,eax
  721.         jz      .exit
  722.         mov     esi,eax
  723.         xchg    eax,[esp]
  724.         mov     edi,eax
  725.         mov     ecx,[esi-4]
  726.         cmp     ecx,[edi-4]
  727.         jbe     @f
  728.         mov     ecx,[edi-4]
  729.     @@: add     ecx,3
  730.         shr     ecx,2
  731.         cld
  732.         rep     movsd
  733.         xchg    eax,[esp]
  734.         call    mem.Free
  735.   .exit:
  736.         pop     eax edi esi ecx ebx
  737.         ret
  738. endf
  739.  
  740. ;-----------------------------------------------------------------------------
  741. func mem.Free ;///////////////////////////////////////////////////////////////
  742. ;-----------------------------------------------------------------------------
  743.         push    ebx ecx
  744.         lea     ecx,[eax-4]
  745.         mcall   68,13
  746.         pop     ecx ebx
  747.         ret
  748. endf
  749.