SIGNALMAN

by Duncan Munro

from ZX Computing Jun/Jul.1985



Duncan Munro has done a lot of 

research in Londonderry to ensure the

accuracy of his signal box simulation.





This program simulates the working of a modern signal box

and is based on the actual working practice of the local

Coleraine box. In order to get the details right, I spent

some time with the signal man on a recent Saturday afternoon

when traffic was quite busy. I had a very interesting time,

away from the computer for a change, discussing and watching

the actual operations and working methods.



The Coleraine Section incidentally was one of the first to

be fitted with track circuiting, colour light signalling,

and a route indicator board in the box in the late 1930's.



The Coleraine signal box has many interesting features,

including control of two level crossing gates, a lifting

cantilevered rail bridge across the river Bann, and control

of trains on the main Belfast - Londonderry line as well as

the branch line to Portrush. There are 48 levers in the

lever frame so my computer simulation is a considerable

simplification with only (!) 16 levers. Nevertheless, the

program does include all the essential features. These

include full interlocking of the crossing gates with the

signals and points levers through a king lever as in real

life. The lever colour coding is also accurately represented

within the limits of the Spectrum's 8 colours. It does not

attempt, however, to handle the various bell codes exchange

between adjacent signal boxes, as this would require a

program in its own right, and also slow operation down to an

unacceptable level. There may seem to be a lot of beeps used

but, in practice, a signal box is a surprisingly noisy place

with different bells, buzzers, and telephones sounding every

few minutes.



The program contains several novel features, including

working in real time to a pre-set timetable. At the end of

the program, the overall efficiency of the signalman is

calculated and displayed. This takes into account both the

efficiency in running the trains to the timetable and the

delays imposed on the road traffic. This delay has been made

proportional to time on an exponential, rather than linear

basis, so that a balance has to be achieved, as in real

life, between running the trains on time, and keeping the

road open to traffic for as long as possible.



Skill is required in efficient and effective route setting

and driving the trains while in the section. The program is

not 'fast moving' in the arcade game sense but rather

corresponds to the speed of operation required in real life

practice. The degree of difficulty can be changed by small

alterations in the delay function exponential power value. A

value of 2, for example, instead of 1.5, will increase road

delays to the point where a high score is almost impossible.

A demo mode option is included, allowing the user to

familiarise himself with the lever codes and the operation

of the gates, signals, points, trains, etc. merely by

pressing one key when instructed.



Once a train is accepted and a route set up for it, the

operator changes roles to become the engine driver. After

driving the train to its correct place (a stop signal,

across a junction, or out of section) he reverts back to the

signalman role.



The program structure and detailed instructions are

described separately. However one or two items are

noteworthy -



1. Due to the large number (37) of user-defined graphics,

   these are split into two sets and each set called up as

   needed by poking values into system variable 23675.



2. The program makes full use of Boolean operators (AND,

   NOT) to ensure correct signal interlocking with the

   gates, and to ensure correct subroutines are used to run

   various possible scenarios, and is essential in directing

   the trains correctly at a points junction.



The method of directing the train at a junction, is, I

believe, somewhat unique. It is fully explained in the

subsequent text.



Finally, the program requires 24.1 K for the Basic listing

and consequently requires a 48K Spectrum.



It has been thoroughly tested and debugged. It is 'idiot

proof' and will not permit trains to be driven while the

gates are closed to rail traffic, neither can a train be

driven past a signal at danger. It will also stop and

request an immediate 'Accident Investigation' if two trains

are allowed to collide, or are driven into the buffers.





Operating Instructions



You are in charge of a Signal Box. Your section is

controlled by colour lights based on British Signalling

Practice. Seven trains will be offered to you in sequence of

the operating time table, from 15:00 hours onwards (you will

find it useful to make a note of the timetable codes for

reference). No more than 2 trains in section are permitted.

The branch line train is a local rail bus. After discharging

passengers, the rail bus must wait for the MAIN line train,

and then be rerouted back via the DOWN BRANCH line.

Therefore, the rail bus must cross over to the Down Line

before you can accept an UP MAIN line train. The seventh and

final train is a DOWN freight train which has to be diverted

to the siding, and then all signals set to 'ON' and the

crossing gates closed. Your score will then be shown. BUT NO

SCORE IF YOU CRASH!



The score takes into account delays in routing of trains

through your section and excessive delays to road traffic

due to keeping the crossing gates closed. Car drivers'

aggravation is indicated on an exponentially rising decibel

scale!



For safety reasons, the gates, and the signal levers are

fully interlocked. Gates must be opened first before pulling

off any other levers. The King lever interlock (labelled KL)

must then be pulled off before you can pull off any signal

levers. This sequence must be reversed before closing the

gates (remember that closing the gates here means closing to

rail traffic, not road traffic!).



The levers are colour coded (yellow = distant, red = starter

or home or advanced starter, black = ground signal, green =

gate lever, magenta = king lever, and cyan = down line

junction route indicator).



1 = 'ON' (at danger or caution)

0 = 'OFF' (clear)



So, to pull off the Down Starter, input DS0. A demo mode

operation is available to assist in familiarising the lever

frame operation. When you have accepted a train, and set the

routine up, you change roles and become the engine driver!

When you have driven the train to its correct position, i.e.

up to a signal at danger, or out of section, you will return

to the box automatically. Otherwise key 'S' to return to the

box.



A description of the train codes and the operating timetable

are shown at start of the program. The train codes are alpha

numeric, containing 5 characters. The first is a numeral, 1

to 4, giving the train description, the second and third

characters are alpha and indicate the line on which the

train is travelling when entering section, and the last two

are digits showing the time due in section. Thus, '2DM05'

signifies ordinary (stopping) passenger train due on the

down main line at 15:05 hours.





Lever Interlocking



There are 3 types of interlocks

- variables LOCK, KL and L (n)

- to ensure that:



a) the signals cannot be set to clear if gates are shut (to

   rail traffic);



b) the gates cannot be shut if a signal is at clear.



As in real life practice, it is necessary to have an

intermediate lever, called a KING lever, which must be

pulled off before any signal lever is pulled. It must also

be set back 'ON' before the gates can be opened or closed.

When the gates are opened, they are physically locked in

position by latch set in the road surface. The diagram

illustrates the sequence of interlocking; '1' means lever is

pulled 'OFF'; '0' means lever is set 'ON'.





Program structure



Lines



20-90        Train codes and Timetable.

100-254      Define USR graphics and store first 17 characters at addresses

             65368 upwards. Store remainder at addresses 64000 and up.

280/600/etc. Poke system variable 23675 to call up required set of graphics.

295-680      Draw layout (The draw statements are left in the original format

             of one number minus another. I found this was essential to the

             task of plotting and drawing to an exact pixel position and

             correcting any errors.)

750-790      Add ink colours.

800-805      Store lever codes and corresponding signal print coordinates

             for use in subsequent subroutines.

865-877      Start the clock (see the Sinclair manual).

900-965      Main control program - controls which subroutines to call

             depending on whether one or two trains already in section and

             whether a train has been accepted into section.

1000-1090    Controls the lever frame operation and calls appropriate

             subroutine.

1100-1160    Finds starting coordinates of a train entering section and

             lights up route indicator.

1170         Main routine to drive trains.

1400-1590    Accident Notices. Program stops if activated.

1600-1720    Warning Notices if incorrect lever operation attempted.

1900-1950    Calculates the time, in minutes, that the gates have been

             opened and increments the value to the power 1.5 to give

             aggravation level on an exponentially rising scale of 'decibels'

             (rd).

2000-2040    Exit from driving routine, and return to signal box operation.

2100-2220    Subroutines for trains 1 and 2 to determine new print

             positions.

3000-3070    Individual train codes.

3100-3297    Gate and King lever routines including interlock setting (see

             text for details). Line 3227 - ot = time gates opened;

             Line 3295 - cumrd = cumulative road traffic delays for each

             interval of time gates opened and closed.

3300-4050    Operates signal levers, sets appropriate signal colour, changes

             the points, and sets signal interlock.

5000-5390    Evaluates the track on which each train is standing. Sets the

             appropriate variables: pt1, pt2, pt3, pt4; for train 1; and:

             vt1, vt2, vt3, vt4; for train 2. Returns to subroutines

             2100-2220 to evaluate direction to move (E, W, NE, SE, SW or NW)

             for INKEY$ "5", "8", or "Q" or "P" (see text for details).

7000-7015    Subroutines to call up appropriate set of graphics.

8000-8060    Calculates the actual time for the digital clock display.

9000-9300    Calculates the display's final scores as separate performances

             against rail timetable operation and road traffic delay and

             also shows overall performance.

9500-9990    Demonstration mode routine.





To open the gates:



At the start,

	LOCK=0 (gate lever), KL=1 (King lever),

	L(n) to L(14)=1 (the signal lever locks are all set to 1).

Pull off CO Open Gates.

	LOCK=1

Pull of KL

	KL=0

Signal lever can now be pulled off (L(1), etc. = 0)





To shut the gates:



All the signal levers must be reset to ON

	L(n) to L(14)=1

Set on KL

	KL=1

Set on CO Close Gates

	LOCK=0





LOCK   KL     L

----  ----  ----  

  0     1     1   start - gates closed

  1     1     1   open gates

  1     0     1   pull King lever

  1     0     0   set signals

  1     0     1   reset signals

  1     1     1   reset King lever

  0     1     1   close gates





--

Another Fine Product transcribed by:

Jim Grimwood (jimg@globalnet.co.uk), Weardale, England

--

