HP Time-Shared BASIC
HP Time-Shared BASIC is a BASIC programming language interpreter for Hewlett-Packard's HP 2000 line of minicomputer-based time-sharing computer systems. TSB is historically notable as the platform that released the first public versions of the game Star Trek.
The system implements a dialect of BASIC as well as a rudimentary user account and program library that allows multiple people to use the system at once. The systems were a major force in the early-to-mid 1970s and generated a large number of programs. HP maintained a database of contributed-programs and customers could order them on punched tape for a nominal fee.
Most BASICs of the 1970s trace their history to the original Dartmouth BASIC of the 1960s, but early versions of Dartmouth did not handle string variables and vendors added their own solutions. This led to two general styles; DEC introduced the
MID/LEFT/RIGHT
functions, while TSB used a system more akin to those in FORTRAN 77 or C where strings are arrays of characters and are parsed using array slicing syntax.As microcomputers began to enter the market in the mid-1970s, many new BASICs appeared that based their parsers on DEC's or HP's syntax. Altair BASIC, the original version of what became Microsoft BASIC, was patterned on DEC's BASIC-PLUS. Others, including Apple's Integer BASIC, Atari BASIC and North Star BASIC were patterned on the HP style. This made conversions between these platforms somewhat difficult if string handling was encountered.
Nomenclature
The software was also known by its versioned name, tied to the hardware version on which it ran, such as HP 2000C Time-Shared BASIC and the operating system came in different varieties — 2000A, 2000B, 2000C, High-Speed 2000C, 2000E, and 2000F.HP also referred to the language as "Access BASIC" in some publications. This matched the naming of the machines on which it ran, known as the "2000/Access" in some publications. This terminology appears to have been used only briefly when the platform was first launched.
Platform details
Except for the 2000A and 2000E systems, the system is implemented using a dual-processor architecture. One fully configured HP 2100-series processor is used for the execution of most of the system code and all of the user code, while a second, smaller HP 2100-series processor is used to handle the RS-232 serial lines through which the time-sharing users connected. Depending on the hardware configuration, the system supports up to 16 or up to 32 simultaneous remote users.The usual terminal for a TSB system was a Teletype Model 33 ASR and connected directly to the I/O processor or through a modem or acoustic coupler. Account names are a combination of one alphabetic character, followed by three decimal digits, e.g., B001. Privileged accounts started with the letter "A" and had some additional command and program storage capabilities. The superuser account is A000. This scheme allows up to 26,000 user accounts.
During execution, user programs are swapped to a fixed head drive — physically a disk, but operating like a magnetic drum. When not executing, user programs are stored on moving-head cartridge- or pack-loaded disk storage. Privileged users can also store programs on the much-faster drum. The hard drive was backed up to magnetic tape.
Program and file names consist of a mix of up to six alphabetic characters and numbers. Programs are stored in a tokenized format, using the SAVE command. They can also be stored in a semi-compiled format, using the CSAVE command, which allows them to start quicker. Since the system was closely tied to the use of commonly available teleprinters, line endings in files consisted of the carriage return character, followed by the linefeed character.
Syntax
The language is a fairly standard implementation of BASIC, providing an integrated editing and runtime environment. Statements are analyzed for correct syntax as they are entered and then stored in tokenized form. Each BASIC statement has to be on a uniquely numbered line, e.g.Line numbers are mandatory, and statements are automatically placed in ascending numeric sequence. TSB lines can contain one statement, chaining multiple statements with the colon as in MS BASIC is not supported. Multiple variable assignments are allowed, e.g.,
In the earliest version, the language supported the following features. Later versions added many more features.
- Unconditional program flow-control via
GOTO
statements, and subroutines via theGOSUB
andRETURN
statements - Conditional flow-control via
IF/THEN
statement - Calculated flow-control via the
GOTO/OF
andGOSUB/OF
statements - Variable-based block loop
FOR
andNEXT
statements - In-code data storage via
DATA
,READ
, andRESTORE
statements - Input from and output to the user or a disc file via
INPUT
,READ #
,PRINT
,PRINT #
, andIF END #
statements - Numeric variables of the form "A" or "An" stored as 32-bit floating-point numbers
- String variables of the form "A$", storing from 0 to 72 characters
- One- or two-dimensional matrix variables of the form "A" or "A"
- Matrix operations via statements and operations
- Boolean operators and relational operators
- Built-in mathematical functions including trigonometric, logarithms, square root, random number generator, others , and user-defined functions
- Punched tape operations using Teletype Model 33 electromechanical teleprinter remote terminals
String handling
DIM
entioned before use. For instance, Substrings within strings are accessed using a "slicing" notation:
This is in sharp contrast to BASICs following the DEC pattern that use functions such as
LEFT$
, MID$
, and RIGHT$
to access substrings, although ANSI BASIC continues to use a similar substring syntax to that introduced by Hewlett-Packard. HP's notation can also be used on the destination side of a LET or INPUT statement to modify part of an existing string value, for example The main advantage to this style of string access is that it eliminates the need for complex memory management that is otherwise required when string lengths change. MS BASIC had a lengthy library to handle the compression of memory by removing dead space in the string heap when the system ran out of memory. It was also notoriously slow, and was modified several times over its lifetime in order to improve performance or fixe bugs. The downside to the TSB style is that the string always takes up the full amount of DIMed space even if the string inside is empty, and simple tasks like concatenation can potentially overflow the string unless it was set to a large size to begin with.
Later versions of Dartmouth BASIC did include string variables, based on the same pattern found in BASIC-PLUS and MS BASIC. However, this version did not use the LEFT/MID/RIGHT functions for manipulating strings, but instead used the
CHANGE
command which converted the string to and from equivalent ASCII values. HP included identical functionality, changing only the name to CONVERT
. Additionally, one could use the single-quote to convert a numeric constant to an ASCII character, allowing one to build up a string in parts; A$='23 '64 '49 "DEF"
produced the string "ABCDEF", without the need for the CHR$
function.MAT commands
Later versions of Dartmouth BASIC included a suite ofMAT
commands that allowed operations on entire arrays with a single statement. These were also available in later versions of TSB. In their simplest form, the MAT
is used like an alternate form of LET
, applying an expression to all the elements in an array. For instance:100 DIM A,B
...
200 MAT A=A+B
Will add the value of every value in B to every entry in A, in the same fashion as:
100 DIM A,B
...
200 FOR I=1 TO 20
210 A=A+B
220 NEXT I
As well as making the code shorter and more obvious, these commands also have the advantage of being highly optimized, easily outperforming the use of FOR/NEXT. Additional functions and statements modify
PRINT
and INPUT
, invert arrays, and build identity matrixes and such in a single statement.Other differences
TSB also includes a number of more minor differences with other dialects. Among the most important are:-
#
is an optional form of the not-equal comparison, identical to<>
- computed-goto using the
ON...GOTO/GOSUB
syntax is not supported. Instead, theGOTO expression OF 1,2,3...
performs the same function by picking a line number from the list based on its ordinal position. For instance,GOTO 1 OF 10,20,30 will always go to line 10, whereasGOSUB A OF 100,200,300 will branch to different lines if the value of A is 1, 2 or 3. - Boolean and relational operators can be used in any mathematical expression, returning 0 for false or 1 for true, which was unusual for BASIC languages of that time, but popular in languages like C. For instance,
IF C+D THEN 1600 will branch to line 1600 if either C or D are greater than zero, because the expressionC+D
will evaluate to 'true' in theIF
. If C and D are both zero, theIF
will evaluate it to 'false' and the branch will not be taken. - TSB includes
ENTER
, a variation on the standardINPUT
statement that continues after a time limit is reached.ENTER
has three inputs, a time limit in seconds, a return variable containing the actual time elapsed, and then finally the user input. For instance,ENTER 15,T,A$ will wait 15 seconds for the user to type in a single character. T will contain the actual time they took, -256 if the timer expired, or -257 or -258 to indicate problems with the terminal. - When printing string constants, semicolons are not needed within the line. For instance,
PRINT "THE NUMBER IS"A", TRY A LARGER VALUE." does not require semicolons between the string constants and the variable A. Some other BASICs, including MS, also supported this syntax. Others, like Atari or Integer, did not. - Commas in
PRINT
use tab stops very 15 characters, leaving 12 at the end of the line to total 72. - The
LIN
function operates as a vertical counterpart toTAB
.LIN will insert three carriage returns, potentially on the existing line if a trailing semicolon or comma was active, while the special-caseLIN will always advance to the next line. Integer BASIC had a similar feature, calledVTAB .Citations