About Archive Tags RSS Feed


Writing a text-based adventure game for CP/M

26 April 2021 18:00

In my previous post I wrote about how I'd been running CP/M on a Z80-based single-board computer.

I've been slowly working my way through a bunch of text-based adventure games:

  • The Hitchhiker's Guide To The Galaxy
  • Zork 1
  • Zork 2
  • Zork 3

Along the way I remembered how much fun I used to have doing this in my early teens, and decided to write my own text-based adventure.

Since I'm not a masochist I figured I'd write something with only three or four locations, and solicited facebook for ideas. Shortly afterwards a "plot" was created and I started work.

I figured that the very last thing I wanted to be doing was to be parsing text-input with Z80 assembly language, so I hacked up a simple adventure game in C. I figured if I could get the design right that would ease the eventual port to assembly.

I had the realization pretty early that using a table-driven approach would be the best way - using structures to contain the name, description, and function-pointers appropriate to each object for example. In my C implementation I have things that look like this:

{name: "generator",
 desc: "A small generator.",
 use: use_generator,
 use_carried: use_generator_carried,
 get_fn: get_generator,
 drop_fn: drop_generator},

A bit noisy, but simple enough. If an object cannot be picked up, or dropped, the corresponding entries are blank:

{name: "desk",
 desc: "",
 edesc: "The desk looks solid, but old."},

Here we see something that is special, there's no description so the item isn't displayed when you enter a room, or LOOK. Instead the edesc (extended description) is available when you type EXAMINE DESK.

Anyway over a couple of days I hacked up the C-game, then I started work porting it to Z80 assembly. The implementation changed, the easter-eggs were different, but on the whole the two things are the same.

Certainly 99% of the text was recycled across the two implementations.

Anyway in the unlikely event you've got a craving for a text-based adventure game I present to you:



Comments on this entry

icon Marek at 12:27 on 27 April 2021

And multilanguage too! Polish version for example

icon Steve Kemp at 12:40 on 27 April 2021

I think that might be beyond me!

As things stand the "engine" is about 3k, and the text is about 5k. I'd have to duplicate all the text, which would be a fairly large job, then I'd need to significantly overhaul the engine to make it conditional.

I could almost imagine moving the text into an external file, then letting users supply alternatives. But as things stand a new language would essentially mean a new game.

icon reretg at 15:06 on 27 April 2021

engine MUST have a options for translating and for other language. Many website have automatic translate system. If this will be open source meybe someone can translate

icon Steve Kemp at 15:18 on 27 April 2021

The code is open-source, and available.

That said I don't think anybody has the right to tell me what I must support.

I agree supporting different languages would be nice - but given that this is a project I wrote for fun, which is designed to run on hardware from the 80s there are obvious constraints involved.

It isn't the kind of project where somebody could just turn up and translate "help" into "apua". There are more fundamental changes required, and there would be ongoing maintenance required when the primary/initial language had changed terms.

icon Niko Tyni at 17:31 on 27 April 2021

Hi, thanks, this was interesting :)

Just in case you're not aware, text adventures are nowadays called interactive fiction and there's lots of tools around to create them. I expect Inform (in Debian/non-free) could still compile zcode files that can be played on CP/M (if you can find a zcode interpreter or manage to extract one from the old Infocom games you have.)

But I guess your project may have been more about coding specifically for Z80...

icon Steve Kemp at 08:15 on 28 April 2021

Yeah, I was mostly interested in coding "from scratch". But it did cross my mind that I could use one of the compilers to write something for the Z-Machine.

(I suspect I might have issues with modern compilers assuming a recent version of the interpreter, but no doubt that could be solved easily enough.)