Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

GameBoy Advance

GBA 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.

GameBoy Advance port

Status

Port notes

FPC does not have some features you will find in gcc-aimed source code for gba.

A workaround is declaring the variable in an external asm file:

pascal
@ external file ExtVars.s
 .section .mySection
 .global myVar
pascal
...

then declare it in pascal source code as external:

pascal
...
{$L ExtVars.o}  // You need to assemble ExtVars.s and link it
var 
  myVar: integer; cvar; external;
...

Building compiler

In this document I will refer to a windows system. It is possible to download a batch file that could help in the building and installation process.

In 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)

Step 1 - Getting Cross Binutils

You 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.

Step 2 - Making Cross compiler

Now 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.

Get the latest 2.1.x source from Subversion repository: http://www.freepascal.org/develop.html#svn

We will suppose that your Free Pascal 2.1.x source code is located here: %FreePascal%\sources

Step 3 - The Build process

In 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

pascal
make PPC_TARGET=arm

At the end of building process, you should have a ppcarm.exe file in %FreePascal%\source\compiler directory.

Now copy these files to %FreePascal%\bin\arm-gba.

In the dos prompt go to %FreePascal%\source\rtl\gba and do

pascal
make CPU_TARGET=arm OS_TARGET=gba PP=ppcarm OPT="-Tgba"

At 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

Step 4 - Configuration file

Now you need to create fpc.cfg configuration file in %FreePascal%\bin\arm-gba folder in order to use ppcarm.exe easily.

Create an empty fpc.cfg file in %FreePascal%\bin\arm-gba folder and add the following lines to it:

pascal
-Tgba
-FuD:\freepascal\units\arm-gba
-XParm-gba-
-FDD:\freepascal\bin\arm-gba

Of course you should replace D:\freepascal with your fpc installation directory.

Done!

Our 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:

text
 @echo off
 REM "placeholder" should be changed according with your file name
 
 ppcarm -gw -s -XX -Xs -Si -Ooregvar placeholder.pp
 arm-gba-as -o prt0.o prt0.s
 arm-gba-as -o placeholder.o placeholder.s
 arm-gba-ld -g --gc-sections -T lnkscript -L. link.res -o placeholder.elf
 arm-gba-objcopy -v -O binary placeholder.elf placeholder.gba
 
 pause

Next steps?

In 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.

Binaries

A zip package of arm-gba binaries is available here or mirrored on my web site

Documentation

Links


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.

Revision 2, last changed by WikiArchive .