million-perfect-letters/src/glue.sound.a

167 lines
3.4 KiB
Plaintext

;
; convenience functions for playing sounds through different libraries
;
; Public functions:
; - InitSound
; - ReinitSoundAfterPrefChange
; - LoopSound
; - PlaySound
; - PlaySoundToCompletion
; - ErrorSound
;
gMockingboardSlot
!byte 0
gSoundPref
!byte 1 ; 0 = no sound, 1 = sound
progressionIndex ; [byte][private]
!byte 0
kProgressionsByWorld ; chord progression to use on each world (index=world)
!word k251Progression
!word k251Progression
!word k251Progression
!word k251Progression
!word k6251Progression
!word k6251Progression
!word k6251Progression
!word k6251Progression
!word k16251Progression
!word k16251Progression
!word k16251Progression
!word k16251Progression
k251Progression
!byte 2
!word M_ii
!word M_V
k6251Progression
!byte 3
!word M_vi6
!word M_ii
!word M_V
k16251Progression
!byte 4
!word M_I
!word M_vi6
!word M_ii
!word M_V
kFinalChord
!word M_I_LONG
kErrorSound
!word M_ERROR
ReinitSoundAfterPrefChange
ldx gMockingboardSlot
InitSound
stx gMockingboardSlot
lda gSoundPref
beq @theSoundOfSilence
cpx #0
beq @playThroughSpeaker
+LDADDR MockingDuet
bne + ; always branches
@playThroughSpeaker
+LDADDR ElectricDuet
bne + ; always branches
@theSoundOfSilence
+LDADDR Silence
+
+ST16 SoundLibraryDispatch
rts
-
+LD16 $FE
LoopSound
sec
+HIDE_NEXT_BYTE
PlaySound
clc
php
+ST16 $1E
+ST16 $FE
SoundLibraryDispatch=*+1
jsr $FDFD ; SMC
plp
bcc +
lda KBD
bpl -
+ lda KBD
Silence rts
PlaySoundToCompletion
pha
lda ED0974+1
sta @restoreED
lda MBKEYBRANCH+1
sta @restoreMB
lda #0
sta ED0974+1
sta MBKEYBRANCH+1
pla
jsr PlaySound
php
pha
@restoreED=*+1
lda #$FD ; SMC
sta ED0974+1
@restoreMB=*+1
lda #$FD ; SMC
sta MBKEYBRANCH+1
pla
plp
rts
InitPuzzleSound
lda #$FF
sta progressionIndex
rts
PlayNextChord
; out: preserves X
txa
pha
lda gWorldID
asl
tax
lda kProgressionsByWorld, x
sta $FE
inx
lda kProgressionsByWorld, x
sta $FF
inc progressionIndex
ldy #0
lda ($FE), y
cmp progressionIndex
bne +
dec progressionIndex
+ lda progressionIndex
asl
tay
iny
lda ($FE), y
pha
iny
lda ($FE), y
tay
pla
jsr PlaySoundToCompletion
pla
tax
rts
PlayFinalChord
; out: preserves X
txa
pha
+LD16 kFinalChord
jsr PlaySoundToCompletion
pla
tax
rts
ErrorSound
+LD16 kErrorSound
jmp PlaySound