作者loveflames (.....)
看板ASM
标题Re: [问题] 组语如何发声音?(已有程式了)
时间Sun Jun 3 15:27:30 2007
无聊做了一点修改
应该有人听得出是啥吧
;------------------------
C1 EQU 11C4H ; 1190000/261.63 (之16进位)
C2 EQU 0FD4H ; 1190000/293.67 (之16进位)
C3 EQU 0E1AH ; 1190000/329.63 (之16进位)
C4 EQU 0D50H ; 1190000/349.23 (之16进位)
C5 EQU 0BDCH ; 1190000/392.00 (之16进位)
C6 EQU 0A91H ; 1190000/440.00 (之16进位)
C7 EQU 0969H ; 1190000/493.89 (之16进位)
D1 EQU 08E2H ; 1190000/(261.63*2) (之16进位)
D2 EQU 07EAH;1190000/(293.67*2)
D3 EQU 070DH ;1190000 /(329.63*2 )
.MODEL SMALL
.STACK
.DATA
MUSIC DW C1,C1,C3,C3,C5,C5,C3,C2,C3,D1,C6,C5,C6
DW C3,C6,C5,C4,C5,C5,C4,C6,C5,D1,C7
DW D2,D1,C6,C6,D1,C6,C5,C3,C2,C1,C5,C5,C5
DW C6,C5,C5,C5,D1,D1,D1,C6,C5,C5,C5,C5,D3,D3,D2,D3
DW D2,D2,C5,D2,D2,D2,D3,D1,D1, 00
.CODE
;----------------------------------------------------------------
; THIS PROCEDURE WILL PLAY THE INPUT FREQUENCY IN DX
; ON SPEAKER
PLAY PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
;10110110
MOV AL, 0B6H ; SET PARAMETERS OF 8254
OUT 43H, AL ; SET 8254 CONTROL MODE
MOV AL, DL ; SET 8254 TIMER 2 DATA
OUT 42H, AL ; FREQUENCY IN DX
MOV AL, DH ;
OUT 42H, AL
MOV AX, 2000H
DELAY: MOV CX, 0FFFFH
DELY2: NOP
LOOP DELY2
DEC AX
JNZ DELAY
POP DX
POP CX
POP BX
POP AX
RET
PLAY ENDP
;----------------------------------------------------------------
MAIN:
MOV AX, @DATA
MOV DS, AX
IN AL, 61H ; OPEN SPEAKER
OR AL, 00000011B
OUT 61H, AL
MOV BX, OFFSET MUSIC ; SET INITIAL MUSIC POINTER IN BX
SOUND: MOV DX, DS:[BX] ; GET SOUND FREQUENCY IN DX
CMP DX,0 ; CHECK END
JZ EXIT ;
CALL PLAY ; CALL PLAY PROCEDURE
ADD BX,2 ; INCREASE BX POINTER BY 2
JMP SOUND ; AGAIN
EXIT: IN AL, 61H ; CLOSE SPEAKER
AND AL, 11111100B
OUT 61H, AL
MOV AH, 4CH
INT 21H
END MAIN
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.225.2.208