Integer BASIC is a
BASIC interpreter
A BASIC interpreter is an Interpreter (computing), interpreter that enables users to enter and run programs in the BASIC programming language, language and was, for the first part of the microcomputer era, the default Application software, applica ...
written by
Steve Wozniak
Stephen Gary Wozniak (; born August 11, 1950), also known by his nickname Woz, is an American technology entrepreneur, electrical engineer, computer programmer, philanthropist, and inventor. In 1976, he co-founded Apple Inc., Apple Computer with ...
for the
Apple I
The Apple Computer 1 (Apple-1), later known predominantly as the Apple I, is an 8-bit personal computer designed by Steve Wozniak and released by the Apple Computer Company (now Apple Inc.) in 1976. The company was initially formed to ...
and
Apple II
Apple II ("apple Roman numerals, two", stylized as Apple ][) is a series of microcomputers manufactured by Apple Computer, Inc. from 1977 to 1993. The Apple II (original), original Apple II model, which gave the series its name, was designed ...
computers. Originally available on Cassette tape, cassette for the Apple I in 1976, then included in Read-only memory, ROM on the Apple II from its release in 1977, it was the first version of BASIC used by many early
home computer
Home computers were a class of microcomputers that entered the market in 1977 and became common during the 1980s. They were marketed to consumers as affordable and accessible computers that, for the first time, were intended for the use of a s ...
owners.
The only numeric data type was the integer;
floating-point
In computing, floating-point arithmetic (FP) is arithmetic on subsets of real numbers formed by a ''significand'' (a Sign (mathematics), signed sequence of a fixed number of digits in some Radix, base) multiplied by an integer power of that ba ...
numbers were not supported. Using integers allowed numbers to be stored in a compact 16-bit format that could be more rapidly read and processed than the 32- or 40-bit floating-point formats found in most BASICs of the era. This made it so fast that
Bill Gates
William Henry Gates III (born October 28, 1955) is an American businessman and philanthropist. A pioneer of the microcomputer revolution of the 1970s and 1980s, he co-founded the software company Microsoft in 1975 with his childhood friend ...
complained when it outperformed
Microsoft BASIC
Microsoft BASIC is the foundation software product of the Microsoft company and evolved into a line of BASIC interpreters and compiler(s) adapted for many different microcomputers. It first appeared in 1975 as Altair BASIC, which was the first v ...
in benchmarks. However, this also limited its applicability as a general-purpose language.
Another difference with other BASICs of the era is that Integer BASIC treated strings as arrays of characters, similar to the system in
C or
Fortran 77. Substrings were accessed using
array slicing
In computer programming, array slicing is an operation that extracts a subset of elements from an array and packages them as another array, possibly in a different dimension from the original.
Common examples of array slicing are extracting a ...
rather than string functions. This style was introduced in
HP Time-Shared BASIC
HP Time-Shared BASIC (HP TSB) is a BASIC, BASIC programming language Interpreter (computing), interpreter for Hewlett-Packard's HP 2100#HP 2000, HP 2000 line of minicomputer-based time-sharing computer systems. TSB is historically notable as th ...
, and could also be found in other contemporary BASICs patterned on HP, like
North Star BASIC
North Star BASIC was a dialect (computing), dialect of the BASIC programming language for the Intel 8080 microprocessor used on the North Star Horizon and available for purchase on other S-100 bus machines of the late 1970s.Richard Milewski,Micro ...
and
Atari BASIC
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 way ...
. It contrasted with the style found in BASICs derived from
DEC, including
Microsoft BASIC
Microsoft BASIC is the foundation software product of the Microsoft company and evolved into a line of BASIC interpreters and compiler(s) adapted for many different microcomputers. It first appeared in 1975 as Altair BASIC, which was the first v ...
.
The language was initially developed under the name GAME BASIC and referred to simply as Apple BASIC when it was introduced on the Apple I. It became Integer BASIC when it was ported to the Apple II and shipped alongside
Applesoft BASIC
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 Read-only memory, ROM in all Apple II series computers after the ori ...
, a port of
Microsoft BASIC
Microsoft BASIC is the foundation software product of the Microsoft company and evolved into a line of BASIC interpreters and compiler(s) adapted for many different microcomputers. It first appeared in 1975 as Altair BASIC, which was the first v ...
which included floating-point support. Integer BASIC was phased out in favor of Applesoft BASIC starting with the
Apple II Plus
The Apple II Plus (stylized as Apple ] or apple plus) is the second model of the Apple II series of personal computers produced by Apple Inc., Apple Computer. It was sold from June 1979 to December 1982. Approximately 380,000 II Pluses we ...
in 1979.
History
As a senior in
high school
A secondary school, high school, or senior school, is an institution that provides secondary education. Some secondary schools provide both ''lower secondary education'' (ages 11 to 14) and ''upper secondary education'' (ages 14 to 18), i.e., ...
,
Steve Wozniak
Stephen Gary Wozniak (; born August 11, 1950), also known by his nickname Woz, is an American technology entrepreneur, electrical engineer, computer programmer, philanthropist, and inventor. In 1976, he co-founded Apple Inc., Apple Computer with ...
's electronics teacher arranged for the leading students in the class to have placements at local electronics companies. Wozniak was sent to
Sylvania where he programmed in
FORTRAN on an
IBM 1130
The IBM 1130 Computing System, introduced in 1965, was IBM's least expensive computer at that time. A binary 16-bit machine, it was marketed to price-sensitive, computing-intensive technical markets, like education and engineering, succeeding th ...
. That same year,
General Electric
General Electric Company (GE) was an American Multinational corporation, multinational Conglomerate (company), conglomerate founded in 1892, incorporated in the New York (state), state of New York and headquartered in Boston.
Over the year ...
placed a terminal in the high school that was connected to one of their mainframes running their
time-sharing
In computing, time-sharing is the Concurrency (computer science), concurrent sharing of a computing resource among many tasks or users by giving each Process (computing), task or User (computing), user a small slice of CPU time, processing time. ...
BASIC service, which they were heavily promoting at the time. After being given three days of access, the students were asked to write letters on why the school should receive a terminal permanently, but their efforts were ultimately unsuccessful.
Some years later, Wozniak was working at
Hewlett-Packard
The Hewlett-Packard Company, commonly shortened to Hewlett-Packard ( ) or HP, was an American multinational information technology company. It was founded by Bill Hewlett and David Packard in 1939 in a one-car garage in Palo Alto, California ...
(HP) running simulations of chip designs and logic layout for calculators. HP made major inroads in the
minicomputer
A minicomputer, or colloquially mini, is a type of general-purpose computer mostly developed from the mid-1960s, built significantly smaller and sold at a much lower price than mainframe computers . By 21st century-standards however, a mini is ...
market with their
HP 2000
The HP 2100 is a series of 16-bit minicomputers that were produced by Hewlett-Packard (HP) from the mid-1960s to early 1990s. Tens of thousands of machines in the series were sold over its 25-year lifetime, making HP the fourth-largest minicomput ...
series machines running a
custom timesharing version of BASIC. For approximately , one could build up a reasonably equipped machine that could support between 16 and 32 users running BASIC programs. While expensive, it was still a fraction of the cost of the
mainframe
A mainframe computer, informally called a mainframe or big iron, is a computer used primarily by large organizations for critical applications like bulk data processing for tasks such as censuses, industry and consumer statistics, enterpris ...
machines and, for heavy users, less than the timesharing services. HP followed this with the
HP 9830
The HP 9800 is a family of what were initially called programmable calculators and later desktop computers that were made by Hewlett-Packard, replacing their first HP 9100 calculator. It is also named "98 line". The 9830 and its successors were ...
, a desktop-sized machine for that also ran BASIC, which Wozniak had access to.
In January 1975 the
Altair 8800
The Altair 8800 is a microcomputer introduced in 1974 by Micro Instrumentation and Telemetry Systems (MITS) based on the Intel 8080 CPU. It was the first commercially successful personal computer. Interest in the Altair 8800 grew quickly after i ...
was announced and sparked off the
microcomputer
A microcomputer is a small, relatively inexpensive computer having a central processing unit (CPU) made out of a microprocessor. The computer also includes memory and input/output (I/O) circuitry together mounted on a printed circuit board (P ...
revolution. In March, Wozniak attended the first meeting of the
Homebrew Computer Club
The Homebrew Computer Club was an early computer hobbyist group in Menlo Park, California, which met from March 1975 to December 1986. The club had an influential role in the development of the microcomputer revolution and the rise of that aspec ...
and began formulating the design of his own computer. One of the most important pieces of software for the Altair, and one of the most heavily
pirated
Copyright infringement (at times referred to as piracy) is the use of works protected by copyright without permission for a usage where such permission is required, thereby infringing certain exclusive rights granted to the copyright holder, ...
, was
Altair BASIC
Altair BASIC is a discontinued interpreter for the BASIC programming language that ran on the MITS Altair 8800 and subsequent S-100 bus computers. It was Microsoft's first product (as Micro-Soft), distributed by MITS under a contract. Altair B ...
from the recently formed
Microsoft
Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
. Wozniak concluded that his machine would have to have a BASIC of its own, which would, hopefully, be the first for the
MOS Technology 6502
The MOS Technology 6502 (typically pronounced "sixty-five-oh-two" or "six-five-oh-two") William Mensch and the moderator both pronounce the 6502 microprocessor as ''"sixty-five-oh-two"''. is an 8-bit computing, 8-bit microprocessor that was desi ...
processor. As the language needed 4 KB RAM, he made that the minimum memory for the design.
Wozniak's references for BASIC were a copy of ''
101 BASIC Computer Games'' and an HP BASIC manual. He did not know that HP's BASIC was very different from the
DEC BASIC variety used in ''101 Games'', which was also the basis of Microsoft BASIC for the Altair. Based on these sources, Wozniak began sketching out a
syntax
In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
chart for the language. The design initially included floating-point support, but still hoping he might publish the first BASIC on the 6502 and become "a star", he decided to abandon floating-point and write a separate integer math system to save a few weeks programming time.
Wozniak would later describe his language as "intended primarily for games and educational uses". Referring to it throughout development as "GAME BASIC", Wozniak wrote the code by hand, translating the
assembler code instructions into their
machine code
In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
equivalents and then uploading the result to his computer. Without any training on how to write a computer language, he used his HP calculator experience to implement a
stack machine
In computer science, computer engineering and programming language implementations, a stack machine is a computer processor or a Virtual machine#Process virtual machines, process virtual machine in which the primary interaction is moving short- ...
to interpret expressions. Once the basic routines were up and running, he worked on the other commands one-by-one in a modular fashion. With every visit to the Homebrew club, he demonstrated a few more features added in the last month.

In early 1976 ads for its
Apple I
The Apple Computer 1 (Apple-1), later known predominantly as the Apple I, is an 8-bit personal computer designed by Steve Wozniak and released by the Apple Computer Company (now Apple Inc.) in 1976. The company was initially formed to ...
computer,
Apple Inc
Apple Inc. is an American multinational corporation and technology company headquartered in Cupertino, California, in Silicon Valley. It is best known for its consumer electronics, software, and services. Founded in 1976 as Apple Computer ...
made the claims that "our philosophy is to provide software for our machines free or at minimal cost" and "yes folks, Apple BASIC is Free". This was printed shortly after
Bill Gates
William Henry Gates III (born October 28, 1955) is an American businessman and philanthropist. A pioneer of the microcomputer revolution of the 1970s and 1980s, he co-founded the software company Microsoft in 1975 with his childhood friend ...
's infamous
Open Letter to Hobbyists
"An Open Letter to Hobbyists" is a 1976 open letter written by Bill Gates, the co-founder of Microsoft, to early personal computer hobbyists, in which Gates expresses dismay at the widespread duplication of software taking place in the hobbyist co ...
that suggested that people were robbing him by copying versions of
Altair BASIC
Altair BASIC is a discontinued interpreter for the BASIC programming language that ran on the MITS Altair 8800 and subsequent S-100 bus computers. It was Microsoft's first product (as Micro-Soft), distributed by MITS under a contract. Altair B ...
.
Wozniak had helped
Steve Jobs
Steven Paul Jobs (February 24, 1955 – October 5, 2011) was an American businessman, inventor, and investor best known for co-founding the technology company Apple Inc. Jobs was also the founder of NeXT and chairman and majority shareholder o ...
, who worked for
Atari
Atari () is a brand name that has been owned by several entities since its inception in 1972. It is currently owned by French holding company Atari SA (formerly Infogrames) and its focus is on "video games, consumer hardware, licensing and bl ...
, with a redesign of
Breakout. At some later point, he decided to see whether one could write the game in BASIC. He added commands to read
paddle controllers and over a series of quick edits had a version of the game up and running. To improve its playability, he added a speaker to make clicks when the ball hit things. While showing it to Jobs, Wozniak demonstrated that he could quickly change the colors that his game used, just by altering the
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
. Wozniak later wrote that he had proved that "software was much more flexible than hardware", and that he and Jobs realized that "now, anyone could create arcade games without having to design it in hardware."
Wozniak did complete a floating-point library for the 6502 and published it in the August 1976 edition of ''
Dr. Dobb's Journal
''Dr. Dobb's Journal'' (often shortened to ''Dr. Dobb's'' or DDJ) was a monthly magazine published in the United States by UBM Technology Group, part of UBM. It covered topics aimed at computer programmers. When launched in 1976, DDJ was the fi ...
''. This library was later made part of the ROMs for the
Apple II
Apple II ("apple Roman numerals, two", stylized as Apple ][) is a series of microcomputers manufactured by Apple Computer, Inc. from 1977 to 1993. The Apple II (original), original Apple II model, which gave the series its name, was designed ...
. Wozniak began work on back-porting the floating-point code into Apple BASIC, but got sidetracked in the task of designing a floppy disk controller for what became the Disk II. Mike Markkula said the company would go to the Consumer Electronics Show in Las Vegas if the disk system was ready in time, so Wozniak and Randy Wigginton worked on it non-stop through the 1977 holidays.
When he returned to the topic of floating-point in BASIC, Jobs complained it was taking too long. Without Wozniak being aware, the company had already arranged a license with Microsoft to receive their recently completed 6502 version of the Altair code. Examining the MS code, Wozniak decided that it was easier to add graphics support to their code than add floating-point his own BASIC, as the latter required hand-patching of the original machine code while MS's was written in assembler and more easily modified. The development of Apple's BASIC ended in favor of what became
Applesoft BASIC
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 Read-only memory, ROM in all Apple II series computers after the ori ...
. Wozniak later noted, "My biggest disappointment was going to the awful string functions like and instead of my own".
When the Apple II shipped in the summer of 1977, Integer BASIC was supplied in ROM, while Applesoft BASIC shipped on cassette. This changed with the introduction of the
Apple II Plus
The Apple II Plus (stylized as Apple ] or apple plus) is the second model of the Apple II series of personal computers produced by Apple Inc., Apple Computer. It was sold from June 1979 to December 1982. Approximately 380,000 II Pluses we ...
in 1979, when Applesoft was put in the ROM.
Description
Program editing
Like most BASIC implementations of the era, Integer BASIC acted as both the language interpreter as well as the line editing environment. When BASIC was running, a
command prompt
A command-line interface (CLI) is a means of interacting with software via commands each formatted as a line of text. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user-friendly alternativ ...
was displayed where the user could enter statements. Unlike later
home computer
Home computers were a class of microcomputers that entered the market in 1977 and became common during the 1980s. They were marketed to consumers as affordable and accessible computers that, for the first time, were intended for the use of a s ...
platforms, BASIC was not the default environment when the Apple II started, it normally started in the
monitor
Monitor or monitor may refer to:
Places
* Monitor, Alberta
* Monitor, Indiana, town in the United States
* Monitor, Kentucky
* Monitor, Oregon, unincorporated community in the United States
* Monitor, Washington
* Monitor, Logan County, Wes ...
. BASIC was started by pressing .
Statements that were entered with leading numbers are entered into the program storage for "deferred execution", either as new lines or replacing any that might have had the same number previously. Statements that were entered without a line number were referred to as commands, and ran immediately. Line numbers could be from 0 to 32767, and lines could contain up to 128 characters.
Integer BASIC also included the command to automatically enter line numbers at a given starting number like , adding 10 to the last number with every new line. would begin numbering at line 300 by fives; 300, 305, etc. Automatic numbering was turned off by entering .
One interesting feature of the editor was that a section of the screen could be set aside as the "window", where live updates took place. This was normally the entire screen, but it could be limited to a smaller area by ing values into memory locations 32 through 35. This feature could be used to create an editable text area while the rest of the screen was in graphics mode.
Debugging
As in most BASICs, programs were started with the command, and as was common, could be directed at a particular line number like . Execution could be stopped at any time using and then restarted with tinue, as opposed to the more typical .
For step-by-step execution, the instruction could be used at the command prompt or placed within the program itself. When it was turned on, line numbers were printed out for each line the program visited. The feature could be turned off again with .
A somewhat unusual feature was the (for "display") command. When encountered in a program, from that point on any ''changes'' to a variable's value would be displayed. For instance, would display the value of X every time it changed, along with the line number where the change occurred. As with TRACE, DSP was turned off with .
Variable names
Where
Dartmouth BASIC
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 interac ...
and HP-BASIC limited variable names to at most two characters (either a single letter or a letter followed by one digit), and where MS-BASIC allowed a letter followed by an optional letter or digit (ignoring subsequent characters), Integer BASIC was unusual in supporting any length variable name (e.g., SUM, GAMEPOINTS, PLAYER2). The only caveat was that variable names could not contain reserved words; for example, THISCOLOR and COLORFUL were invalid variable names because they contained the keyword , a system command. Additionally, lines were limited to 128 characters, so variable names could not exceed that length.
Mathematics
Integer BASIC, as its name implies, uses integers as the basis for its math package. These were stored internally as a 16-bit number,
little-endian
'' Jonathan_Swift.html" ;"title="Gulliver's Travels'' by Jonathan Swift">Gulliver's Travels'' by Jonathan Swift, the novel from which the term was coined
In computing, endianness is the order in which bytes within a word (data type), word of d ...
(as is the 6502). This allowed a maximum value for any calculation between -32767 and 32767; although the format could also store the value -32768, BASIC could not display that number. Calculations that resulted in values outside that range produced a .
Infix operators included (addition), (subtraction), (multiplication), (division),
MOD (remainder) and exponent using the character. Binary operators included , and . Binary comparisons included the standard set of , , , , , and the HP-inspired , which was equivalent to <>.
Only single-dimension arrays were allowed, limited in size only by the available memory. Mathematical functions were sparse; only (absolute value), (sign) and (random number) were supported. In contrast to MS-derived versions, where the parameter was ignored and always returned a value 0..<1, Integer BASIC used the parameter; returned an integer from 0 to 5.
Strings
Integer BASIC's string handling was based on the system in HP BASIC. This treated string variables as arrays of characters which had to be ed prior to use. This is similar to the model in
C or
Fortran 77. This is in contrast to MS-like BASICs where strings are an intrinsic variable-length type. Before MS-derived BASICs became the ''de facto'' standard, this style was not uncommon;
North Star BASIC
North Star BASIC was a dialect (computing), dialect of the BASIC programming language for the Intel 8080 microprocessor used on the North Star Horizon and available for purchase on other S-100 bus machines of the late 1970s.Richard Milewski,Micro ...
and
Atari BASIC
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 way ...
used the same concept, as did others.
Strings in Integer Basic used a fixed amount of memory regardless of the number of characters used within them, up to a maximum of 255 characters. This had the advantage of avoiding the need for the
garbage collection
Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of treatment or landfill. Waste collection also includes the curbside collection of recyclable ...
of the
heap that was notoriously slow in MS BASIC but meant that strings that were shorter than the declared length resulted in wasted memory.
Substring access was provided through
array slicing
In computer programming, array slicing is an operation that extracts a subset of elements from an array and packages them as another array, possibly in a different dimension from the original.
Common examples of array slicing are extracting a ...
syntax. For instance, printed the first six characters of , characters 0 through 5. Concatenation was provided using the same system, replaced any characters starting at position 5 with the string "ABC". This contrasts with the DEC/MS-style string handling which uses string functions like to access substrings and for concatenation.
As many of the features that would be provided by string functions were instead provided by array slicing, the selection of string functions was reduced. returned the length of a string and returned the ASCII numeric code for the first letter in a string. It lacked an equivalent of the that returned the ASCII character with a given numeric code.
Graphics and sound
When launched, the only
game controller
A game controller, gaming controller, or simply controller, is an input device or Input/Output Device, input/output device used with video games or entertainment systems to provide input to a video game. Input devices that have been classified as ...
for the Apple was the
paddle controller, which had two controllers on a single connector. The position of the controller could be read using the function, passing in the controller number, 0 or 1, like , returning a value between 0 and 255.
The Apple machines did not include dedicated sound hardware, only a simple "beeper". Producing sounds was accomplished by ing the memory-mapped location of the speaker, -16336. Repeatedly PEEKing that value produced tones, and the manual suggested using a mathematical expression to do this, like .
Support for graphics was more detailed. Graphics mode was turned on with the statement and off with . Drawing was modal and normally started by issuing a command to change the color, which was accomplished by setting a pseudo-variable; would set the drawing color to 12, light green. One could then to produce a single spot of that color, to draw a horizontal line at row 20 that spanned the screen, or to draw a shorter vertical line down column 7. returned the color of the screen at X,Y.
Input/output
Integer BASIC lacked any custom input/output commands, and also lacked the statement and the associated . To get data into and out of a program, the input/output functionality was redirected to a selected
card slot with the and , which redirected output or input (respectively) to the numbered slot. From then on, data could be sent to the card using conventional commands and read from it using .
Other notes
Integer BASIC included a feature, which positioned the cursor on a given column from 0 to 39. It differed from the versions found in most BASICs in that it was a command with a following number, as opposed to a function with the value in parentheses; one would move the cursor to column 10 using in Integer BASIC whereas in MS this would be . Additionally, the command worked similar to but added vertical spaces instead of horizontal. For unexplained reasons, in this case the coordinates were from 1 to 24 rather than 0 to 23.
Integer BASIC included a command to exit from loops. This popped the topmost item off the FOR stack. Atari BASIC also supported the same command, while
North Star BASIC
North Star BASIC was a dialect (computing), dialect of the BASIC programming language for the Intel 8080 microprocessor used on the North Star Horizon and available for purchase on other S-100 bus machines of the late 1970s.Richard Milewski,Micro ...
used .
The Integer BASIC ROMs also included a
machine code monitor
A machine code monitor ( machine language monitor) is software that allows a user to enter commands to view and change memory address, memory locations on a computer, with options to load and save memory contents from/to secondary storage. Some f ...
, "mini-
assembler", and disassembler to create and debug
assembly language
In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
programs. Wozniak hand-assembled the monitor as the Apple II's first program, then used it to write Integer BASIC.
Reserved words
Apple BASIC
Apple BASIC had the following commands:
AUTO val1, val2
CLR LEARDEL val1, val2
LIST val1, val2
RUN val1
SCR CRATCH / NEWHIMEM = expr
LOMEM = expr
(LET) var = expr
INPUT (prompt,) var1, var2 ...
PRINT item(s)
TAB expr
FOR var = expr1 TO expr2 STEP expr3
NEXT var
IF expr THEN statement
IF expr THEN line number
GOTO expr
GOSUB expr
RETURN
DIM var1(expr1), var2(expr2) ...
REM text
END
POKE expr1, expr2
CALL expr
Functions: ABS(), SGN(), PEEK(), RND(), LEN()
Integer BASIC
Integer BASIC added the following:
COLOR = expr
CON ONTINUEDSP
GR
HLIN expr1, expr2 AT expr3
MAN
NEW eplaces SCRNOTRACE
PLOT expr1, expr2
POP
TEXT
TRACE
VLIN expr1, expr2 AT expr3
Function: ASC(), PDL(), SCRN(X,Y)
Implementation
Integer BASIC read the lines typed in by the user from a buffer and ran them through a
parser
Parsing, syntax analysis, or syntactic analysis is a process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar by breaking it into parts. The term '' ...
which output a series of
tokens. As part of this process, simple
syntax errors were detected and listed. If the parsing was successful, the line number (if present) was converted from
ASCII
ASCII ( ), an acronym for American Standard Code for Information Interchange, is a character encoding standard for representing a particular set of 95 (English language focused) printable character, printable and 33 control character, control c ...
decimal format into a 16-bit integer and any keywords into a 7-bit integer token.
Some keywords were represented by multiple tokens; for instance, where Microsoft BASIC had one token for the keyword , Integer BASIC had three tokens: one if the keyword was followed by no arguments, one if followed by an arithmetic expression, and one if followed by a string literal.
Numeric literals, like the value 500, were converted into their 16-bit (two-byte) binary representation, in this case,
hexadecimal
Hexadecimal (also known as base-16 or simply hex) is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of sixteen. Unlike the decimal system representing numbers using ten symbo ...
. To indicate this was a value and not a keyword, a single byte between and was inserted in front of the two-byte value. String literals, like "HELLO WORLD" were instead converted by setting the high bit of each character so that was stored as . Variable names were converted in the same fashion, with the letters converted to have their high-bit turned on, and any digits in the name represented by the corresponding through , so that the variable would be tokenized as .
If the line was entered without a line number, the code was then executed directly from the buffer. If it had a line number, it was copied from the buffer into the program storage area.
The runtime interpreter used two stacks for execution: one for statement keywords and the other for evaluating the parameters. Each statement was given two priorities: one that stated where it should occur in a multi-step operation, like a string of mathematical operations to provide
order of operations
In mathematics and computer programming, the order of operations is a collection of rules that reflect conventions about which operations to perform first in order to evaluate a given mathematical expression.
These rules are formalized with a ...
, and another that suggested when evaluation should occur, for instance, calculating internal values of a parentheses formula. When variables were encountered, their name was parsed and then looked up in the variable storage area. If it was not found, it was added to the end of the list. The address of the variable's storage, perhaps freshly created, was then placed on the evaluation stack.
ROM details
SWEET16
In addition to Integer BASIC, the Apple ROMs contained a custom
assembler language
In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
known as
SWEET16. SWEET16 is based on
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (normal ...
s that run within a simple 16-bit
virtual machine
In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
. This model was used so memory could be addressed via indirect 16-bit pointers and 16-bit math functions calculated without the need to translate those to the underlying multi-instruction 8-bit 6502 code. The entire virtual machine was written in only 300 bytes. Code can call SWEET16 by issuing a
subroutine
In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times.
Callable units provide a ...
call, and then return to normal 6502 code when the 16-bit operations are complete.
SWEET16 was not used by the core BASIC code, but was later used to implement several utilities. Notable among these was the line renumbering routine, which was included in the Programmer's Aid #1 ROM, added to later Apple II models and available for user installation on earlier examples.
Floating point
Although Integer BASIC contained its own math routines, the Apple II ROMs also included a complete floating-point library located in ROM memory between and . The source code was included in the Apple II manual. BASIC programs requiring floating-point calculations could
CALL
into these routines.
Performance
Because Integer BASIC processed more of the original
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
into tokens, the runtime was faster than versions that required additional runtime parsing. For comparison,
Tiny BASIC
Tiny BASIC is a family of dialects of the BASIC programming language that can fit into 4 or fewer KBs of memory. Tiny BASIC was designed by Dennis Allison and the People's Computer Company (PCC) in response to the open letter published by Bi ...
tokenized only the line number, while MS BASICs tokenized only the keywords. So for instance, while Integer BASIC would convert the line entirely into tokens that could be immediately read and performed, in MS BASIC only the line number and GOTO would be tokenized, the "200" was left in its original ASCII format and had to be re-parsed into a 16-bit integer every time the line was encountered.
Additionally, working solely with integer math provides another major boost in speed. This is due both to the smaller 16-bit format requiring fewer memory accesses, as well as removing the need to move the floating-point decimal after calculations. As many
computer benchmarks of the era were small and often performed simple math that did not require floating-point, Integer BASIC trounced most other BASICs.
On one of the earliest known microcomputer benchmarks, the
Rugg/Feldman benchmarks, Integer BASIC was well over twice as fast as Applesoft BASIC on the same machine.
In the
Byte Sieve, where math was less important but array access and looping performance dominated, Integer BASIC took 166 seconds while Applesoft took 200. A review of Galfo Systems' Integer BASIC Compiler found that it produced code that is about 1.5 to eight times faster than compiled Applesoft BASIC, ten times faster than interpreted Integer BASIC, and 15 times faster than interpreted Applesoft.
Integer BASIC did not appear in the
Creative Computing Benchmark
The Creative Computing Benchmark, also called Ahl's Simple Benchmark, is a Benchmark (computing), computer benchmark that was used to compare the performance of the BASIC programming language on various machines. It was first introduced in the Nove ...
, which was first published in 1983, by which time the language was no longer included with Apple computers.
The following test series, taken from both of the original Rugg/Feldman articles,
[ show Integer's performance relative to the MS-derived BASIC on the same platform.
Here is a summary of what each test did:
*Test 1: for/next loop to 1000.
*Test 2: if/then loop with compare to 1000.
*Test 3: same as 2 with added multiplication, division, addition subtraction by same variable.
*Test 4: same as 3 with added multiplication, division, addition subtraction by constants.
*Test 5: same as 4 with added subroutine call.
*Test 6; same as 5 with added inner loop.
*Test 7: same as 6 with added table population.
]
Sample code
The following is a version of Breakout written in the 1977 version of Integer BASIC for the Apple II, which was listed in the Apple II Mini Manual. There are a number of known bugs in this version.
The program starts by setting the display to and then to clear the screen. Lines 20 through 27, and the associated subroutines at line 100 and 200, are the color selection code Wozniak demonstrated for Jobs. Line 30 sets up the text window with and then uses a series of and statements to draw the playfield and the score display in the text window. The entire main loop runs from line 40 through 90 with associated subroutines. Another large amount of code near the end of the program is concerned with printing the final score. Other notes of interest include the (not-equal) comparisons on line 20, the production of a high-pitch sound using a string of s on line 65 compared to a lower-pitched tone using a loop on line 70, and the mix of graphics and text on a single display.
5 TEXT: CALL -936: VTAB 4: TAB 10: PRINT "*** BREAKOUT GAME ***": PRINT
7 PRINT " OBJECT IS TO DESTROY ALL BRICKS WITH 5 BALLS": FOR N=1 TO 7000: NEXT N
10 DIM A$(20),B$(20): GR: PRINT: INPUT "HI, WHAT'S YOUR NAME? ",A$:A=1:B=13:C=9:D=6:E=15: PRINT "STANDARD COLORS,"; A$;
20 INPUT "? ",B$: IF B$#"N" AND B$#"NO" THEN 30: FOR I=0 TO 39: COLOR=I/2*(I<32): VLIN 0,39 AT I
25 NEXT I: POKE 34,20: PRINT: PRINT: PRINT: FOR I=0 TO 15: VTAB 21+I MOD 2: TAB I+I+1: PRINT I;: NEXT I: POKE 34,22: VTAB 24: PRINT: PRINT "BACKGROUND";
27 GOSUB 100: A=E: PRINT "EVEN BRICK";: GOSUB 100: B=E: PRINT "ODD BRICK";: GOSUB 100: C=E: PRINT "PADDLE";: GOSUB 100: D=E : PRINT "BALL";: GOSUB 100
30 POKE34,20:COLOR=A:FORI=0TO39:VLIN0,39ATI:NEXTI:FOR I=20TO34STEP2:TAB I+1:PRINT I/2-9;:COLOR=B:VLIN 0,39 AT I:COLOR=C:FOR J=I MOD 4 TO 39 STEP4
35 VLIN J,J+1 AT I: NEXT J,I: TAB 5: PRINT "SCORE = 0": PRINT: PRINT: POKE 34,21: S=0: P=S: L=S: X=19: Y=19: X=19
40 COLOR=A:PLOTX,Y/3:X=19:Y=RND(120):V=-1:W=RND(5)-2:L=L+1:IFL>5THEN140:TAB6:PRINT"BALL #";L:PRINT:FORI=1TO100:GOSUB200:NEXTI:M=1:N=0
50 J=Y+W: IF J>=0 AND J<120 THEN 60: W=-W: J=Y: FOR I=1 TO 6: K=PEEK(-16336): NEXT I
55 IF PEEK(-16287)>127 THEN SW=1-SW
60 I=X+V: IF I<0 THEN 400: GOSUB 200: COLOR=A: K=J/3: IF I>39 THEN 70: IF SCRN(I,K)=A THEN 90: IF I THEN 120: N=N+1: V=(N>9)+1: W=(K-P)*2-5:M=1
65 Z = PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336): GOTO 90
70 FOR I=1 TO 6: M=PEEK(-16336): NEXT I: I=X: M=0
80 V=-V
90 PLOT X,Y/3: COLOR=E: PLOT I,K: X=I: Y=J: GOTO 50
99 PRINT "INVALID. REENTER";
100 INPUT " COLOR (0 TO 15)",E: IF E<0 OR E>15 THEN 99: RETURN
120 IF M THEN V=ABS(V): VLIN K/2*2,K/2*2+1 AT I: S=S+I/2-9: VTAB 21: TAB 13: PRINT S
123 Q = PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)-PEEK(-16336)
124 IF S<720 THEN 80
130 PRINT "CONGRATULATIONS, YOU WIN.": GOTO 150
140 PRINT "YOUR SCORE OF ";S;" IS ";: GOTO 141+S/100
141 PRINT "TERRIBLE!": GOTO 150
142 PRINT "LOUSY.": GOTO 150
143 PRINT "POOR.": GOTO 150
144 PRINT "FAIR.": GOTO 150
145 PRINT "GOOD.": GOTO 150
146 PRINT "VERY GOOD.": GOTO 150
147 PRINT "EXCELLENT.": GOTO 150
148 PRINT "NEARLY PERFECT."
150 PRINT "SAME COLORS";: GOTO 20
200 IF SW THEN 220: Q=(PDL(0)-5)/6: IF Q<0 THEN Q=0
205 IF Q>=34 THEN Q=34: COLOR=D: VLIN Q,Q+5 AT 0: COLOR=A: IF P>Q THEN 210: IF Q THEN VLIN 0,Q-1 AT 0: P=Q: RETURN
210 IF P=Q THEN RETURN: IF Q#34 THEN VLIN Q+6,39 AT 0: P=Q: RETURN
220 Q=(Y-5)/3+RND(3)*SGN(W)*(X<10 AND V<0): IF Q<0 THEN Q=0: GOTO 205
400 FOR I=1 TO 80: Q=PEEK(-16336): NEXT I: GOTO 40
Notes
References
Citations
Bibliography
*
*
*
*
*
*
*
*
*
External links
Apple II Integer Basic Disassembly
manually decompiled version by Paul Santa-Maria
– From Landsnail.com's "Apple II Programmer's Reference" website
designed by John Calande, schematic included
{{Apple Inc.
Apple II software
BASIC interpreters
Assembly language software
BASIC programming language family