diff --git a/programs/develop/tinypad/trunk/tp-clipboard.asm b/programs/develop/tinypad/trunk/tp-clipboard.asm index a90b797cc1..ea7c506166 100644 --- a/programs/develop/tinypad/trunk/tp-clipboard.asm +++ b/programs/develop/tinypad/trunk/tp-clipboard.asm @@ -1,288 +1,184 @@ -;----------------------------------------------------------------------------- + put_to_clipboard: -; we have allocated memory? mov edi,[clipboard_buf] test edi,edi jz .end -; convert from Tinypad format to the kernel clipboard format - add edi,3*4 + add edi,12 mov esi,[copy_buf] - mov ecx,[copy_count] + mov edx,[copy_count] + mov ax,0x0a0d ; End of String cld -;-------------------------------------- -@@: - push ecx - lodsd - mov ecx,eax - lodsw - rep movsb - mov ax,0x0a0d ; EOS (end of string) +@@: ; convert format from Tinypad to clipboard + mov ecx,[esi] + add esi,sizeof.EDITOR_LINE_DATA + rep movsb stosw -; mov ax,0x0d -; stosb - pop ecx - dec ecx + dec edx jnz @b - sub edi,2 ; delete last EOS (0x0a0d) + sub edi,2 ; delete last EoS xor eax,eax stosb -; building the clipboard slot header +; build the clipboard slot header mov esi,[clipboard_buf] sub edi,esi - mov [esi],edi ; clipboard area size + mov [esi],edi ; clipboard area size xor eax,eax - mov [esi+4],eax ; ; type 'text' + mov [esi+4],eax ; type 'text' inc eax mov [esi+8],eax ; cp866 text encoding ; put slot to the kernel clipboard mov edx,[clipboard_buf] mov ecx,[edx] mcall 54,2 -; remove unnecessary memory area - xor eax,eax - stdcall mem.ReAlloc,[clipboard_buf],eax - mov [clipboard_buf],eax + stdcall mem.Free,[clipboard_buf] + stdcall mem.Free,[copy_buf] xor eax,eax + mov [copy_buf],eax mov [copy_size],eax - mov [copy_count],eax - stdcall mem.ReAlloc,[copy_buf],eax - mov [copy_buf],eax -;-------------------------------------- + mov [copy_count],eax + mov [clipboard_buf],eax .end: ret -;----------------------------------------------------------------------------- +;--------------------------------------------------------------- get_from_clipboard: + mov [copy_size],0 pushad mcall 54,0 -; no slots of clipboard ? test eax,eax - jz .exit -; main list area not found ? + jz .exit ; no slots of clipboard inc eax - test eax,eax - jz .exit - + jz .exit ; main list area not found sub eax,2 mov ecx,eax mcall 54,1 -; main list area not found ? inc eax - test eax,eax - jz .exit -; error ? + jz .exit ; main list area not found sub eax,2 - test eax,eax - jz .exit - + jz .exit ; error inc eax mov [clipboard_buf],eax ; check contents of container mov ebx,[eax+4] -; check for text test ebx,ebx - jnz .no_valid_text - + jnz .freeMemory ; not text mov ebx,[eax+8] -; check for cp866 - cmp bl,1 - jz .yes_valid_text - -.no_valid_text: - xor eax,eax - mov [copy_size],eax - jmp .remove_area -;-------------------------------------- -.yes_valid_text: - call know_number_line_breaks - mov [copy_count],ebx -; correction of erroneous buffer size - mov eax,[clipboard_buf] - sub esi,eax - mov [eax],esi -; multiple by 6 - shl ebx,1 - lea ebx,[ebx*3] -; calculating a desired size - mov eax,[clipboard_buf] - mov eax,[eax] - sub eax,4*3 - add eax,ebx - mov [copy_size],eax - - stdcall mem.ReAlloc,[copy_buf],eax - mov [copy_buf],eax - - call convert_clipboard_buf_to_copy_buf -; remove unnecessary memory area -.remove_area: - xor eax,eax - stdcall mem.ReAlloc,[clipboard_buf],eax - mov [clipboard_buf],eax -;-------------------------------------- + dec ebx + jnz .freeMemory ; not cp866 + mov edi,[clipboard_buf] + mov al, 10 + mov ecx,[edi] + add edi,12 + sub ecx,12 + jbe .freeMemory + cmp byte[edi],0 + jz .freeMemory +@@: + dec ecx + cmp byte[edi+ecx],0 + jz @b + inc ecx + push ecx + cld +@@: ; count strings + repnz scasb + inc ebx + test ecx,ecx + jnz @b + dec edi + cmp byte[edi],10 + jnz @f + inc ebx +@@: + mov [copy_count],ebx + lea eax,[ebx*4+ebx+2] + add eax,[esp] + stdcall mem.Alloc,eax + mov [copy_buf],eax + mov esi,eax + mov edi,[clipboard_buf] + add edi,12 + pop ecx + mov ebx,ecx + mov al, 10 +.stringSize: ; convert format from clipboard to Tinypad + repnz scasb + sub ebx,ecx + mov edx,edi + sub edi,ebx + dec ebx + test ecx,ecx + jnz .stringEnd +.lastString: + cmp byte[edi+ebx],10 + jz .stringEnd + cmp byte[edi+ebx],0 + jnz @f + dec ebx + jmp .lastString +.stringEnd: + dec ebx + cmp byte[edi+ebx],13 + jz .copyString +@@: + inc ebx +.copyString: + mov [esi],ebx + add esi,sizeof.EDITOR_LINE_DATA + xchg ebx,ecx + xchg esi,edi + rep movsb + mov ecx,ebx + jcxz .done + mov esi,edi + mov edi,edx + jmp .stringSize +.done: + cmp esi,edx + jz @f + inc ecx + mov [edi],ecx + add edi,sizeof.EDITOR_LINE_DATA + mov byte[edi],' ' + inc edi +@@: + sub edi,[copy_buf] + mov [copy_size],edi +.freeMemory: + stdcall mem.Free,[clipboard_buf] + mov [clipboard_buf],0 .exit: popad ret -;----------------------------------------------------------------------------- +;--------------------------------------------------------------- check_clipboard_for_popup: pushad mov [popup_valid_text],0 mcall 54,0 -; no slots of clipboard ? test eax,eax - jz .exit -; main list area not found ? + jz .exit ; no slots of clipboard inc eax - test eax,eax - jz .exit - + jz .exit ; main list area not found sub eax,2 mov ecx,eax mcall 54,1 -; main list area not found ? inc eax - test eax,eax - jz .exit -; error ? + jz .exit ; main list area not found sub eax,2 - test eax,eax - jz .exit - + jz .exit ; error inc eax mov [clipboard_buf],eax ; check contents of container mov ebx,[eax+4] -; check for text test ebx,ebx - jnz .remove_area - + jnz .freeMemory ; not text mov ebx,[eax+8] -; check for cp866 - cmp bl,1 - jnz .remove_area - -.yes_valid_text: + dec ebx + jnz .freeMemory ; not cp866 mov [popup_valid_text],1 -; remove unnecessary memory area -.remove_area: - xor eax,eax - stdcall mem.ReAlloc,[clipboard_buf],eax - mov [clipboard_buf],eax -;-------------------------------------- +.freeMemory: + stdcall mem.Free,[clipboard_buf] + mov [clipboard_buf],0 .exit: popad ret -;----------------------------------------------------------------------------- -convert_clipboard_buf_to_copy_buf: - mov edi,[copy_buf] - mov ebx,edi - add edi,6 - mov eax,[clipboard_buf] - mov esi,eax - add esi,4*3 - mov ecx,[eax] - sub ecx,4*3-1 - xor edx,edx - cld -;-------------------------------------- -.loop: - lodsb - - test al,al - jz .end_of_data - - cmp al,0x0d - je .check_0x0a - - cmp al,0x0a - je .inc_counter - - dec ecx - jz .end_of_data - - stosb - jmp .loop -;-------------------------------------- -.check_0x0a: - dec ecx - jz .end_of_data - - cmp [esi],byte 0x0a - jne @f - - lodsb -;-------------------------------------- -.inc_counter: - dec ecx - jz .end_of_data -;-------------------------------------- -@@: - mov eax,edi - sub eax,ebx - sub eax,6 - mov [ebx],eax ; size of current string - mov ebx,edi - add edi,6 - inc edx - jmp .loop -;-------------------------------------- -.end_of_data: - mov eax,edi - sub eax,ebx - sub eax,6 - mov [ebx],eax ; size of current string - sub edi,[copy_buf] - mov [copy_size],edi - ret -;----------------------------------------------------------------------------- -know_number_line_breaks: -; to know the number of line breaks - mov eax,[clipboard_buf] - mov esi,eax - add esi,4*3 - mov ecx,[eax] - sub ecx,4*3 - xor ebx,ebx - cld -;-------------------------------------- -@@: - lodsb - - test al,al - jz .end_of_data - - cmp al,0x0d - je .check_0x0a - - cmp al,0x0a - je .inc_counter - - dec ecx - jnz @b - - jmp .end_of_data -;-------------------------------------- -.check_0x0a: - inc ebx - dec ecx - jz .end_of_data - - cmp [esi],byte 0x0a - jne @b - - lodsb - dec ecx - jnz @b - - jmp .end_of_data -;-------------------------------------- -.inc_counter: - inc ebx - dec ecx - jnz @b -;-------------------------------------- -.end_of_data: - add ebx,2 - inc esi - ret -;----------------------------------------------------------------------------- \ No newline at end of file diff --git a/programs/develop/tinypad/trunk/tp-key.asm b/programs/develop/tinypad/trunk/tp-key.asm index ac6c18407c..aff0a1cead 100644 --- a/programs/develop/tinypad/trunk/tp-key.asm +++ b/programs/develop/tinypad/trunk/tp-key.asm @@ -589,91 +589,61 @@ proc key.ctrl_v call get_from_clipboard @@: cmp [copy_size],0 - je .exit - + je .exit_1 call delete_selection - mov eax,[copy_size] + sub eax,sizeof.EDITOR_LINE_DATA call editor_realloc_lines - - mov ebx,[cur_editor.Lines.Size] - add ebx,[copy_size] - mov [cur_editor.Lines.Size],ebx - stdcall mem.ReAlloc,[cur_editor.Lines],ebx - mov [cur_editor.Lines],eax - mov ecx,[cur_editor.Caret.Y] call get_line_offset - pushd [esi+EDITOR_LINE_DATA.Size] esi mov ecx,[cur_editor.Caret.X] call line_add_spaces - add [esp],eax - add esi,eax - mov ecx,[copy_size] - mov edi,[copy_count] - test edi,edi - dec edi - jnz @f - sub ecx,sizeof.EDITOR_LINE_DATA -@@: + pushd [esi+EDITOR_LINE_DATA.Size] + push esi + lea eax,[esi+ecx+sizeof.EDITOR_LINE_DATA] mov edi,[cur_editor.Lines] - add edi,[cur_editor.Lines.Size] ;*** add edi,[edi-4] + add edi,[cur_editor.Lines.Size] dec edi - mov eax,esi + mov ecx,[copy_size] + sub ecx,sizeof.EDITOR_LINE_DATA mov esi,edi sub esi,ecx - lea ecx,[eax+sizeof.EDITOR_LINE_DATA] - add ecx,[cur_editor.Caret.X] - neg ecx - lea ecx,[esi+ecx+1] - mov [size_of_moving_area],ecx + neg eax + lea ecx,[esi+eax+1] std rep movsb - + cld + pop edi + mov esi,[copy_buf] + mov eax,[esi+EDITOR_LINE_DATA.Size] + add esi,sizeof.EDITOR_LINE_DATA mov ecx,[copy_count] dec ecx jz .single_line - cld - pop edi - add edi,sizeof.EDITOR_LINE_DATA - mov esi,[copy_buf] - mov eax,[esi+EDITOR_LINE_DATA.Size] - add esi,sizeof.EDITOR_LINE_DATA - - mov ebx,[cur_editor.Caret.X] - add eax,ebx - mov [edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],eax - mov [edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED - sub eax,ebx + add eax,[cur_editor.Caret.X] + mov [edi+EDITOR_LINE_DATA.Size],eax + mov [edi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED + sub eax,[cur_editor.Caret.X] call .check_columns - add edi,ebx - @@: push ecx + add edi,[cur_editor.Caret.X] +@@: + push ecx mov ecx,eax + add edi,sizeof.EDITOR_LINE_DATA rep movsb mov eax,[esi+EDITOR_LINE_DATA.Size] add esi,sizeof.EDITOR_LINE_DATA mov [edi+EDITOR_LINE_DATA.Size],eax mov [edi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED - add edi,sizeof.EDITOR_LINE_DATA pop ecx loop @b pop ecx - sub ecx,ebx - ja @f - - pusha - mov esi,edi - sub edi,sizeof.EDITOR_LINE_DATA - mov ecx,[size_of_moving_area] - cld - rep movsb - popa - jmp .save_cur_editor_values -@@: - add [edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],ecx + sub ecx,[cur_editor.Caret.X] + add [edi+EDITOR_LINE_DATA.Size],ecx call .check_columns + add edi,sizeof.EDITOR_LINE_DATA mov ecx,eax rep movsb .save_cur_editor_values: @@ -684,53 +654,40 @@ proc key.ctrl_v add [cur_editor.Caret.Y],eax add [cur_editor.SelStart.Y],eax add [cur_editor.Lines.Count],eax - mov [cur_editor.Modified],1 jmp .exit - .single_line: - cld - pop edi - add edi,sizeof.EDITOR_LINE_DATA - mov esi,[copy_buf] - mov eax,[esi+EDITOR_LINE_DATA.Size] - add esi,sizeof.EDITOR_LINE_DATA - add [edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],eax - and [edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED - or [edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED +.single_line: + add [edi+EDITOR_LINE_DATA.Size],eax + mov [edi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED call .check_columns + add edi,sizeof.EDITOR_LINE_DATA add edi,[cur_editor.Caret.X] - add esp,4 + pop ecx mov ecx,eax rep movsb - add [cur_editor.Caret.X],eax add [cur_editor.SelStart.X],eax - mov [cur_editor.Modified],1 - - .exit: +.exit: cmp [replace_mode],0 jne .exit_1 - - cmp [copy_size],0 - je .exit_1 -; remove unnecessary memory area + stdcall mem.Free,[copy_buf] xor eax,eax + mov [copy_buf],eax mov [copy_size],eax - mov [copy_count],eax - stdcall mem.ReAlloc,[copy_buf],eax - mov [copy_buf],eax + mov [copy_count],eax .exit_1: ret - .check_columns: +.check_columns: push eax - mov eax,[edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size] + mov eax,[edi+EDITOR_LINE_DATA.Size] cmp eax,[cur_editor.Columns.Count] jbe @f mov [cur_editor.Columns.Count],eax - @@: pop eax +@@: + pop eax ret endp ;----------------------------------------------------------------------------- @@ -812,101 +769,91 @@ endp ;----------------------------------------------------------------------------- proc key.up ;///// GO TO PREVIOUS LINE /////////////////////////////////////// ;----------------------------------------------------------------------------- - call clear_selection - + call key.shift_up + jmp clear_selection ;----------------------------------------------------------------------------- key.shift_up: ;///// GO TO PREVIOUS LINE, WITH SELECTION //////////////// ;----------------------------------------------------------------------------- - mov eax,[cur_editor.Caret.Y] - dec eax - jns @f - xor eax,eax - @@: mov ecx,[cur_editor.TopLeft.Y] - cmp eax,ecx - jae @f + mov ecx,[cur_editor.Caret.Y] dec ecx - jns @f - xor ecx,ecx - @@: test [chr],KM_SHIFT - jnz @f - mov [cur_editor.SelStart.Y],eax - @@: mov [cur_editor.Caret.Y],eax - mov [cur_editor.TopLeft.Y],ecx - - .exit: + js .exit + mov [cur_editor.Caret.Y],ecx + call get_line_offset + mov eax,[esi] + cmp eax,[cur_editor.Caret.X] + jnc .exit + mov [cur_editor.Caret.X],eax +.exit: ret endp ;----------------------------------------------------------------------------- proc key.down ;///// GO TO NEXT LINE ///////////////////////////////////////// ;----------------------------------------------------------------------------- - call clear_selection - + call key.shift_down + jmp clear_selection ;----------------------------------------------------------------------------- key.shift_down: ;///// GO TO NEXT LINE, WITH SELECTION ////////////////// ;----------------------------------------------------------------------------- - - mov eax,[cur_editor.Caret.Y] - inc eax - cmp eax,[cur_editor.Lines.Count] - jb @f - dec eax - @@: mov ecx,[cur_editor.TopLeft.Y] - mov edx,eax - sub edx,ecx - cmp edx,[lines.scr] - jb @f + mov ecx,[cur_editor.Caret.Y] inc ecx - @@: test [chr],KM_SHIFT - jnz @f - mov [cur_editor.SelStart.Y],eax - @@: mov [cur_editor.Caret.Y],eax - mov [cur_editor.TopLeft.Y],ecx - - .exit: + cmp [cur_editor.Lines.Count],ecx + jz .exit + mov [cur_editor.Caret.Y],ecx + call get_line_offset + mov eax,[esi] + cmp eax,[cur_editor.Caret.X] + jnc .exit + mov [cur_editor.Caret.X],eax +.exit: ret endp ;----------------------------------------------------------------------------- proc key.left ;///// GO TO PREVIOUS CHAR ///////////////////////////////////// ;----------------------------------------------------------------------------- - call clear_selection - + call key.shift_left + jmp clear_selection ;----------------------------------------------------------------------------- key.shift_left: ;///// GO TO PREVIOUS CHAR, WITH SELECTION ////////////// ;----------------------------------------------------------------------------- mov eax,[cur_editor.Caret.X] dec eax jns @f - inc eax - @@: test [chr],KM_SHIFT - jnz @f - mov [cur_editor.SelStart.X],eax - @@: mov [cur_editor.Caret.X],eax - - .exit: + mov ecx,[cur_editor.Caret.Y] + dec ecx + js .exit + mov [cur_editor.Caret.Y],ecx + call get_line_offset + mov eax,[esi] +@@: + mov [cur_editor.Caret.X],eax +.exit: ret endp ;----------------------------------------------------------------------------- proc key.right ;///// GO TO NEXT CHAR //////////////////////////////////////// ;----------------------------------------------------------------------------- - call clear_selection - + call key.shift_right + jmp clear_selection ;----------------------------------------------------------------------------- key.shift_right: ;///// GO TO NEXT CHAR, WITH SELECTION ///////////////// ;----------------------------------------------------------------------------- + mov ecx,[cur_editor.Caret.Y] + call get_line_offset mov eax,[cur_editor.Caret.X] inc eax - cmp eax,[cur_editor.Columns.Count] - jbe @f - dec eax - @@: test [chr],KM_SHIFT - jnz @f - mov [cur_editor.SelStart.X],eax - @@: mov [cur_editor.Caret.X],eax - - .exit: + cmp [esi],eax + jnc @f + inc ecx + cmp [cur_editor.Lines.Count],ecx + jz .exit + xor eax,eax + mov [cur_editor.Caret.Y],ecx +@@: + mov [cur_editor.Caret.X],eax +.exit: ret endp @@ -1631,33 +1578,28 @@ endp ;----------------------------------------------------------------------------- proc key.f3 ;///// FIND NEXT MATCH /////////////////////////////////////////// ;----------------------------------------------------------------------------- - call search - jc @f - @@: ret -endp - -;----------------------------------------------------------------------------- -proc key.f9 ;///// COMPILE AND RUN /////////////////////////////////////////// -;----------------------------------------------------------------------------- - mov bl,1 - call start_fasm - ret -endp - -;----------------------------------------------------------------------------- -proc key.f10 ;///// COMPILE AND RUN UNDER DEBUG ////////////////////////////// -;----------------------------------------------------------------------------- - mov bl,2 - call start_fasm - ret + jmp search endp ;----------------------------------------------------------------------------- proc key.ctrl_f9 ;///// COMPILE ////////////////////////////////////////////// ;----------------------------------------------------------------------------- mov bl,0 - call start_fasm - ret + jmp start_fasm +endp + +;----------------------------------------------------------------------------- +proc key.f9 ;///// COMPILE AND RUN /////////////////////////////////////////// +;----------------------------------------------------------------------------- + mov bl,1 + jmp start_fasm +endp + +;----------------------------------------------------------------------------- +proc key.f10 ;///// COMPILE AND RUN UNDER DEBUG ////////////////////////////// +;----------------------------------------------------------------------------- + mov bl,2 + jmp start_fasm endp ;----------------------------------------------------------------------------- diff --git a/programs/develop/tinypad/trunk/tp-mouse.asm b/programs/develop/tinypad/trunk/tp-mouse.asm index 60052d9536..0babbcb2b6 100644 --- a/programs/develop/tinypad/trunk/tp-mouse.asm +++ b/programs/develop/tinypad/trunk/tp-mouse.asm @@ -197,10 +197,11 @@ mouse: mov ecx,6 idiv ecx @@: add eax,[cur_editor.TopLeft.X] - - cmp eax,[cur_editor.Columns.Count] + mov ecx, ebx + call get_line_offset + cmp eax,[esi] jl @f - mov eax,[cur_editor.Columns.Count] + mov eax,[esi] @@: cmp ebx,[cur_editor.Lines.Count] jl @f mov ebx,[cur_editor.Lines.Count]