View Full Version : Freepascal on the Original XBox

20-09-2007, 11:24 PM
Hi, I've been doing some work at porting fpc so it can make programs that run on the original xbox. Finally I've had some success in compiling a program with fpc that can be converted to an xbe which loads and runs on the xbox.

It doesn't do anything glamorous, it just draws to the screen and then has the xbox reboot. I've currently made no code to access the controllers or sound card, network etc. unfortunatly programs which link to OpenXDK don't run :( However it is possible to import all the xbox kernel exports so at least everything that is done in openxdk can be done with fpc.


20-09-2007, 11:32 PM
Excellent work Andrew!

21-09-2007, 01:46 AM
Exelent 1? post :shock:

21-09-2007, 08:59 AM
Sounds very cool! It must have been a lot of hard work to get anything working at all so I'm impressed.
I still use my XBox sometimes as a mediaserver.

21-09-2007, 09:34 AM
This is excellent news!
If this could be expanded, FreePascal would startto rival lots of commercial compilers for console development.

21-09-2007, 09:26 PM
Hi Andrew,
Can you post details about how you got to the point you are at right now and what errors you get when linking to the XDK. Maybe Steve who works for Crome Studios and has written commercial XBox games could provide some insight.

21-09-2007, 09:37 PM
Wow, thats really quite excellent!

Was there any needed additions to the x86 instruction set for Coppermine or was it all pretty much just the rtl that needed the work?

Also, will this work get sent in to the FPC guys to add to the amassing amount of platforms that this bad-boy is packing in? :D

I think this might call for a Platform Support Guide update soon. ;)

21-09-2007, 09:41 PM
FPC :shock:
we are able to use pascal power on many consoles / OS :twisted:

21-09-2007, 10:07 PM

I know almost nothing about x86 instructions or any other platform instructions. The xbox has almost a regular PIII processor; it just has half the amount cache as retail processors.

I will send this to the fpc guys and hope they include it.

I just copied the game boy rtl and stripped out the gameboy stuff. The rtl doesn't currently have any file io or support from the OS for allocationg memory etc, it's a barebones RTL.


I made a barebones RTL that doesn't link to any libs since there are no libs on the xbox and all programs are statically linked. Then I modified fpcmake to generate Makefiles that support xbox and ran fpcmake on the fpc source tree. then I compiled fpc with this:

make PP=ppc386 CROSSOPT="-Xe -XPi386-pc-xbox-" CPU_TARGET=i386 OS_TARGET=xbox all

(the -Xe shouldn't be needed but for now it's needed just to build the crosscompiler.)

The rtl builds fine and the fcl but it fails at freevision but at this point I have the rtl and fcl and a crosscompiler. Then I made a program which just writes to the video framebuffer memory and then calls a xbox kernel function imported by ordinal.

It compiles like so:

ppcross386 -Txbox -WB00010000 program.pas

$10000 is the base address at which xbe's are loaded.

At this point the program.exe is converted with cxbe to program.xbe and the file can be copied to the xbox and run.

I don't link in any way to the official XDK or to OpenXDK. I've tried to link to OpenXDK but for some reason it didn't work.

When I link to OpenXDK it compiles fine and the Import address table is filled correctly but when I run the programon the xbox it freezes afaict. I've had no success using the gnu linker ld, but using the internal linker from fpc for win32 I'm able to compile working programs. It's impossible for me to see what is going on in the xbox with no terminal or debugger.

Currently I'm converting the OpenXDK header for the xboxkrnl functions to pascal. This is giong well so far. Now I can Eject the dvd tray :)



22-09-2007, 04:21 AM
Ah, sounds to me like you sort of made a start of the XBox platform like how I started with the GBA one. Well... I didn't get as far with it as Legolas took it, or you with the XBox (if your actually able to run programs at some capacity) but I like you had no idea how to 'add' instructions or any of that to the FPC compiler.

Luckily though, I think that with some of the platform support documentation that the FPC guys have put up on their site, it has really helped to make these sort of ports accessible for us as the end users to do.

What are you using to send over your executables to the physical machine? Is yours modded or do you have some equipment?

btw, are you the same 'drewski' from IRC? I think we may have even had a chat on there once or twice. :)

22-09-2007, 10:52 AM
Stated that the xbox is 99% like a pc (hard drive, cd drive, video card, directx, ...). I think that you could try to start your porting from the win32 rtl. Maybe you will need some fine tuning on prt0 and linker script, but you don't need to strip out anything from the win32 rtl :)

22-09-2007, 04:35 PM
Just for everyone's info, the Xbox 360 uses the Xenon processor with is essentially a triple core PowerPC processor. There seems to be some high level info about it over @ http://arstechnica.com/articles/paedia/cpu/xbox360-2.ars/1

22-09-2007, 09:10 PM
It would be interesting for FPC to have a parallel option to 'compete' with the Chrome/XNA framework route.

22-09-2007, 09:33 PM
Okay, I've been working on importing kernel functions and making a unit xboxutils which currently just adds methods to eject and close the DVD tray. In so doing I am having the same problem of the program not running on the xbox anymore, just like when linking against openxdk. I suspect that the memory locations of the compiled procedures is changed from what is compiled into the code.

I made a simple program which changes the screen color after each procedure is called and have figured out that using units that are compiled when I compile my program works but using precompiled units like in ones in the rtl/fcl does not always work. :(


22-09-2007, 09:34 PM
Ah... here is a tid-bit that I just found online. http://channel9.msdn.com/ShowPost.aspx?PostID=138002

Perhaps a pat of your problem is the XBox rejecting the signage of your program?

22-09-2007, 09:54 PM
I made a simple program which changes the screen color after each procedure is called and have figured out that using units that are compiled when I compile my program works but using precompiled units like in ones in the rtl/fcl does not always work. :(

Hi Andrew,
I'm confused. By pre-compiled do you mean .ppu units or something else?

22-09-2007, 10:59 PM

my xbox is softmodded so it can run unsigned code.

For instance the entrypoint of the xbe is _WinMainCRTStartup. This function is implemented in the unit sysinitunit, a precompiled unit in the rtl, all it does is set some booleans and then call PASCAL_MAIN which is the begin end. part of a program unit.

If I declare this function in my program.pas it seems to work untill it tries to call a method from a unit in the rtl or fcl.

From my preliminary dissecting of the xbe file the address of the entry point is correct even when the entrypoint is in the sysinitunit unit. perhaps it is having trouble resolving PASCAL_MAIN.


I mean the units that are compiled just after the compiler is built like system, sysutils, classes etc, all the units that are part of the rtl and fcl.

22-09-2007, 11:07 PM
Yes I just added some code so the screen is blanked in the entry point in sysinitunit and the screen is blanked but I guess it's using the wrong address for PASCAL_MAIN

30-09-2007, 04:15 PM
Okay, all I had to do was implement a memorymanager for fpc. The sysutils unit was creating some objects which requires the fpc memory functions to be implemented. It only really needed mapping of the xbox memory functions to the pascal functions we know and love like GetMem FreeMem etc.

so now my program runs and builds including the sysutils unit. Next I'll see if linking to OpenXDK is working :)


30-09-2007, 04:54 PM
Way to go Andrew! I look forward to the OpenXDK report.

30-09-2007, 06:37 PM
Still no improvement linking to openxdk

13-10-2007, 09:35 PM
I wonder how much use this link would be?


Dom passed it to me not long ago. This person is converting a C++ made XBox emulator to Delphi. It seems to be well past half done and the last update was just this last July.

25-02-2009, 06:54 PM
What did you use for fprting your application to XboX or Xbox360. I mean something besides XNA 2.0. And with pascal. Where I get XNA for freePascal or Delphi

25-02-2009, 08:57 PM
For xna you can use delphi prism. The command line edition is a free download on the codegear/embradarco site. Using google you should also be able to find a tutorial on using delphi with xna. Free pascal would not be useable as xna is .net

26-02-2009, 06:27 AM
Currently the only way to use Pascal on Xbox 360 is via Oxygene or Delphi Prism as they are the same compiler. I have tested it and it works with XNA.