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

类别:编程语言 点击:0 评论:0 推荐:

LOAD PROC NEAR

;载入键在屏幕上的位置

CMP KEYFLAG,00H                         ;判断是否是低音键

       JNZ  LOAD_HGH                           ;继续判断

       LEA SI,ST_LX                                  ;载入低音键起始坐标首地址

    LEA DI,ED_LX                                 ;载入低音键结束坐标首地址

       JMP LOAD_END                              ;载入结束

LOAD_HGH:

       CMP KEYFLAG,02H                  ;判断是否是高音键

       JNZ LOAD_MID                       ;继续判断

       LEA SI,ST_HX                          ;载入高音键起始坐标首地址

    LEA DI,ED_HX                         ;载入高音键结束坐标首地址

       JMP LOAD_END

      

LOAD_MID:

       LEA SI,ST_MX                          ;载入中音键起始坐标首地址

       LEA DI,ED_MX                         ;载入中音键结束坐标首地址

LOAD_END:

      RET

LOAD ENDP

 

SCAN_KEY PROC NEAR

;检查按键状态,并存入对应的变量和寄存器

       MOV SI,100

       MOV DI,100

    MOV KEYNUM,100                          ;赋初值

      

MOV AH,0                                       ;读键盘

    INT 16H

       MOV DL,AH

       CALL SCAN_SONG                         ;判断是否是自动播放键(大键盘数字键1~5)

       CALL SCAN_TUNE                          ;判断是否是C/D调选择键

       CALL FREQ_CHANGE                     ;判断是否按下频率改变键:(+/- 符号)

       CMP AH,01H                                    ;是否是结束键

       JNE FLAG_SCAN                      ;若不是继续检测

       CALL EXIT                                      ;若是则退出

 

FLAG_SCAN:                                         

       MOV AH,02H                                   ;读键盘状态字节

       INT 16H

       MOV DH,AL                                    ;判断是否是右shift键

       AND DH,01H

    CMP DH,01H   

    JE SLOW                                         ;是则进行低音处理

       MOV DH,AL                                    ;不是判断是否是左shift键

       AND DH,02H

       CMP DH,02H 

       JE SHGH                                          ;是则进行高音处理

       JMP SMID                                        ;都不是进行中音处理

 

SLOW:                                                    ;低音处理

       MOV AUDIO,1                                

       MOV KEYFLAG,0

       JMP KEY_1                                      ;跳转到音键处理

SHGH:                                                    ;高音处理

       MOV AUDIO,3

       MOV KEYFLAG,2

       JMP KEY_1                                      ;跳转到音键处理

SMID :                                                  ;中音处理

       MOV AUDIO,2

       MOV KEYFLAG,1

 

KEY_1:

       CMP DL,4FH                                    ;是否是1

       JNE KEY_2                                       ;继续判断

       MOV KEYNUM,0                              ;不是则保存标志

       JMP SCAN_END                               ;键扫描结束

KEY_2: 

       CMP DL,50H                                    ; 是否是2

       JNE KEY_3

       MOV KEYNUM,2

       JMP SCAN_END

KEY_3:

       CMP DL,51H                                    ; 是否是3

       JNE KEY_4

       MOV KEYNUM,4

       JMP SCAN_END

KEY_4: 

       CMP DL,4BH                             ; 是否是4

       JNE KEY_5

       MOV KEYNUM,6

       JMP SCAN_END

KEY_5:

       CMP DL,48H                                    ; 是否是5

       JNE KEY_6

       MOV KEYNUM,8

       JMP SCAN_END

KEY_6:

    CMP DL,4DH                                 ; 是否是6

       JNE KEY_7

       MOV KEYNUM,10

       JMP SCAN_END

KEY_7:

       CMP DL,47H                                    ; 是否是7

       JNE SCAN_END

       MOV KEYNUM,12

SCAN_END:

       RET

SCAN_KEY ENDP

 

SCAN_SONG PROC NEAR

;判断是否是自动播放键(键1~5),并保存标志变量(song)

;IN: AH    键扫描码

       PUSH AX

       MOV SONG,100                                       ;赋初始值

       CMP AH,3BH                                    ;与1比较

       JB  SONG_END                                      ;小于1则结束

       CMP AH,3FH                                    ;与5比较

       JA SONG_END                                        ;大于则结束

       SUB AH  3B                                             ;转换成1~5

       MOV AL,AH

       MOV AH,00H

       MOV SONG,AX                                       ;存入标志码

SONG_END:

       POP AX        

       RET

SCAN_SONG ENDP

 

PLAY_SONG PROC NEAR

;选择并播放音乐

PUSH BP

       PUSH SI

       PUSH BX

       PUSH DI

       PUSH AX

 

       CMP SONG,01H                                       ;判断是否是歌1

       JNE GO2                                                 ;不是继续判断

       CALL SONG_LIGHT_OFF               ;灯1~5灭

       DRAW 247,42,251,46,0EH                        ;灯1亮

       LEA BP,MUS_TIME1                               ;载入延时数据首地址

       LEA SI,MUS_FREQ1                               ;载入频率数据首地址

       JMP FREQ                                             

GO2:

       CMP SONG,02H                                       ;判断是否是歌2

       JNE GO3

       CALL SONG_LIGHT_OFF

       DRAW 253,42,257,46,0EH

       LEA BP,MUS_TIME2

       LEA SI,MUS_FREQ2

       JMP FREQ

GO3:

       CMP SONG,03H                                              ;判断是否是歌3

       JNE GO4

       CALL SONG_LIGHT_OFF

       DRAW 259,42,263,46,0EH

       LEA BP,MUS_TIME3

       LEA SI,MUS_FREQ3

       JMP FREQ

 

GO4:

       CMP SONG,04H                                              ;判断是否是歌4

       JNE GO5

       CALL SONG_LIGHT_OFF

       DRAW 265,42,269,46,0EH

       LEA BP,MUS_TIME4

       LEA SI,MUS_FREQ4

       JMP FREQ

 

GO5:

       CMP SONG,05H                                              ;判断是否是歌5

       JNE FREQ

       CALL SONG_LIGHT_OFF

       DRAW 271,42,275,46,0EH

       LEA BP,MUS_TIME5

       LEA SI,MUS_FREQ5

 

FREQ:

       MOV AH,01H                                                 ;读键盘缓冲区字符

       INT 16H

       CMP AH,1CH                                                 ;是否是Enter键

       JNZ CONTINUE                                              ;不是继续

       JMP PLAY_END                                             ;是结自动播放

CONTINUE:

       MOV AH,0CH                                                ;清除键盘缓冲区字符

       MOV AL,06H

       INT 21H

       MOV DI,[SI]

       CMP DI,-1                                                      ;判断结束否

    JE  PLAY_END                                            

       MOV BX,[BP]

       CALL GEN_AUTO                                          ;发声

       ADD SI,2

       ADD BP,2                                                       ;下一频率

       JMP FREQ

PLAY_END:

       CALL SONG_LIGHT_OFF

       POP AX

       POP DI

       POP BX

       POP SI

       POP BP

       RET

PLAY_SONG ENDP

 

〈未完〉

本文地址:http://com.8s8s.com/it/it28919.htm