“The Great Escape” Ported to C
© David Thomas, 2013-2018
16th January 2018
This is a work in progress C port of “The Great Escape”: the classic isometric 3D game for the 48K Sinclair ZX Spectrum in which you execute a daring escape from a wartime prison camp. Loosely based on the film of the same name, it was created by Denton Designs and published in 1986 by Ocean Software.
I reverse engineered the original game from a binary snapshot of the Spectrum version, decoding the graphics, data tables and all of the logic. Originally written in Z80 assembly language, I have translated it into portable C where now builds and runs without an emulator on macOS and Windows. Eventually it could run on mobile platforms and in a web browser.
Goals of the Project
- Reimplement The Great Escape in portable C code.
- While being as faithful to the original as possible.
- Fully disassemble and document the original game.
- My current disassembly is incomplete. Attempting to reimplement the game logic forces through issues and flushes out bugs which enable a complete reimplementation to be made, and the original code fully understood.
- Fix some bugs in the original game.
- Analyse the before-and-after code metrics.
- How much bigger is the compiled C reimplementation compared to the original game?
- What can we learn from the original’s tight coding techniques?
- Provide a basis for porting the game to contemporary systems of the ZX Spectrum.
Current State of the Code
Does it build and run?
- Main menu
- Keyboard + Sinclair joystick (keys 6/7/8/9/0)
- Kempston joystick (mapped to arrow keys)
- Bell ringer
- Score keeping
- Character moves and animates correctly
- Room drawing
- Exterior drawing, scrolling, masking
- Items can be picked up, used and dropped
- Movable items (stoves, crates)
- Sound effects and menu music (macOS only at the moment)
- UI front-ends preserve their aspect ratio
- Keys for window scaling
- Speed control
- Various other divergences from the original to be fixed
- Xcode build - works. This is my default build so is most likely to be up-to-date.
- Windows build - works - needs Visual Studio 2015.
- Makefile build - works, but runs the game for 100,000 iterations in headless mode.
Open up the Xcode project
platform/osx/The Great Escape.xcodeproj and build that using ⌘B. Run using ⌘R.
Open up the Visual Studio solution
platform/windows/TheGreatEscape/TheGreatEscape.sln and build that using F7. Run using F5.
The Makefile build compiles the code using clang, and offers some other handy options, like running an analysis pass, generating ctags, running the source through splint and reformatting the source code through astyle.
dave@macbook platform/generic $ make Usage: build Build clean Clean a previous build analyze Perform a clang analyze run lint Perform a lint run tags Generate tags cscope Generate cscope database astyle Run astyle on the source docs Generate docs MODE=<release|debug>
cd platform/generic make build
MODE=release make build to make the release version of the code.
The Makefile-based build presently links against a stub
main() which does nothing, so does not provide useful runnable code yet.
This is the main game reimplemented in a single (static) library.
Defines an interface to a virtual ZX Spectrum to which the game talks, replacing the bare-metal
OUT instructions and providing a screen to draw to.
./ include/ - public headers TheGreatEscape/ ZXSpectrum/ libraries/ - sources TheGreatEscape/ include/ - private headers ZXSpectrum/ platform/ - platform-specific source generic/ - generic Makefile build environment osx/ - Xcode build environment windows/ - Windows build environment
Further (Planned) Changes
The goal in this project, other than an understanding the original game, is to bring the escapade to modern platforms. Those platforms feature various modern marvels including high resolution, high density screens and capacitive touch screens.
Bearing in mind the various new devices on which the game will be run we must allow for changes to screen resolution, screen density and input devices. So some hard-coded constants for the dimensions of the screen will be replaced with references to variables kept in the game state.
This is tricky as at some point we’ll need to dispense with the Spectrum’s cunning/weird screen memory layout.