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
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]
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
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; I N C L U D E F I L E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include \masm32\include\w2k\ntstatus.inc
include \masm32\include\w2k\ntddk.inc
include \masm32\include\w2k\hal.inc
includelib \masm32\lib\w2k\hal.lib
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; U S E R D E F I N E D E Q U A T E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; U S E R D E F I N E D M A C R O S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DO_DELAY MACRO delays
; Silly method, but it works ;-)
mov eax, delays
.while eax
dec eax
.endw
ENDM
.code
MakeBeep proc dwPitch:DWORD ,dwdelay:DWORD
; Direct hardware access
cli
mov al, 10110110y
out 43h, al ; delayr 8253-5 (AT: 8254.2).
mov eax, dwPitch
out 42h, al
mov al, ah
out 42h, al
; speaker ON
in al, 61h
or al, 11y
out 61h, al
sti
DO_DELAY dwdelay
cli
; speaker OFF
in al, 61h
and al, 11111100y
out 61h, al