If you’ve read my previous console articles, specifically this one and this one where I attempt to write something resembling a game for the original Sony Playstation, you’ll probably be aware that I was struggling with a lack of proper documentation for the PSXSDK. Evidently I’m a sucker for punishment, because here goes with some PS2 stuff, and strap yourself in – the PS1 SDK documentation might have been bare, but it’s a bookshelf-bending, tree-slaughtering, mega-tome compared to that which comes with this PS2 SDK.

Let me say before we continue that, as ever, I really do appreciate the work that goes in to creating these open source SDKs, without which it would be impossible to legally write console software, but for a beginner like me it’s a slog to get anything going out of the gate. In fairness, there’s example code, but seemingly patched together from all sorts of levels of completeness of this and seemingly other versions of SDKs (much like the SDK itself). However, if you’re playing along at home, this is the SDK I’m using. It’s Lazy Bastard’s GSHI_PS2SDK 5.0, which as I understand it is an almost all-inclusive package containing a Windows buildchain and the SDK which is maintained here.

Installing the SDK:

As far as I’m aware, and I’ll explain why in a moment, all you should have to do is extract the GSHI_PS2SDK archive to a folder of your choice. I say “as far as I’m aware” because as always with things like this there’s a certain amount of tweaking to be done before everything works, and this is no exception. Here’s a couple of things you’ll want to fix before attempting to use this SDK:

First, and seemingly the most critical if you want anything to compile, have a flick through the files you just extracted, there’s an msys folder, in here browse to 1.0 and then to etc. In here you’ll find a file called profile. Open it, and add the following line to the bottom:

It seems that the buildchain can’t find certain essential files without this line, without it I can’t compile even simple code, so I’m considering this critical.

Whilst you’re in profile, you might also want to add this line, right at the last line is fine:

By default, the command shell will dump you in your Windows user folder, which isn’t necessarily ideal for this purpose, so the above line will ensure that you’re in the right place whenever you launch it. Don’t forget to change the drive letter and path, as an example, cd “/c/sdk/ps2/msys/1.0/” would equate to the Windows path C:\sdk\ps2\msys\1.0\. You can even add a project folder in there if you like, and tack it on the end, which is what I did, so my path would be “/c/sdk/ps2/msys/1.0/projects/”.

One final thing, I can’t actually remember what prompted me to hit the problem, but there seems to be some kind of bug in the make.exe version provided in the SDK, so grab the newest version from here (requires 7-zip or some other tool capable of extracting lzma files, then the tar file inside it) or this nice easy zipped version which will open in WinRAR or WinZIP, extract, then open the bin folder within (for the tar.lzma version) and copy the make.exe file to msys\1.0\bin\make.exe, overwriting the old version.

Thus concludes the installation, hopefully, if I’ve not forgotten anything important.

Using The SDK:

Now, if you’re familiar with using a GNU GCC buildchain then you can skip this section. If not, here’s a few basics to get you rolling. Your project will typically have at least two files. The first is your C code, which will probably be named something.c, perhaps test.c, mygame.c or helloworld.c. This is the code which makes up your game or program, it contains the functions and references which get turned into something the PS2 can understand and execute. Here’s a hello.c example program taken from the demo code linked above (it’s in the Basic SDK folder, it’s the Hello project, but I’ve tweaked it slightly and added a few comments):

The second file is your makefile. This is the file which tells the buildchain exactly what you want it to do to your code in order to make it into a PS2 program. It will specify things like the output binary, the libraries your program requires, certain flags which alter the way the program is put together and commands to be executed after the program is compiled.

Here’s the makefile for the Hello.c above:

In order to turn this into a functioning program which will run on the PS2, you would save the first chunk of code as a C file, specifically hello.c, and you’d save the second chunk in a file called makefile. You’d then open or switch to your MinGW window (this is what the shortcut you modified in the installation steps above launches), navigate to the folder you put them in using cd, in my case I would save my hello.c and makefile to msys/1.0/projects/hello/ and navigate to it with the following command:

Then enter:

Then, all things being well, you’d receive this output:

It looks like gibberish, but those lines are basically strings of commands which are executed when you use your makefile, resulting in the file hello.elf being created. This is your PS2 program. It’s a lot like a Windows .exe file, it’s a native binary which can be executed, or run, by the PS2 (or in the case of a Windows exe file, by Windows).

If you took this file to a (soft or hard-modded) PS2 and ran it, you’d see this:


…and there’s your very first Playstation 2 homebrew. Incredibly simple, but a good solid step towards being able to write games for a games console. In my next article, I’ll go into more detail about what you can do with it, what I learnt and some caveats and pitfalls to be aware of. Stay tuned!

About The Author

Leave a Reply