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).
Tonc Downloads
Current (and final) version: v1.4 / v1.4.2
- 20130324: example binaries (v1.4.2): tonc-bin.zip
- 20130324: example code (v1.4.2): tonc-code.zip
- 20130324: main text (v1.4.2): tonc-text.zip
- 20080818: the main text as chm (v1.4): tonc.chm
- 20130324: the main text as PDF (v1.4.2): tonc.pdf
Older versions:
- 20080818: example binaries (v1.4.1): tonc-bin.zip
- 20120520: example code (v1.4.1): tonc-code.zip
- 20111119: main text (v1.4): tonc-text.zip
- 20070217: example binaries: tonc-bin-1.3b.zip
- 20070217: example code: tonc-code-1.3b.zip
- 20070217: main text: tonc-text-1.3b.zip
- 20070217: the main text as chm: tonc-1.3b.chm
- 20070217: the main text as PDF: tonc-1.3b.pdf
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.)
In the latest tonc-code.zip, there appears to be no 'source' or 'gfx' subdirectories in code/adv/m7_demo/
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.
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
vsINCLUDES
:INCLUDES
is supposed to be the list for include directories, andINCLUDE
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 usedINCDIRS
in the examples, but somehow missed it in the tonclib makefile.Re-uploaded tonc-code.zip because some links to grit were incorrect.
Thanks for the update. Incidentally, I recently noticed a rogue line of code in chapter 11.5. (http://www.coranac.com/tonc/text/affobj.htm) : int sina= lut_sin(alpha), cosa= lut_cos(alpha);
Damnation >_< ! Found and fixed them. Good call.
Okay this may be a needless / dispensable comment... but DUDE, thank you soo much for this!! Awesome. I love Tonc.
Hi. The b0rked link to the fixed point intoduction on fixed.htm has moved here: http://trac.bookofhook.com/bookofhook/trac.cgi/wiki/IntroductionToFixedPointMath
Pingback: Third time’s the charm…I hope. | RubiksMaze
Dude, this is awesome :) I'm using your tests to improve my WIP GBA emulator!!
Thank you for your work!
What's the license for Tonclib? I couldn't find one. (And under the law, if you don't declare a license, a work is automatically copyrighted with "all rights reserved" terms.)
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
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!
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.
I use linux(Ubuntu 18.04)
In the m7_ex folder, when I do : make
I get errors:
In file included from /home/name/gba/tonc/code/adv/m7_ex/source/m7_ex.c:16:
/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
^
/home/name/gba/tonc/code/adv/m7_ex/build/all_gfx.h:9:2: error: #endif without #if
#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.