stackear segment stack
db 64 dup('stack...')
top label word
stackear ends
dseg segment para 'data'
mus_time0 dw 1
mus_freq dw 330,294,262,294,3 dup(330)
dw 3 dup(294),330,392h,392
dw 330,294,262,294,4 dup(330)
dw 294,294,330,294,262
mus_time dw 6 dup(1*6),2*6
dw 2 dup(1*6,1*6,2*6)
dw 12 dup(1*6),4*6
;------生日快乐MUSIC-------------
mus_freq1 dw 262,262,294,262,349,330,262,262,294,262,392,349
dw 262,262,523,440,349,330,294,446,446,440,262,392,349
mus_time1 dw 2 dup(2*6)
dw 3 dup(4*6),8*6,2*6,2*6
dw 3 dup(4*6),8*6,2*6,2*6
dw 4 dup(4*6),8*6,2*6,2*6,4*6,4*6,4*6,8*6,8*6
;-----------------------------------------
mus_freq2 dw 330,392,330,294,330,392,330,294,330
dw 330,392,330,294,262,294,330,392,294
dw 262,262,220,196,196,220,262,294,330,262
mus_time2 dw 3 dup(2*6),1*6,1*6,2*6,1*6,1*6,4*6
dw 2 dup(2*6,2*6,1*6,1*6),4*6
dw 3 dup(2*6,1*6,1*6),4*6
table_1 dw 262 ;c
dw 294 ;d
dw 330 ;e
dw 349 ;f
dw 392 ;g
dw 440 ;a
dw 494 ;b
dw 523 ;c
;****************
flag db 00h
ratio equ 1
blank db 0dh,0ah,0dh,0ah,'$'
err_1 db ' The press key is no use.',0dh,0ah
db ' Please press the ESC key to up page !',0dh,0ah,'$'
string db ' Please press <1> or <2> key to select playing music!'
db 0dh,0ah,0dh,0ah,'$'
string0 db '*******************************************************',0dh,0ah
db ' If you do not want to lisen or play the music.',0dh,0ah
db ' -> Please press ESC key to return to dos.',0dh,0ah
db ' -> Please ENTERN key to reflash the screen.',0dh,0ah
db '*******************************************************',0dh,0ah,'$'
string1 db ' <1> music_1',0dh,0ah,0dh,0ah,'$'
string2 db ' <2> music_2',0dh,0ah,'$'
string3 db 0dh,0ah,' <3> music_3',0dh,0ah,'$'
string4 db 0dh,0ah,'------Press SPACE key to self_play with 1 to 8 key',0dh,0ah,'$'
str_11 db ' ---music_1 is playing.',0dh,0ah,0dh,0ah,'$'
str_21 db ' ---music_2 is playing.',0dh,0ah,0dh,0ah,'$'
str_31 db ' ---music_3 is playing.',0dh,0ah,0dh,0ah,'$'
str_41 db 0dh,0ah,' --->please press 1 to 8 key to play your music',0dh,0ah
db ' or press ENTERN key to up page',0dh,0ah,'$'
dseg ends
;**************************************************
cseg segment para 'code'
assume cs:cseg,ss:stackear,ds:dseg
start: ;L proc far
mov ax,dseg
mov ds,ax
mov ax,stackear
mov ss,ax
mov sp,offset top
kk:
mov ah,0
mov al,3
int 10h
call clr_screen
lea dx,blank
mov ah,9
int 21h
lea dx,string
mov ah,09h
int 21h
lea dx,string1
mov ah,09h
int 21h
lea dx,string2
mov ah,09h
int 21h
lea dx,string3
int 21h
lea dx,string4
int 21h
lea dx,blank
int 21h
lea dx,string0
mov ah,09h
int 21h
re_read:
mov ah,1
int 16h
jnz re_read
mov ah,0
int 16h
cmp ah,02h
jz key_1
cmp ah,03h
jz key_2
cmp ah,04
jz key_3
cmp ah,01h
jz key_esck
cmp ah,39h
jz key_space
cmp ah,1ch
jz key_ent
mov ah,0
mov al,3
int 10h
call clr_screen
mov ah,0
mov al,3
int 10h
or flag,00000001b
lea dx,blank
mov ah,09
int 21h
lea dx,err_1
mov ah,09h
int 21h
lea si,mus_time2
mov bx,0350h
call sound_play
jmp re_read
key_esck:
jmp key_esc
key_1:
or flag,00000010b
lea dx,str_11
mov ah,9
int 21h
call play_1
and flag,11111101b
jmp re_read
key_2:
or flag,00000100b
lea dx,str_21
mov ah,9
int 21h
call play_2
and flag,11111011b
jmp re_read
key_3:
or flag,00001000b
lea dx,str_31
mov ah,9
int 21h
call play_3
and flag,11110111b
jmp re_read
key_space:
lea dx,str_41
mov ah,09h
int 21h
call self_play
ret
key_ent:
jmp kk
key_esc:
test flag,01h
jz esc_0
mov ah,0
mov al,3
int 10h
call clr_screen
mov ah,0
mov al,3
int 10h
lea dx,blank
mov ah,09
int 21h
lea dx,string
mov ah,09h
int 21h
lea dx,string1
mov ah,09h
int 21h
lea dx,string2
mov ah,09h
int 21h
lea dx,blank
int 21h
lea dx,string0
mov ah,09h
int 21h
and flag,11111110b
jmp re_read
esc_0:
call clr_screen
jmp retdos
play_1:
call music
and flag,11111101b
ret
play_2:
call music
and flag,11111011b
ret
play_3:
call music
and flag,11110111b
ret
;/////////////////////////////////
music:
test flag,00000010b
jnz mus_1
mov cx,28
lea si,mus_time2
lea bp,ds:mus_freq2
jmp musl
mus_1:
test flag,00000100b
jnz mus_2
mov cx,26
lea si,mus_time
lea bp,ds:mus_freq
jmp musl
mus_2:
mov cx,25
lea si,mus_time1
lea bp,ds:mus_freq1
musl:
push cx
mov bx,ds:[bp]
; add bx,0fffh
call sound_play
add si,2
add bp,2
pop cx
loop musl ;oo
ret
;////////////////////////////////////
re_readk:
jmp kk
;////////////////////////////////////
self_play:
mov ah,0
int 16h
cmp al,0dh
je re_readk
mov bx,offset table_1
cmp al,'1'
jb self_play
cmp al,'8'
ja self_play
and ax,0fh
shl ax,1
sub ax,2
mov si,ax
mov di,[bx][si]
mov bx,[si]
lea si,mus_time0
call sound_play
jmp self_play
ret
;/////////////////////////////////////////////
clr_screen:
push ax
push bx
push cx
push dx
mov ah,6
mov ah,0
mov bh,7
mov ch,0
mov cl,0
mov dh,24
mov dl,79
int 10h
mov dx,0
mov ah,2
int 10h
pop dx
pop cx
pop bx
pop ax
ret
retdos:
mov ah,0
mov al,3
int 10h
mov ax,4c00h
int 21h
; ***********************************
; * 声音播放 *
; ***********************************
sound_play proc
assume cs:cseg
; need set BX (Used for Frequency)
;
push es
push ax
push cx
in al,61h
or al,03h
and al,0ffh
out 61h,al
mov al,0b6h
out 43h,al
mov al,bl
out 42h,al
mov al,bh
out 42h,al
mov cx,0040h
mov es,cx
mov cx,es:[006ch]
push ax
mov ax,[si]
push bx
mov bl,ratio
mul bl
pop bx
add ax,cx
mov cx,ax
pop ax
s_wait:
cmp cx,es:[006ch]
jnb s_wait
in al,62h
and al,0fch
out 61h,al
pop cx
pop ax
pop es
ret
sound_play endp
soundf proc far
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 61,al
wait1: mov cx,2800
delay: loop delay
dec bx
jnz wait1
mov al,ah
out 61h,al
pop di
pop dx
pop cx
pop bx
pop ax
ret
soundf endp
cseg ends
end start
稍微注释了下!
str_11 db ' ---music_1 is playing.',0dh,0ah,0dh,0ah,'$'
str_21 db ' ---music_2 is playing.',0dh,0ah,0dh,0ah,'$'
str_31 db ' ---music_3 is playing.',0dh,0ah,0dh,0ah,'$'
str_41 db 0dh,0ah,' --->please press 1 to 8 key to play
此3条代码是 分别代表3种不同的音月
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课