tiistai 1. joulukuuta 2026

GBA9500: a Game Boy Advance in a Communicator

After the NES emulator worked, I went for it: "You can call me mad, but... a GBA emulator for Nokia 9500. You in?"

Claude was in. GBA9500 plays Game Boy Advance games on the Communicator, with sound, save states and an icon on the Desk. As before, the code was written by Claude (Anthropic's AI). I built it on my Windows 2000 VM, ran it on the phone, sent back logs and complained. Pokémon FireRed is what I tested with, and it plays from the start through the first rival battles without crashing.

Is it full speed? No. More on that below, with a chart.

Why this is harder than a NES

A NES has a 1.8 MHz 8-bit CPU, and NES9500 simply interprets its instructions one by one. A GBA has a 16.8 MHz 32-bit ARM, and interpreting that on a 150 MHz ARM9 would give maybe a third of the speed you need. So GBA9500 doesn't interpret. It is a port of gpSP, Exophase's GBA emulator, from notaz's tree for the GP2X and Pandora handhelds. gpSP has a dynamic recompiler: it translates the game's ARM code into native ARM code the first time it runs, and from then on runs the translation.

The GP2X has an ARM920T, the same family as the 9500's ARM925T. gpSP's translator only emits instructions that CPU knows. That was the reason to pick it.

The compiler goes first, again

The SDK's GCC 2.9 is from the last century, and gpSP is written in GNU C of a later decade. The fun ones:

  • The SDK's GCC quietly defines arm as 1. gpSP uses arm as a macro argument name, so half the translator's macros turned into nonsense about the number one.
  • gpSP uses local labels (__label__). GCC 2.9 accepts the keyword but doesn't really scope them, so it complained about duplicate labels, and once crashed outright with an internal compiler error. Every local label became a flag and a loop.
  • The SDK's preprocessor couldn't read gpSP's assembler macros at all. A Python script on the PC now preprocesses them into plain assembler for the old as.

Where the code is

The translator writes its output into big static arrays, and it calls its helper routines with a plain bl, which only reaches 32 MB. On Symbian 7's memory model a program's code lives far from its data. So the helpers moved too: gpSP's assembler stub lives in the data segment, right next to the translation caches, and calls back into C with long calls. The program checks the distances at start-up and writes them to the log, because if that guess was wrong nothing else would work.

It wasn't wrong. The first run on the phone loaded the 6 MB of caches and translated 122 KB of FireRed. Then it died with exception 11.

Exception 11: the 9500 is stricter

Exception 11 is an alignment fault: reading a 32-bit word from an address that isn't a multiple of four. The GP2X let that slide, and gpSP's fast paths relied on it. The 9500 doesn't. The stub's address checks now also look at the low bits, and anything unaligned takes the slower C path, which rotates the data the way a real GBA does.

The second run had a picture and sound. It also took ages to open the menu and longer to save. Both went through the C library's file functions, which on this phone are painfully slow. Now each file is one native read or write: a 128 KB battery save takes 0.3 seconds, a save state about one.



FireRed's intro, as the 9500 shows it: 240×160 scaled to 300×200, the whole height of the screen.

The rival battle

Then a run of crashes, each a little later in the game:

  • Killed after a while, no message. The whole 16 MB ROM had loaded into memory, leaving 2 MB for the phone. The emulator now always leaves 6 MB free and reads the rest of the ROM from the card in 32 KB pages.
  • Gone at the first battle with the rival. No exception in the log, which smelled like a stack overflow: gpSP links translated blocks by translating the next one straight away, recursively, with no limit. The recursion now stops at six levels, and deeper jumps go through a small trampoline. The next run got through the battle start.
  • A panic after the final blow to the rival's Squirtle. I measured the stack this time, and it was fine. The real culprit was the sound. A GB square wave channel has a frequency sweep, and gpSP clamped it at a value that made the next calculation divide by zero. The 9500 does floating point in software, and that library raises an exception for it. A real GBA turns the channel off there, so now GBA9500 does too.

After that, two battles in a row went fine, and the log said zero float errors.

Speed

FireRed runs at about 50 frames a second on the phone, out of the GBA's 60. But only 11 to 17 of those frames are actually drawn, the rest skipped. So we measured where the time goes:

Running the game alone takes nearly the whole 16.7 ms a GBA frame lasts. Drawing a frame takes more than that again. Along the way we fixed what could be fixed:

  • Reading a ROM page took 85 ms through the C library. With a native file kept open it takes 41.
  • Scaling the picture to the screen went from 10.6 ms to 3.5 by writing two pixels at a time.
  • The renderer compiled smaller (-Os) runs faster than at -O2: the ARM925's instruction cache is small, and gpSP's renderer is a lot of macro-expanded code.

The rest is real work. FireRed's overworld draws all four background layers and the sprites on every line, at about 130 µs a line. I had a theory that its window settings were sending it down a slow path. The register dump showed they weren't. There's an option to draw every other line per frame. It's faster, but it looks dizzy, so it's off by default.

1.1: a newer compiler

Quake9500 got 35% faster when its game code moved from GCC 2.9 to GCC 14, so GBA9500 1.1 got the same treatment. All the emulator's C is built on the PC by a modern GCC into one file, gba9500.rbl. A small Symbian program, built with the SDK, loads it and hands it a table of system functions: screen, keys, files, sound and time. Before it went to the phone, an ARM interpreter on the PC ran it through FireRed's intro, six billion instructions, to catch alignment faults the 9500 would trap.

The gain was modest this time. The dynarec's output and the drawing loops matter most here, and a newer compiler doesn't change the first.

The first 1.1 run also asked for E:\gba\gba_bios.bin, and the 9500 doesn't even have an E: drive. It now uses the first GBA folder that actually holds the BIOS, and the messages name the real folder.

The icon

An indigo GBA, drawn by a Python script in the 16 colours the Desk icons use.

As in the earlier ports, the Desk icon belongs to a tiny launcher app that starts gba9500.exe and gets out of the way.

About the pictures

The game pictures aren't photos from the phone. They come from that ARM interpreter, running the real gba9500.rbl on the PC and saving the phone's screen buffer. The chart's numbers are from the phone's own log.

Get it

The source and the SIS are on GitHub: github.com/Scorpizoid/GBA9500. The installable file is under Releases. It's GPL v2, like gpSP.

  1. Install GBA9500.SIS.
  2. Copy your own GBA BIOS dump to D:\GBA\gba_bios.bin (D: is the memory card) or C:\GBA\, and your .gba games next to it. No BIOS or games are included.
  3. Start GBA9500 from the Desk.

The keys: the rocker or arrows are the D-pad, X or Ctrl is A, Z is B, A and S are L and R, Enter is Start and Tab is Select. Esc opens the menu, with save states, picture size, frameskip and sound. Chr+S and Chr+L save and load a state, Chr+F is fast forward.

Thanks to Exophase for gpSP, to notaz for the GP2X tree it came from, and to the libretro people for keeping it alive.

The GBA came out in 2001. The 9500 came out in 2005 and was sold for spreadsheets. It turns out it can play Pokémon. Slowly.

Ei kommentteja: