PlayCryHeader and related wram

This commit is contained in:
yenatch 2013-02-23 16:47:39 -05:00
parent f56f340ce1
commit 8bbfa54059
3 changed files with 124 additions and 30 deletions

View File

@ -2352,72 +2352,87 @@ LoadMusic: ; e8b30
; e8b79 ; e8b79
PlayCry: ; e8b79 PlayCry: ; e8b79
; input: de = cry id ; Play cry de using parameters:
; CryPitch
; CryEcho
; CryLength
call MusicOff call MusicOff
; load cry id
; Overload the music id with the cry id
ld hl, MusicID ld hl, MusicID
ld [hl], e ld [hl], e
inc hl inc hl
ld [hl], d ld [hl], d
; seek pointer table
; 3-byte pointers (bank, address)
ld hl, Cries ld hl, Cries
add hl, de add hl, de
add hl, de add hl, de
add hl, de add hl, de
; get bank
ld a, [hli] ld a, [hli]
ld [MusicBank], a ld [MusicBank], a
; get address
ld e, [hl] ld e, [hl]
inc hl inc hl
ld d, [hl] ld d, [hl]
; read cry header
; get byte at bank:address ; Read the cry's sound header
call FarLoadMusicByte call FarLoadMusicByte
; get top 2 bits (# chs) ; Top 2 bits contain the number of channels
rlca rlca
rlca rlca
and a, $03 and a, 3
inc a ; ch count -> loop count
; For each channel:
inc a
.loop .loop
push af push af
call LoadChannel call LoadChannel
ld hl, Channel1Flags - Channel1 ld hl, Channel1Flags - Channel1
add hl, bc add hl, bc
set 5, [hl] set 5, [hl]
ld hl, Channel1Flags2 - Channel1 ld hl, Channel1Flags2 - Channel1
add hl, bc add hl, bc
set 4, [hl] set 4, [hl]
ld hl, $0027
ld hl, Channel1CryPitch - Channel1
add hl, bc add hl, bc
ld a, [$c2b0] ld a, [CryPitch]
ld [hli], a ld [hli], a
ld a, [$c2b1] ld a, [CryEcho]
ld [hl], a ld [hl], a
; are we on the last channel? (music & sfx)
; No tempo for channel 4
ld a, [CurChannel] ld a, [CurChannel]
and a, $03 and a, 3
cp a, $03 cp 3
jr nc, .start jr nc, .start
; update tempo
; Tempo is effectively length
ld hl, Channel1Tempo - Channel1 ld hl, Channel1Tempo - Channel1
add hl, bc add hl, bc
ld a, [$c2b2] ld a, [CryLength]
ld [hli], a ld [hli], a
ld a, [$c2b3] ld a, [CryLength+1]
ld [hl], a ld [hl], a
.start .start
call StartChannel call StartChannel
ld a, [$c2bc] ld a, [$c2bc]
and a and a
jr z, .next jr z, .next
; play cry from the side of the monster it's coming from (stereo only)
; outside of battles cries play on both tracks ; Stereo only: Play cry from the monster's side.
; is stereo on? ; This only applies in-battle.
ld a, [Options] ld a, [Options]
bit 5, a ; stereo bit 5, a ; stereo
jr z, .next jr z, .next
; and [Tracks], [CryTracks]
; [Tracks] &= [CryTracks]
ld hl, Channel1Tracks - Channel1 ld hl, Channel1Tracks - Channel1
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
@ -2426,21 +2441,25 @@ PlayCry: ; e8b79
ld hl, Channel1Tracks - Channel1 ld hl, Channel1Tracks - Channel1
add hl, bc add hl, bc
ld [hl], a ld [hl], a
.next .next
pop af pop af
dec a dec a
jr nz, .loop jr nz, .loop
; save current volume
; Cries play at max volume, so we save the current volume for later.
ld a, [LastVolume] ld a, [LastVolume]
and a and a
jr nz, .end jr nz, .end
ld a, [Volume] ld a, [Volume]
ld [LastVolume], a ld [LastVolume], a
; cries have max volume
ld a, $77 ld a, $77
ld [Volume], a ld [Volume], a
.end .end
ld a, $01 ; stop playing music ld a, 1 ; stop playing music
ld [SFXPriority], a ld [SFXPriority], a
call MusicOn call MusicOn
ret ret

View File

@ -3392,7 +3392,71 @@ StartMusic: ; 3b97
ret ret
; 3bbc ; 3bbc
INCBIN "baserom.gbc",$3bbc,$3c23 - $3bbc INCBIN "baserom.gbc",$3bbc,$3be3 - $3bbc
PlayCryHeader: ; 3be3
; Play a cry given parameters in header de
push hl
push de
push bc
push af
; Save current bank
ld a, [$ff9d]
push af
; Cry headers are stuck in one bank.
ld a, BANK(CryHeaders)
ld [$ff9d], a
ld [$2000], a
; Each header is 6 bytes long:
ld hl, CryHeaders
add hl, de
add hl, de
add hl, de
add hl, de
add hl, de
add hl, de
; Header struct:
; id
ld e, [hl]
inc hl
ld d, [hl]
inc hl
; pitch
ld a, [hli]
ld [CryPitch], a
; echo
ld a, [hli]
ld [CryEcho], a
; length
ld a, [hli]
ld [CryLength], a
ld a, [hl]
ld [CryLength+1], a
; That's it for the header
ld a, BANK(PlayCry)
ld [$ff9d], a
ld [$2000], a
call PlayCry
; Restore bank
pop af
ld [$ff9d], a
ld [$2000], a
pop af
pop bc
pop de
pop hl
ret
; 3c23
StartSFX: ; 3c23 StartSFX: ; 3c23
; sfx id order is by priority (highest to lowest) ; sfx id order is by priority (highest to lowest)

View File

@ -168,7 +168,13 @@ Channel1VibratoRate: ; c121
ds 1 ds 1
; c126 ; c126
ds 1 ds 1
ds 7 ; c127
ds 1
Channel1CryPitch: ; c128
ds 1
Channel1CryEcho: ; c129
ds 1
ds 4
Channel1NoteLength: ; c12e Channel1NoteLength: ; c12e
; # frames per 16th note ; # frames per 16th note
ds 1 ds 1
@ -278,9 +284,14 @@ MusicFadeIDLo: ; c2a9
ds 1 ds 1
MusicFadeIDHi: ; c2aa MusicFadeIDHi: ; c2aa
ds 1 ds 1
ds 9 ds 5
CryPitch: ; c2b0
ds 1
CryEcho: ; c2b1
ds 1
CryLength: ; c2b2
ds 2
LastVolume: ; c2b4 LastVolume: ; c2b4
; preserves volume of a song playing so cries can have their own volume
ds 1 ds 1
ds 1 ds 1
SFXPriority: ; c2b6 SFXPriority: ; c2b6