Apple Business BASIC

Last updated
Apple Business BASIC
Original author(s) Donn Denman
Developer(s) Apple Computer
Initial release1981;44 years ago (1981)
Platform Apple III
Type BASIC
License Commercial proprietary software

Apple Business BASIC is a dialect of the BASIC programming language for the Apple III with added features for producing business and productivity software. It belongs to the wider group of business BASICs, which first emerged on minicomputers.

Contents

The main additions compared to AppleSoft BASIC on the Apple II were 19-digit long integer values in addition to floating point, better control over formatting input and output, and floppy disk commands that allowed file management without having to exit to Apple DOS. It included a rudimentary system to load and save fixed-width records, which made file handling easier. It also allowed programs to be built in parts and loaded on demand to allow the construction of larger applications.

Business BASIC was the standard dialect for the Apple III. The Apple III also offered an expanded version of Microsoft BASIC, Apple III Microsoft BASIC, which ran under CP/M using 3rd party CP/M support.

Description

Program editing

Apple Business BASIC used many of the editing conventions from the earlier AppleSoft BASIC, with the most noticeable change being the command prompt becoming a paren, ). This visually indicated you were in Business BASIC, as Integer BASIC used > and AppleSoft used ]. Statements entered without a line number were executed immediately, while those with a line number were instead stored for future execution, which Apple referred to as deferred mode . As was the case for AppleSoft, line numbers were limited to 0 through 63999. [1]

Editing was improved with the ability to enter a full-screed editing mode by pressing the Escape key and then using the cursor keys to move within program text. Most home computers of the era already supported this, but the Apple II predated this becoming a standard feature. Setting the value of the INDENT variable, normally defaulted to 2, provided leading spaces in front of the lines inside a FOR...NEXT loop, [2] while the OUTREC variable controlled the maximum line length of LISTed program lines, avoiding it running off the right side of some printers. Finally, the DEL command allowed the mass deletion of program lines, for instance DEL 100 TO 500. DEL and LIST could both use TO, a comma, or a hyphen to separate the starting and ending ranges. [3]

Business BASIC was intended to support large programs, and writing such programs makes debugging difficult using traditional BASIC tools. To address this, Business BASIC added the TRACE command, which causes the system to print a # followed by the line number as statements are executed. Using this with PRINT allows the user to watch as values change and notice the line where it might occur. This can be turned off again with NOTRACE. [4]

Data types and variables

Most BASICs of the era allowed variable names to be a single letter, two letters, or one letter and one digit. A small number, including later versions of Microsoft BASIC, allowed longer variable names to be typed in the source code but only read the first two characters at runtime. This often led to a lack of suitable variable names, especially in long programs where many different variables were being used and spread across hundreds of lines of code. Business BASIC addressed this by allowing variable names up to 64 characters, all of which were significant. [5] A variable name could include most non-space printing characters including basic punctuation, often using the period between individual works in a name, like This.Is.A.Variable.Name [6] Names were case insensitive, so A.Variable and a.VARIABLE are the same. [7]

Variables were typed, meaning they could hold only one type of data. [8] Most BASICs of the era had two types of data. The default type was a floating point number, or "real", normally stored in a 40-bit format (at least on MOS 6502-based machines). [9] The other was the string, which was indicated by adding a dollar sign, $, to the end of the name of the variable. Some dialects, including Business BASIC, added an integer type, normally stored as a 16-bit binary value, indicated by a percent sign, %. To this, Business BASIC added the long integer, a 64-bit binary value that allowed up to 19 decimal digits of accuracy. These were denoted with an ampersand, &. [10]

Small currency values, like one penny, are represented in decimal by the fraction 0.01. This value cannot be exactly represented in binary floating point, and any manipulations, even simple ones like addition, can lead to the values being rounded incorrectly and producing odd output. [11] Apple Business BASIC used the long integer format to address this issue, multiplying dollar values by 100. A value like 0.01 would be stored as 1, and the value 10.10 would be stored as 1010. [12] While this format does not eliminate rounding issues, it greatly reduces them in unexpected cases like addition.

The downside is that all numbers have to be converted back to decimal format on output. This can be accomplished by dividing them by 100, but this may introduce the rounding errors that this system is attempting to avoid. Instead, it uses formatted output that placed the decimal point in the correct location, without changing the number itself. That is, 1010 would be printed as 10.10. This was accomplished with the PRINT USING and the IMAGE statements. The format was represented by a string, which could be typed directly after the USING, or on a separate line using IMAGE. [13] If the IMAGE style was used, the USING was instead followed by the line number of the IMAGE statement. [14]

Program statements and reserved variables

The list of supported statements is largely similar to those in AppleSoft BASIC, with a few additions. One is the ELSE clause on IF...THEN statements. ELSE operated as a separate statement, it could only follow a colon at the end of an IF statement. [15] Another is the WINDOW, which allowed the text display area to be controlled, for instance, WINDOW 37,9 TO 44,16 would limit text output to a small rectangle on the right side of the screen. HOME cleared the text area and returned the cursor to the upper left of the window, and INVERSE and NORMAL set the text mode. Other new basic functionality was offered through the use of "reserved variables", like INDENT. HPOS and VPOS contained the X and Y location of the cursor, respectively, or could be set to move it, like HPOS=6.

Operators and functions

Infix operators included + (addition), - (subtraction), * (multiplication), / (division) and exponent using the ^ character. [16] Binary operators included AND, OR and NOT. Binary comparisons included the standard set of =, >, <, >=, <=, <>. [17] Extensions to these standard operators included MOD (remainder), DIV (integer division, dropping any fraction), and the alternate form of logical tests, ><=> and =<. It did not support the # alternative for not-equals seen in HP Time-Shared BASIC, which had previously been supported in Integer BASIC. [16]

Mathematical functions were fairly standard, including SIN, COS, ATN, RND, INT, ABS, SQR, EXP, LOG. It also included TAN, which was often left out on systems with limited memory. It added the new functions HEX$ which converted a number into a four-digit hexadecimal number and TEN which did the opposite, taking a string with a hex value and converting that to an integer. [18] String functions included the standard LEFT$, RIGHT$, MID$, LEN, ASC, CHR$, VAL, STR$, and added INSTR to find a string within another and return its index, and SUB$ which overwrote the characters in one string with another, starting at a given location. [19] User functions could be defined with DEF FN. [20]

In most BASICs, conversions between types were automatic where possible, meaning that one could use expressions that combined floating point and integer functions and values and the data would be converted between those as needed. Strings could not be automatically converted to numbers, but could be done explicitly using the VAL and STR$ functions, which converted a string to a number and vice-versa. To address the need to convert long integers to the other types, and to generally improve conversions between types in general, Business BASIC introduced a set of four CONV functions, which returned a value of a specified type no matter what sort of input value was used. For instance, CONV&(A%) would convert the (short) integer value in A% into a long integer value. Likewise, one could CONV$(A&) to convert a long integer value to a string. [21] [22]

File handling

Like most BASICs of the era, Business BASIC offered file handling based on the concept of opening a file, reading and writing to it, and then closing the file. Files were referred to by a number provided when the files are opened. Files were opened with the OPEN# statement - the hash mark is not normally used in most dialects. [a] CLOSE# similarly added the hash, but in this case there was another variation, CLOSE, which closed all open files. Once opened, files could be read using INPUT# or READ# and written to using PRINT# or WRITE#. [24]

When reading from files, it is possible that any particular operation will reach the end of file, which would normally return a ?OUT OF DATA error. This error could be trapped like any other using the ON ERR statement, but as these particular errors are expected and commonplace, Business BASIC added the specialized ON EOF# which trapped only that one error and only on the provided file number. This could be turned off using the OFF EOF# statement. Additionally, it had a system variable EOF that was assigned the file number that caused the error, so it could be handled in more general error trapping routines. [25]

Business BASIC also provided a rudimentary system for reading and writing files in a random access fashion. This was managed by the CREATE statement, which had parameters for the filename, file type, and the length of the records. For instance, one could CREATE "testfile",DATA,500 to create a new random-access file containing byte data where each "record" was 500 bytes long.{{efn|If the length was not specified, it assumed 512 bytes. [26] Once created, all reads and writes to such a file would now always read exactly that number of bytes, so if one were to PRINT #1,A, the system would print the value of A and then pad out the rest of the line with nulls. When used with a random-access file, the read and write statements allowed an optional "record number" to be added after the file number. For instance INPUT #1,10;A would read the 10th record, and then attempt to read the value for A from it. Random-access files also set the value of the TYP system variable to a value indicating the type of variable that would next be read or written, and REC contained the number of the last record to be read or written. [27]

Files had to be CREATEd before they could be written to, whereas most dialects would create the file when it was OPENed for writing. CREATE could also be used to create directories. [28] Additional statements included CATALOG to produce a directory of files at a given path, DELETE to remove files, RENAME and LOCK and UNLOCK. [29] To make working with directories easier, the PREFIX$ system variable could be set to a string containing a path, which would then be pre-pended to any file name reference. [30]

Constructing longer programs

Machines of the era had limited memory, often too little to build useful business programs in BASIC. To address this, a number of dialects added the CHAIN statement. In Business BASIC, CHAIN had a required parameter, a filename which was not surrounded by quotes. When encountered in a program, this would load the new program code and start executing it. Unlike a LOAD or RUN, using CHAIN did not clear out the current values in variables, allowing the new code to continue processing data created by the previous one. It also allowed a second optional parameter, a line number, where execution should start in the new code. For instance, CHAIN /Link/Fence, 800 would load the program "Fence" in the directory "Chain" and start execution at line 800. [31]

One problem with this approach is that BASIC variables are global, meaning that any values that are changed by the new program will cause them to be changed in the original one, assuming it is loaded again as part of the CHAIN. For common variables like I, often used as the index variable in loops, this can lead to problems when one program changes the value in another. Many dialects that supported CHAIN had functionality to address this, like COMMON, but Business BASIC lacked this ability. This meant authors had to carefully track their use of variables. This was especially true for arrays, as it was possible for two chained programs to both DIM the same variable, which would cause the second to raise a ?REDIM ERROR. [32]

The new EXEC statement read a named text file and parsed its contents as input into the system. One could use this to place a series of instructions in a text file, like LOAD and RUN, and these would be executed one by one when the file was EXECed. The file could also contain new lines of code, allowing programs to be merged, rather than replaced entirely, [33] although this was a slower process than reading in the already-parsed code which was used by CHAIN or RUN. The program text could be written into a text file using the OUTPUT statement, which redirected all output, including LISTs, to a numbered file handle previously OPENed. [34] [b]

Calling external code

Business BASIC also included a number of features to allow external, non-BASIC, code to be used in BASIC programs. INVOKE loaded machine language code from an external file into memory. Multiple routines could be loaded by comma separating the file names in a single statement. [36]

PERFORM called a routine previously loaded by INVOKE, and passed in values in parens like a function call. For unexplained reasons, integer and long values had to be indicated by prefixing the variable name, rather than the normal post-fix notation. For instance, PERFORM StrangeRites(&Pennies, %Accountants) would call the StrangeRights function, passing in a long integer Pennies and a short integer Accountants. [37]

EXFN was similar to PERFORM, but called code that was expected to return a real number (floating point) value to the program. EXFN% was the same but expected an integer value. [38]

Examples

This program creates a new random-access file containing text, and then writes 10 lines of text to it. As the CREATE statement specifies a record length of 16, the lines will be 16 characters long no matter how much text is actually written. [39]

 10 REM Program PrintRandom  20 CREATE "RandomText", TEXT, 16  30 OPEN# 1 AS OUTPUT, "RandomText"  40 FOR X=1 TO 10  50 PRINT# 1 ,X; "This is line ";X  60 NEXT X  70 CLOSE# 1  8O END

The following program reads the data back in again, but due to the STEP 2 in line 30, it will print every other line in the file: [25]

 10 REM Program InputRandom  20 OPEN# 1 AS INPUT, "RandomText"  30 FOR X=2 TO 10 STEP 2  40 INPUT#1,X; ACCEPT$  50 PRINT ACCEPT$  60 NEXT X  70 CLOSE# 1  80 END

Notes

  1. Another dialect that did use the hash on OPEN# was Atari BASIC. [23]
  2. Commodore BASIC on the C64 and later machines offered a similar feature CMD. [35]

Related Research Articles

Applesoft BASIC is a dialect of Microsoft BASIC, developed by Marc McDonald and Ric Weiland, supplied with Apple II computers. It supersedes Integer BASIC and is the BASIC in ROM in all Apple II series computers after the original Apple II model. It is also referred to as FP BASIC because of the Apple DOS command FP used to invoke it, instead of INT for Integer BASIC.

BASIC09 is a structured BASIC programming language dialect developed by Microware on behalf of Motorola for the then-new Motorola 6809 CPU and released in February 1980. It is primarily used with the OS-9 operating system, released in 1979. Microware also released a version for OS-9/68k on the 68000 as Microware BASIC.

<span class="mw-page-title-main">Atari BASIC</span> Dialect of the BASIC programming language

Atari BASIC is an interpreter for the BASIC programming language that shipped with Atari 8-bit computers. Unlike most American BASICs of the home computer era, Atari BASIC is not a derivative of Microsoft BASIC and differs in significant ways. It includes keywords for Atari-specific features and lacks support for string arrays.

Integer BASIC is a BASIC interpreter written by Steve Wozniak for the Apple I and Apple II computers. Originally available on cassette for the Apple I in 1976, then included in ROM on the Apple II from its release in 1977, it was the first version of BASIC used by many early home computer owners.

Commodore BASIC, also known as PET BASIC or CBM-BASIC, is the dialect of the BASIC programming language used in Commodore International's 8-bit home computer line, stretching from the PET (1977) to the Commodore 128 (1985).

SAIL, the Stanford Artificial Intelligence Language, was developed by Dan Swinehart and Bob Sproull of the Stanford AI Lab. It was originally a large ALGOL 60-like language for the PDP-10 and DECSYSTEM-20. The language combined the earlier PDP-6/-10 language GOGOL compiler, essentially an integer-only version of ALGOL, with the associative store from the LEAP language. The first release was in November 1969 and it saw continued development into the 1980s, including a commercial derivative, MAINSAIL.

Dartmouth BASIC is the original version of the BASIC programming language. It was designed by two professors at Dartmouth College, John G. Kemeny and Thomas E. Kurtz. With the underlying Dartmouth Time-Sharing System (DTSS), it offered an interactive programming environment to all undergraduates as well as the larger university community.

BASIC-PLUS is an extended dialect of the BASIC programming language that was developed by Digital Equipment Corporation (DEC) for use on its RSTS/E time-sharing operating system for the PDP-11 series of 16-bit minicomputers in the early 1970s through the 1980s.

<span class="mw-page-title-main">Vilnius BASIC</span> Dialect of the BASIC programming language

Vilnius BASIC, sometimes known as BK BASIC, is a dialect of the BASIC programming language running on the Elektronika BK-0010-01/BK-0011M and UKNC computers. It was developed at Vilnius University, located in Lithuania which was a republic of the Soviet Union at the time.

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.

Color BASIC is the implementation of Microsoft BASIC that is included in the ROM of the Tandy/Radio Shack TRS-80 Color Computers manufactured between 1980 and 1991. BASIC is a high level language with simple syntax that makes it easy to write simple programs. Color BASIC is interpreted, that is, decoded as it is run.

SCELBAL, short for SCientific ELementary BAsic Language, is a version of the BASIC programming language released in 1976 for the SCELBI and other early Intel 8008 and 8080-based microcomputers like the Mark-8. Later add-ons to the language included an extended math package and string handling. The original version required 8 kB of RAM, while the additions demanded at least 12 kB.

SUPER BASIC, sometimes SBASIC for short, is an advanced dialect of the BASIC programming language offered on Tymshare's SDS 940 systems starting in 1968 and available well into the 1970s.

The TENET 210 was a mainframe computer designed for timesharing services. The machine was designed for high throughput and expandability, including 20 direct memory access (DMA) channels and eight slots for core memory, allowing up to 128k 32-bit words of RAM. The sales materials boasted that it guaranteed user responses within one second.

SDS BASIC, also known as CP-V BASIC, Batch BASIC or Sigma BASIC depending on the version, is a BASIC programming language compiler for Scientific Data Systems's (SDS) Sigma series mainframe computers, originally released in 1967. Xerox purchased SDS in 1969 and began rebranding it as Xerox Data Systems, and finally just Xerox, at which time the language became known as Xerox BASIC.

<span class="mw-page-title-main">BASIC interpreter</span> Interpreter that enables users to enter and run programs in the BASIC language

A BASIC interpreter is an interpreter that enables users to enter and run programs in the BASIC language and was, for the first part of the microcomputer era, the default application that computers would launch. Users were expected to use the BASIC interpreter to type in programs or to load programs from storage.

Wang BASIC is a series of BASIC programming languages for computers from Wang Laboratories. The term can be used to refer to the BASIC on any Wang machine, but is mostly associated with the versions on the Wang 2200 minicomputer series of the early 1970s. When these machines were updated to the VP series in 1976, BASIC-2 was introduced and remained the pattern for future machines in the 2200 series. A planned BASIC-3 was never released.

BASIC-8, is a BASIC programming language for the Digital Equipment (DEC) PDP-8 series minicomputers. It was the first BASIC dialect released by the company, and its success led DEC to produce new BASICs for its future machines, notably BASIC-PLUS for the PDP-11 series. DEC's adoption of BASIC cemented the use of the language as the standard educational and utility programming language of its era, which combined with its small system requirements, made BASIC the major language during the launch of microcomputers in the mid-1970s.

Acorn System BASIC and Atom BASIC are two closely related dialects of the BASIC programming language developed by Acorn Computers for their early microcomputers like the Acorn System 3 and Acorn Atom. Developed in-house, they have a number of significant idiosyncrasies compared to most BASIC dialects of the home computer era.

Benton Harbor BASIC and Extended Benton Harbor BASIC were two versions of the BASIC programming language written by Heathkit for their H8 microcomputers. The BASICs were patterned on Dartmouth BASIC, and thus differ in some respects from the many Microsoft BASIC clones of the late-1970s era. The two differ from each other in that the former was able to run in machines with only 8 kB of main memory and only supported string constants, while Extended required 12 kB and added string variables and additional features. It is named after the town where Heathkit was located.

References

Citations

  1. Manual 1981, p. 6.
  2. Adams 1984, p. 121.
  3. Adams 1984, pp. 102–106.
  4. Manual 1981, pp. 25–26.
  5. Adams 1984, pp. 6–7.
  6. Adams 1984, p. 6.
  7. Adams 1984, p. 9.
  8. Adams 1984, p. 5.
  9. Manual 1981, p. 41.
  10. Adams 1984, pp. 1–4.
  11. Goldberg, David (March 1991). "What Every Computer Scientist Should Know About Floating-Point Arithmetic". ACM Computing Surveys. 23: 5–48. doi:10.1145/103162.103163.
  12. Adams 1984, p. 4.
  13. Adams 1984, pp. 166–172.
  14. Adams 1984, pp. 172–173.
  15. Adams 1984, p. 96.
  16. 1 2 Manual 1981, p. 168.
  17. Manual 1981, p. 192.
  18. Adams 1984, pp. 51, 52.
  19. Adams 1984, pp. 40–50.
  20. Adams 1984, p. 33.
  21. Manual 1981, pp. 174, 175.
  22. Adams 1984, pp. 28–32.
  23. Atari BASIC Reference Manual (PDF). Atari. 1983. p. 33.
  24. Manual 1981, pp. 139–144.
  25. 1 2 Manual 1981, p. 154.
  26. Manual 1981, p. 145.
  27. Manual 1981, pp. 142–152.
  28. Manual 1981, p. 130.
  29. Manual 1981, pp. 132–135.
  30. Manual 1981, p. 129.
  31. Manual 1981, p. 23.
  32. Manual 1981, p. 24.
  33. Manual 1981, p. 28.
  34. Manual 1981, p. 140.
  35. User's Reference Manual, Commodore BASIC 4.0 (PDF). 1980. p. 27.
  36. Manual 1981, p. 161.
  37. Manual 1981, p. 162.
  38. Manual 1981, pp. 164–165.
  39. Manual 1981, p. 152.

Bibliography