Such a huge message that I can't even hold it. Let me get some explain soon. I'm still learning ROM hacking so there maybe have some wrong explainations.
The Rust code is definitely compiled to ARM code and running in NDS machine (The screenshot is No$GBA but it also work in real machine (on my 3DS)), not by Emulator's features (Lua or anything else).
As we know NDS have a feature called overlay which behaved like DLLs that can be loaded into memory and executed. So I configured Rust compiler to let it compiled an pure ARM overlay file that can be injected into ROM and memory.
To load this overlay we need to write a little assembly to call the NitroSDK API "FS_LoadOverlay" at the start time. Here I used ARMIPS as the assembly compiler. (It's a great tool
)
First we hooked "FS_Init" call and run our initialize code. I used CrystalTile2 to search NitroSDK API functions and their address. Then I used an useless arm9 code space to load overlay and execute it. (In this game is a 12x12 font character graph which will be useless after translation hacking)
And to have a space to load overlay in memory without being overwrote by other program, I moved the heap starting pointer to create a space that can fit the overlay code. First I used CrystalTile2 to search the heap pointer.
So we searched the address and modify it in assembly. Now we have a clear space for our overlay.
The 0x219AF60 is the heap starting address and it will be the entry point of our rust code. So we also need a linker script to define the code area to locate the entry point. Then the code should be executed as wished.
About the font cache, although NitroSDK provided their own fonts loading and printing technique but this game doesn't use it. It just placed the fonts in arm9 code directly with very little kanji which is impossible to just be replaced by thousands of Chinese characters. So I have to write external code to let it read our own font file stored in ROM and print it. And the font cache is to reduce ROM reading frequency (Some old flashcards will freeze the game when the ROM reading is too heavy and too frequently) and ensure the font in VRAM will keep in their own memory and being referenced as planned.
Back to Rust itself, it's a good language that have some modern features and let us write patch code easier. So I tried to use it on this translation hacking just for learning and fun.
As I know some of the Chinese translation rom hackers already using C language to write patch code. So I just basically learnt the method and tried to upgrade it to Rust. And that's it.
My forum user level limited me to post further message since I just started to post. Reply if there's anything I doesn't explain clearly.