📄 sound.asm
字号:
;============================================================================================
;============================================================================================
PlaySound:
; JB B_Demo,NoPlaySound
STA SoundPtr ; "SoundPtr" * 3
CLC ;
ROL ;
ADC SoundPtr ;
STA R_Index ; "Xi" is a dummy X register
INC R_Index
LDA #SOUND_START/100H
STA R_Index+1
LDA (R_Index) ; load the OffsetValue of the "SoundLen" ("X")
;R_TEMP
CLC
ADC R_Index+1
STA Sound_Start
DEC R_Index
LDA (R_Index)
STA R_Index
LDA Sound_Start
STA R_Index+1
LDA (R_Index)
CLC
ADC #01H
STA SoundLen ; store the "length" of the sound file
INC R_Index ;
INC R_Index
LDA (R_Index)
STA Speed ; store the "speed" for playing sound
STA SpeedCnt ; store down counter of the "speed"
INC R_Index
INC R_Index
INC R_Index
LDA R_Index
STA SoundPtr ; store the first byte of the SoundFile to "SoundPtr"
SETB fSounding
TMR0_ON ; open tmr0
PWM_ON
NoPlaySound:
RTS
;--------------------------------
DivUpdateSound:
JNB fSounding,exSd ; if no fSounding, exit
DEC SpeedCnt
BNE exSd ; if SoundCnt<>0, sound continue
LDA Speed
STA SpeedCnt ; store the "Speed" to "SpeedCnt" for next "syllable"
LDA SoundLen
BEQ EndSound ; if "SoundLen"=0, sound end
DEC SoundLen
LDA SoundPtr
STA R_Index
LDA Sound_Start
STA R_Index+1
LDA (R_Index) ; load the syllable
EOR #0FFH
CLC
ADC #01H
BCS ?silence ; if the "syllable"=0, sound switch off
STA TMR0 ; store to tmr0
PWM_ON ; sound switch on
JMP ?ext
?silence
PWM_OFF ; sound switch off
?ext
INCW SoundPtr ; "SoundPtr"+1, point to the next "syllable"
exSd:
RTS
EndSound:
CLRB fSounding
TMR0_OFF ; tmr0 close
PWM_OFF ; sound switch off
RTS
;===================================================================================
F_UpDataSound:
IF_NOT_DIV_IRQ_FLAG F_UpDataSound
CLR_DIV_IRQ_FLAG
JSR DivUpdateSound
RTS
;=====================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -