Subversion Repositories Kolibri OS

Rev

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

  1. diff16 'tp-common.asm',0,$
  2.  
  3. ;-----------------------------------------------------------------------------
  4. proc clear_selection ;////////////////////////////////////////////////////////
  5. ;-----------------------------------------------------------------------------
  6.         push    eax ebx
  7.         mov     eax,[cur_editor.SelStart.Y]
  8.         mov     ebx,[cur_editor.Caret.Y]
  9.         cmp     eax,ebx
  10.         jle     @f
  11.         xchg    eax,ebx
  12.     @@: push    [cur_editor.Caret.X] [cur_editor.Caret.Y]
  13.         pop     [cur_editor.SelStart.Y] [cur_editor.SelStart.X]
  14.         pop     ebx eax
  15.         ret
  16. endp
  17.  
  18. ;-----------------------------------------------------------------------------
  19. proc pt_in_rect ;/////////////////////////////////////////////////////////////
  20. ;-----------------------------------------------------------------------------
  21.         cmp     eax,[ecx+0x0]
  22.         jl      @f
  23.         cmp     ebx,[ecx+0x4]
  24.         jl      @f
  25.         cmp     eax,[ecx+0x8]
  26.         jg      @f
  27.         cmp     ebx,[ecx+0xC]
  28.         jg      @f
  29.         stc
  30.         ret
  31.     @@: clc
  32.         ret
  33. endp
  34.  
  35. ;-----------------------------------------------------------------------------
  36. proc check_bottom_right ;/////////////////////////////////////////////////////
  37. ;-----------------------------------------------------------------------------
  38.         push    eax
  39.         mov     eax,[cur_editor.TopLeft.Y]
  40.         or      eax,eax
  41.         jns     @f
  42.         xor     eax,eax
  43.         mov     [cur_editor.TopLeft.Y],eax
  44.     @@: add     eax,[lines.scr]
  45.         cmp     eax,[cur_editor.Lines.Count]
  46.         jbe     .lp1
  47.         mov     eax,[cur_editor.Lines.Count]
  48.         sub     eax,[lines.scr]
  49.         jns     @f
  50.         xor     eax,eax
  51.     @@: mov     [cur_editor.TopLeft.Y],eax
  52.   .lp1: mov     eax,[cur_editor.TopLeft.X]
  53.         or      eax,eax
  54.         jns     @f
  55.         xor     eax,eax
  56.         mov     [cur_editor.TopLeft.X],eax
  57.     @@: add     eax,[columns.scr]
  58.         cmp     eax,[cur_editor.Columns.Count]
  59.         jbe     .exit
  60.         mov     eax,[cur_editor.Columns.Count]
  61.         sub     eax,[columns.scr]
  62.         jns     @f
  63.         xor     eax,eax
  64.     @@: mov     [cur_editor.TopLeft.X],eax
  65.   .exit:
  66.         pop     eax
  67.         ret
  68. endp
  69.  
  70. ;-----------------------------------------------------------------------------
  71. proc get_real_length ;////////////////////////////////////////////////////////
  72. ;-----------------------------------------------------------------------------
  73.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  74.  
  75.     @@: cmp     byte[esi+eax+sizeof.EDITOR_LINE_DATA-1],' '
  76.         jne     @f
  77.         dec     eax
  78.         jnz     @b
  79.     @@: ret
  80. endp
  81.  
  82. ;-----------------------------------------------------------------------------
  83. proc get_line_offset ;////////////////////////////////////////////////////////
  84. ;-----------------------------------------------------------------------------
  85. ; Input:
  86. ;  ECX = line number
  87. ; Output:
  88. ;  ESI = line data offset
  89. ;-----------------------------------------------------------------------------
  90.         push    eax ecx
  91.         mov     esi,[cur_editor.Lines]
  92.     @@: dec     ecx
  93.         js      .exit
  94.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  95.         lea     esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
  96.         jmp     @b
  97.   .exit:
  98.         pop     ecx eax
  99.         ret
  100. endp
  101.  
  102. ;-----------------------------------------------------------------------------
  103. proc init_sel_vars ;//////////////////////////////////////////////////////////
  104. ;-----------------------------------------------------------------------------
  105.         pushad
  106.         mov     [sel.selected],1
  107.         mov     eax,[ebp+EDITOR.SelStart.X]
  108.         mov     ebx,[ebp+EDITOR.SelStart.Y]
  109.         mov     ecx,[ebp+EDITOR.Caret.X]
  110.         mov     edx,[ebp+EDITOR.Caret.Y]
  111.         cmp     ebx,edx
  112.         jl      .lp2
  113.         jne     @f
  114.         cmp     eax,ecx
  115.         jl      .lp2
  116.         jne     .lp1
  117.         dec     [sel.selected]
  118.         jmp     .lp2
  119.     @@: xchg    ebx,edx
  120.   .lp1: xchg    eax,ecx
  121.   .lp2: mov     [sel.begin.x],eax
  122.         mov     [sel.begin.y],ebx
  123.         mov     [sel.end.x],ecx
  124.         mov     [sel.end.y],edx
  125.         popad
  126.         ret
  127. endp
  128.  
  129. ;-----------------------------------------------------------------------------
  130. proc get_scroll_vars ;////////////////////////////////////////////////////////
  131. ;-----------------------------------------------------------------------------
  132. ; Input:
  133. ;  EAX = maximum data size      (units)
  134. ;  EBX = visible data size      (units)
  135. ;  ECX = current data position  (units)
  136. ;  EDX = scrolling area size    (pixels)
  137. ; Output:
  138. ;  EAX = srcoller offset        (pixels)
  139. ;  EBX = scroller size          (pixels)
  140. ;-----------------------------------------------------------------------------
  141.         push    eax ebx edx
  142. ;       sub     eax,ebx
  143.         mov     esi,eax
  144.         mov     eax,edx
  145.         imul    ebx
  146.         idiv    esi
  147.         cmp     eax,[esp]
  148.         jge     .null
  149.         cmp     eax,AMINS
  150.         jge     @f
  151.         neg     eax
  152.         add     eax,AMINS
  153.         sub     [esp],eax
  154.         mov     eax,AMINS
  155.     @@: mov     [esp+4],eax     ; scroller size
  156.         mov     eax,[esp]
  157.         imul    ecx
  158.         idiv    esi
  159.         or      eax,eax
  160.         jns     @f
  161.         xor     eax,eax
  162.    @@:  mov     [esp+8],eax     ; scroller offset
  163.         add     eax,[esp+4]
  164.         cmp     eax,[esp]
  165.         jle     @f
  166.     @@:
  167.         pop     edx ebx eax
  168.         ret
  169.   .null:
  170.         mov     dword[esp+4],0
  171.         mov     dword[esp+8],0
  172.         jmp     @b
  173. endp
  174.  
  175. ;-----------------------------------------------------------------------------
  176. proc uint2strz ;//////////////////////////////////////////////////////////////
  177. ;-----------------------------------------------------------------------------
  178.         dec     ebx
  179.         jz      @f
  180.         xor     edx,edx
  181.         div     ecx
  182.         push    edx
  183.         call    uint2strz
  184.         pop     eax
  185.     @@: cmp     al,10
  186.         sbb     al,$69
  187.         das
  188.         stosb
  189.         ret
  190. endp
  191.  
  192. ;-----------------------------------------------------------------------------
  193. proc uint2str ;///////////////////////////////////////////////////////////////
  194. ;-----------------------------------------------------------------------------
  195.         cmp     eax,ecx
  196.         jb      @f
  197.         xor     edx,edx
  198.         div     ecx
  199.         push    edx
  200.         call    uint2str
  201.         pop     eax
  202.     @@: cmp     al,10
  203.         sbb     al,$69
  204.         das
  205.         stosb
  206.         ret
  207. endp
  208.  
  209. ;-----------------------------------------------------------------------------
  210. proc strlen ;/////////////////////////////////////////////////////////////////
  211. ;-----------------------------------------------------------------------------
  212.         push    ebx
  213.         mov     ebx,eax
  214.         xor     eax,eax
  215.     @@: cmp     byte[ebx+eax],0
  216.         je      @f
  217.         inc     eax
  218.         jmp     @b
  219.     @@: pop     ebx
  220.         ret
  221. endp
  222.  
  223. ;-----------------------------------------------------------------------------
  224. proc rgb_to_gray ;////////////////////////////////////////////////////////////
  225. ;-----------------------------------------------------------------------------
  226.         push    0 eax
  227.         and     dword[esp],0x000000FF
  228.         fild    dword[esp]
  229.         fmul    [float_gray_b]
  230.         shr     eax,8
  231.         mov     [esp],eax
  232.         and     dword[esp],0x000000FF
  233.         fild    dword[esp]
  234.         fmul    [float_gray_g]
  235.         faddp
  236.         shr     eax,8
  237.         and     eax,0x000000FF
  238.         mov     [esp],eax
  239.         fild    dword[esp]
  240.         fmul    [float_gray_r]
  241.         faddp
  242.         frndint
  243.         fist    dword[esp]
  244.         fist    dword[esp+1]
  245.         fistp   dword[esp+2]
  246.         pop     eax
  247.         add     esp,4
  248.         ret
  249. endp
  250.  
  251. ;float_gray_r dd 0.30f
  252. ;float_gray_g dd 0.59f
  253. ;float_gray_b dd 0.11f
  254.  
  255. ;-----------------------------------------------------------------------------
  256. proc get_active_menu_item ;///////////////////////////////////////////////////
  257. ;-----------------------------------------------------------------------------
  258.         pushad
  259.         mov     [mi_cur],0
  260.         mcall   37,1
  261.         movsx   ebx,ax
  262.         sar     eax,16
  263.         mov     ecx,__rc
  264.         pushd   2 0 (main_menu.width+7) (ATOPH-2)
  265.         popd    [__rc+0xC] [__rc+0x8] [__rc+0x4] [__rc+0x0]
  266. ;       add     [__rc+0xC],ATOPH-2
  267.         call    pt_in_rect
  268.         jnc     .outside_menu
  269.         m2m     dword[ecx+0x8],dword[ecx+0x0]
  270.         mov     edx,main_menu
  271.     @@: inc     [mi_cur]
  272.         movzx   esi,word[edx+0]
  273.         add     [ecx+0x8],esi
  274.         call    pt_in_rect
  275.         jc      .exit
  276.         m2m     dword[ecx+0x0],dword[ecx+0x8]
  277.         add     edx,8+1
  278.         movzx   esi,byte[edx-1]
  279.         add     edx,esi
  280.         cmp     byte[edx+8],0
  281.         jne     @b
  282.         mov     [mi_cur],0
  283.   .exit:
  284.         popad
  285.         ret
  286.   .outside_menu:
  287.         or      [mi_cur],-1
  288.     @@: popad
  289.         ret
  290. endp
  291.  
  292. ;-----------------------------------------------------------------------------
  293. proc get_active_popup_item ;//////////////////////////////////////////////////
  294. ;-----------------------------------------------------------------------------
  295.         pushad
  296.         mov     [pi_cur],0
  297.         mcall   37,1
  298.         movsx   ebx,ax
  299.         sar     eax,16
  300.         mov     ecx,__rc
  301.         mov     dword[ecx+0x0],0
  302.         mov     dword[ecx+0x4],0
  303.         movzx   edx,[ebp+POPUP.width]
  304.         mov     dword[ecx+0x8],edx
  305.         movzx   edx,[ebp+POPUP.height]
  306.         mov     dword[ecx+0xC],edx
  307.         call    pt_in_rect
  308.         jnc     .outside_window
  309.         inc     dword[ecx+0x0]
  310.         mov     dword[ecx+0x4],2
  311.         dec     dword[ecx+0x8]
  312.         mov     dword[ecx+0xC],2+POP_IHEIGHT-1
  313.         mov     edx,[ebp+POPUP.data]
  314.     @@: inc     [pi_cur]
  315.         inc     edx
  316.         movzx   esi,byte[edx-1]
  317.         cmp     byte[edx],'-'
  318.         jne     .lp1
  319.         pushd   [ecx+0xC]
  320.         sub     dword[ecx+0xC],POP_IHEIGHT-POP_SHEIGHT
  321.         call    pt_in_rect
  322.         popd    [ecx+0xC]
  323.         jc      .separator
  324.         add     dword[ecx+0x4],POP_SHEIGHT
  325.         add     dword[ecx+0xC],POP_SHEIGHT
  326.         jmp     .lp3
  327.   .lp1: call    pt_in_rect
  328.         jnc     .lp2
  329.         mov     eax,[pi_cur]
  330.         test    byte[ebp+eax-1],1
  331.         jnz     .exit
  332.         jmp     .separator
  333.   .lp2: add     dword[ecx+0x4],POP_IHEIGHT
  334.         add     dword[ecx+0xC],POP_IHEIGHT
  335.         add     edx,esi
  336.         inc     edx
  337.         movzx   esi,byte[edx-1]
  338.   .lp3: add     edx,esi
  339.         cmp     byte[edx],0
  340.         jne     @b
  341.   .separator:
  342.         mov     [pi_cur],0
  343.   .exit:
  344.         popad
  345.         ret
  346.   .outside_window:
  347.         or      [pi_cur],-1
  348.         jmp     .exit
  349. endp
  350.  
  351. ;-----------------------------------------------------------------------------
  352. proc line_add_spaces ;////////////////////////////////////////////////////////
  353. ;-----------------------------------------------------------------------------
  354. ; Input:
  355. ;  ESI = line offset
  356. ;  ECX = needed line length
  357. ; Output:
  358. ;  EAX = delta
  359. ;-----------------------------------------------------------------------------
  360.         xor     eax,eax
  361.         pushad
  362.         mov     edx,[esi+EDITOR_LINE_DATA.Size]
  363.         cmp     ecx,edx
  364.         jbe     .exit
  365.         sub     ecx,edx
  366.         lea     eax,[ecx+sizeof.EDITOR_LINE_DATA]
  367.         call    editor_realloc_lines
  368.         mov     [esp+4*7],eax
  369.         add     esi,eax
  370.         push    ecx
  371.         mov     edi,[cur_editor.Lines]
  372.         add     edi,[cur_editor.Lines.Size] ; !!! CHECK THIS!!! add edi,[edi-4]
  373.         dec     edi
  374.         mov     eax,esi
  375.         mov     esi,edi
  376.         sub     esi,ecx
  377.         lea     ecx,[eax+sizeof.EDITOR_LINE_DATA]
  378.         add     ecx,edx
  379.         push    ecx
  380.         neg     ecx
  381.         lea     ecx,[esi+ecx+1]
  382.         std
  383.         rep     movsb
  384.         pop     edi ecx
  385.         add     [eax+EDITOR_LINE_DATA.Size],ecx
  386.         mov     al,' '
  387.         cld
  388.         rep     stosb
  389.   .exit:
  390.         popad
  391.         ret
  392. endp
  393.  
  394. ;-----------------------------------------------------------------------------
  395. proc delete_selection ;///////////////////////////////////////////////////////
  396. ;-----------------------------------------------------------------------------
  397. ;       call    init_sel_vars
  398.  
  399.         cmp     [sel.selected],0
  400.         je      .exit.2
  401.  
  402.         pushad
  403.         mov     ecx,[sel.begin.y]
  404.         cmp     ecx,[sel.end.y]
  405.         je      .single_line
  406.         call    get_line_offset
  407.         and     [esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
  408.         or      [esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  409.         mov     ecx,[sel.begin.x]
  410.         call    line_add_spaces
  411.         add     esi,eax
  412.         lea     edi,[esi+sizeof.EDITOR_LINE_DATA]
  413.         mov     ecx,[sel.end.y]
  414.         call    get_line_offset
  415.         call    get_real_length
  416.         cmp     eax,[sel.end.x]
  417.         jbe     @f
  418.         mov     eax,[sel.end.x]
  419.     @@: mov     ecx,[esi+EDITOR_LINE_DATA.Size]
  420.         sub     ecx,eax
  421.         mov     ebx,[sel.begin.x]
  422.         add     ebx,ecx
  423.         mov     [edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],ebx
  424.         add     edi,[sel.begin.x]
  425.         lea     esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
  426.         mov     ecx,[cur_editor.Lines]
  427.         add     ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
  428.         sub     ecx,esi
  429.         cld
  430.         rep     movsb
  431.         mov     eax,[sel.end.y]
  432.         sub     eax,[sel.begin.y]
  433.         sub     [cur_editor.Lines.Count],eax
  434.         jmp     .exit
  435.  
  436.   .single_line:
  437.         call    get_line_offset
  438.         and     [esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
  439.         or      [esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  440.         call    get_real_length
  441.         cmp     eax,[sel.begin.x]
  442.         jbe     .exit
  443.         mov     ecx,[sel.end.x]
  444.         cmp     ecx,eax
  445.         jbe     @f
  446.         mov     ecx,eax
  447.     @@: sub     ecx,[sel.begin.x]
  448.         sub     [esi+EDITOR_LINE_DATA.Size],ecx
  449.         lea     edi,[esi+sizeof.EDITOR_LINE_DATA]
  450.         add     edi,[sel.begin.x]
  451.         lea     esi,[edi+ecx]
  452.         mov     ecx,[cur_editor.Lines]
  453.         add     ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
  454.         sub     ecx,esi
  455.         cld
  456.         rep     movsb
  457.  
  458.   .exit:
  459.         mov     eax,[sel.begin.x]
  460.         mov     [cur_editor.Caret.X],eax
  461.         mov     [cur_editor.SelStart.X],eax
  462.         mov     eax,[sel.begin.y]
  463.         mov     [cur_editor.Caret.Y],eax
  464.         mov     [cur_editor.SelStart.Y],eax
  465.  
  466.         mov     ecx,[cur_editor.Lines.Count]
  467.         call    get_line_offset
  468.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  469.         lea     esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
  470.         mov     eax,[cur_editor.Lines]
  471.         add     eax,[cur_editor.Lines.Size] ;*** add eax,[eax-4]
  472.         sub     esi,eax
  473.         lea     eax,[esi+4096]
  474.         call    editor_realloc_lines
  475.  
  476.         popad
  477.         mov     [cur_editor.Modified],1
  478.         clc
  479.         ret
  480.  
  481.   .exit.2:
  482.         stc
  483.         ret
  484. endp
  485.  
  486. ;-----------------------------------------------------------------------------
  487. proc get_selection_size ;/////////////////////////////////////////////////////
  488. ;-----------------------------------------------------------------------------
  489.         push    ecx esi
  490.         mov     ecx,[sel.end.y]
  491.         inc     ecx
  492.         call    get_line_offset
  493.         mov     eax,esi
  494.         mov     ecx,[sel.begin.y]
  495.         call    get_line_offset
  496.         sub     eax,esi
  497.         pop     esi ecx
  498.         ret
  499. endp
  500.  
  501. ;-----------------------------------------------------------------------------
  502. proc get_lines_in_file ;//////////////////////////////////////////////////////
  503. ;-----------------------------------------------------------------------------
  504. ; Input:
  505. ;  ESI = data pointer
  506. ;  ECX = data length
  507. ; Output:
  508. ;  EAX = lines number
  509. ;  EBX = extra length after tabs expansion
  510. ;-----------------------------------------------------------------------------
  511.         push    ecx edx esi 0
  512.         or      ebx,-1
  513.         xor     edx,edx
  514.   .lp0: inc     ebx
  515.   .lp1: dec     ecx
  516.         jle     .lp2
  517.         lodsb
  518.         cmp     al,0
  519.         je      .lp2
  520.         cmp     al,9
  521.         je      .TB
  522.         cmp     al,10
  523.         je      .LF
  524.         cmp     al,13
  525.         je      .CR
  526.         inc     edx
  527.         jmp     .lp1
  528.   .lp2: lea     eax,[ebx+1]
  529.         pop     ebx esi edx ecx
  530.         ret
  531.  
  532.    .CR: cmp     byte[esi],10
  533.         jne     .LF
  534.         lodsb
  535.    .LF: xor     edx,edx
  536.         jmp     .lp0
  537.    .TB: and     edx,00000111b
  538.         add     dword[esp],ATABW
  539.         sub     [esp],edx
  540.         xor     edx,edx
  541.         jmp     .lp1
  542. endp
  543.  
  544. ;-----------------------------------------------------------------------------
  545. proc update_caption ;/////////////////////////////////////////////////////////
  546. ;-----------------------------------------------------------------------------
  547.         lea     esi,[cur_editor.FilePath]
  548.         mov     edi,s_title
  549.  
  550.         xor     ecx,ecx
  551.     @@: lodsb
  552.         cmp     al,0
  553.         je      @f
  554.         stosb
  555.         inc     ecx
  556.         jmp     @b
  557.     @@:
  558.         push    ecx
  559.         mov     dword[edi],' - '
  560.         add     edi,3
  561.         mov     esi,htext
  562.         mov     ecx,htext.size
  563.         cld
  564.         rep     movsb
  565.  
  566.         mov     al,0
  567.         stosb
  568.  
  569.         mcall   71,1,s_title
  570.  
  571.         cmp     [do_not_draw],0
  572.         jne     @f
  573.         lea     esi,[cur_editor.FilePath]
  574.         mov     edi,tb_opensave.text
  575.         mov     ecx,[esp]
  576.         cld
  577.         rep     movsb
  578.         pop     ecx
  579.         mov     [tb_opensave.length],cl
  580.         clc
  581.         ret
  582.     @@:
  583.         add     esp,4
  584.         clc
  585.         ret
  586. endp
  587.  
  588.