Xbox UWP SDL2 Starter Project

After finishing up my Z80/Pac-Man Emulator I thought it would be fun to port it to a game console. Since it was written in C#, the Xbox seemed like a natural fit.

All Xbox One retail units also support a DevMode out of the box, so there would be no need for a jailbreak or hacking around security. I knew the Xbox used UWP apps, so I figured it would be a pretty straightforward port.

I was able to get my emulator running on the Xbox, but I did run into a few hurdles along the way.

While getting a Hello World up and running on an Xbox One is quick and easy using Visual Studio, it assumes you'll be building a GUI app using Windows Presentation Foundation (WPF). This means using XAML to build out screens using controls and widgets. If you want to build a game instead of write an app, this is less than ideal. When building a game you probably want to render to the screen yourself.

It took many hours of Googling to find the correct incantations and hidden settings to get this working, so I figured I would document it here for others trying to accomplish the same thing.

The gist of it is:

  • Obtain the source for SDL2 and compile it for the WinRT platform to get a native code SDL2.dll binary
  • Use SDL2-CS wrapper to call into the native SDL2 library from C#
  • Set the DISABLE_XAML_GENERATED_MAIN compilation flag to prevent the compiler from auto-generating the Main entrypoint
  • Remove the *.xaml and *.xaml.cs components
  • Create your own Main which delegates to SDL_WinRTRunApp(mainFunction, IntPtr.Zero)
  • Write your SDL code to render the screen!

I've documented this in much more detail in the project readme on GitHub. I've also created a pre-packaged starter project which should allow anyone to download, unzip, and open a Visual Studio solution and immediately get started.

Author image
Northern California
A software geek who is into IoT devices, gaming, and Arcade restoration.