sunnuntai 22. marraskuuta 2026
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:
| File | Lines | What it does |
|---|---|---|
epocsnd.cpp | 1241 | Sound thread, one kept-alive player per effect, the chaingun |
r_drawasm.c | 232 | ARM assembly: wall columns, floor spans, fixed-point maths |
winsrt.c | 220 | Compiler helpers for the emulator build, which has no C runtime |
armrt.c | 171 | 64-bit helpers that this SDK's egcc.lib lacks |
o2.bat | 79 | Sneaks -O2 past a build system that doesn't allow it |
Launcher\* | 600 | The app on the Desk |
Ten builds to link
The first emulator build took ten attempts. A selection from the list:
ftd_conf.hnot found. The SDK's ownassert.hincludes it. It belongs to a Nokia-internal "field trial diagnostics" build and was never shipped. That's very likely why CDoom doesn't useassert.hanywhere. PrBoom does, so it got an empty stub.io.hnot 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,__chkstkunresolved. There's no compiler runtime either, so 64-bit maths doesn't link. Claude wrote those helpers in naked assembly from memory, which is whatwinsrt.cis. Remember that one.signalunresolved. This libc doesn't have it, and at-O0GCC 2.9 keeps unused static functions, so even a handler nobody installs needs its whole body removed.__divdi3unresolved, on the ARM this time, followed by__ucmpdi2. This SDK'segcc.libhas none of libgcc's 64-bit helpers, soarmrt.chas the whole family, andFixedDivwas 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_SCREENWIDTH1600 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
inttoshort.
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
registerlocals, 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:
| Step | Render | Frame rate |
|---|---|---|
| Where the day started | 109.7 ms | 6.7 fps |
| Wall loop rewritten: register locals, texture lookup inlined, calls the assembly directly | 101.3 ms | 7.1 fps |
FixedMul and FixedDiv in assembly, everywhere | 95.0 ms | 7.6 fps |
SlopeDiv in assembly, r_segs.c at -O2 | 88.9 ms | 7.9 fps |
All six renderer files at -O2 | 83.3 ms | 8.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.
maanantai 2. marraskuuta 2026
Doom9500: PlayStation Doom's sounds and music on a Nokia 9500 Communicator
The best way to play Doom is the PlayStation version. I will not be taking objections. Those long, dark, reverberating sound effects and Aubrey Hodges' horrible, wonderful ambient music turn a cheerful 1993 shooter into something that makes you check behind you.
The Nokia 9500 Communicator already had a Doom. C2Doom is closed source and never ran that nicely for me, so nothing could be done about it. So one Sunday in October I asked Claude a question: do you want to make the fastest Doom on the 9500, with custom sound and music WAD support, so that I can play it with the PSX audio? "In or out?"
Claude was in. The result is Doom9500: PrBoom 2.2.6 on the 640×200 screen, drawing straight into the framebuffer, with a software mixer and MP3 music decoded on the phone while the game runs. As with NES9500 and Quake9500, the code was written by Claude (Anthropic's AI). I built it on my Windows 2000 VM, ran it on the phone and complained. The very first build that linked played with working sound effects, and by the end of that same day it was playing the whole PlayStation soundtrack. My exact words in the bug report were "Doesn't seem to have any issues!!! No sluggishness whatsoever."
This post is about how that was possible in a day. Spoiler: it wasn't really a day. It was a day plus a month of earlier suffering on a different phone.
The month before
Doom9500 is a fork of Doomunicator, my PrBoom port for the Nokia 9210. That one took a month of real-hardware debugging, and most of it carried straight over:
- The renderer draws a native 640×200 picture, not a doubled 320×200.
- ARM assembly for the wall column and floor span loops, and for every
FixedMul,FixedDivandSlopeDivin the game. They give bit-for-bit the same results as the C versions, or the title demos would go out of sync, which makes the demos a free test suite. - Auto detail drops to half the columns when the average frame goes over 120 ms and comes back under 55 ms. Z cycles High, Low and Auto.
- A full-screen 3D view with a heads-up overlay, because a status bar on a 200-row screen is a luxury.
High detail on top, low detail below, both zoomed 2×. Low renders half the columns and doubles them.
The 9210 needed all of that. In the first log from a real phone, a level ran at about 9 fps with a 1.7 MB memory zone. Its SDK compiled everything at -O0, so the hot loops had to be written by hand. Near the end, the 9210 got about 8–9 fps in a big hall on high detail and 15 or more on low.
When the 9210 started shutting itself off at random and missed one of my alarms, I moved to the 9500. Many 9210 apps run on it untouched. Doomunicator isn't one of them: it starts and draws a few pixels at the top of the screen.
Throwing out SDL
The obvious fix was to find out why the old driver was confused and patch it. We didn't. Doomunicator got its screen, keys, timer and sound from a static SDL library, built for a different SDK with 9210 assumptions in it. For the fastest possible Doom, the right number of layers between the renderer and the screen is zero. So SDL went, and two small files came in:
| File | Lines | What it does |
|---|---|---|
epocsys.cpp | 626 | Window group, framebuffer, blit loops, keys, clock |
epocaudio.cpp | 343 | Audio thread feeding CMdaAudioOutputStream |
mp3music.c | 225 | Music: libmad, resampling, mixing |
i_sound.c | 571 | PrBoom's mixer, rewritten for a real audio thread |
i_video.c | 255 | PrBoom's video interface, now a thin wrapper |
If you've read the NES9500 and Quake9500 posts, you've met these files. This is where they started.
The new layer doesn't assume anything about the screen. It asks the HAL for the memory address, colour depth, offset to the first pixel and line pitch. The 9500 answers like this:
HAL display: mode 0, 640x200, 16 bpp HAL display: memory 0x59912000, first pixel +32, line 1280 bytes
The renderer still draws 8-bit pixels, so each one goes through a 256-entry table on its way to the screen. That table is the only part that knows about colour formats:
if (gBpp == 16)
gPalette[i] = TUint16(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
else
gPalette[i] = TUint16(((r & 0xf0) << 4) | (g & 0xf0) | (b >> 4));
Doomunicator's ARM blit loops came along unchanged, because they copy 16-bit table entries without ever looking at them. They served 12-bit colour on the 9210 and now serve RGB565 on the 9500.
There's also a free speed-up in the toolchain: the S80 v2.0 SDK builds release code at -O, where the 9210's SDK used -O0. All of the game logic and every line of C that nobody ever bothered to hand-optimise now goes through the optimiser, without anyone touching it.
The menu is PrBoom's, drawn on the 640×200 screen. The rocker's middle press is Enter here, more on that below.
Three builds to first light
For the record, here's every error between the fork and the phone:
'gOpen' undeclared. Claude moved the window objects into a struct, because nobody's sure whether an EKA1 EXE runs global constructors, and deleted one line too many.conflicting types for 'TInt const w'. The blit had a window reference calledwand a row width calledw. Same refactoring, same Sunday.undefined reference to __crt0.ECRT0.LIBneeds a function fromESTLIB.LIB, and the linker had already gone past that library. It'sSTATICLIBRARYnow, which links first. Doomunicator never hit this because SDL brought its own startup code.
The fourth attempt linked, and I put it on the phone. My report back was "Claude. The game works AMAZINGLY. Sounds work awesomely!"
Doom's 320×200 title art across the whole Communicator screen. It has never looked this wide.
From one voice to a real mixer
Sound on the 9210 was a war. Its ROM has no streaming audio DLL at all. All you get is a player that plays a file, and only one at a time. So each Doom effect became a tiny WAV in memory with its own player object. Creating one takes 0.3 to 1.3 seconds, which gave me sound with a one to two second lag at first. Players were then cached per effect and preloaded. The chaingun needed its own hack: restarting a player costs about 80 ms, the gun fires every 114 ms, and that left about 25 ms of each shot audible. So we mixed eight shots into a seamless pre-rendered rattle and looped it. Music was tried too, and the 9210's media server turned out to have no MIDI codec, so that version stayed silent.
The 9500 has CMdaAudioOutputStream, so all of that could be deleted. PrBoom has always had a software mixer, and it only needs somewhere to send its output: 22050 Hz stereo, 8 channels by default, every effect at once. No lag per effect, and no chaingun hack.
The hard lessons had already been paid for, by Rayman. Getting that game's sound working on the 9500 taught us two things that went straight into epocaudio.cpp:
- The stream needs an active scheduler and a cleanup stack, and Doom's main loop has neither. So it runs in a thread of its own.
MaoscBufferCopiedlies. On the 9500 it fires when the framework has copied a buffer, not when it has been heard. Feed the stream every time it fires, and you pile up latency. So the audio thread works out what has been played from the clock, and only mixes more while it's less than three mix calls ahead:
const TInt64 us = now.MicroSecondsFrom(iClockStart).Int64(); const TInt64 heard = us * TInt64(iShared.iRate) / TInt64(1000000); const TInt played = iClockFrames + I64INT(heard); return played < iQueued ? played : iQueued;
Each mix call is 512 samples, about 23 ms, so that's roughly 70 ms in the queue. A CPeriodic asking for 20 ms really ticks about every 31 ms on this phone, so one tick may mix more than one chunk.
Moving to a real audio thread also exposed a bug that had been in the design for years. PrBoom's mixer releases a sound's WAD lump when the sound ends, and it did that from inside the mix callback. That means calling into Doom's zone allocator from the audio thread, while the game thread might be in the middle of allocating from it. That's the kind of bug that crashes once a week. Now a finished channel only clears its data pointer, and the game thread releases the lump the next time it looks at that channel.
psxsound.wad: no code required
I had prepared myself for a format battle, so here's the entire engineering effort for the PSX sound effects:
-file psxsound.wad
All 107 effects are standard Doom sound lumps at 11025 Hz with the standard DS* names. PrBoom loads the WAD and the new sounds replace the old ones. The mixer steps through each sample at its own rate, so the pack would be fine at any other rate too.
The shotgun, drawn from the actual WADs at the same time scale. Grey: PC Doom, 0.86 seconds. Red: PSX, 2.8 seconds, nearly all of it reverb. This is what you're paying for, and it's why you want more than one voice: on the 9210 each new sound would have cut that tail off.
psxmusic.wad: 192 minutes of MP3
The music is another matter. Opening the WAD gave me this:
PSXMUSIC.WAD PWAD 67 lumps D_E1M1 1963760 ff f3 48 64 ... D_E1M2 1198546 ff f3 48 64 ... ... D_RUNNIN 1963760 ff f3 48 64 ...
ff f3 is an MPEG audio frame. These are MP3s stored in Doom's music lumps: mostly MPEG-2 at 16 kHz, stereo, 32 kbps, plus a few at 22 and 44.1 kHz. The longest, E1M4, runs for over nine minutes. There are 36 different tracks and 192 minutes in total, and all of the Doom 2 names point at the same data as the Doom 1 names, which is why the directory adds up to 94 MB and the file is only 49 MB.
That left a real decision, and Claude left it to me:
| Option | On the card | The catch |
|---|---|---|
| Convert on the PC to IMA ADPCM, stereo | 184 MB | Almost free to decode, but needs a converter step and a big card |
| Same, mono | 92 MB | Loses the stereo of the ambient tracks |
| Decode the MP3 on the phone | 49 MB | Costs CPU in a project whose whole point is speed |
Claude recommended ADPCM, since speed was the goal. I picked MP3 anyway, because it means that a music WAD just works as it is, with no conversion step. A 150 MHz ARM9 decoding MP3 on top of Doom sounded greedy. It turned out not to be.
The decoder is libmad 0.15.1b by Underbit: fixed-point, which you need on a CPU with no FPU, and GPL like PrBoom. Its FPM_ARM mode uses the ARM's smull and smlal, which the 9500's ARM925T has. Using it took three small adjustments:
mad.has shipped is generated for MSVC and hard-codesFPM_INTEL. It now picks by platform, and libmad gets its ownconfig.h.- libmad's
version.cwould compile to the sameVERSION.oas PrBoom'sversion.c. Nothing uses it, so it's gone. - The Layer III decoder
mallocs two buffers on first use, from whichever thread is calling. Our audio thread has its own small heap, separate from the game's, and I'd rather not have a decoder allocating there. If those pointers are already set, it never allocates, somp3music.cowns the buffers and sets them itself. This is why it never callsmad_stream_finish.
Doom's own music code loads the whole lump into the zone and keeps it locked while it plays, so the MP3 is simply in memory, up to 2.2 MB per track. The zone went from the 9210's 2.5 MB to 8 MB, which fits it easily. The cost is a little extra time when a level loads. In exchange, the audio thread never has to touch a file.
Decoding happens inside the mix call, a frame at a time: music first, then the effects added on top. PSX tracks come out at 16 kHz and the mixer runs at 22050 Hz, so there's a linear resampler. It keeps the last sample of each decoded frame at index 0 of the buffer, so it can interpolate straight across frame boundaries:
while (idx >= mp3->n) {
if (mp3->n) {
/* keep the last sample for interpolating into the next frame */
buf[0] = buf[2 * mp3->n];
buf[1] = buf[2 * mp3->n + 1];
mp3->pos -= mp3->n << 16;
}
if (!DecodeFrame(outrate))
return;
idx = mp3->pos >> 16;
}
Full music volume is 3/4 of full scale, which leaves room for the effects. The audio thread's stack went up to 32 KB, since the Layer III decoder keeps about 5 KB of arrays on the stack.
None of this could be tested on the PC at the time, as I had no compiler there yet. So it went onto the phone untested. It worked on the first try, and that's when I reported the lack of sluggishness. Doom's original MUS music isn't played at all, because there's no MIDI synth. To me that isn't a loss. You're here for the PlayStation soundtrack.
The barrels are too fat
The 9500's screen has the same shape as the 9210's, and I'd fought this one already. PrBoom's vertical projection assumes a 4:3 monitor. At 640×200 on a screen with square pixels, that makes the 3D view twice as wide as it should be. Barrels are fat and imps are wrestlers. It's also how every pixel-doubled port on this screen looks, and after a while, you stop noticing.
Top: wide, the default. Bottom: true proportions, on J. Look at the fireball. It's the same 90° across, but you see far less above and below.
The fix is a single line that makes the vertical scale equal the horizontal one. Wide stayed the default, since true proportions on this screen only show about 35° up and down. The same mismatch also explained a stranger bug, where a dead marine vanished as you walked up to it. PrBoom's sprite height clip used the horizontal scale for a vertical test, which never matters on a 4:3 monitor. It uses the vertical scale now.
The rocker, and Chr
Then I actually played it, and asked for two things. The 9500's rocker did nothing, and I wanted Chr to toggle strafing.
The rocker was already measured, for Rayman. It sends the normal arrow key codes, which is why other apps work with it, but its own scan codes: up 0xac, down 0xad, left 0xaa, right 0xab, middle 0xae. Doom needs press and release events, and those come with scan codes. Five lines in a switch, and it worked.
The middle press fired the gun, which was right until I opened the menu and it fired the gun there too. epocsys.cpp can't know whether a menu is open, so now it reports a special key and i_video.c decides at the moment of the press. What the press sent is remembered, so that the release always matches it, even if a menu opens while you hold the button:
if (key == EPOC_KEY_SELECT) {
/* Enter while a menu is up, fire otherwise; the release matches the press */
if (down)
select_sent = menuactive ? KEYD_ENTER : key_fire;
key = select_sent;
}
Chr toggling strafe is one of those small things that changes how the game feels on this keyboard, because holding Alt with one finger while steering is no fun. Each tap sends Doom a press or a release of its strafe key. The catch is that Chr + Q, W, E and so on are how you get F1 to F12 on this keyboard, for saving and loading. So if another key goes down while Chr is held, the release of Chr flips strafe back, as if nothing had happened.
Finally, logging got turned off. Every line went through fopen, an append and fclose, all during startup. It's behind a DOOM_LOG switch now, except that a fatal error still writes its message to C:\doomlog.txt. Yes, Quake9500 went on to learn this exact lesson the hard way. The event polling bug from the NES9500 post was in here too, and it got the same one-line fix.
The launcher, and some surgery on the logo
A plain .exe can't sit on the Desk, so the 9210 launcher got ported: a tiny app that starts doom9500.exe and exits to give back its RAM. Its Args button edits the game's options, so -file psxsound.wad psxmusic.wad is typed once, on the phone, and saved to doomargs.txt. The port also fixed a bug from the 9210 version: _LIT(KArgsFileC, "C:\doomargs.txt"). Spot the single backslash.
The icon, its mask and the result on a blue Desk, zoomed 3×. The artwork came as two versions, one on white and one on black, and neither was a mask. Any pixel that differs between them must be background, so a short Python script gets the mask exactly right.
The launcher's background said "CommDoom", the 9210 port's name. I asked for "Doom9500" in the same letters, which raises the question of where you get digits in that font. It's Doom's own red menu lettering at 2×, and the menu never needed digits. But "Doom" was already there, as the right half of "CommDoom", and the intermission screen's numbers (WINUM0–9 in the WAD) have the same red shading and dark outline. So make_title.py cuts "Doom" out of the old title and adds 9, 5, 0 and 0 from the game's own graphics at 2×, on the same baseline.
How these screenshots were made
Same trick as in the Quake9500 post. None of the game pictures here were taken on the phone. They come from the phone's code: the same C files compiled for a PC with a stand-in for epocsys.cpp and epocaudio.cpp, with a script that presses keys at given frames and writes frames to disk on a virtual clock.
One new wrinkle: GCC 2.9 accepts static int basetic; after extern int basetic;, and a modern GCC refuses to compile it. Removing static isn't quite right either, because another file has its own basetic. So the build script compiles a copy of the source, and for each error it removes that static and adds #define basetic d_main_basetic at the top of the file, which keeps it private to that file. It ran first try after that, and played id's demos correctly.
What's missing
- A number. I haven't run a timedemo on the 9500 yet, because it has simply felt fast.
- More speed. libmad's ARM assembly for its slowest step (
imdct_l_arm.S) isn't built yet. I also haven't triedo2.bat, the script that rebuilds the hot files at-O2, on this SDK. - The BOOM translucency map is still off from the 9210 days, when 64 KB and a slow startup mattered. On the 9500 it probably shouldn't be.
The controls: arrows or the rocker move and turn, Ctrl or the rocker's middle fires, Space opens doors, Shift runs, Alt strafes while held and Chr toggles strafing. Z cycles the detail, J toggles the proportions, and Chr with Q W E R T Y U I A S D F gives F1 to F12.
Install the SIS, and it puts Doom9500 on the Desk and prboom.wad in \Doom\. Copy your doom.wad, doom2.wad or the shareware doom1.wad to D:\Doom\ on the memory card, or to C:\Doom\. For the PlayStation experience, add psxsound.wad and psxmusic.wad and press Args in the launcher. I can't give those WADs to you, but they aren't hard to find. Any other music pack with MP3s in its D_* lumps should work the same way. Doom9500 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, which showed it could be done on a Communicator back in 2001, to Underbit for libmad, and to Aubrey Hodges for the music that started this whole thing.
E1M1 was never meant to sound like this. Turn the lights off, hold the 9500 close, and listen to that shotgun ring out for three whole seconds on a phone from 2004.
I'll put the game pack here when it's finished.
lauantai 27. joulukuuta 2008
id Tech 5 / Doom 4 ported to Symbian OS
How long will it take until this news is reported all over the net? Think about it, Quake I, II and III have already been ported. We will just see when Doom 3 and Quake 4 get their sources released, and finally Doom 4. Symbian OS is growing and expanding its capabilities all the time, and in the future it supports quad core (or even more) processor composition, so it's very likely that these games would be playable in the future devices.
Interesting to see what the future brings to us, eh?
torstai 15. marraskuuta 2007
Nokia N800
Nokia N800 kiinnostaa hyvien videonkatselu-, internet- ja pelimahdollisuuksiensa puolesta. Näyttö on 800 x 480 pikseliä, prosessorin taajuus saadaan uuden Maemo OS2008:n avulla kellotettua 400 MHz:iin, ja Youtuben videotkin toimii tässä uudessa käyttöjärjestelmässä lukemani perusteella niin kuin sen pitääkin eli pehmeästi. Doomia ja Quakea pystyy pelaamaan siististi ja kaikenlaista hyötyohjelmaakin löytyy tälle koneelle. Ja miksei sitä äkkiä vääntäisi itsekin jonkinlaista ohjelmaa äkkiä tolle, kun tarve tulee?
Joka tapauksessa erittäin siisti laite on kyseessä ja täytyy tarkkaan miettiä, josko tuon sitten ostaisi, kun on rahaa (vakiolauseeni, (c) Sami Vuori 2007-2008).
-----
Ajattelin tätä ennen ostaa ZTC ZT8380 -mallia olevan puhelimen, joka on erittäin hienon ja teknisen näköinen ja suhteellisen kehittynyt kiinalaiseksi "halpapuhelinmalliksi". Alle 180 €:lla saisin tilattua sen tänne Suomeen, jos tulliinjäämisriskiä ei oteta huomioon (silloinhan tulee lisäksi ALV 22 % + tullivero 3,5 % paketin arvosta), mutta silti aika huono malli: Kysyin Sourcinggaten asiakaspalvelulta tuon kännykän GPS:stä ja sieltä ilmoitettiin että valitettavasti GPS on hyödytön täällä Suomessa, koska puhelimesta ei löydy karttaa tänne.
Katselin myös Nokia E90 -kopiota, mutta se ei kyllä kiinnosta paljoa, kun molemmat näytöt ovat samankokoiset (320 x 240 pikseliä), ja lisäohjelmiakaan ei pysty oletettavasti asentamaan tuohon kännykkään.
Heh, my decisions wobble from one side to another like flagpoles in an autumn storm. At first I thought I'd buy Nokia N93, then E90 and now I have come to a decision, that I wouldn't buy a Symbian based phone, but transferred into Linux devices. So Nokia N800 and in addition to that I'd use for phone and SMS purposes Nokia 5110 or 5510, which I'm an owner of both. I think Nokia N800's technical specifications and price look so good that it would almost be madness to buy instead a Nokia E90, which could even have the screen scratching and smudging problem. It wouldn't be so nice in a phone, which has an SRP of about a thousand euros.
Nokia N800 interests me because of its good video viewing, internet and gaming possibilities. The screen is of 800 x 480 pixels resolution, the processor's frequency can be clocked up to 400 MHz with the new Maemo OS2008, and from what I've read, Youtube's videos work as they should, cleanly that is. Doom and Quake can be played decently and every kind of utility programs can be found for this device. And why not quickly code myself some kind of program for this apparatus, when the need hits?
In every way it's a very neat device and I have to think carefully, if I'd buy it when I have enough money (the basic phrase, (c) Sami Vuori 2007-2008).
-----
Before this I wondered if I should buy ZTC ZT8380 branded phone, which is looks very cool and technical and is relatively developed for being a "Chinese cheapie." For under 180 € I could order it right here to Finland, if the risk of being caught in the customs isn't taken into observation (because then comes the 22 % VAT and customs taxes of 3,5 % of the overall product's price), but the device is still somewhat bad: I asked about the GPS property from Sourcinggate's customer service and they said that unfortunately the GPS is useless here in Finland because the phone doesn't have maps for this country.
I also looked at the Nokia E90 rip off, but it doesn't interest me much, when both screens are equally sized (320 x 240 pixels), and extra applications can't assumably be installed onto the phone.












