Rewriting classic ZX Spectrum game "The Great Escape" in portable C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cmake/Modules
include
libraries
platform
scripts/certs
.astylerc
.editorconfig
.gitignore
.splintrc
.travis.yml
.ycm_extra_conf.py
BUGS.md
CMakeLists.txt
CONVERSION.md
NOTES.md
README.md
TODO.md
demo.gif

README.md

“The Great Escape” Ported to C

© David Thomas, 2013-2018

16th January 2018

Demo

Overview

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.
    • Although old ports of the game exist for the PC, C64 and CPC, retro fans would like to see the game on other contemporary systems too.

Chat

Join the chat at https://gitter.im/The-Great-Escape/Lobby

Current State of the Code

Does it build and run?

Yes!

What works?

  • Main menu
  • Input
    • Keyboard + Sinclair joystick (keys 6/7/8/9/0)
    • Kempston joystick (mapped to arrow keys)
  • Bell ringer
  • Score keeping
  • Character moves and animates correctly
  • Doors
  • Boundaries
  • Transitions
  • Room drawing
  • Exterior drawing, scrolling, masking
  • Items can be picked up, used and dropped
  • Masking
  • AI
  • Movable items (stoves, crates)
  • Sound effects and menu music (macOS only at the moment)

Non-core:

  • UI front-ends preserve their aspect ratio
  • Keys for window scaling
  • Speed control

What doesn't?

  • Various other divergences from the original to be fixed

Current Builds

  • 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.

Build Status

Branch Windows macOS
master AppVeyor build status Travis CI build status

Xcode Build

Open up the Xcode project platform/osx/The Great Escape.xcodeproj and build that using ⌘B. Run using ⌘R.

Windows Build

Open up the Visual Studio solution platform/windows/TheGreatEscape/TheGreatEscape.sln and build that using F7. Run using F5.

Makefile Build

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>

To build:

cd platform/generic
make build

Or 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.

Components

TheGreatEscape

This is the main game reimplemented in a single (static) library.

ZXSpectrum

Defines an interface to a virtual ZX Spectrum to which the game talks, replacing the bare-metal IN and OUT instructions and providing a screen to draw to.

Source Layout

./
    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

Variable resolution

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.

Related Links

Porting Chuckie Egg