📄 edxiug.asm
字号:
;*********************************************************************
;题目2. 文本方式下的字编辑处理程序(4人)*
;设计任务要求与说明(参考教材8,9,10,11章和实验教程3.3节):
; 该编辑程序要求具备的功能:清晰且易于操作的用户界面,在出现的界面
; 中输入任意文本内容,利用DEL键、BACKSPACE键、HOME键、END键、上下
; 左右光标键对文本进行全屏幕编辑。按F1键激活菜单FILE,下移光标,选
; 择SAVE,输入文件名,文本的存盘。按f10激活帮助,按ESC键退出帮助。可
; 以选择FILE菜单的其他菜单项,完成打开文件,文字的插入、删除、修改,
; 文本行、列号的动态显示等功能。
;*********************************************************************
;---------------------------------------------------------------------
red_chr macro ;读取字符宏定义
mov ah,0 ;返回的al=字符码,ah=扫描码
int 16h
endm
;---------------------------------------------------------------------
string macro p1 ;显示字符串信息
mov ah,9
lea dx,p1
int 21h
endm
;---------------------------------------------------------------------
win macro opr1,opr2,opr3,opr4,opr5,opr6 ;建立窗口
mov ah,06h ;0pr1=上卷行数,opr2=行属性
mov al,opr1 ;opr3=左上角行号,opr4=左上角列号
mov bh,opr2 ;opr5=右下角行号,opr6=右下角列号
mov ch,opr3
mov cl,opr4
mov dh,opr5
mov dl,opr6
int 10h
endm
;---------------------------------------------------------------------
pos_curse macro op1,op2,op3 ;定义光标位置
mov ah,2 ;op1=页号,0p2=行号,0p3=列号
mov bh,op1
mov dh,op2
mov dl,op3
int 10h
endm
;---------------------------------------------------------------------
pos_get macro ;显示光标位置
mov ah,03h ;dh=行号,dl=列号
mov bh,0
int 10h
endm
;---------------------------------------------------------------------
;*********************************************************************
data segment ;定义数据段
flag dw ?
color_1 db 32 dup(' '),' Black_to_Blue ',13,10,'$'
color_2 db 32 dup(' '),' Red_to_White ',13,10,'$'
color_3 db 32 dup(' '),' Cyan_to_Red ',13,10,'$'
menu db 'File Edit Format Options Help $'
mess db 'F1-File F2-Edit F3-Format F4-Options F10-help Esc-quit','$'
manu_1 db ' New ',13,10,'$'
manu_2 db ' Open ',13,10,'$'
manu_3 db ' Save ',13,10,'$'
manu_4 db ' Save as ',13,10,'$'
manu_5 db ' Exit ','$'
manu_6 db 6 dup(' '),' Cut ',13,10,'$'
manu_7 db 6 dup(' '),' Copy ',13,10,'$'
manu_8 db 6 dup(' '),' Paste ',13,10,'$'
manu_9 db 6 dup(' '),' Clear ',13,10,'$'
manu_10 db 12 dup(' '),' Font ',13,10,'$'
manu_11 db 20 dup(' '),' Color ',13,10,'$'
manu_12 db 20 dup(' '),' Setting ',13,10,'$'
manu_13 db 29 dup(' '),' Command ',13,10,'$'
manu_14 db 29 dup(' '),' About ',13,10,'$'
handle dw ?
mess1 db ' Please input a file name:','$'
mess2 db ' Please input a saving file name:','$'
mess3 db ' Please input an open file name:','$'
mess4 db ' The file is not saved! Save it now? (Y/N): ','$'
path db 50 dup(0),'$'
buffer db 2000 dup(?)
bak db 3850 dup(0)
line db ?
row db ?
char db ?
help_mas0 db ' About Editor $'
help_mas1 db '************************************************$' ;帮助内容
help_mas2 db '* Thank you for using this editor! *$'
help_mas3 db '* *$'
help_mas4 db '* Smooth Everything! Good luck! *$'
help_mas5 db '*----------------------------------------------*$'
help_mas6 db '* MS-DOS Editor *$'
help_mas7 db '* Copyright <WC-CGP> 2008.1 *$'
help_mas8 db '* <OK> *$'
help_mas9 db '************************************************$'
com_mess0 db ' Edit Commands $'
com_mess1 db '------------------------------------------------------------$'
com_mess2 db ' Home -Move to the start of the current line. $'
com_mess3 db ' End -Move to the end of the current line. $'
com_mess4 db ' Delete -Delete the character that the cursor is on. $'
com_mess5 db ' Backspace -Delete the character to the left of the cursor.$'
com_mess6 db ' Ctrl+Up -Scroll up one line. $'
com_mess7 db ' Ctrl+down -Scroll down one line. $'
com_mess8 db ' Ctrl+Left -Move left one word. $'
com_mess9 db ' Ctrl+right -Move right one word. $'
com_mess10 db ' Enter -Start a new line. $'
com_mess11 db ' Tab -Move the cursor to next tab stop. $'
date db 'DATE:0000/00/00$' ;调用日期
hanglie db 'Lin:000/Com:000$' ;行//列
time db 'TIME:00:00:00$' ;调用时间
data ends
;*********************************************************************
;---------------------------------------------------------------------
code segment
main proc far ;主程序
assume cs:code,ds:data
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
call window ;创建窗口子程序
call edit ;编辑输入的字符
ret
main endp
;---------------------------------------------------------------------
;---------------------------------------------------------------------
window proc near ;创建窗口子程序
win 0,14h,1,0,24,79 ;定义窗口背景
win 1,3fh,0,0,0,79
win 0,3fh,24,0,24,79
show: ;显示菜单位置及内容
pos_curse 0,0,1
string menu
show_2: ;显示状态栏位置及内容
pos_curse 0,24,1
string mess
call win3 ;显示日期
pos_curse 0,1,0
call win4 ;显示行//列
pos_curse 0,1,0
mov row,dh ;dh=1
mov line,dl ;dl=0
ret
window endp
;---------------------------------------------------------------------
;---------------------------------------------------------------------
edit proc near ;编辑输入的字符
char_get: ;读字符
call com
ret
edit endp
;---------------------------------------------------------------------
;---------------------------------------------------------------------
menu_show proc near ;显示菜单
call savedisplay
push cx
cmp ah,3bh
jz menu_file1 ;F1功能File
cmp ah,3ch
jz menu_edit1 ;F2功能Edit
cmp ah,3dh
jz menu_format1 ;F3功能Format
cmp ah,3eh
jz menu_options1 ;F4功能Options
cmp ah,44h
jz menu_help1 ;F10功能Help
jmp char_get
;....................................................................
menu_file1:jmp menu_file
menu_edit1:jmp menu_edit
menu_format1:jmp menu_format
menu_options1:jmp menu_options
menu_help1:jmp menu_help
;....................................................................
menu_file: ;定义菜单的背景字体颜色
pos_get
push dx
win 0,06h,2,1,7,11 ;建立菜单子窗口
win 0,65h,1,0,6,10
pos_curse 0,1,0
string manu_1
string manu_2
string manu_3
string manu_4
string manu_5
pop dx
dec dl
pos_curse 0,dh,dl
copmar:
red_chr ;从I/O读取字符
cmp ah,50h ;向下
jz manu_n
jmp manu_hid
manu_hid: ;菜单隐藏
win 0,1eh,1,1,7,50
call backdisplay
jmp char_get
manu_n: ;开始定义各个菜单项
win 0,65h,5,1,5,8
pos_curse 0,5,0
string manu_5
win 0,65h,2,1,2,8
pos_curse 0,2,0
string manu_2
win 0,06h,1,1,1,8
pos_curse 0,1,0
string manu_1
red_chr
cmp ah,48h ;向上
je manu_ee ;exit
cmp al,0dh ;按回车键选中
jz new_1 ;new
cmp ah,50h ;向下
je manu_o ;open
jmp manu_hid
manu_ee:jmp manu_e ;new to exit
manu_n0:jmp manu_n
new_1: jmp new
manu_nn:jmp manu_n ;open to new
manu_o:
win 0,65h,1,1,1,8
pos_curse 0,1,0
string manu_1
win 0,65h,3,1,3,8
pos_curse 0,3,0
string manu_3
win 0,06h,2,1,2,8
pos_curse 0,2,0
string manu_2
red_chr
cmp ah,48h
je manu_nn ;new
cmp al,0dh
jz open_1 ;open
cmp ah,50h
je manu_s ;save
jmp manu_hid
open_1: jmp open
manu_oo:jmp manu_o ;save to open
manu_s:
win 0,65h,2,1,2,8
pos_curse 0,2,0
string manu_2
win 0,65h,4,1,4,8
pos_curse 0,4,0
string manu_4
win 0,06h,3,1,3,8
pos_curse 0,3,0
string manu_3
red_chr
cmp al,0dh
jz save_1 ;save
cmp ah,48h
je manu_oo ;open
cmp ah,50h
je manu_a ;saveas
jmp manu_hid
save_1: call save
manu_ss:jmp manu_s ;saveas to save
manu_a:
win 0,65h,3,1,3,8
pos_curse 0,3,0
string manu_3
win 0,65h,5,1,5,8
pos_curse 0,5,0
string manu_5
win 0,06h,4,1,4,8
pos_curse 0,4,0
string manu_4
red_chr
cmp ah,1ch
jz save_2 ;saveas
cmp ah,48h
je manu_ss ;save
cmp ah,50h
je manu_e ;exit
jmp manu_hid
manu_n2:jmp manu_n
manu_as:jmp manu_a
save_2: call saveas
manu_e:
win 0,65h,4,1,4,8
pos_curse 0,4,0
string manu_4
win 0,65h,1,1,1,8
pos_curse 0,1,0
string manu_1
win 0,06h,5,1,5,8
pos_curse 0,5,0
string manu_5
red_chr
cmp ah,50h
je manu_n2 ;new
cmp ah,48h
je manu_as ;saveas
cmp ah,1ch
je exit ;exit
jmp manu_hid
exit:
call backdisplay
win 0,07h,15,10,17,61
win 0,24h,14,9,16,60
mov dh,15
mov dl,9
mov bh,0
mov ah,2
int 10h
lea dx,mess4
mov ah,9
int 21h
mov ah,1
int 21h
cmp al,79h
jnz q
call quitt
q: cmp al,6eh
jz quit
quit: win 0,07h,0,0,24,79
pos_curse 0,0,0
mov ah,4ch
int 21h
ret ;结束,退出程序
;....................................................................
menu_edit: ;选中edit菜单
pos_get
push dx
win 0,06h,2,8,6,18 ;建立菜单子窗口
win 0,65h,1,7,5,17
pos_curse 0,1,0
string manu_6
string manu_7
string manu_8
string manu_9
pop dx
dec dl
pos_curse 0,dh,dl
red_chr ;从I/O读取字符
cmp ah,50h ;向下
jz manu_copy
jmp manu_hid
manu_copy: ;开始定义各个菜单项
win 0,65h,4,7,4,17
pos_curse 0,4,0
string manu_9
win 0,65h,2,7,2,17
pos_curse 0,2,0
string manu_7
win 0,06h,1,7,1,17
pos_curse 0,1,0
string manu_6
red_chr
cmp ah,48h ;向上
je manu_clear1 ;clear
cmp al,0dh ;按回车键选中
jz manu_copy ;copy
cmp ah,50h ;向下
je manu_cut ;cut
jmp manu_hid
manu_clear1:jmp manu_clear
manu_copy1:jmp manu_copy
manu_cut:
win 0,65h,3,7,3,17
pos_curse 0,3,0
string manu_8
win 0,65h,1,7,1,17
pos_curse 0,1,0
string manu_6
win 0,06h,2,7,2,17
pos_curse 0,2,0
string manu_7
red_chr
cmp ah,48h ;向上
je manu_copy1 ;copy
cmp al,0dh ;按回车键选中
jz manu_cut ;cut
cmp ah,50h ;向下
je manu_paste ;paste
jmp manu_hid
manu_cut1:jmp manu_cut
manu_paste:
win 0,65h,4,7,4,17
pos_curse 0,4,0
string manu_9
win 0,65h,2,7,2,17
pos_curse 0,2,0
string manu_7
win 0,06h,3,7,3,17
pos_curse 0,3,0
string manu_8
red_chr
cmp ah,48h ;向上
je manu_cut1 ;cut
cmp al,0dh ;按回车键选中
jz manu_paste ;paste
cmp ah,50h ;向下
je manu_clear ;clear
jmp manu_hid
manu_paste1:jmp manu_paste
manu_copy2:jmp manu_copy
manu_clear:
win 0,65h,1,7,1,17
pos_curse 0,1,0
string manu_6
win 0,65h,3,7,3,17
pos_curse 0,3,0
string manu_8
win 0,06h,4,7,4,17
pos_curse 0,4,0
string manu_9
red_chr
cmp ah,48h ;向上
je manu_paste1 ;paste
cmp al,0dh ;按回车键选中
jz manu_clear ;clear
cmp ah,50h ;向下
je manu_copy2 ;copy
jmp manu_hid
;....................................................................
menu_format:
pos_get
push dx
win 0,06h,2,14,3,24 ;建立菜单子窗口
win 0,65h,1,13,2,23
pos_curse 0,1,0
string manu_10
pop dx
dec dl
pos_curse 0,dh,dl
red_chr ;从I/O读取字符
cmp ah,50h ;向下
jz manu_font ;font
jmp manu_hid
manu_font:
win 0,06h,1,13,1,23
pos_curse 0,1,0
string manu_10
red_chr
cmp al,0dh ;按回车键选中
jz font1 ;font
jmp manu_hid
font1: call font ;调用font子程序,获取当前时间(子程序接口,亦可用于选择字型号)
;font1: jmp manu_hid
;....................................................................
menu_options:
pos_get
push dx
win 0,06h,2,22,4,32 ;建立菜单子窗口
win 0,65h,1,21,3,31
pos_curse 0,1,0
string manu_11
string manu_12
pop dx
dec dl
pos_curse 0,dh,dl
red_chr ;从I/O读取字符
cmp ah,50h ;向下
jz manu_color
jmp manu_hid
manu_color:
win 0,65h,2,21,2,31
pos_curse 0,2,0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -