A simple text-based adventure game
This repository contain a simple text-based adventure game, implemented twice, once in portable C, and once in Z80 assembly language.
The Z80 version of the game will run under the CP/M operating system, and the humble 48k ZX Spectrum.
My intention was to write a simple text-based adventure game to run under CP/M. Starting large projects in Z80 assembly language from scratch is a bit of a daunting prospect, so I decided to code the game in C first, so that I could get the design right, and avoid getting stuck in too many low-level details initially. Later I ported to the Spectrum, because it seemed like a fun challenge for myself!
Quick links within this README file:
Thanks to the excellent jsspeccy ZX Spectrum emulator you can play this game with your browser here:
The game is over, when you either fix the light, or find another solution.
If you do not achieve victory within a turn-limit the boat runs aground, and death will consume you all. (It is a very big boat!)
The implementation is mostly concerned with creating the correct series of data-structures, which are essentially arrays of objects. Because if we can make the game table-based we simplify the coding that needs to be done - we don't need to write per-object handlers anywhere, we can just add pointers to tables/structures.
The C implementation defines most of the important things in the file globals.h such as:
The game-state itself is stored in a couple of global variables, there isn't too much state to care about:
The Z80 implementation is based upon the C-implementation, with a few small changes.
The implementation uses a simple set of structures:
The main implementation can be found in the file game.z80, but because we support two targets (CP/M 2.x and the ZX Spectrum) there is a small amount of platform-specific code found in bios.z80.
The Makefile
should build everything appropriately for both systems,
defining SPECTRUM
, and ENTRYPOINT
as appropriate.
xyzzy
" a few times).WRAP 80
to wrap output around column 80.WRAP
to view the current wrapping value.make release
to build both "normal" and "protected" versions of the release.Roughly speaking the game consists of two parts:
All told the binaries for both CP/M and the ZX Spectrum are approximately 14k.
The layout in memory is basically the same for both variants, however the starting address is different:
When the game starts a copy of the "state" is made to 0xD000
before anything has been modified, and then when the game is started that state is copied back to where it is used. This consists of all content between per_game_state_start
and the end of the file. This has the location, flags, and similar, as well as all the static-text which will not change between runs. However copying this region was easier than just copying, or otherwise resetting, the state that changes during play.
No doubt things will change over time, however the (undocumented) BIOS
command will show you rough sizes for the various parts of the game.
Ensure you have the pasmo
assembler installed, and then use the supplied Makefile to compile the game.
Running make
will generate the default targets, if you wish to build only individual things then :
make game-cpm
to build a normal CP/M version.
make game-cpm-encrypted
to build an encrypted CP/M version.make game-spectrum
to build the ZX Spectrum version.
make game-spectrum-encrypted
to build the encrypted ZX Spectrum version.make lighthouse
will build the C-game for Linuxmake release
will build both versions of the CP/M and ZX Spectrum release.If you have a working golang system you can run the game under this trivial CP/M emulator:
If you look on our release page you can find the latest stable build.
lihouse.com
to your system, and then run LIHOUSE
to launch it.
lihousex.com
is the encrypted version.lihouse.tap
to your system, and then launch in your favourite emulator.
lihousex.tap
is the encrypted version.Report any bugs as you see them:
Steve