Xbox 360/Xbox Development on the Mac

This article describes the process to configure an iBook to compile C code written with OpenXDK, and make Xbox native executables. At the time of writing, the author had successfully compiled a Windows executable but had not been able to convert it to an Xbox executable.

Overview edit

All of these steps are fairly straight forward, although there are some tricks that the novice needs to know to bypass hours of "googling". The process taken is similar to installing OpenXDK on Linux, but differs because in this example we're using a PowerPC processor. This means that we first have to build a cross compiler. The assumption is that you know how to access the shell.

DarwinPorts edit

DarwinPorts is a way to track and install open source programs to your system easily. It is designed specifically for Darwin (as the name suggests), and using this you can download MingGW. The current version of DarwinPorts is 1.2, and it comes in a handy installer package. Once it's installed, run the following command to update the internal list of available ports:

$ sudo port -d selfupdate

MinGW edit

The MingGW compilers and Windows API libraries let you write and compile programs for execution on the i386 system. Although you can download a copy of everything you need from the website, using DarwinPorts to download the right files for you is a better option. To download the tools needed, run the command:

$ sudo port install i386-mingw32-gcc

This will download, configure and install the gcc cross-compiler and tools to your system. Note: this step will take a while.

Compile Errors edit

As of this writing, there is a compile error when the installer executes make for the binutils package. The exact error is listed below:

$.../work/binutils-2.15.91-20040904-1/gas/config/tc-i386.h:457: error: array type has incomplete element type

To get around this problem, change the compiler to gcc-3.3 when preparing the build.

$ sudo gcc_select 3.3

Then, once the binutils package has compiled successfully, halt the install (Ctrl+C) (the install will fail anyway) and change the compiler back to gcc-4.0. Then the install should complete successfully.

Testing edit

This is an option step. I just tested that the setup worked, by writing a Hello World! program, and running it on my Windows box. The contents of hello.c are shown below:

#include <stdio.h>

int main(int argc, char **argv)
 {
 	printf ("Hello\n");
 	return 0;
 }

Then to compile, it's just like normal gcc/++:

$ i386-mingw32-gcc -o hello.exe hello.c

This produces a windows executable hello.exe that can be run natively in Windows. Note that this only tests the cross compiler setup, and not OpenXDK.

OpenXDK edit

OpenXDK is a free kit for developing applications that will run on the Xbox. It contains a complete libc replacement, uses SDL for multimedia (sound and networking are not currently supported) and compiles with gcc.

You can download the latest version from SourceForge. Make sure to download the binary file OpenXDK_#_bin.zip (where # is the version). Note: although it says it's for the i386 platform, that's our target system, and OpenXDK will NOT compile (even with i386-mingw32-gcc) on the Mac.

Cxbe edit

Cxbe comes with OpenXDK, and is located in the bin directory. It is responsible for converting the Windows executable into an Xbox executable. You won't be able to use the one provided, as it is for Windows.

Unfortunately, at the time of writing the Cxbe source in the OpenXDK_src package is from an older version than the compiled version in the OpenXDK_bin package. Until a workaround surfaces, we will have to send the half completed executable to a Windows box and run Cxbe there.

Compiling edit

To compile C code written for the xBox, you need a lengthy flag list for the compiler. The following was adapted from the OpenXDK Website. This assumes that you have a working version of cxbe on your system.

# installed OpenXDK path
XDK = /usr/local/openXDK
# cross-compiler
CC = i386-mingw32-gcc
# cxbe path (for post-processing)
CXBE = $(XDK)/bin/cxbe
SDLFLAGS = -DENABLE_XBOX -DDISABLE_CDROM
CC_FLAGSA = -g -std=gnu99 -ffreestanding -nostdlib -fno-builtin
CC_FLAGSB = -fno-exceptions -mno-cygwin -march=i386 $(SDLFLAGS)
INCLUDE = -I$(XDK)/i386-pc-xbox/include -I$(XDK)/include -I$(XDK)/include/SDL
CLINK = -nostdlib
ALIGN = -Wl,--file-alignment,0x20 -Wl,--section-alignment,0x20
SHARED = -shared
ENTRYPOINT = -Wl,--entry,_WinMainCRTStartup
STRIP = -Wl,--strip-all
LD_FLAGS = $(CLINK) $(ALIGN) $(SHARED) $(ENTRYPOINT) $(STRIP)
LD_DIRS = -L$(XDK)/i386-pc-xbox/lib -L$(XDK)/lib
LD_LIBS = $(LD_DIRS) -lSDL -lopenXDK -lhal -lc -lhal -lc -lusb -lxboxkrnl
all: default.exe
*.o: *.c
$(CC) $(CC_FLAGSA) $(CC_FLAGSB) $(INCLUDE) $<
default.exe: *.o
$(CC) -c $< -o $@ $(LD_LIBS) $(LD_FLAGS)
$(CXBE) -TITLE:"$@" -DUMPINFO:"default.cxbe" -OUT:"default.xbe" $@ >/dev/null
clean:
rm -f *.o *.xbe *.cxbe *.exe

Conclusion edit

While there is limited support for Xbox development on the Mac, because of the use of Linux to develop legal Xbox executables and the fact that Mac OS X is built on a flavor of Unix, it is possible to piggy-back Linux's support sources and (with slight manipulation) produce a viable solution to Mac Xbox Development.

References edit

External Links edit