Internals of BASIC-PLUS
The original BASIC-PLUS from Digital Equipment Corporation was groundbreaking and influenced many BASIC systems following it. I will describe some of the unique capabilities of BASIC-PLUS.
To set the stage, the original BASIC-PLUS was designed in 1970 to run on DEC PDP-11/20 computers. The maximum amount of memory on early PDP-11s was 56KB. The total disk storage was only a few megabytes. There were two types of disks, one permanently enclosed with multiple fixed heads for each track of the disk, and a removable pizza platter type disk. The fixed disk could store approximately 1MB, and the pizza platter could store about 4MB. The fixed head disk was much faster and was mostly used for swapping programs to and from memory. Main memory was made out of magnetic cores which were small rings with two wires strung through each core wikipedia link. The CPU was made out of discrete components such as transistors and small integrated circuit chips for logic functions like NAND and NOR. The CPU was built on a single board that was plugged into a back plane that was used as a bus. (An aside, I misconstrued the lyrics of an Eagles song. They were living life in the Back Plane).
By 1980s standards, this machine was smaller than an IBM PC, Apple II, and TRS-80. Machines like this cost on the order of $10s of thousands of 1970 dollars. Home computers in the 80s were comparibly much cheaper and used integrated circuit CPUs. Machines in the 80s were used by a single person. Due to the cost of the PDP-11/20 it was necessary to maximumly use the resources of the computer. A single user typing commands to the computer wastes CPU cycles. The computer is spinning its wheels waiting for the user to press ENTER. These cycles could be used to support other users.
The 1970s were the heyday for time-sharing systems. As I’ve written before, time-sharing first appeared on mainframe computers in the 60s, then minicomputers in the 70s, which led to personal computers in the 80s. Through this entire arc, BASIC was a prominent programming language along with FORTRAN and COBOL.
The challenge for DEC in the early 70s was to develop a time-sharing system for the PDP-11/20 that could support 12 concurrent users communicating with the computer via Teletype machines. Each user would be given a virtual personal computer that acted like it was devoted to that user alone, when in fact it was doing the same for 11 other users. Each user was given 8KB of memory for their programs. Eight times twelve is 96KB of memory. To achieve this feat the RSTS-11 operating system swapped user’s Jobs (70s terminology for processes) to and from fixed head disk. Both CPU time and memory space had to be partitioned across 12 users. The scheme worked because most users are typing at any given point in time, which requires very little CPU time. Each keystroke would interrupt the machine, which would store the ASCII code in memory and then echo it back to the user’s Teletype to be printed on a roll of paper.
Printing also does not require too many resources. The printers were slow, about 10 characters per second. The operating system would collect a buffer of output and then pause the job while the output was being printed. This also resulted in free CPU cycles that could be shared with other users. It was only during the infrequent times when all jobs were CPU bound that users would truly experience how slow the machine really was. When sitting down to a Teletype it was common for the user to ask how slow the machine was that day.
BASIC-PLUS Language
The BASIC-PLUS language was very robust given the limited machine resources. BASICA from Microsoft/IBM, and later GW-BASIC from Microsoft were almost command to command, and function to function identical to BASIC-PLUS. But, BASIC-PLUS had several unique features that Microsoft never copied. The most significant ones were:
Incremental Compilation and Error Checking
Prior to execution all FOR-NEXT pairs were matched
Memory protection between users, where the CPU provided no hardware memory protection
Virtual arrays which could be stored on disk instead of memory
Innovative text editor that used a combination of disk storage and memory (a.k.a Core) to store users programs. At any point in time only one line of BASIC source was maintained in Core.
BASIC-PLUS’s main limitation was computer graphics. Most of the terminals were Teletype machines which printed characters onto a roll of paper. Even so, kids (kids were the primary users) did some interesting graphics using character cells. This included sine waves, biometric charts, Conway’s game of life, maze generation, maze solvers, and some interesting three dimensional images projected on a two dimensional piece of paper.
Some schools had CRT (Cathode Ray Tube) terminals. These were used in my school to give quizzes to kids in Chemistry class. It was not desirable to have the quizzes printed on paper. I was the unpaid maintenance programmer for these programs. This was a recurring theme for me, I was unpaid, but given more access to the computer.
One of the kids wrote an interesting game that animated a horse track with racing horses running around the track. This was on a CRT display directly connected to the computer with with a 960 character per second interface.
BASIC-PLUS Implementation
BASIC-PLUS was compiled via an incremental compiler. Each time a line was entered, the compiler would compile the line into PP-CODE. The code was based on reverse polish notation which used a stack for storing intermediate results. It was not necessary to store parenthesis, all that was left after compilation were push, math operations, and pops. For example the expression a+b*c was compiled into:
push a
push b
push c
multiply
add
pop
The expression (a+b)*c was compiled into:
push a
push b
add
push c
mult
pop
PP-Code was executed by a virtual machine, non-unlike what Java originally used. The PP-Code was very compressed, and source code was maintained on disk in a temporary file until permanently saved.
When the user started a new program with the NEW command, RSTS would create an empty temporary text file on disk. The file was named TMP##.TMP where ## was the users job number. When the user typed ENTER on a line, the incremental compiler would compile the text, and link the PP-CODE into a linked list based on line number. The ASCII text was appended to the end of the TMP file, and discarded from memory. A pointer was maintained from the PP-CODE back to the TMP file. If a line was changed there was no need to delete the line on disk, it would just be dangling and not pointed to by any PP-CODE in memory. The dangling lines would be removed and a new clean TMP file would be created whenever the user typed LIST or SAVE.
RSTS provided a COMPILE command, but it was misleading, the code was compiled when the user pressed ENTER. The COMPILE command simply saved the PP-CODE to disk in a file with the .BAC extension. Using these files it was possible to hide the source from other users. The operating system would not allow a user to open the file, and thus the PP-CODE was hidden from prying eyes. Due to the limitation of disk space most programs were SAVEd to disk in source form. A .BAS extension denoted these files. Many system functions, like LOGIN, were performed by BASIC programs. These programs were always saved in .BAC form. RSTS-11 also had a SETUID-like feature similar to UNIX. A utility like the UNIX ps program would have the privilege bit enabled.
BASIC-PLUS presented the user with the illusion that it was both compiled and interpreted. Programs ran somewhat faster than a fully interpreted language, and required much less space in memory. It was very similar to Java 1.0. The PP-CODE instructions were designed to wall off each user in their own section of memory. The code was non-modifiable and had no escape to machine language. The code was also position independent and could be moved from one location to another. This facilitated Job swapping. A Job could be written on swap disk, and then brought back into memory at a different location.
BASIC-PLUS also had an immediate mode, that allowed statements to be typed without a line number. They would be immediately compiled and run. Program variables could be read and changed in immediate mode. Breakpoints could be put in code via the STOP statement, and the CONT command would return following a breakpoint. After the STOP the user could view and change variables and then type CONT. It was also possible to press Control-C, view and change variables, and then enter CONT.
Checkpass
RSTS ran a so-called CHECKPASS prior to execution of a program. When the user typed RUN, the checkpass would match up FORs and NEXTs. FOR-NEXT loops had static scope. In other words no funky stuff like, IF-THEN-NEXT!! RSTS would also match DIM statements for virtual arrays with OPEN commands to open a file as the backing store for the array.
An amazing feat on engineering
It was amazing how capable BASIC-PLUS and RSTS-11 were in 1971 when I discovered two Teletype machines in my High School. In my minds eye I pictured dialing into a large computer at the Delaware Information Center for Education (DICE). I was shocked when I saw the computer and it was about the size of two refridgerators standing side by side. I’ve previously written about Project Delta that was the program overseeing the PDP-11.
The University of Delaware also had a program for High School students. They gave us access to an Electrical Engineering lab that had two PDP-8 computers and a half dozen Teletype machines connected to a Burroughs B5700 mainframe. I recently finished reading a book on the B5700/B6700 architecture and they were amazing machines.
what is "RSTS"?
Do you remember the SYS() commands, and things like SYS(CHR(-7)+CHR(8)) to disable full duplex for password entry?