Clean up and add a couple functions in bank 0

Mostly related to sound
This commit is contained in:
yenatch 2013-05-02 21:55:03 -04:00
parent 10604fe8b3
commit b921c130e8
1 changed files with 162 additions and 63 deletions

209
main.asm
View File

@ -3920,60 +3920,122 @@ BattleTextBox: ; 3ac3
FarBattleTextBox: ; 3ad5 FarBattleTextBox: ; 3ad5
; save bank ; Open a textbox and print text at 20:hl.
ld a, [$ff9d] ; bank
ld a, [hROMBank]
push af push af
; bank 20
ld a, $20 ld a, $20
rst $10 rst Bankswitch
; print text at hl
call BattleTextBox call BattleTextBox
; restore bank
pop af pop af
rst $10 rst Bankswitch
ret ret
; 3ae1 ; 3ae1
INCBIN "baserom.gbc", $3ae1, $3b86 - $3ae1 INCBIN "baserom.gbc", $3ae1, $3b4e - $3ae1
LoadMusicByte: ; 3b86
; load music data into CurMusicByte
; input:
; a: bank
; de: address
ld [hROMBank], a
ld [$2000], a ; bankswitch
ld a, [de]
ld [CurMusicByte], a
ld a, $3a ; manual bank restore
ld [hROMBank], a
ld [$2000], a ; bankswitch
ret
; 3b97
StartMusic: ; 3b97 CleanSoundRestart: ; 3b4e
; input:
; e = song number
push hl push hl
push de push de
push bc push bc
push af push af
ld a, [hROMBank] ; save bank
ld a, [hROMBank]
push af push af
ld a, BANK(LoadMusic) ld a, BANK(SoundRestart)
ld [hROMBank], a ld [hROMBank], a
ld [$2000], a ; bankswitch ld [$2000], a
ld a, e ; song number
call SoundRestart
pop af
ld [hROMBank], a
ld [$2000], a
pop af
pop bc
pop de
pop hl
ret
; 3b6a
CleanUpdateSound: ; 3b6a
push hl
push de
push bc
push af
ld a, [hROMBank]
push af
ld a, BANK(UpdateSound)
ld [hROMBank], a
ld [$2000], a
call UpdateSound
pop af
ld [hROMBank], a
ld [$2000], a
pop af
pop bc
pop de
pop hl
ret
; 3b86
LoadMusicByte: ; 3b86
; CurMusicByte = [a:de]
ld [hROMBank], a
ld [$2000], a
ld a, [de]
ld [CurMusicByte], a
ld a, $3a ; manual bank restore
ld [hROMBank], a
ld [$2000], a
ret
; 3b97
StartMusic: ; 3b97
; Play music de.
push hl
push de
push bc
push af
ld a, [hROMBank]
push af
ld a, BANK(LoadMusic) ; and BANK(SoundRestart)
ld [hROMBank], a
ld [$2000], a
ld a, e
and a and a
jr z, .nomusic jr z, .nomusic
call LoadMusic call LoadMusic
jr .end jr .end
.nomusic .nomusic
call SoundRestart call SoundRestart
.end .end
pop af pop af
ld [hROMBank], a ; restore bank ld [hROMBank], a
ld [$2000], a ld [$2000], a
pop af pop af
pop bc pop bc
@ -3982,7 +4044,40 @@ StartMusic: ; 3b97
ret ret
; 3bbc ; 3bbc
INCBIN "baserom.gbc", $3bbc, $3be3 - $3bbc
StartMusic2: ; 3bbc
; Stop playing music, then play music de.
push hl
push de
push bc
push af
ld a, [hROMBank]
push af
ld a, BANK(LoadMusic)
ld [hROMBank], a
ld [$2000], a
push de
ld de, MUSIC_NONE
call LoadMusic
call DelayFrame
pop de
call LoadMusic
pop af
ld [hROMBank], a
ld [$2000], a
pop af
pop bc
pop de
pop hl
ret
; 3be3
PlayCryHeader: ; 3be3 PlayCryHeader: ; 3be3
; Play a cry given parameters in header de ; Play a cry given parameters in header de
@ -4010,32 +4105,26 @@ PlayCryHeader: ; 3be3
add hl, de add hl, de
add hl, de add hl, de
; Header struct:
; id
ld e, [hl] ld e, [hl]
inc hl inc hl
ld d, [hl] ld d, [hl]
inc hl inc hl
; pitch
ld a, [hli] ld a, [hli]
ld [CryPitch], a ld [CryPitch], a
; echo
ld a, [hli] ld a, [hli]
ld [CryEcho], a ld [CryEcho], a
; length
ld a, [hli] ld a, [hli]
ld [CryLength], a ld [CryLength], a
ld a, [hl] ld a, [hl]
ld [CryLength+1], a ld [CryLength+1], a
; That's it for the header
ld a, BANK(PlayCry) ld a, BANK(PlayCry)
ld [hROMBank], a ld [hROMBank], a
ld [$2000], a ld [$2000], a
call PlayCry call PlayCry
; Restore bank
pop af pop af
ld [hROMBank], a ld [hROMBank], a
ld [$2000], a ld [$2000], a
@ -4049,31 +4138,35 @@ PlayCryHeader: ; 3be3
StartSFX: ; 3c23 StartSFX: ; 3c23
; sfx id order is by priority (highest to lowest) ; Play sound effect de.
; to disable this, remove the check! ; Sound effects are ordered by priority (lowest to highest)
; input: de = sfx id
push hl push hl
push de push de
push bc push bc
push af push af
; is something already playing?
; Is something already playing?
call CheckSFX call CheckSFX
jr nc, .asm_3c32 jr nc, .play
; only play sfx if it has priority ; Does it have priority?
ld a, [CurSFX] ld a, [CurSFX]
cp e cp e
jr c, .quit jr c, .quit
.asm_3c32
ld a, [hROMBank] ; save bank .play
ld a, [hROMBank]
push af push af
ld a, $3a ; music bank ld a, BANK(LoadSFX)
ld [hROMBank], a ld [hROMBank], a
ld [$2000], a ; bankswitch ld [$2000], a ; bankswitch
ld a, e ld a, e
ld [CurSFX], a ld [CurSFX], a
call LoadSFX call LoadSFX
pop af pop af
ld [hROMBank], a ; restore bank ld [hROMBank], a
ld [$2000], a ; bankswitch ld [$2000], a ; bankswitch
.quit .quit
pop af pop af
@ -4083,31 +4176,37 @@ StartSFX: ; 3c23
ret ret
; 3c4e ; 3c4e
INCBIN "baserom.gbc", $3c4e, $3c55-$3c4e
WaitPlaySFX: ; 3c4e
call WaitSFX
call StartSFX
ret
; 3c55
WaitSFX: ; 3c55 WaitSFX: ; 3c55
; infinite loop until sfx is done playing ; infinite loop until sfx is done playing
push hl push hl
.loop .loop
; ch5 on? ; ch5 on?
ld hl, $c1cc ; Channel5Flags ld hl, Channel5 + Channel1Flags - Channel1
bit 0, [hl] bit 0, [hl]
jr nz, .loop jr nz, .loop
; ch6 on? ; ch6 on?
ld hl, $c1fe ; Channel6Flags ld hl, Channel6 + Channel1Flags - Channel1
bit 0, [hl] bit 0, [hl]
jr nz, .loop jr nz, .loop
; ch7 on? ; ch7 on?
ld hl, $c230 ; Channel7Flags ld hl, Channel7 + Channel1Flags - Channel1
bit 0, [hl] bit 0, [hl]
jr nz, .loop jr nz, .loop
; ch8 on? ; ch8 on?
ld hl, $c262 ; Channel8Flags ld hl, Channel8 + Channel1Flags - Channel1
bit 0, [hl] bit 0, [hl]
jr nz, .loop jr nz, .loop
; we're done
pop hl pop hl
ret ret
; 3c74 ; 3c74