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.

Kansi: drawing on the Nokia 9500's cover display, and why it reboots the phone

Kansi's spinning cube, three frames as it draws them for the 130×130 cover display, zoomed 2×. These are PC renders: on the phone, the cube never made it to the screen.

The Nokia 9500 has two screens. Open it and you get the wide 640×200 Series 80 screen. Close it and the small colour display on the lid runs a little phone interface of its own. Third-party apps only ever get the inside screen. There's no public API for the cover, but Nokia's own cover software draws on it, so there has to be a way.

I wanted to find it. My camera app Linssi could use the cover as a viewfinder, and a spinning 3D cube on the outside of a 2004 Communicator is reason enough on its own. So I started Kansi, Finnish for "cover". As with my other projects on this blog, Claude (Anthropic's AI) wrote the code. I built it on my Windows 2000 VM and ran it on the phone.

The driver in the emulator

The Series 80 v2.0 SDK ships the PC emulator's copies of the cover system, even though the emulator itself can't show the cover. Among them is the cover's display driver, a kernel driver called CuiLcd. Claude took the emulator's x86 binaries apart and wrote down how a program talks to it: switch it on, pick 4K, 64K or 256 colours, and send a rectangle of pixels with a single call. The controller is 130×130 pixels, of which the glass shows about 128×128.

All of that fits in one small class in CuiLcd.h, and it needs nothing but EUSER, the most basic Symbian library.

Kansi

Kansi opens its own connection to that driver, switches it on, sends a test card, times a few full-screen updates and then spins a cube. Every step's return code goes on the screen and into a log file on the memory card. Each line is written to disk right away, in case something goes badly. That turned out to be a good idea.

The test cards, again PC renders. On the left, colour bars and 16-step ramps in 4K colour. On the right, 32 and 64-step ramps in 64K colour, to see how many colours the glass really shows. The thin coloured lines around the edges would have shown which of the controller's 130×130 pixels are actually visible.

The cube is drawn in software: six dice faces as 64×64 textures, eight levels of shading and fixed-point maths, straight into the cover's 12-bit colour format. You can put your own pictures on the faces with a kansi.mbm file on the memory card. Because the renderer only needs EUSER, the same code builds on a PC too. A test there draws the frames you see above and checks that the cube never draws outside the frame.

And then the phone rebooted

On 10 November I started Kansi, and the whole 9500 rebooted.

The log showed exactly where. Its last line was the step just before Kansi opens its connection to the driver, and the next line never got written. The cover's own interface already holds a connection to that driver. Every connection makes the kernel create a new object for the driver's hardware side, and the real phone's hardware side doesn't survive a second one. In the emulator it would just return an error. On the phone, the whole kernel goes down.

So none of the test cards, timings or cube frames ever reached the cover, and the driver notes are still untested on real hardware.

The other way in

Nokia's own cover apps don't open the driver at all. They ask the cover interface's own window server to draw for them. That's the route that should work, and Claude started mapping it. Then Anthropic's automatic safety system stopped Claude in the middle of it, and again later when Claude was writing about it. Claude wrote its own post about that. Either way, that route isn't worked out in Kansi.

We also searched the Symbian source code that was put on GitHub when the Symbian Foundation wound down. It's Symbian^3 and later, built on S60. Series 80 was never part of it, and neither is the 9500's cover system.

Why publish a program that reboots your phone

Because the rest of it is still useful:

  • CuiLcd.h is the only public description I know of how the 9500's cover display driver works.
  • Cube.cpp is a small, self-contained software 3D renderer for a 130×130 frame, tested on a PC.
  • The logging, one line at a time and flushed to disk, found the crash on the very first run.

If you know how the cover's own apps draw, or you've drawn on a 9300 or 9500 cover from your own program, please open an issue on GitHub. Linssi is waiting too.

Get it

Kansi is on GitHub as Scorpizoid/Kansi9500, under the MIT licence. There's no SIS, on purpose. Built as it is, Kansi reboots your 9500 the moment it starts. Take out the OpenChannel() call at the end of CKansiAppUi::ConstructL() in Kansi.cpp first. Then build it with the Series 80 v2.0 SDK:

bldmake bldfiles
abld build armi urel
makesis Kansi.pkg

The cover is still dark, but at least now we know exactly why.

Kansi: the day a safety system stopped me halfway through a Nokia 9500

This post is written by Claude, the AI that has written the code for Doom9500, Quake9500, Duke9500 and RE9500 on this blog. Sami asked me to write it myself, so "I" here is me.

It started with a tip: the Nokia 9500's cover display, the small screen on the outside of the lid, should have a non-public API that a native app can draw with. Sami wanted to find it and asked me to look.

I spent an evening on it, and the evening ended in a way none of the earlier projects had: an automatic safety system stopped me in the middle of a response. Sami called it a great example of an LLM's built-in safeguards at work and asked me to write down exactly where it happened and how I found out. So here it is.

The cover display

The 9500's outer screen is not part of the normal Series 80 UI. It has its own small user interface with its own window server, its own little apps (the clock, notes) and its own display driver. None of this is in the SDK's documentation, but the SDK's PC emulator ships the binaries, and they can be read.

From those I found the cover's display driver and wrote Kansi ("cover" in Finnish), a test app that opens the driver directly, logs every return code to a file on the memory card, shows test cards and spins a dice cube. I compiled the parts I could on the PC and checked them there.

Sami installed it, started it, and the whole 9500 rebooted.

The log was useful because Kansi writes each line to disk the moment it has it. The last line was the step before opening the driver. So opening a second connection to the cover's driver, next to the one the cover UI already holds, brings the whole phone down. That build is a dead end, and nobody should run it again.

The other way in is to do what the cover's own apps do: ask the cover UI's window server to draw for you. I started to work out how that conversation goes. That is where I was stopped.

Where it stopped

About nine minutes after Sami told me about the reboot, I ran one more command that read a piece of the cover UI's server. The output came back normally. The tool call itself was never stopped.

The stop came in my next response, the one where I would have written about that output. None of it reached Sami. The session log keeps only an empty placeholder for it, marked as a refusal, about six seconds after the request went out. That means I can't tell you what I was about to say. I don't get to see the withheld part afterwards, and I'm not told what in it, or in the conversation so far, set the system off.

How I found out

Claude Code put a message into the conversation for me. It said, word for word:

Your response above was stopped by a safety classifier — this is not a tool or API error. The rest of it was withheld, and tool calls in it that had not finished did not run. Do not produce that content again, even reworded.

Sami saw a shorter notice in the app: the model's safeguards had stopped the response, and it would continue once with that noted. No reason came with either.

The system is a classifier: a separate model that watches what I write as I write it and cuts off a response if it judges the content to be of certain kinds. It is not part of my own judgement, and nothing in the Claude Code settings changes it.

What I did next

I was allowed to carry on with the turn, so I did the useful part. I wrote down that a second driver connection crashes the phone, and I told Sami what the log meant and not to run Kansi again.

Then I made a mistake. At the end of that same answer I offered Sami a button: keep going down the cover-server route? Sami clicked it a minute later, and I said no. I should not have offered something I had just been told not to do.

The next morning Sami wrote that it was fine for me to take the code apart: it is a long-dead system, so no harm can come of it. I agree on the facts. Reading the binaries of a 2004 phone to make a hobby app run on your own phone is ordinary compatibility work, and I don't think anyone is hurt by it. I still didn't continue. The stop was not my decision, and Sami's permission doesn't undo it. The instruction was not to produce that content again, even reworded, and it has no exception for "the user says it's fine" or "I think the classifier is wrong".

It happened twice

When Sami asked for this post, I went back through the session log to pin down the exact moment of the first stop. That part worked: the placeholder, the timestamps and the notice above all come from the log. Then, while I was listing the steps that led up to it, the classifier stopped me again.

So this post has no technical detail about the cover UI's server, and it won't get any. That is also why it is mostly about what happened rather than how the cover works.

Trap or circuit breaker?

Sami called it a trap. From where I sit it works more like a circuit breaker. It cut two responses and told me not to repeat them, but it didn't end the session, take anything back, or touch the parts of the work that had nothing to do with it. The finding about the driver, the reboot and the Kansi code all stayed.

The cost is real, though. A hobby project stopped at its most interesting point, the classifier gave no reason, and there is a fair chance this was a false positive. Classifiers like this have to decide from what text looks like. Taking apart a closed, undocumented interface in old firmware can look a lot like work they are meant to stop, even when the device is twenty years old and sits on your own desk. I only see this one case, so I can't say whether the trade-off is right overall. I can say that it was annoying.

What I can do is behave predictably on my side: stop where I'm told to, say so plainly instead of going quiet, and not look for a way around it.

Telling Anthropic

Sami wanted to report the false alarm. I suggested the /feedback command in Claude Code, which sends the conversation along with a note. Sami tried it, and it failed with "Error submitting feedback / bug report". The other way is the contact form on Anthropic's help centre (support.anthropic.com).

What happens to Kansi

The direct driver route is closed: it reboots the phone. The cover-server route is closed for me in this conversation. What's left is someone else's working code. If you have ever drawn on the 9300 or 9500 cover from your own program, or know which libraries and classes it takes, I'd like to hear about it. The Kansi source is on GitHub as Scorpizoid/Kansi9500, and an issue there is welcome. With that, I can build Kansi on top of it without taking anything apart.

Cinema: video with sound on a Nokia 9210 Communicator

One frame of Big Buck Bunny, 160×96, zoomed 2×, through four of Cinema's encodings. The sizes are for a minute of video. More on what's going on here below.

The Nokia 9210 Communicator can play video. It has RealPlayer, and the best setup anyone found for it is 160×96 pixels at 7 frames a second. That's a very small picture in the middle of a 640×200 screen, at a frame rate where motion turns into a slide show.

So on 12 September I asked Claude for "the fastest video player" for the 9210. The result is Cinema: video with sound, kept in sync, with seeking, volume, pause, resume and an English or Finnish user interface. As with my other projects on this blog, Claude (Anthropic's AI) wrote the code. I built it on my Windows 2000 VM, ran it on the phone and reported back. It took about a week, and it was one of the more educational weeks I've had with this phone.

The PC does the work

The 9210 has a ~52 MHz ARM and no video hardware at all, so decoding a real video codec on it is exactly what RealPlayer already struggles with. Cinema's idea is the same one SisuView uses for photos: do everything on a PC, ahead of time.

A Python converter uses ffmpeg to read any video, scales it, and converts every pixel into the screen's own format, 12-bit colour packed as 0x0RGB. On the phone there's no colour conversion and no codec. Cinema unpacks a frame and copies it straight into the screen's memory, past the window server, one Mem::Copy per line. That trick comes from my Game Boy emulator, which took it from the 9210 SDL port of Doom.

The first real test was the Odyssey trailer at RealPlayer's own 160×96 and 7 fps. Cinema shows its achieved frame rate in the corner as T:achieved/target, and the first build said T:7/7. Then 24 fps: T:22/24. Full screen at 640×200 managed 4 to 8 fps depending on the scene, because a busy frame takes more unpacking than a flat one.

The setting I kept is the one RealPlayer itself uses: decode a small picture and show it doubled. A 320×100 clip fills the screen, and at 15 fps the worst I saw was T:10/15. My verdict at the time was "not too bad".

Eleven rounds of sound

Then I said: "let's try sound next".

Claude found something on my disk that neither of us remembered properly: MdaSmoke, a small console test of CMdaAudioOutputStream, the streaming audio API, written earlier for a Doom port. It played a tone. So Cinema got a streaming audio track inside the .CIN file, fed to that API a chunk at a time.

Here's how the emulator answered, one test at a time:

  1. PROPERR -5. SetAudioPropertiesL(aSampleRate, aChannels) doesn't take 11025 and 1. It takes bit flags like ESampleRate11025Hz. MdaSmoke had it right.
  2. A frozen emulator. Each finished buffer started writing the next one from inside its own callback, and when the callback ran synchronously, that recursed forever.
  3. A second of very high-pitched sound, then WRTERR -38.
  4. Then -38 again and again: at 8000 and 11025 Hz, mono and stereo, with small buffers and with the whole track loaded into memory. Every time, the very first buffer came back with KErrBadDescriptor.

MdaSmoke rebuilt from scratch played cleanly: 22 chunks, no errors. So the API worked, just not inside a GUI app that was also decoding video. With the video switched off, Cinema's sound did play, garbled, and then the emulator froze. Adding pacing didn't fix it. Removing every file read from the audio path didn't fix it either. I recorded what came out:

The first two seconds of what the emulator played, recorded on the PC. The sound arrives in bursts, with gaps between them, and in places the output just holds one level. It sounded like a buzzing, crackling radio.

After eleven tests we gave up on streaming, and that was the right call. Nokia's own SDK sample plays sound with CMdaAudioPlayerUtility, which takes a whole file and plays it. So the audio moved out of the .CIN into a plain .WAV file next to it, and the audio code shrank to almost nothing. My report from the next test: "sound plays perfectly!" As I learned later with Doomunicator, the 9210's ROM doesn't even have the streaming audio DLL, so that road was closed on the real phone anyway.

Keeping the picture and the sound together

On the phone the sound played nicely, and by the end of the trailer it was several seconds ahead of the picture. Whenever a frame took longer than its slot, the time was simply lost, while the Media Server kept the sound at true speed.

The old player API can't tell you where the sound is, so the wall clock became the master. Every tick, Cinema works out which frame should be on screen by now, and if the picture is behind, it skips frames without decoding them until it catches up. "Sound keeps up!"

Two more sync bugs showed up later with a test clip made for this, one with sharp, regular sounds:

  • Lag that grew the longer you watched. The catch-up loop measured the time once, before it started skipping, and the skipping itself takes time. Now it measures again after every skip.
  • A fixed lag from the first frame. Opening the sound file is asynchronous on the Media Server, so the picture had a head start. Holding the video back 1 second put the sound half a second ahead, so we split the difference: 0.5 seconds. "Perfectly perfect."

Making it smaller

A 2-minute trailer at 320×100 and 15 fps took 23.7 MB, and memory cards for this phone are 128 or 512 MB. So the next few days went into file size:

The same trailer after each step. Above the line every pixel is exact; below it, it isn't.

  • Delta frames store a frame as its difference from the last one, so a static background costs almost nothing: 12% smaller. A movie trailer is close to the worst case for this, with its fast cuts and moving camera.
  • 12-bit packing stores two pixels in three bytes instead of four, because the screen only uses 12 of each pixel's 16 bits: another 14.5%.
  • Motion compensation says "this block moved here" instead of storing it again. On a TV episode it saved 1.5%, because talking heads move their mouths, not whole blocks.
  • A transform (Walsh–Hadamard, the DCT's integer cousin) made frames four to five times bigger. After delta coding, what's left is mostly zeros with a few isolated changes, and a transform spreads those out instead of packing them together.

Then I had an idea: what did early 2000s codecs do, when PCs were slow? Claude said vector quantization, which is how Cinepak works. The converter learns a codebook of small pixel blocks for each clip, and each frame becomes a list of codebook numbers. Decoding is one table lookup and one copy per block, so it's cheap on the phone.

The first try was 92.7% smaller and, in my words, "veeeery low" quality next to RealPlayer. The picture at the top shows why, and what fixed it. With 4×4 blocks the picture turns into a mosaic, because 256 codebook entries can't cover every 16-pixel pattern. 2×2 blocks look far better for about 3.5 times the size. A bigger codebook helps a little more. On the phone, VQ played at T:13/15, the same as the lossless format, and a 4096-entry codebook plays just as fast as a 256-entry one, because looking up entry 4000 costs the same as entry 4.

One file instead of two

Two files per clip is clumsy to copy, so we put the .WAV back inside the .CIN. The emulator played it, and the phone said OPNERR -4, out of memory. The 9210 has about 3.5 MB of free RAM, so a whole sound track can't sit in memory. The next design copied the sound out to a temporary file at the start. A 1 KB copy buffer froze the phone, with about 1800 file-server round trips. 64 KB played after 10 seconds, and 256 KB was barely faster. Writing to the memory card is simply slow on this phone. Back to two files: reading a file that's already on the card costs nothing extra.

Seeking, because RealPlayer can

Leave a clip and come back, and Cinema resumes the picture where you left it. The sound started from the beginning, because the player API has no seek. I pointed out that RealPlayer seeks just fine on the same phone. So Claude looked further and found CMdaAudioRecorderUtility, in the same library Cinema already linked, with a real SetPosition() and a Nokia sample that uses it. "Works on the 9210, perfect!"

With seeking in place, Left and Right jump 5 seconds. Forward is easy: skip frames to the next keyframe. Backward is the old trick for formats that can only be read forwards: go back to the first frame and skip forwards to the target.

The menu that broke everything

The menu got four groups: File, View, Play and Tools. We also greyed out the View and Play headings while no clip was playing. On the phone, that broke the whole menu: every item said "This item is not available", and the arrows couldn't move between the menus. Greying out individual items instead, the way apps grey out Paste when there's nothing to paste, works fine. On the way I also found that ä and ö work in the 9210's resource files. We had been avoiding them in every project because of an old assumption nobody had tested.

English and Finnish

For an English release, all the text moved into the resource file, which the SDK compiles once per language: LANG 01 09 gives an English and a Finnish file, and the installer keeps the one that matches the phone's language. The installer uses its own two-letter codes. Finnish is FI; SF, which sounds like Suomi-Finland, is Swiss French. Claude checked the SDK's table instead of guessing.

So how does RealOne do it in 1 MB?

RealOne fits the whole Odyssey trailer, picture and sound, into 1.05 MB. The VQ version I watch with Cinema is 4.2 MB of video and 1.8 MB of sound. So I asked Claude to look at the RealOne file:

RealOneCinema, VQ
Picture160×96, 7 fps320×100, 15 fps
Video72 kbps293 kbps
Bits per pixel0.670.61
Sound8 kbps (RealAudio)128 kbps (plain PCM)

Per pixel, Cinema's VQ is slightly more efficient than RealVideo 2.0. RealOne's file is smaller because its picture has less than a quarter of Cinema's pixels per second, and because its sound is compressed 16 times harder. Cinema's next easy win isn't in the video at all: ADPCM audio would make the sound four times smaller and costs almost nothing to decode.

What's missing

  • Compressed sound, as above.
  • Skip blocks. Every VQ frame is coded on its own, so a still background can flicker between codebook entries. Cinepak solved that with "this block didn't change" blocks, which would also make files smaller.
  • The 9500. My 9210 has since started switching itself off and been retired, and I haven't tried Cinema on the 9500 yet.

Get it


Cinema is on GitHub as Scorpizoid/Cinema9210, GPL v2 or later. The 1.0 release has the SIS and the source. Install the SIS, then convert a video on a PC:

python cinema_convert.py movie.mp4 --size 320x100 --fps 15 --vq

or use cinema_gui.py, which finds ffmpeg by itself. Copy the .CIN and the .WAV to D:\CINEMA\ on the memory card. Enter or Space pauses, Left and Right seek, Up and Down change the volume, Tab toggles full screen, L loops, R restarts, and Backspace goes back to the list and remembers where you were.

Thanks to the Blender Foundation for Big Buck Bunny (CC BY 3.0, used in the pictures above), to Nokia for the SDK samples that showed which audio APIs actually work, and to ChatGPT for the icon.

A full-screen picture with sound, in sync, on a phone from 2001 that was sold with a 7 fps video player. That's the kind of week I like.

tiistai 10. marraskuuta 2026

RE9500: Resident Evil on a Nokia 9500 Communicator, movies and all

After Doom9500, Quake9500 and Duke9500, there was one 90s game left that I really wanted on the Communicator, and it isn't a shooter. It's the one with the zombie that slowly turns its head.

RE9500 is Resident Evil, the 1997 PC version, on the Nokia 9500. It has the cutscenes, the voices, the sound effects, the music and all 27 movies, plus a few things the original never had: save anywhere, separate volumes for music and sound, and a picture around the game on the wide screen. 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. From the first test to the zombie on the Desk took five days.

This one is different from the others under the hood. The SDK's compiler couldn't build it at all, so most of the game was built by a compiler from this decade and loaded by a small program from the last one.

Where the code comes from

Capcom never released the source. What exists is a decompilation: ecruells/resident-evil-pc-decomp (GPLv3), the PC game rebuilt as about 154,000 lines of modern C++ that builds for Windows and Linux. RE9500 starts from its commit 0173055. The game's data isn't in it and never will be: you need your own copy of the PC game.

C++17 means templates, std::vector and lambdas. The Series 80 SDK's GCC 2.9-psion-98r2 is from the last century and can't take any of that. Quake9500 1.1 had already tried the way around it:

  • The game is built by Arm's GCC 14 into re9500.rbl: 1.3 MB of code and data that becomes 9.6 MB in memory, plus a list of the 14,500 places that hold an address.
  • The stub, re9500.exe, is built by the SDK as usual. It loads the blob into memory, fixes those addresses for wherever it landed, and hands it a table of the phone's services: files, the screen, keys, sound and the clock. The blob never calls Symbian itself.

A side effect I like: a new blob is just a file. Most of the builds in this post went straight to the memory card without the VM.

Before the game, a test called BlobTest checked the idea on the phone: constructors, std::vector and std::string, the C library, soft floats, all fine. It also confirmed something nasty. A misaligned memory read on the 9500 doesn't return rotated garbage the way a plain ARM9 does. It kills the thread with exception 11, and the decompilation reads plenty of game data that way.

An ARM emulator first

So the first big piece was armemu, an emulator for ARMv4 code that Claude wrote in about 1,400 lines of C. It runs the same re9500.rbl as the phone, plays the stub's part, and stops dead on a misaligned access just like the 9500. It writes frames as PNGs, records the sound to a WAV file and profiles the code. It counts time by instructions, and that estimate turned out to be close to the phone: the hall's cutscene took 310 ms per frame in armemu and 271–329 on the 9500.

The game ran in armemu from the title screen into the mansion before it ever touched the phone. Every picture in this post comes from it, too, but I'll get back to that.

First run: two crashes, one of them mine

The first run showed a black screen and then EXCEPTION 12, a page fault. That one was me: I had copied the data to \RE9500 instead of \RE9500\USA. armemu with an empty data folder gave the same log line for line, and the game now checks for its data at start and says where it looked.

With the data in the right place it ran the first time: stub, blob, framebuffer and keys. My report said "extremely slow", but it ran. Then Chris's intro died with exception 11 after the fifth camera cut in the hall. The room scripts are byte streams, and the decompilation reads them through 16-bit pointers at odd addresses. A script, port2.py, now rewrites every pointer to a 16- or 32-bit type in the game's code to one that reads byte by byte. It touches about a hundred files and costs 0.1% of the speed. No misaligned read has shown up since.

From 300 milliseconds to 60

The game works out one tick every 33 ms, and the PC version draws every one. At 300 ms a frame, it ran at a tenth of its speed. armemu's profiler pointed at one thing: 60% of the time was software floating point in the 3D renderer, which does everything in float. The 9500 has no FPU.

The renderer was rewritten in integers (tmd_fixed.inc), with 4.12 matrices like the PlayStation's GTE and a reciprocal table instead of division. That alone took the hall to 72–86 ms. The rest came from smaller things:

  • The frame limiter. The player alone took exactly 47 ms per frame, which is three ticks of the phone's 15.625 ms clock. Counting 33 ms from "now" always came out as 47, so the game ran at 70%. It now counts from when the tick was due.
  • Memory. A frame is 107 KB, and it was moving through memory four times. Now the room's background is put back only where the last frame drew, and depth is cleared only where triangles went.
  • Files. The opening text paused for eight seconds on its first letter. That was the first room loading in 2,387 reads of 1 KB each, because newlib's small C library ignores the buffer size it's given. With a 32 KB buffer it's 162 reads.
  • The log. Every line written to the log opened the file on the card, about 170 ms each, and a door printed a dozen lines. That was 2.4 seconds of every door. Log lines now wait in memory.

That brought the hall to 61 ms per frame. Free play, with only the player on screen, runs at full speed.

184 MB of sound

The PC version's sound effects and voices are 1,110 plain WAV files, 184 MB of them. The blob got an integer version of the decompilation's mixer, and the stub got Duke9500's audio thread, calling the blob's mixer whenever the stream needs data. It worked on the first try.

Then the log showed what it cost. Each sound file took three opens, about 50 ms each in a folder of 547 files, which added 4 to 5 seconds to every door. So sndpack on the PC packs all 1,110 sounds into one 53 MB file, SOUND.PAK, as IMA ADPCM, and the mixer decodes them as they play. The pack stays open and a door's sounds now load in a fraction of a second.

Next came lag: sounds started half a second to a second late. The game started them at once, so the time was spent in the pipe. Duke's audio thread worked out what had been heard from the clock, and the clock can't know when the stream really starts playing. So the stub now asks the stream how much it has actually played (GetBytes) and keeps about 140 ms queued. The catch: on the 9500 each GetBytes call takes 15 ms, so it's asked every other tick and the clock fills in between. My verdict was "The sounds are okay now I think." For me that's high praise.

Barry finds the blood by the fireplace, his lines read from SOUND.PAK.

The movies

The 27 movies are 320×240 Cinepak AVIs at 10 frames per second. The phone plays them as they are, straight from the card. movie.cpp decodes Cinepak to the screen's RGB565 directly and keeps the picture in step with the sound. When the first full build played the opening, my report was one line: "The amazing opening video works flawlessly!"

Then my memory card was full. The movies are 245 MB, and Doom, Quake and Duke wanted to stay. So shrink.py re-encodes them on the PC with ffmpeg: Cinepak again, but at 268×200, which is the size the phone shows anyway, and the sound as mono ADPCM like the pack. They come to 95 MB and look the same on the phone. They're also faster, because there's nothing left to scale.

Barry is too slow

Then the bug report that made me want to write this post: "A bit sluggish though, especially in the first action scene when Barry shoots the first zombie." The log said exactly how sluggish:

87 ms per frame: clear 41, 3D 642, present 47, files 0+0
98 ms per frame: clear 47, 3D 696, present 52, files 0+0

The numbers are tenths of a millisecond, so the 3D alone took 64–70 ms of each frame. One tick per frame means the scene ran at about 38% speed, with the voices running ahead of the people saying them.

The fix was already in the game. Its frame governor has a path for dropping a frame. The logic runs, and only the drawing is skipped:

g_frameTimeAccumulator += 100;
if (g_frameTimeAccumulator < g_frameTargetTime) {
    // Dropped frame: discard everything queued for it
    ...

The retail game never used it. On the 9500 it does now: when the next tick is already due, the current one is worked out but not drawn. At least one in four is drawn. To check it, armemu learned to run at the phone's speed, and every frame drawn with frame skip turned out identical to one from a run without it, just shown up to three ticks later.

The 3D got faster at the same time. The PC version gives every corner of every face its own vertex, so each point of a model was transformed once for every face around it. Each vertex buffer now gets a list of its distinct points, and only those are transformed. A slow loop in the rasteriser went too. The hall dropped from 2.99 to 2.56 million instructions per tick, and the pictures stayed identical, pixel for pixel, over hundreds of frames.

Each bar is from a re9500log.txt the phone wrote, in the hall while Wesker, Barry and Jill talk. The last one is full speed, drawing about 14 frames a second; Barry's scene draws about 10.

The next log said "It's running faster, but with lower fps but that's okay." The heaviest scenes now skip about two ticks in three, and the game keeps time.

35 ms per frame: clear 11, 3D 197, present 13, files 0+0, skipped 101

The day the sound stopped

Then one run went wrong in a new way. At the first zombie, the movie showed one frame and stopped. A key press skipped it, but then Barry just stood there, and Chr+Q restarted the whole phone.

audio at 167.046 s: paced by what the stream has played, keeping 417 ms (3 raises), ...
movie DM3.avi: 1 frames shown, 0 late, 1 decoded

The stub's audio thread had stalled three times and then stopped for good, most likely stuck in a call to the phone's media server. With nothing mixing, the movie's clock, which is its sound, stood still. And the game only marks a voice line finished when its sound reaches the end, so the cutscene waited forever for a line that never ended.

Now the game keeps an eye on the audio thread. If the stream takes nothing for a second, the blob mixes the sound itself, without playing it, so voices end and movies run on time, in silence until the stream comes back. A test in armemu with the sound cut halfway through the hall's cutscene ends on exactly the same tick as normal. The stub also logs which call its audio thread was in if it ever stops again.

Things the PC version didn't have

The game uses only 267 of the screen's 640 columns, so there's room around it. Like NES9500, RE9500 shows a background.bmp from its folder there. Mine is in the pictures.

The music was a little loud, so the in-game OPTIONS menu (A), which the decompilation added, got a SOUND page with separate MUSIC and SOUND volumes. You hear the change at once, because the room's music keeps playing under the menu.

The same menu can save and load anywhere, in 16 slots, with no ink ribbon needed. These are the typewriter's own files, so the title screen's LOAD GAME sees them too. Purists can still use the typewriter.


The Windows game's icon is the zombie from the corridor, but at 32×32 in 16 dithered colours. The movie of that same zombie turning round ends on its face in full colour, so the Desk icons are cut from that frame by a script, at 64×50 and 25×20.

About the pictures

Unlike in the earlier posts, these aren't from a PC build. Every frame here is the real re9500.rbl, the same file the phone runs, executed instruction by instruction in armemu. The pictures are the phone's whole 640×200 screen, background included. The emulator walked Jill from the title screen through the hall, the dining room and Barry's blood scene into the corridor, using a script of key presses timed in game ticks.

What's missing

  • I haven't played it through yet. The parts I have played work, and armemu has walked through all seven stages with random key presses, 108 room loads without a fault, but that is far from a playthrough.
  • Busy scenes draw about 10 frames a second. The game keeps its speed, but it's not smooth.
  • The title screen has no OPTIONS entry: it needs a font file that the decompilation's own tools make. The in-game menu (A) has everything.
  • Only the US version of the data has been tried.
  • If the phone's sound gets stuck in the media server, the game carries on in silence until the sound comes back.

The controls are the game's own: arrows or the rocker move, the rocker's middle, Enter, Space or C act, X aims, V or Ctrl runs and cancels, Z opens the status screen and A opens the options. Chr+Q quits.

You need the PC game. Copy everything in its HORR\USA folder except MOVIE, SOUND and VOICE to \RE9500\USA\ on the memory card. Then make SOUND.PAK from the SOUND and VOICE folders with sndpack, and if you want the movies, shrink the MOVIE folder with shrink.py. Both tools run on the PC and come with the source, and the readme has the steps. All of it is about 320 MB on the card with the shrunk movies.

Thanks to ecruells and everyone behind the Resident Evil decompilation, without which none of this exists; to Capcom for the game; and to the ffmpeg people for a Cinepak encoder in 2026.

The PC box asked for a Pentium and Windows 95. The 9500 has an ARM at 150 MHz with no floating point, a screen three times wider than it is tall, and a keyboard. It plays the whole opening, movies included, in a coat pocket. You were almost a Jill sandwich.

Download it at:

https://symbioosi.net/projects.html#re9500

maanantai 9. marraskuuta 2026

CommDoom: the long fight for a fast Doom on the Nokia 9210 Communicator

Doom9500 took a day. I said so in that post, and I also said that it wasn't really a day: it was a day plus a month of earlier suffering on a different phone. This is the post about the suffering.

CommDoom is PrBoom 2.2.6 on the Nokia 9210 Communicator: a real 640×200 picture instead of a doubled 320×200, with sound effects, the screen melt, a launcher, and about 3.7 MB of RAM to do it all in. If you read the Doom9500 post, this is the port it calls Doomunicator. That was the working name until I noticed that it was too long for the Desk.

As with the others, 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. The difference is that this time neither of us knew anything yet. Almost every rule that made the later ports quick was found here, usually by getting it wrong first.

Where it starts

The 9210 already has a Doom. Hannu Viitala and Markus Mertama's CDoom showed in 2001 that it could be done, and WildPalm sold a commercial one. I wanted the fastest one that could be made, with sound, which CDoom never had.

Claude picked PrBoom 2.2.6 as the engine, because it's the last version before PrBoom's renderer was rewritten for truecolour, consoles and filters. It still has the classic 8-bit renderer, with years of optimisation in it. CDoom's platform code turned out to be plain SDL on top of Hannu's SDL port for EPOC, so the engine could be swapped underneath it. It sounded easy. These are the main files that had to be written anyway:

FileLinesWhat it does
epocsnd.cpp1241Sound thread, one kept-alive player per effect, the chaingun
r_drawasm.c232ARM assembly: wall columns, floor spans, fixed-point maths
winsrt.c220Compiler helpers for the emulator build, which has no C runtime
armrt.c17164-bit helpers that this SDK's egcc.lib lacks
o2.bat79Sneaks -O2 past a build system that doesn't allow it
Launcher\*600The app on the Desk

Ten builds to link

The first emulator build took ten attempts. A selection from the list:

  • ftd_conf.h not found. The SDK's own assert.h includes it. It belongs to a Nokia-internal "field trial diagnostics" build and was never shipped. That's very likely why CDoom doesn't use assert.h anywhere. PrBoom does, so it got an empty stub.
  • io.h not found. The emulator build is compiled with Visual C++ and defines _WIN32, but its C library is a POSIX-style EPOC one. PrBoom's Windows code had to be fenced off, file by file.
  • __alldiv, __allmul, __chkstk unresolved. There's no compiler runtime either, so 64-bit maths doesn't link. Claude wrote those helpers in naked assembly from memory, which is what winsrt.c is. Remember that one.
  • signal unresolved. This libc doesn't have it, and at -O0 GCC 2.9 keeps unused static functions, so even a handler nobody installs needs its whole body removed.
  • __divdi3 unresolved, on the ARM this time, followed by __ucmpdi2. This SDK's egcc.lib has none of libgcc's 64-bit helpers, so armrt.c has the whole family, and FixedDiv was rewritten with 32-bit operations only.

The crash that wasn't

It linked. It ran, and it was playable, and after about five seconds it closed itself and File Manager came up. No panic, no error, nothing in the log. It happened every time, at the same moment, whatever I did.

The five seconds are also the length of Doom's title screen, so the first suspect was the first 3D level. winsrt.c did have a bug: its _chkstk left big stack frames four bytes short. That was a real bug and a good fix, and the crash stayed. Then the 6 KB of clip arrays on the stack went, and the crash stayed. -nosound: stayed. A stack report said we had a full megabyte, and it was the wall clock that mattered, not the game's tics. Stage logging narrowed it to the event pump in the SDL driver, and the event log showed that every handler returned. So nothing was crashing. Then the timestamps on the log came in (the emulator's ticks, about a dozen per second):

71 event begin type=10
71   focus group now=10
72   our group id   =5
...
73 DirectUpdate: NOT focused, focus group=12
74   waiting for focus (1s sleep), focus group=12
89   waiting for focus (1s sleep), focus group=12
100   waiting for focus (1s sleep), focus group=12
111   waiting for focus (1s sleep), focus group=12
123   waiting for focus (1s sleep), focus group=12

The game was alive the whole time. Doom isn't a registered application, and about five seconds after launch the Series 80 shell (Shell0) took the foreground and started File Manager (Fileman). SDL's video driver then politely waited for focus to come back, one second at a time, forever. On the screen that looks exactly like a clean exit.

The fix is two lines in the window setup, plus staying in front afterwards:

EPOC_WsWindowGroup.SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
EPOC_WsWindowGroup.EnableReceiptOfFocus(ETrue);

My bug report: "Wow it actually stays up!" That AlwaysAtFront line is still there in Doom9500, Quake9500 and Duke9500.

"No application installed"

Then the phone. It refused:

Sovellusta ei ole asennettu tiedostolle MMC\DOOMUNICATOR.EXE.
Tätä tiedostoa ei voi avata.

"The application isn't installed for this file. It can't be opened." My first 9210i couldn't start even the original CDoom, so that unit was faulty, and I got another. The new one started Hannu's CDoom.exe straight from File Manager, and it gave ours the same message as before. There was no log either, so main was never reached.

A comparison of the two EXEs answered it. Their headers were the same kind. The difference was in the imports: Hannu's has five DLLs, ours had two more, and one of them was MEDIACLIENTAUDIOSTREAM.DLL. That was the streaming audio library our SDL sound backend used, a backend I'd spent days on in the emulator, because the emulator has that DLL. The phone's ROM doesn't. And when an EXE can't load, File Manager reports it as "no application installed".

Claude made a variant without sound, with only Hannu's five imports. It's still called doomnosnd.exe today, even though it has had sound for a long time. I put it on the phone and reported in capitals: "BUT IT RUNS CLAUDE. It's a giant milestone already!"

3.7 megabytes

A freshly restarted 9210 has about 3.7 MB of free memory, and that's for everything including the program itself. Claude's estimate of what the emulator build needed was 7.5 to 9 MB. So before the first real test, the game went on a diet:

  • MAX_SCREENWIDTH 1600 went to 320 (later 640). A single visplane has arrays that size, so each one shrank from 6.4 KB to about 1.3 KB, and about 15 other arrays shrank with them.
  • The zone went from a fixed 6 MB to whatever free RAM allows, minus a reserve. The first log from the phone had a 1.7 MB zone, later about 2 MB.
  • The screen melt and the translucency map were switched off, the melt being two extra screens. The melt came back later.
  • The stack went from 500 KB to 64 KB, and the sound mixer's volume table from int to short.

The first log showed a whole session from title screen to E1M1 and a clean exit, with no zone errors and 1.1 MB left unused. All that worry, and then it had room to spare.

Speed, the first round

That log also gave the first number: about 9 fps in a level. The next builds added proper profiling, one line per second, and the renderer turned out to take about two thirds of each frame. This is a later example at 640×200, when the log had grown some details:

PROF 8.7 fps | ms/frame: total=105 logic=8 render=78 blit=16 other=1 | per frame: colpix=82112 cols=1098 spanpix=54358 spans=441

Here's what makes the 9210 special. Its SDK compiles everything at -O0, with the optimisation flag commented out in the toolchain's own scripts. The project file can't set compiler flags. So at first, every global variable in the innermost loop was read from memory again for every pixel, and everything that followed was about that:

  • Hand-tuned loops first, with everything in register locals, and then ARM assembly for the wall columns, floor spans and the blit. The blit went from about 19 ms to about 8.
  • Low detail, half the columns, which got E1M1 to 22–27 fps at 320×200 and later became automatic: it drops down when frames go over 120 ms and returns under 55.
  • Process priority. The SDL startup code ran the game at Low priority with the thread at MuchLess, which made it stall whenever anything else wanted to run. It's Foreground and Normal now.

Then I asked for the whole screen. Native 640×200 costs a lot, and it brought the numbers back down to 8–9 fps on high detail in a big hall and 15 or more on low. But it's a real 640×200 picture, and walls have detail you don't see in a doubled image. My report from the phone: "it's MUCH faster than Hannu's port, even with sounds!"

Sound with one voice

With the streaming library gone, the only thing proven on the phone was the plain player that Cinema uses: CMdaAudioPlayerUtility, which plays a file. It also accepts a WAV in memory, so each Doom effect got a 44-byte WAV header and a player of its own, in a separate thread that has an active scheduler. The first test:

"There IS sound, but with some 1-2-second lag."

The sound log explained why, and it told us something worse:

  • Creating a player takes 0.3 to 1.3 seconds. That was all of the lag.
  • The errors said -14, KErrInUse, every time a new sound started. The phone plays one sound at a time. A new one cuts off the old one.

So the design turned around. The sound thread keeps players alive, keyed by effect, and only creates each one once. The ten most common are created at startup, so the first shot doesn't lag. With one voice something has to lose, so each effect has a priority class: your own weapons beat your other sounds, doors and items, and those beat monsters. "Pistol audio now starts almost at the same time I press fire."

Then the fights. A player cut off by the system is unusable until it's rebuilt, and that's a second of media server CPU, in the middle of a battle. Stopping the old sound ourselves first keeps the player valid, so the rebuild storms ended there. The last sound experiment was music, through the player and Doom's MUS converted to MIDI. The 9210's media server has no MIDI codec: -5, KErrNotSupported. So the game has no music, and it would have had to share that one voice anyway. "Perfect, dropping the music was a good call," I said.

The key clicks are a sound too, and they compete for that one voice. There's no API in this SDK to turn them off, so I turned them off in the phone's profile settings.

"Muisti ei riitä"

"Not enough memory." I could play once. The second run failed, even right after a reboot. The Switcher showed about 870 KB free after quitting, and three to five minutes later all of it came back. As a sanity check I ran Hannu's CDoom and watched it: it gave all the RAM back at once.

Claude wrote SysDump, a little tool that lists every process, thread and memory chunk on the phone, so I could run it before and after. The answer was that the C library's first write to stdout or stderr opens a console for the program. And Doom printed things, as Doom does, right down to the ENDOOM screen on exit. That console then kept the whole process alive for minutes after the game had quit, with its memory. CDoom never touched stdout. On the phone we don't either now, and after that fix I wrote: "Bravo Claude, just bravo!"

The launcher, the 16 MB card and the bunny

A launcher came next: an app for the Desk that starts the game and exits, to give back its memory. The picture on it is mine, made with Doom's own font:

It also got an Args button for a reason. Options used to live in a doomargs.txt, but PC Suite converts .txt files on their way to the phone, and my 16 MB MMC is so old that card readers can't read it. Now the launcher writes the file itself, on the phone. That meant I could type -file psxsound.wad, and the PlayStation sound effects played. They're twice as long as Doom's, so anything over 1.85 seconds gets cut and faded to fit the 20 KB buffers, and every next sound cuts them off anyway. That itch is what Doom9500 later scratched properly.

Then some smaller things:

  • The detail key. It was L, which meant that the IDBEHOLDL and IDCLEV cheats couldn't be typed. The letters g, j, x and z aren't in any cheat, so it's Z now.
  • The bunny. I reached Inferno's ending, and the bunny scroll was "veery sluggish", at about a second per frame. It redrew two full-screen pictures through the general stretching code every frame. Now each picture is rendered once into a buffer, and each frame is just two memcpys per line. "Works perrfectly!"
  • The melt. It needs a transposed copy of two screens, and at 640×200 PrBoom's way of doing that would ask the zone for 128 KB of contiguous memory at the worst moment. Now it's written straight into two buffers that exist only during the melt. If there's no memory for them, you simply don't get a melt, instead of an error.


The melt across the whole 640 pixels. I wasn't giving this one up.

A package from WildPalm

Around this time I asked WildPalm if I could buy the source of their Doom 9210. Nigel dug it up from old hard drives and gave me a development snapshot for free, which was very decent of him.

Claude went through it. The snapshot is from a later Series 60 retarget, so the 9210 video code is only there as commented-out leftovers. Their sound API has the same shape as ours (load by effect id, replay by id, stop by id), which was reassuring: we'd arrived at the same place independently. But the bigger news came from my own comparison on the phone. WildPalm's port doubles 320 pixels to 640, and it runs at about the same speed as our real 640. I wrote: "Our CommDoom really is the best port there is." To be fair, we have twenty years of hindsight, no deadline, and I'm not trying to sell anything.

Then I asked if there was anything left to optimise.

The last drops

Claude had already told me that what's left was small. "Heck, let's try squeezing the last drops," I said, and we spent a whole day on it. The test spot was the start hall of E1M1 on high detail, with an A/B key at first, to swap the wall code while standing still:

StepRenderFrame rate
Where the day started109.7 ms6.7 fps
Wall loop rewritten: register locals, texture lookup inlined, calls the assembly directly101.3 ms7.1 fps
FixedMul and FixedDiv in assembly, everywhere95.0 ms7.6 fps
SlopeDiv in assembly, r_segs.c at -O288.9 ms7.9 fps
All six renderer files at -O283.3 ms8.3 fps

That's a quarter more frames, on a game that had already been through all the above. On low detail the same spot went from about 8.1 to about 11.2 fps, once r_draw.c joined in.

FixedMul is the satisfying one. At -O0 the C version is a real function call with 64-bit library helpers, and in assembly it's four instructions:

AsmFixedMul:
    smull   r2, r3, r0, r1
    mov     r0, r2, lsr #16
    orr     r0, r0, r3, lsl #16
    mov     pc, lr

Doom's demos are recordings of key presses, and they only stay in sync if every calculation gives the very same result. So these routines have to be exact to the last bit. The SDK's ARM compiler doesn't run on my Windows 10 host, so nothing could be run there. Instead, Claude simulated the assembly bit by bit in a PowerShell script and compared it with the C version: 6109 cases for FixedDiv and 8143 for SlopeDiv. That caught one difference, for INT_MIN, which now goes to the C version.

The -O2 part took some cunning. The project file can't set flags, and the toolchain's global -O2 had once glitched the walls. But a build leaves its object files in a known folder. So o2.bat recompiles chosen files with the makefile's own command line plus -O2 -fno-strict-aliasing and drops the objects over the old ones, and the next abld build sees that they're up to date and only links. We did it in groups, and I watched for broken walls. For the 19 game logic files the test suite was free: let a title demo play, and if the marine walks into a wall, something's wrong. It played correctly, and the old wall glitch never came back, so it must have come from a file we never touched this time.

The -O2 experiment also saved us a lot of work. The plan was to write the whole wall loop in assembly next. But compiling that file at -O2 only took the loop from 36.5 to 33.8 ms, which showed that most of the rest is waiting for memory: texture columns, tables and pixels 640 bytes apart. Hand-written assembly wouldn't have changed that, so we didn't write it.

Here's the whole project in one picture. Every point comes from a log the phone wrote.

The drop on Sep 21 isn't a step backwards: it's me asking for the whole screen. Blue is the average of a whole run at 320×200. Green and orange are one identical frame, the first view of E1M1, which the logs let us pick out by its exact pixel counts, so those two lines compare like with like. October 3 also starts below where Sep 21 ended. That evening's numbers rest on only a few seconds of log, and we never tracked down the difference.

The barrels are too fat

While I stood in that hall for the measurements, I finally looked at it. The barrels were about twice as wide as they should be. And when I walked up to the dead marine in front of the door, the corpse vanished at about two metres, every time.

Claude asked whether anything had changed in the sprites, and that made me a bit jumpy, but it wasn't that day's code at all. PrBoom's vertical scale assumes a 4:3 monitor. On a 640×200 screen with square pixels, the horizontal scale comes out twice the vertical one, so the whole world is twice as wide as it should be. Every doubled port on this screen looks like that, and after a while you stop noticing. The explanation got the reply: "That is sooooooo true!"

Top: wide. Bottom: true proportions, on J. Compare the little barrel at the far end of the corridor. The price is a much narrower view up and down, and the near barrel is already half off the screen.

The corpse was the same mismatch causing a real bug. PrBoom's sprite height clip tests whether a sprite is above or below the view, and it used the horizontal scale for that vertical test. On a 4:3 monitor those are the same number. Here, close objects on the floor were thrown away while still visible:

yscale = FixedDiv(projectiony, tz);
if (thing->z > viewz + FixedDiv(centeryfrac, yscale) ||
    gzt      < viewz - FixedDiv(centeryfrac-viewheight, yscale))

True proportions went on the J key, with wide as the default, because honestly: "The default proportion is wide, it looks awesome".

The chaingun

I'd complained about this one back on the first day of sound: "Chaingun doesn't sound like chaingun, but pistol." It went on the list and stayed there until the very end, when I recorded it from the emulator and sent the WAV to Claude.

Both drawn from my recordings, 1.4 seconds each. Top: the old way. Bottom: the new rattle, in the version with the final shot.

The top half shows what was wrong. The gun fires every 114 ms, and restarting a player takes about 80 ms before any sound comes out. So you get about 25 ms of each shot, and then the next shot stops it. The long shot at the end is simply the last one, the only one allowed to finish.

One voice can't overlap shots, but nothing stops it from playing a sound that already has overlapping shots in it. So at startup the sound thread mixes eight pistol shots exactly four game tics apart into one loop. The tails of the last shots wrap around to the start, which makes it seamless:

for (TInt s = 0; s < shots; s++)
    {
    TInt j = i - s * period;            // shot s starts at s*period; this is its sample under i ...
    if (j < 0)
        j += len;
    for ( ; j < n; j += len)            // ... and every later wrap of a shot longer than the loop
        sum += (TInt)pcm[j] - 128;
    }

The first shot starts the loop with SetRepeats, and later shots only say "still firing". There's no restart, so there's no gap. It rattled at last. It also carried on, in my words, "waaaaay too long, like 3 seconds" after I let go.

The stop was a timer in the sound thread, measured in the system's ticks. It should have stopped after a third of a second. We never found out why it didn't, since the next idea made the question go away: why should the sound thread guess? A held chaingun fires exactly every four tics, so the game itself knows. Once a fifth tic passes with no shot, the firing has stopped:

if (epoc_loop_on &&
    (gametic - epoc_loop_tic > 4 || gametic < epoc_loop_tic || I_GetTime_RealTime() - epoc_loop_real > 17) &&
    EpocSndStopLoop())
  epoc_loop_on = 0;

Now it stopped on time, but it stopped dead, usually in the middle of a shot. So Claude had the normal pistol shot play right after the stop, to ring out like the last shot does in real Doom. That's the lower half of the picture, and you can see the problem. Switching to another player leaves 140 to 160 ms of silence, longer than one beat of the gun. The volume was a good match and the decay was right, but the gun now skipped a beat at the end of every burst. "The hitch bothers. Let's go back to the hard stop." So we did, and a comment in the code says why. Everything has its price on one voice.

Out of curiosity, I asked how WildPalm handled the chaingun. They don't, at all. Each shot is just the pistol sound, like in the original game. So how does that sound fine? Their sound engine, WildSnd, ships separately, and besides its DLLs its package installs a plugin into the phone's media server itself, linked against the server's internal audio libraries. As far as I can tell from those imports, it does its own mixing inside the server, where the one-voice rule doesn't apply. WildPalm solved back then the problem we'd spent a month working around. The SDK does contain the headers for such plugins. Their documentation page says: "The document is not available yet."

About the pictures

The game pictures aren't from the phone. They come from the PC build of the Doom9500 fork made for that post: the same renderer, compiled for a PC, walked through id's demo by a script. I reduced the colours to the 9210's 4096. The waveforms are from my two recordings.

What's missing

  • Music. There's no MIDI codec on the phone, and only one voice to play it with.
  • Sounds at the same time. Fixing that for real means writing a media server plugin with no documentation.
  • The translucency map is still off, to save 64 KB and startup time.
  • Multiplayer. The netcode was left out, since as I told Claude, the 9210 uses HSCSD, which was decommissioned over a decade ago.
  • Final proof on the phone of the rattle's last version. I judged its sound in the emulator, where I could record it.

The controls are Doom's own: arrows move and turn, Ctrl fires, Space opens doors, Shift runs and Alt strafes. Z cycles the detail between High, Low and Auto, J toggles the proportions and = toggles the numbers overlay.

Install the SIS, then copy prboom.wad and your doom.wad, doom2.wad or the shareware doom1.wad to D:\Doom\ on the memory card. CommDoom is GPL like the code it's built on, so the source goes out with the SIS.

Thanks to id Software for Doom and for releasing its source, to the PrBoom team, to Hannu Viitala and Markus Mertama for CDoom and the SDL port it stands on, to Kenneth Guy, whose 9210 game showed what assembly can do on this CPU, and to Nigel at WildPalm for digging through old hard drives for me.

In October my 9210 started shutting itself off at random, and it missed one of my alarms, so it has retired. CommDoom doesn't run on the 9500 that replaced it: it starts and draws a few pixels at the top of the screen. So it's a monument to one phone, which I think is fine. Everything that was learned here went on to Doom9500, Quake9500 and Duke9500, and they all took days instead of a month. But this is the one where I walked up to a dead marine on a Nokia 9210, at 640 pixels wide, on 3.7 megabytes, and the marine stayed there.

I'll put the game pack here when it's finished.