Sign in to follow this  
  • entries
  • comments
  • views

Speed: in which MSDOS meets Windows Phone 8

Sign in to follow this  


Inspired by long standing XNA team tradition, the Windows Phone graphics team recently spent some time using our product and trying to build some apps. One of our goals in supporting native C++ was to make it easier to port existing software and frameworks to the platform, so I thought, what is the most legacy thing I could possibly try to port? For App Week I took a game called Speed, which I wrote 13 years ago (last century!) in C (yep, that's C, not C++) using an MSDOS library called Allegro, and ported it to Windows Phone 8.
Check it out:





If you want to play this yourself, or look at the code, you can download it here:
You'll need a copy of DirectXTK to build it (unzip into a folder named DirectXTK in the same location as the Speed.sln file). Although it runs ok in the Windows Phone emulator, you really need an actual device to play this properly. Touch input using left, right and center of the screen, not to mention tilt sensor input, doesn't work so well via a mouse!
Porting this turned out to be pleasingly straightforward. The OriginalGame folder contains, can you guess? Yup, that's the original C code, almost entirely unchanged since 1999. Meanwhile, allegro.h and allegro.cpp (in the PhonePort folder) provide an emulation layer which translates the necessary subset of the old Allegro API into D3D11, XAudio2 and WinRT calls. It uses DirectXTK SpriteFont for the text rendering, PrimitiveBatch and BasicEffect for all other graphics, XAudio2 for the music and sound effects, and WinRT ThreadPool::RunAsync to emulate Allegro timer interrupts.
A silly-but-I-think-kinda-neat thing about this game is that the music is entirely procedural. The init_music() function (in OriginalGamesound.c) generates a set of single cycle waveform samples using sine, square, and sawtooth waves. Then the music_player() function is installed as a custom timer interrupt handler. This walks through a set of tables describing the pitch and duration of each note, and calls the Allegro voice functions to trigger or stop playback as appropriate. I didn't change this code at all, yet my emulation layer is good enough to play the music exactly as it sounded in the original.
For bonus points I added a bloom postprocess (implemented in PhonePortGame.cpp) because, hey, this is 2012 after all :-)aggbug.aspx?PostID=10364972

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now