Commodore 64 Basic Programming

The Commodore computer has a built in language known as BASIC, which stands for “Beginner’s All Symbolic Instruction Code”. It obtains extractions from many of the earlier versions of Basic which allows for Commodore 64 Basic Programming. This section lists each of the individual Commodore 64 Single Commands.

Basic Programming has also been used to create text adventure simulations. There are too many too list, but feel free to explore the article on this website called Basic Text Adventures to learn more.

The purpose of this guide is to hopefully encourage the beginning novice to turn on their favorite Commodore computer (PET, VIC or the C64), and begin exploring some Commodore 64 Basic programming commands to get used to their machine.

I am using examples obtained from the book Commodore 64 Programmer’s Reference Guide to demonstrate what these Commodore 64 Programming Commands are used for. Keep in mind that this is not a programming example, but rather a guide to get your “feet wet” so to speak.

The Commodore 64 Basic programming commands are listed below following by an appropriate definition. Also included here are programs obtained from the book, which was published by Commodore Business Machines, Inc.

VICE C64 Live Emulator

Feel free to use the VICE C64 Emulator below to load up Basic programs or files that were downloaded on this page.

To load a file, click on the menu C64/Attach D64 or you can also drop and drag a .D64 image onto the VICE window and it will load.

Basic Programs

CLR -This allows a user to clear up available RAM memory that was currently being used. It does not erase a Basic program in memory. However all variables, arrays, GOSUB addresses, FOR/NEXT loops, user-defined functions, and files are deleted from memory and that new space is now available for any variables that are setup again and so on.

Example program:

10 X=25
20 CLR
30 PRINT X

CONT – When a program has received a command to exit by the user adding a STOP or END to their program, typing in the command CONT will start the program at the last point of exit. However, if the program ended due to an error, the message CAN’T CONTINUE will be seen to prevent the program from running again until it has been properly debugged.

Example program:

PI=0:C=1
20 PI=PI+4/C-4(C+2)
30 PRINT PI
40 C=C+4:GOTO20

END – When a Commodore 64 program encounters this instruction, the program will halt and the READY prompt will appear again allowing the user to utilize full control of the keyboard, variables, it’s memory, and so on.

Example program:

10 PRINT “DO YOU REALLY WANT TO RUN THIS PROGRAM”
20 INPUT A$
30 IF A$=”NO” THEN END
40 REM REST OF PROGRAM
999 END

Basic List Command

LIST – When Commodore 64 Single Commands execute the LIST command, Basic will show the program the exits currently in the Commodore 64’s memory. If the program lines are too long to fit onto the screen display, when the text scrolls to the bottom the screen will move up to show more of the lines that are present in Basic’s memory.

Also note that while the screen is scrolling, if you press the CTRL key the display will pause to allow you to read the listing more effectively. Likewise you can also abort the command, by pressing the RUN/STOP key.
This program can also be appended to a format list of lines that will allow you to show specific sections of a program in memory. Also if you type a LIST followed by a specific line number and then the dash symbol, it will begin showing a listing from that specific line number until the end of the listing in memory.

Examples:

LIST = show the whole program in memory
LIST 500 = show only line 500
LIST -1000 = show all lines from the beginning up to line 1000
LIST 150-1000 = show all lines from 150 through 1000

Example program:

10 PRINT “THIS IS LINE 10”
20 LIST
30 PRINT “THIS IS LINE 30”

NEW – this program is used to erase a program that exists currently in the Commodore 64’s Basic programming memory. It will also clear any variables that exist. It can be used in direct mode (when no program is running) or inside a program to erase a program after a specific line is reached. Always remember, before beginning a new program, be sure to execute the NEW command to delete the current program in memory.

Examples NEW

Example program:

10 NEW

Commodore 64 Basic PRINT

PRINT – When this command is used in a program the cursor will move to the next line vertically. It can often be used as a carriage return to separate sentences sequentially. It can also be followed by a semicolon or comma. When a semicolon is appended to the end of it, the text will continue at that point and be appended together. If a comma is added to the end of the PRINT command, the next PRINT command following this will begin in a new zone putting 10 spaces between them (similar to how a TAB works).

It can also be followed by variables, numbers, parenthesis, and expressions (to be covered soon).

Example programs:

5 X=5
10 PRINT -5*X,X-5,X+5, X ↑ 5

5 X=9
10 PRINT X;”SQUARED IS”;X*X;”AND”;
20 PRINT X “CUBED IS” X ↑ 3

90 AA$=”ALPHA”:BB$=”BAKER”:CC$=”CHARLIE”:DD$=”DOG:”EE$=”ECHO”
100 PRINT AA$BB$;CC$ DD$,EE$

REM – this is one of the Commodore 64 Basic Programming Commands that serves as a comment in a program. Essentially when you follow this with a :REM, after the REM you can write out what that section is about. This is more important to the user looking at a program never seen before, or if you want a reminder much later what that part of your program was about. THE REM command stands for “Remark”. The text proceeding it can contain any word, character, or Basic keywords. The lines after the REM are ignored by Basic.

10 REM CALCULATE AVERAGE VELOCITY
20 FOR X=1 TO 20: REM LOOP FOR TWENTY VALUES
30 SUM=SUM+VEL(X):NEXT
40 AVG=SUM/20

Basic Read Command

RESTORE – this command is used as an internal point to reference the next DATA that will be executed by the READ command. When it is issued in a program, the pointer is reset to begin reading the first DATA constant that exists. Essentially it is used to “re-read” data in a program.

100 FOR X=1 TO 10: READ A(X):NEXT
200 RESTORE
300 FOR Y=1 TO 10:READ B(Y):NEXT

4000 DATA 3.08, 5.19, 3.12, 3.98, 4.24
4100 DATA 5.08, 5.55, 4.00, 3.16, 3.37

10 DATA 1,2,3,4
20 DATA 5,6,7,8
30 FOR L=1 TO 8
40 READ A: PRINT A
50 NEXT
60 RESTORE
70 FOR L=1 TO 8
80 READ A: PRINT A
90 NEXT

Basic GOSUB Command

RETURN – another of the Commodore 64 Single Commands that is used to exit from a subroutine that was called from a previous GOSUB statement in a program. The program is then reset to begin execution at the next line down in the program. Each GOSUB must accompany a RETURN statement.

Example program:

10 PRINT”THIS IS THE PROGRAM”
20 GOSUB 1000
30 PRINT”PROGRAM CONTINUES”
40 GOSUB 1000
50 PRINT”MORE PROGRAM”
60 END
1000 PRINT “THIS IS THE GOSUB”:RETURN

RUN – this command will begin executing a program that currently exists in the Commodore 64’s memory. It also will automatically execute the CLR command each time. It can be used in direct mode or within a program.

Examples:

RUN
RUN 500

10 PRINT”THIS PROGRAM HAS ENDED.”
20 INPUT”DO YOU WISH TO RESTART IT”AN$
30 IF AN$=”Y” OR AN$=”YES” THEN RUN

STOP – as reviewed earlier, this command will cause the current program to cease operations and return to the READY prompt in direct mode. Files will remain open and any variables in memory are not lost when this command is executed. The program can continue by using the CONT command if an error did not cause the program to end.

Finally the program that produced the featured image (at the top) for the Commodore 64 Simple Commands is listed below as an additional bonus for being a member of C64Brain!