?? muedit.asm
字號:
include macro.inc
;********************************************************
;數據段定義
; .386
data_seg SEGMENT
totalChars DB 0 ;字符總數,以此來控制數據緩沖區,
CHar1 DB 0b3h ;常量,是一個豎線
tempchar DB ? ;臨時字節變量
musicInt DB 0 ;文件數量
musicIndex DB 30h ;默認文件名的最后一個字符,隨新建打開而增1,關閉減1
SaveAsFlag DB 0 ;已調用過filesaveas函數
modifyFlag DB 0 ;為0時已做修改
AsOrIfFlag DB 0 ;為0時是saveas調用
saveActive DB 78h ;根據musicInt來判斷是否激活save,saveAs菜單
copyActive DB 78h ;根據copyFlag來判斷是否激活copy,cut菜單
pasteActive DB 78h ;根據paste來判斷是否激活paste菜單
CLearFlag DB 0 ;clearFlag為0時表示不需要處理選擇文本,如將反色顯示還原
pasteFlag DB 0 ;pasteFlag為0時為不能粘貼,
copyFlag DB 0 ;copyFlag為0時為不能復制與剪切,
pasteNum DB 0 ;粘貼緩沖區中字符個數.
PasteBuffer DB 25 DUP (0)
DB '$'
;復制粘貼緩沖區
INsertNum DB 1 ;insertNum為插入字符的個數
save DB 0 ;
path DB 30 DUP (0) ;文件名存放緩沖區
DB '$'
buffer DB 2000 DUP(?) ;buffer為數據緩沖區
bak DB 3850 DUP(0) ;視頻緩沖區的備份
row DB 2 ;保存行號,
column DB 1 ;保存列號.
rowBak DB 2
columnbak DB 1
peak DB 0Dah, 78 DUP(0C4h) ,0BFh,13,10,'$' ;頂端橫線
errormess1 DB 'can not creat the file,path is wrong! ','$'
errormess2 DB 'can not write to the file! ','$'
errormess3 DB 'the filename is too long! ','$'
errormess4 DB 'can not open the file,filename is wrong','$'
errormess5 DB 'can not read the file! ','$'
mess1 DB 'Please input save file name:','$'
mess2 DB ' Please input open file name:','$'
mess3 DB ' ***The file is not save! Save it now? (Y/N)***: ','$'
mess4 DB 'please input the filename again ','$'
mess5 DB 'your put is wrong!please input Y/N again','$'
mess6 DB 0b3H,' row:??? column:???','$'
mess7 DB 'Creat a new file ','$'
mess8 DB 'loads an exiting file from disk ','$'
mess9 DB 'save current file ','$'
mess10 DB 'save current file with new name ','$'
mess11 DB 'Exits the editor ','$'
mess12 DB 'F1:file menu F2:Play Music F3:help ','$'
mess21 DB 'Copy selected text to buffer ','$'
mess22 DB 'Deletes selected text and copys it ','$'
mess23 DB 'Inserts buffer contents here ','$'
mess13 DB 0b3H,'modified ','$'
mess14 DB 0b3h,'NoModified','$'
mess15 DB ' editing... press Esc can escape ','$'
mess16 DB ' IBM PC Assemble Language Course Design',13,10,'$'
mess17 DB ' MusicEdit 1.0 ',13,10,'$'
mess18 DB ' Made by GuSui etc. ',13,10,'$'
mess19 DB ' Dec,30,2004 ',13,10,'$'
mess20 DB ' Press any keys to return','$'
musicname DB 'd:\music0',0
RF DB 13,10,'$'
music DW 2 DUP(262,294,330,262) ;兩只老虎
DW 2 DUP(330,349,392)
DW 2 DUP(392,440,392,349,330,262)
DW 2 DUP(294,196,262),0
time DW 8 DUP(4)
DW 2 DUP(4,4,8)
DW 2 DUP(2,2,2,2,4,4)
DW 2 DUP(4,4,8)
music1 DW 262,294,330,349,392,440,494,523 ;音階
DW 523,494,440,392,349,330,294,262,0
time1 DW 16 DUP(25)
;文件相關數據定義
handler DW 0
filename DB 'e:/tiger.vol',0
CHartemp DB 0
Buffertemp DB 4 DUP(0)
Bufferflag DW 0
musicFinish DB 0
musicTemp DW 0
times DW 1
musicBuffer DW 100 DUP(0)
bufferIndex DW 0
timeBuffer DW 100 DUP(0)
;菜單數據定義
str_menu DB ' File(F1) Play(F2) Edit(F3) Help(F4)',13,10,'$'
file_0 DB 0dah , 11 DUP(0C4H),0BFH ,13,10,'$'
file_1 DB 0B3H,' New ',0B3H,13,10,'$'
file_2 DB 0B3H,' Open ',0B3H,13,10,'$'
file_3 DB 0B3H,' Save ',0B3H,13,10,'$'
file_4 DB 0B3H,' Save as ',0B3H,13,10,'$'
file_5 DB 0B3H,' Exit ',0B3H,13,10,'$'
file_6 DB 0c0H, 11 DUP(0c4h),0d9H,13,10,'$'
play_0 DB 0dah , 10 DUP(0C4H),0BFH ,13,10,'$'
play_1 DB 0B3H,' tiger ',0B3H,13,10,'$'
play_2 DB 0B3H,' music2 ',0B3H,13,10,'$'
play_3 DB 0B3H,' scale ',0B3H,13,10,'$'
play_4 DB 0B3H,' gun ',0B3H,13,10,'$'
play_5 DB 0c0H, 10 DUP(0c4h),0d9H,13,10,'$'
edit_0 DB 0dah , 10 DUP(0C4H),0BFH ,13,10,'$'
edit_1 DB 0B3H,' Copy ',0B3H,13,10,'$'
edit_2 DB 0B3H,' cut ',0B3H,13,10,'$'
edit_3 DB 0B3H,' Paste ',0B3H,13,10,'$'
edit_4 DB 0c0H, 10 DUP(0c4h),0d9H,13,10,'$'
error0 DB 'Open File failed',13,10,'$'
error1 DB 'the file have illegal character', 13,10,'$'
error2 DB 'the file have illegal character2', 13,10,'$'
data_seg ENDS
;*********************代碼段*************8
code_seg SEGMENT
ASSUME CS:code_seg,DS:data_seg
;************主過程開始**************
start:
MOV AX,data_seg
MOV DS,AX
CALL welcome
INit:
CALL INitwin
GEtchar ;讀鍵盤
CMP AH,3bh ;F1
JZ showFile
CMP AH,3ch ;F2
JZ showPlay
CMP AH,3dh
JZ showE
CMP AH,3Eh ;F3
JZ showh
CMP AH,01h
JZ exitf
JMP INit
showFile: CALL showmenuF
JMP INit
showPlay: CALL showMenuP
JMP INit
showE: CALL showMenuE
JMP INit
showh: CALL showmenuh
JMP INit
exitf:
MOV AH, 4ch
INT 21h
;主執行代碼結束,下面都是要調用的函數定義.
;***********************************
;**********歡迎模塊*****************
welcome PROC
saveE
recover
RET
welcome ENDP
;----------------------------
;***********初始化模塊*******
;功能:初始化屏幕,顯示菜單,提示信息,設置工作模式為3號字符模式
;****************************
INitwin PROC
saveE
MOV AH,01h
MOV CH,03h
INT 10h ;設置為字符模式03
win 0,0,24,79,70h ;清屏
win 1,0,23,79,07h
win 2,1,23,78,27H
poscur 0,0
show str_menu
poscur 1,0
show peak ;顯示上面的橫線
;兩個循環是畫左右兩條線的.
MOV CL,23
LOOPf:
poscur CL,0
putchar CHar1
DEC CL
CMP CL,1
JNZ LOOPf
LOOPf2:
INC CL
poscur CL,79
putchar CHar1
CMP CL,23
JNZ LOOPf2
poscur 2,1
posgets
CALL showRC
poscur 24,1
show mess12
poscur 2,1
recover
RET
INitwin ENDP
;*************************************
;************************************
;********文件菜單模塊*****************
;功能:當在主過程或編輯狀態檢測到F1而被激活的.根據用戶的選擇來
; 執行相應的菜單命令
;入口參數有musicInt:文件數量,以此來判斷是激活save,save as 菜單
;先保存視頻緩沖區的內容 ,再獲取鍵盤輸入,按照輸入跳到不同的分支,
;每個分支都調用相應的函數來處理.
;to*為當前選中項*的處理分支
;to*&,其中&是數字,為了解決匯編中的一些跳轉指令分幾次跳的問題,
showmenuF PROC
saveE
CALL savedisplay
CMP musicInt,0
JZ NOTactive
MOV saveActive,79h
JMP activeOK
notactive:
MOV saveActive,78h
activeOK:
win 0,3,0,11,07h
poscur 0,0
show str_menu
win 2,3,8,15,saveActive ;菜單不選中的顏色(白底黑字)
win 9,4,9,16,07h ;菜單的陰影
win 3,16,9,16,07h ;菜單的陰影
;顯示各個菜單,并設置第一個菜單為默認項,
poscur 2,3
show file_0
poscur 3,3
show file_1
poscur 4,3
show file_2
poscur 5,3
show file_3
poscur 6,3
show file_4
poscur 7,3
show file_5
poscur 8,3
show file_6
;to*為當前選中項*的處理分支
tonew:
win 7,4,7,14,79h ;
poscur 7,3
show file_5
win 4,4,4,14,79h
poscur 4,3
show file_2
win 3,4,3,14,67h
poscur 3,3
show file_1
showM mess7
GEtchar
CMP AH,50h ;若按下鍵下方向鍵
JZ toOpen
CMP AH,48H
JZ toexit1
CMP AH,1ch ;若按了Enter鍵
JZ NEwfile1
JMP exitfile ;其他就返回
toexit1: JMP toexit
NEwfile1: JMP NEwfile
toOpen:
win 3,4,3,14,79h
poscur 3,3
show file_1
win 5,4,5,14,saveActive
poscur 5,3
show file_3
win 4,4,4,14,67h
poscur 4,3
show file_2
showM mess8
GEtchar
CMP AH,50h
JZ toSave
CMP AH,48H
JZ tonew1
JMP tonew3
tonew1: JMP tonew
tonew3:
CMP AH,1ch
JZ openfile1
JMP exitfile
openfile1: JMP openfile
toSave:
win 4,4,4,14,79h
poscur 4,3
show file_2
win 6,4,6,14,saveActive
poscur 6,3
show file_4
win 5,4,5,14,67h
poscur 5,3
show file_3
showM mess9
GEtchar
CMP AH,50h
JZ toSaveas
CMP AH,48H
JZ toOpen1
JMP toopen3
toopen1: JMP toopen
toopen3: CMP AH,1ch
JZ savefile1
JMP exitfile
savefile1: JMP savefile
toSaveas:
win 5,4,5,14,saveActive
poscur 5,3
show file_3
win 7,4,7,14,79h
poscur 7,3
show file_5
win 6,4,6,14,67h
poscur 6,3
show file_4
showM mess10
GEtchar
CMP AH,50h
JZ toExit
CMP AH,48h
JZ tosave1
JMP tosave3
tosave1: JMP tosave
tosave3: CMP AH,1ch
JZ saveasfile1
JMP exitfile
saveasfile1: JMP saveasfile
tosaveas1: JMP tosaveas
toExit:
win 6,4,6,14,saveActive
poscur 6,3
show file_4
win 3,4,3,14,79h
poscur 3,3
show file_1
win 7,4,7,14,67h
poscur 7,3
show file_5
showM mess11
GEtchar
CMP AH,50h
JZ tonew2
JMP tonew4
tonew2: JMP tonew
tonew4: CMP AH,48h
JZ tosaveas3
CMP AH,1ch
JZ EXITMusic
JMP exitfile
tosaveas3: JMP tosaveas1
;****處理不同的分支所調用的不同的函數.****/
NEwfile:
CALL filenew
JMP exitfile
;播放完畢跳到初始位置
openfile:
CALL fileopen
JMP exitfile
savefile:
CALL filesave
JMP exitfile
saveasfile:
CALL filesaveas
JMP exitfile
EXITMusic : CMP modifyFlag,0
JNZ exitfile20
CALL IFsave
JMP exitMusic
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -