Gameboy Advance Development in Linux

Versión en Español This is my page about Gameboy Advance development under Linux. All GBA C sources are written for this toolchain (local copy) and for this crt0/lnkscript by Jeff Frohwein. Nevertheless it is very easy to adapt the sources for the http://www.devkitpro.org's toolchain. • • • • • utils sound graphics games hardware

• midiout advance - First release of DINAMISE: A tracker-style MIDI sequencer for midioutadvance. • Utils • bin2o.cpp - A binary to ELF object file converter that lets you create C buffers from raw data files directly in .o format. The original utility by DarkFader (http://darkfader.net/gp32). I had to patch it. To compile simply do a: g++ -o bin2o bin2o.cpp on Linux. • romfs-0.1.tar.gz - A minimalistic ROMFS implementation for Gameboy Advance. ROMFS is a space-efficient, small, read-only filesystem originally for Linux and used by some Linux based projects (http://romfs.sourceforge.net). • stdio-0.1.tar.gz - newlib extension that allows use of standard input/output routines in GBA. The current implementation is partial and these are the features: o The GBA uses graphic mode 0, so we have a 30x20 characters screen (8x8 pixels each character). We write to screen ussing the usual commands printf, puts, etc, because the screen is the file handle 1 (as in Unix). Be careful: there is no extended ASCII support (only the ASCII codes from 32 to 127 are visibles, plus the '\n' character that is used for new line). linksavelinoherrera@hotpop.com

o There is no file handle associated to GBA keypad and the file handle 0 (standard input) cannot be used, perhaps in the future... ;-) o The file handle 2 (standard error output) is mapped at SRAM (the internal static non-volatile RAM on all flash cartridges). This SRAM is 64KByte length. It is possible to call lseek over file handle 2 to positioning into SRAM. o There is romfs support. We can open, close, lseek, read and fstat files located at a romfs image merged with the main program ROM: cat my_program.gba image.romfs > my_final_program.gba.

• • • • • • • • • • • • • • • • •

int AgbMain() { console_init(); romfs_init(); ... printf("opening 'index.html'...\n"); fd = open("index.html", O_RDONLY); printf("handle = %d\n", fd); printf("=== BEGIN\n"); while (1) { int readed = read(fd, &data, 1); if (readed == 0) break; putchar(data); } close(fd); printf("=== EOF\n"); ... }
example of romfs file access

To extend the newlib we must to recompile it adding the option -DREENTRANT_SYSCALLS_PROVIDED to the CFLAGS_FOR_TARGET variable at Makefile after configure. Here we can read a very interesting article about how to port the newlib for embedded systems.
int AgbMain() { console_init(); romfs_init();

... printf("writing SRAM..."); write(2, "Hello, SRAM :-)", 16); printf("ok\n"); lseek(2, 0, SEEK_SET); read(2, sram_example_data, 20); printf("SRAM content = '%s'\n", sram_example_data); ... }
example of SRAM access

Sound

• • •

directsound.tar.gz - An example application that plays a sound sample. The drum sample was downloaded from http://www.looperman.com, converted to raw format ussing sox and converted to ELF object file format ussing bin2o.cpp (original from http://darkfader.net/gp32 and patched by me for g++ compatibility). modplayer-0.1.tar.gz - An initial version of the fixed point MOD player for the GBA. It must be improved to consume less CPU. tremor_example-0.1.tar.gz - An adaptation of the Tremor OggVorbis fixed point decoder for the GBA and an example of use. ritma-0.3.tar.gz - A simple metronome for GBA. GPL licensed (binaries and sources included).

Graphics

• • •

tiled-c-map-writer-plugin-0.2.tar.gz - An output plugin for Tiled to export tile maps in C header format suitable for GCC. Simply extract it into the folder tiled-0.6.1/plugins. Now you can build the entire project and the output plugin will be included in the distribution. Thanks to Jaymin Kessler to mail me about the problem: the previous 0.1 version of the plugin is not compatible with the newer version of Tiled. HGenerator.java - An image to C header (.h) converter targeted to Gameboy Advance. It supports both indexed and RGB images. mode4.tar.gz - A mode 4 graphics example (240x160 - 256 colors). mode4font.tar.gz - A mode 4 character font example (8x8).

Games

matchit-0.1c.tar.gz - The last version of MatchIt (a puzzle game I am developping). Now features a falling down animation when key down pressed and the game over screen notices about the reached score (thanks for the suggestion, Y-o-g-a :-).

Here is a video in that we can see the MatchIt game running in a real Gameboy Advance.

Hardware

I have connected some leds to the GBA serial port (EXT) and I have tested them ussing a program that writes to the REG_R register in general purpose mode.

Here is the source code for this mini project :-) and this is the circuit diagram connected to the EXT port.

• •

Here you can obtain a detailed description of the GBA link port.

midioutadvance • dinamise-0.1.tar.gz - Tracker-based MIDI sequencer.

New 100% compatible MIDI hardware implementation. The Gameboy Advance has now a MIDI out port :-D. I have built a simple MIDI out interface with two resistors, a BJT and a female DIN-5 plug connected to the EXT port of the Gameboy Advance. This is the electrical diagram:

More info about electrical specification of the MIDI interface can be found here. This is the source code of a simple application I have made for testing purposes. This application sends a note on message when keypad A is pressed and a note off message when keypad B is pressed. For further info, see the source code comments or e-mail me.

The following are some photos of the Gameboy Advance with this MIDI out interface. It is now 100% MIDI compatible!

I have used the 2-player link cable with the master end connected to GBA (in my cable it is labeled 1P).

male plug (cable)

female plug (GBA)

The SI (pin 3) and SC (pin 5) connector pins are adyacent in the same side of the male plug, so we can use a simple bakelite board in such a way that two copper tracks fits in that pins. In this photo you can see this hack. Some related links:
o o

The complete MIDI specification (both hardware and software). Low level MIDI packet generation.

Links and resources

• • •

http://linux.gbadev.org - Very nice step by step tutorial: How to build your own Gameboy Advance toolchain in Linux ussing standard GNU tools (binutils, gcc and newlib). http://gbajunkie.co.uk - GBA programming tutorials (here you can download the adaptation made by me of the gbajunkie.co.uk tutorial examples to compile with the linux.gbadev.org toolchain). http://belogic.com/gba - GBA programming tutorial for the GBA sound subsystem. http://www.reinerziegler.de/GBA/gba.htm - Very useful hardware technical info. http://nocash.emubase.de/gbatek.htm - All the registers, the memory map, BIOS functions, etc listed.

This work is licensed under a Creative Commons License.