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

📄 muedit.asm

📁 汇编课程设计报告 文档编辑器及乐曲演奏程序
💻 ASM
📖 第 1 页 / 共 5 页
字号:
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 + -