汇编乐曲编程

来源:互联网 发布:换手机壁纸的软件 编辑:程序博客网 时间:2024/04/28 16:13
;***************************************************************************
;新年好乐曲
;author:野渡无人
;create date:2007-12-22
;***************************************************************************
stack segment para stack 'stack'
      db 64 dup('stack...')
stack ends
;*******************************************************************
dseg segment para 'data'
mus_freq   dw  262,262,262,196,330,330,330,262
    dw  262,330,392,392,349,330,294
    dw  294,330,349,349,330,294,330,262
           dw  262,330,294,392,494,294,262,-1
mus_time   dw  16,16,33,33,16,16,33,33
           dw  16,16,33,33,16,16,67
    dw  16,16,33,33,16,16,33,33
    dw  16,16,33,33,16,16,67
message1   db  'Merry Christmas and Happy New Year!',13,10,'$'
message2   db  'Play again?(Y/N):$'
play_flag  db  ?
crlf       db 13,10,'$'
dseg ends
;*******************************************************************
cseg segment para 'code'
      assume cs:cseg,ss:stack,ds:dseg
;-------------------------------------------------------------------
music proc far
      mov  ax,dseg
      mov  ds,ax
      lea  dx,message1
      mov  ah,09
      int  21h
start:
      lea  si,mus_freq
      lea  bp,ds:mus_time
freq:
      mov  di,[si]
      cmp  di,-1
      je   end_mus
      mov  bx,ds:[bp]
      call soundf
      add  si,2
      add  bp,2
      jmp  freq
end_mus:
      lea  dx,message2
      mov  ah,09
      int  21h
      call judge
      cmp  play_flag,1
      je   start
      mov  ax,4c00h
      int  21h
music endp
;--------------------------------------------------------------------------
soundf proc near
      push ax
      push bx
      push cx
      push dx
      push di
      mov  al,0b6h
      out  43h,al
      mov  dx,12h
      mov  ax,348ch
      div  di
      out  42h,al
      mov  al,ah
      out  42h,al
      in   al,61h
      mov  ah,al
      or   al,3
      out  61h,al
wait1:
      mov  cx,16630
      call waitf
      dec  bx
      jnz  wait1
      mov  al,ah
      out  61h,al
      pop  di
      pop  dx
      pop  cx
      pop  bx
      pop  ax
      ret
soundf endp
;--------------------------------------------------------------------------
waitf proc near
      push ax
waitf1:
      in   al,61h
      and  al,10h
      cmp  al,ah
      je   waitf1
      mov  ah,al
      loop waitf1
      pop  ax
      ret
waitf endp
;--------------------------------------------------------------------------
judge proc near
       mov  ah,01
       int  21h
     
       cmp  al,'Y'
       je   judge_continue1
       cmp  al,'y'
       je   judge_continue1
       cmp  al,'N'
       je   judge_continue2
       cmp  al,'n'
       je   judge_continue2
       mov  ah,09
       lea  dx,crlf
       int  21h
       jmp  judge_exit
judge_continue1:
       mov  play_flag,1
       jmp  judge_exit
judge_continue2:
       mov  play_flag,0
judge_exit:
       mov  ah,09
       lea  dx,crlf
       int  21h
       ret
judge endp
;----------------------------------------------------------
cseg ends
;***************************************************************************
      end music
;*************************************************************************** 
原创粉丝点击