Tonc - GBA Programming in rot13

Tonc is my reasonably successful tutorial on GBA programming, covering most aspects of the hardware in all its technical glory. Tonc explains the GBA hardware in detail, and how you should and should not work with it. Prior programming knowledge is required, an affinity for mathematics is also recommended.

1.4 is the final version, but I will try to fix errors when they are found. Look in the errata for details.

(2018-06-24) A recent change in devkitArm (probably 48?) changed the way ctype.h works, resulting in a broken libtonc.a. To fix it, recompile libtonc manually. Go to the tonclib folder and do make clean and make. That should do it.

(2013-03-24) fixed for change in DKA r41 prefix (the arm-none-eabi thing).

(2012-05-20) alright, 1.4 was supposed the final version, but GCC 4.7 requires an extra line for assembly routines, so I had to check and fix a number of things. Code's at 1.4.1 now and the rest will follow soon (hopefully).

Current (and final) version: v1.4 / v1.4.2

Older versions:

NOTE. I've had a report a while back that the CHM version didn't work. The reason seems to be the silly security settings in Windows that block downloaded CHM files to open properly. If you get this too, open the file's properties and click Unblock' (Thanks for pointing this out, Kevin.)

15 thoughts on “Tonc - GBA Programming in rot13”

1. In the latest tonc-code.zip, there appears to be no 'source' or 'gfx' subdirectories in code/adv/m7_demo/

2. There is a problem building the tonclib v1.4. It seems that make isn't pointing out where the headers are. I looked through the makefile and found some discrepancies between the variables INCLUDE and INCLUDES. But after changing them all to INCLUDES, the same thing happened.

3. Odd. I've rebuilt tonclib here and it seems to compile okay. It did seem I missed a few points in the main codebase, though, so I've re-uploaded everything. Maybe it'll work better this time.

About INCLUDE vs INCLUDES: INCLUDES is supposed to be the list for include directories, and INCLUDE is the variable that the compiler needs to search for the directories. You shouldn't replace one for the other, that won't work. Because of the obvious potential for confusion here, I always used INCDIRS` in the examples, but somehow missed it in the tonclib makefile.

4. Okay this may be a needless / dispensable comment... but DUDE, thank you soo much for this!! Awesome. I love Tonc.

5. Dude, this is awesome :) I'm using your tests to improve my WIP GBA emulator!!

7. this is not working on my pc. I use the command program and it comes with a bunch of errors. I am using devkitpro and it is just not working. Im really confused on why this isnt working. I can send pictures of the code that comes from the cmd program and maybe someone can help me. It would be very helpful and greatly appreciated

8. Damian, tonclib is MIT licenced. Or would have been if I hadn't forgotten to add the license file >_>

Nicolas, I've added the explanation for the problem you have to the description. Thanks for bringing it to my attention!

9. I'm also having a similar issue to Nicholas, but manually recompiling doesn't seem to work. I still get a "undefined reference to '__ctype_ptr__' " when trying to use the text components of tonc. I've tried the built-in devkitpro tonclib, and cloned the tonclib repo from devkitpro and recompiled it. Is there something I'm missing? If someone else has it working today help would be greatly appreciated.

10. I use linux(Ubuntu 18.04)

In the m7_ex folder, when I do : make

I get errors:

/home/name/gba/tonc/code/adv/m7_ex/build/all_gfx.h:1:1: error: expected identifier or '(' before '-' token
-e //
^
/home/name/gba/tonc/code/adv/m7_ex/build/all_gfx.h:7:4: error: stray '#' in program
-e #ifdef __cplusplus
^
#endif
^~~~~
/home/name/gba/tonc/code/adv/m7_ex/../../tonc_rules:73: recipe for target 'm7_ex.o' failed
make[1]: *** [m7_ex.o] Error 1
Makefile:158: recipe for target 'build' failed
make: *** [build] Error 2

and if I delete the -e in the gfxmake file

## Merge all headers into a single large one for easier including.

define master-header # $1 : master path,$2 separate header paths
echo "//\n// $(notdir$(strip $1))\n//" >$1
echo "// One header to rule them and in the darkness bind them" >> $1 echo "// Date:$(shell date +'%F %X' )\n" >> $1 echo "#ifdef __cplusplus\nextern \"C\" {\n#endif" >>$1
cat $2 >>$1
echo "\n#ifdef __cplusplus\n};\n#endif\n" >> \$1
endef

the program works, but I end up with karts and thwomp gray color.