xboxscene.org forums

OG Xbox Forums => Software Forums => Emulators => Topic started by: nes6502 on June 22, 2006, 07:36:00 AM

Title: Very Simple Guide To Xbox App/emulator Porting
Post by: nes6502 on June 22, 2006, 07:36:00 AM
The reason I wrote this guide was to explain the process of porting a game or an emulator to the Xbox. You don’t have to be a coding master. All you need is the tools to build an Xbox application, basic knowledge of C (and or C++), and some determination. I am not the authority on the subject, but I have ported an emulator to the Xbox, and I am writing from this experience. This is a VERY high level view. But the framework is here.

Why am I writing this and posting it in the emulators forum? I realize that many emulator users read this forum and might want their favorite application/game/emulator ported to the Xbox. In reality, the only way it may ever get ported is if they do it themselves. I have wanted ZSNES on the Xbox (native port) since I started using the Xbox, and I realised that the only way it was going to happen was if I did it myself. So I did. I had never ported anything to the Xbox (or any console) before and I am not an expert coder. With determination I was able to do it, and i think it turned out well. So if you want your favorite app/emulator/game on the Xbox, instead of waiting for a day that may never come, people might want to try and do it themselves. This is a basic guide for those people that don't know where to begin.

Tools:

1)   XDK
2)   Visual Studio 2003. NET
3)   You do not need a debug XBOX (even though it is helpful). Without one, you will be burning CD’s every time you want to test a change.

Step 1) Decide what you want to port. For this example I will talk about ZSNES. ZSNES is written in C and Assembly. I’m pretty familiar with C and not very familiar with Assembly.

Step 2) Download the source code. It’s easiest if you can compile it on Windows first. After following the instructions, I was able to compile the windows version of ZSNES.

Step 3) Create a new Xbox application workspace in VS 2003. Add all the C/C++ files to the project. If there are assembly files (like in ZSNES), just add the “obj” files for the ASM ones generated from Step 2 to the project.

Step 4) Compile the Xbox project. This is where the fun starts. There will be lots of compile errors because the PC version is likely using code, functions, libraries that are not supported on the Xbox. For example, ZSNES uses DirectDraw code to draw the screen. There is no DirectDraw support on the Xbox, so I had to learn how to do the same thing with Direct3D. Basically: how to set the color of each pixel on the screen. Once I replaced all the DirectDraw code, that entire group of errors went away.

Another example is the input. ZSNES assumes there is a mouse used. I commented out all the code that used a mouse because there isn’t one on the Xbox. Another example is the keyboard. Since there is no Xbox keyboard, I replaced all the keyboard code with Xbox controller code. ZSNES still thinks there is a keyboard attached and checks to see if any buttons are pressed. I just monitor buttons on the Xbox controller, and when one is pressed, I tell ZSNES that one of the keyboard keys was pressed.

Step 5) Compile again. Now continue replacing code that gives errors with code that doesn’t.

Step 6) Repeat Step 5 until all errors are gone. Once all the errors are fixed, VS will generate an “xbe” file that can be run on the Xbox.

A great starting point is the Genadrive source code. It is easy to read and easy to compile. Try compiling it and running it on the Xbox. Then study what it is doing to draw pixels on the screen, read the controller, read files in a directory for the ROM browser, etc.. In fact I used this as my base for ZsnexBox and basically built around it, added to it, etc...This is the only thing I’ve ported to the Xbox and I am not a coding expert. You don’t have to be. If you have a basic understanding of C, the tools needed to compile the application, and the willingness to learn things you need (like basic Direct3D), then there is nothing stopping you from porting anything you want.

This post has been edited by nes6502: Jun 22 2006, 02:43 PM
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: wizzel on June 22, 2006, 05:12:00 PM
...and i thought i was a nOOb.
Now all i know is that i must be a super-duper multi-nOOb.  ph34r.gif

It reminds me of coding my first CGA-emulator for the HGC Graphics Card
on the PC way back in the early 80s.  laugh.gif

Especially the "until all errors are gone"-part.  biggrin.gif

Anyway, nice (interesting) guide, nes!  happy.gif
Keep on rocking!
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: Albino on June 22, 2006, 06:28:00 PM
I've always fancied a go at something and when I get some free time, I may have a crack at mame with a newer core, these old ones and running clrmamepro do my nut in. No doubt I will fail misserbly but I've gotta have something to do instead of my degree when I go to uni in september. I like the "repeat step 5 until all errors are gone" it reminds me of disassembling and recompiling my acpi under linux.
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: nes6502 on June 22, 2006, 06:41:00 PM
Yes. Step 6 is the hard one. In fact I gave up many times when doing ZsnexBox. I was overwhelmed by the code. I thought there was no way I could pull it off. Especially since it's all assembly. But the reality is, I didn't have to change much of anything in the assembly. I just had to replace the video and input code (and change the sound code a bit).

In fact, many of the errors in the "Step 6 Loop" were easy to fix. I just commented the code out. This is whey there is no ZSNES movie support, no ZSNES png support, or jma support.

I havn't figured out how to "fix" those errors yet.

ZSNES was not considered (I don't think) by many as an "easy" port. It was my first port and I pulled it off. So I don't want pople to get bogged down with the complexity of the source material. You won't have to change or even understand 99% of it.

If they can use Direct3D to set a pixel color, play a streaming wav with DirectSound, and have an intro level C or C++ skill level, they can port anything (with enough determination).

This post has been edited by nes6502: Jun 23 2006, 01:47 AM
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: Diontae18 on June 22, 2006, 06:13:00 PM
Man I had those tools on my hdd forever, but only used them for XBMC.
This oughta be linked from VampX's great emu guide, or pinned. This lil' guide will become very useful for me, and I'm sure a lot of others. Thanks nes6502.
 pop.gif
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: XaRaNn on June 23, 2006, 10:08:00 AM
I second the pinning of this thread.

Many people probably get turned off by xbox porting since it seems like a huge task, when they could probably get it done with some determination and help on the big problems.
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: GogoAckman on June 23, 2006, 09:51:00 AM
QUOTE
Many people probably get turned off by xbox porting since it seems like a huge task, when they could probably get it done with some determination and help on the big problems.


True, but you should first thank xport, lantus and tmaul for their efforts in the first place, it is easy now to take a code from their emus and implant it to another code.
There s a lack in the scene, help between devs, I am always open to help someone and asked for devs to help me but there seems to be a competitions between devs and that s not serving the goal achievement.

Remember, that simple way can be the hardest too tongue.gif .
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: nes6502 on June 23, 2006, 11:01:00 AM
I can only speak from my experience. I have mainly asked for help from Xport. But I have also gotten help from GogoAckman and Cacharus.

The available code is a good point. There is a lot of code that has already been written that can almost be plugged in with little change. Even though the Xport code I use only makes up about 1% of ZsnexBox, it was a 1% that saved me a lot of time, research, and effort (like screenshot saving, zip file contents, mounting partitions, HD support).
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: Carcharius on June 23, 2006, 11:57:00 AM
QUOTE(nes6502 @ Jun 23 2006, 05:32 PM) View Post

I can only speak from my experience. I have mainly asked for help from Xport. But I have also gotten help from GogoAckman and Cacharus.

*cough* Carcharius *cough*  tongue.gif
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: nes6502 on June 23, 2006, 12:06:00 PM
QUOTE(Carcharius @ Jun 23 2006, 07:04 PM) View Post

*cough* Carcharius *cough*  tongue.gif


Sorry, I allways mispell your name. Never was a good speller
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: manlol on June 24, 2006, 04:28:00 AM
Thanks for the excellent guide nes, two questions:

1. I'm not able to get a copy of VS2003, will MS Visual C++ 6.0 Standard Edition suffice?

2. Will it be difficult to port a game which uses the Allegro library? I've always wanted to play Liquid War on my xbox.
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: VampX on June 24, 2006, 05:14:00 AM
QUOTE(Diontae18 @ Jun 23 2006, 02:20 AM) View Post

This oughta be linked from VampX's great emu guide, or pinned.


Since there are like as many xbox developers as there are people that can't figure out pcsxbox right?
PIN PIN PIN THERE'S ROOM NOW!!!  tongue.gif


ofcourse this is going to be in the new revision of the pinned thread, but lets refrain from pinning everything again  ohmy.gif
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: nes6502 on June 24, 2006, 07:15:00 AM
QUOTE(manlol @ Jun 24 2006, 10:59 AM) View Post

Thanks for the excellent guide nes, two questions:

1. I'm not able to get a copy of VS2003, will MS Visual C++ 6.0 Standard Edition suffice?

2. Will it be difficult to port a game which uses the Allegro library? I've always wanted to play Liquid War on my xbox.



Only VS 2003 .NET will work easilly. I'm sure it's possible to use 2005 and 6.0 but I don't know how to configure them to build the xbe. 6.0 should work depending on which version of the XDK you have (versions before 5993. But the easiest way is to use XDK 5993 with VS 2003 .NET.

For Allegro, you'll have to rewrite all the graphics code in Direct3D. So it won't be any harder than anything else that doesn't allready use Direct3D (like OpenGl, DirectDraw, etc)
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: Retroplay on June 24, 2006, 02:59:00 PM
What about the directX sdk?
No need to install that then?

I really have to start getting into this (IMG:style_emoticons/default/smile.gif)

This post has been edited by Retroplay: Jun 24 2006, 10:00 PM
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: GogoAckman on June 24, 2006, 03:02:00 PM
QUOTE(Retroplay @ Jun 24 2006, 10:30 PM) View Post

What about the directX sdk?
No need to install that then?

I really have to start getting into this smile.gif


No, the xbox uses direct3d8 version, and even a reprogrammed version of direct3d (textures and some functions differ from PC d3d, but you can have a lot of informations in the help section of the xdk smile.gif ).
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: alg5 on June 25, 2006, 03:22:00 PM
QUOTE(manlol @ Jun 24 2006, 11:59 AM) View Post

1. I'm not able to get a copy of VS2003, will MS Visual C++ 6.0 Standard Edition suffice?


yes cou can.
i personnaly use it with the xbox SDK 4627.

you will need some addons for visual: the processor pack & the sp5 for vc++6 . one of the addon will refuse to install on standard edition. you need to extract the addon unsing winzip, then select install by right clicking on one inf file. then copy the created directory created to the directory where vc++6 is install
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: nes6502 on June 26, 2006, 11:22:00 AM
More porting tips:

Many programs are written in a language (like C, C++, Assembly) and use a library to draw the graphics (like SDL, OpenGL, DirectDraw, Allegro, Direct3D)

As long as the application is written in either C or C++ it should work.

99% of the "porting" of any application or game to the Xbox is this:

Find the code that draws the screen, plays sounds, and reads the input.
Then replace this code with Xbox compatable code.

For example, if the game had a RenderScreen() method that made all the calls to OpenGL, you could look for all the calls to "RenderScreen()" and replace it with your drawScreen() method. your drawScreen method would take the same screen data that RenderScreen used, but instead make Direct3D calls to draw the screen.

This applies to sound and input (replace the keybaord code with Xbox controller code).

If an application is using SDL as the library to draw the graphics, then that's one entire category you don't have to touch because lantus has provided the SDLx (SDL Xbox version). You would then only focus on the other categories.

This is my suggestion on how to proceed:
1) I STRONGLY reccomend the first step be compile it (and run it) on windows.
2) Then comment out all the input and sound code.
3) If it uses SDL, ou can link to the SDLx libraries so you shouldn't have to change anything regarding the graphics.
4) Create the new Xbox application, link to the SDLx libraries, and compile it. This will generate the xbe.

So in theory, you should be able to compile and run an SDL application on the Xbox without changing or writing one line of code (just commenting out any code that gives a compile error like Windows Code, DirectInput code, ect..).

5) After it is running on the Xbox, start looking at replacing the keyboard code with Xbox controller code.
6) When input is working, make any changes that need to be made to get the sound working
7) That's it.

You do not have to be a coding master, but you should have a basic understanding of programming in C. For example, you need to know how all of this works:

variables (local, global)
loops (for, while)
data types (int, float, char)
arrays
functions (passing parameters, returning values, pass by reference)
pointers
structs
switch statements
if/else statements
how to write and read a text file (fopen, fprintf, fclose)
How to set a pixel color on a texture using Direct3D

Don't even begin the port until you understand all of these concepts. I reccomend learning them in the context of C (and porting apps written in C). That will make things a lot easier. There are lots of C tutorials on the net that cover all of these concepts.
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: cricri_pingouin on July 20, 2007, 05:22:00 AM
QUOTE
If an application is using SDL as the library to draw the graphics, then that's one entire category you don't have to touch because lantus has provided the SDLx (SDL Xbox version). You would then only focus on the other categories.
(...)
3) If it uses SDL, ou can link to the SDLx libraries so you shouldn't have to change anything regarding the graphics.
4) Create the new Xbox application, link to the SDLx libraries, and compile it. This will generate the xbe.

So in theory, you should be able to compile and run an SDL application on the Xbox without changing or writing one line of code (just commenting out any code that gives a compile error like Windows Code, DirectInput code, ect..).


I have a couple of questions regarding SDLx.
1 ) what video modes are XBox compatible? 640x480 32bits only? What if I have a 320x200 application?
2 ) what about controller related functions syntax? I don't know how to test for the different buttons on the different controllers blink.gif

TIA!

*EDIT* BTW, I think this thread would fit better in the "Development" forum, just my $0.02.
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: devouringone3 on February 12, 2009, 10:07:00 AM
Nice thread, I pretty much know nothing about coding... but hey, it is a good opportunity to start.

I want to port one or many Touhou Project games... anyone knows if it'll be a big task?

It is a game that looks like stepmania, windowed 640x480, 16bits/32bits colors... simple keyboard-only controls in menu and in game. The game weight about nothing... but yeah, thanks your "guide" is good for hope and motivation.
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: Bomb Bloke on February 12, 2009, 06:14:00 PM
1) Is the source code for this particular game available? Can't do much without it.

2) You do know Stepmania has already been ported to the X-Box, right?
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: Bomb Bloke on February 13, 2009, 05:38:00 AM
QUOTE(devouringone3 @ Feb 13 2009, 04:43 PM) View Post
But hey, the game is essentially a zip file containing a .exe a .cfg and 3 .dat.

Wasn't the sourcecode only a "plus"?

For users, yes, the sourcecode could be considered just a "plus".

But for coders/porters, the source is EVERYTHING.

See, when you write a program, you write what's called the "source". The source is text, pretty close to standard english, that tells the program what to do. Pretty much anyone can read source code and get a vague idea as to what it's supposed to do (especially if it's well written source, in which case it'll contain plenty of "real" english comments explaining all the complex bits).

Once you've produced your source, you compile it. For a PC, this converts the source to code the computer can run - an EXE file. This is pretty much unreadable to everyone except experienced coders (and even they have to take some time to translate it). Try opening up an EXE in Wordpad or something, you'll see what I mean.

So how do you re-write an EXE to work on the X-Box? Well... you don't. The amount of work involved is massive. Instead, you simply get a compiler for the X-Box, and tweak the source a little bit and bam, you're done.

(The X-Box uses XBE files instead of EXE files).

Without the source, you've got no hope of convincing anyone to attempt a port for you. And given that I just had to explain the above to you, I'd also guess you haven't a hope of doing it yourself.  unsure.gif
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: Red_Breast on February 17, 2009, 02:37:00 PM
Getting hold of XDK then.
I seem to remember that the one on Xbins is an open-source version of the XDK.
Is that correct?
If so I take it getting hold of the XDK is one of those things I need to search for myself.
Is that correct?
I'd really like an updated ScummVM. Cacharius' last build was Xmas 2007. Quite a lot of games have been added since then.
Title: Very Simple Guide To Xbox App/emulator Porting
Post by: Pulsemasta on January 09, 2010, 02:20:00 AM
I couldn't find the Genadrive source code on Xbins, or elsewhere. Is it still open source?