Posts Tagged ‘ Doom

Doom in Javascript (I’m jealous)

Yes, someone ported Doom to javascript.  I must say I’m pretty jealous of that since I still haven’t had time to get a real grasp of the original code yet (and I got busy with ioquake3).

Three cheers for this excellent hack.


Edit:  The code to this program is now long gone. My guess is it’s because the author embedded the graphics into the code which are not part of the GPL licence.

More Doom obsession with Ubuntu PowerPC

Continuing with my obsession with Doom – as decribed in my previous post – I tried compiling my modified original source on a PowerPC running both Mac OS X and Ubuntu Linux. Since they both have the X Windows system, it should work. Today’s post will be about Ubuntu.

Relevant libraries

I guess I got ahead of myself last time when I suggested to simply type ‘make’ to compile. In fact, they are a few packages that must be installed on Ubuntu. So install the relevant X developement libraries like so:

sudo apt-get install xlibs-dev x11proto-xext-dev libxext-dev

Compiling linuxdoom will yield a new set of errors that I hadn’t notice the first time around on a Intel x86 PC.


Endianess, for those who might not know, is how computer store numbers in the processor and, corollarily, on other devices in the system. On a big endian system, like a PowerPC, the numbers are stored, byte per byte with the highest values first. On a little endian system, such as the Intel x86 family, it’s stored with the smallest values first. Originally, Doom used a little endian scheme under DOS, so a Linux port that runs on an x86 would have no trouble with it. For big endian, you need to swap the values. Not necessarily all of them but certainly those who affect the devices: video, filesystem, etc. There are many references in linuxdoom to macros called SHORT() or LONG() that wrap certain values for this purpose. So the Doom porters added some extra pre-processor switches where a conversion will happen if you happen to compile on a big endian system. But is this enough … ?

Here’s what you get in m_swap.h:

// Endianess handling.
// WAD files are stored little endian.
#ifdef __BIG_ENDIAN__
short	SwapSHORT(short);
long	SwapLONG(long);
#define SHORT(x)	((short)SwapSHORT((unsigned short) (x)))
#define LONG(x)         ((long)SwapLONG((unsigned long) (x)))
#define SHORT(x)	(x)
#define LONG(x)     (x)

And here’s what you get in m_swap.c:

// Not needed with big endian.
#ifndef __BIG_ENDIAN__

// Swap 16bit, that is, MSB and LSB byte.
unsigned short SwapSHORT(unsigned short x)
    // No masking with 0xFF should be necessary. 
    return (x>>8) | (x<<8);

// Swapping 32bit.
unsigned long SwapLONG( unsigned long x)
	| ((x>>8) & 0xff00)
	| ((x<<8) & 0xff0000)
	| (x<<24);


First, even as #ifdef __BIG_ENDIAN__ in m_swap.h will set prototypes for the swap functions SwapSHORT() and SwapLONG(), it is incompatible with the fact that w_swap.c wraps these functions with #ifndef __BIG_ENDIAN__. We couldn't notice this error under x86 compilation - although the compiler could have warned us that the prototypes were missing - but on a PowerPC, it will fail.

So change the line in m_swap.c from

#ifndef __BIG_ENDIAN__


#ifdef __BIG_ENDIAN__

Next, the values between the prototypes and the definitions are all wrong. In the header file, SwapSHORT() and SwapLONG() both take and return signed values, whereas in the .c file, they're all unsigned. Change the signed ones in m_swap.h like so:

unsigned short   SwapSHORT(unsigned short);
unsigned long    SwapLONG(unsigned long);

These changes should make the linuxdoom code compile (with all its usual sets of warnings).

The sound server

What about the sound server ? It does compile and is set up to its right endianness. But the sound comes out all scratchy. It is possible that the conversion process was not complete. For the moment I have no solution for that. You can still compile the main linuxdoom source without the -DSNDSERV flag in the Makefile.

Final words

So, just like the x86 version on my previous post, start a new X session in 8 bit colors, open a console, set the environment variable for DOOM, make sure your Doom IWAD is present (and the sound server if you like scratchy noises) and voilà.

Next stop: Mac OS X.

Running Doom under Linux

[Edit: 2014-03-05: I’m closing this thread now.  Check out the references to chocolate-doom in the comments below as probably our last resort to actually compile Doom from a reasonably corrected source for our modern times.  Beyond that, I’m pretty much as clueless as you are]

I love Doom. Actually, Doom II was the first PC game I ever got in my hands onto. The game was fast-paced, gritty and scary like hell, even with its 8 bit architecture. The sound was ominous, the levels and monsters were darn frikin’ hard to go against … I totally agree with anyone that would put it onto their top list of games since the beginning of that instrustry we call “gaming”.

This post is about compiling Doom on a modern Linux distro.

The source of the Doom engine (which ran Doom, Doom II, and Ultimate Doom) was released in 1997 as a Linux port that used X with a separate sound server. It is still available here.

I got interested in the source code in 2003 and started taking notes about compilation, PCX and 8bit paletting, and WAD (de)construction. Now, in 2010, I re-read my notes and decided to give it a go again, this time putting those notes public, although there’s nothing really new here for anyone. With so many ports of Doom that have spawned over the years, there are better options today in playing Doom with full screen graphics, perhaps in 3D, and MP3 sound and music instead using 16 bit mono WAVs and on board MIDI.

But I like retro stuff and this is as close as we can get to the original. The SDL version, made by SDL creator Sam Lantinga, is a straightfoward port of the original with sound and can run on 640 x 480 without palletting. It’s a great way to see how SDL works. But before compiling that version, keep reading this post, there is at least one modification you should be aware of.

Fixing errors and compiling

The first thing about Doom, is that its creator, id software, did released the source code but not any of the data files to run it, called IWADs, which contain the images and sounds of the game. You must either have the commercial version of Doom, Doom II or Ultimate Doom, or the shareware version (a copy of the shareware IWAD is available here). Unzip it and put that file somewhere on your system. We’ll need to point to it later on.

Unzipping the file gives you two packages, the source code of DOOM and a separate sound server that Doom will imbed at run time (apparrently, id licenced a copyrighted sound engine at the time, which is why there is no original DOS release: ‘A mistake’ says John Carmack in the README.TXT file.)

Unzip the source code and make the following changes:

In i_video:49, replace

#include <errnos.h>


#include <errno.h>

In i_sound.c:166 and i_video.c:669, delete all declarations of

extern int errno;

and include this file somewhere at the top of i_sound.c:

#include <errno.h>

In s_sound.c:367, replace

#ifndef SNDSRV


#ifndef SNDSERV

In the Makefile, add the -DSNDSERV define for compilation.

Finally, and this affects both the original and SDLDoom, change d_main.c:587 from

doomuwad = malloc(strlen(doomwaddir)+1+8+1);


doomuwad = malloc(strlen(doomwaddir)+1+9+1);

This “off-by-one” error will generate a ASSERT error in malloc.c:3074 once the X display kicks in. The gdb debugger will tell you so, and yet we are very far from any video initialization at this moment. It took me a while to trap this.

Compile by simply calling ‘make’ at the command line. Everything should compile under 30 seconds. Don’t (?) worry about all the warnings you’ll see passing by. They shouldn’t affect the game at this point. Feel free to clean up the code if you like.

Compiling the sound server

Unzip the sound server’s package and change to that directory. Simply call ‘make’ at the command line.

Move the ‘sndserver’ binary located in the ‘linux’ directory to the same directory you put your IWAD, mentionned above.

Switching to 8 bit

Doom runs in 8 bit (256 palettized colors) at a whoppin size of 320 x 200 pixels. It’s better to simply call another X desktop instead of ruining your current setup.

Issue the following on the command line.

sudo startx -- :1 -depth 8 vt8

This starts another desktop at vt8 (i.e. Ctrl-Alt-F8. You can return to your original desktop with Ctrl-Alt-F7 or loggin off from that session). You’ll notice how rough your desktop will look because of the 8 bit palette it’s running on.

Note that you will be running your new desktop with super-user privileges, so be VERY careful.

Open up a console and set an environment variable called DOOMWADDIR like so:

export DOOMWADDIR=<my path>

and replace <my path> with the location of the IWAD and sound server. If you dip into the code, there always a way to set those changes to a permanent location without defining this value or doing it through some parameter.

You can now run the binary located at linux/linuxdoom in the source code directory.

You’ll see your desktop flashing because Doom will set up its palette to it.

Voilà. Enjoy playing Doom on an itsy bitsy scale. 🙂

You can alway resize your desktop to 640 x 480 to see it a little larger. Don’t forget to set it back to its original size. I believe if you don’t, it will screw up your default settings once you run X again from a fresh boot.

If you don’t want to go through all this trouble, make the change I recommend to d_main.c:587 in SDLDoom, compile it and call the -fullscreen parameter to play Doom at a reasonable scale.

return top