million-perfect-letters/src/glue.sound.a
2020-05-12 22:25:32 -04:00

149 lines
3.1 KiB
Plaintext

;
; convenience functions for playing sounds through different libraries
;
; Public functions:
; - InitSound
; - ReinitSoundAfterPrefChange
; - LoopSound
; - PlaySound
; - SoftBell
;
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
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
InitPuzzleSound
lda #$FF
sta progressionIndex
rts
PlayNextChord
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
jmp PlaySound
PlayFinalChord
; out: preserves A
pha
+LD16 kFinalChord
jsr PlaySound
pla
rts
;------------------------------------------------------------------------------
; SoftBell
;
; in: none
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
SoftBell
lda gSoundPref
beq +
ldx #32
- lda #2
jsr ROM_WAIT
bit SPEAKER
lda #33
jsr ROM_WAIT
bit SPEAKER
dex
bne -
+ rts