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

📄 music程序增加功能(按1到8变速度,按a到g变调).asm

📁 是一个关于汇编的我的第一个汇编源代码
💻 ASM
字号:
; present time: 2005.05.18
;last modify timer 2005.05.18
; ver 1.20 
; auther      : dengrui(修改:yerunbin)(增加功能:按1到8变速度,按A到G变调)
; functiong   : f1 pressed start music,f5 pressed end, music f9 pressed exit progarm,按1到5变速度,按A到G变调

.model small
.stack

.code
;--------- main program is use to save int 1ch and set 1ch intrrupte to the
;          sub progarm timer_int ,then remain in ram and exit.

main         proc far                   ; show intall message in screen
             mov ax,@code
             mov ds,ax
             mov es,ax
             mov dx,offset msg_install
             mov ah,9h
             int 21h

get_arrower: push es                  ; store the old 1ch intrrupte arrower
             mov ah,35h               ; to the var key_arrower
             mov al,1ch
             int 21h
             mov si,offset timer_arrower
             mov [si],bx
             mov [si+2],es
             pop es

set_arrower: mov ax,seg timer_int        ;set the intrrupt 1ch to the timer_int
             mov ds,ax                 ; sub program
             mov dx ,offset timer_int
             mov al,1ch
             mov ah,25h
             int 21h


exit:        mov ah,31h
             mov al,0
             mov dx,((prog_length+15)/16)+16
             int 21h
main endp

;----------  this is the timer intrrupt
timer_int proc near
        push ds
        push ax
        push bx
        push es
        push di
        push bp
        push cx
        push dx
        push si
;------------- set the es and ds segment
               mov ax,@code
               mov ds,ax
               mov es,ax
func_key_test:
               in al,60h        ;input from the keyboard
key_test1:     cmp al,43h        ;if f9 pressed then restore intrrput arrower 
               jz restore2 

;修改 
keya:cmp al,1eh
 jne keyb 
lea di,tone
mov [di],byte ptr 'A'

keyb:cmp al,30h
 jne keyc 
lea di,tone
mov [di],byte ptr 'B'

keyc:cmp al,2eh
 jne keyd
lea di,tone
mov [di],byte ptr 'C'

keyd:cmp al,20h
 jne keye 
lea di,tone
mov [di],byte ptr 'D'

keye:cmp al,12h
 jne keyf 
lea di,tone
mov [di],byte ptr 'E'

keyf:cmp al,21h
 jne keyg 
lea di,tone
mov [di],byte ptr 'F'

keyg:cmp al,22h
 jne keynum
lea di,tone
mov [di],byte ptr 'G'

keynum:cmp al,02h
jl key_test2 
cmp al,09h
jg key_test2
lea di,time_dure
dec al
mov [di],al

jmp key_test2
restore2:jmp  restore   ;修改



key_test2:     cmp al,3fh        ;if f5 pressed then stop music
               jnz key_test3
lea  di, current_tap  ;set the music pointer to end of music
               lea bx,music_end 
               mov es:[di],bx
               lea bx,litter_tap_time
               mov word ptr[bx], 0            ; set the litter_tap_time to zero
                                     ;disable the music
        jmp play              ; go to play part



key_test3:     cmp al,03bh        ;if f1 pressed the begin music
               jnz play      ;if other key pressed
               mov al,10111111b
               out 43h,al
               lea  di, current_tap  ;set the music pointer to start of music
               lea  bx, music_start
               mov  es:[di],bx
               lea  bx,litter_tap_time
               mov word ptr[bx], 0            ; set the litter_tap_time to zero
                                      ;disable the music
play:
               lea bx,current_tap     ;get the music data pointer
               mov di,[bx]
               cmp word ptr es:[di],'AB'  ;just if pointer to the data end
               jnz  just_delay2             ; not end of music

               lea bx, litter_tap_time
just_delay1:   cmp word ptr[bx],0      ;just whether delay time is end or not 
               jnz  time_dec             ; delay time is not end to timer-1
               mov al,30h              ;delay time is end, turn off speaker
               out 61h,al
               jmp continue         ;exit
time_dec:      dec word ptr[bx]             ; litter_tap_time=litter_tap_time-1
               jmp continue        ;exit

just_delay2:   lea bx,litter_tap_time
               cmp word ptr[bx],0     ;just whether litter tap is end  
               jnz time_dec             ; if time not end ,time=time-1
                                 
set_timer:     lea di,current_tap
               mov bx,es:[di]          ; set the pointer of music data to bx
               mov ax,[bx]             ;read data from music table
               call music_set          ;call the sub for set music data 
               jmp continue            ;exit


restore:                  ; if the f6 key pressed, then restore the
        mov ax,@code      ; 1ch intrupte
        mov ds,ax
        mov bx,offset timer_arrower
        sub ax,ax
        mov es,ax
        mov di,70h

        mov ax,[bx]        ;restore intrrupt 1ch arrower
        mov es:[di],ax
        mov ax,[bx+2]
        mov es:[di+2],ax

        mov al,30h         ;turn off speaker
        out 61h,al


 
continue:
          pop si
          pop dx
          pop cx
          pop bp
          pop di
          pop es
          pop bx
          pop ax
          pop ds
        iret
timer_int endp

;----- set the music data to the timer2 ,set during timer and inc pointer 2

music_set proc near
            ;-------- read the tone data and get the tonepostion
            push bx         ;save the pointer 
            xchg ah,al      ; change the tone flag and during time
            mov cx,ax       ;save  the music data to cx
            lea bx,tone      ;read tone to al
            mov al,[bx]
            sub al,'A'       ;get tone_postion pointer
            mov ah,0         ; clear ah
            mov di,ax        ;set relate pointer to di

            lea bx,tone_postion ;get the tone_postion table index to bx
            mov al,[bx+di]   ;get the tone_postion to al
            mov ah,0
            mov bx,ax        ; set the tone_postion to bx
            shl bx,1         ; bx=bx*2 use to deal with word


            ;--------- compute the music data position
             mov ax,cx      ;restore the music data
             and ah,00001111b ; get the music flag
             xchg ah,al
             mov ah,0
             dec ax
             shl ax,1         ;ax=ax*2   use to deal with word
             add bx,ax        ;set the right music position


             mov ax,cx       ;adjust pointer according to the music flag tone 
             and ah,11110000b ;get the the music flag tone

low_tong:    cmp ah,00h     ;the tone is low ,so bx=bx-14
             jnz high_tone
             sub bx,14
             jmp get_freq
high_tone:   cmp ah,20h    ;;the tone is high ,so bx=bx+14
             jnz get_freq
             add bx,14

            ;------- from the freq convert to the data in timer2

get_freq:    lea di,music_flag_freq  ;set the freq to si
             mov si,[bx+di]
             mov dx,0012h          ; set dx:ax 1,193,180 hz
             mov ax,43dch
             div si                ;div si get the timer2 data in ax
             push ax               ;save the timer2 data in ax to stack

                 ;------ set the timer2 freq data
set_timer2:    
             
             pop ax
             out 42h,al
             xchg ah,al
             out 42h,al        ; set the data to the timer2

             mov al,3fh        ;turn on the speak
             out 61h,al


set_during_time:
             mov ax,cx        ;read the data store in cx to ax
             mov ah,0         ; clear the high apart
             lea bx,time_dure ;set the dure time to dl to multiy al
             mov dl,[bx]
             mul dl
             lea bx,litter_tap_time
             mov [bx],ax      ; set the litter tap time

;------------ set the music data pointer to the next music data

add_msc_piointer:
             pop bx     ; current_tap=current_tap+2
             inc bx
             inc bx
             lea di,current_tap
             mov es:[di],bx
             ret


music_set endp

tone db 'G'      ;which tone the song belonge to 

tone_postion db 20,21,15,16,17,18,19 ;postion in music flag table of tone
                                     ; A B C D E F G

;---------- the freq of the all kind of music flag

music_flag_freq dw  0
                dw    65,  74,  83,  88,  98, 110, 124
                dw    131, 147, 165, 175, 196, 220, 247
                dw    262, 294, 330, 349, 392, 440, 494
                dw    524, 588, 660, 698, 784, 880, 988
                dw    1048,1176,1320,1396,1568,1760,1976

;-------- music flage of the song and the litter tap

music_start db  13h,08,15h,08,13h,08,12h,04,13h,04
            db  15h,08,13h,04,12h,04,13h,16
            db  13h,08,15h,08,13h,04,12h,04,11h,08
            db  12h,08,13h,04,15h,04,12h,16
            db  11h,08,11h,04,06h,04,05h,08,05h,04,06h,04
            db  11h,08,12h,04,13h,04,11h,16

music_end   dw  'AB'



current_tap dw $-2           ; pointer to the tap of current

litter_tap_time dw 0      ;how much time  the litter tap left

time_dure     db  1      ; how much timers the litter tap mulity


timer_arrower dw 0,0

msg_install db 'The music progaram installed! ',0dh,0ah,'$'


prog_length equ $-main
     end  main

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -