I'm having a problem with this routine in Emerald.
[massive wall of text]
It's supposed to check for the first gym badge (flag 0x867), then if it's set it checks for the other gym badges. It then branches to a script which adds 5 to the base power ram location 0x02024400 per badge. This is to increase the base power of a move as you progress through the game. The asm is called before the damagecalculation.
Currently it just freezes the game. What's wrong with it?
As far as I can see, there are a couple of small problems with this routine, as well as some things that we don't know. First of all, where are you hooking from? We need to know the offset of the hook.
The first problem with this routine is that you don't actually get 0x867 into r0 in the very beginning.
.thumb
start:
mov r0, #0x86
lsl r0, r0, #0x4
add r0, r0, #0x7This is what you should be doing to get 0x867 into r0.
In addition, some things are rather confusing. What is the function at 0x809D790? I know this is the get_flag address, but that's because I went and checked. You should use a label. Your first check is wrong as well. If you wanted to jump to the end if the first flag's not set, then just jump to the end rather than jumping to somewhere that jumps to the end.
What I think you're trying to do; get the first flag in r0, then seeing if that flag is set. If it is, check to see if the next flag is set, otherwise jump to the first battlescript. If the second badge is set, check the third badge, etc.
What you're actually doing; loading a flag into r0, then comparing that. If it is set, then it'll continue to add 1 to the result of the the function you called earlier. This will either cause only the first or second check to actually result in anything.
My suggestion; drop the battlescript, it's rather complicated to call a battlescript in a function. Instead, read and write directly to that offset. Also, edit your checks and your flag checks.
start:
push
load byte from base_power(0x02024400) into r5
get flag in both r0 and r4
bl to flag_check
check if the flag was set
if it wasn't, b to the_end
add five to r5
add 1 to r4
bl to flag_check
check to see if second flag was set
if it wasn't b to the_end
add five to r5
add 1 to r4, then bl to flag_check
(you can do this until you checked all your flags)
the_end:
store r5 in 0x02024400
pop
flag_check:
move r4 to r0
make r1 0x0809D790 + 1
bx r1
This is kinda sloppy and can be done by a loop, but once you make a routine resembling this, I'll show you how to make this into a loop.
~EDIT~ Oh yeah and just as a reminder, you should add a check to make sure that this routine only does this to one move or else you'll be increasing the power of every move. In addition, the AI will calculate how to use that move based on its original base power, and will get the same bonus that you do when using this move.