An Experiment in Real-Time Networking.



by

Stuart Cheshire

Sidney Sussex College


Previous | Table of Contents

Appendix A -- The Original Proposal
Project Description
Part I
Part II
Resources Required Plan Of Work
Appendix B -- Specific Instructions for the BBC micro
Appendix C -- The Timetable of the Project
Mid December 1987 -- 2 Weeks
Mid January 1988 -- 2 Weeks
Easter Holiday 1988 -- 4 Weeks
November / December 1988 -- 9 Weeks
February / March 1989 -- 6 Weeks
March 1989 -- 2 Weeks
April 1989 -- 4 weeks
Appendix D -- Supporting Software
The Assembler Environment
Making Pictures
Building an Island -- The Map Editor
Booting from Nothing!
Appendix E -- Code listings

Appendix A -- The Original Proposal

The project did not adhere closely to either the timetable or the plan of the original project proposal.

The real reason for this was, in fact, dealings with Acorn. I had hoped to be able to get an Archimedes Development System -- machine, hard disc, C-compiler, technical manuals etc. -- at the discounted price that Acorn offers to members of their I.S.V. (Independent Software Vendors) scheme. I wrote countless letters to them, thinking that they would be interested in a project of this kind, but I got no-where. I never even managed to get a price-list out of them. I had not realized that they do not want to support the development of any games for the Archimedes. They are determined to promote the Archimedes as a business machine, and to this end they pursue the twin goals of supporting the development of business software and discouraging games.

It is possible that Acorn are right, that the existence of games for a machine detracts from its credibility to business purchasers.

I have now decided to produce Bolo for the Macintosh and IBM PC instead.

... the Macintosh because I have one, so I already have a machine to work on.

... the IBM PC (& compatibles) because of the sheer number which exist in the world, and the fact that so many in offices are already connected together by networks such as Token Ring and Ethernet. Perhaps, with good fortune, Bolo could become as popular and commonplace as Flight Simulator is now.

Computer Science Tripos

Part II

Project Proposal

Project Description

Part I

The aim of the project is to produce a real-time, multi-user, graphical game, running on a Local Area Network. The intention is to support up to sixteen players, and to provide each with a screen display updated 25 times per second in order to create the appearance of smooth movement. This should be achieved with a total network traffic measured in terms of hundreds of bytes per second instead of the more familiar hundreds of kilobytes per second now associated with LAN's.

The game is set on an island. Each player is in control of a tank, which can drive across the land at differing speeds determined by the terrain. Tanks can also board ships, which they control, in order to cross lakes or to travel quickly around the coast. Players can build bridges in order to facilitate the crossing of rivers, and can perform other building work such as the construction of roads and buildings. In this way, they can build a fortress to use as their home base, which can be defended in their absence by automatic pill-boxes (which shoot at any hostile tanks) and minefields. Players can also make formal alliances and work as a team, or may simply agree a temporary truce in order to concentrate on attacking a stronger player. In either case, the question of if and when and how to break the alliance is all important.

A simple prototype has already been written (and tested with 8 players) for the BBC micro which implements a subset of the full game planned, and suggests that the above performance goals are reasonable.

The BBC micro code must first be re-written more rigorously, in accordance with some principles of Computer Science. In particular it is necessary to implement reliable semaphores. Currently the only protection on shared resources is to disable interrupts in short routines, and to hope that nothing goes wrong in routines too long for this approach. Other potential problems such as buffer overflow are also dealt with in a similar manner.

The code will be divided into three distinct modules: The game itself, working on internal data structures; the display driver, providing the user with a graphical representation of the said data structures; and the network driver, insulating the game from the details of the actual type of hardware interface being used.

A version for the Archimedes will also be written. This should only take a short time, since the graphics modes and operating system of the Archimedes are so similar to the BBC micro. It also provides the opportunity to write the program in a language such as C instead of machine code, since the ARM processor provides sufficient processing power for this to be feasible.

Several interesting topics are to be covered, including:

Graphics
The approach to graphics is to be more sophisticated than the primitive `rub out space invader and redraw at new position' usually expected in a game. Instead, there will be an object-list, in which each game object is identified by a unique number, and has associated with it a graphical character (tank, shell, man etc.), a colour scheme, and pixel coordinates on the screen. Instead of actually calling the `plot character' routine to plot pixels directly on the screen, the various game processes communicate with this table via calls to create, delete, move, or otherwise alter an object. Meanwhile, a foreground process runs, (using however much or little processor time is left after all the real time routines have been dealt with) which continually reads the object list and redraws any that have changed since the last time it looked at them. It also automatically erases the old image of a moved character by redrawing the background where appropriate, and also any stationary objects which may have been overplotted by other things.

Distributed Computing
Since the program will be running on an unknown number of machines, division of the workload has to be done carefully in order that all machines do a `fair' amount of processing. Real time processes must be truly real time since it is unacceptable for one player's tank to be able to drive faster than another's simply because his machine momentarily has less work to do.

Networking
An efficient network protocol has to be defined. It must be able to carry both synchronous and asynchronous data, and is also expected to support simple Remote Procedure Call facilities. Synchronous data, such as the position of a shell at a particular instant, must be fast if it is to be of any use, but if lost is not worth re-transmitting since it is soon out of date. Asynchronous data, such as the fact that a player has built a bridge, should still be transmitted as soon as possible, but must also be guaranteeably received by all machines since it would be unacceptable for different players' maps to become inconsistent. This requirement also implies that there should be reliable error detection and recovery, not just to cope with line noise, but also the distinct possibility of trailing wires being tripped over and pulled out by a careless player.

New players
The question of allowing individual players to join and leave the game independently is an important and non-trivial part of the project. Both the provision of a consistent map when a player joins the network and the behaviour of his automatic defences after he leaves will require a great deal of careful thought.
Part II

When the program is finished, it will be necessary to test it. Unfortunately, this would require a large number of players, playing for a long time, in order to ensure an exhaustive test. There is however an alternative -- which in itself makes an interesting challenge.-- that of writing a program to play the game. This need not attempt to be a completely autonomous and `intelligent' pseudo-player, but instead could just pick, in a semi-random way, goals which are regarded as generally `good things to do'. It would be provided with simple algorithms to enable it to, for example, find its way across the map to any given coordinates.

Since all the machines will be communicating via the network driver, there is no reason why human players should not be able to play simultaneously with the computer-controlled ones without any special modifications to either program. Another possibility is that, instead of the semi-random choice of goals, there could be a provision for manual choice, enabling a human user to act as a commander over several tanks simultaneously.

Resources Required

Plan Of Work

Part I

November Re-write simple BBC version.

December Begin full implementation on the Archimedes.

January Working version ready in time for progress report.

Part II

February Finish off details, test, debug, and write game-tester.

March User interface for the game-playing routines.

April Finish debugging and write dissertation.


Appendix B -- Specific Instructions for the BBC micro

The following document contains the preliminary instructions for the BBC micro version.

Appendix C -- The Timetable of the Project

This appendix provides more precise details of exactly what work was done at what times.

Mid December 1987 -- 2 Weeks

BBC Assembler environment.

Graphics editor and compilers.

Map editor program.

Ring transfer program.

Simple graphics. Basis of setob and refresh routines designed

Tank driving and communicating but only just.

Mine laying but no explosions on other machines.

Mid January 1988 -- 2 Weeks

Machines made to communicate a bit more reliably.

Mines made to work.

Shooting routines written.

Message system to allow messages to be typed to other machines (important for communicating between our two separate rooms in Cromwell court).

Simple building operations (only at the tank's location).

Still crashing occasionally.

Easter Holiday 1988 -- 4 Weeks

Pillboxes done -- aiming algorithm using vector product iteration.

Remote views from pillboxes.

Hiding of tanks under cover of forest.

Targeting cross-hairs and manual setting of tank's gun range

General bug fixing and

re-coding of the values of the opcodes used in the network packets.

November / December 1988 -- 9 Weeks

Elimination totally of output buffer which could overflow. Switch made to totally network driven dataflow.

Score counters showing the number of `kills'

and the number of times the player has been killed.

Screen indicators showing tank inventory and other status information.

Building Man and parachute for when another is needed.

Farming mode to provide building materials.

New Network Opcodes (again).

Buildings made more robust so that it takes several shots to destroy them

(difficult because of the meagre information stored in the map).

New map with curved edges (arbitrary shape).

Simple and Advanced mode controls.

Regrouping of code into two separate parts (because it got too big) -- one part in normal RAM and one part in ROM space (actually RAM

for development, but eventually to be blown in EPROM when finished).

Fireball when tank dies, followed by `static' on screen.

Crater left on land where tank explodes when it is destroyed.

Boats, both leaving and re-boarding.

Tanks swept along by flooding water.

Pillboxes scattered around tank's location when it is destroyed.

Pillboxes remain loyal to alliance if one player leaves it -- none remain loyal to that player.

Mines shown on allies screens.

More bridge characters & pillbox characters.

Map character compaction.

optimisation of tank coords -- don't send if not moved.

Taking bases and pillboxes out of map to tables.

Intelligent scrolling to automatically show hostile elements in the game.

Making Refueling bases manufacture products at a fixed rate and

notion of capture and ownership of a base by a player.

Sound effects.

Realistic looking growing of forests.

February / March 1989 -- 6 Weeks

MacTransfer.

March 1989 -- 2 Weeks

BBC fixes.

New players arriving and leaving.

Dynamic recolouring of pillboxes (during plotting on the screen) to indicate

whether they are hostile or friendly.

April 1989 -- 4 weeks

Macintosh version started, and further enhancements made to the BBC version, such as the addition of the Circular Buffer.


Appendix D -- Supporting Software

The Assembler Environment

A problem of the BBC micro is simple lack of memory. The 15K or so of 6502 machine code (along with 20K of screen RAM and about 10K of graphical data), just about fits into 48K[46], but the 100K of assembler source definitely does not. Disc-to-disc assembly on floppy disk is impossibly slow so an alternative had to be found.

(i)
The special hardware of the Solidisc Sideways RAM was utilized. This allows the pages of RAM to be separately selected for read and write. The BBC Basic ROM (containing the assembler) was selected for read, and 16K of RAM was selected for writes to the same addresses.

(ii)
Offset assembly was used, where code assembled to run at address &1000 is actually placed in RAM at address &8000. This left all 32K of standard BBC RAM free for source code and symbol table etc, because the 15K of code generated was being placed `on top' of the Basic ROM.

(iii) The source was separated into 6 modules of about 16K each, each using the CHAIN command to call the next, and the final one saving the object code. This did produce the slight disadvantage that inter-module calls could only make backward references, but assembly was very fast[47].

(v)
A ROM was written for the BBC micro which enabled any command to be prefixed with `SWR' to make it apply to the shadow page of RAM instead of the normal memory which the operating system knows about. Eg. *SWR SAVE <filename> to save the code, *SWR MZAP <address> to examine the memory, *SWR DIS <address> to disassemble the code, etc.

Making Pictures

A graphical editor was written. It allows characters to be designed and edited in BBC Mode 1 (320x256 pixels, 4 colours). A fifth, `transparent' colour is also provided, to distinguish between black as an actual black pixel in the image, and black as a space around the edge of the character where the background pixels on the screen are to be left unaltered.

Characters can be loaded into a scratchpad region on the screen where they are seen real size. They can be moved around and superimposed on other characters. Areas can be filled with colour, and manipulated in various ways such as rotation and reflection (useful for producing a tank facing in all directions without having to draw every one by hand).

The program saves files in a simple format -- a byte for the width in pixels, a byte for the depth, and then one byte per pixel with values 0-3 for colours or 4 for transparent.

These files are read by two other programs, the background character compiler, and the foreground character compiler, which compress the data in different ways.

Building an Island -- The Map Editor

The data structure representing the terrain of the island was simple[49] but it still needed to be created somehow, and working out numbers and typing them in seemed to be as futile for this as it would have been for the graphics. Hence a simple editor was written, which displayed the map on the screen with a pixel[50] per map square, its colour indicating the type of terrain in that square. The cursor keys moved a small cursor around the screen and pressing keys 0-9 and A-F deposited a pixel of the appropriate terrain.[51]

Booting from Nothing!

Since the program was intended to be tested in the Old Biometry Room, where the machines are not equipped with disc drives, and locked into cages which make the connection of disc drives difficult, it was felt advantageous to find an alternative way of loading the program into memory. The obvious answer was to use the serial port itself.

A simple filing system was written which supported just the LOAD command and its derivatives. Then, when the loader program loaded the various constituent files (the code, the graphical data, the map etc.), they were read in from the serial port at 76,800 baud[52], almost as fast as a floppy disc. No `requests' for files were made -- it simply relied on the required files being transmitted by the host in the right order, which of course they were. The bytes were passed on to the output of the port as soon as they were received, so that all the machines in the ring received the required files (virtually) simultaneously.

The only problem remaining was how to get the filing system program into each machine. The solution was to use a bootstrap program, written in Basic, to receive the bytes of the machine code with a FOR/NEXT loop and place them in memory before executing the command *DUD[53] to run the game. The Basic program of course also transmitted all the bytes it received, so that all the other machines in the ring would receive them too.

The only problem remaining was how to get the Basic bootstrap program into each machine. The solution was to use the Operating system command *FX2,1 which selects the serial port as the current input stream. This causes all bytes received by the serial port to be treated in the way normally associated with keystrokes typed on the keyboard.

The host machine could then send the line of Basic down the serial port, and it would be received and executed as if it had been typed on the keyboard. The only remaining problem was that the receiver must also pass on the line to the next machine in the ring, and so on, round the ring, back to the host again.

The program:

*FX3,3

FORF%=0TO&1BF:F%?&E00=GET:VDUF%?&E00:NEXT

CALL&E00:*DUD

must also send on a copy of itself to the next machine. We use *FX3,3 to send the output stream to the serial port, and then use PRINT to send the required characters. Eg.

*FX3,3

PRINT"*FX3,3

FORF%=0TO&1BF:F%?&E00=GET:VDUF%?&E00:NEXT

CALL&E00:*DUD"

FORF%=0TO&1BF:F%?&E00=GET:VDUF%?&E00:NEXT

CALL&E00:*DUD

Unfortunately, the functional part of the code is sent, but not the PRINT statement itself, so the code will be sent to the next machine, but that machine won't transmit it any further. We need to put the PRINT statement inside a PRINT statement itself. I won't attempt to do this, because it involves infinite regressing, putting the whole program above inside a PRINT statement, and then putting the whole result of that inside a PRINT statement etc. etc. ad infinitum.

The solution used at the time was simply to put the whole thing onto a single long line, and to use PRINT$&400 to send it on:

OSCLI"FX3,3":PRINT$&400:FORF%=0TO&1BF:F%?&E00=GET:VDUF%?&E00NEXT:CALL&E00:*DUD

Basic reads its input into a line buffer at location &400 in memory, so printing the string at location &400 simply causes the entire line, whatever it may be, to be printed.

This is a very inelegant solution, and highly machine specific, so I decided that, as a Computer Science Project, I ought to smarten it up.

The following program prints itself in its entirety, in a machine independent way, without reading any dubious memory locations:

*BASIC

0*FX 3 3

1PRINT;CHR$13;"*BASIC";CHR$13;:FORF%=0TO4:READA$:PRINT;F%;A$;CHR$13;:NEXT

2RESTORE:FORF%=5TO9:READA$:PRINT;F%;"DATA ";A$;CHR$13;:NEXT

3PRINT"RUN";CHR$13;

4FORF%=0TO&1BF:F%?&E00=GET:VDUF%?&E00:NEXT:CALL&E00:*DUD

5DATA *FX 3 3

6DATA PRINT;CHR$13;"*BASIC";CHR$13;:FORF%=0TO4:READA$:PRINT;F%;A$;CHR$13;:NEXT

7DATA RESTORE:FORF%=5TO9:READA$:PRINT;F%;"DATA ";A$;CHR$13;:NEXT

8DATA PRINT"RUN";CHR$13;

9DATA FORF%=0TO&1BF:F%?&E00=GET:VDUF%?&E00:NEXT:CALL&E00:*DUD

RUN

The secret is that the program contains an entire listing of itself as data.

Ironically, this `superior' program caused the transfer to fail when the game was tested on the BBC Masters in the Biometry Room, where the `dirty' one had previously worked. The reason was that, as you see, the filing system program is placed at location &E00 in memory. This is disc workspace in the BBC micro, the ideal place (I thought) to put the replacement filing system. However, on the Master, the disc workspace has been moved, and Basic programs start at &E00. This meant that the Basic program above (which worked fine on my BBCs for a long time) was overwriting itself when run on a Master.

Appendix E -- Code listings

The following pages contain sample assembly code from the BBC micro version.

Only the code which deals with the networking has been included.

This comprises roughly 1/4 of the total volume of code written.


Previous | Table of Contents

[ Intro | News | Links | Archive | Guides | Gallery | People | Misc ]
The Bolo Home Page is copyrighted by
Joseph Lo & Chris Hwang