Back in April 2009, I bought a Mac Mini to do iPhone development. One of the first things I did with it was port John Jordan's JJFFE to OS X. For the uninitiated, JJFFE is a reverse engineered, bug-squished version of David Braben's Frontier: First Encounters, a classic PC space sim from the 1990s. FFE is the third game in the famous Elite series, and inspired me to get into game development probably more than any other single game.
JJFFE wasn't difficult to port, and was mostly done in a single evening. The only major hurdle was OS X's x86 ABI, which specifies 16 byte stack alignment for function calls. The monolithic hunk of x86 assembly that makes up most of JJFFE doesn't know anything about this requirement, and terrible things happen when it tries to make direct calls to libc routines with an unaligned stack. The messy but practical solution was to create wrapper functions for sprintf and the few dozen other libc routines that ffe.asm uses. The wrappers live in C land and just pass through to their libc equivalents. If we set -mstackrealign, GCC handily fixes up the stack for us on the way through:
-mstackrealign Realign the stack at entry. On the Intel x86, the -mstackrealign option will generate an alternate prologue/epilogue that realigns the runtime stack. This supports mixing legacy codes that keep a 4-byte aligned stack with modern codes that keep a 16-byte stack for SSE compatibility.
It's pretty surreal seeing an old DOS game running natively on a Mac in 2009. That's despite knowing there's no magic involved, since x86 is x86 and essentially I just recompiled the thing. Kudos to John Jordan for the superhuman reverse engineering effort involved in freeing FFE from its MS-DOS roots in the first place.
The port had been sitting on my hard drive for six months, but I finally got around to packaging it up for release. So, Mac-owning retro space sim fans (all six of you), go check out MacJJFFE and tell me if it works.
Post a comment
Powered by clunkyblog release 3.10. Generated in 8ms.