Site logo,

Terrain - maps, simulation

May 2014

I have recently had a blast from the past about some games I wrote for the Sinclair ZX Spectrum and similar machines 30 years ago. It seems that the current resurgence of interest in popular programming may be reviving the ideas behind the games. I had a particular technique of my own for generating terrain on a large enough scale to be explorable, despite the lack of memory in those early machines (the Spectrum had only 48k bytes - and that was the larger version). Indeed, one of my games was simply called Explorer. Its predecessor, The Forest, was a simulation of the sport of orienteering.

[Update 24 June 2014: There is now an interesting article looking back at Explorer on Mark Green's blog, Pixelatron.]

There is a web site called World of Spectrum where a group of people are attempting to assemble an archive about all programs written for the ZX Spectrum and make many of them available to download and run in one of the many Spectrum simulators that are now also available for free. They have listed my two programs here (they have promised to correct the spelling of my name).

Technology has advanced so much in 30 years that much better versions of such games are now practical. For one thing processor clock speeds have gone up by a factor of nearly 1,000 - the Spectrum ran (I think) at 4 MHz. Also it is common now to have multiple processors in a single machine (eg, the Intel Core i5 etc), giving another potential speed increase. Also the processing of graphics is now usually hived off to a separate Graphics Processing Unit (GPU) rather than the Central Processing Unit having to do everything, as was the case all those years ago. Today's processors also have special instructions built into their hardware for frequently used computations. For example, I think it was in the mid-1980s that Intel processors (such as 80286) started to have companion chips called coprocessors, for doing non-integer arithmetic. Devices on silicon have now been so much further miniaturised that all such work can now be done on a single chip rather than requiring a coprocessor.

It is now common to have gigabytes of main memory. Even the laptop on which I am writing this has 8 Gbytes of RAM, which is 167,000 times that of the Spectrum. It almost goes without saying that we can now have very much better graphics, of photographic quality (something I could only dream of in the 1980s).

It is possible to re-implement the Forest/Explorer games in HTML5 with JavaScript, making them available on just about any platform that can browse the web. Despite the fact that JavaScript is run interpretively by a browser, which is in principle much less efficient than the assembly code I wrote for the Spectrum's Z80 microprocessor, speeds are still much better than 30 years ago. To establish that, I have started to write a demonstration version. It can be seen here:

 Status of the demonstration Forest

There are two views available: either a map or the view seen by an observer on the ground. Although there are buttons for switching between these views there is also a keyboard alternative: m (with or without shift).

The observer is marked on the map with a red circle which has an arrow point showing the observer's direction of view or motion. The map can be scrolled and panned and there is a button for centring the map on the observer (referred to as "me" on the button). The speed of scrolling/panning can be changed by doubling or halving the step size. The current coordinates of the map and the size of the step are shown in a status line at the bottom. There is also a coloured key to different types of terrain depicted in the map. The colours are those used on orienteering maps.

The other view, the scene, indicates what the observer would see on the ground. The type of terrain ahead is indicated by graphics. One of the advances here is that real photographic images can be used rather than simple drawn graphics. The base line for the graphics indicates whether the ground ahead slopes up or down, according to the contours on the map. The arrow keys are active in the scene and they act as follows.

NB: The arrow keys may scroll/pan the window in some browsers or on small screens, so letter key alternatives are allowed: initials of Right, Left, Up , Down or the suitably laid out group of keys H, J, U, N.

Note that the observer's current position (x, y) and bearing (degrees clockwise from due North) are shown in the status line at the bottom of the view. A compass is also shown at the bottom centre of the scene view.

The red dots on the map are teleportation machines. In the scene view they appear as on the right here. They were called warp gates in the original Explorer. The point of these is that by typing in any name you will be taken magically to a particular spot on the map. When you find another teleporter you can go back to exactly the same spot by using the same name. A set of names enables you to jump about to known places. So if the game included important immovable objects (with messages on them perhaps) you could always revisit them after you had found them. It is entirely up to you to choose location names. There is no telling in advance where any particular name will take you. Letter case is irrelevant: London and LONDON will both go to the same place.

Black dots on the map are intended to be cave entrances but as yet nothing happens there.

 Planned soon for the demonstration

* I am testing in Firefox 29.0 running on 64-bit Windows 7 Home Premium on an Acer 4830T laptop (Intel Core-i5-2430M processor running at 2.4GHz "with Turbo Boost up to 3.0GHz"). The map takes about 60ms to draw and the scene takes only 1ms or less. Please tell me if your platform takes significantly longer.


The original versions of The Forest and Explorer were written in Z80 assembler, in order to fit into the very limited amount of memory available and to run at a reasonable speed (much faster than interpreted BASIC). The new demonstration at is mostly written in JavaScript, a much more easily comprehended language, running within an HTML5 page. If you right-click and "view source" on that page you can see the file names for the JavaScript files and therefore view them also in your browser, to see how it works. If you are not familiar with JavaScript, particularly its object-oriented aspects, you may wish to peruse my introductory programming course.

 Further information

I will be writing more here but meanwhile some further information about orienteering maps can be obtained here (and follow the links there to read more about the simulated forest).

 Earlier writings

In 1982 I had two articles published in the now long-defunct British magazine "Practical Computing". The articles described the basic techniques I was using to generate terrain from mathematical functions rather than storing it in memory. Following here are links to scanned images of the articles.

 March 1982

Cover image

Page 93

Page 95

 September 1982

Cover image

Page 127

Page 129

Page 130

Next page