基于汇编语言的电子琴设计(5)

时间:2022-02-14 01:26:39

LOAD_AUDIO PROC NEAR<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

C/D调及对应的低、中、高频率分别载入

OUT:BX

IN:TUNE,AUDIO

TUNE_D:                                                        D大调判断

       CMP TUNE,'D'

       JNZ TUNE_CL                                         ;不是判断是否是C调

TUNE_DL:

       CMP AUDIO,1                                         ;低频判断

       JNE TUNE_CM

       LEA BX,LOWDD

       JMP AUDIO_END

TUNE_DM:

       CMP AUDIO,2                                         ;中频判断

       JNE TUNE_CH

       LEA BX,MIDD

       JMP AUDIO_END

TUNE_DH:

       LEA BX,HGHD                                        ;高频判断

       JMP AUDIO_END

 

TUNE_CL:                                                      C调处理

       CMP AUDIO,1

       JNE TUNE_CM

       LEA BX,LOWD

       JMP AUDIO_END

TUNE_CM:

       CMP AUDIO,2

       JNE TUNE_CH

       LEA BX,MID

       JMP AUDIO_END

TUNE_CH:

       LEA BX,HGH

 

AUDIO_END:

       RET

LOAD_AUDIO ENDP

 

SCAN_TUNE PROC NEAR

C/D调判断及其状态在屏幕上的显示

IN:DL  键盘扫描码

OUT:TUNE

       CMP DL,2EH                                    ;判断是C否

       JNZ NEXT_D                                    ;不是则判断是D否

       MOV TUNE,'C'

       DRAW 55,38,60,41,0EH                           ;关D灯

       DRAW 65,38,70,41,0AH                           ;开C灯

       JMP TUNE_END                                       ;结束

NEXT_D:

       CMP DL,20H                                           ;判断D否

       JNZ TUNE_END

       MOV TUNE,'D'

       DRAW 55,38,60,41,0AH                           ;开D灯

       DRAW 65,38,70,41,0EH                           ;关C灯

TUNE_END:

       RET

SCAN_TUNE ENDP

 

SHOW_TEXT PROC NEAR

;在屏幕上显示字符

       LEA DI,TEXT                                          ;载入字符串首地址

       MOV DH,[DI]                                         ;赋行值

       INC DI                                                    ;取得列

       MOV DL,[DI]                                          ;赋列值

       MOV START_COL,DL                            ;保存开始列

       MOV AH,2                                              ;设置光标位置

       MOV BH,0                                              0页

       INT 10H

       INC DI                                                    ;取得颜色值

       MOV BL,[DI]                                          ;赋颜色值

CHAR_WRITE:

       INC DI                                                    ;取得要显示的字符

       MOV AL,[DI]

       CMP <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />AL,0FFH                                         ;行结束否

       JE BUMP_ROW                                      ;下一行

       CMP AL,0                                                ;结束否

       JZ END_TEXT

       CALL SHOW_CHAR                              ;显示字符

       JMP CHAR_WRITE                                       ;下一个字符

       END_TEXT:

       RET

BUMP_ROW:

       INC DH                                                          ;下一行

       MOV DL,START_COL                                   ;赋开始列值

       MOV AH,2                                                     ;设光标位置

       MOV BH,0

       INT 10H

       JMP CHAR_WRITE

SHOW_TEXT ENDP

 

SHOW_CHAR PROC NEAR

;显示字符

MOV AH,9                                                     ;显示字符

       MOV BH,0                                                     0页

       MOV CX,1

       INT 10H

       INC DL                                                         

       MOV AH,2                                                     ;设置光标位置

       MOV BH,0                                                     0页

       INT 10H

       RET

SHOW_CHAR ENDP

 

INIT PROC NEAR

;初始化屏幕:画琴键

MOV AX,DATA

    MOV DS,AX

 

       MOV AH,0                                                     ;设置屏幕

    MOV AL,0DH

       INT 10H

    MOV AH,0BH

    MOV BH,0

    MOV BL,00H                                                 ;背景色

    INT 10H

 

       CALL SHOW_TEXT                                       ;显示字符串

       DRAW 45,30,285,94,05H    

       DRAWSQRE 45,30,285,94,0DH

       DRAWSQRE 49,48,280,49,00H

      

       DRAW 55,38,60,41,0EH                                  C调灯

       DRAW 65,38,70,41,0AH                                  D调灯

       CALL SONG_LIGHT_OFF                      ;自动播放歌指示灯关

 

       LEA SI,ST_LX                                                ;画21个白色键

    LEA DI,ED_LX

    MOV CX,21

INIT_DRAW:

    DRAW [SI],ST_Y,[DI],ED_Y,0FH

    DRAW [SI],90,[DI],93,07H                             ;阴影

    ADD SI,2

    ADD DI,2

    LOOP INIT_DRAW    

 

    LEA SI,BT_X                                           ;画15个黑色键

    LEA DI,BD_X

    MOV CX,15

INIT_BLOCK:

    DRAW [SI],BT_Y,[DI],BD_Y,00H

    ADD SI,2

    ADD DI,2

    LOOP INIT_BLOCK  

 

       RET

INIT ENDP

SONG_LIGHT_OFF PROC NEAR

;关闭灯1~5

       DRAW 271,42,275,46,09H

       DRAW 265,42,269,46,09H

       DRAW 259,42,263,46,09H

       DRAW 253,42,257,46,09H

       DRAW 247,42,251,46,09H

      

       RET

SONG_LIGHT_OFF ENDP

 

FREQ_CHANGE PROC NEAR

;IN:DL   扫描码

       CMP DELAY_TIME,600

       JB  CHANGE_ADD

       CMP DELAY_TIME,60000

       JA  CHANGE_SUB

       CMP DL,0CH              ;-

       JNZ FREQ_SUB

       ADD DELAY_TIME,500

       DRAW 271,38,274,41,0EH

       JMP CHANGE_END

CHANGE_ADD:

       ADD DELAY_TIME,500

       JMP CHANGE_END

CHANGE_SUB:

       SUB DELAY_TIME,500

       JMP CHANGE_END

FREQ_SUB:

       CMP DL,0DH              ;+

       DRAW 271,38,274,41,0AH

       JNZ CHANGE_END

       SUB DELAY_TIME,500

CHANGE_END:

       RET

FREQ_CHANGE ENDP

 

EXIT PROC NEAR

;程序结束

       MOV AH,4CH

       INT 21H

        RET

EXIT ENDP

CODE ENDS

     END START

 

 七、参考资料

〈IBM-PC汇编语言程序设计〉----清华大学出版社

 

〈完〉