• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Using C language to hack Pokemon (3rd Gen)

9
Posts
8
Years
  • Age 29
  • Seen Jun 6, 2016
so do you know how to link "professional" libraries in our simple C files?

Not sure if there are any static library files (*.lib, *.a) that you can link with the -mthumb specifier, but if there is, just add the following to your line above:
Code:
-l/path/to/library -Llibraryname

Then, of course, don't forget to include the header files for that library:
Code:
-I/path/to/headers
 

Bonnox

Time (wasting) Lord
47
Posts
8
Years
Not sure if there are any static library files (*.lib, *.a) that you can link with the -mthumb specifier, but if there is, just add the following to your line above:
Code:
-l/path/to/library -Llibraryname
Then, of course, don't forget to include the header files for that library:
Code:
-I/path/to/headers

thanks a lot, will surely try sooner or later. I infact recall that libgba might exist in a compiled fashion (matter? substance?).

but... doesn't suffice to include the header in the source? do I really have to specify things via command line?

anyway, thank you for the support! sorry for having bothered you :)
 
Last edited:

Blah

Free supporter
1,924
Posts
11
Years
There's a library in C:\devkitPro\libgba by default if you have installed devkitarm. I dislike using a make file myself for this sort of thing, I'm pretty sure it doesn't even support things like extern.

You could try using the Python and DevkitARM dependent setup here: https://github.com/EternalCode/Empty-Template/tree/master/Sample Project

If I recall correctly, you need to execute scripts/build and scripts/insert for Linux, and windows required scripts/build2 and scripts/insert3. Sorry for the poor names. This setup is far superior for bigger projects as it also supports direct insertion and various other perks like hooking and address repointing. It works well for small single-file projects as well.
 

Bonnox

Time (wasting) Lord
47
Posts
8
Years
You could try using the Python and DevkitARM dependent setup here: https://github.com/EternalCode/Empty-Template/tree/master/Sample Project

If I recall correctly, you need to execute scripts/build and scripts/insert for Linux, and windows required scripts/build2 and scripts/insert3. Sorry for the poor names. This setup is far superior for bigger projects as it also supports direct insertion and various other perks like hooking and address repointing. It works well for small single-file projects as well.

thanks also to you, FBI.
.woah, I just discovered that also libtonc comes with an A file...
so now how to compile properly? (sorry if I'm an hassle)
if I look at openpoke, he does

#include <libtonc>

and lets the makefile do the rest.
but you said me completely different things!

Code:
arm-none-eabi-gcc -I/path/to/headers -l/path/to/library -Llibraryname -mthumb -o file.o
arm-none-eabi-gcc file.o -o asm.bin

is that correct? and in the sources?
(i did a mistake, I don't have gcc but devkit, with arm-none-eabi-gcc)

excuse me, I don't understand very well the parameters "path to library" and "libraryname". dees the latter have to match something in particular or can it be anything? and in "path to library", what does "library" identify? the A file?

therefore, assuming I want to use libtonc and didn't change the folder directory, what are the steps neded to compile?

sorry if I'm demanding for such a great detail but as you can imagine I'm a total newbie in this kind of things.
I feel really bad for bothering a "god" and a recently signed-up user :p

well, I primarily use windows :p
what do your scripts do? I used to use a simple program developed in java by me to insert a routine in the ROM :p
and once compiled, what do I have to search to branch to?

I saw your template in the other post (have to reply yet), but don't have looked at it for now. I will do, but I use ruby, does anithing change (hope/think not) ?
 
9
Posts
8
Years
  • Age 29
  • Seen Jun 6, 2016
I also recommend FBI's method, unfortunately you have to modify their python scripts to link to external stuff.

Your lines above would be correct, just your source file is missing somewhere at the beginning. /path/to/library simply refers to the folder where the library file is located in. libraryname would be libtonc then. (as far as I know, GCC automatically appends .lib or .a)

So it would basically be (libtonc in the same directory as main.c):
Code:
arm-none-eabi-gcc main.c -Llibtonc -mthumb -o file.o
arm-none-eabi-gcc file.o -o asm.bin

Check out if it works and post again if you stumble upon any problems. :)
 

Blah

Free supporter
1,924
Posts
11
Years
if I look at openpoke, he does

#include <libtonc>
...

well, I primarily use windows :p
what do your scripts do? I used to use a simple program developed in java by me to insert a routine in the ROM :p
and once compiled, what do I have to search to branch to?

I saw your template in the other post (have to reply yet), but don't have looked at it for now. I will do, but I use ruby, does anithing change (hope/think not) ?
Oh, looks like our friend Porygon has answered most of your questions, but I'll speak about the ones directed at me.

Yeah, so you can't directly do using #include <libtonc> with this python setup unless you went into C:\devkitPro\devkitARM\arm-none-eabi\include and put in the files you needed in there. You could alternatively just cp the files you wanted to use into the cwd and call it a day, lol. I personally prefer to make my own .h files for generic GBA stuff, but that's just me.

The python script build essentially is recursively doing:
arm-none-eabi-gcc -mthum -mno-thumb-interwork -mcpu=arm7tdmi -fno-inlin -mlong-calls -march=armv4t -Wall -O2 -c file.c -o ./build/file
Then doing arm-none-eabi-ld with the linker files and such.

The python script insert is taking the .bin output and placing it in the ROM, as well as setting up hooks and address repointing. It's got a nice --debug command line argument which will tell you what function was compiled into what part of the ROM. :)

For using this setup for Ruby, you first put Ruby.gba in the recycling bin and empty bin, just make sure your ROM is called BPRE.gba. It doesn't actually check the ROM tag, just the file name.
 

Bonnox

Time (wasting) Lord
47
Posts
8
Years
i feel sad telling you this, but I decided (a hard decision) to rewrite the library in ASM myself, and use it in C, because seems simplier to me rather than doing strange things with linker and compilers (i'm not used to)
Since the library is called more often than the application logic, I think that the performances will improve compared to a full C library.
I will do only the minimum necessary for a comfortable basic usage of the console (tilemap, bios, etc), trying to avoid complex themes (transformation matrix, sound) and then will put the source on this site , if tou want.
 
160
Posts
18
Years
  • Seen Dec 10, 2020
Gonna provide some input and say that I use this web tool a lot to view compiler optimizations but it will make the process of C/C++ -> ASM a much more rapid iteration process for smaller cases. You can't have multiple files included beyond the standard library but you can flatly implement your data types for the sake of getting some workable ASM out. Could possibly make a fork on github specifically for the purpose of generating pokemon asm with custom include files.
https://gcc.godbolt.org/
 

Bonnox

Time (wasting) Lord
47
Posts
8
Years
Hi all, after succeding in logging in after some months, I give a little update.

I started to write a C lightweight library for the GBA, to be used in our hacks.
Progress is slow, since I have little free time.
At the moment I have almost finished the basic systems. Remain only the dynamic memory allocation, some stuff with strings and video.

(there are several files, each one dealing with a confined aspect of the GBA mechanics, but at the end they are all included in a single one, for the sake of simplicity of compiling. sorry about that, if you're a pro)

the strange thing is that if I ensble optimizations, some of the code is broken. Moreover, seems that I am unable to usesome of the advanced features of C, like structures and array initialization (including strings... hell I've even done four function with 2, 4, 8 and 16 parameters for creating a string without having to type too much with pointers...)
 
Last edited:
794
Posts
10
Years
Hi all, after succeding in logging in after some months, I give a little update.

I started to write a C lightweight library for the GBA, to be used in our hacks.
Progress is slow, since I have little free time.
At the moment I have almost finished the basic systems. Remain only the dynamic memory allocation, some stuff with strings and video.

(there are several files, each one dealing with a confined aspect of the GBA mechanics, but at the end they are all included in a single one, for the sake of simplicity of compiling. sorry about that, if you're a pro)

the strange thing is that if I ensble optimizations, some of the code is broken. Moreover, seems that I am unable to usesome of the advanced features of C, like structures and array initialization (including strings... hell I've even done four function with 2, 4, 8 and 16 parameters for creating a string without having to type too much with pointers...)

I'd like to talk with you. Join this irc channel, I'm Dizzy there http://chat.linkandzelda.com:9090/?channels=rh.
Also, you know that we code in C already? See Emerald battle engine upgrade
 

Bonnox

Time (wasting) Lord
47
Posts
8
Years
I'd like to talk with you. Join this irc channel, I'm Dizzy there http://chat.linkandzelda.com:9090/?channels=rh.
Also, you know that we code in C already? See Emerald battle engine upgrade



well, i need a training on how to use the IRC first! haha, I'm kind of new to the internet. Moreover, I have little free time
if you want to speak with me , you could send me a PM, or use telegram (we could even make a group)! I have the same username, no profilw picture.

where do i find that source?
i'd be glad to get in touch with other programmers!
thanks
 
Last edited:

Blah

Free supporter
1,924
Posts
11
Years
well, i need a training on how to use the IRC first! haha, I'm kind of new to the internet. Moreover, I have little free time
if you want to speak with me , you could send me a PM, or use telegram (we could even make a group)! I have the same username, no profilw picture.

where do i find that source?
i'd be glad to get in touch with other programmers!
thanks

Open the link in your web browser. The rest is self explanatory, most people are online during the mornings for European countries.
 
Back
Top