-
Notifications
You must be signed in to change notification settings - Fork 806
Add a new music command to change drumkits
In this tutorial we'll implement a new command is called noisesampleset
. It basically changes the drumkit used on the fly. For some background information, there are many different noise "notes" but each drumkit only has 12 slots, so there are multiple different drumkits to choose from. The original game has a command to set the drumkit (togglenoise
), but using it again turns off the noise channel entirely. For compatibility reasons, it's better to create a new command to do this than change the original one.
(This code was adapted from Polished Crystal)
Edit macros/scripts/audio.asm:
- const unknownmusic0xf9_cmd ; $f9
- unknownmusic0xf9: MACRO
- db unknownmusic0xf9_cmd
- ENDM
+ const noisesampleset_cmd ; $f9
+noisesampleset: MACRO
+ db noisesampleset_cmd
+ db \1 ; noise
+ ENDM
Edit audio/engine.asm in these spots:
MusicCommands:
(...)
dw MusicF1 ; nothing
dw MusicF2 ; nothing
dw MusicF3 ; nothing
dw MusicF4 ; nothing
dw MusicF5 ; nothing
dw MusicF6 ; nothing
dw MusicF7 ; nothing
dw MusicF8 ; nothing
- dw MusicF9 ; unused
+ dw Music_ChangeNoiseSampleSet ; noisesampleset
dw Music_SetCondition ; set condition
dw Music_JumpIf ; jumpif
dw Music_Jump ; jump
dw Music_Loop ; loop
dw Music_Call ; call
dw Music_Ret ; return
_PlayMusic::
(...)
.loop
; start playing channels
push af
call LoadChannel
call StartChannel
pop af
dec a
jr nz, .loop
xor a
- ld [wUnusedMusicF9Flag], a
ld [wChannel1JumpCondition], a
ld [wChannel2JumpCondition], a
(...)
-MusicF9:
-; sets some flag
-; seems to be unused
-; params: 0
- ld a, TRUE
- ld [wUnusedMusicF9Flag], a
- ret
(...)
Music_ToggleNoise: ; e893b
(...)
.on
; turn noise sampling on
set SOUND_NOISE, [hl]
+Music_ChangeNoiseSampleSet:
call GetMusicByte
ld [MusicNoiseSampleSet], a
ret
That's pretty much it! We are just removing an unused music command and replacing it with our new one, which reuses a piece of code from Music_ToggleNoise
that already exists.