Apple II BASIC programs can be written in a web browser using the following steps:
- Choose a web browser.
- Type “apple II BASIC” into the address bar and press return.
- A web page will appear that contains the Apple II BASIC program you just wrote.
Of course, if you have a real Apple II, you can follow along, as well. Otherwise, we’ll be using a handy Apple II emulator called Apple ][js created by Will Scullin. We’ll cover the basics of BASIC and run two simple programs.
Why the Apple II Was So Important
Introduced in 1977, the Apple II was launched as part of a class of small, inexpensive computers made possible by microprocessor technology. These personal computers allowed people to own and operate their own machines with relative ease. Prior to this, most computers were expensive and only owned (or shared) by large organizations.
The Apple II stood out because of its low cost and color graphics. It also had seven internal expansion slots that worked with the world’s least expensive floppy disk system at that time, the Disk II. Apple co-founder, Steve Wozniak’s, wizardry with circuit design allowed all these features to fit into a small desktop machine with a lightweight plastic case.
The Apple II was a stunning breakout success for Apple. Over the course of its approximate 16-year lifespan (it was discontinued in 1993), the Apple II platform hosted seven versions of Wozniak’s original computer design. A typical Apple II computer came equipped with 48 or 64 KB of RAM, and a 1.022 MHz 6502 CPU. You could program every model in BASIC.
The Basics of BASIC
From the late 1970s through the early ’80s, most personal computers included a programming language known as BASIC, an acronym for Beginners’ All-purpose Symbolic Instruction Code. BASIC emerged in 1964 on the Dartmouth College Time Sharing System. It quickly became a popular educational tool for computer science due to its ease of use.
The Apple II shipped with two major versions of BASIC over the years: Wozniak’s Integer BASIC, and Applesoft. Microsoft created Applesoft long before it became famous for Windows.
For this article, we used Applesoft BASIC.
Some Syntax Tips
Every BASIC program on the Apple II is composed of lines of code. Each line has a number, and when a program is RUN, the computer executes each line in numerical order from least to greatest. Each line is entered into computer memory by hitting the Return key.
These three fundamental BASIC commands will always come in handy.
At any time while programming, you can see the contents of your program by typing the LIST command. To start a new program (erasing the current program from memory), type NEW. To clear the screen, type HOME.
If you make a mistake while typing in the program, the Apple II will return a “SYNTAX ERROR” upon running the program, and it will include a line number where the error occurred. Simply re-type the offending line, double-checking for possible typos.
Got it? Let’s get started.
Your First Program
First, we’re going to write a very simple program that counts upward forever. It’s a quick way to test if BASIC is working properly on any system.
If you have a real Apple II, power it up. Make sure you use a machine with Applesoft in ROM, such as the Apple II Plus or later, or an original Apple II with the proper language card.
If you’re following along without a real Apple II, open a new browser window to the Apple ][js emulator. Apple ][js uses JavaScript to simulate the circuitry of a real Apple II in software. Basically, you’ll be running an entire Apple II system in a web browser (it works best in Google Chrome).
When you first load the emulator (or boot an Apple II without a floppy disk system), you see a screen like the one shown below.
Press or click “Reset.”
You hear a beep, and then see a “]” prompt with a blinking cursor.
At the prompt, type the following and press Enter (or Return) at the end of each line:
If you make a mistake, just use the left arrow key on your keyboard to move the cursor backward and make corrections. The new characters you type will overwrite the old ones. You can also re-type the entire line.
Each time you type a line of code with a certain line number, BASIC replaces whatever was previously stored on that line number with the new input.
When you use BASIC on an older system, like the Apple II, it’s common to number the lines in multiples of 10. This gives you room to add new lines of code between them later if necessary.
Next, type LIST, and then press Enter (or Return) to see a listing of your program.
If you accidentally end up with lines you don’t need (for example, if you typed 32 instead of 30), just type the line number and press Enter (or Return) to delete it.
If everything looks okay, it’s time to run your program. Type RUN at the ] prompt, and then press Enter (Return).
The program counts upward by one forever, and prints each number on a new line at the bottom of the screen.
To stop the program, press Ctrl+C. This will BREAK the program, interrupting its execution.
So, how does this program work? Let’s break it down line by line:
Line 10: Here, we tell the program that a variable named “X” is equal to itself plus one. At the beginning of the program, “X” equals zero. So, on its first pass, the program adds one to zero, resulting in one. Line 20: The program will use the PRINT command to display the contents of the variable “X” on the screen. Line 30: We use the GOTO command to send the program back to line 10 in a loop. The value of variable “X” (now incremented by one) is fed back into line 10. The program then repeats this process forever, counting upward by one, and then printing the result in each loop.
A Simple Input Program
Now that you’ve had a taste of typing, listing, running, and breaking a program, let’s take a look at one that can do something with the input you give it.
First, type NEW , and press Enter (Return). This clears our last program from the memory, so we can start fresh.
Type the following line by line, and then press Enter (Return) at the end of each:
When you’re done, LIST the program to double-check you typed it correctly.
Next type RUN and press Enter (Return) to run it. The program will ask you for input with a question mark ( ? ). Type your name and press Enter (Return) to answer the question.
Like some kind of arcane dark magic, the program knew your name and talked back to you! How did it work? Let’s take a look at each line:
Line 10: The program displayed a line of text on the screen. Every line of text you want to PRINT must be in quotation marks. Line 20: The program asks for INPUT from you and stores the result in a variable called N$. The dollar sign is short for “string. ” Every variable that includes letters must be a string-type variable. Line 30: The program displayed Hello, followed by a comma and space, and then printed the contents of the variable N$. The semicolon told the program to print N$ on the same line without inserting a line break.
Scratching the Surface
Now that you’ve had a taste of BASIC on the Apple II, you can tell all your friends you’ve programmed a vintage computer! In fact, you can even tell Steve Wozniak on Twitter.
If you’d like to dive further into Applesoft BASIC, we recommend this wonderful online tutorial by Yuri Yakimenko. It goes into far more detail than we have here. There’s also this handy quick reference of Applesoft BASIC commands.
A full scan of the Apple II Basic Programming Manual from 1978 is also available. It goes into detail about how to save and load your programs.
Thousands of amazing games and applications have been programmed in Applesoft over the past 42 years, so the sky’s the limit of what you can do with it. (Actually, the amount of RAM in your machine is the limit, but that’s so much less poetic.)
For all you Apple II veterans out there, we’d love to hear your stories about using BASIC in the comments. Happy programming!