📄 edit.inc
字号:
; Assembly Editor core
; Copyright (c) 2001-2006, Tomasz Grysztar.
; All rights reserved.
put_character:
call get_caret_segment
inc [caret_position]
put_here:
cmp edx,SEGMENT_DATA_LENGTH
jae put_after_line_end
call store_segment_for_undo
test [editor_mode],AEMODE_OVERWRITE
jnz overwrite
mov ah,[esi+SEGMENT_HEADER_LENGTH+edx]
shl eax,8
mov al,ah
insert_in_segment:
lea ebx,[esi+SEGMENT_HEADER_LENGTH+edx]
mov ecx,SEGMENT_DATA_LENGTH
sub ecx,edx
shift_data_right:
xchg al,[ebx]
inc ebx
loop shift_data_right
test byte [esi],1
jnz shift_next_segment_right
cmp al,20h
je put_ok
add_segment:
push eax
call allocate_segment
jc memory_shortage
call store_free_segment_for_undo
mov edi,eax
or eax,1
xchg eax,[esi]
stosd
mov eax,esi
or eax,1
stosd
add edi,SEGMENT_HEADER_LENGTH - 8
pop eax
stosb
mov ecx,SEGMENT_DATA_LENGTH - 1
mov al,20h
rep stosb
jmp put_ok
shift_next_segment_right:
mov esi,[esi]
dec esi
call store_segment_for_undo
xor edx,edx
jmp insert_in_segment
put_after_line_end:
push eax
call attach_empty_segments
pop eax
mov [esi+SEGMENT_HEADER_LENGTH+edx],al
mov ah,20h
shl eax,8
put_ok:
test [editor_style],AES_AUTOBRACKETS
jz insert_done
shr eax,8
xchg ah,al
call recognize_character
jnc insert_done
cmp ah,'('
je round
cmp ah,'['
je square
cmp ah,'{'
je brace
insert_done:
retn
round:
mov al,')'
jmp auto_bracket
square:
mov al,']'
jmp auto_bracket
brace:
mov al,'}'
auto_bracket:
mov edx,[caret_position]
mov esi,[caret_line]
call find_segment
jmp put_here
overwrite:
mov [esi+SEGMENT_HEADER_LENGTH+edx],al
retn
attach_empty_segments:
call store_segment_for_undo
attach_segment:
push edx
call allocate_segment
jc memory_shortage
call store_free_segment_for_undo
pop edx
mov ebx,esi
mov esi,eax
mov edi,eax
or eax,1
xchg eax,[ebx]
stosd
mov eax,ebx
or eax,1
stosd
add edi,SEGMENT_HEADER_LENGTH - 8
mov ecx,SEGMENT_DATA_LENGTH shr 2
mov eax,20202020h
rep stosd
sub edx,SEGMENT_DATA_LENGTH
cmp edx,SEGMENT_DATA_LENGTH
jae attach_segment
retn
recognize_character:
cmp al,20h
jb neutral_character
cmp al,30h
jb separator_character
cmp al,3Ah
jb neutral_character
cmp al,40h
jb separator_character
cmp al,5Bh
jb neutral_character
cmp al,5Fh
jb separator_character
cmp al,7Bh
jb neutral_character
cmp al,7Fh
jb separator_character
neutral_character:
clc
retn
separator_character:
stc
retn
delete_character:
call get_caret_segment
delete_here:
cmp edx,SEGMENT_DATA_LENGTH
jae delete_done
call store_segment_for_undo
test [editor_mode],AEMODE_OVERWRITE
jnz blank
lea ebx,[esi+SEGMENT_LENGTH]
mov ecx,SEGMENT_DATA_LENGTH
sub ecx,edx
mov al,20h
mov edi,[esi]
test edi,1
jz shift_data_left
mov al,[edi-1+SEGMENT_HEADER_LENGTH]
shift_data_left:
dec ebx
xchg al,[ebx]
loop shift_data_left
lea esi,[edi-1]
xor edx,edx
test edi,1
jnz delete_here
delete_done:
retn
blank:
mov byte [esi+SEGMENT_HEADER_LENGTH+edx],20h
retn
insert_into_line:
or ecx,ecx
jz void_insert
push ecx esi
call get_caret_segment
test [editor_mode],AEMODE_OVERWRITE
jnz overwrite_in_line
cmp edx,SEGMENT_DATA_LENGTH
jae attach_after_line_end
mov eax,[esp+4]
push edx
xor edx,edx
mov ecx,SEGMENT_DATA_LENGTH
div ecx
mov ebx,esi
push esi
or edx,edx
jnz find_last_segment_to_shift
call store_segment_for_undo
mov esi,[esi]
btr esi,0
jnc following_segments_shifted
call store_segment_for_undo
jmp following_segments_shifted
find_last_segment_to_shift:
test byte [ebx],1
jz shift_following_segments
mov ebx,[ebx]
dec ebx
jmp find_last_segment_to_shift
shift_following_segments:
push edx
call allocate_segment
jc memory_shortage
call store_free_segment_for_undo
pop edx
mov edi,eax
mov esi,[ebx]
mov [edi],esi
mov eax,ebx
or eax,1
mov [edi+4],eax
lea edi,[edi+SEGMENT_HEADER_LENGTH+edx]
mov ecx,SEGMENT_DATA_LENGTH
sub ecx,edx
mov al,20h
rep stosb
sub edi,SEGMENT_LENGTH
carry_to_next_segment:
mov esi,ebx
call store_segment_for_undo
mov eax,edi
or eax,1
mov [esi],eax
add esi,SEGMENT_LENGTH
sub esi,edx
mov ecx,edx
add edi,SEGMENT_HEADER_LENGTH
rep movsb
cmp ebx,[esp]
je following_segments_shifted
mov edi,ebx
mov ebx,[edi+4]
btr ebx,0
push edi
add edi,SEGMENT_LENGTH-1
mov esi,edi
sub esi,edx
mov ecx,SEGMENT_DATA_LENGTH
sub ecx,edx
std
rep movsb
cld
pop edi
jmp carry_to_next_segment
following_segments_shifted:
pop esi edx
insert_more_segments:
mov edi,esi
mov ecx,[esp+4]
make_inserted_segment:
sub ecx,SEGMENT_DATA_LENGTH
jb fill_inserted_segments
push ecx edx
call allocate_segment
jc memory_shortage
call store_free_segment_for_undo
pop edx ecx
mov ebx,[edi]
btr ebx,0
jnc make_attached_segment
or eax,1
mov [edi],eax
mov [ebx+4],eax
and eax,not 1
or ebx,1
mov [eax],ebx
or edi,1
mov [eax+4],edi
mov edi,eax
jmp make_inserted_segment
make_attached_segment:
or eax,1
mov [edi],eax
and eax,not 1
mov [eax],ebx
or edi,1
mov [eax+4],edi
mov edi,eax
jmp make_inserted_segment
fill_inserted_segments:
mov eax,SEGMENT_DATA_LENGTH
add ecx,eax
sub eax,edx
sub eax,ecx
jbe all_shifts_done
mov ecx,eax
lea edi,[edi+SEGMENT_LENGTH-1]
push esi
lea esi,[esi+SEGMENT_HEADER_LENGTH+ecx-1]
add esi,edx
std
rep movsb
cld
pop esi
all_shifts_done:
mov edi,esi
pop esi ebx
fill_new_segment:
mov ecx,SEGMENT_DATA_LENGTH
sub ecx,edx
cmp ecx,ebx
jbe length_for_inserting_ok
mov ecx,ebx
length_for_inserting_ok:
sub ebx,ecx
push edi
lea edi,[edi+SEGMENT_HEADER_LENGTH+edx]
or esi,esi
jz insert_blank_string
rep movsb
jmp string_inserted
insert_blank_string:
mov al,20h
rep stosb
string_inserted:
pop edi
mov edi,[edi]
and edi,not 1
xor edx,edx
or ebx,ebx
jnz fill_new_segment
retn
attach_after_line_end:
call attach_empty_segments
mov ebx,esi
pop esi
or esi,esi
jnz attach_string
pop ecx
retn
attach_string:
mov ecx,[esp]
mov eax,SEGMENT_DATA_LENGTH
sub eax,edx
cmp eax,ecx
jae length_to_attach_ok
mov ecx,eax
length_to_attach_ok:
sub [esp],ecx
lea edi,[ebx+SEGMENT_HEADER_LENGTH+edx]
rep movsb
mov ecx,[esp]
jecxz attach_ok
call allocate_segment
jc memory_shortage
call store_free_segment_for_undo
mov edi,eax
or eax,1
xchg eax,[ebx]
mov [edi],eax
or ebx,1
mov [edi+4],eax
mov ebx,edi
xor edx,edx
jmp attach_string
attach_ok:
pop eax
lea ecx,[ebx+SEGMENT_LENGTH]
sub ecx,edi
mov al,20h
rep stosb
void_insert:
retn
overwrite_in_line:
cmp edx,SEGMENT_DATA_LENGTH
jb position_for_overwrite_ok
call attach_empty_segments
position_for_overwrite_ok:
mov edi,esi
pop esi ebx
overwrite_segment:
xchg esi,edi
call store_segment_for_undo
xchg esi,edi
mov ecx,SEGMENT_DATA_LENGTH
sub ecx,edx
cmp ecx,ebx
jbe length_to_overwrite_ok
mov ecx,ebx
length_to_overwrite_ok:
sub ebx,ecx
push edi
lea edi,[edi+SEGMENT_HEADER_LENGTH+edx]
or esi,esi
jz overwrite_with_blank
rep movsb
jmp overwritten_ok
overwrite_with_blank:
mov al,20h
rep stosb
overwritten_ok:
pop edi
or ebx,ebx
jz overwrite_done
push esi
mov esi,[edi]
btr esi,0
jc overwrite_existing_segment
call allocate_segment
jc memory_shortage
call store_free_segment_for_undo
mov edx,eax
or edx,1
mov [edi],edx
mov [eax],esi
or edi,1
mov [eax+4],edi
mov edi,eax
pop esi
xor edx,edx
cmp ebx,SEGMENT_DATA_LENGTH
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -