Difference between revisions of "GameBoy Advance"
m (Typos corrected) |
|||
Line 66: | Line 66: | ||
'''Step 3''' - The Build process | '''Step 3''' - The Build process | ||
− | In order to build the cross compiler it is necessary to have a correct <tt>PATH</tt> environment variable pointing to cross binutils.In Windows You should add <tt>%FreePascal%\bin\arm-gba</tt> to the PATH. | + | In order to build the cross compiler it is necessary to have a correct <tt>PATH</tt> environment variable pointing to cross binutils. In Windows You should add <tt>%FreePascal%\bin\arm-gba</tt> to the PATH. |
Now open a dos prompt, go to <tt>%FreePascal%\source\compiler</tt> and run | Now open a dos prompt, go to <tt>%FreePascal%\source\compiler</tt> and run | ||
Line 75: | Line 75: | ||
At the end of building process, you should have a <tt>ppcarm.exe</tt> file in <tt>%FreePascal%\source\compiler</tt> directory. | At the end of building process, you should have a <tt>ppcarm.exe</tt> file in <tt>%FreePascal%\source\compiler</tt> directory. | ||
− | Now copy | + | Now copy these files to <tt>%FreePascal%\bin\arm-gba</tt>. |
− | In the dos prompt <tt>%FreePascal%\source\rtl\gba</tt> and do | + | In the dos prompt go to <tt>%FreePascal%\source\rtl\gba</tt> and do |
<pre> | <pre> | ||
Line 89: | Line 89: | ||
'''Step 4''' - Configuration file | '''Step 4''' - Configuration file | ||
− | Now you need to create <tt>fpc.cfg</tt> configuration file in <tt>%FreePascal%\bin\arm-gba</tt> folder in order to use <tt>ppcarm.exe</tt> | + | Now you need to create <tt>fpc.cfg</tt> configuration file in <tt>%FreePascal%\bin\arm-gba</tt> folder in order to use <tt>ppcarm.exe</tt> easily. |
Create an empty <tt>fpc.cfg</tt> file in <tt>%FreePascal%\bin\arm-gba</tt> folder and add the following lines to it: | Create an empty <tt>fpc.cfg</tt> file in <tt>%FreePascal%\bin\arm-gba</tt> folder and add the following lines to it: | ||
Line 126: | Line 126: | ||
== Binaries == | == Binaries == | ||
A zip package of arm-gba binaries is available [ftp://ftp.freepascal.org/pub/fpc/snapshot/v21/arm-gba/fpc4gba.zip here] or mirrored on my [http://itaprogaming.free.fr/download/fpc4gba.zip web site] | A zip package of arm-gba binaries is available [ftp://ftp.freepascal.org/pub/fpc/snapshot/v21/arm-gba/fpc4gba.zip here] or mirrored on my [http://itaprogaming.free.fr/download/fpc4gba.zip web site] | ||
+ | |||
== Documentation == | == Documentation == |
Revision as of 15:07, 1 June 2006
GBA port is still in an initial stage, though it should be pretty usable. Initial compiler port was by Jason 'WILL' McMillen. New compiler and RTL port was started and mantained by Francesco Lombardi.
GameBoy Advance port
Status
- The 2.1.x compiler has compiler support for Gameboy Advance.
- ARM CPU is supported.
- ASM THUMB mode is not supported.
- Base RTL units *should* be complete.
Port notes
FPC does not have some features you will find in gcc-aimed source code for gba.
- At this time, you can't use THUMB asm instruction set
- It is not possible to relocate variables in pascal source directly. In gcc you can write:
__attribute__ ((section (".mySection"))
A workaround is declaring the variable in an external asm file:
@ external file ExtVars.s .section .mySection .global myVar ...
then declare it in pascal source code as external:
... {$L ExtVars.o} // You need to assemble ExtVars.s and link it var myVar: integer; cvar; external; ...
- FPC does not allow volatile declarations. Instead you can try to exclude the compiler optimization, though I don't have investigated about it:
// in C int volatile myVar; ... //in Pascal var {$OPTIMIZATION OFF} myVar: integer; {$OPTIMIZATION ON}
Building compiler
In this document I'll refer to a windows system.
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
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
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:
-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:
@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?
Now we need some libraries for gba. I have translated a basic library 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
- Programming The Nintendo Game Boy Advance: a free book for beginners about GBA game programming.
- TONC: if you want to program a game for gba, you MUST read this tutorial.
- FPC4GBA initiative site: Here you can find more infos on FPC 4 GBA.
- GBA FAQ: A lot of obscure GBA internal infos.
Links
- My home page with some tools and demos.
- GBADev: a great GBA developers community.
- GBA Devr's: Jeff Frohwein's GBA related stuff.
- Pascal Game Development: the biggest pascal game development community.
- devkitPro: the home page of the GBA development toolkit.