Title: Intro to GBA Development
1Intro to GBA Development
GBA Game Boy Advance, for the slower members
of the audience (Nintendo made them).
2Hardware
- 16.78MHz ARM7TDMI Processor, capable of both 16
(Thumb) and 32 (Arm) bit modes - 32KB On-Die RAM (32 Bit bus, fast), 256KB
External Ram (16 Bit bus, slow) - 4 Analog, 2 Digital Sound Channels
- 4 Way D-Pad, 6 General Buttons
- Serial Port
- 2.9 Inch, 240x160 pixel TFT Display.
I really didnt disassemble my GBA, not this time
anyway.
3Memory Map
- 0x00000000-0x00003FFF BIOS - 16 KB
- 0x02000000-0x0203FFFF External RAM - 256 KB
- 0x03000000-0x03007FFF On-Die RAM - 32 KB
- 0x04000000-0x040003FE Memory Registers
- 0x05000000-0x050003FF BG/OBJ Palette RAM - 1 KB
- 0x06000000-0x0617FFFF Video RAM - 96 KB
- 0x07000000-0x070003FF OAM OBJ Attributes - 1 KB
- 0x08000000-0x09FFFFFF Cart ROM - 32MB
- 0x0A000000-0x0DFFFFFF Cart Mirror - 64MB
- 0x0E000000-0x0E00FFFF Cart SRAM or EEPROM - 64 KB
The colored ones are important, remember them, or
else!
4Tools
- GCC built for the ARM architecture (Someone was
nice enough to pre-package it for us, we will use
devkitARM). - Legal grey area emulator of some sort (We will
use VBA). - Text editor.
- Some way to put our code on the GBA
Yes, I do own a legal copy of FFTA, you dirty
pirates.
5How do we get our code on the GBA?
- Flash Cart
- Pros
- Big code size.
- Everything is the same as real hardware.
- Freedom!
- Cons
- Expensive.
- Slow.
- Multiboot Cable (Xboo)
- Pros
- Fast.
- Cheap.
- Cons
- Small code size.
- Tethered to your computer.
Size is everything.
6Yay! Code!
- First we need to define some useful memory
locations -
-
- Remember the colored memory locations earlier?
They have come back to haunt you! - We define video_buffer as a pointer to the Video
RAM. The GBA is so nice, it lets us write
straight to the screen. - We also define display_control as a pointer to
the Display Control Register, which is
conveniently located at the beginning of the
memory register memory block I asked you to
remember earlier and you didnt. - We use the volatile keyword because we are not
guaranteed that the data at the memory locations
will stay the same while our code executes.
define video_buffer ((volatile unsigned short )
0x06000000) define display_control ((volatile
unsigned long ) 0x04000000)
Syntax highlighting, yeah!
7More code, yay
- Next we need to define some also useful
constants. -
- These two values are flags we will use later to
setup the proper graphics mode. - The value mode_3 will tell the GBA that we want
to use Graphics Mode 3, a bitmapped graphics
mode. - We also will use the value bg_2 to enable
Background 2, which is located in Video RAM.
define mode_3 0x0003 // (0000 0000 0000 0011 in
binary) define bg_2 0x0400 // (0000 0100 0000
0000 in binary)
Poor audience, no pictures in two slides, such
deprivation, (.
8Yes, I am subjecting you to more code.
- Finally! We start the real code.
-
- Here we shove the two values we defined last
slide into the pointer we defined two slides ago,
and like magic, the GBA switches into the proper
graphics mode. - Also, we started our program, thats why the int
main() is there. We take no arguments because
he have no command line, and we return an int so
the startup code knows if we did something bad
(it wont really do anything about it, it is just
good to let it know anyways).
int main() // Set mode to 3 and turn on bg
2 display_control mode_3 bg_2
You! In Back! Wake Up!
9This is the end!
- Ok, now we finish up our code, we dump a bunch of
red on the screen. -
- Handy thing about pointers is that we can use
them as an array. Since we defined the proper
element size earlier we can write to Video RAM
quite easily. - The GBA uses a 5,5,5-BGR format, so pure red is
0x001F (0000 0000 0001 1111).
int x, y for (x 0 x 0 y red) video_bufferx y 240
0x001F return 0
If any of you asks how the for loops work, I will
murder someone.
10Ha! I lied! We still have more to do.
- Alright, now that we have some pretty code, what
do we do? We need to compile the damn thing. -
- Since we are compiling for the 16 bit External
RAM, we will use the 16 bit Thumb mode so we only
need one memory read per instruction. We also
tell the compiler to use the linker script
specified in gba_mb.specs in order to compile
the code for the proper memory addresses (we will
be using multiboot). - Next we take the object file the compiler gives
us and convert it into a flat binary without all
the extra information we dont need. - Finally, we correct the header and checksum in
the final file (the GBA will not run it if we
have an invalid header).
C\arm-elf-gcc -o demo.elf main.c -mthumb
-specsgba_mb.specs C\arm-elf-objcopy -v -O
binary demo.elf demo.gba C\gbafix demo.gba
You were expecting something funny here, werent
you?
11Ok, now how do we run our code?
- For debugging purposes we can use an emulator.
- This is simple.
- Very simple.
- It is pretty. Isnt it?
- If we want to run on real hardware we can use a
multiboot cable. - Requires assembly.
- Solder is hot.
- Windows XP hates multiboot.
- We could also use a flash cart, but we would have
to recompile our code for the right memory
addresses.
I have scars.
12Where do we go from here?
- Stuff to learn
- Tiled and paletted graphics modes.
- Sound.
- Input.
- Link port communication.
- SRAM and save game capabilities.
- Interrupts
- DMA
- Places to learn it
- GBATek - A very complete hardware reference.
- CowBite VHS - Another good hardware reference.
- Gbadev.org - Hub for all GBA homebrew people and
stuff.
This is the last slide, really, I swear.