Applesoft BASIC is a dialect 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 ve ...
, developed by
Marc McDonald
Marc B. McDonald is an American who was Microsoft's first salaried employee (not counting Monte Davidoff, who wrote the math package for BASIC for a flat fee).
He is credited with designing and implementing the 8-bit File Allocation Table file sy ...
and
Ric Weiland
Richard William "Ric" Weiland (April 21, 1953 – June 24, 2006) was a computer software pioneer, programmer and philanthropist. He was the second employee at Microsoft Corporation, joining the company during his final year at Stanford Un ...
, supplied with the
Apple II series of computers. It supersedes
Integer BASIC
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 ve ...
and is the BASIC in
ROM
Rom, or ROM may refer to:
Biomechanics and medicine
* Risk of mortality, a medical classification to estimate the likelihood of death for a patient
* Rupture of membranes, a term used during pregnancy to describe a rupture of the amniotic sac
* ...
in all Apple II series computers after the original
Apple II
The Apple II (stylized as ) is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak; Jerry Manock developed the design of Apple II's foam-m ...
model. It is also referred to as FP BASIC (from
floating point
In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be ...
) because of the
Apple DOS command used to invoke it, instead of
INT
for Integer BASIC.
Applesoft BASIC was supplied by
Microsoft
Microsoft Corporation is an American multinational technology corporation producing computer software, consumer electronics, personal computers, and related services headquartered at the Microsoft Redmond campus located in Redmond, Washing ...
and its name is derived from the names of both
Apple Computer
Apple Inc. is an American multinational technology company headquartered in Cupertino, California, United States. Apple is the largest technology company by revenue (totaling in 2021) and, as of June 2022, is the world's biggest company b ...
and Microsoft. Apple employees, including
Randy Wigginton
Randy Wigginton was one of Apple Computer's first employees (#6), creator of MacWrite, Full Impact, and numerous other Mac applications. He used to work in development at eBay, Quigo, Inc and Move.com. In November 2010, he left his position as ...
, adapted Microsoft's interpreter for the Apple II and added several features. The first version of Applesoft was released in 1977 on
cassette tape
The Compact Cassette or Musicassette (MC), also commonly called the tape cassette, cassette tape, audio cassette, or simply tape or cassette, is an analog magnetic tape recording format for audio recording and playback. Invented by Lou Ottens ...
and lacked proper support for high-resolution graphics. Applesoft II, which was made available on cassette and disk and in the ROM 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 Computer. It was sold from June 1979 to December 1982. Approximately 380,000 II Pluses were sold during its ...
and subsequent models, was released in 1978. It is this latter version, which has some syntax differences and support for the Apple II high-resolution graphics modes, that is usually synonymous with the term "Applesoft."
A compiler for Applesoft BASIC, ''TASC'' (The Applesoft Compiler), was released by Microsoft in 1981.
History
When
Steve Wozniak
Stephen Gary Wozniak (; born August 11, 1950), also known by his nickname "Woz", is an American electronics engineer, computer programmer, philanthropist, inventor, and technology entrepreneur. In 1976, with business partner Steve Jobs, he c ...
wrote
Integer BASIC
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 ve ...
for the
Apple II
The Apple II (stylized as ) is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak; Jerry Manock developed the design of Apple II's foam-m ...
, he did not implement support for
floating-point arithmetic
In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be ...
because he was primarily interested in writing games, a task for which integers alone were sufficient.
In 1976, Microsoft had developed
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 ve ...
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 microprocessor that was designed by a small t ...
, but at the time there was no production computer that used it. Upon learning that Apple had a 6502 machine, Microsoft asked if the company were interested in licensing BASIC, but
Steve Jobs
Steven Paul Jobs (February 24, 1955 – October 5, 2011) was an American entrepreneur, industrial designer, media proprietor, and investor. He was the co-founder, chairman, and CEO of Apple; the chairman and majority shareholder of Pixar; a ...
replied that Apple already had one.
The Apple II was unveiled to the public at the
West Coast Computer Faire
The West Coast Computer Faire was an annual computer industry conference and exposition most often associated with San Francisco, its first and most frequent venue. The first fair was held in 1977 and was organized by Jim Warren and Bob Reil ...
in April 1977 and became available for sale in June. One of the most common customer complaints about the computer was BASIC's lack of floating-point math. Making things more problematic was that the rival
Commodore PET
The Commodore PET is a line of personal computers produced starting in 1977 by Commodore International. A single all-in-one case combines a MOS Technology 6502 microprocessor, Commodore BASIC in read-only memory, keyboard, monochrome monitor, an ...
personal computer had a floating point-capable BASIC interpreter from the beginning. As Wozniak—the only person who understood Integer BASIC well enough to add floating point features—was busy with the
Disk II
The Disk II Floppy Disk Subsystem, often rendered as Disk ] '', is a -inch floppy disk drive designed by Apple Computer, Inc. It went on sale in June 1978 at a retail price of US$495 for pre-order; it was later sold for $595 () including the Di ...
drive and controller and with
Apple DOS, Apple turned to Microsoft.
Apple reportedly obtained an eight-year license for Applesoft BASIC from Microsoft for a flat fee of $31,000, renewing it in 1985 through an arrangement that gave Microsoft the rights and source code for Apple's
MacBASIC, Macintosh version of BASIC. Applesoft was designed to be backwards-compatible with Integer BASIC and uses the core of Microsoft's 6502 BASIC implementation, which includes using the GET command for detecting key presses and not requiring any spaces on program lines. While Applesoft BASIC is slower than Integer BASIC, it has many features that the older BASIC lacks:
* Atomic strings: A string is no longer an array of characters (as in Integer BASIC and
C); it is instead a
garbage-collected object (as in
Scheme A scheme is a systematic plan for the implementation of a certain idea.
Scheme or schemer may refer to:
Arts and entertainment
* ''The Scheme'' (TV series), a BBC Scotland documentary series
* The Scheme (band), an English pop band
* ''The Schem ...
and
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
). This allows for string arrays; creates an array of ''eleven'' string variables numbered 0–10.
* Multidimensional
arrays
An array is a systematic arrangement of similar objects, usually in rows and columns.
Things called an array include:
{{TOC right
Music
* In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
(numbers or strings)
* Single-precision floating-point variables with an 8-bit exponent and a 31-bit significand and improved math capabilities, including trigonometry and logarithmic functions
* Commands for high-resolution graphics
*
DATA
statements, with
READ
and
RESTORE
commands, for representing numerical and string values in quantity
*
CHR$
,
STR$
, and
VAL
functions for converting between string and numeric types (both languages did have the
ASC
function)
*
User-defined function A user-defined function (UDF) is a function provided by the user of a program or environment, in a context where the usual assumption is that functions are built into the program or environment. UDFs are usually written for the requirement of its c ...
s: simple one-line functions written in BASIC, with a single parameter
* Error-trapping: allowing BASIC programs to handle unexpected errors via subroutine written in BASIC
Conversely, Applesoft lacks the
MOD
(remainder) operator from Integer BASIC.
Adapting BASIC for the Apple II was a tedious job as Apple received a source listing for Microsoft 6502 BASIC which proved to be buggy and also required the addition of Integer BASIC commands. Since Apple had no 6502 assembler on hand, the development team was forced to send the source code over the phone lines to Call Computer, an outfit that offered compiler services. This was an extremely tedious, slow process and after Call Computer lost the source code due to an equipment malfunction, one of the programmers, Cliff Huston, used his own IMSAI 8080 computer to
cross assemble the BASIC source.
Features
Applesoft is similar to Commodore's BASIC 2.0 aside from features inherited from Integer BASIC. There are a few minor differences such as Applesoft's lack of bitwise operators; otherwise most BASIC programs that do not use hardware-dependent features will run on both BASICs.
The statement redirects output to an expansion card, and IN# redirects input from an expansion card. The slot number of the card is specified after the or within the statement. The computer locks-up if there is no card present in the slot. restores output to the 40 column screen and to the keyboard.
The PR# statement can be used to redirect output to the printer (e.g. ) where x is the slot number containing the printer port card. To send a BASIC program listing to the printer, the user types .
PR#6 causes Applesoft to boot the disk drives (although the Disk II controller can be in any slot, it is usually in slot 6). PR#3 switches to 80 column text mode if an 80 column card is present.
As with Commodore BASIC, numeric variables are stored as 40-bit floating point; each variable requires five bytes of memory. The programmer may designate variables as integer by following them with a percent sign, in which case they use two bytes and are limited to a range of -32768 to 32767; however BASIC internally converts them back to floating point, while each percent sign also takes an additional byte of program code, so in practice this feature is only useful for reducing the memory usage of large array variables.
The RND function generates a
pseudorandom
A pseudorandom sequence of numbers is one that appears to be statistically random, despite having been produced by a completely deterministic and repeatable process.
Background
The generation of random numbers has many uses, such as for rand ...
fractional number between 0 and 1. returns the most recently generated random number. with a negative number will jump to a point in the sequence determined by the particular negative number used. RND with any positive value generates the next number in the sequence, not dependent on the actual value given. Locations and , which the system cycles the values of continuously while waiting for user keystrokes, can be PEEKed to provide truly random values to use as a seed (when negated) for . For example, after keyboard input, will seed RND with the values of and .
Like other implementations of Microsoft BASIC, Applesoft discards spaces (outside of strings and comments) on program lines.
LIST
adds spaces when displaying code for the sake of readability. Since adds a space before and after every tokenized keyword, it often produces two spaces in a row where one would suffice for readability.
The default prompt for
INPUT
is a question mark.
PRINT
does not add a leading space in front of numbers.
Coleco
Coleco Industries, Inc. was an American company founded in 1932 by Maurice Greenberg as The Connecticut Leather Company. It was a successful toy company in the 1980s, mass-producing versions of Cabbage Patch Kids dolls and its video game conso ...
claimed that its
Adam
Adam; el, Ἀδάμ, Adám; la, Adam is the name given in Genesis 1-5 to the first human. Beyond its use as the name of the first man, ''adam'' is also used in the Bible as a pronoun, individually as "a human" and in a collective sense as " ...
home computer's SmartBASIC was source-code compatible with Applesoft.
Microsoft licensed a BASIC compatible with Applesoft to
VTech for its
Laser 128
The Laser 128 is an Apple II clone, released by VTech in 1986 and comparable to the Apple IIe and Apple IIc.
Description
VTech Laser 128 has 128 kB of RAM. Like the Apple IIc, it is a one-piece semi-portable design with a carrying handle ...
clone.
Limitations
Through several early models of the Apple II, Applesoft BASIC did not support the use of
lowercase
Letter case is the distinction between the letters that are in larger uppercase or capitals (or more formally ''majuscule'') and smaller lowercase (or more formally ''minuscule'') in the written representation of certain languages. The writing ...
letters in programs, except in strings.
PRINT
is a valid command but
print
and
Print
result in a syntax error.
Applesoft lacks several commands and functions common to most of the non-6502 Microsoft BASIC interpreters, such as:
*
INSTR
(search for a substring in a string)
*
PRINT USING
(format numbers in printed output)
*
INKEY$
(check for a keypress without stopping the program; although a PEEK to location $C000 achieves this action)
*
LPRINT
(output to a printer instead of the screen)
Applesoft does not have commands for file or disk handling, other than to save and load programs via cassette tape. The Apple II disk operating system, known simply as DOS, augments the language to provide such abilities.
Only the first two letters of variables names are significant. For example, "LOW" and "LOSS" are treated as the same variable, and attempting to assign a value to "LOSS" overwrites any value assigned to "LOW". A programmer also has to avoid consecutive letters that are Applesoft commands or operations. The name "SCORE" for a variable is interpreted as containing the
OR
Boolean operator, rendered as
SC OR E
. "BACKGROUND" contains
GR
, the command to invoke the low-resolution graphics mode, and results in a syntax error.
Sound and graphics
The only sound support is the option to
PRINT
an ASCII
bell character
A bell code (sometimes bell character) is a device control code originally sent to ring a small electromechanical bell on tickers and other teleprinters and teletypewriters to alert operators at the other end of the line, often of an incoming me ...
to sound the system alert
beep
The Blocks Extensible Exchange Protocol (BEEP) is a framework for creating network application protocols. BEEP includes building blocks like framing, pipelining, multiplexing, reporting and authentication for connection and message-oriented pe ...
, and a
PEEK
Polyether ether ketone (PEEK) is a colourless organic thermoplastic polymer in the polyaryletherketone (PAEK) family, used in engineering applications. The polymer was first developed in November 1978, later being introduced to the market by Vic ...
command to click the speaker. The language is not fast enough to produce more than a baritone buzz from repeated clicks. Programs can, however, store a machine-language routine to be called to generate electronic musical tones spanning several octaves.
Applesoft supports the low resolution (''lores'') graphics display, where 40 color pixels horizontally, and up to 48 vertically, can be displayed in 16 colors, and the 280 by 192 high resolution (''hires'') mode. There are commands to plot pixels and draw horizontal and vertical lines in lores. Hires allows drawing arbitrary lines. Vector-based
shape table
Shape tables are a feature of the Apple II ROMs which allows for manipulation of small images encoded as a series of vectors. An image (or ''shape'') can be drawn in the high-resolution graphics mode—with scaling and rotation—via software rou ...
s can be used to draw objects in high-resolution graphic modes. They consist of horizontal and vertical lines, and entire shapes can be scaled to larger sizes and rotated to any angle. No provision exists for mixing text and graphics, except for the Apple's four lines of text at the bottom of a graphic display.
Beginning with the Apple IIe, a "double-high resolution" mode became available on machines with 128k of memory. This mode essentially duplicates the resolution of the original hires mode, but including all 16 colors of the lores palette. Applesoft does not provide direct support for this mode.
Apple IIGS
The Apple IIGS (styled as II), the fifth and most powerful of the Apple II family, is a 16-bit personal computer produced by Apple Computer. While featuring the Macintosh look and feel, and resolution and color similar to the Amiga and Atari ST ...
-specific modes are likewise not supported.
Extensions
Applesoft BASIC can be extended by two means: the ampersand () command and the function. These are two features that call low-level machine-language routines stored in memory, which is useful for routines that need to be fast or require direct access to arbitrary functions or data in memory. The function takes one numerical argument, and can be programmed to derive and return a calculated function value, to be used in a numerical expression. is effectively a shorthand for , with an address that is predefined.
Bugs
A deficiency with error-trapping via
ONERR
means that the system stack is not reset if an error-handling routine does not invoke
RESUME
, potentially leading to a crash.
The built-in pseudorandom number generator function
RND
is capable of producing a predictable series of outputs due to the manner in which the generator is seeded when first powering on. This behavior is contrary to how Apple's documentation describes the function.
Performance
Wozniak originally referred to his Integer BASIC as "Game BASIC" (having written it so he could implement a
''Breakout'' clone for his new computer).
Few
action game
An action game is a video game genre that emphasizes physical challenges, including hand–eye coordination and reaction-time. The genre includes a large variety of sub-genres, such as fighting games, beat 'em ups, shooter games, and platform gam ...
s were written in Applesoft BASIC, in large part because the use of floating-point numbers for all math operations degrades performance.
Applesoft BASIC programs are stored as a
linked list
In computer science, a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes whic ...
of lines; a
GOTO
or
GOSUB
takes
linear time
In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by ...
. Some programs have the subroutines at the top to reduce the time for calling them.
Unlike Integer BASIC, Applesoft does not convert literal numbers (like 100) in the source code to binary when a line is entered. Rather, the ASCII string is converted whenever the line is executed. Since variable lookup is often faster than this conversion, it can be faster to store numeric constants used inside loops in variables before the loop is entered.
Sample code
Hello World
''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses
''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich ...
in Applesoft BASIC can be entered as the following:
10TEXT:HOME
20?"HELLO WORLD"
Multiple commands can be included on the same line of code if separated by a colon (
:
). The
?
can be used in Applesoft BASIC (and almost all versions of Microsoft BASIC) as a shortcut for "PRINT", though spelling out the word is not only acceptable but canonical—Applesoft converted "?" in entered programs to the same token as "PRINT" (thus no memory is actually saved by using "?"), thus either appears as "PRINT" when a program is listed. The program above appears in a
LIST
command as:
10 TEXT : HOME
20 PRINT "HELLO WORLD"
When Applesoft II BASIC was initially released in mid-1978, it came on cassette tape and could be loaded into memory via the Apple II's machine language monitor. When the enhanced Apple II+ replaced the original II in 1979, Applesoft was now included in ROM and automatically started on power-up if no bootable floppy disk was present. Conversely, Integer BASIC was now removed from ROM and turned into an executable file on the DOS 3.3 disk.
Early evolution
The original Applesoft, stored in RAM as documented in its Reference Manual of November 1977, has smaller interpreter code than the later Applesoft II, occupying 8½ KB of memory,
instead of the 10 KB used by the later Applesoft II. Consequently, it lacks a number of command features developed for the later, mainstream version:
* All commands supporting Apple's "high resolution" graphics (9 total)
* Error-trapping with ONERR...GOTO and RESUME
* Machine-routine shorthand call "&"
* Screen-clearing HOME (a call to a system ROM routine)
* Text-output control NORMAL, INVERSE, FLASH and SPEED=
* The print-space function SPC() is listed among reserved words in the manual, but is not otherwise documented (the TAB() print-function ''is'' documented)
* Cassette tape storage of numerical arrays: STORE and RECALL
* Device response: WAIT
as well as several the later version would have, that had already been present in Apple's Integer BASIC:
* Program-line deletion: DEL
* Machine-routine access: CALL
* Peripheral device access: IN# and PR# (although IN without "#" is listed among reserved words)
* Memory range control: HIMEM: and LOMEM:
* Execution tracking for debugging: TRACE and NOTRACE
* Screen-positioning: HTAB and VTAB
* Subroutine aborting POP
* Functions PDL() to read the analog controllers, and SCRN() to read the low-resolution graphics screen (both accessing system ROM routines)
In addition, its low-resolution graphics commands have different names from their Integer BASIC/Applesoft II counterparts. All command names are of the form PLTx such that GR, COLOR=, PLOT, HLIN and VLIN are called PLTG, PLTC, PLTP, PLTH, and PLTV, respectively. The command for returning to text mode, known as TEXT in other versions, is simply TEX, and carries the proviso that it has to be the last statement in a program line.
Applesoft BASIC 1.x was closer to Microsoft's original 6502 BASIC code than the later Applesoft II; it retained the Memory Size? prompt and displayed a Microsoft copyright notice. To maintain consistency with Integer BASIC, the "Ok" prompt from Microsoft's code was replaced by a ] character. Applesoft 1.x also prompted the user upon loading if he wished to disable the REM statement and the LET keyword in assignment statements in exchange for lores graphics commands.
The USR() function is also defined differently, serving as a stand-in for the absent CALL command. Its argument is not for passing a numerical value to the machine-language routine, but is instead the call-address of the routine itself; there is no "hook" to pre-define the address. All of several examples in the manual use the function only to access "system monitor ROM" routines, or short user-routines to manipulate the ROM routines. No mention is made of any code to calculate the value returned by the function itself; the function is always shown being assigned to "dummy" variables, which, without action to set a value by user-code, just receive a meaningless value handed back to them. Even accessed ROM routines that return values (in examples, those that provide the service of PDL() and SCRN() functions) merely have their values stored, by user-routines, in locations that are separately PEEKed in a subsequent statement.
Unlike in Integer BASIC and Applesoft II, the Boolean operators AND, OR and NOT perform
bitwise operation
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operati ...
s on 16-bit integer values. If they are given values outside that range, an error results.
The terms OUT and PLT (and the aforementioned IN) appear in the list of reserved words, but are not explained anywhere in the manual.
See also
*
ALF's Formula Transfer Link, speed enhancement for Applesoft BASIC
*
Chinese BASIC Chinese BASIC () is the name given to several Chinese-localized versions of the BASIC programming language in the early 1980s.
Versions
At least two versions of Chinese BASIC were modified Applesoft BASIC that accepted Chinese commands and varia ...
, a Chinese-localized version of Applesoft BASIC
*
Apple III BASICs from Apple and Microsoft
References
External links
Disassembled ROMAppleSoft BASIC in JavaScript
{{DEFAULTSORT:Applesoft Basic
Apple II software
BASIC interpreters
Discontinued Microsoft BASICs
BASIC programming language family
Microsoft programming languages