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

132 lines
2.7 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 0
!word 0
!word 0
!word 0
k251Progression
!byte 3
!word M2
!word M5
!word M1
k6251Progression
!byte 4
!word M6
!word M2
!word M5
!word M1
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
; TODO
rts
inc progressionIndex
lda gWorldID
asl
tax
lda kProgressionsByWorld, x
sta $FE
inx
lda kProgressionsByWorld, x
sta $FF
lda progressionIndex
asl
tay
iny
lda ($FE), y
pha
iny
lda ($FE), y
tay
pla
jmp PlaySound
;------------------------------------------------------------------------------
; 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