⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edit.inc

📁 一个用纯汇编 写的操作系统 源代码 是用 TASM 编译器写的
💻 INC
📖 第 1 页 / 共 2 页
字号:
	jae	overwrite_segment
	mov	ecx,SEGMENT_DATA_LENGTH
	sub	ecx,ebx
	lea	edi,[edi+SEGMENT_HEADER_LENGTH+ebx]
	mov	al,20h
	rep	stosb
	sub	edi,SEGMENT_LENGTH
	jmp	overwrite_segment
    overwrite_existing_segment:
	call	store_segment_for_undo
	mov	edi,esi
	xor	edx,edx
	pop	esi
	jmp	overwrite_segment
    overwrite_done:
	retn

delete_from_line:
	or	ecx,ecx
	jz	nothing_to_delete
	test	[editor_mode],AEMODE_OVERWRITE
	jnz	clear_in_line
	push	ecx
	add	[caret_position],ecx
	call	get_caret_segment
	pop	ecx
	sub	[caret_position],ecx
	cmp	edx,SEGMENT_DATA_LENGTH
	jae	clear_rest_of_line
	push	esi edx
	call	get_caret_segment
	call	store_segment_for_undo
	mov	edi,esi
	mov	ebx,edx
	pop	edx esi
    shift_over_deleted:
	mov	ecx,SEGMENT_DATA_LENGTH
	mov	eax,ecx
	sub	ecx,ebx
	sub	eax,edx
	cmp	eax,ecx
	jae	size_to_shift_ok
	mov	ecx,eax
    size_to_shift_ok:
	push	esi edi
	lea	esi,[esi+SEGMENT_HEADER_LENGTH+edx]
	lea	edi,[edi+SEGMENT_HEADER_LENGTH+ebx]
	add	edx,ecx
	add	ebx,ecx
	rep	movsb
	pop	edi
	cmp	ebx,SEGMENT_DATA_LENGTH
	je	next_destination_segment
	pop	esi
	cmp	edx,SEGMENT_DATA_LENGTH
	jne	shift_over_deleted
	mov	esi,[esi]
	btr	esi,0
	jnc	cut_line
	xor	edx,edx
	jmp	shift_over_deleted
    next_destination_segment:
	mov	esi,[edi]
	btr	esi,0
	call	store_segment_for_undo
	mov	edi,esi
	pop	esi
	xor	ebx,ebx
	jmp	shift_over_deleted
    cut_line:
	mov	esi,edi
	mov	edx,ebx
	jmp	clear_from_here
    clear_in_line:
	xor	esi,esi
	jmp	insert_into_line
  clear_rest_of_line:
	call	get_caret_segment
	cmp	edx,SEGMENT_DATA_LENGTH
	jae	no_line_tail_to_clear
	call	store_segment_for_undo
    clear_from_here:
	lea	edi,[esi+SEGMENT_HEADER_LENGTH+edx]
	mov	ecx,SEGMENT_DATA_LENGTH
	sub	ecx,edx
	mov	al,20h
	rep	stosb
	mov	ebx,esi
	mov	esi,[ebx]
    remove_following_segments:
	btr	esi,0
	jnc	rest_of_line_cleared
	call	store_segment_for_undo
	or	eax,-1
	xchg	eax,[esi]
	mov	esi,eax
	inc	[released_segments]
	jmp	remove_following_segments
    rest_of_line_cleared:
	mov	[ebx],esi
    nothing_to_delete:
	retn
    no_line_tail_to_clear:
	mov	esi,[esi]
	retn
break_line:
	test	[editor_mode],AEMODE_OVERWRITE
	jnz	go_to_next_line
	push	ebx
	call	allocate_segment
	jc	memory_shortage
	call	store_free_segment_for_undo
	mov	edi,eax
	mov	eax,[caret_line]
	mov	[edi+4],eax
	mov	ebx,[esp]
	push	edi
	add	edi,SEGMENT_HEADER_LENGTH
	mov	ecx,SEGMENT_DATA_LENGTH shr 2
	mov	eax,20202020h
	rep	stosd
	call	get_caret_segment
	call	store_segment_for_undo
	mov	edi,[esp]
	cmp	edx,SEGMENT_DATA_LENGTH
	jae	empty_new_line
	push	esi edx
    new_line_segment:
	cmp	ebx,SEGMENT_DATA_LENGTH
	jb	new_line_segments_ok
	push	edi ebx
	call	allocate_segment
	jc	memory_shortage
	call	store_free_segment_for_undo
	mov	esi,eax
	lea	edi,[esi+SEGMENT_HEADER_LENGTH]
	mov	ecx,SEGMENT_DATA_LENGTH shr 2
	mov	eax,20202020h
	rep	stosd
	pop	ebx edi
	sub	ebx,SEGMENT_DATA_LENGTH
	mov	eax,esi
	or	eax,1
	mov	[edi],eax
	or	edi,1
	mov	[esi+4],edi
	mov	edi,esi
	jmp	new_line_segment
    new_line_segments_ok:
	pop	edx esi
    split_data:
	cmp	ebx,edx
	jbe	indent_data
	push	esi edi
	mov	ecx,SEGMENT_DATA_LENGTH
	sub	ecx,ebx
	lea	esi,[esi+SEGMENT_HEADER_LENGTH+edx]
	lea	edi,[edi+SEGMENT_HEADER_LENGTH+ebx]
	add	edx,ecx
	mov	eax,ecx
	rep	movsb
	mov	edi,esi
	sub	edi,eax
	mov	ecx,eax
	mov	al,20h
	rep	stosb
	push	edx
	call	allocate_segment
	jc	memory_shortage
	call	store_free_segment_for_undo
	pop	edx edi esi
	mov	ebx,eax
	or	eax,1
	mov	[edi],eax
	or	edi,1
	mov	[ebx+4],edi
	mov	edi,ebx
	xor	ebx,ebx
	jmp	split_data
    indent_data:
	push	edi
	mov	ecx,SEGMENT_DATA_LENGTH
	sub	ecx,edx
	mov	eax,ecx
	lea	esi,[esi+SEGMENT_HEADER_LENGTH+edx]
	lea	edi,[edi+SEGMENT_HEADER_LENGTH+ebx]
	rep	movsb
	add	ebx,eax
	mov	edi,esi
	sub	edi,eax
	mov	ecx,eax
	mov	al,20h
	rep	stosb
	pop	edi
	mov	eax,[esp]
	xchg	eax,[esi-SEGMENT_LENGTH]
	btr	eax,0
	jnc	finish_new_line
    shift_splitted_data:
	mov	esi,eax
	or	eax,1
	mov	[edi],eax
	call	store_segment_for_undo
	mov	eax,edi
	or	eax,1
	mov	[esi+4],eax
	mov	ecx,SEGMENT_DATA_LENGTH
	sub	ecx,ebx
	lea	edi,[edi+SEGMENT_HEADER_LENGTH+ebx]
	add	esi,SEGMENT_HEADER_LENGTH
	mov	eax,esi
	rep	movsb
	mov	edi,eax
	mov	ecx,ebx
	rep	movsb
	sub	edi,ebx
	sub	edi,SEGMENT_HEADER_LENGTH
	mov	eax,[edi]
	btr	eax,0
	jc	shift_splitted_data
    finish_new_line:
	mov	esi,edi
	call	store_segment_for_undo
	mov	[edi],eax
	pop	esi
	or	eax,eax
	jz	new_line_pointers_ok
	xchg	esi,eax
	call	store_segment_for_undo
	xchg	esi,eax
	mov	[eax+4],esi
    new_line_pointers_ok:
	mov	ecx,SEGMENT_DATA_LENGTH
	sub	ecx,ebx
	lea	edi,[edi+SEGMENT_HEADER_LENGTH+ebx]
	mov	al,20h
	rep	stosb
	xchg	[caret_line],esi
	inc	[caret_line_number]
	call	check_line_length
	mov	esi,[caret_line]
	mov	dword [esi+8],0
	call	check_line_length
	inc	[lines_count]
	pop	[caret_position]
	retn
    empty_new_line:
	pop	edi
	mov	eax,[esi]
	mov	[esi],edi
	mov	[edi],eax
	or	eax,eax
	jz	empty_line_pointers_ok
	mov	[eax+4],edi
    empty_line_pointers_ok:
	mov	dword [edi+8],0
	mov	[caret_line],edi
	inc	[caret_line_number]
	inc	[lines_count]
	pop	[caret_position]
	retn
  go_to_next_line:
	mov	[caret_position],ebx
	mov	esi,[caret_line]
    skip_line_segments:
	mov	eax,[esi]
	btr	eax,0
	jnc	line_segments_skipped
	mov	esi,eax
	jmp	skip_line_segments
    line_segments_skipped:
	or	eax,eax
	jz	no_next_line
	mov	[caret_line],eax
    next_line_ok:
	inc	[caret_line_number]
	retn
    no_next_line:
	call	store_segment_for_undo
	call	allocate_segment
	jc	memory_shortage
	call	store_free_segment_for_undo
	mov	[esi],eax
	mov	edi,eax
	mov	[caret_line],edi
	xor	eax,eax
	stosd
	mov	[edi],esi
	add	edi,4
	stosd
	add	edi,SEGMENT_HEADER_LENGTH - 12
	mov	ecx,SEGMENT_DATA_LENGTH shr 2
	mov	eax,20202020h
	rep	stosd
	inc	[lines_count]
	jmp	next_line_ok

cut_line_break:
	test	[editor_mode],AEMODE_OVERWRITE
	jnz	do_nothing
	call	get_caret_segment
	cmp	edx,SEGMENT_DATA_LENGTH
	jbe	segment_for_deleting_ok
	call	store_segment_for_undo
    add_empty_segment:
	push	edx esi
	call	allocate_segment
	jc	memory_shortage
	call	store_free_segment_for_undo
	pop	ebx edx
	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
	ja	add_empty_segment
    segment_for_deleting_ok:
	call	store_segment_for_undo
	mov	edi,esi
	mov	esi,[esi]
	btr	esi,0
	jc	append_segment
	call	cancel_line
    append_segment:
	or	esi,esi
	jz	fill_rest_with_spaces
	call	store_segment_for_undo
	or	byte [edi],1
	lea	eax,[edi+1]
	mov	[esi+4],eax
	mov	ecx,SEGMENT_DATA_LENGTH
	sub	ecx,edx
	mov	eax,ecx
	add	esi,SEGMENT_HEADER_LENGTH
	lea	edi,[edi+SEGMENT_HEADER_LENGTH+edx]
	rep	movsb
	mov	edi,esi
	sub	edi,eax
	mov	ecx,edx
	rep	movsb
	sub	esi,SEGMENT_LENGTH
	mov	edi,esi
	mov	esi,[esi]
	btr	esi,0
	jc	append_segment
    fill_rest_with_spaces:
	lea	edi,[edi+SEGMENT_HEADER_LENGTH+edx]
	mov	ecx,SEGMENT_DATA_LENGTH
	sub	ecx,edx
	mov	al,20h
	rep	stosb
	or	esi,esi
	jz	delete_done
	call	store_segment_for_undo
	mov	eax,[caret_line]
	mov	[esi+4],eax
    do_nothing:
	retn

cancel_line:
	dec	[lines_count]
	mov	eax,[esi+8]
	call	unregister_length
	cmp	esi,[window_line]
	jne	window_line_ok
	mov	eax,[caret_line]
	mov	[window_line],eax
	mov	eax,[caret_line_number]
	mov	[window_line_number],eax
    window_line_ok:
	cmp	esi,[first_line]
	jne	first_line_ok
	mov	eax,[caret_line]
	mov	[first_line],eax
    first_line_ok:
	retn

set_text:
	push	esi
	call	reset_editor_memory
	pop	esi
	mov	ebx,[first_line]
	or	esi,esi
	jz	new_text_ok
    set_text_line:
	call	set_line
	jc	new_text_ok
	call	allocate_segment
	jc	memory_shortage
	mov	[ebx],eax
	mov	ebx,eax
	mov	eax,[caret_line]
	mov	[ebx+4],eax
	mov	[caret_line],ebx
	inc	[lines_count]
	jmp	set_text_line
    new_text_ok:
	mov	dword [ebx],0
	mov	eax,[first_line]
	mov	[caret_line],eax
	mov	[caret_position],0
	retn

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -