比这篇新的文章: Codee#2421
比这篇旧的文章: Codee#2419

Codee#2420

语言: NASM, 标签: 无  2009/06/24发布 8个月前更新
作者: underredflag, 点击177次, 评论(0), 收藏者(0), , 打分:

背景
主题: 字体:
NASM语言: Codee#2420
001 ;*******************************************************************
002 ;program name:    MUSIC 痴心绝对
003 ;author:曹 政
004 ;create date:2009-06-24
005 ;*******************************************************************
006 stack segment para stack 'stack'
007       db 64 dup('stack...')
008 stack ends
009 ;*******************************************************************
010 dseg segment para 'data'
011 mus_freq    dw  523,588,660,660,660,698,660,588            ;频率表
012             dw  588,523,588,588,784,588,523,494            ;痴心绝对高潮部分
013             dw  523,523,523,660,660,523,523,440
014             dw  494,494,660,494,440,392,440,440
015             dw  440,698,698,660,784,523,440,392
016             dw  440,440,440,698,698,523,523,440
017             dw  588,523,523,588,660,660,660,698
018             dw  660,588,588,523,588,588,784,588
019             dw  523,494,523,523,523,660,660,523
020             dw  523,440,494,494,660,494,440,392
021             dw  440,440,698,698,660,784,523,440
022             dw  392,440,440,440,698,698,523,523
023             dw  523,494,523,-1
024 mus_time    dw  12,12,12,12,12,12,12,12,12,12,25,12        ;时间表
025             dw  12,25,12,12,12,12,12,12,12,12,12,12
026             dw  25,12,12,25,12,12,25,12,12,37,12,25
027             dw  12,37,12,12,12,12,12,12,12,12,12,12
028             dw  50,25,12,12,12,12,12,12,12,12,12,12
029             dw  25,12,12,25,12,12,12,12,12,12,12,12
030             dw  12,12,25,12,12,25,12,12,25,25,37,12
031             dw  25,12,37,12,12,12,12,12,12,25,12,12
032             dw  75,25,100
033 dseg ends
034 ;*******************************************************************
035 cseg segment para 'code'
036       assume cs:cseg,ss:stack,ds:dseg
037 ;-------------------------------------------------------------------
038 music proc far
039       mov  ax,dseg
040       mov  ds,ax
041       lea  si,mus_freq
042       lea  bp,ds:mus_time
043 freq:                                                    ;频率发生
044       mov  di,[si]                                        ;从频率表中读下一频率
045       cmp  di,-1                                        ;乐曲结束了吗?
046       je   end_mus                                        ;是的,结束了
047       mov  bx,ds:[bp]                                    ;否,还未结束
048       call soundf
049       add  si,2
050       add  bp,2
051       jmp  freq
052 end_mus:
053       mov  ax,4c00h
054       int  21h
055 music endp
056 ;--------------------------------------------------------------------------
057 soundf proc near
058       push ax
059       push bx
060       push cx
061       push dx
062       push di
063       mov  al,0b6h
064       out  43h,al
065       mov  dx,12h
066       mov  ax,348ch
067       div  di
068       out  42h,al
069       mov  al,ah
070       out  42h,al
071       in   al,61h
072       mov  ah,al
073       or   al,3
074       out  61h,al
075 wait1:       
076       mov  cx,1326
077       call waitf
078       dec  bx
079       jnz  wait1
080       mov  al,ah
081       out  61h,al
082       pop  di
083       pop  dx
084       pop  cx
085       pop  bx
086       pop  ax
087       ret
088 soundf endp
089 ;--------------------------------------------------------------------------
090 waitf proc near
091       push ax
092 waitf1:
093       in   al,61h
094       and  al,10h
095       cmp  al,ah
096       je   waitf1
097       mov  ah,al
098       loop waitf1
099       pop  ax
100       ret
101 waitf endp
102 ;--------------------------------------------------------------------------
103 cseg ends
104 ;***************************************************************************
105       end music
106 ;***************************************************************************


所有评论,共0条:( 我也来说两句)


发表评论

注册登录后再发表评论