Applesoft BASIC

Last updated

Applesoft BASIC
Original author(s) Marc McDonald
Ric Weiland
Initial release1977;47 years ago (1977)
Stable release
Applesoft II / 1978;46 years ago (1978)
Operating system Apple II
Type Microsoft 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 ROM in all Apple II series computers after the original Apple II model. It is also referred to as FP BASIC (from floating point) because of the Apple DOS command FP used to invoke it, instead of INT for Integer BASIC.

Contents

Applesoft BASIC was supplied by Microsoft and its name is derived from the names of both 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."

A compiler for Applesoft BASIC, TASC (The Applesoft Compiler), was released by Microsoft in 1981. [1]

History

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. [2] 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.

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. [3] 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.

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 Macintosh version of BASIC. [4] 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:

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. [5]

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 PR# 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 PR# or IN# within the statement. The computer locks-up if there is no card present in the slot. PR#0 restores output to the 40 column screen and IN#0 to the keyboard.

The PR# statement can be used to redirect output to the printer (e.g. 10PR#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 PR#x:LIST.

Using PR# on a slot with a disk drive (usually in slot 6) causes Applesoft to boot the disk drive. Using 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 fractional number between 0 and 1. RND(0) returns the most recently generated random number. 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. LIST adds spaces when displaying code for the sake of readability. Since 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 INPUT is a question mark. PRINT 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. 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:

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 to sound the system alert beep, and a PEEK 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 tables 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 (&) command and the 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 USR() function takes one 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 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 ONERR means that the system stack is not reset if an error-handling routine does not invoke RESUME, potentially leading to a crash. [6] 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. [7]

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). [2] Few action games 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 GOTO or GOSUB takes 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

Hello, World!, with inverse video and bell character, run then listed Applesoft BASIC.png
Hello, World!, with inverse video and bell character, run then listed

Hello, World! in Applesoft BASIC can be entered as the following:

10TEXT:HOME20?"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:

10TEXT:HOME20PRINT"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, [8] 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:

as well as several the later version would have, that had already been present in Apple's Integer BASIC:

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.

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 operations 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.

Coleco claimed that its Adam home computer's SmartBASIC was source-code compatible with Applesoft. [9]

Microsoft licensed a BASIC compatible with Applesoft to VTech for its Laser 128 clone. [10]

See also

Related Research Articles

<span class="mw-page-title-main">Apple III</span> Business-oriented personal computer made by Apple Computer

The Apple III is a business-oriented personal computer produced by Apple Computer and released in 1980. Running the Apple SOS operating system, it was intended as the successor to the Apple II, but was largely considered a failure in the market. It was designed to provide key features business users wanted in a personal computer: a true typewriter-style upper/lowercase keyboard and an 80-column display.

<span class="mw-page-title-main">Apple II (original)</span> First model in the Apple II computer series

The Apple II is a personal computer released by Apple Inc. in June 1977. It was one of the first successful mass-produced microcomputer products and is widely regarded as one of the most important personal computers of all time due to its role in popularizing home computing and influencing later software development.

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

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

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 version of BASIC published by Microsoft as well as the first high-level programming language available for the Altair 8800 microcomputer.

<span class="mw-page-title-main">Acorn Atom</span> Acorn Computers home computer, 1980–1982

The Acorn Atom is a home computer made by Acorn Computers Ltd from 1980 to 1982, when it was replaced by the BBC Micro. The BBC Micro began life as an upgrade to the Atom, originally known as the Proton.

Apple DOS is the disk operating system for the Apple II computers from late 1978 through early 1983. It was superseded by ProDOS in 1983. Apple DOS has 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 3.2 did that minor release receive its own version number, Apple DOS 3.2.1. The best-known and most-used version is Apple DOS 3.3 in the 1980 and 1983 releases. Prior to the release of Apple DOS 3.1, Apple users had to rely on audio cassette tapes for data storage and retrieval.

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

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

Sinclair BASIC is a dialect of the programming language BASIC used in the 8-bit home computers from Sinclair Research, Timex Sinclair and Amstrad. The Sinclair BASIC interpreter was written by Nine Tiles Networks Ltd.

The Atari Microsoft BASIC and Atari Microsoft BASIC II variants of the 6502-version of Microsoft BASIC ported to the Atari 8-bit computers. The first version, released 1981, required 32 KB of RAM and was supplied on floppy disk. The second version, released the next year, had most of the code on a ROM cartridge with additional functions on an optional floppy.

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 can be drawn in the high-resolution graphics mode—with scaling and rotation—via software routines in the ROM. Shape tables are supported via Applesoft BASIC and from machine code in the "Programmer's Aid" package that was bundled with the original Integer BASIC ROMs for that computer.

Lazer's Interactive Symbolic Assembler (Lisa) is an interactive 6502 assembler for Apple II computers written by Randall Hyde in the late 1970s.

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

<span class="mw-page-title-main">Simons' BASIC</span>

Simons' BASIC is an extension to BASIC 2.0 for the Commodore 64 home computer. Written by British programmer David Simons in 1983, who was 16 years old at the time, it was distributed by Commodore as a cartridge.

<span class="mw-page-title-main">Apple II Plus</span> Second model of the Apple II computer line

The Apple II 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 four years in production before being replaced by the Apple IIe in January 1983.

Apple II graphics debuted on the original Apple II in 1977 and were used throughout the computer series of the same name. The graphics consist of a 16 color low-resolution mode and a high-resolution mode where visuals are dependent on artifact color. The Apple IIe added "double" versions of each of these, most prominently "double high-resolution" with twice the horizontal resolution in 16 colors. Internally, Apple II graphics modes are idiosyncratic and do not use a linear frame buffer.

<span class="mw-page-title-main">ITT 2020</span>

The ITT 2020 was an Apple II computer clone manufactured by ITT under license from Apple Computer, specifically for the European market. In the Benelux, it was distributed by International Bell Telephone Company. It was distributed in the United Kingdom by Microsense Computer Limited.

Level I BASIC is a dialect of the BASIC programming language that shipped with the first TRS-80, the TRS-80 Model I.

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

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

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

References

  1. TASC (The AppleSoft Compiler) User's Manual. Bellevue, WA: Microsoft Consumer Products. 1981.
  2. 1 2 Wozniak, Steve (May 1, 2014). "How Steve Wozniak Wrote BASIC for the Original Apple From Scratch". Gizmodo. Retrieved May 2, 2014.
  3. McCracken, Harry (April 16, 2012). "Apple II Forever: a 35th-Anniversary Tribute to Apple's First Iconic Product". Time. ISSN   0040-781X . Retrieved June 21, 2019.
  4. Herzfeld, Andy (February 12, 2014). "MacBasic – The Sad Story of MacBasic". Folklore.org.
  5. "Chapter 16: Languages". History of the Apple II. July 2010. Retrieved July 6, 2016.
  6. Applesoft BASIC Programmer's Reference Manual (for IIe only). Apple Computer, Inc. 1982. p. 70.
  7. Aldridge, James W. (July 1987). "Cautions regarding random number generation on the Apple II". Behavior Research Methods, Instruments, & Computers. 19 (4): 397–99. doi: 10.3758/BF03202585 . S2CID   62633043.
  8. Applesoft Extended Precision Floating Point Basic Language Reference Manual. Apple Computer, Inc. November 1977.
  9. Coleco Presents The Adam Computer System. May 3, 2016 [September 28, 1983]. Event occurs at 31:55. Archived from the original on November 22, 2021 via YouTube. 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.
  10. Grevstad, Eric (December 1986). "Laser 128 / An Affordable Compatible". inCider. p. 58. Retrieved April 24, 2017.

This article includes text from Everything2, licensed under GFDL.