Applesoft BASIC: Difference between revisions

Content deleted Content added
m WikiCleaner 0.99 - Repairing link to disambiguation page - (You can help)
m Related BASICs: Cite update
 
(267 intermediate revisions by more than 100 users not shown)
Line 1:
{{unrefUse mdy dates|date=MarchDecember 20092021}}
{{short description|Dialect of Microsoft BASIC programming language}}
'''Applesoft BASIC''' was a dialect of [[BASIC programming language|BASIC]] supplied with the [[Apple II series]] of computers. It superseded [[Integer BASIC]] and was the BASIC in [[Read-only memory|ROM]] in all Apple II series computers after the original [[Apple II#Apple II|Apple II]] model. It was also referred to as '''FP''' (from "[[floating point]]") because of the command used to invoke it instead of INT for Integer BASIC. Applesoft BASIC was supplied by [[Microsoft]] and its name is derived from the names of both [[Apple Inc.|Apple]] and Microsoft. Apple employees, including [[Randy Wigginton]], 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."
{{Infobox software
| name = Applesoft BASIC
| logo = <!-- Image name is enough -->
| logo alt =
| screenshot = <!-- Image name is enough -->
| caption =
| screenshot alt =
| collapsible =
| author = [[Marc McDonald]]<br>[[Ric Weiland]]
| developer =
| released = {{Start date and age|1977}}
| discontinued =
| latest release version = Applesoft II
| latest release date = {{Start date and age|1978}}
| latest preview version =
| latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} -->
| programming language =
| operating system = [[Apple II]]
| platform =
| size =
| language =
| language count = <!-- Number only -->
| language footnote =
| genre = [[Microsoft BASIC]]
| license =
| alexa =
| website = <!--{{URL|example.org}}-->
| standard =
| AsOf =
}}
'''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 original [[Apple II]] model. It is also referred to as '''FP BASIC''' (from [[floating-point arithmetic|floating point]]) because of the [[Apple DOS]] command <code>FP</code> used to invoke it, instead of <code>INT</code> for Integer BASIC.
 
Applesoft BASIC was supplied by [[Microsoft]] and its name is derived from the names of both [[Apple Inc.|Apple Computer]] and Microsoft. Apple employees, including [[Randy Wigginton]], adapted Microsoft's interpreter for the Apple II and added several features. The first version of Applesoft was released in 1977 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 and support for the Apple II high-resolution graphics modes, that is usually synonymous with the term "Applesoft."
==Background==
Apple's customers were demanding a version of BASIC that supported [[floating point]] calculations. As [[Steve Wozniak]], 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]] drive and controller and with [[Apple DOS]], Apple turned to Microsoft, who was the BASIC vendor of choice after their success with [[Altair BASIC]], and licensed a 10 KB [[assembly language]] 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.
 
==History==
Applesoft was similar to (and indeed had a common code base with) BASIC implementations on other [[MOS Technology 6502|6502]]-based computers, such as [[Commodore BASIC]]: 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:
When [[Steve Wozniak]] wrote [[Integer BASIC]] for the [[Apple II]], he did not implement support for [[floating-point arithmetic]] because he was primarily interested in writing games, a task for which integers alone were sufficient.<ref name="wozniak20140501">{{cite web |url = https://gizmodo.com/how-steve-wozniak-wrote-basic-for-the-original-apple-fr-1570573636 |title = How Steve Wozniak Wrote BASIC for the Original Apple From Scratch |website = Gizmodo |date = May 1, 2014 |access-date = May 2, 2014 |author = Wozniak, Steve }}</ref> In 1976, Microsoft had developed [[Microsoft BASIC]] for the [[MOS Technology 6502]], 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]] replied that Apple already had one.
* Atomic strings: A string is no longer an array of characters (as in Integer BASIC and [[C (programming language)|C]]); it is instead a [[garbage collection (computer science)|garbage-collected]] object (as in [[Scheme (programming language)|Scheme]] and [[Java (programming language)|Java]]). This allows for string arrays; <code>DIM A$(10)</code> resulted in a [[Array data type|vector]] of ''eleven'' string variables numbered 0–10.
 
* Multidimensional [[Array data type|arrays]]
The Apple II was unveiled to the public at the [[West Coast Computer Faire]] 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.<ref>{{Cite magazine |url = https://techland.time.com/2012/04/16/apple-ii-forever-a-35th-anniversary-tribute-to-apples-first-iconic-product/ |title = Apple II Forever: a 35th-Anniversary Tribute to Apple's First Iconic Product |last = McCracken |first = Harry |date = April 16, 2012 |magazine = Time |access-date = June 21, 2019 |language = en-US |issn = 0040-781X }}</ref> Making things more problematic was that the rival [[Commodore PET]] 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]] drive and controller and with [[Apple DOS]], Apple turned to Microsoft.
* Single-precision [[floating point]] variables with an 8-bit exponent and a 31-bit significand and improved math capabilities, including trigonometry and logarithmic functions
 
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]].<ref>{{cite web |last = Herzfeld |first = Andy |title = MacBasic – The Sad Story of MacBasic |url = http://www.folklore.org/StoryView.py?project=Macintosh&story=MacBasic.txt |website = Folklore.org |date = February 12, 2014 }}</ref> 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 (programming language)|C]]); it is instead a [[garbage collection (computer science)|garbage-collected]] object (as in [[Scheme (programming language)|Scheme]] and [[Java (programming language)|Java]]). This allows for string arrays; {{code|DIM A$(10)|basic}} creates an array of ''eleven'' string variables numbered 0–10.
* Multidimensional [[array (data type)|arrays]] (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
* <code>DATA</code> statements, with <code>READ</code> and <code>RESTORE</code> commands, for representing numerical and string values in quantity
* <code>CHR$</code>, <code>STR$</code>, and <code>VAL</code> functions for converting between string and numeric types (both languages did have the <code>ASC</code> function)
* [[User-defined function]]s: simple one-line functions written in BASIC, with a single parameter
* Error-trapping,: allowing BASIC programs to handle unexpected errors by means of avia subroutine written in BASIC
Conversely, Applesoft lacked the <code>MOD</code> (remainder) operator that had been present in Integer BASIC.
 
Conversely, Applesoft lacks the <code>MOD</code> (remainder) operator from Integer BASIC.
Whereas Wozniak originally referred to his Integer BASIC as "Game BASIC," having written it so he could write a [[Breakout clone]] for his new computer, few [[action game]]s were written in Applesoft BASIC for several reasons:
 
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 assembler|cross assemble]] the BASIC source.<ref>{{cite book |chapter-url = http://apple2history.org/history/ah16/ |title = History of the Apple II |chapter = Chapter 16: Languages |date = July 2010 |access-date = July 6, 2016 }}</ref>
* 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.
==Features==
* [[Shape table]]s were a slow alternative to [[bitmap]]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]] and [[Apple IIc]] models' BASIC interpreters for the new machines' extra memory and double-resolution graphics, or for the [[Apple IIgs|Apple II<small>GS</small>'s]] 16-color mode. ([[Beagle Bros]] offered machine-language workarounds for these problems.)
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 program was stored as a [[linked list]] of lines; a <code>[[GOTO]]</code> or <code>[[GOSUB]]</code> took [[Computational complexity theory|O(n) (linear) time]], 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 <code>GOSUB</code> calls.
 
* No sound support aside from a <code>[[PEEK and POKE|PEEK]]</code> command that could be used to click the speaker, though one could also <code>PRINT</code> an ASCII [[bell character]] to sound the system alert [[beep (sound)|beep]]. 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.
The {{mono|PR#}} statement redirects output to an expansion card, and {{mono|IN#}} redirects input from an expansion card. The slot number of the card is specified after the {{mono|PR#}} or {{mono|IN#}} within the statement. The computer locks-up if there is no card present in the slot. {{mono|PR#0}} restores output to the 40 column screen and {{mono|IN#0}} to the keyboard.
 
The {{mono|PR#}} statement can be used to redirect output to the printer (e.g. {{code|2=basic|10 PR#x:PRINT"Hello!"}}) where x is the slot number containing the printer port card. To send a BASIC program listing to the printer, the user types {{code|PR#x:LIST}}.
 
Using {{mono|PR#}} on a slot with a disk drive (usually in slot 6) causes Applesoft to boot the disk drive. Using {{mono|PR#}} on a slot with an 80 column card (usually in slot 3) switches to 80 column text mode.
 
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 when performing calculations, 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, as it offers no performance benefit.
 
The RND function generates a [[pseudorandom number generator|pseudorandom]] fractional number between 0 and 1. {{code|RND(0)}} returns the most recently generated random number. {{mono|RND}} 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.
 
Like other implementations of Microsoft BASIC, Applesoft discards spaces (outside of strings and comments) on program lines. <code>LIST</code> adds spaces when displaying code for the sake of readability. Since {{mono|LIST}} 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 <code>INPUT</code> is a question mark. <code>PRINT</code> does not add a leading space in front of numbers.
 
===Limitations===
Through several early models of the Apple II, Applesoft BASIC did not support the use of [[lowercase]] letters in programs, except in strings. <code>PRINT</code> is a valid command but <code>print</code> and <code>Print</code> result in a syntax error.
 
Applesoft lacks several commands and functions common to most of the non-6502 Microsoft BASIC interpreters, such as:
* <code>INSTR</code> (search for a substring in a string)
* <code>PRINT USING</code> (format numbers in printed output)
* <code>INKEY$</code> (check for a keypress without stopping the program; although a PEEK to ___location $C000 achieves this action)
* <code>LPRINT</code> (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 <code>OR</code> [[Boolean operator (computer programming)|Boolean operator]], rendered as <code>SC OR E</code>. "BACKGROUND" contains <code>GR</code>, 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 <code>PRINT</code> an ASCII [[bell character]] to sound the system alert [[beep (sound)|beep]], and a <code>[[PEEK and POKE|PEEK]]</code> 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 drawing in the Apple II's low resolution and high resolution modes. There are commands to plot pixels and draw horizontal and vertical lines in low resolution. High resolution allows arbitrary lines and vector-based [[shape table]]s for drawing scaled and rotated objects. The only provision for mixing text and graphics is the 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 high resolution mode, but including all 16 colors of the low resolution palette. Applesoft does not provide direct support for this mode. [[Apple IIGS]]-specific modes are likewise not supported.
 
===Extensions===
Applesoft BASIC can be extended by two means: the ampersand ({{mono|&amp;}}) command and the {{mono|USR()}} 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 {{mono|USR()}} function takes one argument, and can be programmed to derive and return a calculated function value to be used in a numerical expression. {{code|&}} is effectively a shorthand for {{mono|CALL}}, with an address that is predefined. By calling routines in the Applesoft ROM, it is possible for ampersand routines to parse values that follow the ampersand. Numerous third-party commercial packages were available to extend Applesoft using ampersand routines.
 
===Bugs===
A deficiency with error-trapping via <code>ONERR</code> means that the system stack is not reset if an error-handling routine does not invoke <code>RESUME</code>, potentially leading to a crash.<ref name="ManualIIe">{{cite book |title = Applesoft BASIC Programmer's Reference Manual (for IIe only) |url = https://archive.org/details/applesoft-basic-programmers-reference-manual-vol-1-for-iie-only/page/70/mode/2up |publisher = Apple Computer, Inc. |year = 1982 |page = 70 }}</ref> The built-in pseudorandom number generator function <code>RND</code> 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.<ref>{{cite journal |last1 = Aldridge |first1 = James W. |title = Cautions regarding random number generation on the Apple II |journal = Behavior Research Methods, Instruments, & Computers |date = July 1987 |volume = 19 |issue = 4 |pages = 397–99 |doi = 10.3758/BF03202585 |s2cid = 62633043 |doi-access = free }}</ref>
 
===Performance===
Wozniak originally referred to his Integer BASIC as "Game BASIC" (having written it so he could implement a [[Breakout clone|''Breakout'' clone]] for his new computer).<ref name="wozniak20140501" /> Few [[action game]]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]] of lines; a <code>GOTO</code> or <code>GOSUB</code> takes [[Computational complexity theory|linear time]]. 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==
[[File:Applesoft BASIC.png|thumb|[["Hello, World!" program|Hello, World!]], with [[inverse video]] and [[bell character]], run then listed]]
[["Hello, World!" program|Hello, World!]] in Applesoft BASIC couldcan be entered as the following:
<syntaxhighlight lang="cbmbas">
10 TEXT:HOME
10TEXT:HOME
20 ?"HELLO WORLD"
20?"HELLO WORLD"
</syntaxhighlight>
Multiple commands can be included on the same line of code if separated by a colon (<code>:</code>). The <code>?</code> 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 <code>LIST</code> command as:
<syntaxhighlight lang="cbmbas">
10 TEXT : HOME
20 PRINT "HELLO WORLD"
</syntaxhighlight>
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==
Multiple commands could be included on the same line of code if separated by a colon (<code>:</code>). The <code>?</code> can be used in Applesoft BASIC as a shortcut for "PRINT", though spelling out the word is not only acceptable but canonical&mdash;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 <code>LIST</code> command as:
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½&nbsp;KB of memory,<ref>{{cite book |title = Applesoft Extended Precision Floating Point Basic Language Reference Manual |url = https://archive.org/details/Apple_II_Extended_Precision_Floating_Point_BASIC_Language_Reference_Manual/mode/1up |publisher = Apple Computer, Inc. |date = November 1977 }}</ref> instead of the 10&nbsp;KB used by the later Applesoft II. Consequently, it lacks a number of command features developed for the later, mainstream version:
10 TEXT : HOME
* All commands supporting Apple's "high resolution" graphics (9 total)
20 PRINT "HELLO WORLD"
* 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 they wished to disable the REM statement and the LET keyword in assignment statements in exchange for lores graphics commands.
''This article includes text from [http://everything2.com/?node=Applesoft+BASIC Everything2], licensed under GFDL.''
 
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.
==Apple Business BASIC==
Apple Business BASIC shipped with the [[Apple ///]] computer. Donn Denman ported Applesoft BASIC to [[Apple SOS|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.
 
Unlike in Integer BASIC and Applesoft II, the Boolean operators AND, OR and NOT perform [[bitwise operation]]s on 16-bit integer values. If they are given values outside that range, an error results.
== Trivia<ref>Applesoft II Basic Programming Reference Manual, Apple Computer, Inc., 1978</ref> ==
* Despite its heritage, Applesoft lacked commands common to non-6502 Microsoft BASIC interpreters, such as INSTR (which searched for a substring in a given string), 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, 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.<ref>[http://www.txbobsc.com/scsc/scdocumentor/ Disassembled ROM]</ref>
* Applesoft could be extended by two means: the ampersand (&amp;) 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.
* Applesoft, like Integer BASIC before it, did not come with any built-in commands for dealing with files or disks. 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).<ref>The DOS Manual for Apple II, Apple Computer, Inc., 1980, 1981</ref> [[Apple ProDOS|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.<ref>Apple II ProDOS Manual, Apple Computer, Inc.</ref>
 
The terms OUT and PLT (and the aforementioned IN) appear in the list of reserved words, but are not explained anywhere in the manual.
== Notes ==
{{Reflist}}
 
==Related See also BASICs==
Several [[compiler]]s for Applesoft BASIC exist,<ref name="byte198209">{{Cite magazine |last=Taylor |first=Joseph H. |last2=Taylor |first2=Jeffrey S. |date=September 1982 |title=A Comparison of Five Compilers for Applesoft BASIC |url=https://archive.org/details/byte-magazine-1982-09/page/n438/mode/1up?view=theater |access-date=2024-12-30 |magazine=BYTE |pages=440-464}}</ref> including TASC (The Applesoft Compiler) from Microsoft in 1981.<ref>{{cite book |url = https://archive.org/details/TASC_The_AppleSoft_Compiler_Manual/page/n1 |title = TASC (The AppleSoft Compiler) User's Manual |year = 1981 |publisher=Microsoft Consumer Products |___location=Bellevue, WA}}</ref>
* [[Chinese BASIC]] &mdash; a Chinese-localized version of Applesoft BASIC
 
[[Coleco]] claimed that its [[Coleco Adam|Adam]] home computer's SmartBASIC was source-code compatible with Applesoft.<ref name="coleco19830928">{{Cite AV media |url = https://www.youtube.com/watch?v=gg_I9TGYM-w | archive-url = https://ghostarchive.org/varchive/youtube/20211122/gg_I9TGYM-w |archive-date = November 22, 2021 |url-status = live |title = Coleco Presents The Adam Computer System |date = May 3, 2016 |via = YouTube |orig-year = September 28, 1983 |time = 31:55 |quote = Everybody who knows Applesoft BASIC will also know Adam SmartBASIC. All the same commands, all the same controls for this BASIC, this interpreter, are available. In fact, we're going to show you a program which uses Applesoft graphic commands ... executed through Adam. ... As far as we're concerned, when we're in BASIC, and we're not PEEKing or POKEing ... anything below the BASIC interpreter, we are source-code compatible. }}{{cbignore}}</ref>
== External links ==
 
Microsoft licensed a BASIC compatible with Applesoft to [[VTech]] for its [[Laser 128]] [[Apple II clones|clone]].<ref name="grevstad198612">{{cite news |url = https://archive.org/stream/inCider_86-12#page/n59/mode/2up |title = Laser 128 / An Affordable Compatible |work = inCider |date = December 1986 |access-date = April 24, 2017 |last = Grevstad |first = Eric |pages = 58 }}</ref>
 
==See also==
* [[ALF Products#FTL|ALF's Formula Transfer Link]], speed enhancement for Applesoft BASIC
* [[Chinese BASIC]], a Chinese-localized version of Applesoft BASIC
* [[Apple III#BASIC|Apple III BASIC]]s from Apple and Microsoft
 
==References==
{{Reflist}}
This article includes text from [http://everything2.com/?node=Applesoft+BASIC Everything2], licensed under GFDL.
 
==External links==
* [http://www.txbobsc.com/scsc/scdocumentor/ Disassembled ROM]
* [http://www.calormen.com/jsbasic/ AppleSoft BASIC in JavaScript]
 
{{BASIC}}
 
{{DEFAULTSORT:Applesoft Basic}}
[[Category:Apple II software]]
[[Category:BASIC interpreters]]
[[Category:Discontinued Microsoft BASICs]]
[[Category:BASIC programming language family]]
 
[[Category:Microsoft programming languages]]
[[de:Applesoft BASIC]]
[[ko:애플소프트 베이직]]
[[it:Applesoft BASIC]]
[[nl:Applesoft BASIC]]
[[ru:Applesoft BASIC]]
[[fi:Applesoft BASIC]]