📄 edit.asm
字号:
red_chr macro ;读取字符宏定义
mov ah,0
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
mov al,opr1 ;上卷行数
mov bh,opr2 ;卷入行属性
mov ch,opr3 ;左上角行号
mov cl,opr4 ;左上角列号
mov dh,opr5 ;右上角行号
mov dl,opr6 ;右上角列号
int 10h
endm
pos_curse macro op1,op2,op3 ;定义光标位置
mov ah,2
mov bh,op1 ;页号
mov dh,op2 ;行
mov dl,op3 ;列
int 10h
endm
pos_get macro ;读光标位置
mov ah,03h
mov bh,0 ;页号
int 10h
endm
data segment ;定义数据段
menu db 'File Edit Exit Help $'
mass_1 db 'F1 File F2 Edit F4 Exit F10 Help','$'
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 ' copy ',13,10,'$'
manu_7 db ' cut ',13,10,'$'
manu_8 db ' paste ',13,10,'$'
handle dw ?
message1 db ' Please input file name:','$'
message2 db ' Please input save file name:','$'
message3 db ' Please input open file name:','$'
message4 db ' ***The file is not save! 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 ?
END_KEY db ?
help_mas1 db ' welcome use editor! $' ;帮助内容
help_mas2 db 'please the first active help! $'
help_mas3 db 'good lucky!! $'
help_mas4 db '==========================================================$'
help_mas5 db 'Press F1 to file. $'
help_mas6 db 'You can use DOWN cursor key to choose the fuction $'
help_mas7 db 'Press F10 to show the help massage.Press Esc To Quit $'
date db 'today ??/??/ $'
hanglie db '???//??? $'
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 wind
call edit
ret
main endp
wind proc near ;创建窗口子程序
win 0,3eh,1,0,24,79 ;定义窗口背景
win 1,1fh,0,0,0,79
win 0,1fh,24,0,24,79
show: ;显示菜单位置及内容
pos_curse 0,0,1
mov ah,9
lea dx,menu
int 21h
show_2:
pos_curse 0,24,1
mov ah,9
lea dx,mass_1
int 21h
call win3 ;显示时间
call win4 ;显示行数和列数
pos_curse 0,1,0
mov row,dh ;行
mov line,dl ;列
wind endp
edit proc near
char_get: ;读字符
call com
com proc near ;定义功能鍵
pos_get ;读光标位置
mov row,dh
mov line,dl
first:
pos_curse 0,row,line
j00: mov ah,0
int 16h ;从键盘读字符 ah=扫描码 al=字符码
push ax
lea dx,buffer
mov buffer[bx],al
inc bx
cmp ah,48h ;上
jz up_1
cmp ah,50h ;下
jz down_1
cmp ah,4bh ;左
jz left
cmp ah,4dh ;右
jz right
cmp ah,1ch ;回车
jz enter_1
call fuc_key
mov ah,2 ;显示 输出字符
mov dl,al
int 21h
pop ax
call menu_show
jmp j6
down_1:
jmp down
enter_1:
jmp enter_2
up_1: jmp up
left: ;光标左移
pos_get ;读光标位置
mov row,dh
mov line,dl
cmp line,0
jnz direct
mov line,79
dec row
cmp row,0
je stop2
jmp first
stop2:
mov row,1
jmp first
direct:
dec line
call win4 ;显示光标位置
jmp first
right: ;光标右移
pos_get
mov row,dh
mov line,dl
cmp line,79
jnz direct2
mov line,0
inc row
cmp row,24
je returns1
jmp first
direct2:
inc line
call win4 ;显示光标位置
jmp first
enter_2:
jmp enterg
up: ;上移光标
pos_get
mov row,dh
mov line,dl
dec row
cmp row,0
je stop1
call win4 ;显示光标位置
jmp first
stop1:
mov row,1
jmp first
down: ;下移光标
pos_get
mov row,dh
mov line,dl
inc row
cmp row,24
je stop3
call win4 ;显示光标位置
jmp first
stop3:
mov row,23
jmp first
returns1:
jmp returns
enterg: ;回车换行
pos_get
mov row,dh
mov line,dl
inc row
cmp row,24
je returns
mov line,0
call win4 ;显示光标位置
jmp first
returns:
mov row,24
mov line,0
jmp first
j6:
ret
com endp
fuc_key proc near ;功能键子程序
next:
cmp ah,47h ;home
jz home
cmp ah,4fh ;end
jz _end
cmp ah,0eh ;backspace
jz bak_sp
cmp ah,53h ;Del
jz del
cmp ah,44h ;F10
jz help_0
ret
help_0: call help
home: ;HOME键的功能
pos_get
mov row,dh
mov line,0
call win4 ;显示光标位置
jmp first
_end: ;END键的功能
pos_get
mov row,dh
mov line,79
call win4 ;显示光标位置
jmp first
bak_sp: ;退格键的功能
pos_get
mov row,dh
mov line,dl
cmp line,0
je stop
dec line
jmp ab
stop:
mov line,0
ab:
pos_get
mov ah,2
mov dl,00
int 21h
call win4 ;显示光标位置
jmp first
del: ;DEL删除
pos_get
mov row,dh
mov line,dl
dec line
pos_get
mov ah,2
mov dl,00
int 21h
inc line
call win4
jmp first
cm:
cmp line,00
jz pos_cm
pos_cm:
pos_curse 0,0,0
jmp first
help proc near ;显示帮助信息
call savedisplay ;保存窗口
pos_get ;读光标位置
push dx
win 0,57h,4,5,21,70
pos_curse 0,6,25 ;定义光标位置
string help_mas1
pos_curse 0,8,11
string help_mas2
pos_curse 0,10,11
string help_mas3
pos_curse 0,12,11
string help_mas4
pos_curse 0,14,11
string help_mas5
pos_curse 0,16,11
string help_mas6
pos_curse 0,18,11
string help_mas7
pop dx
pos_curse 0,dh,dl
mov ah,0
int 16h ;读字符
cmp ah,36h ;F10 help
jnz cls
call help
cls:
win 0,1eh,9,10,13,70 ;清屏
call backdisplay ;还原窗口
help endp
fuc_key endp
menu_show proc near ;显示菜单
call savedisplay
push cx
cmp ah,3bh ;F1功能
jnz x0
call menu1_sh
jmp char_get
x0:
cmp ah,3ch ;F2
jnz x00
call menu2_sh
jmp char_get
x00:
cmp ah,3eh
je x000
jmp char_get
x000:
ret
menu_show endp
menu1_sh proc near ;定义菜单的背景字体颜色
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:
pos_curse 0,1,0
win 0,15h,1,1,1,8
string manu_1
red_chr
cmp ah,1ch
jz manu_n ;读取字符
cmp ah,50h ;向下
jz manu_o2
cmp ah,48h
jz manu_e1
jmp manu_hid
manu_hid: ;菜单隐藏
win 0,1eh,1,1,7,11
call backdisplay
jmp char_get
manu_n: ;开始定义各个菜单项
win 0,65h,5,1,5,8
pos_curse 0,5,0
string manu_5
win 0,15h,1,1,1,8
pos_curse 0,1,0
string manu_1
red_chr
cmp ah,48h ;向上
je manu_e1
cmp al,0dh
jz new_1 ;新建文件
cmp ah,50h ;向下
je manu_o
jmp manu_hid
new_1: jmp new_2
manu_o2:
jmp manu_o
manu_e1:
win 0,65h,1,0,1,10
pos_curse 0,1,0
string manu_1
jmp manu_e
manu_n0:win 0,65h,2,0,2,10
pos_curse 0,2,0
string manu_2
jmp manu_n
manu_o: ;第二个子菜单open
win 0,65h,1,1,1,8
pos_curse 0,1,0
string manu_1
win 0,15h,2,1,2,8
pos_curse 0,2,0
string manu_2
red_chr
cmp ah,48h
je manu_n0
cmp al,0dh
jz open_1 ;打开文件
cmp ah,50h
je manu_s
jmp manu_hid
manu_o1:
win 0,65h,3,0,3,10
pos_curse 0,3,0
string manu_3
jmp manu_o
open_1: jmp open_2
manu_s: ;第三个子菜单save
win 0,65h,2,1,2,8
pos_curse 0,2,0
string manu_2
win 0,15h,3,1,3,8
pos_curse 0,3,0
string manu_3
red_chr
cmp al,0dh
jz save_1 ;保存文件
cmp ah,48h
je manu_o1
cmp ah,50h
je manu_a
jmp manu_hid
manu_n1:
jmp manu_n
manu_s1:win 0,65h,4,0,4,10
pos_curse 0,4,0
string manu_4
jmp manu_s
save_1: call save
manu_a: ;第四个子菜单save as
win 0,65h,3,1,3,8
pos_curse 0,3,0
string manu_3
win 0,15h,4,1,4,8
pos_curse 0,4,0
string manu_4
red_chr
cmp ah,1ch
jz save_2 ;令存为文件
cmp ah,48h
je manu_s1
cmp ah,50h
je manu_e
jmp manu_hid
manu_n2:
jmp manu_n1
manu_a1:win 0,65h,5,1,5,8
pos_curse 0,5,0
string manu_5
jmp manu_a
new_2: jmp new
save_2: call saveas
manu_e: ;第五个子菜单exit
win 0,65h,4,1,4,8
pos_curse 0,4,0
string manu_4
win 0,15h,5,1,5,8
pos_curse 0,5,0
string manu_5
red_chr
cmp ah,50h ;向下
je manu_n2
cmp ah,48h
je manu_a1
cmp ah,1ch
je 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,message4
mov ah,9
int 21h ;显示字符串
mov ah,1
int 21h
cmp al,79h ;字符y
jnz q
call quitt ;保存文件并退出
q: cmp al,6eh ;字符n
jz quit
quit: win 0,07h,0,0,24,79
pos_curse 0,0,0
mov ah,4ch
int 21h ;终止
ret
menu1_sh endp
new proc near ;新建文件
pos_get ;读光标位置
push dx
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,message1
cmp al,0dh
mov ah,9
int 21h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -