Wang BASIC
| Company type | Software |
|---|---|
| Industry | Computer programming languages |
| Founded | Early 1970s |
| Founder | Wang Laboratories |
| Products | BASIC programming language variants for Wang 2200 minicomputer series |
Wang BASIC represents a collection of BASIC programming language variants created by Wang Laboratories mainly for their Wang 2200 minicomputer lineup during the early 1970s. With the 1976 introduction of the VP series, BASIC-2 became the prevailing version across later 2200 models. Although a BASIC-3 was planned, it never reached release.
The primary distinction among the 2200 series models lay in the volume of microcode embedded in read-only memory (ROM), which dictated the quantity of BASIC commands offered. For instance, the B model doubled the ROM capacity compared to the A model, incorporating additional input/output and file handling instructions.
Following the syntax of Dartmouth BASIC closely, Wang BASIC operated as an interpreter rather than a compile-and-run environment. It utilized double-precision binary-coded decimal (BCD) arithmetic, reflecting Wang’s background in business calculator technology. While it initially lacked some features found in later dialects such as Microsoft BASIC, many were incorporated with the arrival of BASIC-2.
Description
This section concentrates on the original BASIC version present in the 2200A. Subsequent models like 2200B and C introduced numerous extra keywords.
Program editing and execution
Wang BASIC shared similarities with standard Dartmouth BASIC interpreters by functioning in either immediate or program mode, automatically switching to program mode upon entering a line number. Line numbers ranged from 0 to 9999; each line could contain up to 192 characters and hold multiple statements separated by colons. The command assisted in managing extensive programs.
The command displayed source code listings; meanwhile, showed the initial 15 lines with pauses for easier reading. Programs were stored and retrieved via cassette tape using and , with commands like and facilitating navigation through tape files. Disk operations employed commands such as , where "F" identified a fixed disk drive.
Program execution was initiated through , optionally specifying a starting line (e.g., ). The command allowed inclusion of optional messages useful for debugging purposes. Enabled printing each executed line and worked alongside keyboard break controls like and for step-by-step execution. Delays between traced lines could be adjusted using , measured in increments of one-sixth of a second.
Rather than having a dedicated command to clear memory, Wang BASIC used . Variations included to remove particular line ranges, to clear variables, and , which preserved variables shared across programs. These functions were analogous to or found in other BASIC implementations.
Syntax
Control flow statements included , , and ; however, the alternative form was not implemented. A restriction existed whereby the THEN clause accepted only line numbers, unlike modern dialects permitting any statement following THEN. Logical conjunctions such as or were not supported; thus, conditional tests could contain only a single comparison.
An interesting characteristic was the use of named routines defined by followed by a single quote and a number between 0 and 255 (e.g., ), which could be invoked with . These subroutines accepted parameters, allowing multi-line functional definitions—a contrast to other dialects relying on GOSUB rather than named functions. Routines numbered from 0 to 31 corresponded directly to keys on the 2200 keyboard, enabling immediate calling via single key presses.
Output separators included commas and semicolons; commas advanced the cursor to the next 16-character tab stop, while semicolons left it positioned at the end of output. The function was available, but was not supported. Formatted output was provided through along with separate format "images" declared on lines beginning with %, such as , which could be applied within . Characters not part of format strings were echoed during printing, allowing customized output formatting.
Statements accepted prompts combined with comma-separated variables; semicolons were prohibited, and after input completion, the cursor remained at the line’s end.
Mathematics and Logic
Variable identifiers were restricted to either a single uppercase letter or a letter followed by a digit; names consisting of two letters were not supported. It was possible to assign values to several variables simultaneously using commas, for example , with an optional . Arrays could be declared using , accommodating both one-dimensional () and two-dimensional () structures.
Standard relational operators included symbols such as , , , , , and . The set of trigonometric functions encompassed , , , along with inverse functions like . Logarithmic and exponential operations included functions such as , , and others like , , , as well as random number generation through . Additionally, a pseudo-variable named was provided.
By default, trigonometric calculations were performed in radians; however, the mode could be switched to degrees () or gradians (), with an option to revert back to radians ().
Distinct from most BASIC dialects, the function interpreted any non-zero argument as enabling randomization, whereas passing zero reset the sequence similarly to a RANDOMIZE command. This behavior could introduce errors when porting code from other dialects where zero is treated as a neutral argument ignored by RND.
Strings
Wang BASIC supported string variables and allowed concatenation using the plus operator. Unlike later BASIC implementations that utilized dynamically sized strings stored on a heap (such as Microsoft BASIC), Wang BASIC fixed string lengths at a default of 16 characters, truncating any overflow. Unused portions of strings were padded with spaces, and trailing spaces were omitted during PRINT operations, potentially causing compatibility issues when migrating code.
The length of strings could be modified using the statement with syntax like , which set the maximum string size up to 64 characters. The language also supported arrays of strings; for instance, created five default-length strings, while generated ten strings each with a length of 20 characters.
A limited collection of string functions was available. The function acted as a versatile substring extractor replacing the DEC/Microsoft-style // operator; for example, returned five characters starting from position 10. The second parameter was optional— omitting it retrieved all characters from position five onward. The function returned the length of a string excluding trailing spaces, so produced a value of 3. Interestingly, empty strings yielded a length of 1. Unlike many BASIC variants, these string functions did not use a trailing $, even though they returned string results.
Data and Input/Output
Following the Dartmouth tradition, Wang BASIC employed statements to embed constants within the program code, which could be accessed sequentially through commands. The statement reset the data pointer and allowed positioning it at a specific data element (e.g., ). Programs could contain up to 256 DATA entries.
The command redirected output from instructions to various hardware devices by specifying device addresses—for example, sent PRINT output to a printer located at address 215, whereas returned output to the CRT screen. Similarly, LIST output could be redirected using . The SELECT statement also allowed defining maximum line widths (e.g., ) and supported predefined devices such as CI for console input or LIST for program listings.
Program Chaining
Due to memory constraints typical of that era’s computers, most BASIC dialects implemented "chaining" capabilities to divide programs into smaller segments. Wang BASIC facilitated this through the use of and statements.
The statement designated variables as "common" (global), for example . When loading a new module with LOAD, common variables preserved their values while non-common variables were reset. Common variables could be cleared entirely using , whereas cleared only non-common variables. Variables could be removed from common status via or selectively with ; however, the sequence in which variables were declared influenced which ones were affected by these resets.
The command also supported chaining by optionally specifying starting and ending line numbers; it would delete existing lines within that range before loading the new program segment and begin execution either at the specified line or at the program’s start.
Variations of 2200 BASIC
Wang BASIC was available in multiple versions distinguished by the size of their ROM-based microcode, which influenced the range of supported keywords.
2200B
The 2200B edition built upon the 2200A by incorporating previously absent features, additional string manipulation commands, vector-style operations, and improved input/output capabilities. Key enhancements included commands such as and , along with , which allowed keyboard input reading without halting execution. The function extracted numerical data from strings, while provided the length of numeric substrings.
Replacing the STR$ function, 2200B introduced the command to convert between strings and numbers, offering formatting options comparable to C's sprintf. Unlike MS BASIC’s INSTR that locates substrings, the function returned the position of a single character within a string.
The command converted hexadecimal values into characters (for example, inserts a space) and could process multiple codes simultaneously. Its binary equivalent was .
The unique command filled strings with designated characters or hexadecimal values (e.g., populating A$ entirely with 'X').
Vector-style commands such as , , , and enabled operations over multiple expressions more efficiently than equivalent infix expressions.
Most new features targeted floppy disk file input/output, adding support for various file types including data files identified by the "DA" prefix. Additional commands like , , and file management operations such as (file deletion) and (disk erasure) were also introduced.
2200C
In contrast to the substantial additions in 2200B, the 2200C update was more modest. It added the command to clear shared variables, a hex-outputting variant of , the command to remove a GOSUB from the call stack, and for implementing error trapping within programs.
2200T
Later models incorporated selected commands from both B and C versions; however, only the 2200T significantly broadened functionality. Its primary enhancement was matrix mathematics along with certain input/output improvements.
Matrix operations resembled those found in subsequent Dartmouth BASIC versions, employing direct assignments like instead of LET statements. For instance, forms matrix A by element-wise addition of matrices B and C. Additional matrix-related commands included (matrix inversion), (identity matrix creation), and (zero matrix generation), complemented by utility functions such as , , , and .
BASIC-2
The introduction of the new instruction set in the 2200VP necessitated a full rewrite of BASIC. While preserving backward compatibility, BASIC-2 incorporated missing features and boosted execution speed. Unlike earlier versions stored in read-only memory (ROM), BASIC-2 loaded from disk during boot-up, facilitating straightforward field updates. Optimized for the VP hardware, it achieved approximately eightfold performance improvements.
IF statements were extensively enhanced: Boolean conjunctions enabled complex conditional expressions like , and THEN clauses could contain explicit statements rather than implying GOTOs (e.g., ). An ELSE clause was added requiring colon separation—for example, . ELSE also supported ON statements facilitating multi-way branching.
New functions included , which truncates toward zero in contrast to INT’s floor rounding; for decimal rounding; returning integer remainders; and variadic functions like and that determine maximum or minimum values respectively. The function computed base-10 logarithms, while verified string format compliance similar to PRINTUSING.
PRINTUSING gained functionality to output formatted data into strings (e.g., converting numbers into variables). Additional pseudo-functions enhanced printing capabilities: positioned the cursor at specified coordinates; drew boxes at cursor location; and returned hexadecimal values.
String length limits increased from 64 to 124 characters, while array dimensions expanded dramatically from a maximum of 255 elements up to 65,535 elements.
BASIC-3
In March 1977, Wang launched an enhanced VP system featuring memory capacity up to 256 KB and a terminal server capable of supporting twelve terminals, marketed as the 2200MVP. The initial units were delivered in January 1978, with additional models introduced in 1980, including a four-user LVP and a single-user SVP.
At the Hannover Fair on April 2, 1981, Wang revealed a significant microcode upgrade for the MVP series. Priced at $2,000, the "C" option offered a COBOL compiler alongside an improved BASIC iteration known as BASIC-3. Although beta testing commenced later that year, the upgrade was never officially launched.