pokecrystal-board/home/audio.asm

554 lines
6.9 KiB
NASM
Raw Normal View History

; Audio interfaces.
2018-06-24 07:09:41 -07:00
MapSetup_Sound_Off::
push hl
push de
push bc
push af
ldh a, [hROMBank]
push af
2015-11-11 20:38:57 -08:00
ld a, BANK(_MapSetup_Sound_Off)
ldh [hROMBank], a
ld [MBC3RomBank], a
2015-11-11 20:38:57 -08:00
call _MapSetup_Sound_Off
pop af
ldh [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
UpdateSound::
push hl
push de
push bc
push af
ldh a, [hROMBank]
push af
ld a, BANK(_UpdateSound)
ldh [hROMBank], a
ld [MBC3RomBank], a
call _UpdateSound
pop af
ldh [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
_LoadMusicByte::
2018-01-23 14:39:09 -08:00
; wCurMusicByte = [a:de]
ldh [hROMBank], a
ld [MBC3RomBank], a
ld a, [de]
2018-01-23 14:39:09 -08:00
ld [wCurMusicByte], a
ld a, BANK(LoadMusicByte)
ldh [hROMBank], a
ld [MBC3RomBank], a
ret
2018-06-24 07:09:41 -07:00
PlayMusic::
; Play music de.
push hl
push de
push bc
push af
ldh a, [hROMBank]
push af
ld a, BANK(_PlayMusic) ; aka BANK(_MapSetup_Sound_Off)
ldh [hROMBank], a
ld [MBC3RomBank], a
ld a, e
and a
jr z, .nomusic
call _PlayMusic
jr .end
.nomusic
2015-11-11 20:38:57 -08:00
call _MapSetup_Sound_Off
.end
pop af
ldh [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
PlayMusic2::
; Stop playing music, then play music de.
push hl
push de
push bc
push af
ldh a, [hROMBank]
push af
ld a, BANK(_PlayMusic)
ldh [hROMBank], a
ld [MBC3RomBank], a
push de
ld de, MUSIC_NONE
call _PlayMusic
call DelayFrame
pop de
call _PlayMusic
pop af
ldh [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
PlayCry::
; Play cry de.
push hl
push de
push bc
push af
ldh a, [hROMBank]
push af
; Cries are stuck in one bank.
ld a, BANK(PokemonCries)
ldh [hROMBank], a
ld [MBC3RomBank], a
ld hl, PokemonCries
rept 6 ; sizeof(mon_cry)
add hl, de
2015-07-20 19:18:18 -07:00
endr
ld e, [hl]
inc hl
ld d, [hl]
inc hl
ld a, [hli]
2018-01-23 14:39:09 -08:00
ld [wCryPitch], a
ld a, [hli]
2018-01-23 14:39:09 -08:00
ld [wCryPitch + 1], a
ld a, [hli]
2018-01-23 14:39:09 -08:00
ld [wCryLength], a
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wCryLength + 1], a
ld a, BANK(_PlayCry)
ldh [hROMBank], a
ld [MBC3RomBank], a
call _PlayCry
pop af
ldh [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
PlaySFX::
; Play sound effect de.
2016-05-28 12:43:41 -07:00
; Sound effects are ordered by priority (highest to lowest)
push hl
push de
push bc
push af
; Is something already playing?
call CheckSFX
jr nc, .play
; Does it have priority?
2018-01-23 14:39:09 -08:00
ld a, [wCurSFX]
cp e
jr c, .done
.play
ldh a, [hROMBank]
push af
ld a, BANK(_PlaySFX)
ldh [hROMBank], a
ld [MBC3RomBank], a
ld a, e
2018-01-23 14:39:09 -08:00
ld [wCurSFX], a
call _PlaySFX
pop af
ldh [hROMBank], a
ld [MBC3RomBank], a
.done
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
WaitPlaySFX::
call WaitSFX
call PlaySFX
ret
2018-06-24 07:09:41 -07:00
WaitSFX::
; infinite loop until sfx is done playing
push hl
.wait
ld hl, wChannel5Flags1
bit 0, [hl]
jr nz, .wait
ld hl, wChannel6Flags1
bit 0, [hl]
jr nz, .wait
ld hl, wChannel7Flags1
bit 0, [hl]
jr nz, .wait
ld hl, wChannel8Flags1
bit 0, [hl]
jr nz, .wait
pop hl
ret
2018-06-24 07:09:41 -07:00
IsSFXPlaying::
; Return carry if no sound effect is playing.
; The inverse of CheckSFX.
push hl
ld hl, wChannel5Flags1
bit 0, [hl]
jr nz, .playing
ld hl, wChannel6Flags1
bit 0, [hl]
jr nz, .playing
ld hl, wChannel7Flags1
bit 0, [hl]
jr nz, .playing
ld hl, wChannel8Flags1
bit 0, [hl]
jr nz, .playing
pop hl
scf
ret
.playing
pop hl
and a
ret
2018-06-24 07:09:41 -07:00
MaxVolume::
2017-12-09 10:28:23 -08:00
ld a, MAX_VOLUME
ld [wVolume], a
ret
2018-06-24 07:09:41 -07:00
LowVolume::
ld a, $33 ; 40%
ld [wVolume], a
ret
2018-06-24 07:09:41 -07:00
VolumeOff::
xor a
ld [wVolume], a
ret
2018-06-24 07:09:41 -07:00
Unused_FadeOutMusic::
ld a, 4
2018-01-23 14:39:09 -08:00
ld [wMusicFade], a
ret
2018-06-24 07:09:41 -07:00
FadeInMusic::
2018-01-09 14:20:47 -08:00
ld a, 4 | (1 << MUSIC_FADE_IN_F)
2018-01-23 14:39:09 -08:00
ld [wMusicFade], a
ret
2018-06-24 07:09:41 -07:00
SkipMusic::
; Skip a frames of music.
2015-11-05 11:06:03 -08:00
.loop
and a
ret z
dec a
call UpdateSound
2015-11-05 11:06:03 -08:00
jr .loop
2018-06-24 07:09:41 -07:00
FadeToMapMusic::
push hl
push de
push bc
push af
call GetMapMusic_MaybeSpecial
ld a, [wMapMusic]
cp e
jr z, .done
ld a, 8
2018-01-23 14:39:09 -08:00
ld [wMusicFade], a
ld a, e
2018-01-23 14:39:09 -08:00
ld [wMusicFadeID], a
ld a, d
2018-01-23 14:39:09 -08:00
ld [wMusicFadeID + 1], a
ld a, e
ld [wMapMusic], a
.done
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
PlayMapMusic::
push hl
push de
push bc
push af
call GetMapMusic_MaybeSpecial
ld a, [wMapMusic]
cp e
jr z, .done
push de
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
pop de
ld a, e
ld [wMapMusic], a
call PlayMusic
.done
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
EnterMapMusic::
push hl
push de
push bc
push af
xor a
ld [wDontPlayMapMusicOnReload], a
ld de, MUSIC_BICYCLE
2018-01-23 14:39:09 -08:00
ld a, [wPlayerState]
cp PLAYER_BIKE
jr z, .play
call GetMapMusic_MaybeSpecial
.play
push de
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
pop de
ld a, e
ld [wMapMusic], a
call PlayMusic
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
TryRestartMapMusic::
ld a, [wDontPlayMapMusicOnReload]
and a
jr z, RestartMapMusic
xor a
ld [wMapMusic], a
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
xor a
ld [wDontPlayMapMusicOnReload], a
ret
2018-06-24 07:09:41 -07:00
RestartMapMusic::
push hl
push de
push bc
push af
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld a, [wMapMusic]
ld e, a
ld d, 0
call PlayMusic
pop af
pop bc
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
SpecialMapMusic::
2018-01-23 14:39:09 -08:00
ld a, [wPlayerState]
cp PLAYER_SURF
jr z, .surf
cp PLAYER_SURF_PIKA
jr z, .surf
ld a, [wStatusFlags2]
2018-01-22 12:40:43 -08:00
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, a
jr nz, .contest
.no
and a
ret
.bike
ld de, MUSIC_BICYCLE
scf
ret
.surf
ld de, MUSIC_SURF
scf
ret
.contest
2018-01-23 14:39:09 -08:00
ld a, [wMapGroup]
cp GROUP_ROUTE_35_NATIONAL_PARK_GATE
jr nz, .no
2018-01-23 14:39:09 -08:00
ld a, [wMapNumber]
cp MAP_ROUTE_35_NATIONAL_PARK_GATE
jr z, .ranking
cp MAP_ROUTE_36_NATIONAL_PARK_GATE
jr nz, .no
.ranking
ld de, MUSIC_BUG_CATCHING_CONTEST_RANKING
scf
ret
2018-06-24 07:09:41 -07:00
GetMapMusic_MaybeSpecial::
call SpecialMapMusic
ret c
call GetMapMusic
ret
2018-06-24 07:09:41 -07:00
Unreferenced_Function3d9f::
; Places a BCD number at the
; upper center of the screen.
2018-01-10 10:47:57 -08:00
ld a, 4 * TILE_WIDTH
2018-01-30 11:52:46 -08:00
ld [wVirtualOAMSprite38YCoord], a
ld [wVirtualOAMSprite39YCoord], a
2018-01-10 10:47:57 -08:00
ld a, 10 * TILE_WIDTH
2018-01-30 11:52:46 -08:00
ld [wVirtualOAMSprite38XCoord], a
2018-01-10 10:47:57 -08:00
ld a, 11 * TILE_WIDTH
2018-01-30 11:52:46 -08:00
ld [wVirtualOAMSprite39XCoord], a
xor a
2018-01-30 11:52:46 -08:00
ld [wVirtualOAMSprite38Attributes], a
ld [wVirtualOAMSprite39Attributes], a
2019-04-19 08:35:27 -07:00
ld a, [wUnusedBCDNumber]
2016-01-17 21:39:01 -08:00
cp 100
jr nc, .max
add 1
daa
ld b, a
swap a
and $f
add "0"
2018-01-30 11:52:46 -08:00
ld [wVirtualOAMSprite38TileID], a
ld a, b
and $f
add "0"
2018-01-30 11:52:46 -08:00
ld [wVirtualOAMSprite39TileID], a
ret
.max
ld a, "9"
2018-01-30 11:52:46 -08:00
ld [wVirtualOAMSprite38TileID], a
ld [wVirtualOAMSprite39TileID], a
ret
2018-06-24 07:09:41 -07:00
CheckSFX::
; Return carry if any SFX channels are active.
ld a, [wChannel5Flags1]
bit 0, a
jr nz, .playing
ld a, [wChannel6Flags1]
bit 0, a
jr nz, .playing
ld a, [wChannel7Flags1]
bit 0, a
jr nz, .playing
ld a, [wChannel8Flags1]
bit 0, a
jr nz, .playing
and a
ret
.playing
scf
ret
2018-06-24 07:09:41 -07:00
TerminateExpBarSound::
xor a
ld [wChannel5Flags1], a
2018-01-23 14:39:09 -08:00
ld [wSoundInput], a
ldh [rNR10], a
ldh [rNR11], a
ldh [rNR12], a
ldh [rNR13], a
ldh [rNR14], a
ret
2018-06-24 07:09:41 -07:00
ChannelsOff::
; Quickly turn off music channels
xor a
ld [wChannel1Flags1], a
ld [wChannel2Flags1], a
ld [wChannel3Flags1], a
ld [wChannel4Flags1], a
2018-01-23 14:39:09 -08:00
ld [wSoundInput], a
ret
2018-06-24 07:09:41 -07:00
SFXChannelsOff::
; Quickly turn off sound effect channels
xor a
ld [wChannel5Flags1], a
ld [wChannel6Flags1], a
ld [wChannel7Flags1], a
ld [wChannel8Flags1], a
2018-01-23 14:39:09 -08:00
ld [wSoundInput], a
ret