Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Applesoft BASIC
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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 {{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|&}}) 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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)