Jump to content

HP Time-Shared BASIC

From Alfawiki
Hewlett-Packard
IndustryComputer software, Computer hardware
FoundedJanuary 1, 1939; 87 years ago (1939-01-01)
Headquarters
Palo Alto, California
,
United States
ProductsHP Time-Shared BASIC, HP 2000 minicomputer
Websitewww.hp.com

HP Time-Shared BASIC (HP TSB) is an interpreter for the BASIC programming language created by Hewlett-Packard specifically for the HP 2000 minicomputer-based time-sharing environments. It gained recognition for distributing the earliest public versions of the text-based game Star Trek.

The platform provided a version of BASIC alongside a fundamental user account system and a program repository, facilitating simultaneous access for multiple users. During the early to mid-1970s, Hewlett-Packard maintained a catalog of user-submitted programs that clients could purchase on punched tape media for a fee.

Most BASIC variants from the 1970s originated from Dartmouth BASIC, which initially did not support string variables. HP introduced string manipulation through array slicing techniques similar to those in Fortran, differing from DEC’s subsequent MID/LEFT/RIGHT string functions. With the rise of microcomputers in the mid-1970s, many BASIC dialects adopted syntax influenced either by HP or DEC versions. For instance, Microsoft's Altair BASIC was based on DEC's BASIC-PLUS, whereas Apple's Integer BASIC and Atari BASIC followed HP's conventions, resulting in challenges for cross-platform string code compatibility.

Nomenclature

The software’s name often reflected the specific hardware model it operated on, such as HP 2000C Time-Shared BASIC. Operating system versions included 2000A, 2000B, 2000C, High-Speed 2000C, 2000E, and 2000F.

During its initial release phase, HP briefly promoted the language under the name "Access BASIC" alongside devices branded as "2000/Access."

Platform details

Apart from the 2000A and 2000E models, this system employed a dual-processor design: one HP 2100-series CPU executed both system and user programs, while a secondary, smaller HP 2100 processor handled RS-232 serial communications for time-sharing connections. Depending on setup, these systems could accommodate between 16 and 32 concurrent remote users.

Users generally connected through Teletype Model 33 ASR terminals either directly or via modems or acoustic couplers. Account identifiers consisted of one letter followed by three digits (e.g., B001), with privileged accounts beginning with "A"—the highest-level superuser account being A000—allowing a maximum of approximately 26,000 accounts.

During execution, user programs were swapped onto a fixed-head disk drive functioning similarly to magnetic drum memory; when idle, they were stored on moving-head cartridge or pack-loaded disks. Users with elevated privileges had the option to save programs on the faster drum storage. Magnetic tape was utilized for data backup purposes.

Program and file names could be up to six alphanumeric characters long and were saved in tokenized form using the SAVE command or in a semi-compiled format via CSAVE to enable quicker startup times. Files used carriage return and linefeed characters as line terminators to support teleprinter terminal compatibility.

Syntax

This language implements a standard BASIC interpreter featuring an integrated editing and runtime environment. Syntax is validated upon entry and stored in tokenized form. Each line of BASIC code requires a unique line number; for example:

<syntaxhighlight lang="basic">10 PRINT "HELLO WORLD"</syntaxhighlight>

Line numbers are compulsory and lines are automatically ordered numerically. Unlike MS BASIC, each TSB line contains only one statement; however, multiple variable assignments per line are permitted, such as <syntaxhighlight lang="basic" inline>20 LET A=B=C=42</syntaxhighlight>. The use of the "LET" keyword is optional.

The initial release (model 2000A) supported these features with later versions expanding capabilities:

  • Unconditional jumps using GOTO, and subroutine calls with GOSUB and RETURN
  • Conditional branching via IF/THEN
  • Computed control flow using GOTO/OF and GOSUB/OF
  • Looping constructs through FOR and NEXT
  • Embedded data storage using DATA, READ, and RESTORE
  • User input/output from terminals or disk files employing INPUT, READ #, PRINT, PRINT #, and IF END #
  • Numeric variables named by a single letter or letter-digit combination (e.g., "A" or "A1")
  • String variables designated by a letter followed by "$" (e.g., "A$"), capable of storing between 1 and 255 characters; also supported were variants like "A0$" or "A1$"
  • One- or two-dimensional arrays expressed as "A[x]" or "A[x,y]"
  • Matrix operations facilitated through statements (MAT READ, MAT INPUT, MAT PRINT, MAT=) and functions (+, -, *, ZER, CON, IDN, INV, TRN)
  • Boolean logic operators (AND, OR, NOT) alongside relational operators (<, <=, =, #, <>, >=, >)
  • Built-in mathematical functions including trigonometric (SIN, COS, TAN, ATN), logarithmic (LOG, EXP), square root (SQR), random number generation (RND), plus others like (ABS, INT, SGN, MIN, MAX)
  • Support for punched tape operations when using Teletype Model 33 terminals

String manipulation

In TSB, strings are managed as character arrays instead of single entities containing multiple characters. By default, each string reserves space for one character in memory, so longer strings require prior declaration. For instance, <syntaxhighlight lang="basic" inline>DIM A$[10]</syntaxhighlight> defines a string with a capacity of up to 10 characters. The maximum allowable string length in TSB is 255 characters.

To extract substrings, TSB employs slicing syntax: <syntaxhighlight lang="basic" inline>A$(L,R)</syntaxhighlight> or <syntaxhighlight lang="basic" inline>A$[L,R]</syntaxhighlight>, where L and R denote the start and end positions of the desired substring. Using <syntaxhighlight lang="basic" inline>A$[L]</syntaxhighlight> retrieves the substring from position L through to the end. Both parentheses and brackets serve interchangeably for this purpose, with indexing beginning at 1.

This method differs from DEC-style BASIC dialects that utilize functions such as LEFT$(), MID$(), and RIGHT$(). ANSI BASIC adopted similar slicing conventions inspired by Hewlett-Packard’s implementation. HP’s syntax permits direct modification of string segments, for example: <syntaxhighlight lang="basic" inline>100 A$[3,5]="XYZ"</syntaxhighlight>, a capability not supported by earlier LEFT/MID/RIGHT function versions.

The key benefit of TSB’s design lies in simplified memory management, eliminating the need for complex procedures found in MS BASIC that compress heap space when strings vary in length. MS BASIC’s memory handling was notably slower and underwent continuous refinements to improve speed and fix bugs. However, a drawback of TSB’s fixed-length strings is that DIMed strings always consume their full allocated size even when empty, which can lead to overflow during concatenation unless initially oversized.

Subsequent Dartmouth BASIC releases, including BASIC-PLUS and MS BASIC, retained string variables but replaced LEFT/MID/RIGHT functions with the CHANGE command that converts strings into ASCII codes; HP implemented a comparable CONVERT command. Moreover, numeric constants could be transformed into ASCII characters using single quotes, facilitating string assembly without relying on CHR$(). For example, <syntaxhighlight lang="basic" inline>A$='23 '64 '49 "DEF"</syntaxhighlight> results in the string "ABCDEF".

MAT commands

Later iterations of Dartmouth BASIC introduced the MAT statement, which enables operations on entire arrays (matrices) through a single instruction. This feature was also incorporated into later versions of TSB. The MAT keyword functions as an alternative to LET, applying expressions across all elements within an array simultaneously. For example: <syntaxhighlight lang="basic"> 100 DIM A(20),B(20) ... 200 MAT A=A+B </syntaxhighlight> adds corresponding elements of array B to array A element-wise, equivalent to: <syntaxhighlight lang="basic"> 100 DIM A(20),B(20) ... 200 FOR I=1 TO 20 210 A[I]=A[I]+B[I] 220 NEXT I </syntaxhighlight> This approach reduces code length and enhances performance by optimizing beyond traditional FOR/NEXT loops. Additional MAT commands enable streamlined operations such as modifying output with PRINT, accepting input via INPUT, inverting arrays, and generating identity matrices—all achievable with concise statements.

Additional distinctions

TSB incorporates several subtle yet important variations compared to other BASIC versions:

  • The symbol # can optionally represent the not-equal operator, functioning identically to <>.
  • Computed GOTO using ON...GOTO/GOSUB is not supported. Instead, line selection is performed with GOTO expression OF 1,2,3..., where the expression determines the ordinal position of the target line number. For example, <syntaxhighlight lang="basic" inline>GOTO 1 OF 10,20,30</syntaxhighlight> transfers control to line 10; similarly, <syntaxhighlight lang="basic" inline>GOTO A OF 100,200,300</syntaxhighlight> branches according to the value held in A.
  • Within mathematical contexts, Boolean and relational operators yield 0 for false and 1 for true. This behavior is unusual among BASIC dialects but resembles that of C. For instance, <syntaxhighlight lang="basic" inline>IF C+D THEN 1600</syntaxhighlight> executes a branch if either C or D holds a positive value.
  • The ENTER command extends the functionality of INPUT by allowing input with a time constraint. It takes three arguments: the time limit in seconds, a variable to store elapsed time or status, and the input variable itself. For example: <syntaxhighlight lang="basic" inline>ENTER 15,T,A$[1,1]</syntaxhighlight> waits up to 15 seconds for user input; T captures the elapsed time or error information.
  • When printing string literals alongside variables using PRINT, semicolons are not necessary between strings and variables. For example: <syntaxhighlight lang="basic" inline>PRINT "THE NUMBER IS"A", TRY A LARGER VALUE."</syntaxhighlight>
  • Commas within a PRINT statement insert tab stops spaced every 15 characters, leaving a margin of 12 characters at the end of a 72-character line.
  • The function LIN serves as a vertical tab mechanism: calling <syntaxhighlight lang="basic" inline>LIN(3)</syntaxhighlight> inserts three carriage returns; invoking <syntaxhighlight lang="basic" inline>LIN(-1)</syntaxhighlight> moves to the next line unconditionally. This feature is comparable to Integer BASIC’s <syntaxhighlight lang="basic" inline>VTAB</syntaxhighlight> command.

See also

Bibliography

  • , Part No. 22687-90001
  • , Part No. 22687-90009


External links