Applesoft BASIC
Encyclopedia
Applesoft BASIC was a dialect of Microsoft BASIC
Microsoft BASIC
Microsoft BASIC was the foundation product of the Microsoft company. It first appeared in 1975 as Altair BASIC, which was the first BASIC, and the first high level programming language available for the MITS Altair 8800 hobbyist microcomputer....

 supplied with the Apple II series
Apple II series
The Apple II series is a set of 8-bit home computers, one of the first highly successful mass-produced microcomputer products, designed primarily by Steve Wozniak, manufactured by Apple Computer and introduced in 1977 with the original Apple II...

 of computers. It superseded Integer BASIC
Integer BASIC
Integer BASIC, written by Steve Wozniak, was the BASIC interpreter of the Apple I and original Apple II computers. Originally available on cassette, then included in ROM on the original Apple II computer at release in 1977, it was the first version of BASIC used by many early home computer owners...

 and was the BASIC in ROM
Read-only memory
Read-only memory is a class of storage medium used in computers and other electronic devices. Data stored in ROM cannot be modified, or can be modified only slowly or with difficulty, so it is mainly used to distribute firmware .In its strictest sense, ROM refers only...

 in all Apple II series computers after the original Apple II model. It was also referred to as FP (from "floating point
Floating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

") because of the command used to invoke it instead of INT for Integer BASIC. Applesoft BASIC was supplied by Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

 and its name is derived from the names of both Apple and Microsoft. Apple employees, including Randy Wigginton
Randy Wigginton
Randy Wigginton was one of Apple Computer's first employees , creator of MacWrite, Full Impact, and numerous other Mac applications. He used to work in development at eBay, Quigo, Inc and Move.com. In Nov 2010 he left his position as a "Site Reliability Engineer" at Google Inc., purportedly after...

, adapted Microsoft's interpreter for the Apple II and added several features. The first version of Applesoft was released in 1977 only on cassette tape 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 and subsequent models, was released in 1978. It is this latter version, which has some syntax differences from the first as well as support for the Apple II high-resolution graphics modes, that most people mean by the term "Applesoft."

Background

Apple's customers were demanding a version of BASIC that supported floating point
Floating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

 calculations. As Steve Wozniak
Steve Wozniak
Stephen Gary "Woz" Wozniak is an American computer engineer and programmer who founded Apple Computer, Co. with Steve Jobs and Ronald Wayne...

, the creator of Integer BASIC and the only person who understood it well enough to add floating point features, was busy with the Disk II
Disk II
The Disk II Floppy Disk Subsystem was a 5¼-inch floppy disk drive designed by Steve Wozniak and manufactured by Apple Computer. It was first introduced in 1978 at a retail price of US$495 for pre-order; it was later sold for $595 including the controller card and cable...

 drive and controller and with Apple DOS
Apple DOS
Apple DOS refers to operating systems for the Apple II series of microcomputers from late 1978 through early 1983. Apple DOS had three major releases: DOS 3.1, DOS 3.2, and DOS 3.3; each one of these three releases was followed by a second, minor "bug-fix" release, but only in the case of Apple DOS...

, Apple turned to Microsoft, who was the BASIC vendor of choice after their success with Altair BASIC
Altair BASIC
Altair BASIC was an 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 , distributed by MITS under a contract...

, and licensed a 10 KB assembly language
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

 version of BASIC dubbed "Applesoft." Apple reportedly obtained an eight-year license for Applesoft BASIC from Microsoft for a flat fee of $21,000, renewing it in 1985 through an arrangement that gave Microsoft the rights and source code for Apple's Macintosh version of BASIC.

Applesoft was similar to (and indeed had a common code base with) Microsoft BASIC implementations on other 6502
MOS Technology 6502
The MOS Technology 6502 is an 8-bit microprocessor that was designed by Chuck Peddle and Bill Mensch for MOS Technology in 1975. When it was introduced, it was the least expensive full-featured microprocessor on the market by a considerable margin, costing less than one-sixth the price of...

-based computers, such as Commodore BASIC
Commodore BASIC
Commodore BASIC, also known as PET BASIC, is the dialect of the BASIC programming language used in Commodore International's 8-bit home computer line, stretching from the PET of 1977 to the C128 of 1985...

: it used line numbers, and spaces were not necessary in lines. While Applesoft was slower than Integer BASIC, it had many features that the older BASIC lacked:
  • Atomic strings: A string is no longer an array of characters (as in Integer BASIC and C
    C (programming language)
    C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

    ); it is instead a garbage-collected
    Garbage collection (computer science)
    In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...

     object (as in Scheme and Java
    Java (programming language)
    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

    ). This allows for string arrays; DIM A$(10) resulted in a vector
    Array data type
    In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...

     of eleven string variables numbered 0–10.
  • Multidimensional arrays
    Array data type
    In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...

  • Single-precision floating point
    Floating point
    In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

     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
  • CHR$, STR$, and VAL functions for converting between string and numeric types (both languages did have the ASC function)
  • User-defined functions: simple one-line functions written in BASIC, with a single parameter
  • Error-trapping, allowing BASIC programs to handle unexpected errors by means of a subroutine written in BASIC

Conversely, Applesoft lacked the MOD (remainder) operator that had been present in Integer BASIC.

Whereas Wozniak originally referred to his Integer BASIC as "Game BASIC," having written it so he could write a Breakout clone
Breakout clone
A Breakout clone is a sub-class of the "bat-and-ball" genre introduced with the Magnavox Odyssey's Tennis and Atari's Pong...

 for his new computer, few action game
Action game
Action game is a video game genre that emphasizes physical challenges, including hand–eye coordination and reaction-time. The genre includes diverse subgenres such as fighting games, shooter games, and platform games, which are widely considered the most important action games, though some...

s were written in Applesoft BASIC for several reasons:
  • In that era of carefully counting clock cycles and limited memory, it was inefficient to write speed-dependent programs that ran on a runtime interpreter.
  • The use of "real" (floating-point) numbers for all math operations created unnecessary overhead and degraded performance. Applesoft converted integer numbers to real before performing operations on them, converting the result back to an integer only if it was to be assigned to a (16-bit signed) integer variable.
  • Shape table
    Shape table
    Shape tables were a powerful yet little-used feature of the early Apple II ROMs, allowing for simple graphic manipulation on Apple II series computers, using the "hi-res" graphics mode...

    s were a slow alternative to bitmap
    Bitmap
    In computer graphics, a bitmap or pixmap is a type of memory organization or image file format used to store digital images. The term bitmap comes from the computer programming terminology, meaning just a map of bits, a spatially mapped array of bits. Now, along with pixmap, it commonly refers to...

    s. No provision existed for mixing text and graphics, except for the limited "hardware split screen" of the Apple II (four lines of text at the bottom of the screen). Many graphics programs thus contained their own bitmap character generator routines. No provision was added in the 128 kB Apple IIe
    Apple IIe
    The Apple IIe is the third model in the Apple II series of personal computers produced by Apple Computer. The e in the name stands for enhanced, referring to the fact that several popular features were now built-in that were only available as upgrades and add-ons in earlier models...

     and Apple IIc
    Apple IIc
    The Apple IIc, the fourth model in the Apple II series of personal computers, was Apple Computer’s first endeavor to produce a portable computer. The end result was a notebook-sized version of the Apple II that could be transported from place to place...

     models' BASIC interpreters for the new machines' extra memory and double-resolution graphics, or for the Apple IIGS's
    Apple IIGS
    The Apple , the fifth and most powerful model in the Apple II series of personal computers produced by Apple Computer. The "GS" in the name stands for Graphics and Sound, referring to its enhanced graphics and sound capabilities, both of which greatly surpassed previous models of the line...

     16-color mode. (Beagle Bros
    Beagle Bros
    Beagle Bros was a software company that specialized in creating personal computing products that were both useful and whimsical. Their primary focus was on the Apple II family of computers.-History:...

     offered machine-language workarounds for these problems.)
  • The program was stored as a linked list
    Linked list
    In computer science, a linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of a datum and a reference to the next node in the sequence; more complex variants add additional links...

     of lines; a GOTO
    Goto
    goto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...

    or GOSUB
    GOSUB
    GOSUB is a command in many versions of the BASIC computer programming language. A GOSUB statement jumps to a line elsewhere in the program. That line and the following lines up to a RETURN are used as a simple kind of a subroutine without parameters or local variables.The GOSUB command may be used...

    took O(n) (linear) time
    Computational complexity theory
    Computational complexity theory is a branch of the theory of computation in theoretical computer science and mathematics that focuses on classifying computational problems according to their inherent difficulty, and relating those classes to each other...

    , and although Applesoft programs were not very long compared to today's software, on a 1 MHz 6502 this could be a significant bottleneck. Large programs were often written with the most-used subroutines at the top of the program to reduce the processing time for GOSUB calls.
  • No sound support aside from a PEEK
    PEEK and POKE
    In computing, PEEK is a BASIC programming language extension used for reading the contents of a memory cell at a specified address. The corresponding command to set the contents of a memory cell is POKE.-Statement syntax:...

    command that could be used to click the speaker, though one could also PRINT an ASCII bell character
    Bell character
    A bell code 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 message...

     to sound the system alert beep
    Beep (sound)
    A beep is a single tone onomatopoeia, generally made by a computer or a machine.-Use in computers:In some computer terminals, the ASCII character code 7, bell character, outputs an audible beep. The beep is also sometimes used to notify the user when the BIOS is not working or there is some other...

    . The language was not fast enough to produce more than a baritone buzz from repeated clicks anyway. However, music spanning several octaves could be played by repeated calls to a machine-language tone generator.

Sample code

Hello World in Applesoft BASIC could be entered as the following:
10 TEXT:HOME
20 ?"HELLO WORLD"

Multiple commands could be included on the same line of code if separated by a colon (:). The ? can be used in Applesoft 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 either would appear as "PRINT" when a program was listed. The program above would be appear in a LIST command as:
10 TEXT : HOME
20 PRINT "HELLO WORLD"

This article includes text from Everything2, licensed under GFDL.

Apple Business BASIC

Apple Business BASIC shipped with the Apple /// computer. Donn Denman ported Applesoft BASIC to SOS and reworked it to take advantage of the extended memory of the Apple ///. Following the trend of avoiding absolute addresses, the PEEK and POKE commands were replaced with INVOKE and PERFORM statements that loaded and executed separately-assembled code modules.

Trivia

  • Despite its heritage, Applesoft lacked commands common to most other Microsoft BASIC interpreters, such as INSTR (which searched for a substring in a given string; this had to be done manually with loops and the MID$ function), PRINT USING (which formatted numbers with commas and currency signs according to a format string), and INKEY$ (which checked for a keypress without stopping the program as Applesoft's GET command—analogous to the INPUT$ function—did, although a PEEK location did provide this functionality). It seems likely that memory constraints were at the root of these differences, as the Apple II ROM had only 10 kilobytes available for the interpreter, and the improved hi-res graphics support was clearly a higher priority. Microsoft's CLS command (for clearing the screen) was renamed HOME in Applesoft.
  • There was a well-documented bug in Applesoft BASIC that could actually crash the interpreter if ONERR GOTO was in effect and numerous program errors occurred. Apple provided a short assembly-language routine which could be POKEd into RAM and CALLed to ameliorate the problem to an extent. Later it was discovered by an enterprising hacker that the required code was actually in the Applesoft ROM (though it was never executed) and could be called there instead: CALL -3288 or (equivalent) 62248.
  • Applesoft could be extended by two means: the ampersand (&) command and the USR function. These were two functions that called machine-language functions stored in memory. Routines that needed to be as fast or required direct access to arbitrary functions or data in memory could thus be called from a higher-level interpreted BASIC program. Additionally, these lower-level functions could read the data immediately following the "&" or "USR" command, allowing a BASIC program to pass parameters to the functions.
  • Both Integer BASIC and Applesoft used tokenizing to reduce the memory requirements of programs and to speed their interpretation. As code was entered, BASIC keywords would be converted to single-byte tokens; the process was reversed when the program was listed. Integer BASIC used characters with codes above 127 for normal text and codes below 128 for tokens; Applesoft used exactly the reverse. Unlike Integer BASIC, Applesoft did not tokenize literal numbers appearing in the code but stored them digit by digit. As a result of the tokenizing process, programmers could not use any variable name that had the name of one of the BASIC commands (e.g. a person could not use the name "SCORE" because the "OR" would invoke a disjunction
    Logical disjunction
    In logic and mathematics, a two-place logical connective or, is a logical disjunction, also known as inclusive disjunction or alternation, that results in true whenever one or more of its operands are true. E.g. in this context, "A or B" is true if A is true, or if B is true, or if both A and B are...

     operator, and "BACKGROUND" could similarly not be used because "GR" would invoke the low-resolution graphics system; both would create syntax errors).
  • Applesoft, like Integer BASIC before it, did not come with any built-in commands for dealing with files or disks, other than a feature to save programs to, and load programs from, audiotape. The Apple II disk operating system, known simply as DOS, thus intercepted all input typed at the BASIC command prompt to determine whether it was a DOS command. Similarly, all output was scrutinized for a Control-D character (ASCII 4), which BASIC programs would send before seemingly PRINTing a disk command to get DOS's attention (the disk commands would not really get PRINTed but were intercepted by DOS and prevented from making it to the screen output). ProDOS followed this lead, although the BASIC command interpreter was placed in a separate program called BASIC.SYSTEM and the hook worked in a different manner.
  • Variable names were limited to two letters; they could be made longer, but only the first two letters would be used. For instance, "LOW" and "LOSS" would be treated as the same variable, and attempting to assign a value to "LOSS" would overwrite any value assigned to "LOW."

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK