An absolute beginner’s introduction to BASIC programming on the BASIC Engine.

Note
This document has been adapted from the book Personal Computing on the VIC 20: A friendly computer guide, 5th ed., published by Commodore Electronics, Ltd. in 1982.
Important
This guide is a work in progress.

Getting to Know Your BASIC Engine

Try typing this program

Type this program exactly as shown and see what happens!

1 PRINT "BASIC Engine" RETURN
2 GOTO 1 RETURN
R U N RETURN

To stop the program press the keys Ctrl and C at the same time.

Getting Started—​Experiment a Little

You made it! Your BASIC Engine is aglow with color and ready for you to tell it what to do. The green, blinking rectangle, called the cursor, is a signal from the BASIC Engine that it is waiting for you.

Ain’t nothin' but a G thang
Engine BASIC
62680 bytes free
Directory /flash
OK
 (1)
  1. The BASIC Engine is saying it’s ready.

Tip
If you type a character on the screen that you don’t want, press the ⟻   key; it’s usually above the RETURN key.
This key will erase the character immediately to the left of the blinking cursor.
Use this key as often as you like to delete unwanted characters.

Now, on with the tour! Begin by pressing the following keys:

P R I N T

See how the cursor moves over one position every time you press a key? The cursor tells you where the next character is going to appear on the screen. OK, now find the SHIFT key, it usually looks like this: ⇧  

There are two of them, both the same.

Hold the ⇧   key down, and while it is being held, press: '

You can release the ⇧   key after you press the ' key. The screen should look like this:

Ain’t nothin' but a G thang
Engine BASIC
62680 bytes free
Directory /flash
OK
print"

Pressing the ' key while holding down the ⇧   key caused the quotation mark to appear on the screen. [1]

Let’s continue. Now press the following keys:

R A I N B O W

Finally, hold down the ⇧   key, and press the ' key once again. The screen now shows:

Ain’t nothin' but a G thang
Engine BASIC
62680 bytes free
Directory /flash
OK
print"rainbow"

Press the RETURN key and look at the screen.

Ain’t nothin' but a G thang
Engine BASIC
62680 bytes free
Directory /flash
OK
print"rainbow" (1)
rainbow (2)
OK (2)
 (2)
  1. You typed this.

  2. The BASIC Engine typed these.

Pressing the RETURN key told the BASIC Engine you were finished typing. The BE then looked at what you typed, recognized that it was being asked to do something (actually, you told it to print something). The BE then PRINTed everything between the two quotation marks (rainbow).

When the BE finished PRINTing the word rainbow, it let you know by displaying the OK message and blinking the cursor.

It’s your turn. Go ahead and enter some other PRINT messages for your BASIC Engine to display. Try these or make up your own:

P R I N T " R A I N " (Press RETURN here.)

P R I N T " H E L L O " (RETURN here)

P R I N T " K A T H Y " (and RETURN again.)

(Remember to hold the ⇧   key down to get the " character.)

Experiment by using characters other than letters between the quote marks: The BASIC Engine won’t mind.

Note that if you misspell the word PRINT, the BE will let you know by displaying this message on the screen:

prinyt (1)
Unknown command (prinyt)
OK
  1. Huh?

Don’t worry. There is no known way you can unintentionally hurt your BASIC Engine by typing at the keyboard [2] (unless, of course, you’re an elephant), but if you make a mistake, the BE will help you out by calling attention to the error. At this point, don’t worry about the Unknown command message. Just keep experimenting.

In no time your screen gets cluttered with all the stuff you have been typing. The BASIC Engine has a handy way to clear up this clutter. To tell the BE to "clear" the screen, do the following:

Hold down the Ctrl key and press the L key.

The screen clears instantly; everything you and the BE have typed disappears. You are left with a clean black display area and a green cursor blinking away in the upper left hand corner.

Remember how you told the BE to do this feat. Clearing up the screen is one of the more frequent commands you’ll be using as you get to know your BASIC Engine.

Your First Computer "Program"

If your BASIC Engine performed well in displaying your messages, no matter how bizarre they might have been, then your computer is probably ready to do just about anything. Let’s begin by "entering" your first computer program.

STEP 1

Clear the screen by holding down the Ctrl key and then pressing the L key.

STEP 2

Type N E W and press the RETURN key.

STEP 3

Type 1 0 SPACE P R I N T SPACE " SPACE B A S I C SPACE E n g i n e " ; and press RETURN.

Use ⇧   to get the " character and to get upper-case instead of lower-case letters. Do not type out the letters in SPACE; press the space bar (long key at the bottom of the keyboard). ; is the semicolon key.

STEP 4

Type 2 0 SPACE G O T O SPACE 1 0 and press RETURN.

When you finish, the screen looks like this:

new (1)
OK (2)
10 print " BASIC Engine"; (1)
20 goto 10 (1)
 (3)
  1. You typed this and the pressed RETURN.

  2. The BASIC Engine typed this.

  3. Blink, blink, blink…​the BASIC Engine is waiting.

BASIC Engine Tip: Editing Mistakes in a Program

If you make a mistake on a line, you have these editing options:

  1. You can retype a line anytime and the BASIC Engine will automatically substitute the new line for the old one. For example, if your program looks like this:

    10 PRINN " BASIC ENgine"
    20 GOTO 10

    You can skip down by hitting the down arrow key a few times and type:

    10 PRINT " BASIC Engine"; RETURN

    Now, the new line has replaced the old line and the program will work. To make sure, type L I S T. Replacing lines in a program is also a quick and easy way to experiment.

  2. You can erase an unwanted line by typing the number of that line and hitting RETURN. The entire line will be erased from memory.

  3. You can edit a line by using the cursor keys to move to the character(s) in the line of a program you want to change, replacing what is written there with the correct program text and hitting RETURN.

If everything looks all right to you, type the following word, and press RETURN:

R U N RETURN

The screen should fill with BASIC Engine. At times, it looks like small animated letters traveling across the screen.

Want to slow down the program? Press the left Alt key. If you hold down the Alt key, the program slows down. Amazing! Your BASIC Engine is full of wonderful features. Here, with just a single key, you are telling the BE to reduce how fast it is displaying stuff on the screen.

But how do you stop the program? Good question. Look around the keyboard until you find the Ctrl key. It is usually at the bottom left. Press and hold the Ctrl key and press the C key at the same time. The program should stop, and the message

Break in 20
20 GOTO 10
OK

should appear on the screen. (Don’t worry, you didn’t break the BASIC Engine — "break" means "stop" in computer language). The cursor has also reappeared. Did you notice that it was gone while the program was running?

Now, let’s take a look at your program and see if it’s still there. Try typing this:

L I S T RETURN

Your program (lines 10 and 20) will be displayed on the screen.

Note
You may have noticed that the BASIC Engine types commands like PRINT and GOTO in capital letters, even if you have entered them differently. This is to help you distinguish them from other elements of the program, such as the message you are printing. You can enter commands in any case you want.

Now type RUN and the program will "run" again.

You have just been introduced to several aspects of the BASIC Engine that you will use in many of the later chapters. You have:

  • PRINTed messages on the screen.

  • "Cleared" the screen (Ctrl L keys).

  • Written your first program ("BASIC Engine") and created a moving display.

  • Slowed down the program with the left Alt key.

  • Stopped the program with the Ctrl C keys.

  • LISTed the program

  • Learned some easy ways to edit what you type.

As you explore the chapters of this guide, you will find many uses for what you have seen here. Don’t worry if you have unanswered questions at this point. Just go ahead and experiment, and most of your questions will be answered as you go along.

This guide is designed so that you can go directly to any chapter that looks interesting to you. You do not have to read each chapter in order to get to know your BASIC Engine. Just be sure to start from the beginning of each chapter. You will find that our gradual introduction to each topic makes it easier for you to learn how to create adventures of your own. Enjoy!

Using the Screen and Keyboard

Try typing this program

Type this program exactly as shown and see what happens!

10 CLS
20 WAIT 300
30 PRINT "your name"
40 WAIT 300
50 GOTO 10

Type R U N and hit RETURN. To stop the program press the keys Ctrl and C at the same time.

Using the Screen and Keyboard

This chapter assumes that you’ve read and understood Getting to Know Your BASIC Engine. If you have not, go back and read at least the last two sections which show you how to use the keyboard to control what the BE prints on the screen.

To start, poise yourself before the keyboard and type as follows, including the program line numbers and punctuation marks:

Hold down the Ctrl key and press the L key.

Type N E W and press the RETURN key.

1   P R I N T " H e l l o SPACE SPACE " ; and press RETURN.

2   G O T O   1 and press RETURN.

R U N and press RETURN.

When you type RUN, the screen should fill with the word:

Hello

The words appear to be moving up and sideways! Press the Alt key to slow things a bit. The BASIC Engine is PRINTing the message several times near the bottom of the screen. When the screen fills, the contents of the screen are moved up to make room for more PRINTing. So, the upward movement is really happening. The "barber pole effect" is an "illusion" caused by the number of characters the BASIC Engine is putting in each line.

To stop this program, press Ctrl and C.

Now, it’s your turn. Type these two lines:

1   PRINT   "Hello (your name) "; and press RETURN.

2   G O T O   1 and press RETURN.

R U N and press RETURN.

Wow! Now that you’re a TV star, what does your name do on the screen? The "illusion" of movement depends on the number of characters in the message. Again, when you want to stop the action, hold Ctrl and press C.

Your First Graphic Character

Clear the screen (hold down Ctrl and L). Now hold Alt and ⇧   and press C. You should get a white heart on the screen. Try it again. You have just typed your first graphic character.

Try typing other graphics by replacing C with other keys and by holding or not holding down the ⇧   key.

Note
The BASIC Engine has different character sets built-in, each of which has different graphic characters. You can try them out by entering FONT 1 RETURN, FONT 2 RETURN etc. Enter FONT 0 RETURN to go back to the default font.

Size of the Screen

How big is the screen of the BASIC Engine? Let’s find out. Do this: Clear the screen and type the following:

N E W and press RETURN

1   P R I N T " " ; RETURN

(To type the white heart, hold down Alt and ⇧   and press C.)

2   G O T O 1 RETURN

R U N RETURN

The screen will fill with white hearts! Count the number of hearts being printed across the screen. There are 76 of them in each row. The BASIC Engine has 76 PRINT positions across the screen. These positions are sometimes called columns. The BE has 76 columns.

How many positions are there down the screen? Press the Alt key to slow down the PRINTing. The BASIC Engine has 28 rows down the screen.

Note
The BASIC Engine allows you to choose different screen sizes if you need them using the SCREEN command. You can try them out by typing SCREEN 2 RETURN, SCREEN 3 RETURN and so forth. To return to the default screen size, type SCREEN 1 RETURN.

The BASIC Engine’s default screen has 2128 places for characters, letters, symbols, and so forth. You might say that the BE can juggle 2128 characters at the same time. Amazing!

Tip
If the BASIC Engine has 76 column across the screen, then any message whose length is an even divisor of 76 (that is, for instance, 2, 4 or 19 characters in length) causes the BE to PRINT in nice neat columns. Messages of other lengths spill over to the next line. Test this assumption for yourself.

Stop the BASIC Engine’s PRINTing of the neat columns of hearts by pressing Ctrl and C. Then enter these two lines:

1   P R I N T " " ;   RETURN (press Alt, ⇧   and C to get the heart)

You can change the way information is printed on the screen by putting spaces between the quotation marks. Another way is to use periods (or dots) instead of spaces. Try typing your name and 3 periods in the program at the beginning of this chapter.

A Tour of the Keyboard

You have now used the keyboard to create and PRINT messages, put graphics characters on the screen, control the flow of what the BASIC Engine is doing (Ctrl and C), and possibly edit what you have typed (⟻  ).

Computer keyboard US

Time now for an extended tour of the keyboard and what it can do for you. Consult the diagram above for the powerful and versatile set of BASIC Engine keys.

Here is how you can use these keys:

⇧   ⇧     (shift) keys

The BASIC Engine’s keyboard is a regular PC keyboard and has two shift keys and a CAPS LOCK key. The ⇧   and ⇧     keys are used with other keys to type upper-case letters, punctuation marks and, together with the Alt key, different graphics characters.

Home and End keys

Press the Home key, and the cursor moves to the left-hand side of the screen. Press the End key, and the cursor moves to the end of the current line. (Note that the cursor will not move either way if the current line does not have anything in it.)

(cursor) keys

With the BASIC Engine, you can easily move the cursor up, down and sideways. Like most keys, the cursor keys have a repeat feature that keeps the cursor moving until you release the key. Each key has an arrow that tells you the direction the key controls—​up, down, left or right. It is significant to keep in mind that you can move the cursor over the tops of characters on the screen without affecting those characters.

RETURN key

You press RETURN at the end of each line of instruction. Pressing this key tells the BASIC Engine to enter the line, or to execute the instruction(s). Sometimes it helps to think of RETURN as an Enter key because this key actually enters the information or instruction into the computer.

Tip
Many keyboards have an actual Enter key as part of the numeric keyboard on the right. Both keys work the same.
Ctrl key

This key is used to enter various graphics characters, similar to the Alt key, as well as to execute control commands, of which you have already encountered Ctrl+C (interrupts a running program) and Ctrl+L (clears the screen).

⟻   ("backspace") key

You can delete characters from the line you are typing by pressing this key. When you do so, the character that was immediately to the left of the cursor disappears. If you’re in the middle of a line, the character to the left is deleted and the characters to the right automatically move in to close up the space.

Print Screen key

This key will save what you currently see on the screen to a file on the SD card. Use this if you have created something interesting and want to show it off, or when something happens that you don’t understand and you want to ask for advice.

This concludes our tour of the keyboard. Using only words, it’s difficult to convey just how flexible and powerful it is. The best way to discover everything it can do is to begin your own "touring". Experiment with the keyboard. Try out combinations of the various modifiers (Ctrl, ⇧   and Alt) and see what happens when you press them together with other keys. The keyboard is your direct link to the BE. Knowing the keyboard will help you know your BASIC Engine.

PRINTing On The Screen

Clear the screen and enter the following lines:

NEW RETURN

PRINT "A","B" RETURN

NEW (1)
OK (2)
PRINT "A","B" (1)
A       B (2)
OK
  1. You typed these.

  2. The BASIC Engine typed these.

Now, enter this line and press RETURN:

PRINT "A";"B"

The screen now shows:

NEW
OK
PRINT "A","B"
A       B
OK
PRINT "A";"B" (1)
AB (2)
OK
  1. You typed this.

  2. BASIC Engine shows this.

When the comma was used in the first PRINT statement, the BE placed the letters on the screen, but separated them by several spaces. When the semicolon was used, the BE displayed the two letters close together.

In the first case, the letters are exactly 8 spaces apart. That fact gives a clue to what’s happening. The BE divides the screen area into equally sized columns.

When the BE is PRINTing two messages or numbers separated by a comma, it puts the first item in the first eight-character column, the second on the next eight-character column, and so forth. If an item is wider than one column, it skips to the next. Clear the screen and try this example:

PRINT "ABCDEFGHIJKL","X"

The screen will show:

PRINT "ABCDEFGHIJKL","X"
ABCDEFGHIJKL    X
OK

The first part of the message is 12 characters long, so the X ends up in the third column.

The BASIC Engine Calculator

The BE can also be used as a high-precision calculator. The + and - sign are used just like in mathematics. The BE multiplication sign is the asterisk (*) and the division sign is the slash (/). Type these calculations and check the results.

PRINT 1+1 RETURN

PRINT 2*(4/2) RETURN

PRINT 3-2 RETURN

PRINT 5000/5 RETURN

PRINT 5*2 RETURN

PRINT 2/3 RETURN

PRINT 6/3 RETURN

PRINT 3^3 RETURN

If you PRINT a calculation you should put it outside the quotation marks. Try these examples:

PRINT"2*(4/2)" RETURN: BASIC Engine prints everything inside the quotes.

PRINT"The answer is ";2*(4/2) RETURN: BE automatically performs the calculation outside the quotes and prints the result.)


1. If the single-quote character appeared on the screen instead of the " sign, you didn’t hold the shift key. Hit the ⟻   key once to erase the ' and try again.
2. There is, in fact, no known way to do so intentionally either. If you know of a way, please contact me so it can be fixed or mitigated.