Insert Crystal audio engine and music

most credit goes to Sanqui
This commit is contained in:
dannye 2017-05-07 15:30:08 -05:00
parent 832c28eaea
commit 87eed68710
586 changed files with 193763 additions and 6447 deletions

View file

@ -23,7 +23,7 @@ HallOfFamePC:
call EnableLCD
ld a, $ff
call PlaySoundWaitForCurrent
ld c, BANK(Music_Credits)
ld c, 0 ; BANK(Music_Credits)
ld a, MUSIC_CREDITS
call PlayMusic
ld c, 128

View file

@ -200,7 +200,7 @@ PlayAnimation:
push hl
push de
call GetMoveSound
call PlaySound
call nc, AnimPlaySFX
pop de
pop hl
.skipPlayingSound
@ -256,6 +256,15 @@ PlayAnimation:
.AnimationOver
ret
AnimPlaySFX:
push de
ld e, a
xor a
ld d, a
call PlaySFX
pop de
ret
LoadSubanimation:
ld a,[wSubAnimAddrPtr + 1]
ld h,a
@ -551,7 +560,7 @@ PlaySubanimation:
cp a,$FF
jr z,.skipPlayingSound
call GetMoveSound
call PlaySound
call nc, AnimPlaySFX
.skipPlayingSound
ld hl,wOAMBuffer ; base address of OAM buffer
ld a,l
@ -2328,18 +2337,28 @@ GetMoveSound:
.next
ld a,[wEnemyMonSpecies]
.Continue
push hl
call GetCryData
ld b,a
pop hl
ld a,[wFrequencyModifier]
add [hl]
ld [wFrequencyModifier],a
inc hl
ld a,[wTempoModifier]
add [hl]
ld [wTempoModifier],a
jr .done
push af
ld a, 1
ld [wSFXDontWait], a
pop af
call PlayCry
xor a
ld [wSFXDontWait], a
ld a, b
scf
ret
;push hl
;call GetCryData
;ld b,a
;pop hl
;ld a,[wFrequencyModifier]
;add [hl]
;ld [wFrequencyModifier],a
;inc hl
;ld a,[wTempoModifier]
;add [hl]
;ld [wTempoModifier],a
;jr .done
.NotCryMove
ld a,[hli]
ld [wFrequencyModifier],a
@ -3011,24 +3030,27 @@ PlayApplyingAttackSound:
; play a different sound depending if move is not very effective, neutral, or super-effective
; don't play any sound at all if move is ineffective
call WaitForSoundToFinish
ld a, [wDamageMultipliers]
ld a, [wDamageMultipliers] ; effectiveness
and $7f
ret z
cp 10
ld a, $20
ld b, $30
ld c, SFX_DAMAGE
ld c, GSSFX_DAMAGE ; SFX_DAMAGE
jr z, .playSound
ld a, $e0
ld b, $ff
ld c, SFX_SUPER_EFFECTIVE
ld c, GSSFX_SUPER_EFFECTIVE ; SFX_SUPER_EFFECTIVE
jr nc, .playSound
ld a, $50
ld b, $1
ld c, SFX_NOT_VERY_EFFECTIVE
ld c, GSSFX_NOT_VERY_EFFECTIVE ; SFX_NOT_VERY_EFFECTIVE
.playSound
ld [wFrequencyModifier], a
ld a, b
ld [wTempoModifier], a
ld a, c
jp PlaySound
jp PlaySound

View file

@ -955,7 +955,7 @@ EndLowHealthAlarm:
; This function is called when the player has the won the battle. It turns off
; the low health alarm and prevents it from reactivating until the next battle.
xor a
ld [wLowHealthAlarm], a ; turn off low health alarm
ld [wDanger], a ; turn off low health alarm
ld [wChannelSoundIDs + Ch4], a
inc a
ld [wLowHealthAlarmDisabled], a ; prevent it from reactivating
@ -1051,7 +1051,7 @@ PlayBattleVictoryMusic:
ld a, $ff
ld [wNewSoundID], a
call PlaySoundWaitForCurrent
ld c, BANK(Music_DefeatedTrainer)
ld c, 0 ; BANK(Music_DefeatedTrainer)
pop af
call PlayMusic
jp Delay3
@ -1098,11 +1098,11 @@ RemoveFaintedPlayerMon:
predef FlagActionPredef ; clear gain exp flag for fainted mon
ld hl, wEnemyBattleStatus1
res 2, [hl] ; reset "attacking multiple times" flag
ld a, [wLowHealthAlarm]
ld a, [wDanger]
bit 7, a ; skip sound flag (red bar (?))
jr z, .skipWaitForSound
ld a, $ff
ld [wLowHealthAlarm], a ;disable low health alarm
ld [wDanger], a ;disable low health alarm
call WaitForSoundToFinish
.skipWaitForSound
; a is 0, so this zeroes the enemy's accumulated damage.
@ -1949,7 +1949,7 @@ DrawPlayerHUDAndHPBar:
cp HP_BAR_RED
jr z, .setLowHealthAlarm
.fainted
ld hl, wLowHealthAlarm
ld hl, wDanger
bit 7, [hl] ;low health alarm enabled?
ld [hl], $0
ret z
@ -1957,7 +1957,7 @@ DrawPlayerHUDAndHPBar:
ld [wChannelSoundIDs + Ch4], a
ret
.setLowHealthAlarm
ld hl, wLowHealthAlarm
ld hl, wDanger
set 7, [hl] ;enable low health alarm
ret

View file

@ -45,7 +45,7 @@ EndOfBattle:
predef EvolutionAfterBattle
.resetVariables
xor a
ld [wLowHealthAlarm], a ;disable low health alarm
ld [wDanger], a ;disable low health alarm
ld [wChannelSoundIDs + Ch4], a
ld [wIsInBattle], a
ld [wBattleType], a

View file

@ -284,7 +284,7 @@ CableClub_DoBattleOrTradeAgain:
predef HealParty
jp ReturnToCableClubRoom
.trading
ld c, BANK(Music_GameCorner)
ld c, 0 ; BANK(Music_GameCorner)
ld a, MUSIC_GAME_CORNER
call PlayMusic
jr CallCurrentTradeCenterFunction
@ -917,7 +917,7 @@ CableClub_Run:
ld [hJoy5], a
ld a, 10
ld [wAudioFadeOutControl], a
ld a, BANK(Music_Celadon)
ld a, 0 ; BANK(Music_Celadon)
ld [wAudioSavedROMBank], a
ld a, MUSIC_CELADON
ld [wNewSoundID], a

View file

@ -7,7 +7,7 @@ EvolveMon:
ld a, [wd0b5]
push af
xor a
ld [wLowHealthAlarm], a
ld [wDanger], a
ld [wChannelSoundIDs + Ch4], a
dec a
ld [wNewSoundID], a
@ -41,7 +41,7 @@ EvolveMon:
ld a, [wEvoOldSpecies]
call PlayCry
call WaitForSoundToFinish
ld c, BANK(Music_SafariZone)
ld c, 0 ; BANK(Music_SafariZone)
ld a, MUSIC_SAFARI_ZONE
call PlayMusic
ld c, 80

View file

@ -33,7 +33,7 @@ AnimateHallOfFame:
.skipInc
ld a, $90
ld [hWY], a
ld c, BANK(Music_HallOfFame)
ld c, 0 ; BANK(Music_HallOfFame)
ld a, MUSIC_HALL_OF_FAME
call PlayMusic
ld hl, wPartySpecies

View file

@ -473,3 +473,10 @@ VermilionGymTrashFailText:
call PlaySound
call WaitForSoundToFinish
jp TextScriptEnd
; Trash cans are broken and can read the 255th entry sometimes for
; the second can.
; rgblink was placing stuff here, so the behavior was different from
; original Red. This is the simplest non-code fix: allocate zeroes as
; far as the broken code could reach.
ds 255

View file

@ -67,13 +67,11 @@ SafariZoneGameOver:
ld [wAudioFadeOutControl], a
dec a
call PlaySound
ld c, BANK(SFX_Safari_Zone_PA)
ld c, 0 ; BANK(SFX_Safari_Zone_PA)
ld a, SFX_SAFARI_ZONE_PA
call PlayMusic
.waitForMusicToPlay
ld a, [wChannelSoundIDs + Ch4]
cp SFX_SAFARI_ZONE_PA
jr nz, .waitForMusicToPlay
call PlaySound
call WaitForSoundToFinish
ld a, TEXT_SAFARI_GAME_OVER
ld [hSpriteIndexOrTextID], a
call DisplayTextID

View file

@ -328,12 +328,12 @@ PlayShootingStar:
ld c, 40
call DelayFrames
.next
ld a, BANK(Music_IntroBattle)
ld a, 0 ; BANK(Music_IntroBattle)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, MUSIC_INTRO_BATTLE
ld [wNewSoundID], a
call PlaySound
call PlayMusic
call IntroClearMiddleOfScreen
call ClearSprites
jp Delay3

View file

@ -989,7 +989,7 @@ ItemUseMedicine:
jp .cureStatusAilment
.notFullHP ; if the pokemon's current HP doesn't equal its max HP
xor a
ld [wLowHealthAlarm],a ;disable low health alarm
ld [wDanger],a ;disable low health alarm
ld [wChannelSoundIDs + Ch4],a
push hl
push de
@ -1771,11 +1771,11 @@ ItemUsePokeflute:
; if some pokemon were asleep
ld hl,PlayedFluteHadEffectText
call PrintText
ld a,[wLowHealthAlarm]
ld a,[wDanger]
and a,$80
jr nz,.skipMusic
call WaitForSoundToFinish ; wait for sound to end
callba Music_PokeFluteInBattle ; play in-battle pokeflute music
;callba Music_PokeFluteInBattle ; play in-battle pokeflute music ; XXX
.musicWaitLoop ; wait for music to finish playing
ld a,[wChannelSoundIDs + Ch6]
and a ; music off?
@ -1847,12 +1847,9 @@ PlayedFluteHadEffectText:
ld a,$ff
call PlaySound ; turn off music
ld a, SFX_POKEFLUE
ld c, BANK(SFX_Pokeflute)
call PlayMusic
.musicWaitLoop ; wait for music to finish playing
ld a,[wChannelSoundIDs + Ch2]
cp a, SFX_POKEFLUE
jr z,.musicWaitLoop
ld c, 0 ; BANK(SFX_Pokeflute)
call PlaySound
call WaitForSoundToFinish
call PlayDefaultMusic ; start playing normal music again
.done
jp TextScriptEnd ; end text

View file

@ -224,9 +224,11 @@ BillsPCDeposit:
jp c, BillsPCMenu
call DisplayDepositWithdrawMenu
jp nc, BillsPCMenu
call WaitForSoundToFinish
ld a, [wcf91]
call GetCryData
call PlaySoundWaitForCurrent
call PlayCry
;call GetCryData
;call PlaySoundWaitForCurrent
ld a, PARTY_TO_BOX
ld [wMoveMonType], a
call MoveMon
@ -276,9 +278,11 @@ BillsPCWithdraw:
ld a, [wWhichPokemon]
ld hl, wBoxMonNicks
call GetPartyMonName
call WaitForSoundToFinish
ld a, [wcf91]
call GetCryData
call PlaySoundWaitForCurrent
call PlayCry
;call GetCryData
;call PlaySoundWaitForCurrent
xor a ; BOX_TO_PARTY
ld [wMoveMonType], a
call MoveMon
@ -551,4 +555,3 @@ JustAMomentText::
OpenBillsPCText::
db $FD ; FuncTX_BillsPC

View file

@ -143,8 +143,10 @@ HandlePokedexSideMenu:
; play pokemon cry
.choseCry
ld a,[wd11e]
call GetCryData
call PlaySound
push af
call PlayCry
pop af
ld [wd11e], a
jr .handleMenuInput
.choseArea

View file

@ -34,7 +34,7 @@ SetDefaultNames:
OakSpeech:
ld a,$FF
call PlaySound ; stop music
ld a, BANK(Music_Routes2)
ld a, 0 ; BANK(Music_Routes2)
ld c,a
ld a, MUSIC_ROUTES2
call PlayMusic
@ -128,7 +128,7 @@ OakSpeech:
call ResetPlayerSpriteData
ld a,[H_LOADEDROMBANK]
push af
ld a, BANK(Music_PalletTown)
ld a, 0 ; BANK(Music_PalletTown)
ld [wAudioROMBank],a
ld [wAudioSavedROMBank],a
ld a, 10

View file

@ -17,9 +17,9 @@ ShakeElevator:
add d
ld [hSCY], a
push bc
ld c, BANK(SFX_Collision_1)
ld c, 0 ; BANK(SFX_Collision_1)
ld a, SFX_COLLISION
call PlayMusic
call PlaySound
pop bc
ld c, 2
call DelayFrames
@ -29,9 +29,9 @@ ShakeElevator:
ld [hSCY], a
ld a, $ff
call PlaySound
ld c, BANK(SFX_Safari_Zone_PA)
ld c, 0 ; BANK(SFX_Safari_Zone_PA)
ld a, SFX_SAFARI_ZONE_PA
call PlayMusic
call PlaySound
.musicLoop
ld a, [wChannelSoundIDs + Ch4]
cp SFX_SAFARI_ZONE_PA

View file

@ -1,4 +1,7 @@
AnimateHealingMachine:
xor a
call PlayMusic
ld de, PokeCenterFlashingMonitorAndHealBall
ld hl, vChars0 + $7c0
lb bc, BANK(PokeCenterFlashingMonitorAndHealBall), $03 ; loads one too many tiles
@ -15,15 +18,17 @@ AnimateHealingMachine:
ld hl, wOAMBuffer + $84
ld de, PokeCenterOAMData
call CopyHealingMachineOAM
ld a, 4
ld [wAudioFadeOutControl], a
ld a, $ff
ld [wNewSoundID], a
call PlaySound
.waitLoop
ld a, [wAudioFadeOutControl]
and a ; is fade-out finished?
jr nz, .waitLoop ; if not, check again
; ld a, 4
; ld [wAudioFadeOutControl], a
; ld a, $ff
; ld [wNewSoundID], a
; call PlaySound
;.waitLoop
; ld a, [wAudioFadeOutControl]
; and a ; is fade-out finished?
; jr nz, .waitLoop ; if not, check again
ld a, [wPartyCount]
ld b, a
.partyLoop
@ -35,24 +40,25 @@ AnimateHealingMachine:
dec b
jr nz, .partyLoop
ld a, [wAudioROMBank]
cp BANK(Audio3_UpdateMusic)
cp $1f ; 0 ; BANK(Audio3_UpdateMusic) XXXXX
ld [wAudioSavedROMBank], a
jr nz, .next
ld a, $ff
ld [wNewSoundID], a
call PlaySound
ld a, BANK(Music_PkmnHealed)
ld a, 0 ; BANK(Music_PkmnHealed)
ld [wAudioROMBank], a
.next
ld a, MUSIC_PKMN_HEALED
ld [wNewSoundID], a
call PlaySound
call PlayMusic
ld d, $28
call FlashSprite8Times
.waitLoop2
ld a, [wChannelSoundIDs]
cp MUSIC_PKMN_HEALED ; is the healed music still playing?
jr z, .waitLoop2 ; if so, check gain
ld a, [Channel1MusicID]
and a
jr nz, .waitLoop2
ld c, 32
call DelayFrames
pop af
@ -60,6 +66,8 @@ AnimateHealingMachine:
pop hl
pop af
ld [hl], a
jp UpdateSprites
PokeCenterFlashingMonitorAndHealBall:

View file

@ -117,6 +117,9 @@ UpdateNPCSprite:
ld hl, wMapSpriteData
add l
ld l, a
jr nc, .nc
inc h
.nc
ld a, [hl] ; read movement byte 2
ld [wCurSpriteMovement2], a
ld h, $c1

View file

@ -162,12 +162,12 @@ PewterMuseumGuyMovementScriptPointerTable:
dw PewterMovementScript_Done
PewterMovementScript_WalkToMuseum:
ld a, BANK(Music_MuseumGuy)
ld a, 0 ; BANK(Music_MuseumGuy)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, MUSIC_MUSEUM_GUY
ld [wNewSoundID], a
call PlaySound
call PlayMusic
ld a, [wSpriteIndex]
swap a
ld [wNPCMovementScriptSpriteOffset], a
@ -218,12 +218,12 @@ PewterGymGuyMovementScriptPointerTable:
dw PewterMovementScript_Done
PewterMovementScript_WalkToGym:
ld a, BANK(Music_MuseumGuy)
ld a, 0 ; BANK(Music_MuseumGuy)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, MUSIC_MUSEUM_GUY
ld [wNewSoundID], a
call PlaySound
call PlayMusic
ld a, [wSpriteIndex]
swap a
ld [wNPCMovementScriptSpriteOffset], a

View file

@ -30,7 +30,7 @@ DisplayPokemonCenterDialogue_:
ld a, [wMapMusicSoundID]
ld [wLastMusicSoundID], a
ld [wNewSoundID], a
call PlaySound
call PlayMusic
ld hl, PokemonFightingFitText
call PrintText
ld a, $14

View file

@ -58,7 +58,7 @@ PredefPointers::
add_predef ScaleSpriteByTwo
add_predef LoadMonBackPic
add_predef CopyDownscaledMonTiles
dbw $03,JumpMoveEffect ; wrong bank
add_predef LoadMissableObjects ; dbw $03,JumpMoveEffect ; wrong bank XXXXX
add_predef HealParty
add_predef MoveAnimation
add_predef DivideBCDPredef

View file

@ -4,6 +4,10 @@ LoadSAV:
call ClearScreen
call LoadFontTilePatterns
call LoadTextBoxTilePatterns
ld a, 1
ld [wHaltAudio], a
call LoadSAV0
jr c, .badsum
call LoadSAV1
@ -25,6 +29,9 @@ LoadSAV:
ld a, $1 ; bad checksum
.goodsum
ld [wSaveFileStatus], a
ld a, 0
ld [wHaltAudio], a
ret
FileDataDestroyedText:
@ -274,9 +281,18 @@ SaveSAVtoSRAM2:
SaveSAVtoSRAM:
ld a, $2
ld [wSaveFileStatus], a
ld a, 1
ld [wHaltAudio], a
call SaveSAVtoSRAM0
call SaveSAVtoSRAM1
jp SaveSAVtoSRAM2
call SaveSAVtoSRAM2
ld a, 0
ld [wHaltAudio], a
ret
SAVCheckSum:
;Check Sum (result[1 byte] is complemented)
@ -391,6 +407,9 @@ WhenYouChangeBoxText:
CopyBoxToOrFromSRAM:
; copy an entire box from hl to de with b as the SRAM bank
ld a, 1
ld [wHaltAudio], a
push hl
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
@ -416,6 +435,9 @@ CopyBoxToOrFromSRAM:
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
xor a
ld [wHaltAudio], a
ret
DisplayChangeBoxMenu:
@ -513,6 +535,9 @@ BoxNoText:
EmptyAllSRAMBoxes:
; marks all boxes in SRAM as empty (initialisation for the first time the
; player changes the box)
ld a, 1
ld [wHaltAudio], a
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
@ -526,6 +551,9 @@ EmptyAllSRAMBoxes:
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
xor a
ld [wHaltAudio], a
ret
EmptySRAMBoxesInBank:
@ -557,6 +585,9 @@ EmptySRAMBox:
ret
GetMonCountsForAllBoxes:
ld a, 1
ld [wHaltAudio], a
ld hl, wBoxMonCounts
push hl
ld a, SRAM_ENABLE
@ -583,6 +614,8 @@ GetMonCountsForAllBoxes:
ld a, [wNumInBox]
ld [hl], a
xor a
ld [wHaltAudio], a
ret
GetMonCountsForBoxesInBank:
@ -604,6 +637,9 @@ SAVCheckRandomID:
;checks if Sav file is the same by checking player's name 1st letter ($a598)
; and the two random numbers generated at game beginning
;(which are stored at wPlayerID)s
ld a, 1
ld [wHaltAudio], a
ld a,$0a
ld [MBC1SRamEnable],a
ld a,$01
@ -632,6 +668,9 @@ SAVCheckRandomID:
ld a,$00
ld [MBC1SRamBankingMode],a
ld [MBC1SRamEnable],a
xor a
ld [wHaltAudio], a
ret
SaveHallOfFameTeams:
@ -670,6 +709,9 @@ LoadHallOfFameTeams:
; fallthrough
HallOfFame_Copy:
ld a, 1
ld [wHaltAudio], a
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
@ -680,9 +722,15 @@ HallOfFame_Copy:
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
xor a
ld [wHaltAudio], a
ret
ClearSAV:
ld a, 1
ld [wHaltAudio], a
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
@ -698,6 +746,9 @@ ClearSAV:
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
xor a
ld [wHaltAudio], a
ret
PadSRAM_FF:

View file

@ -17,7 +17,7 @@ SetDefaultNamesBeforeTitlescreen:
ld [hli], a
ld [hli], a
ld [hl], a
ld a, BANK(Music_TitleScreen)
ld a, 0 ; BANK(Music_TitleScreen)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
@ -181,6 +181,9 @@ ENDC
ret
.finishedBouncingPokemonLogo
xor a
ld [hSCY], a
call LoadScreenTilesFromBuffer1
ld c, 36
call DelayFrames
@ -213,7 +216,7 @@ ENDC
call WaitForSoundToFinish
ld a, MUSIC_TITLE_SCREEN
ld [wNewSoundID], a
call PlaySound
call PlayMusic
xor a
ld [wUnusedCC5B], a