GameBoy Advance: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | 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. | |
| 2 | 2 | ||
| 3 | 3 | # GameBoy Advance port | |
| 4 | 4 | ||
| 5 | 5 | ## Status | |
| 6 | 6 | ||
| 7 | 7 | - The 2.1.x compiler has compiler support for Gameboy Advance. | |
| 8 | 8 | - ARM CPU is supported. | |
| 9 | 9 | - ASM THUMB mode is not supported. | |
| 10 | 10 | - Base RTL units *should* be complete. | |
| 11 | 11 | ||
| 12 | 12 | ## Port notes | |
| 13 | 13 | ||
| 14 | 14 | FPC does not have some features you will find in gcc-aimed source code for gba. | |
| 15 | 15 | ||
| 16 | 16 | - At this time, you can't use THUMB asm instruction set | |
| 17 | 17 | - It is not possible to relocate variables in pascal source directly. In gcc you can write: | |
| 18 | 18 | ||
| 19 | 19 | __attribute__ ((section (".mySection")) | |
| 20 | 20 | ||
| 21 | 21 | A workaround is declaring the variable in an external asm file: | |
| 22 | 22 | ||
| 23 | 23 | @ external file ExtVars.s | |
| 24 | 24 | .section .mySection | |
| 25 | 25 | .global myVar | |
| 26 | 26 | ... | |
| 27 | 27 | ||
| 28 | 28 | then declare it in pascal source code as external: | |
| 29 | 29 | ||
| 30 | 30 | ... | |
| 31 | 31 | {$L ExtVars.o} // You need to assemble ExtVars.s and link it | |
| 32 | 32 | var | |
| 33 | 33 | myVar: integer; cvar; external; | |
| 34 | 34 | ... | |
| 35 | 35 | ||
| 36 | 36 | - FPC does not allow `volatile` declarations. Just ignore it, because the fpc compiler does not handle such an optimization. | |
| 37 | 37 | - 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: | |
| 38 | 38 | ||
| 39 | 39 | // GCC preprocessor define... | |
| 40 | 40 | #define SCREEN_BASE(m) ((m) << 8) | |
| 41 | 41 | ||
| 42 | 42 | // ...in fpc becomes: | |
| 43 | 43 | function ScreenBase(m: integer): integer; inline; | |
| 44 | 44 | begin | |
| 45 | 45 | ScreenBase := m shl 8; | |
| 46 | 46 | end; | |
| 47 | 47 | ||
| 48 | 48 | ## Building compiler | |
| 49 | 49 | ||
| 50 | 50 | *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.* | |
| 51 | 51 | ||
| 52 | 52 | 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`) | |
| 53 | 53 | ||
| 54 | 54 | **Step 1** - Getting Cross Binutils | |
| 55 | 55 | ||
| 56 | 56 | 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. | |
| 57 | 57 | ||
| 58 | 58 | **Step 2** - Making Cross compiler | |
| 59 | 59 | ||
| 60 | 60 | 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. | |
| 61 | 61 | ||
| 62 | 62 | Get the latest 2.1.x source from Subversion repository: <http://www.freepascal.org/develop.html#svn> | |
| 63 | 63 | ||
| 64 | 64 | We will suppose that your Free Pascal 2.1.x source code is located here: `%FreePascal%\sources` | |
| 65 | 65 | ||
| 66 | 66 | **Step 3** - The Build process | |
| 67 | 67 | ||
| 68 | 68 | 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 | |
| 69 | 69 | ||
| 70 | 70 | make PPC_TARGET=arm | |
| 71 | 71 | ||
| 72 | 72 | At the end of building process, you should have a `ppcarm.exe` file in `%FreePascal%\source\compiler` directory. | |
| 73 | 73 | ||
| 74 | 74 | Now copy these files to `%FreePascal%\bin\arm-gba`. | |
| 75 | 75 | ||
| 76 | 76 | In the dos prompt go to `%FreePascal%\source\rtl\gba` and do | |
| 77 | 77 | ||
| 78 | 78 | make CPU_TARGET=arm OS_TARGET=gba PP=ppcarm OPT="-Tgba" | |
| 79 | 79 | ||
| 80 | 80 | 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` | |
| 81 | 81 | ||
| 82 | 82 | **Step 4** - Configuration file | |
| 83 | 83 | ||
| 84 | 84 | Now you need to create `fpc.cfg` configuration file in `%FreePascal%\bin\arm-gba` folder in order to use `ppcarm.exe` easily. | |
| 85 | 85 | ||
| 86 | 86 | Create an empty `fpc.cfg` file in `%FreePascal%\bin\arm-gba` folder and add the following lines to it: | |
| 87 | 87 | ||
| 88 | 88 | -Tgba | |
| 89 | 89 | -FuD:\freepascal\units\arm-gba | |
| 90 | 90 | -XParm-gba- | |
| 91 | 91 | -FDD:\freepascal\bin\arm-gba | |
| 92 | 92 | ||
| 93 | 93 | Of course you should replace `D:\freepascal` with your fpc installation directory. | |
| 94 | 94 | ||
| 95 | 95 | **Done!** | |
| 96 | 96 | ||
| 97 | 97 | 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: | |
| 98 | 98 | ||
| 99 | - | ||
| 100 | - | ||
| 101 | - | ||
| 102 | - | ||
| 103 | - | ||
| 104 | - | ||
| 105 | - | ||
| 106 | - | ||
| 107 | - | ||
| 108 | - | ||
| 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 | + | ``` | |
| 109 | 111 | ||
| 110 | 112 | **Next steps?** | |
| 111 | 113 | ||
| 112 | 114 | 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](http://www.devkitpro.org). | |
| 113 | 115 | ||
| 114 | 116 | ## Binaries | |
| 115 | 117 | ||
| 116 | 118 | A 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) | |
| 117 | 119 | ||
| 118 | 120 | ## Documentation | |
| 119 | 121 | ||
| 120 | 122 | - [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 | |
| 121 | 123 | - [Programming The Nintendo Game Boy Advance](http://www.jharbour.com/gameboy/default.aspx): a free book for beginners about GBA game programming. | |
| 122 | 124 | - [TONC](http://user.chem.tue.nl/jakvijn/tonc/): if you want to program a game for gba, you MUST read this tutorial. | |
| 123 | 125 | - [FPC4GBA initiative site](http://fpc4gba.pascalgamedevelopment.com): Here you can find more infos on FPC 4 GBA. | |
| 124 | 126 | - [GBA FAQ](http://www.devrs.com/gba/files/gbadevfaqs.php): A lot of obscure GBA internal infos. | |
| 125 | 127 | ||
| 126 | 128 | ## Links | |
| 127 | 129 | ||
| 128 | 130 | - [My home page](http://itaprogaming.free.fr) with some tools and demos. | |
| 129 | 131 | - [GBADev](http://www.gbadev.org): a great GBA developers community. | |
| 130 | 132 | - [GBA Devr's](http://www.devrs.com/gba): Jeff Frohwein's GBA related stuff. | |
| 131 | 133 | - [Pascal Game Development](http://www.pascalgamedevelopment.com): the biggest pascal game development community. | |
| 132 | 134 | - [devkitPro](http://www.devkitpro.org): the home page of the GBA development toolkit. | |
| 133 | 135 | ||
| 134 | 136 | --- | |
| 135 | 137 | *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).* | |
| 136 | 138 | Category: Operating Systems and Platforms | |
| 137 | 139 | Category: Video Game Consoles |
