Posts Tagged ‘ PowerPC

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.

return top