WAITS: Terminals and keyboards

To expand on what we saw in the quick tour, let's look further at how you can interact with WAITS using the simh emulator. There are two classes of terminals: teletypes and display terminals.

Teletypes

Teletypes here means the console typewriter (shown below, with John McCarthy helpfully holding the paper) and remote connections, which simh emulates as a telnet connection but on the real system could have come from phone dial up lines or over the Arpanet.

/images/waits/sail-console.jpg Using the console at SAIL. Source: CHM.

These devices support the backspace key, but do not delete characters; instead they print a backslash, then the characters you want deleted, then another backslash when you start typing again. So if I entered ABCDEF but deleted the last three characters and inserted XYZ it would look like:

ABCDEF\FED\XYZ

You can press Control-U to delete the whole line, but TOPS-10's Control-R to reprint the line is not supported.

Pressing Control-C will stop a job; pressing Control-O will keep a job running but suppress any further output.

The console

By default the console will print in upper case, but you can coerce it to print lower case (in most programs) by typing TTY FULL.

The console was not intended for regular users and if you try to log on as one (eg L 1,BGB) it will ask for a password:

.L 1,BGB
JOB 1    STANFORD 6.17/K 08-16-74
THE CTY IS FOR DEBUGGING ONLY,
UNLESS YOU KNOW THE PASSWORD =

Well, we own the system now, so the password to get around this is FEEPER. This is a special password for the console, and if you have a password for the account this would be prompted for next.

Remote access

simh allows remote access via telnet: if using the quickstart this is on port 1974. However, users without a password (which is true for the REG and BGB accounts we have used so far) are not allowed.

$ telnet 0 1974
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.


Connected to the KA-10 simulator DCS device, line 0


TTY2    SYSTEM LOADED ON FRIDAY    26-JUL-74    18:10  
^C
.l 1,reg
JOB 2    Stanford 6.17/K 08-16-74
Remote login prohibited for that account.
You must log in locally and set a password to allow remote logins.
KJOB
.

To set a password, use the console or display terminal to login as your chosen account using % instead of . in the login command, eg L 1%REG. It will prompt you for a password and whether to use this on all logins, or just remote ones.

If you try to login as an unknown user over a remote connection, you get politely redirected to use the NET,GUE guest account

.l 1,foo
JOB 2    Stanford 6.17/K 08-16-74
We prefer that our ARPA NET guests login as "NET,GUE".
Type "Y" to be logged in as "NET,GUE"; anything else to proceed: y
What is your name, please? A tourist
Friday  26-JUL-74       1822
3 jobs logged in. 1 Running.
.

The guest account has no disk directory and cannot run all programs.

Note that the remote access communication speed is quite slow, and I have seen it hang for 10-20 seconds sometimes.

Display terminals

Most users in the lab would have access to a display terminal, which was very unusual for the early 1970s. There were 6 III (Triple-I) vector displays and 58 DD (Data Disc) raster displays in 1973 (not all DDs could be used at the same time, however). simh has good support for the III which we'll go into details below.

/images/waits/iii.png Left: An III display in use at SAIL running an unknown music program. Source: CHM. Right: a simulated III display on simh.

Display terminal keyboards

Display terminals used a special keyboard, the layout of which is recreated below.

/images/waits/stanford-keyboard.png Stanford keyboard layout. Source: keyboard-layout-editor.com

There are a number of modifiers that can be combined with other keys: Shift, Control, Meta and Top. On simh, Meta is mapped to the Alt or Option key. Top is used to select the symbol on the top of most letter and number keys, such as > on the F key. This is mapped to the Windows/Command key on your keyboard (which may be hard to use as some window managers grab these). On your modern keyboard you will have many of these available directly, so for > you can press Shift and dot as normal.

There are also special keys at the side like BREAK and CALL which are used to control the line editor; simh uses the function keys for these. These are not modifiers, ie to type the sequence BREAK e you'd press F3, let go and type E.

The ALT key (also known as ALTMODE) is not a modifier but another special key, and is accessed by pressing Escape on your modern keyboard. The ESC key is another function key not related to the modern Escape key.

Here's a summary of how all these keys are mapped to a modern keyboard when using simh.

Stanford key Modern key
META Alt/Option
TOP Windows/Command
CALL F1
ESC F2
BREAK F3
LINE F4
FORM F5
VT F6
ALT Escape

There does not seem to be a simh mapping for CLEAR, however

The cursor keys will emit the arrow characters like ←.

Not a Stanford key, but a facility provided by simh: pressing F11 will make the window full screen.

The saildart javascript emulator does not use the above keyboard mappings, but does provide a layout with a virtual keyboard you can click keys on.

The line editor

Similar to the facility you are used to in modern shells like bash, the display terminals supported a powerful line editor to help you quickly edit text, using the Control and Meta keys. This works on all text input fields, not just the monitor command line.

If you log on to the III you will see there are two cursors, one at the start of the text field you are typing into, and one at the end. You can move back and forward on the line with Control-Backspace and Control-Space respectively. If you are not at the end of the line, typing a character will replace what's currently behind the second cursor. Typing Meta and a character will insert a character. So typing X with the cursors as shown below would change 'world' to 'xorld'.

/images/waits/two-cursors.png The two cursors. Source: Rupert Lane. License: CC0.

Meta-Backspace will delete the character behind the cursor. Control-D deletes the character in front of the cursor.

Plain Backspace at the end of the line deletes the last character, but if the cursor is not at the end it will act the same as Control-Backspace, ie move the cursor left.

A summary including the other line editing commands. C- means Control. M- means Meta.

C-Space Forwards one character
C-Backspace Back one character
M-ch Insert character ch
M-Backspace Delete char to the left
C-d Delete char to the right
C-Return Recall last command typed
C-Tab Move to end of line
C-FORM (F5) Move to start of line
C-S Search forwards for the next char you type
C-K As above, but search backwards
C-R Repeats the last Control-S or -K search
C-I Toggle insert mode

Finally, you can repeat a command n times by typing Control and the number n, then typing the command.

Controlling the screen

Often commands with lots of output will cause the screen to scroll. To pause the output, press Control-BREAK (ie Control-F3). HOLDING will appear at the top of the screen. Press an editing key like Control-Tab to resume.

You can also make it pause automatically after every n lines by typing ESC n E, ie to pause after every 20 lines press the keys F2 2 0 E. The important thing here is that you must enter this command while a program is running, and it only has effect for the life of that program, ie you can't set it once at the monitor level and have it apply to all programs.

In summary:

Control-BREAK Pause output; press Control-Tab to resume
ESC n E Pause display after n lines
ESC E Turn off pause display

To control the WHO line at the top of the screen:

ESC W Display a who line at the top of the screen
BREAK W Turn off the who line
ESC Q Display your next job in the who line

There are also other controls to adjust the position and pane of glass behaviour which I have not yet found much use for - see section 2 of the Monitor Command Manual, linked below for details.

The Data Disc terminal

/images/waits/waits-simh-dd.png The Data Disc display on simh. Source: Rupert Lane. License: CC0.

The Data DIsc terminal was the more common of the two terminal types at SAIL. It used a modified TV set to display pixel graphics and text; the name came from the controller which used tracks on a hard disk to store pixel data to be sent to the screen. It also had a video switch so you could select video from TV cameras used in lab experiments and even broadcast TV signals. There's a footmote in the Monitor manual that says:

The first edition said, at this point, "Thus, BREAK S at 6pm on a weekday selects Star Trek." However, I understand that we are being spared that this season.

This terminal is not supported on the saildart emulator yet. On simh, it is emulated but has several problems with scrolling (see this issue for details). You can try this out by changing set dd disable to set dd enable in the run.ini file in the quickstart and restarting the emulator.

Further information

You can find out more about the SAIL keyboard, along with pictures, at Xah Lee's site and in an issue created by Lars Brinkhoff on the Github PDP-10 organisation.

This 1975 video shows the Stanford DD display terminals in action.

The Monitor Command Manual section 2 describes the display terminal in more depth.

Questions, corrections, comments

June 2026: Corrected numbers and availability of display terminals, from a comment by Lars Brinkhoff.

I welcome any questions or comments, and also especially any corrections if I have got something wrong. Please email me at rupert@timereshared.com and I will add it here and update the main text.


WAITS: A quick tour using simh

In this post I will show how to get the 1974 snapshot of WAITS running using the simh emulator. We'll use the command line on the console, run a AI program from 50 years ago, write a short program and use the display terminal for some vector graphics.

/images/waits/waits-simh.png Running WAITS on simh. Source: Rupert Lane. License: CC0.

The quick start repo

I have put together a repo on Github that uses Richard Cornwell's KA PDP-10 simh emulator along with a ready-to-use disk image of WAITS from Lars Brinkhoff's sailing-on-arpanet project. This builds on the simh disk images from Richard Cornwell and ultimately Bruce Guenther Baumgart's saildart archive.

To use this, you will need a Unix-like environment capable of running a shell, git, make, a C compiler, bunziip2 and the SDL library. An optional requirement is a telnet client. See the README for more details.

First, clone the repo and cd into it

git clone https://github.com/timereshared/stanford-waits-simh-quickstart.git
cd stanford-waits-simh-quickstart

Then type ./build.sh. This will

  • Download opensimh using git and compile the pdp10-ka emulator binary.
  • Download a copy of the WAITS disk images.
  • Apply some missing system files.

Start WAITS

Type ./run.sh. An III display terminal window will pop up, and the system will boot, showing the below on the main console window.

Stanford 6.17/K 08-16-74

CTY	SYSTEM LOADED ON (date, time)

Using the WAITS CLI

The main window now acts as the PDP-10 console. You can log into it using the LOGIN command which can be abbreviated as L. As this is a snapshot of a live system, it has several accounts set up already. Let's use REG, which was the account of Ralph Gorin, a system programmer at SAIL. By defailt, no password is needed so just type L 1, REG

L 1,REG
JOB 1    STANFORD 6.17/K 08-16-74
FRIDAY  26-JUL-74       1105


EXIT
^C
.

It prints EXIT and ^C to show the login job has finished, then prompts you to enter commands with a dot.

Type TTY FULL to let it use upper and lower case letters (the console would normally only print capitals).

If you have tried TOPS-10 the interface will look familiar, and indeed most of the commands work the same way. Type DIR to get a directory listing; you can use wildcards to limit the search, so to find all SAIL programs:

.dir *.sai

26-JUL-74  1132
FILNAM  EXT   SIZE LAST WRITTEN

   [1,REG]
FORTUN  SAI    256  30-MAY-72
        TOTAL=   256


EXIT
^C

You can view the contents of files by using the TYPE command, so to see the above you'd enter TYPE FORTUN.SAI

The help system is invoked by typing HELP; to see a summary of commands type HELP HELPER.

.help helper
ALIAS   Command to change default directory used for disk files
ARPA    Basic information for users from other ARPA network sites
ASSIGN  Command to acquire use of non-sharable device
ATTACH  Command to attach terminal to a detached job
BINCOM  Program to compare binary files
...

Running programs

As a snapshot of a running system rather than a freshly installed but blank operating systen, there are several commands available to run that were created by the researchers at the AI Lab. One example is PARRY, which was an attemp by psychiatrist Kenneth Colby to simulate a person with paranoid schizophrenia. You can invoke this with the R command. It asks you some questions to set up the parameters for the interaction than lets you start talking to Parry. Press Control-C to exit.

.r parry

END INPUT PARAMETERS WITH CARRIAGE RETURN OR ALTMODE

PRINT NON VERBAL FEATURE? [Y,N]
*y
[...] 
END INPUT WITH A PERIOD OR QUESTION MARK, 
   FOLLOWED BY CARRIAGE RETURN. 
TO INDICATE SILENCE, TYPE   . 
   WHEN FINISHED, TYPE   BYE. 
USE PERIODS ONLY AT THE ENDS OF SENTENCES,
   NOT IN ABBREVIATIONS.

READY:
*why is the sky blue?

THAT'S THE WAY IT GOES

READY:
*tell me about your past.

I'M QUITE UPSET

READY:
*why are you upset?

PEOPLE GET ON MY NERVES SOMETIMES

READY:
*^C
^C

Creating a simple program

Let's create a simple hello world program using Fortran. We will use the SOS editor to create the source file then compile it and run it.

Type CREATE HWORLD.F4 to create a new file and put us in the editor. As this is a new file, the editor will allow you enter text immediately. It will precede each line with a line number (which is not a Fortran label) automatically. So the screen will look something like this after you run CREATE

.create hworld.f4
00100

Type the following program. Where you see below you should press the Tab key rather than typing spaces.

	DO 1 J=1,5
1 	WRITE(5, 2)
2 	FORMAT(' HELLO, WORLD')
	END

Type Alt-mode (which is Esc on your keyboard) to exit input mode, and then type e at the * prompt to save and exit. Finally type exec hworld.f4 to compile and run the program. Your screen will look something like the below.

.create hworld.f4

00100           DO 1 J=1,5
00200   1       WRITE(5, 2)
00300   2       FORMAT(' HELLO, WORLD')
00400           END
00500   $
*e

EXIT
^C
.exec hworld.f4

FORTRAN:  HWORLD.F4
LOADING

LOADER 5K CORE
EXECUTION

HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
EXIT
^C
.

The program is still in core memory at this point, so if you want to save a permanent copy to disk use the SAVE command

.save hworld
JOB SAVED IN 4K

^C

If you now use DIR you can see the files you created.

.dir hworld.*

26-JUL-74  1122
FILNAM  EXT   SIZE LAST WRITTEN

   [1,REG]
HWORLD  F4      19  26-JUL-74
HWORLD  DMP    3.5  26-JUL-74
HWORLD  REL     57  26-JUL-74
        TOTAL=   3.6

EXIT
^C

The .rel file is the object code and the .dmp the executable, which you can run again by typing RUN HWORLD (RUN rather than R as R is for system programs)

Using the display terminal

So far we've done everything using the console, but you probably noticed the III display terminal that appeared when simh started with its welcoming prompt.

/images/waits/waits-iii-prompt.png Prompt on WAITS display terminals. Source: Rupert Lane. License: CC0.

All the login and command line programs we have used so far will work on this terminal as well. But this is a vector terminal that can draw text and graphics, along with a keyboard that can enter more characters than the traditional teletype.

Let's login this time as BGB, the main archivist of the saildart.org site. Type L 1,BGB and then try a few commands. You will note that pressing Delete will delete the last character rather than reprinting it as it does on the teletype; in fact there is an extensive command line editor which we will look at in a later post. A warning: the system does not handle type-ahead that well, so it's best to type slowly.

The video display can show more than just the interaction with the monitor command line. Press F2 then W and a dynamic display of system usage will appear at the top of the screen - called the WHO line. Press F3 and then W to turn it off. A more extensive set of system information cab be displayed in the main area by typing WHO; press any key to exit.

Next, type COPY MON ← MONCOM.BH[S,DOC]: you can get the left arrow by pressing your left cursor keu. And then type TV MON.

This will open up the TV editor on a copy of the monitor command manual. Type Control-P to advance by page and Control-minus then Control-P to go back. Press Control-Alt-E to exit back to the prompt.

/images/waits/waits-tv-editor.png Running the TV editor. Source: Rupert Lane. License: CC0.

There are also a number of graphical demos. Try running each of these with R, eg R DAZZLE

  • armdpy
  • dazzle
  • hypno
  • petal
  • repent

When done with each, press F1 twice and type CORE 0 to clear the screen.

/images/waits/waits-iii-display-hacks.png Display hacks running on the III. Source: Rupert Lane. License: CC0.

Maybe finish with a game? Two which have graphical versions for the III are Go (R IIIGO) and AI Monopoly (R MONPLY).

/images/waits/waits-games-montage.png Two games on the III. Source: Rupert Lane. License: CC0.

Logging off and shutting down the system

Type K, short for KJOB on any logged in terminal to log off. Or get a more personalised signoff by typing K/ME.

There is no procedure to shut down the operating system. Just switch over to the main simh window, press Control-E and type q.

You can restart the operating system with ./run.sh as needed.

Further information

Read the Monitor Command Manual on saildart.org for more information on WAITS commands (this was the document we saw in the TV edit session above).

See PARRY Parries Again for a recreation of a dialogue between ELIZA and PARRY.

Questions, corrections, comments

June 2026: Corrected program compilation example to use e to exit SOSt and then to type the exec monitor command, rather than the g command in SOS, as g will not work until you have done the first compile/exec command.

I welcome any questions or comments, and also especially any corrections if I have got something wrong. Please email me at rupert@timereshared.com and I will add it here and update the main text.


Stanford WAITS

WAITS was the operating system for the PDP-6 and PDP-10 at the first incarnation of the Stanford AI Laboratory (SAIL), running continuously from 1966 to 1991. Uniquely, its full file system was preserved and a snapshot of the system can be run under emulation.

/images/waits/sail-collage.jpg Collage of images from a visit from DEC staff to SAIL, 1976. Source: CHM.

SAIL was founded by John McCarthy in 1963 (before Stanford even had a CS department) with 6 researchers. This grew to 128 people by 1973, by which time the lab had became one of the principal centres for AI research. Work spanned robotics, heuristic programming, NLP and computational theory. Among its alumni were Arthur Samuel, Raj Reddy, Hans Moravec and Alan Kay. Several people not associated with AI also made the lab their home, including Whitfield Diffie, John Chowning and Donald Knuth.

SAIL started out with a PDP-1, for which they implemented a time-sharing system with interactive displays. No traces of this remain, but there is an amusing film about its superiority to batch computing. In 1966, they got a PDP-6. WAITS started off as a version of DEC's Monitor (the forerunner of TOPS-10) but was extensively modified to suit the needs of the lab. It was notable for its support of experimental peripherals - robot arms, autonomous vehicles, display terminals, audio/visual support, and the XGP, one of the first laser printers. Over its lifetime it moved from the PDP-6 to the PDP-10 KA in 1968 and then the KL, added paging (from Tenex) and more memory and disk. As of 1973, it had 256k words of memory, 86M words of disk and 64 display terminals. It was one of the first machines connected to the Arpanet. It was also installed on machines outside of SAIL for a brief time, including at Lawrence Livermore National Labs.

On the software side, most AI research was done in Lisp, but it also spawned its own dialect of Algol called SAIL, and a powerful assembler called FAIL. It had several text editors that made use of its interactive terminals, and had document compilers that could use the XGP, including the first version of TeX.

Incidentally, the name WAITS was adopted several years after the system was introduced, and there are multiple explanations for the name: Western AI Time-sharing System, West coast Alternative to ITS, Worst Acronym for a Time-sharing System, or simply that it waits on you hand and foot.

Preservation status

/images/waits/saildart.org.png Screenshot of saildart.org. Source: Rupert Lane. License: CC0.

The complete backup tapes for WAITS have been preserved and are available for access. Bruce Guenther Baumgart, who worked at SAIL, was asked by John McCarthy to preserve the tapes produced by the DART archive tool when the system was shut down. He has built an amazing archive site, saildart.org, where you can access files, documents and other information about the system. (Personal files are not publicly available.)

For most operating systems we will look at, we only have the material to install the officially published software. But in this case we have the full file system, so we get to see all the surrounding files that made up a living system. Most of the documentation for WAITS was produced on WAITS, so it is available in its original digital form. Also, as an incremental backup, we can see how files changed over time.

Beyond the file archive, Bruce has produced a snapshot of the system as of July 1974 - representative of the lab's peak activity period - that can be used by emulators.

Emulation status

There are two emulators for WAITS.

/images/waits/waits-saildart-emu-montage.png WAITS running on saildart.org's emulator. Source: Rupert Lane. License: CC0.

Bruce has produced an emulator that uses the 1974 snapshot and runs in your web browser at saildart.org. This has demonstrations of a number of interesting systems such as SUDS, the Stanford University Drawing System. It also has interactive access to the complete system using either the console or the III display terminal, so you can login and run commands. Without any additional setup, this allows you to try out the system, but note that your work is not persisted across sessions.

/images/waits/waits-simh.png WAITS running on simh. Source: Rupert Lane. License: CC0.

Richard Cornwell has adapted his simh PDP-10 KA emulator to incorporate some of the special hardware used by WAITS, and has provided disk images on his site. The emulator contains support for the III and DD display terminals, along with networking capabilities, which Lars Brinkhoff is currently trying to recreate its Arpanet connection at sailing-on-arpanet. The simh version needs some set up, but does allow you to import/export files and keep your changes over several runs of the system.

One important thing to note: neither emulator has complete coverage of WAITS features, and some programs do not work. This is not due to lack of effort on the part of the authors, rather due to the non-standard nature of the SAIL hardware, which often lacks docs and diagnostics, and the fact this is a snapshot of a running system rather than an official release.

Topics

In this series of blog posts I plan to cover

  • A quick tour of running WAITS on simh
  • Using the terminals
  • Files and directories
  • Users, jobs and security
  • Utilities and tools
  • Text editors
  • Getting data in and out of the system
  • Printing and documentation tools

    • The XGP
    • PUB
    • POX
    • TeX
  • Programming

    • SAIL
    • LISP

The main focus of this blog is the operating system and its associated tools, so I will not look in detail at all the user programs available on WAITS - but if time permits, I will try to cover some interesting examples.

Further information

For background information on the PDP-10, see my previous article.

As mentioned, there is a great deal of information on saildart.org. A good place to start is the booklet which gives an overview of SAIL WAITS, and the archive project. The Visitor 1976 gives a photo tour of the lab along with some of its equipment and people.

For more detail, look at the collection of AI Memos and SAIL Operation Notes, or dig further into specialised areas on the main page such as music.

References to files on the SAIL system can be viewed by prepending saildart.org. For example, to read the Lisp manual LISP.WD[S,DOC] you would go to https://www.saildart.org/LISP.WD[S,DOC]

AI Memo 228 gives a good overview of the work done at SAIL in its first 10 years.

Regarding the PDP-1 system that preceded WAITS, the Stanford archive The History of Artificial Intelligence has some interesting material, eg Time Sharing Implementation on the PDP-1 and the User's Guide.

Questions, corrections, comments

June 2026: Added links to more PDP-1 material.

I welcome any questions or comments, and also especially any corrections if I have got something wrong. Please email me at rupert@timereshared.com and I will add it here and update the main text.


Site Update

That's all, for now, on TOPS-10. I've concentrated on the roughly pre-1975 era, using the PDP-10 KA CPU and operating system version 6.03; I may come back to this in the future and look at later versions if I find anything interesting.

Next update to this blog will be in June, where we will look at the Stanford University A.I. lab's operating system for the PDP-10, WAITS. This started out as a version of DEC's PDP-6 Monitor (which became TOPS-10) but WAITS evolved over the years to add support for experimental peripherals - display terminals, laser printers, robotics - and many interesting software features, as well as being an important platform for A.I. research.

As a taste of WAITS, here's a small demo I was involved in recently. PARRY, a chat program that mimics a paranoid patient, was written by Kenneth Colby on WAITS in 1972. Using simh, Lars Brinkhoff got PARRY running on WAITS for the first time in many years. I then got this talking to the ELIZA chat program running on CTSS, recreating a dotctor/patient dialogue done in 1973 as RFC 439. See Jeff Shrager's writeup, PARRY Parries Again, for more details.

Questions, corrections, comments

May 2026: Lars Brinkhoff correctly pointed out that WAITS derived from the PDP-6 Monitor rather than TOPS-10.

I welcome any questions or comments, and also especially any corrections if I have got something wrong. Please email me at rupert@timereshared.com and I will add it here and update the main text.


TOPS-10: Essex BCPL

BCPL - Basic Combined Programming Language - is probably best known as the ancestor of the C programming language made famous by Unix. But BCPL was an important and widely used language in its own right. First implemented by Martin Richards for CTSS, it spread to many different architectures during the 1970s, especially in the UK where it was used for teaching computer science, AI and in industry.

(Incidentally my first ever job, as an intern in 1990 working for the former British semiconductor company Inmos, was writing CAD tools using BCPL on a micro-VAX).

Essex BCPL for TOPS-10

The version we are looking at today for TOPS-10 is from the University of Essex and dates from the mid 1970s. The original compiler by Richards generated machine code for a generic stack machine, called OCODE, and the compiler itself was available in OCODE, so it was easy to port to new machines. Essex produced a version for the ICL 1900 to start with, and moved this across to TOPS-10 on their new PDP-10 in 1970. They then rewrote the compiler to remove the OCODE layer and improve performance.

This second implementation of BCPL is included in the TOPS-10 6.03 disk images we are using so there are no special set up instructions. The compilation system recognises files with a .BCP extension by default. Here's what a hello world program looks like and how to run it:

.type hello.bcp
GET "BCL:BCPLIB"
LET START() BE
$(
	WRITES(TTY,"Hello, world*C*L")
$)

.execute hello.bcp
BCPL:  HELLO	400031/2	32%
LINK:	Loading
[LNKXCT BCPL Execution]
Hello, world

EXIT

TPK in BCPL

Let's use the compiler to run the TPK algorithm. The source code can be found here. This can be loaded onto the disk using the techniques described in this article.

The TPK formula (√|x | + 5x³) is implemented as a function with a single expression:

LET TPK(X) = SQRT(#ABS X) #+ 5.0 #* X ** 3

As BCPL is typeless, different operators are needed for floating point and integer arithmetic such as #+ for floating point add. Note also that #ABS is a unary operator.

However, we have a problem in that SQRT is not part of the language library at this point in history. We can implement it using the Babylonian approximation:

LET SQRT(X) = VALOF
$(
    LET X1, X2 = X, X #/ 2.0
    WHILE #ABS (X1 #- X2) #> 0.0001 DO
    $(
        LET OLD = X2
        X2 := 0.5 #* (X1 #+ (X2 #/ X1))
        X1 := OLD
    $)
    RESULTIS X2
$)

This uses a VALOF expression which yields its results using RESULTIS. As there is more than one statement we use a block, marked by $( ... $). Semicolon can be used to separate statements, but is not needed if there is a single statement per line.

Inside the block we define a variable, LET OLD = X2, but note that assignment uses := ad plain = is used for comparison.

With this, we can supply the driving logic in START, BCPL's equivalent of C's main.

// Define constants
MANIFEST $( N = 11; IOVS = 300 $)

// Main program
LET START() BE
$(
    LET A = VEC N
    LET IOVECTOR = VEC IOVS
    INITIALISEIO(IOVECTOR, IOVS)
    WRITE(TTY, "Please enter :N numbers*C*L", N)
    FOR J = 0 TO N-1 DO A!J := RDF(TTY)
    WRITE(TTY, "Results are*C*L")
    FOR J = N-1 TO 0 BY -1 DO
    $(
        LET R = TPK(A!J)
        TEST R #> 400.0 THEN
            WRITE(TTY, "Too large*C*L")
        OR
            WRITE(TTY, ":F*C*L", R)
     $)
$)

BCPL allows both single line comments with // and block comments with /* ... */. C initially only took block comments, with single line comments first re-implemented by C++ and coming back to C in the 1999 standard.

MANIFEST sets up compile time constants, which we can use when declaring the stack vector LET A = VEC N. Elements of this vector can be accessed using infix !, eg A!2. Two FOR loops are used, one counting forwards to read in numbers and the second counting backwards to calculate and print results. BCPL has IF, but it only supports a single clause for the true case; TEST ... THEN ... OR supports both true and false cases.

I/O is done using RDF to read in a single floating point value and WRITE for output. I/O is stream based, and we use the predefined value TTY to communicate with the user's console. INITIALISEIO is needed before we use I/O to allocate buffers. WRITE supports output of different types using : as positional markers, eg :F for a floating point number. *C*L in the string means carriage return / line feed.

A full transcript of the program execution can be found here.

Further information

The Github PDP-10 organisation has the essex-bcpl repo which contains the source tape and manual for the version of the language. There is also MUD1 which is an early multi-user dungeon written in BCPL; this looks like it needs TOPS-10 7.03 and a KI CPU to run, however.

A completely separate implementation of BCPL on TENEX from BBN can also be found at tenex-bcpl.

The Computer History Museum Software Preservation Group has a detailed history of BCPL, including links to documents, papers and other implementations.

The classic reference to BCPL (and what I originally leaned the language from) is "BCPL - the language and its compiler" by Martin Richards and Colin Whitby-Strevens; there's a copy at the Internet Archive.

Martin Richards continues to work on BCPL and his home page has links to implementations for modern computers.

Questions, corrections, comments

I welcome any questions or comments, and also especially any corrections if I have got something wrong. Please email me at rupert@timereshared.com and I will add it here and update the main text.


Next →