From e0ebf4eb7b63769a4bf3bb7f0cd6479a788cbc8d Mon Sep 17 00:00:00 2001 From: TriteHexagon <37734530+TriteHexagon@users.noreply.github.com> Date: Thu, 26 Nov 2020 11:57:32 +0000 Subject: Created Add a new music command to change drumkits (noisesampleset) (markdown) --- ...-command-to-change-drumkits-(noisesampleset).md | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Add-a-new-music-command-to-change-drumkits-(noisesampleset).md diff --git a/Add-a-new-music-command-to-change-drumkits-(noisesampleset).md b/Add-a-new-music-command-to-change-drumkits-(noisesampleset).md new file mode 100644 index 0000000..f3113b6 --- /dev/null +++ b/Add-a-new-music-command-to-change-drumkits-(noisesampleset).md @@ -0,0 +1,79 @@ +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**: + +```diff +- 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: + +```diff +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. \ No newline at end of file -- cgit v1.2.3