📄 fasmd.asm
字号:
mov [screen_width],edx
shl edx,1
mov [video_pitch],edx
movzx eax,byte [fs:84h]
inc eax
mov [screen_height],eax
imul edx,eax
push edx
dec edx
shld ecx,edx,16
mov ax,8
int 31h
jc video_init_failed
pop ecx
call get_memory
jc video_init_failed
mov [video_storage],eax
mov [video_storage_handle],ebx
clc
ret
video_init_failed:
stc
ret
check_video_mode:
test byte [fs:65h],110b
jnz set_video_mode
cmp byte [fs:4Ah],80
jb set_video_mode
ret
set_video_mode:
mov ax,3
int 10h
ret
close_video:
mov ebx,[video_storage_handle]
call release_memory
ret
switch_to_ide_screen:
call check_video_mode
xor esi,esi
mov edi,[video_storage]
mov ecx,[video_pitch]
imul ecx,[screen_height]
rep movs byte [es:edi],[gs:esi]
mov ah,3
xor bh,bh
int 10h
mov [stored_cursor],cx
mov [stored_cursor_position],dx
mov ah,0Fh
int 10h
mov [stored_page],bh
mov ax,0500h
int 10h
mov al,[fs:65h]
mov [stored_mode],al
mov ax,1003h
xor bx,bx
int 10h
mov eax,[screen_width]
mov [window_width],eax
mov eax,[screen_height]
sub eax,2
mov [window_height],eax
call update_window
ret
switch_to_user_screen:
push es gs
pop es
mov esi,[video_storage]
xor edi,edi
mov ecx,[video_pitch]
imul ecx,[screen_height]
rep movs byte [es:edi],[ds:esi]
mov ah,1
mov cx,[stored_cursor]
int 10h
mov ah,2
xor bh,bh
mov dx,[stored_cursor_position]
int 10h
mov ah,5
mov al,[stored_page]
int 10h
mov ax,1003h
xor bh,bh
mov bl,[stored_mode]
shr bl,5
and bl,1
int 10h
pop es
ret
create_editor_instance:
call flush_editor_data
mov esi,[editor_memory]
find_last_instance:
mov eax,[esi+16+next_instance-editor_data]
or eax,eax
jz attach_new_instance
mov esi,eax
jmp find_last_instance
attach_new_instance:
push esi
call init_editor_memory
pop esi
jc not_enough_memory
mov eax,[editor_memory]
xchg eax,[esi+16+next_instance-editor_data]
mov [next_instance],eax
mov [previous_instance],esi
xor eax,eax
mov [file_path],eax
flush_editor_data:
mov edi,[editor_memory]
add edi,16
mov esi,editor_data
mov ecx,editor_data_size
rep movsb
ret
switch_editor_instance:
call flush_editor_data
cmp eax,[editor_memory]
je editor_switch_ok
mov [editor_memory],eax
lea esi,[eax+16]
mov edi,editor_data
mov ecx,editor_data_size
rep movsb
editor_switch_ok:
call update_positions
ret
remove_editor_instance:
mov eax,[editor_memory]
xor eax,[main_project_file]
jnz main_project_file_ok
mov [main_project_file],eax
main_project_file_ok:
mov esi,[previous_instance]
mov edi,[next_instance]
mov eax,edi
or edi,edi
jz next_instance_links_ok
mov [edi+16+previous_instance-editor_data],esi
next_instance_links_ok:
or esi,esi
jz previous_instance_links_ok
mov [esi+16+next_instance-editor_data],edi
mov eax,esi
previous_instance_links_ok:
push eax
call release_editor_memory
mov eax,[file_path]
or eax,eax
jz file_path_released
mov ebx,[file_path_handle]
call release_memory
file_path_released:
pop eax
or eax,eax
jz no_instance_left
call switch_editor_instance
clc
ret
no_instance_left:
stc
ret
load_file:
push edx [editor_memory]
call get_full_pathname
push esi
call flush_editor_data
mov esi,[esp]
mov edx,[editor_memory]
prepare_to_scan_editors:
mov eax,[edx+16+previous_instance-editor_data]
or eax,eax
jz scan_editors
mov edx,eax
jmp prepare_to_scan_editors
scan_editors:
mov edi,[edx+16+file_path-editor_data]
or edi,edi
jz scan_next_editor
xor ecx,ecx
mov ebx,case_table
compare_pathnames:
mov al,[esi+ecx]
xlatb
mov ah,al
mov al,[edi+ecx]
xlatb
cmp al,ah
jne scan_next_editor
or al,ah
jz file_found
inc ecx
jmp compare_pathnames
scan_next_editor:
mov edx,[edx+16+next_instance-editor_data]
or edx,edx
jnz scan_editors
mov eax,[undo_data]
or eax,[file_path]
jz open_in_current_instance
call create_editor_instance
open_in_current_instance:
pop esi
call use_pathname
mov edx,[file_path]
call open
jc load_failed
xor edx,edx
mov al,2
call lseek
push eax ebx
lea ecx,[eax+1]
call get_memory
or eax,eax
jz not_enough_memory
mov esi,eax
mov edi,ecx
pop ebx
xor edx,edx
xor al,al
call lseek
pop ecx
mov edx,esi
mov byte [edx+ecx],0
call read
jc load_failed
call close
push edi
call set_text
pop ebx
call release_memory
add esp,8
ret
file_found:
mov eax,edx
call switch_editor_instance
pop esi
add esp,8
ret
load_failed:
mov eax,[previous_instance]
or eax,[next_instance]
jnz cancel_instance
cancel_path_only:
xor ebx,ebx
xchg ebx,[file_path]
call release_memory
jmp editor_cancelled
cancel_instance:
mov eax,[editor_memory]
cmp eax,[esp]
je cancel_path_only
call remove_editor_instance
editor_cancelled:
pop eax
call switch_editor_instance
call update_screen
mov edi,buffer
mov esi,_loading_error
mov ebx,esp
call sprintf
pop eax
mov esi,buffer
mov ebx,_error
movzx eax,[error_box_colors]
call message_box
ret
get_full_pathname:
call adapt_path
sub edi,buffer
mov ax,7160h
xor cx,cx
xor si,si
stc
call dos_int
jnc got_full_pathname
mov ah,60h
call dos_int
jc full_pathname_exit
got_full_pathname:
lea esi,[buffer + edi]
cmp word [esi],'\\'
jne full_pathname_ok
cmp dword [esi+3],'.\A.'
jne full_pathname_ok
mov al,[esi+2]
mov ah,':'
add esi,5
mov [esi],ax
full_pathname_ok:
clc
full_pathname_exit:
ret
use_pathname:
mov edi,[file_path]
or edi,edi
jnz copy_pathname
mov ecx,1000h
push esi
call get_memory
pop esi
or eax,eax
jz not_enough_memory
mov edi,eax
mov [file_path],edi
mov [file_path_handle],ebx
copy_pathname:
lodsb
stosb
or al,al
jnz copy_pathname
ret
save_file:
mov edx,[file_path]
call create
jc file_creation_error
mov [file_handle],ebx
mov esi,[first_line]
mov edi,[line_buffer]
copy_text:
mov ecx,[esi+8]
lea eax,[edi+ecx]
mov edx,[line_buffer_size]
shr edx,1
sub eax,edx
cmp eax,[line_buffer]
ja flush_to_file
mov ebp,edi
xor edx,edx
push ecx
call copy_from_line
pop ecx
test [editor_style],AES_OPTIMALFILL
jz line_copied
cmp ecx,8
jb line_copied
push esi edi ecx
mov esi,ebp
mov edi,[line_buffer]
mov eax,[line_buffer_size]
shr eax,1
add edi,eax
push edi
mov ecx,[esp+4]
xor al,al
rep stosb
mov ecx,[esp+4]
mov edi,[esp]
call syntax_proc
pop ebx ecx edi
mov esi,ebp
mov edi,ebp
sub ebx,esi
xor edx,edx
optimal_fill:
lodsb
cmp al,20h
jne store_character
cmp byte [esi-1+ebx],0
jne store_character
mov eax,esi
sub eax,ebp
test eax,111b
jz store_tab
inc edx
mov al,20h
stosb
loop optimal_fill
jmp optimal_fill_done
store_tab:
mov al,20h
or edx,edx
jz store_character
sub edi,edx
mov al,9
store_character:
stosb
xor edx,edx
loop optimal_fill
optimal_fill_done:
pop esi
jmp line_copied
line_copied:
or esi,esi
jz flush_to_file
mov ax,0A0Dh
stosw
jmp copy_text
flush_to_file:
push esi
mov edx,[line_buffer]
mov ecx,edi
sub ecx,edx
mov ebx,[file_handle]
call write
jc file_writing_error
pop esi
mov edi,[line_buffer]
or esi,esi
jnz copy_text
mov ebx,[file_handle]
call close
call clear_undo_data
clc
ret
file_writing_error:
add esp,4
file_creation_error:
call update_screen
mov esi,_saving_error
mov ebx,_error
movzx eax,[error_box_colors]
call message_box
stc
ret
get_saving_path:
mov esi,_save_as
call file_open_dialog
jc saving_aborted
push edx
call open
pop edx
jc saving_allowed
push edx
call close
call update_screen
mov edi,buffer
mov esi,_overwrite_question
mov ebx,esp
call sprintf
mov esi,buffer
mov ebx,_save_as
mov eax,2 shl 24
mov ax,[message_box_colors]
mov [first_button],_yes
mov [second_button],_no
call message_box
pop edx
cmp eax,1
jb saving_aborted
je saving_allowed
call update_screen
jmp get_saving_path
saving_allowed:
call get_full_pathname
jc invalid_saving_path
call use_pathname
clc
ret
invalid_saving_path:
call update_screen
mov esi,_invalid_path
mov ebx,_error
movzx eax,[error_box_colors]
call message_box
saving_aborted:
stc
ret
update_positions:
mov eax,[screen_width]
mov [window_width],eax
mov eax,[screen_height]
sub eax,2
mov [window_height],eax
call update_window
ret
update_cursor:
xor bh,bh
mov edx,[caret_position]
sub edx,[window_position]
jc cursor_out_of_sight
cmp edx,[window_width]
jae cursor_out_of_sight
mov eax,[caret_line_number]
sub eax,[window_line_number]
jc cursor_out_of_sight
cmp eax,[window_height]
jae cursor_out_of_sight
inc al
mov dh,al
mov ah,2
int 10h
test [editor_mode],AEMODE_OVERWRITE
jnz block_cursor
mov ah,1
mov cx,0D0Eh
int 10h
ret
block_cursor:
mov ah,1
mov cx,000Fh
int 10h
ret
cursor_out_of_sight:
mov ah,1
mov cx,1000h
int 10h
ret
; Text drawing
update_screen:
call update_title_bar
mov eax,[peak_line_length]
xor edx,edx
mov ebx,SEGMENT_DATA_LENGTH
div ebx
inc eax
mul ebx
shl eax,1
mov ecx,eax
cmp [line_buffer],0
je line_buffer_reallocate
cmp ecx,[line_buffer_size]
jbe line_buffer_ok
mov [line_buffer],0
push ecx
mov ebx,[line_buffer_handle]
call release_memory
pop ecx
line_buffer_reallocate:
call get_memory
or eax,eax
jz memory_shortage
mov [line_buffer],eax
mov [line_buffer_handle],ebx
line_buffer_ok:
mov esi,[window_line]
mov edx,[window_line_number]
mov eax,[video_pitch]
mov [screen_offset],eax
mov edi,[line_buffer]
prepare_line:
add esi,SEGMENT_HEADER_LENGTH
mov ecx,SEGMENT_DATA_LENGTH
rep movsb
mov esi,[esi-SEGMENT_LENGTH]
btr esi,0
jc prepare_line
push esi edx
mov ecx,edi
mov esi,[line_buffer]
sub ecx,esi
push ecx
mov al,[text_colors]
and al,0Fh
rep stosb
mov esi,[line_buffer]
mov ecx,[esp]
lea edi,[esi+ecx]
call syntax_proc
line_prepared:
mov edi,screen_row_buffer
mov ecx,[window_width]
mov al,20h
mov ah,[text_colors]
rep stosw
pop ecx
mov esi,[line_buffer]
lea ebx,[esi+ecx]
add esi,[window_position]
add ebx,[window_position]
sub ecx,[window_position]
jbe text_drawing_ok
mov edi,screen_row_buffer
cmp ecx,[window_width]
jbe draw_text
mov ecx,[window_width]
draw_text:
movsb
mov al,[text_colors]
and al,0F0h
or al,[ebx]
stosb
inc ebx
loop draw_text
text_drawing_ok:
mov edi,screen_row_buffer
cmp [selection_line],0
je selection_marked
mov eax,[selection_line_number]
cmp eax,[caret_line_number]
jne mark_multiline_selection
cmp eax,[esp]
jne selection_marked
mark_simple_selection:
mov eax,[selection_position]
mov ecx,[caret_position]
cmp eax,ecx
jbe simple_selection_boundaries_ok
xchg eax,ecx
simple_selection_boundaries_ok:
sub ecx,[window_position]
jbe selection_marked
sub eax,[window_position]
jae simple_selection_start_ok
xor eax,eax
simple_selection_start_ok:
cmp ecx,[window_width]
jbe simple_selection_length_ok
mov ecx,[window_width]
simple_selection_length_ok:
sub ecx,eax
jbe selection_marked
lea edi,[screen_row_buffer+eax*2]
draw_selection:
inc edi
mov al,[selection_colors]
stosb
loop draw_selection
jmp selection_marked
mark_multiline_selection:
test [editor_mode],AEMODE_VERTICALSEL
jnz mark_vertical_selection
mov eax,[selection_line_number]
mov ebx,[selection_position]
mov edx,[caret_line_number]
mov ebp,[caret_position]
cmp eax,edx
jbe multiline_selection_boundaries_ok
xchg eax,edx
xchg ebx,ebp
multiline_selection_boundaries_ok:
mov edi,screen_row_buffer
mov ecx,[window_width]
cmp eax,[esp]
ja selection_marked
je mark_selection_start
cmp edx,[esp]
ja draw_selection
jb selection_marked
mark_selection_end:
cmp ebp,[window_position]
jbe selection_marked
sub ebp,[window_position]
cmp ecx,ebp
jbe draw_selection
mov ecx,ebp
jmp draw_selection
mark_selection_start:
sub ebx,[window_position]
jbe draw_selection
sub ecx,ebx
jbe selection_marked
lea edi,[edi+ebx*2]
jmp draw_selection
mark_vertical_selection:
mov eax,[selection_line_number]
mov edx,[caret_line_number]
sub eax,[esp]
jz mark_simple_selection
sub edx,[esp]
jz mark_simple_selection
xor eax,edx
js mark_simple_selection
selection_marked:
push es gs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -