This is my accidental discovery when compiling C. Let me take an example:
#include "include/gbafe.h"
int GetUnitPower(const struct Unit* unit){
int iPow = unit->pow;
iPow += GetItemPowBonus(GetUnitEquippedWeapon(unit));
// just for test
iPow++;
return iPow;
}
Note that the file Definitions.h.s
, which will be used for linking then, also contains the function definition “GetUnitPower”:
@ inside Definitions.h.s
SET_FUNC GetUnitPower, 0x80191B1
Refer to @StanH 's C tutorial to compile it, and Something interesting happened :
PUSH
ORG $191b0
ALIGN 4
SHORT $4778 $46C0
WORD $E59FC000 $E12FFF1C
POIN GetUnitPower
POP
ALIGN 4
PUSH
ORG CURRENTOFFSET+$1;GetUnitPower:
POP
SHORT $B510 $2414 $4B05 $5704 $F000 $F80C $4B04 $F000 $F809 $1820 $3001 $BC10 $BC02 $4708
BYTE $29 $6B $1 $8 $21 $64 $1 $8
SHORT $4718 $46C0
A “PUSH” and “POP” at 0x80191B1 ???
Then just set the ROM Buildfile.event
as this:
ORG $B2A610
#include "src/JumpTest.lyn.event"
No “jumpToHack”, just include lyn file and then everyone get power+1 and this program can be jumpted from the original GetUnitPower (0x80191B0)
function Location:
I am not very clear how the compiler implements such a jump at specific location, but this may be an easy way to skip the “jumpToHack” in the Buildfile, and directly jump to C function when compiling.
In particular, when you are intended to replace an original function in Vanilla, this may be an easy way.