Sign in Join
Wiki copytemporary

GameBoy Advance: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11GBA port is still in an initial stage, though it should be pretty usable. Initial compiler port was by Jason McMillen. New compiler and RTL port was started and mantained by Francesco Lombardi.
22
33# GameBoy Advance port
44
55## Status
66
77- The 2.1.x compiler has compiler support for Gameboy Advance.
88- ARM CPU is supported.
99- ASM THUMB mode is not supported.
1010- Base RTL units *should* be complete.
1111
1212## Port notes
1313
1414FPC does not have some features you will find in gcc-aimed source code for gba.
1515
1616- At this time, you can't use THUMB asm instruction set
1717- It is not possible to relocate variables in pascal source directly. In gcc you can write:
1818
1919 __attribute__ ((section (".mySection"))
2020
2121A workaround is declaring the variable in an external asm file:
2222
2323 @ external file ExtVars.s
2424 .section .mySection
2525 .global myVar
2626 ...
2727
2828then declare it in pascal source code as external:
2929
3030 ...
3131 {$L ExtVars.o} // You need to assemble ExtVars.s and link it
3232 var
3333 myVar: integer; cvar; external;
3434 ...
3535
3636- FPC does not allow `volatile` declarations. Just ignore it, because the fpc compiler does not handle such an optimization.
3737- The GCC preprocessor is a bit more complex than the fpc one. All \#define that require a parameter can be safely replaced by an inline procedure, declaring the parameter as an integer:
3838
3939 // GCC preprocessor define...
4040 #define SCREEN_BASE(m) ((m) << 8)
4141
4242 // ...in fpc becomes:
4343 function ScreenBase(m: integer): integer; inline;
4444 begin
4545 ScreenBase := m shl 8;
4646 end;
4747
4848## Building compiler
4949
5050*In this document I will refer to a windows system. It is possible to download a [batch file](http://itaprogaming.free.fr/download/build_fpc4gba.bat) that could help in the building and installation process.*
5151
5252In order to build fpc for gba you need a working copy of fpc binaries. Be sure that fpc path (eg. `c:\fpc\bin\i386-win32`) is at the first place in your search path (because compatibility problems with eg. Delphi `make.exe`)
5353
5454**Step 1** - Getting Cross Binutils
5555
5656You need cross binutils for arm-gba. You can get it (for win32) from <http://itaprogaming.free.fr/download/arm-gba-binutils.zip>. Extract them to some dir in the path on your machine. We will suppose that you extracted the cross binutils to: `%FreePascal%\bin\arm-gba` where %FreePascal% is the path of your fpc binary installation.
5757
5858**Step 2** - Making Cross compiler
5959
6060Now you need to build fpc cross compiler for ARM processor. To do that you need the latest fpc 2.1.x sources and a working installation of fpc 2.0.x.
6161
6262Get the latest 2.1.x source from Subversion repository: <http://www.freepascal.org/develop.html#svn>
6363
6464We will suppose that your Free Pascal 2.1.x source code is located here: `%FreePascal%\sources`
6565
6666**Step 3** - The Build process
6767
6868In order to build the cross compiler it is necessary to have a correct `PATH` environment variable pointing to cross binutils. In Windows You should add `%FreePascal%\bin\arm-gba` to the PATH. Now open a dos prompt, go to `%FreePascal%\source\compiler` and run
6969
7070 make PPC_TARGET=arm
7171
7272At the end of building process, you should have a `ppcarm.exe` file in `%FreePascal%\source\compiler` directory.
7373
7474Now copy these files to `%FreePascal%\bin\arm-gba`.
7575
7676In the dos prompt go to `%FreePascal%\source\rtl\gba` and do
7777
7878 make CPU_TARGET=arm OS_TARGET=gba PP=ppcarm OPT="-Tgba"
7979
8080At the end of the compiling process, you can find a new directory called `%FreePascal%\source\rtl\units\arm-gba` Now copy the directory 'arm-gba' and all files inside in `%FreePascal%\units`
8181
8282**Step 4** - Configuration file
8383
8484Now you need to create `fpc.cfg` configuration file in `%FreePascal%\bin\arm-gba` folder in order to use `ppcarm.exe` easily.
8585
8686Create an empty `fpc.cfg` file in `%FreePascal%\bin\arm-gba` folder and add the following lines to it:
8787
8888 -Tgba
8989 -FuD:\freepascal\units\arm-gba
9090 -XParm-gba-
9191 -FDD:\freepascal\bin\arm-gba
9292
9393Of course you should replace `D:\freepascal` with your fpc installation directory.
9494
9595**Done!**
9696
9797Our job is done! Now you should have a freepascal compiler that can build apps for gba target. Though it is not just about calling "ppcarm yourfile.pp"... First of all, you need to copy `lnkscript` and `prt0.s` (that you have found in `%FreePascal%\source\rtl\gba`) in your project directory. In order to make things a bit simpler, copy following text in a batch file:
9898
99-` @echo off`\
100-` REM "placeholder" should be changed according with your file name`\
101-` `\
102-` ppcarm -gw -s -XX -Xs -Si -Ooregvar placeholder.pp`\
103-` arm-gba-as -o prt0.o prt0.s`\
104-` arm-gba-as -o placeholder.o placeholder.s`\
105-` arm-gba-ld -g --gc-sections -T lnkscript -L. link.res -o placeholder.elf`\
106-` arm-gba-objcopy -v -O binary placeholder.elf placeholder.gba`\
107-` `\
108-` pause`
99+```text
100+ @echo off
101+ REM "placeholder" should be changed according with your file name
102+
103+ ppcarm -gw -s -XX -Xs -Si -Ooregvar placeholder.pp
104+ arm-gba-as -o prt0.o prt0.s
105+ arm-gba-as -o placeholder.o placeholder.s
106+ arm-gba-ld -g --gc-sections -T lnkscript -L. link.res -o placeholder.elf
107+ arm-gba-objcopy -v -O binary placeholder.elf placeholder.gba
108+
109+ pause
110+```
109111
110112**Next steps?**
111113
112114In the SVN repository there is gbaunits, a package that incapsulates a library I have translated from c, but it needs some changes and some testing too. About prt0.s, lnkscript and binutils: these files come from [devkitPro](http://www.devkitpro.org).
113115
114116## Binaries
115117
116118A zip package of arm-gba binaries is available [here](ftp://ftp.freepascal.org/pub/fpc/snapshot/v21/arm-gba/fpc4gba.zip) or mirrored on my [web site](http://itaprogaming.free.fr/download/fpc4gba.zip)
117119
118120## Documentation
119121
120122- [FPC 4 GBA Game Programming Tutorial](http://itaprogaming.free.fr/tutorial.html): a work-in-progress tutorial I'm writing about gba programming with fpc
121123- [Programming The Nintendo Game Boy Advance](http://www.jharbour.com/gameboy/default.aspx): a free book for beginners about GBA game programming.
122124- [TONC](http://user.chem.tue.nl/jakvijn/tonc/): if you want to program a game for gba, you MUST read this tutorial.
123125- [FPC4GBA initiative site](http://fpc4gba.pascalgamedevelopment.com): Here you can find more infos on FPC 4 GBA.
124126- [GBA FAQ](http://www.devrs.com/gba/files/gbadevfaqs.php): A lot of obscure GBA internal infos.
125127
126128## Links
127129
128130- [My home page](http://itaprogaming.free.fr) with some tools and demos.
129131- [GBADev](http://www.gbadev.org): a great GBA developers community.
130132- [GBA Devr's](http://www.devrs.com/gba): Jeff Frohwein's GBA related stuff.
131133- [Pascal Game Development](http://www.pascalgamedevelopment.com): the biggest pascal game development community.
132134- [devkitPro](http://www.devkitpro.org): the home page of the GBA development toolkit.
133135
134136---
135137*From the Free Pascal wiki, page "GameBoy Advance", as it stood on 2013-04-06 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
136138Category: Operating Systems and Platforms
137139Category: Video Game Consoles

Back to history