Assembly: Adaptive BGM and Danger Area

Here I’ll be uploading some ASM I wrote. I’m pretty new to thumb assembly and have not shared ASM before, so expect issues when trying to use this stuff. I’d really appreciate it if you could tell me of any issues you run into!

I implemented both of these hacks on an FE8 rom that’s already had the skillsystem (2020-02-23) (credits below) implemented, so things may not work on a clean rom. I also used FEBuilder’s Event Assembler to implement the code. I definitely don’t expect the code to work in FE7 or FE6. In short: I’d advise assembling the code in a skillsystem FE8U rom.

UPDATE: Alright, I removed the hard-coding in both Adaptive BGM and Danger Area, things should work better now.

Also, massive thanks to the people who helped me understand asm over at the spell-academy channel in FEU’s discord. You’ve been a great help! Teq’s guide has also been incredibly helpful:

Adaptive BGM

Dropbox containing the patch.

I’ve actually decided to rework this patch a little, and I’ll upload a better version soon. I may be able to circumvent the Popuprework, and make the code work for vanilla FE8U as well as skillsystem FE8U. UPDATE: It’s been reworked, and no longer relies on the Popuprework.

What it do?
Basically, Adaptive BGM mutes/unmutes certain tracks/channels of a midi during battle and unmutes/mutes those tracks outside of battle. In the example I provided in dropbox, I’m using a modifed version of Desire Below (arranged by Libera over at ninsheetmusic, modifed by me). Outside of battle, only tracks 1, 2 and 3 are playing (0, 1, 2 depending on your mood). When battle starts, tracks 4 and up are unmuted. When battle ends tracks 4 and up are muted again.

Prerequisites
To take full advantage of Adaptive BGM, you should assemble the Change Battle BGM By Chapter (credit: 7743) patch.

You should probably also assemble the 16 Tracks/12 Sounds Fix (credit: Agro/Brendor) patch. It’s part of the Essential Fixes of the skillsystem.

Make sure NOT to assemble the Continue Battle BGM Between Map and Combat (credit: 7743) patch. Adaptive BGM actually uses a modifed version of Continue Battle BGM.

How to install
There’s 2 options:

1. If you have a buildfile, just add an #include "FE8-CalmFlow/CalmFlow.txt" to the buildfile. Make sure that the FE8-CalmFlow folder is in the same directory. Alternatively download the Dependencies folder and buildfile.event, and assemble buildfile.event using a clean FE8U ROM.

2. Apply the FE8U-ABGM.ups patch to a clean ROM. This patch also sets the Prologue’s Player Phase BGM, Player Phase Battle BGM, Enemy Phase BGM and Enemy Phase Battle BGM to Desire Below. Please let me know if the patch doesn’t adapt successfully, or if something goes wrong.

How to use
I’ll be using FEBuilder a lot in this section. I find it more easy to work with for this part.

There’s no need to keep the .midi, .s or .mp4 files in the FE8-CalmFlow folder, but to replicate what’s happening in the .mp4 sample, import Fire Emblem Fates - Desire Below.s in FEBuilder’s Song Track editor to track 3DD.

Make sure to also set 3DD's priority type to High (Map Music) in FEBuilder’s Song Table. Finally, in the chapter editor, set the Player Phase BGM and the Player Battle BGM and/or the Enemy Phase BGM and Enemy Battle BGM to 3DD. That should be all.

Customization
Right-o, that’s all neat for this one (poorly adapted) soundtrack, but what about other soundtracks? Well, there’s some room for customization!

  • Simply importing a different MIDI to location 3DD will have the same effect of channels 4 and up being unmuted during battle and muted outside of battle.
  • This effect can also be applied to a different location, X, if you replace all instances of 3DD in InitCalm.asm, ReturnCalm.asm, FadeoutCalm.asm, EndBattleCalm and ContinueBattleBGM.asm with X and re-assemble these files.
  • What if you want to mute different (from the top 3) channels outside of battle? Not very hard, but requires a little knowledge of asm. I’ll provide some details below.
  • Maybe there are certain channels you wish to mute during battle. This one will also require some asm knowledge. More details below.
  • You may want to have multiple soundtracks that can adapt. Maybe for one of these soundtracks channels 3 and up should be muted outside of battle, yet for another soundtrack it’s channels 5 and up. This requires more asm stuff. this time too, it’s not particularly hard, but rather than me painstakingly explaining every step for this one I’d rather you take a look at the asm (I commented it) and ask me if anything isn’t clear, so I can clarify it.
Muting channels outside of battle

There’s a cmp rX, #0xD command (where X can be some number between 0 and 7) in InitCalm.asm, ReturnCalm.asm and FadeoutCalm.asm, followed by a conditional branch (either ble or bgt). 0xD ensures that channels 3 (0xE), 2 (0xF) and 1 (0x10) remain unmuted outside of battle. increment 0xD to 0xE, and only channel 1 and 2 will be unmuted outside of battle. Decrement 0xD to 0xC and channel 1, 2, 3 and 4 will remain unmuted outside of battle. You will also have to increase or decrease the immediate in line 36 of ContinueBattleBGM.asm accordingly, to indicate which tracks should be unmuted during battle. Also, the immediate in line 38 of EndBattleBGM.asm needs to be adapted appropriately as well. As long as the channels that are to be muted outside of battle are at the top (not interwoven with the other tracks), this will work. If they aren’t, you’ll have add a few more conditional and unconditional branches and labels. Teq’s guide should be very helpful for this: GBAFE Assembly for Dummies, by Dummies

muting channels during battle

I won’t go into too much detail this time, but to mute channels when battle starts you’ll have to put some conditional branches around line 52 in ContinueBattleBGM.asm. If the immediate in line 52 is 0x40, the track (which should be 0x10-r5) at that iteration of the loop will be unmuted when battle starts. If the immediate is 0x0 the track will be muted when battle starts. r5 contains the counter which counts down for every iteration of the loop, and we know which track we’re dealing with by subtracting it from 0x10.

Concluding
In retrospect, after writing all these paragraphs, I do see how user-unfriendly this patch really is. I still believe it’s more helpful than nothing, but I understand it’s not very attractive to have to do assembly-coding to ‘properly’ take advantage of this patch. I’ll see if I can make the patch more user-friendly in the future!

Danger Area

Dropbox containing the patch.

How to install
There’s 3 options:

1. If you have a buildfile, just add an #include "FE8-FogDZ/FE8-FogDZ.txt" to the buildfile. Make sure that the FE8-FogDZ folder is in the same directory. You will need to also build the skillsystem. Replace the DangerZone.event file in skillsystem/Engine Hacks/QualityOfLife/DangerZone with the DangerZone.event file in Other Stuff.

2. There’s a UPS patch called SkillsTest.ups in Other Stuff. apply that patch to a clean FE8U ROM. This will also install the skillsystem (The ‘version’ I downloaded on 20/5/2020, that’s 5/20/2020 in American, I believe). Tell me if it doesn’t work.

3.

  • Download the latest version (or any of the other more recent versions) of the skillsystem, put it in some folder (I’ll refer to it as the skillsystem folder from hereon).
  • Get the latest version of Event assembler (v11.0.1 as of the latest release) and put it in the skillsystem folder.
  • Get a clean rom called “FE8_clean.gba” and put it in the skillsystem folder.
  • Place the FE8-FogDZ folder (make sure the name is FE8-FogDZ) in the skillsystem folder.
  • Replace the skillsystem ROM Buildfile.event with the one in Other Stuff .
  • In the skillsystem/Engine Hacks/QualityOfLife/DangerZone folder, replace DangerZone.event with the one in Other Stuff .
  • Run MAKE HACK_full.cmd .

Assuming MAKE HACK_full didn’t report any errors, there should then be a SkillsTest.gba file in the skillsystem folder.

What it do?
This patch implements a more permanent version of Danger Area/Danger Zone. The danger zone will remain visible even when selecting/moving units, and will also adjust before committing to a move. To enable Danger Area, press select. Press select again to disable.

Limitations

  • This patch replaces the Fog of War, FOW, functionality with Danger Area. Essentially, Fog is used to display Danger Area. This means that you won’t be able to use Fog of War for any chapter if this patch is installed. Just to be safe, I’d recommend disabling Fog on every chapter.
  • The Danger Area calculation is pretty slow (maybe this is why vanilla fe8 doesn’t enable it despite it being present?). As a result, enabling it under certain circumstances (when there’s a lot of enemy units on the field, or maybe when the map size is considerable, not quite sure) will slow down the game considerably whenever the danger area is recalculated. These circumstances appear to be pretty common too, unfortunately.
  • Danger Area automatically disables itself when the current phase is not player phase. It’ll have to be manually re-enabled (by pressing select) when it’s the player phase.

Danger Area Colour
If you want the danger area to display as a purple ‘layer’ instead of it using the default FOW palette, you’ll have to replace the FOW palette. This can be done quite easily in FEBuilder, and is what I did to obtain the palette used in the example gif:

The palette I’m using in the sample gif can be obtained by following these steps:

  • Ensure the Tileset Palette is “Fields(01 02 03 05 00)” and Palette Type is “1=fog.” Both are marked in red in the image above.
  • Set Palette No. to “0000=0 palette.” Go to the Digitize Palette menu by pressing the Clipboard button and enter
    1900934D9149D741185A9530D4553339123D9645D74D5441F03CD861B65D173D
    before pressing Change.
  • Set Palette No. to “1000=1 palette.” Go to the Digitize Palette menu by pressing the Clipboard button and enter
    0038B541113D14668D556C552D550F51EF4CD655B255D255D44DB349724D5345
    before pressing Change.
  • Set Palette No. to “2000=2 palette.” Go to the Digitize Palette menu by pressing the Clipboard button and enter
    0038F1510F49165EF359F255B151D451914DD559B05592557349514D1045F555
    before pressing Change.
  • Set Palette No. to “3000=3 palette.” Go to the Digitize Palette menu by pressing the Clipboard button and enter
    00387341394EF35139621962184E1556B64DF459AF596E594E5931551051534D
    before pressing Change.
  • Set Palette No. to “4000=4 palette.” Go to the Digitize Palette menu by pressing the Clipboard button and enter
    00385A66576A345EF255F255B2597249524D19621952D84D764D54493245F165
    before pressing Change.

Do note that this only changes the FOW palette for the “Fields(01 02 03 05 00)” tileset palette. To get the purplish Danger Area for any other tileset, you’ll still have to change their palettes. Of course, feel free to go for a completely different palette (negative, sepia, black-and-white, go wild).

Concluding
This one doesn’t require too much extra effort on behalf of the user… well, comparatively at least. I could research if I could change the tileset palette as part of the patch, but if I manage to implement that, the patch will mess up custom FOW tileset palettes. I also have plans of creating a more ‘individual’ Danger Area; One where you can select which enemies should be included in the Danger Area calculation instead of all enemies being included as standard. Unfortunately, I wouldn’t be able to implement both Danger Area and ‘Individual’ Danger Area, as there’s only one FOW palette per tileset. Either way, the choice would atleast be there for the user.

2020-05-19_20-10-23

Again, please tell me if you run into any issues adapting these patches. I’m also new to these forums, so Hi!

SkillSystem Credits

Circleseverywhere
Colorz for debuffs, freeze, and dragon veins
Monkeybard & Black Mage for most of the skill icons; Blaze for Stances skill icons; vlak for Drive skill icons; Pikmin1211 for miscellaneous icons; Zaim for Indoor March icon
Tequila, Rossendale, StanH, Leonarth, 2WB, Teraspark, Darrman, SD9k, Kao, blademaster, Snakey1, Zeta, Kirb, Sme, Ganzap for skills, 7743 for various bugfixes
Primefusion for the test map
Str/Mag Split based off of Kirb’s FE8 version which is based off of Tequila’s FE7 version. RobertFPY, Pikmin1211, and Snakey1 for finalization)

31 Likes

really gonna post a screenshot of ManBat! rennac with no context huh

for this adaptive bgm, is this similar to like what fe13/14/16 do with the rain/thunder versions? I’m trying to understand the functionality

1 Like

I’m not quite sure quite what those games exactly do to transition between the rain/thunder versions, but that is the effect I’m trying to replicate, yes.

I’d upload Rennac’s class to the animation directory, but I’m still planning on tweaking it a little.

3 Likes

basically they have one track with two versions of the same song and the versions switch in real time during battle

so this wouldn’t restart the song but continue it on then? that is a very neat thing to add

Well, this doesn’t switch any soundtracks. It mutes certain parts of the song, instruments (sorta), outside of battle, and unmutes them during battle.

The main limiting factor here is that the two versions of the song share the same 12-note limit.

is it possible to upload a video showing it off?

There’s an .mp4 in the dropbox I linked. I’ll upload it to youtube and see if I can embed it.

EDIT: the youtube video is up and embedded.

1 Like

Oh shit this is actually really cool

i really like the dangerzone range display

oh yeah is exactly what i was thinking
aka sicko mode

Sicko mode… in a good sense?

1 Like

I see danger zone display, I like

1 Like

yuh, this is insane.
For some reason I swear danger zones already existed, but I wouldn’t use them anyway because I’m sadistic. Still, I know that this is a big, sudden contribution from a newcomer, and people with actually good design philosophies are gonna love it. I hope you get the “new member of the month” award.

2 Likes

iirc the danger zone that already exists doesnt continue to show like this one - if you click away on the existing danger zone hack it gets rid of the danger zone thing while this one appears to stay in place

Yes, the original Danger Zone is a bit flighty. I tried to go for a more permanent solution.

UPDATE: I added the Danger Zone patch and instructions.

EDIT: And now the dropbox link is correct, woops, sorry.

4 Likes

This is actually poggers, I’m definitely keeping an eye out for this if you’re continuing to work on it

So, there’s no way to keep this Danger Zone and the FoW?
Maybe using a palette that isn’t tied to the tilesets?
Like a table in which you can set which palette is used for a tileset.

Edit: I found a Bug.
With the Danger Zone active, the skill Elbow Room gives a massive boost of 127 might.
SkillsTest_02 SkillsTest_03
I guess the same happens with Natural Cover.

Thanks! I’ll look into that bug!

The way I understood it, is that there’s a limited amount of palettes that can be displayed at any time for a layer. Which is why there’s no room to let the maptile-layer display more palettes. On second read-through, I’m not quite sure if that actually answers your question.

In all fairness, when you know you’re in danger your fight-or-flight response kicks into overgear. Our buddy over here injected a heap of elephant steroids just so he can delete the enemies.

5 Likes

Yoooooo, that adaptive music thing is epic ngl