This is a boring post while I am waiting for checking out the project and copying 2GB of data to another laptop. It's kind of boring because I have these two things finish to continue my work. But actually, this post is not about my boring stuff, hehe, I happen to have a chance to work with GameBoy Advance (GBA) development for the next two weeks and it's quite interesting so I wanna blog about it. It's just my note about the progress of studying, so don't mind about the noob work.
The very first step is to setup the development environment. Pure C is used and some tools for compiler and emulator. It has been a long time since I come back to low-level C. it's quite fun to work with byte and bit again, it's like stoneage. The emulator is easy, you just go to VBA and download the latest version. For the environment, I think the document is not generally available because I have a hard time to setup the environment. Go to DevKitAdv and download the latest version (latest version is 2003, woot!!!). I choose release 4, it's look safe. I have no idea which file should download so I just download all, and then later I found out that you will need the following one:
- agb-win-core-r5.zip
- agb-win-binutils-r4.zip
- agb-win-gcc-r4.zip
- agb-win-libstdcpp-r4.zip
- agb-win-newlib-r4.zip
- crtls.zip (for compiling crts0.o)
Extract all these files to a folder, like C:\devkitadv. Then set the PATH variable in in the Environment Variables window to include the bin folder, my case is C:\devkitadv\bin. Check if you can run gcc from Command line then you are in the right way. Also, you need to download gfx2gba to convert (I don't know other way yet, hehe). Now we are ready to write some hello world.
Open paint, create a hello world picture and then save as BMP format. Make sure it's 8bit BMP or gfx2gba won't work. Copy the image to your workspace folder, name it hello.bmp or so, create src folder and then go to the command line and type gfx2gba -fsrc -osrc hello.bmp, it will create hello.raw.c for you. Then open src\main.c and paste the following code
#include "../common/gba.h"
#include "master.pal.c"
#include "hello.raw.c"
#define MODE_4 0x4
#define BG2_ENABLE 0x400
#define VideoBuffer ((unsigned short*)0x6000000)
#define BGPaletteMem ((unsigned short*)0x5000000)
int main (void) {
int i;
REG_DISPCNT = MODE_4 | BG2_ENABLE;
for (i = 0; i < 120*160; ++i) {
VideoBuffer[i] = ((u16*)hello_Bitmap)[i];
}
for (i = 0; i < 255; ++i) {
BGPaletteMem[i] = master_Palette[i];
}
while (1);
return 0;
}
You can get gba.h on this page. The idea is simple, copy the image to video buffer, then copy the color palette. Now we need to compile this script, open build.bat then paste the following build code
@echo off
gcc -O3 -W -o main.elf src\main.c
objcopy -O binary main.elf main.gba
Run this file, If you see main.gba then: congratulation. Open VBA (the emulator) then select main.gba, you will see something like this (depends on your picture, of course!).

This is just the first step, I'm going to blog more about this in next two weeks. Hope so =)) !
Note: In case you have some problem with crt0.o then download crtls.zip, then go to the folder where you extract crtls.zip and type as -o crt0.o crt0.s, then copy crt0.o to devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2, devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2\interwork, devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2\thumb, devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2\thumb\interwork.