C 64 User
C 64 User
-
""'···········-·-
- ·- .. . . . . .. - - . . .. .. - -
.. - ..... ~ • .. • .. • ' l - ... _
--- - -
USER'S MANUAL STATEMENT
This equipment generates and uses radio frequency energy. If it is not properly
installed and used in strict accordance with the manufacturer's instructions,
this equipment may interfere with radio and television reception : This machine
has been tested and found to comply with the limits for a Class B computing
device in accordance with the specifications in Subpart J of Part 15 of the FCC
rules, which are designed to provide reasonable protection against such inter-
ference in a residential installation. If you suspect interference, you can test
this equipment by turning it off and on . If you determine that there is interfer-
ence, with radio or television reception, try one or more of the following mea-
sures to correct it:
• Reorient the recei vi ng antenna
• Move the computer away from the receiver
• Change the relative positions of the ocmputer equipment and the
receiver
• Plug the computer into a different outlet so that the computer and the
receiver are on different branch circuits
This booklet is available from the U.S. Government Printing Office, Washing·
ton, D.C. 20402, Stock No. 004- 000- 00345-4 .
You should use only the cables, accessories, and peripherals recommended by
Commodore for your Commodore 64. All cables , including the cables for the
television hookup, serial port , video port, datassette, and joysticks, are spe·
cially shielded , in accordance with the regulations of the Federal Commu·
nications Commission . Failure to use the appropriate accessories and cables
will invalidate the FCC grant of certification , and may cause harmful radio
interference.
COMMODORE 64 K
USER'S GUIDE
Published by
Commodore Business Machines, Inc .
COi
COi
Joystjcks
Colar Monitor
iiiINTRODUCTION
v HOW TO USE THIS GUIDE
MODORE 64
PUTER
Commodore 64
Equipment
Interconnection
1 UNPACKING AND SETTING UP
How to unpack and set up your Commodore 64 computer and
any accessory Commodore equipment you may have purchased
with your computer 1
Diagram
Note 1 : Connections shown are
for Commodore equipment only.
17 THE C64 KEYBOARD
How to use the Commodore 64's Keyboard to enter information
and perform special functions
2
3
Connection location or type may 25 USING SOFTWARE
be different for non-Commodore What software is and how to use it with the C64
equipment. See your equipment
manual for details.
patassette
Note 2: You can use either a TV
set or a monitor as your visual
display unit. Follow the diagram
33 BASIC-A PROGRAMMING LANGUAGE
Introducing the BASIC language through some elementary corn-
mands and some simple programs
4
5
51 PROGRAMMING IN BASIC
for whichever type of display unit
Additional BASIC commands and more sophisticated program-
you are using. ming techniques
115
Introducing the C64 's versatile music and sound capabilities
APPENDICES
8
159 BASIC 2.0 ENCYCLOPEDIA
191 GLOSSARY
203 INDEX
Copyright© 1984 by Commodore Electronics Limited. INTRODUCTION
Th is manual is copyrighted and all rights are reserved by Commodore Elec-
tronics Limited. This document may not, in whole or in part , be copied, photo- THE COMMODORE 64
copied , reproduced , translated or reduced to any electronic medium or
machine readable form without prior consent, in writing , from Commodore -YOUR KEY TO THE INFORMATION AGE
Electr.onics Ltd.
The Commodore 64 personal computer (more simply, the C64) is a power-
Commodore BASIC V2 .0 ful , sophisticated yet easy to use information processing system. With the
Copyright© 1982 by Commodore Electronics Limited. C64 , you can process almost any kind of information-business, personal ,
Copyright© 1977 by Microsoft, all rights reserved. educational , recreational , scientific, financial and more. And with the C64
you can present this information in almost any form-words, numbers, pic-
tures and sound .
With the wide-ranging capabilities of the C64 at your disposal , you can do
all this:
• Word Processing-Type a draft, make changes or correct mistakes
electron ically, then print out a perfect final copy. Create form letters and
mailing lists. Save all your material in electronic files and recall it with a
few keystrokes.
• Business Calculations-Electronically create spreadsheets , do budg-
eting and payrolls , create " what if " scenarios. do complex statistical
analysis , calculate tax and income data, and control your investment
portfolio. Do general ledgers, accounts receivable and accounts pay-
able. Create full-color graphs and charts based on your numerical data.
Even use the C64 to balance your checkbook.
• Data Base and File Management-Create your own electronic files
and data bases. Store and control all the letters and documents you
write and all the numerical , statistical and financial data you generate.
Keep track of inventories and collections. Create and update status
reports. Even file recipes . (The C64 can electronically adjust a recipe
that serves, say, four to serve, say, a party of 10.) In short , save , delete,
change or combine any and all of your information at will.
• Telecommunications-Electronical ly " mail " almost any kind of infor-
mation, almost anywhere. Access information services-like Compu-
serve , The Source, Dow Jones and the New York Times-for detailed
information on almost any topic . Consult the World Book and other ency-
clopedias electronically. Send and receive personal messages and other
information through computer bullet in boards. Even receive newspapers
on your TV or monitor.
iii
• Education-Learn a language and improve your spelling . Help your
children learn math , science , English, music and other subjects, at both • HOW TO USE THIS GUIDE
elementary and advanced levels. Use light pens, drawing tablets and
To start using your Commodore 64 , follow this procedure:
speech synthesizers. Visit the stars through your own planetarium .
Learn how to program . And note that with the C64 , YOU control the pace • Read Section 1, UNPACKING AND SETUP Then unpack all the equip-
of learning , so you can go as fast or as slow as you like. ment and set it up. Follow the directions given in Section 1 and in the
• Entertainment-Play hundreds of act ion games and mind games. overall interconnection diagram found just inside the front cover of this
Draw pictures , make music, pursue evil villains and save fair damsels. Guide
Do all this in the comfort of your home-you never have to wait in line or • Read Section 2, THE C64 KEYBOARD . This section introduces you to
pay to park the car. the C64 keyboard , including special keys and functions .
• Sound/Color/Graphics-Control a versatile 3-voice , 9-octave sound • Read Section 3, USING SOFTWARE. This section tells you how to use
synthesizer. Mix and match 16 colors. Create animated figures and dis- software that is packaged in any of the three standard formats-
plays. Incorporate all these features in your own programs. cartridge , tape and disk. When you have completed this section, you will
• Programming Languages-Learn to use the powerful BASIC pro- be ready to use almost any of the many commercially available software
gramming language built into the C64. Use other programming lan- packages. In other words , you can start computing right away-even
guages such as C, COBOL, COMAL, FORTH , FORTRAN , LOGO , PILOT without reading the rest of this Guide.
and PASCAL. as well as machine language • If you are interested in programming the Commodore 64 yourself, you
• Interfacing with Other Equipment-Interface with prin ters, disk will want to read Section 4, BASIC-A PROGRAMMING LANGUAGE , Sec-
drives, tape recorders, communications modems, video monitors, televi- tion 5 PROGRAMMING IN BASIC, and Section 6, ADVANCED CON-
sion sets, stereo equipment , video recorders, Joysticks, paddle control- CEPTS. These sections describe the Commodore 64 's computational
lers, telephones, light pens , drawing tablets , numeric keypads, music capabilities and introduce the advanced BASIC programming langu~ge
synthesizers and many other types of equ ipment-including a robot that is built into the Commodore 64. The sophisticated color, graphics,
servant! sound and music capabilities of the Commodore 64 are described in
Sections 7 and 8. For complete details on all of these features , consult
In doing all these things , you can use the C64 in two ways:
the Commodore 64 Programmer 's Guide, available from your dealer and
• You can select from many prepackaged programs (software) available at most bookstores.
on cartridge , disk or tape . • Refer to the Appendices for a wide range of information on the C64 ,
• Or you can create and run your own programs . including a list of error messages and recommended responses;
detailed technical data on color, graphics and sound ; definitions of all
Whatever your level of expertise , this User 's Guide is designed to help you
C64 BASIC commands, statements and functions; a glossary of comput-
begin using your C64 quickly and easily.
ing terms; a list of software available for the C64 , and a list of publica-
tions on various aspects of the C64.
You can begin using your Commodore 64 as soon as you have set up an.d
connected the equipment. How far and how fast you progress after this
beginning is up to you. YOU are in control.
iv
v
UNPACKING AND
SETTING UP
This section tells how to unpack and set up
your Commodore 64 Computer and any
accessory Commodore equipment you may
have purchased with your computer
Unpacking _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 3
Checking What You Received 3
Setting Up 4
Picking a Spot For Your Computer 5
Connecting Your Computer to a Television
Set or Monitor _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 5
-Connection to a Television Set 5
-Connection to a Monitor 7
Connecting Your Computer to Electrical Power 7
Turning On The Computer For The First Time 7
If You Have a Problem . . . 8
Connecting Accessory Equipment 11
-Cassette Recorder 11
-Disk Drives 11
-Printers 12
-Chaining Disk Drives and Printers 13
-Modems 13
-Controllers 13
Typical Arrangement of Accessory Equipment
andtheC64 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 14
About RAM and ROM 14
•UNPACKING
Since you are reading this Guide, you have probably already opened the
box containing your Commodore 64 computer.
IMPORTANT!-Don 't try to connect one piece of equipment to another,
and don ' t plug anything into an electrical outlet until you have read the
instructions 1n this section .
3
TV Switch Box-This is a small black and silver piece of equipment that is
PICKING A SPOT FOR YOUR COMPUTER
about the size of a pack of cigarettes. There is a short strip of flat TV antenna
wire attached to the side of the switch box.
When you set up your computer equipment , pick a spot away from heat,
dust, smoke or electrical interference. If possible , plug your equipment into
its own separate circuit.
The following procedure assumes that your television set uses the flat
300-ohm wire connections . If your set uses 75-ohm connections , see the
Notes following Step 6 of the procedure .
Warranty Card-This is a prepaid , preaddressed postcard. You should fill 1. Disconnect the VHF antenna wires from the VHF terminal of
out and mail this card promptly to ensure that your computer is protected the TV.
under the terms of the Commodore warranty. 2. Insert these wires under the screws at the bottom of the
NOTE: If any of the items listed above is missing , contact your switch box, marked CONNECT TO ANTENNA.
dealer immediately. Save the boxes your equipment comes in . 3. Connect the short wire , coming from the side of the switch
They will provide protection for the equipment if you move it or box and marked TV VHF, to the VHF terminal of the TV.
return it for service. 4. Slide the selector switch on the switch box to the position
marked COMPUTER.
5. Plug one end of the TV connector cable (the 10-foot long black
•SETTING UP cable with the phono plug at each end) into the TV jack on the
back of the C64.
NOTE: When you are setting up and connecting your C64 , refer to 6. Plug the other end of the TV connector cable into the jack
the large, fo lded interconnection diagram located just inside the marked COMPUTER at the top of the switch box.
front cover of thi s Guide. This diag ram illustrates how to connect
typical Commodore accessory equipment to the C64 computer.
4 5
Connection To A Monitor
NOTE-Step 2: If your antenna You connect a monitor to your C64 through the audio/video connector on
cable is the round 75-ohm type , you the back of the computer. The kind of cable you use depends on the type of
will need to use a 75-ohm to 300- monitor you have and the type of audio/video connector your C64 has . The
ohm adapter (not supplied) to attach inte(connection diagram at the front of the Guide shows a Commodore moni-
your VHF antenna cable to the tor connected to the C64 . If you have a monitor, consult your user's manual
scre·ws at the bottom of the switch for full installation and operation instructions.
box. See diagram at right.
75 OHM TO
300 OHM
ADAPTER
{a~~]
attach the switch box to your set 's CONNECTING YOUR COMPUTER TO ELECTRICAL POWER
VHF terminals . See the diagram at To connect your computer to electrical power, plug the end of the round
right. power supply cable into the computer power socket (the back connection on
/ the right side of the computer). Make sure the computer power switch
TO VHF ANT (located on the right side of the computer. next to the power socket) is set to
OFF.
Next, insert the 3-prong plug from the power supply into a 3-hole electr ical
outlet.
7
6
Initial Screen Display
Symptom Cause Remedy
Shortly after you turn on your computer, you should see a display like this
on your television set or monitor: Indicator Light Computer not " On " Make sure power
not " On " switch is in " On "
position
8 9
• CONNECTING ACCESSORY EQUIPMENT
Symptom Cause Remedy
In addition to the television set or video monitor used for the display, you
Picture OK, but TV volume too low Adjust volume of TV
can connect various types of accessory equipment (known as peripheral
no sound
equipment, or simply peripherals) to your C64. Some commonly used periph-
Aux. output not prop- Connect sound jack
erly connected to aux . input on ampli -
erals are described in the following paragraphs.
fier and select aux. NOTE: Refer to the large interconnection drawing for illustrations
input of how to connect peripheral equipment.
Computer stuck; Computer inadver- While depressing the
cursor not flash- tently received RUN/STOP key press CASSETTE RECORDER
ing instructions to dis- RESTORE key twice;
able keyboard ; or the or reset the accesso- A special Commodore cassette recorder called a Datassette provides an
printer, cassette or ries by turning off and easy and inexpensive way to save information entered in the computer, or to
disk drive is in listen- on ; or reset the com- supply information to the computer. In the interconnection diagram, notice
ing mode puter off and on . that you connect the Datassette recorder to the C64 through the cassette
Computer dis- Overheating Pull plug on power port on the back of the computer. (Note: To avoid conditions that could
plays garbled supply whe!l not adversely affect Datassette performance, always make sure that the
symbols on the using computer for recorder is at least two feet from the television set or monitor, or any other
screen extended periods equipment-such as stereo components and speakers-that can generate
(overnight). electromagnetic interference.)
If you have a Datassette, consult your user 's manual for full installation
and operation instructions.
DISK DRIVES
A disk drive is another, faster way to save information entered in the com-
puter or to supply information to the computer. The information is saved or
stored on 5-inch disks (sometimes called " floppies"). A typical con nection
between a Commodore 1541 disk drive and the C64 is shown in the intercon-
11
10
CHAINING DISK DRIVES AND PRINTERS
nection diagram. Note that you connect the disk drive to the C64 through the
You can use the " daisy chaining " (or simply " chaining") technique to con-
serial port on the back of the computer. If you have a disk drive, consult your
nect up to five disk drives or printers to the C64 computer at one time. In this
user's manual for full installation and operation instructions.
technique, you connect a cable from one serial port of a printer or disk drive
to a serial port of another disk drive or printer. Note that a disk drive must be
the item of equipment that is directly connected to the C64 's serial port.
MODEMS
PRINTERS
A printer can provide a printed copy (" hard copy " ) of information that is in
the computer or stored on disks or tapes . A connect i 9tween a Commo-
dore MPS-802 printer and the C64 computer is shown in the interconnection
diagram. Note that in this example the printer is connected to the C64
through the serial port on the back of the disk drive. This type of multiple
connection, called "daisy chaining ," is described in the next paragraph. You
can also connect a printer directly to the C64 by using the serial port on the
back of the computer console. If you have a printer, consult your user 's man-
ual for full installation and operation instructions.
' CONTROLLERS
13
12
• TYPICAL ARRANGEMENT OF ACCESSORY
tus of ROM . So, unless you are interested in creating your own programs, you
EQUIPMENT AND THE C64 generally need not be concerned about RAM and ROM .
Shown connected to the C64 in the accompanying diagram is a grouping
of some of the popular Commodore peripheral equipment. This equipment
includes a Commodore color monitor, a single disk drive, a Datassette
recorder, an AUTOMODEM , a serial printer and a pair of joysticks. You should now be able to set up, plug in and turn on all your equipment.
Check the equipment connections you make against the overall interconnec-
tion diagram in the front of this Guide. This diagram shows a typical setup for
an all-Commodore equipment package . You should also refer to the manuals
included with any peripheral equipment you may have purchased .
The next section of this Guide describes the Commodore keyboard , telling
you how to use some special keys that make the C64 's keyboard slightly
different-and far more poyverful-than that of a standard typewriter.
- · .. •••T• • • W•-"•-
=--
': 7-.'' ."" _ .... _, ... • -- .. · _.....- -· _;_
-----
14
15
THE C64 KEYBOARD
This section tells how to use the Commodore
64 's keyboard to enter information and to
perform special functions
17
• WHAT THE KEYBOARD IS USED FOR
Using the keyboard to enter information is probably the most important
method of communicating with your Commodore 64 computer. You use the
keys to tell the computer what you want it to do, and to reply to any mes-
sages or questions the computer displays on the screen . (These messages
and questions are sometimes called " screen prompts " or simply
" prompts ".)
Most of the letter, number and punctuation keys on the Commodore 64 's
keyboard look and work like the corresponding key on a standard typewriter.
In addition, many of these keys can produce special graphic symbols , which
are indicated on the front of the keys . There are also special keys that let the
Commodore 64 computer do much more than a typewriter can do. The key-
board illustration shown below points out these special keys . The following
paragraphs tell how to use the keys .
Feel free to experiment at the keyboard . There 1s little chance that any-
thing you do at the keyboard can cause harm and you will benefit from the
" hands on " experience.
19
• KEYBOARD MODES SHIFT LOCK
The C64 keyboard has two typing modes: This key locks the SHIFT key in the ON position.
You don't have to keep tapping a CRSR key to get it to move more than one
and function of the special keys described in this section. space. Just hold the CRSR key down and the cursor will continue to move
until it reaches the position you want it to be in. Remember that you also
• FUNCTIONS OF THE SPECIAL KEYS must hold down the SHIFT key at the same time if you are moving up or to
the left.
RETURN INST/DEL
Pressing the RETURN key sends what you type into the Commodore 64
This is a dual purpose key. INST stands for INSerT, and DEL stands for
computer's memory. Pressing the RETURN key also moves the cursor (the DELete.
small flashing rectangle that marks where you are on the screen) to the next
line. Inserting Characters
You must use the SHIFT key with the INST/DEL key when you want to
SHIFT
insert characters in a line. If you 've left some characters out of a line, use the
The SHIFT key works like the shift key on a regular typewriter: that is, CRSR keys to move the cursor back to the error, like this:
when the SHIFT key is held down, it lets you print capital letters or the top
WHILE U WERE OUT
characters on double character keys. The SHIFT key is also used with some
WHILE I WERE OUT
other special function keys.
When the keyboard is in the upper case/graphic mode, you can use the
SHIFT key to print the graphic symbols or characters that appear on the Then , while you hold down the SHIFT key, press the INST/DEL key until you
fronts of certain keys. To do this, you hold down the SHIFT key while you have enough space to add the missing characters. INST doesn 't move the
press the key with the graphic character you want to print or display. (Note: cursor; it adds space between the cursor and the character to its right , like
You can only print the graphic character on the right side of the key when you this:
are in the upper case/graphic mode.)
WHILE • U WERE OUT
When you are using the four large keys at the right side of the keyboard
WHILE YOU WERE OUT
(marked f1, f3, f5 and f7 on the top), you must hold down the SHIFT key to
activate the functions associated with the markings on the front of the keys
(f2, f4, f6 and f8).
20 21
avoids the problem of a program being stopped accidentally, with a possible
loss of much valuable data.
Deleting Characters When you want to use the RUN function of the RUN/STOP key, you must
also use the SHIFT key. For instance, you can RUN a program automatically
When you press the DEL key, the cursor moves back a space and erases
from a cassette recorder by pressing the RUN/STOP and SHIFT keys at the
the character that is there, like this:
same time .
PRINT " ERROR " # •
PRINT " ERROR " I RESTORE
When you DELete in the middle of a line, move the cursor just to the right The RESTORE key is used with the RUN /STOP key to return the computer
of the character you want to DELete, like th is: to its normal conditions (also known as the default conditions). For example ,
the normal or default screen color is blue. Suppose you have colored letters
FIX IT AGAINS • SAM
on the screen (which you can get by using the SHIFT or C• keys and the
FIX IT AGAIN • SAM
number keys from 1 through 8). If you then press the RESTORE and RUN/
Then press the DEL key. The characters to the right automatica lly move STOP keys together, the screen is cleared and returned to its normal blue
over one space to the left to close up the space and you get the correct color, and the READY message is displayed
wording , like this: Most prepackaged software programs also disable the RESTORE key
along with the RUN/STOP key. Again , this eliminates the problem of a pro-
FIX IT AGAIN , SAM gram being accidentally stopped and then perhaps restarted 1n such a way
Using INSerT and DELete Together as to garble or destroy important information .
You can use the INSerT and DELete functions together to fix wrong char-
CLR HOME
acters. Just move the cursor to the incorrect characters and press the INST/
DEL key by itself to delete the characters. Then press the SHIFT CLR stands for CLeaR. HOME refers to the upper left corner of the screen ,
key and INST/DEL key together to add any necessary space. Then type in the which is called the HOME position . When you use the SHIFT key with the
corrections . CLR HOME key, the screen CLeaRs and the cursor returns to the HOME
position . When you use CLR HOME key by itself, the cursor returns to the
CTRL HOME position , but the screen is not CLeaRed.
The ConTRoL key is used with other keys to let you do special tasks called COMMODORE KEY ( C• )
control functions . To perform a control function , you hold down the CTRL key
while you press some other key. Control functions are commonly used in The C• key (known as the COMMODORE key) has two functions:
prepackaged software such as a word processing system . 1. It lets you switch back and forth between the upper/lower case display
One control function that is used often is setting colors. To set a color, you mode (the letters and characters on the tops of the keys) and the upper
hold down the CTRL key while you press the numbered key (1 thorugh 8) that case/g raphic display mode (capital letters and the graphics on the
controls the color you want. (You can get additional colors by using the C•
fronts of the keys). To switch modes, press the C• key and the SHIFT
key in the same way.)
key at the same time.
2. The C• key also lets you use a second set of eight colors . To get these
RUN/STOP
colors, hold down the C• key while you press one of the number keys,
This is another dual purpose key. (1-8) in the top row for the color you want.
Under certain conditions you can halt a program that is running or a print-
out that is in progress by pressing the RUN/STOP key. In using the STOP
function, you need only press the RUN/STOP key by itself. Most prepackaged
software programs disable the STOP Function of the RUN/STOP key. This
23
22
• PRINTING GRAPHIC CHARACTERS
To print the graphic symbol on the right side of a key, hold down the SHIFT
key while you press the key that has the graphic character you want to print.
Remember that you can only print the right side graphic characters when
you are in the upper case/graphic mode .
. To print the graphic character on the left side of a key, hold down the C•
key while you press the key that has the graphic character you want to pr int.
You can print the left side graphic in either mode.
Now that you have successfully connected your C64 equipment and can
find your way around the keyboard, you are probably ready and anxious to
begin using your computer. The next section tells how to use various types of
peripheral equipment to load and run prepackaged software programs. What Software Is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 27
Software Package Formats 27
-Cartridge 27
-Tape 27
-Disk 27
What 's in a Software Package 27
Loading and Running Software 28
-Loading Cartridge Software 28
-Loading Prepackaged Cassette Tape Software 28
-Loading Your Own Tape Programs 29
-Disks and Disk Drives 30
-Loading Disk Software 30
Hints on Selecting Software 32
For More Information 32
24 25
• WHAT SOFTWARE IS
Software is a set of instructions (also called a program) that tells your
computer just what you want it to do.
There are many thousands of prepackaged or " canned" software pro-
grams available to you today. This software is what lets you do all those
processing activities mentioned in the INTRODUCTION to this Guide.
Most software comes from commercial software companies. There are
also many software programs available in computer magazines or from com-
puter user groups. You can even create your own software by using a pro-
gramming language like BASIC, as described in Sections 4, 5 and 6 of this
Guide.
27
5. At this point , the screen goes blank until the computer finds the pro-
• LOADING AND RUNNING SOFTWARE gram. Wheri the program is found, the computer displays this message:
29
28
DISKS AND DISK DRIVES
Disks (also known as diskettes, floppy disks or simply " floppies " ) are fast ,
easy-to-use data storage devices. Disks must be inserted into a device
known as a disk drive in order to store or provide information .
When using a disk drive , you should make sure that the drive's power cord
is plugged into an electrical socket , and that the cable connecting the disk
drive to the C64 is plugged into the serial port on the back of the computer.
As with the Datassette tape recorder, you should keep the disk drive at least
two feet away from any possible sources of electrical interference.
There are two small indicator lights on the front of the disk drive.
• The green light is the power light , indicating whether the disk drive is on
or off.
• The red light tells you two things :
1. When a program is being LOADed or SAVEd, the red light is lit while
the disk is spinning in the drive. When the red light goes of f, the LOAD
or SAVE is complete . 2. Close the protective gate on the disk drive after you insert the disk. Just
2. If there is a problem with the disk or drive, the red light flashes on and push down the lever.
off, even after the disk stops spinning in the drive. 3. Type the following :
You can also use disks to store prog rams that you write yoursel f, and these LOAD " PROGRAM NAME '', 8
disks can then be used to load the program back into your C64 whenever you
Here, the number 8 tells the computer that you 're loading a disk.
want to run them . See Sect ion 4 for additional commands that you can use if
you plan to create , save and run your own programs. NOTE: You can LOAD the first program on the disk by using the *
sign in place of the program name, as follows :
LOADING PREPACKAGED DISK SOFTWARE
LOAD " * ",8
Whether you are loading preprogrammed disks or disks that you have pro-
grammed yourself, the steps are basically as follows: 4. Press the RETURN key. The disk will spin and your screen wil l display
this message:
1. Insert a disk into your disk drive, as shown in the diagram . Make sure
SEARCHING FOR PROGRAM NAME
the label on the disk is facing up. Put the disk in so that the labeled end
LOADING
goes in last. Look for a little notch on the disk (it might be covered with
a little piece of tape). This notch must be on the left side as you put in 5. Type RUN when the screen says READY and the cursor appears . Your
the disk, assuming that you 're facing your computer. Be sure the disk is software is ready to use.
all the way in .
In some cases , prepackaged software may have its own special format for
the LOAD command . Also, some commercial software may have an auto-
matic RUN function built into the program . Check the software instructions
carefully, espec ially if you have any problems .
31
30
• HINTS ON SELECTING SOFTWARE
Because of the great number of software products available , and because
of the variety of claims made for those products, selecting the right software
can be a difficult task. Here are a few tips on choosing software:
• Analyze your needs. Try to find software that meets those needs. Avoid
frills.
• If possibl e, talk to someone who has used the software you are
considering .
• Purchase the software from a reputable dealer.
BASIC-
• Try ou t the package on an equipmen t setup identical or similar to your
own. A PROGRAMMING
One way to ensure compatibi lity between your C64 and the software you
buy is to select from the wide variety of software produced by Commodore.
A list of cu rrently avai lable Commodore software is given in Appendix B.
LANGUAGE
This section introduces the BASIC language
through some elementary commands and
• FOR MORE INFORMATION ...
some sim le r rams
The information supplied to this point in this Guide will allow you to load
and ru n prepackaged software in cartridges , tape and disk formats . How- The Basic Prog ramming Language _ _ _ _ _ _ __ _ _ ,35
eve r, if you would like more information on LOADing , SAVEing and RUNning Typing Basic Programs 35
sof tware packages , refer to the instructions contained in the individual soft-
ware packages and to the information in your equipment manuals. You The PRINT Command 36
shou ld also read the next section of this Guide and consult the Commodore Order of Operations 37
64 Prog rammer 's Reference Guide, available from your dealer or at most Printing Text 38
bookstores.
Direct Mode Functions 39
Mathematical Functions 40
You should now be able to run a wide variety of prepackaged software , Program Mode 41
using your C64 computer and peripheral equipment. You will find that you
can derive great benefit and enjoyment from using these products. Constants, Variables and Strings 42
The remaining sections of this GUIDE are addressed to those newcomers IF · THEN 45
to computing who are interested in learning to create their own programs , Editing Tips 46
and to those experienced programmers who want to explore further the con-
Storing and Reusing Your Program 47
siderable capabilities of the Commodore 64 personal computer.
Formatting a Disk 47
The SAVE Command 47
The LOAD Command 48
Displaying Your Program 49
Other Disk-Related Commands 49
Sample Program 50
33
32
-
Your Commodore 64 computer 1s a powerful tool , with many capab1l1tles. It
can perform computations in a fraction of a second It has the ability to make
dec1s1ons and repeat commands according to your instructions. It can print
text on a screen or printer. Up to 1OOO characters can be printed on a single
screen , which 1s 40 characters wide by 25 lines high.
1. Spacing between words is not critical ; e.g ., typing FORT= 1T010 is the
same as typing FOR T = 1 TO 10. However, a BASIC word itself must
not be broken up by spaces. (See the BASIC Encyclopedia in the back
of this Guide for a list of BASIC words.)
2. Any characters can be typed in quotes. Reverse graphic characters
within quotes have special control functions.
3. Be careful with punctuation marks. Commas, colons and semicolons
also have special functions.
4. Always press the RETURN key (indicated in this Guide by the symbol
:REHJRN= ) after completing a line. Never exceed 80 characters in a
line (two screen lines).
5. Distinguish clearly between I and 1 and between(/) and 0 .
35
-
6. The computer ignores anything following the letters REM on a program comma or a semicolon in your command, depending on whether or not you
line. REM stands for REMARK. You can use the REM statement to put want your results spread out.
descriptive comments in your program . Find the asterisk key (*) on the right side of your keyboard . This is the
symbol for multiplication. Use the(/} located next to the right SHIFT key for
Concentrate on typing short programs until you are familiar with BASIC. division . Type .
36 37
--
pie above , if you want to tell the computer to add before dividing , you would See how the computer PRINTS what you put in quotes, makes the calcula-
type : tion and PRINTS the result. It doesn 't matter whether the text or calculation
comes first. In fact , you can use both several times in one PRINT command.
?(4 + 6)/24 6¥
?4*(2 + 3) " is the same as " 4* 5M
! ll•EBE
This gives you the correct answer, 5.
If you want the computer to divide before squaring in the second example, Notice that even the spaces inside the quotation marks are printed on the
you would type : screen . Type
?(16/4)i2BillB ?" OVER HERE " !MIEEB
Now you have the correct answer, 16. There are special keys on your keyboard that you can use in PRINT com-
If you don 't use parentheses, the computer wi ll perform the calculat ions mands to tell the computer where to put the information on the screen. They
according to the basic precedence rules. When all operat ions in a calcula- are the cursor control keys (CRSR) located below the RETURN key. The one
tion have equal preceden ce. they are per formed from left to right . For exam- on the right is the cursor right/left key, the other one is the cursor down/up
ple: key. Press these keys and note how the cursor moves on the screen . To move
the cursor up, press SHIFT while pressing the down/up key. To move the
?4*5/10*6BRB
cursor left, press SHI FT while pressing the right/left key.
The operations are performed in order from left to right , so the resu lt is 12. When you type the cursor keys inside quotation marks, graphic characters
If you want to divide 4 *5 by 10*6 you would type : are shown on the screen to represent the keys. These characters will NOT be
printed on the screen when you press RETURN . Retype the example above,
?(4*5)/(10*6) E using the cursor down key instead of the spaces inside the quotes. It should
The answer is now 0.333333333. look like th is:
?" 0000000000 OVER HERE " MB!liE
!I
• PRINTING TEXT You can tell the computer to print anywhere on your screen by using the
Now that you know how to print numbers and make calculat ions, it 's time cursor control keys in side quotation marks.
to learn how to print text. It's actually very simple-there are far fewer rules
for printing text than making calculations . You just type the PRINT command • DIRECT MODE FUNCTIONS
followed by whatever you want put on the screen in quotation marks (" " ).
You can get the quotes by pressing the SHIFT key and the numeral "2" key. There are two BASIC funct ions that tell the computer where to print infor-
Try the following examples. mation on the screen . If you 've used a typewriter, you are familiar with the
TAB function . It tells the computer to print your information starting in the
?" COMMODORE 64 " ¥ specified column . For example , if you want to print something starting in the
?"4*5"BillE 10th column and something else in the 20th column , you would use the TAB
Notice that when you press RETURN , what was in the quotes is displayed function like this:
on the screen exactly as you typed it. Also note the difference between the ? TAB(9)"HERE " TAB(19) " HERE " &Ell!E
second example and
The computer moves the cursor nine spaces to the right and then begins
?4*5® 55 to print the first "HERE " in the 10th column. If you want to print two pieces of
You can PRINT anything you want on the screen by using the PRINT com- information with exactly 10 spaces between tt1e end of the first and the
mand. You can combine text and calculations in a PRINT command . beginning of the second , how could you do it? If you knew how many letters
were in the first item, you could figure out how many spaces to TAB from the
?" 4*5 = "4*541 f\1¥
38 39
left side to PRINT the second item, but that isn't necessary. There 's another What if you want to round off numbers to the nearest 0.01-such as dol-
function that makes this task much easier, the SPC (space) function . Now the lars and cents? First, instead of adding 0.5 to your number, add 0.005 and
PRINT command would look like this: then multiply by 100. Let 's say you want to round 2.876 to the nearest 0.01 .
Using this method, you start with :
? " HERE " SPC(10)" HERE " E3ITFfH"'H?
The second piece of information is printed on the screen 10 spaces to the
? (2.876 + 0.005)* 100 Mi
right of the end of the first piece , no matter how long the first piece is. Now using the INT function to get rid of everything after the decimal point
(which moves two places to the right when you multiply by 100) so you are
left with :
• MATHEMATICAL FUNCTIONS
? INT(((2.876 + 0.005)*100)¥ w
Here are three other important functions that can be very helpful if you
want to do more advanced mathematical procedures like rounding off num- which gives you 288. All that's left to do is divide by 100 to give you 2.88-
bers and finding square roots. which is what you want! You can round off calculations to the nearest 0.01
The first function is the square root function: SOR. If you want to find the like this one:
square root of 50, just type:
?INT(((2.876 + 1.29 + 16.1-9.534) + .005)*100)/100 ¥
? SQR(50) ¥1 ¥
There is one more function which may come in handy when dealing with
You can find the square root of any positive number in this way. negative numbers. It is the absolute value function: ABS. Using this function
The second function is rounding off a number to the nearest integer. First, gives you the positive value of the number regardless of whether it is a posi-
use the INT (integer) function. The INT function takes away everything after tive or negative number.
the decimal point. Type:
?ABS(-10)mliE!R
? ABS(5) ;" IS EQUAL TO " ;ABS (-5)&BiaiE
? INT(SQR(5il))a;·
? INT(4.25)
? INT(4 .75)
• PROGRAM MODE
If you want to round off to the nearest whole number, then the 1ast exam-
ple should return a value of 5. In fact, you want to round off to the next Now that you can communicate with your Commodore 64 in DIRECT
highest number any number with a decimal above 0.5. To do this , you have to mode by typing BASIC commands, it's time to begin the next step: Writing a
program.
add 0.5 to the number when using the INT function, so numbers with deci-
mals above 0.5 will be increased by 1 before being rounded down by the INT A program is just a series of BASIC commands that tell the computer what
function . Try this example: to do. The commands are numbered so the computer will know in what order
you want them executed. In a BASIC program , the commands are called
? INT(4 .75 + 0.5).ii!iE statements or lines. Many of the commands you learned in DIRECT mode
can be easily made into program statements. For example, type:
In this case the computer adds 0.5 to 4.75 before it executes the INT
function , so that 5.25 is rounded down to 5 for the result. If you want to round 10?" COMMODORE64 " ;;;;;
off the result of a division calculation, you do this:
The first thing you should notice is that the computer did not print COM-
? INT((X/Y) + 0.5) !W&!illl~ MODORE 64 when you hit RETURN. That is because the 10 before the PRINT
command tells the computer that you are writing a BASIC program that
In this case you can substitute any values for the characters X and Yin the
begins at line number 10. Now type RUN and press RETURN .
inner parentheses.
Congratulations! You have just written and RUN your first BASIC program.
40 41
The line numbers in a program serve another purpose besides ordering the computer that store information about your program. Type in this short
your commands for the computer. They serve as a reference for the com- program:
puter in case you want to execute the command on that line later in your 10X = 5
program. We use the GOTO command to tell the computer to go to a line and 20?X
execute the command(s) in it . Now type:
Now RUN the program and see how the computer prints a 5 on your
20GOTO 10 screen. You told the computer in line 10 that the letter X will represent the
When you press RETURN after typing that line, you add it to your program number 5 for the remainder of the program. We call this an assignment state-
in the computer 's memory. It is common practice to number your program ment because now there is a box labeled X in the computer's memory, and
lines in increments of 10 in case you want to go back and add lines later on . the number 5 has been assigned to it. The = sign tells the computer that
Type RUN and watch the PRINT message scroll down your whatever comes to the right of it will be assigned to a box (a memory loca-
screen . When you have finished watching , press the RUN/STOP key on the tion) labeled with the letter(s) to the left of it. The box name on the left of the
left side of your keyboard to stop ihe program. This is a simple two-line pro- = sign can be either one or two letters, or one letter and one number (the
gram that repeats itself endlessly because the second line keeps referring letter MUST come first). The names can be longer but the computer only
the computer back to the first line. It would go on forever unless you stopped looks at the first two characters so the names PA and PART would refer to
it with the STOP key. Now type LIST #iU ;;u;;;_The screen should say: the same box. Also, you cannot use BASIC commands (LOAD , RUN , LIST,
etc.) or keywords (INT, ABS, SOR, etc .) as names. Refer to the BASIC ency-
10 PR INT"COMMODORE 64" clopedia in the back of this manual if you have any doubt about what is and
20GOTO 10 what is not a BASIC keyword.
READY In this case, X is called a constant because it always represents the num-
ber 5. You can put calculations to the right of the = sign to assign the result
Your program is still in memory. You can RUN it again if you want to. This is
to a box. You can mix text with constants in a print statement to identify
an important difference between PROGRAM mode and DIRECT mode. Once
them. Type NEW , then try this program:
a command is executed in DIRECT mode, it is no longer in the computer's
memory. 10 A = 3*100
Notice that if you used the? symbol in the PRINT statement, the computer 20 B = 3*200
has converted it into the full command. This happens when you LIST any 30 ?"A IS EQUAL TO " A
command you have abbreviated in a program . 40 ?" BIS EQUAL TO " B
You can use any whole number from 0 to 63,999 for a line number. Don 't
Now there are two boxes labeled A and B in the computer 's memory,
be afraid to experiment with your computer, writing programs or just making
containing the numbers 300 and 600 respectively. If, later in the program, you
calculations in DIRECT mode. Nothing you type can damage the computer
want to change the value of a constant , just put another assignment state-
permanently. Anytime you want to start again or erase a BASIC program in
ment in the program. Add these lines to the program above and RUN it again.
the computer's memory, just type NEW fu&J#1'ii'BI$. This command clears
out the computer 's BASIC memory, the area where programs are stored. 50A = SOR(121)
60 B = ABS(-15)
• CONSTANTS, VARIABLES AND STRINGS 70GOT030
Once again , you 'll have to press the STOP key to break from the program.
CONSTANTS LIST the program and trace the steps taken by the computer. First, it assigns
the value to the right of the = sign in line 10 to the letter A. It does the same
There is a part of the computer's BASIC memory reserved for the num- thing in line 20 for the letter B. Next, it prints the messages in lines 30 and 40
bers and letters you use in your program. Think of it as a number of boxes in that give you the values of A and B. Finally, it assigns new values to A and B
43
42
in lines 50 and 60. The old values are destroyed and cannot be returned that you can print the value of a variable from a program in DIRECT mode
unless the computer executes lines 10 and 20 again (which it does not in this once the program has been RUN . Type ?A$;X;B;$ after running the program
program). When the comput~r is sent to line 30 to begin printing the values of above and see that those three boxes are still in the computer's memory. If
A and B again , it prints the new values. Lines 50 and 60 reassign the same you want to clear this area of BASIC memory but still leave your program
values to A and B (this does no harm) and 1;ne 70 sends the computer back to intact, use the CLR (clear) command. Just type CLR ~ and all con·
line 30. This is called an endless loop. It is not good programming practice. stants, variables and strings are wiped out . But when you type LIST, you can
Other methods of looping are discussed later 1n thi s and the following two see that the program is stil l in memory. The NEW command discussed ear·
chapters. lier erases both the program and the variables in it.
VARIABLES •IF-THEN
A variable is a value assigned to a box that changes during the course of Now that you can change the values of variables easily, the next step is to
the program . Sometimes the value of a variable is not known at the beginning have the computer make decisions based on these updated values. we do
of the program (i.e., its value will be the resu lt of a calculation to be made in this with the IF-THEN statement. We tell the computer to execute a corn·
the program). Clear your computer's memory by typing NEW RETURf'.t and mand only IF a condition is true (i.e., IF X = 5). The command we want the
type in the program below: computer to execute when the condition is true comes after the THEN part
10 A = INT(100/9) 1n the statement. Clear your computer 's memory and type in this program.
20 B = (3*4)t2 10J = 0
30 C = A*B 20 ?J, " COMMODORE 64 "
40 ?A " TIMES "B " EQUALS " C =
30 J J + 1
40 IF J = 5 THEN GOTO 60
Note that A and B are constants-they are expressed only in numeric
50GOTO 20
terms in the program. C. on the other hand , is expressed in terms of A and B.
60 END
making it a variable . The value in a variable box in memory often changes
during a program . At last, we no longer have to press the STOP key to break out of a looping
program. The IF-THEN statement tells the computer to keep printing " COM·
STRINGS MODORE 64" and incrementing J until (J = 5) is true. When the IF condition
A string is a character or group of characters enclosed in quotes. These is false, the computer just jumps to the next line of the program no matter
characters are stored in the computer's memory in much the sa me way what .comes after the THEN . Notice the END command in line 60. It is good
numeric variables are. You can also use names to represent strings as you practice to put an END statement at the end of your programs. It tells the
computer where to stop executing statements.
use them to represent numbers. Use the $ after the string name to tell the
computer it is a string variable and not a numeric variable . Clear your corn· Following is a list of symbols that may be used in the IF condition and
their meanings: '
puter's memory and type in the program below:
SYMBOL MEANING
10A$ = "COMMODORE "
20 x = (200/25)t2 EQUALS
30 B$ ="COMPUTER ' > GREATER THAN
40 Y = INT(4 *0 .35) < LESS THAN
50 ?"THE "A$;X;B$ " IS NUMBER " Y <> NOT EQUAL TO
See how you can print numeric and string variables in the same stat e· >= GREATER THAN OR EQUAL TO
ment? Try experimenting with variables in your own short programs. Notice <= LESS THAN OR EQUAL TO
44 45
• EDITING TIPS • STORING AND REUSING YOUR PROGRAM
Once you have edited your program , you may want to store it permanently
At this point, you know enough to begin programming in BASIC. You have so that you will be able to recall and use it later. To do this you'll need either
learned how to make calculations in both DIRECT and PROGRAM modes. the Commodore Datassette recorder or a Commodore disk drive.
You have seen how to print text or characters on the screen . You also know
how to tell the computer to repeat commands and make decisions. There are
more advanced ways of telling the computer to do these things (which you'll • FORMATTING A DISK
see later in this Guide), but you have all you need to get started. The following
To store programs on a new (or blank) disk, you must first prepare the disk
paragraphs provide some tips on typing in your programs and making correc-
to receive data Thi s is called "for matting " the disk. Make su re that you turn
tions and additions to them.
on the disk drive before inserting any disk.
To begin with, type in the program from the IF-THEN example just dis-
To format a blank disk, type t111s command.
cussed . Now type 1O ± - 4@. You just erased line 10 from the program .
LIST your program and see for yourself. If the old line 10 is still on the screen, OPEN 15,8, 15: PRINT# 15, " N : A$ , B$ " ~i:i~
move the cursor up so that it is blinking anywhere on that line. Now, if you
In place of A$, type a disk name of your choice: you can use up to 16
press RETURN, line 10 is back in the computer 's memory. Hold down the
characters to identify the disk. In place of 8$ , type a two-character code of
SHIFT and press the CLR/HOME key on the upper right of your keyboard to
your choice (such as W2).
clear your screen. Now LIST your program and notice that line 10 is back
The cursor di sa ppears for a second or so . When the cursor blinks again ,
again. Move the cursor up again so it is blinking on the 0 in 10. Now type a 5
seal the disk with the following command ·
and press RETURN . You have just duplicated line 10 with a new line at 15.
Clear your screen and list the program . You can cursor up and make any CLOSE15m~
changes to any line of the program you want to. Just remember to press
The entire format ting process takes about 80 seconds.
RE TURN after you make changes , or the computer will not recognize them .
Also, you can retype a whole line and press RETURN-the old version of the
statement wil be erased when you press RETURN . • THE SAVE COMMAND
Now clear your memory and type:
You use the SAVE command to store your program on cassette tape or
10 ?" I ADORE MY 64" disk .
Let 's say you want to add a word in the middle of that string (for example,
the word CO MMODORE). Just move the cursor so it is blinking on the letter SAVEing ON CASSETTE TAPE
that is one space after the spot where you want to insert the word. In this If you are using a Datassette to store your program , insert a blank tape in
case, the cursor should be blinking on the 6. Hold down the SHIFT while the recorder, rewind the tape (if necessa ry) and type:
pressing the INST/DEL key in the upper right corner of your keyboard and
watch the 64" move to the right until you release the INST/DEL key. Then
type COMM ODORE and move the cursor to the 6. In you held down the The PROGRAM NAME can be anything you want it to be. You can use
INSERT key for a long time, then you have some blank spaces to get rid of. letters, numbers and/or symbols-up to 16 characters in all. Note that you
Hold down the DEL key until the 64 " is in the correct posi tion. Now press must enc lose the PROGRAM NAME in quotation marks. The screen on your
RETURN and LIST your prog ram to see if your change is registered in mem- computer goes blank while the program is being SAVEd. but it return s to
ory. normal when the process is completed .
47
46
SAVEing ON A DISK Again, the 8 indicates to the computer that you are working with a disk
drive.
If you have a Commodore single disk drive, you can store your program on
disk by typing:
SAVE "PROGRAM NAME ", 8 ¥
To see your program once it has been loaded from either tape or disk,
The 8 indicates to the computer that you are using a disk drive to store type:
your program .
The same rules apply for the PROGRAM NAME whether you are using LIST I 'PW
tape or disk. Note that you cannot put two programs with the same name Your entire program will then be displayed.
onto the same disk.
If the program in the computer is identical to the one on the disk, the
and the next program on the tape will be retrieved . screen display will respond with the letters "OK".
You can use the counter on the Datassette to identify the starting position
of programs. Then, when you want to retrieve a program, simply wind the DISPLAYING YOUR DISK DIRECTORY
tape forward from OOO to the programs 's start location , and type :
To see a list of the programs on your disk, type:
LOAD IJ!ll'§
LOAD"$",8&!liilli
In this case you don 't have to specify the PROGRAM NAME; your program
will load automatically because it is the next program on the tape . The cursor disappears during this process. When the cursor reappears,
type:
NOTE: During the LOAD process, programs are not erased from
the tape; they are simply copied into the computer. However, LIST ~Wl!&llli
LOADing a program automatically erases any BASIC program that
A list of the programs on your disk will then be displayed.
may have been in the computer 's memory.
48 49
DELETING A PROGRAM
To delete a program from the disk (also known as " scratching" a program) ,
type:
OPEN 1,8, 15, " SO:PROGRAM NAME" !EBBEllE
· CLOSE 1 &Biiii!
•SAMPLE PROGRAM
Here is a sample program incorporating many of the techniques and com- FOR-NEXT 53
mands discussed in this section. INPUT 54
This program calculates the average of three variables {X, Y and Z) and
GET 55
prints their values and their average on the screen. You can edit the program
and change the calculations in lines 10 - 30 to change the values of the STOP and CONT 56
variables. Line 40 adds the variables and divides by 3 to get the average. Sample Program 56
Note the use of parentheses in line 40 to tell the computer to add the num-
bers before it divides them .
TIP: Whenever you are using more than one set of parentheses in
a statement, it's a good idea to count the number of left parenthe-
ses and right parentheses to make sure they are matched.
50 51
This section gives you additional information on BASIC that will allow you
to create and run more sophisticated BASIC programs . New commands and
statements like FOR-NEXT, INPUT, GET and STOP are introduced and used
in sample programs. The structure and operation of these sample programs
are analyzed and illustrated.
•FOR-NEXT
Remember the sample program in the IF-THEN example in Section 4? We
got the computer to print COMMODORE 64 five times by telling it to incre-
ment the variable J by units of one until it equalled five, then ended the
program .There is a simpler way to do this in BASIC. We use a FOR-NEXT
loop in the following way:
=
10 FORJ 1 TO 5
20 ?" COMMODORE 64 "
30 NEXT J
40 END
RUN this program and compare the result with the result of the IF-THEN
program-they are the same I In fact , the steps taken by the computer are
almost identical for the two programs. The FOR-NEXT loop is a very power-
ful set of commands. You can tell the computer to do many things without
having to type them all in your program. Let 's trace the computer's steps for
the program above.
First , the computer assigns a value of 1 to the variable J. The 5 in the FOR
statement tells the computer to execute all statements between the FOR
statement and the NEXT statement , in this case just the PRINT statement ,
until J is equal to 5. After the computer assigns a value of 1 to J, it compares
=
1 to 5 to see if J 5 is true-much in the same way as the IF sta tement.
=
Since J 5 is not true yet , the computer continues with the program . It exe-
cutes the PR INT statement. The NEXT J statement tells it to go back to the
=
FOR statement , add 1 to J, compare J to 5 and continue if J 5 is still false .
After five executions of this loop, J will equal 5. At this point. the computer
drops down to the statement that comes immediately after the NEXT state-
ment and continues from there.
You can tell the computer to increment your counter by units of 10, 0.5 or
any other number. You do this with the STEP command in the FOR state-
ment. For example, if you want the computer to count by tens to 100, type:
10 FORX =0 TO 1OOSTEP 10
20?X
30 NEXT
53
Notice that you do not need the X in the NEXT statement if you are only can put anything you want in your prompt , but it cannot be longer than 38
executing one loop at a time-this is discussed in the chapter on advanced characters.
concepts. Also, you do not have to increment your counter-you can decre- The INPUT statement can also be used with string variables. The same
ment it. rules that apply for numeri_ c variables apply for strings-don't forget to use
Edit line 10 in the program to read: the$ to 1dent1fy all your string variables. Clear your computer's memory and
type in this program .
10FORX=100TO 0 STEP-10
10 INPUT" WHAT IS YOUR NAME "; N$
The computer will count backwards in units of 10 from 100 to 0. If you
20 ?" HELLO " N$
don 't use the STEP command , the computer will increment the counter by
units of 1. An important thing to remember when you use the FOR-NEXT Don 't forget to press RETURN after you type in your name. Once the value
loop is that you can use a variable in place of any of the numbers in the FOR of a variable (numeric or string) has been INPUT in a program , you can refer
statement. As we introduce more of the BASIC commands , you will see what to 1t by its variable name any time in the program . Type ?N$ x
a powerful device this can be. Clear the computer's memory and RUN this your computer remembers your name!
program.
10K=10 •GET
20 FOR I = 1 TO K
30 ?"COMMODORE 64 " . There is another BASIC command you can use in your program to interact
40 NEXT with the computer. It is the GET command and is similar to INPUT To see
how the GET statement works, clear the computer 's memory and type in this
program .
• INPUT 10 GET A$
You can change the value of Kin line 10 to make the computer execute the 20 IF A$= "" THEN GOTO 10
loop as many times as you want it to. What if you wanted to be able to tell the 30?A$
computer how many times to execute the loop at the time the program is 40 END
RUN?
You want to be able to change the value of K each time you run the pro- When you type RUN+ 4A#, the computer doesn't appear to do any-
gram without having to change the program itself. We call this the ability to thing . It is waiting for you to press a key on the keyboard. The GET command
interact with the computer. You can have the computer ask you how many tells the computer to fetch a character from the keyboard. The computer is
times you want it to execute the loop. To do this, use the INPUT command . perfectly sat1sf1ed ""'.1th a null character-which is what it gets when no key is
Replace line 10 in the program above with : being pressed. This 1s the reason for line 20, which tells the computer that if it
got a null character, (two double quotes with no space between them), it
10 INPUT K should go back to line 10 and get another character. This loop continues until
Now when you RUN the program , the computer responds with a? to let you actually press a key. The computer then assigns the character on that
key to A$ .
you know it is waiting for you to tell it what you want the value of K to be . Type
15 and press RETURN . The computer will then execute the loop 15 times. The GET command is very useful in BASIC because you can use it to
You can make the computer print a message in an INPUT statement to tell program a key on your keyboard. The example below programs the Q key to
you what variable it's waiting for. Replace line 10 with : print a message on the screen. Once you type it in and RUN it, press o and
see what happens.
10 INPUT" PLEASE ENTER A VALUE FOR K" ;K
10 ?"PRESS 0 TO VIEW MESSAGE "
Remember to enclose your message to be printed (called a prompt) in 20GET A$
quotes. Also, you must use a semicolon between the prompt and the K. You 30 IF A$ = "" THEN GOTO 20
54 55
loop and the INPUT command, you can make the program more powerful.
40 IF A$ = " Q " THEN GOTO 60
Clear the computer's memory and type in the program below. By now, you
50 GOT020
should recognize the graphic character in line 40 as the CRSR down key
60 FOR I = 1 TO 25
inside quotes. Don 't worry that line 90 does not fit onto one line of your
70 ?" NOW I CAN USE THE GET STATEMENT"
screen . Remember, a p1ogram line can be up to two screen lines (80 charac-
80 NEXT
ters) long.
90 END
Notice that if you try to press any key other than the Q , the computer will 10T = O
20 INPUT" HOW MANY NUMBERS"; N
go back to line 20 to GET another character.
30 FOR J = 1 TO N
40 INPUT" iPLEASE ENTER A NUMBER ";X
• STOP AND CONT 50T = T+X
60 NEXT
There is another way to interact with your computer. You can make it stop
70A = T/N
running the program , then continue executing it when you are ready. The
80 PRINT
STOP command must be in the program-you can put a STOP statement
90 ?" YOU HAVE "; N" NUMBERS TOTALING ";T
anywhere you wan t to in a program . When the computer breaks from the
program , you can use direct mode commands to find out exactly what is
100 ?"AVERAGE =";A
110 END
going on in the program (i .e., the value of a loop counter or other variable) .
This is a powerful device when you are debugging (fixing) your program . Here is a line-by-line explanation of what the program does.
Clear the computer's memory and type in the prograrr be low.
Line 10 assigns an initial value of 0 to T, which w ill be the running total of
10 X = INT(SOR(630)) the numbers.
20 Y = (.025*80)T 2 Line 20 lets you determine how many numbers to average .
30 Z = INT(X*Y) Line 30 tells the computer to execute a loop that many times.
40 STOP Line 40 lets you type in the actual numbers to be averaged.
50 FOR J = 0 TO Z STEP Y Line 50 adds each number to the running total.
60 ?" INTERACTION CAN BE FUN " Line 60 tells the computer to go back to line 30, increment the counter (J)
70 NEXT and start the loop again .
80 END Line 70 divides the total by the amount of numbers you typed in (N) after
the loop has been executed N times to calculate the average.
Now RUN the program-the computer responds with "BREAK IN 40 ' . At
Line 80 prints a blank line on the screen.
this point, the compu ter has calcu lated the values of X. Y and Z. If you want
Line 90 prints the message that gives you the amount of numbers and
to be able to figure out what the rest of the program is supposed to do , tell
their total.
the computer to PR INT X;Y:Z . ™lil'iH Often , when you are fixing a large
Line 100 prints the average of the numbers.
program (or a complex small one) , you'll want to know the value of a variable
Line 110 tells the computer that your program is finished.
at a certain point in the program. When you have all the information you
need, type CONT~ - The computer continues with the program . Now you have the ability to tell the computer how many numbers you want
starting with the statement after the STOP command . to average, and you can change the numbers every time you run the
program-without having to change the program.
• SAMPLE PROGRAM You have extended your grasp of BASIC in this section . The next section
Remember the program from the previous section that calculated the shows you how to fine-tune the commands, concepts and techniques you've
average of three numbers? Now that you know how to use the FOR-NEXT learned so far.
57
56
ADVANCED CONCEPTS
This section defines and shows how to use
even more powerful BASIC commands, statements,
functions and programming techniques
READ-DATA 61
RESTORE 62
Using Loops 64
Using the Colon 65
Dimensioning Arrays 65
GOSU B-RETU RN 67
ON GOTO/GOSUB 68
RAM/ROM Access 69
ASC and CHR$ 70
Function Keys 70
Converting Strings and Numbers 71
Random Numbers 72
This section introduces still more BASIC commands, statements, func-
tions and programming techniques . New commands and functions include
READ-DATA. RESTORE, DIMENSION , GOSUB-RETURN, ON GOTO/GOSUB,
PEEK, POKE, ASC , CHA$ and STR$.
These commands and functions allow you to create repeated actions
through techniques called looping and nesting; handle tables of values;
branch or jump to another section of a program and also return from that
section ; assign varying values to a quantity-and more. The use of special
function keys (the four large keys to the right of the main keyboard) is also
explained. Again , sample programs are developed and analyzed to illustrate
just how these BASIC concepts work and interact.
•READ-DATA
There is another way to tell the computer what numbers or characters to
use in your program . You can use the READ statement in your program to tell
the computer to get a number or character(s) from the DATA statement. For
example, if you want the computer to find the average of five numbers, you
can use the READ and DATA statements this way:
10T=O
20 FOR J = 1 TO 5
30 READ X
40T=T +X
50 NEXT
60A=T/5
70 ?"AVERAGE =";A
80 END
90 DATA 5,12,1,34 ,18
When you run the program , the computer will print AVERAGE = 14 on
your screen. Let 's trace the steps taken by the computer to arrive at this
number:
Line 10 assigns a value of zero to T-the running total.
Line 20 tells the computer to execute a loop five times.
Line 30 tells the computer to go to the DATA statement (line 90), get a
value and assign it to the variable X.
Line 40 adds the value of X to the running total.
Line 50 tells the computer to execute the loop again.
Line 60 divides the total by five when the loop is completed for the fifth
time.
Line 70 prints the average on the screen .
61
.........- -
62 63
'W
-
assigns a value from the DATA statement to the position in the X array that
corresponds to loop counter (J). Line 40 does the same thing it did before ,
• USING THE COLON
but you must use a subscripted variable to do it. Another useful tool in programming is the colon (:). You can use the colon
After you run the program , if you want to recall the third number, type ?X(3) to separate two (or more) BASIC statements on the same line. This may save
ll!Eli!E. The computer remembers every number in the array X. You can time and space in your programs , and it may save some memory. Update the
create string arrays to store the characters in string variables the same way. above program by combining the statements in the delay loop on one line.
Try upaating the COMMODORE 64 COMPUTER program so the computer This is how it should now appear:
will remember the elements in the A$ array. It should look like this:
10 A$ = "COMMODORE 64 "
5 DIM A$(3) 20 FOR J = 1 TO 20
10 FOR J = 1 TO 3 30 PRINT
20 READ A$(J) 40 FORK = 1TO1500:NEXT
30 ?A$(J) 50 PRINT A$
40 NEXT 60 NEXT
50END 70END
60 DATA COMMODORE ,64 ,COMPUTER
Notice the program is one line shorter than before . Often the statements
TI P: You do not need the DIM statement in your program unless in a delay loop are combined on one line, because they work together and
the array you use has more than 10 elements. See DIMENSION- are executed in succession .
ING ARRAYS.
Statements after a colon on a line are executed in order, from left to right.
You can put as many statements as you can fit onto two screen lines (80
• USING LOOPS characters) in one line of your program . This provides an excellent opportu-
Before you proceed any further, you 'll need to understand more about nity to take advantage of the THEN part of the IF-THEN statement. You can
loops and the ways they are used to get the computer to do what you want. tell the computer to execute several commands when your IF condition is
You can use a loop to slow down the computer-by now you have witnessed true. Clear the computer 's memory and type in the following program:
the amazing speed with which the computer executes commands. See if you 10 INPUT" I ENTER ANY NUMBER"; N
can predict what this program will do before you run it. 20 IF N<5.,.HEN PRINT" i LESSTHAN 5":GOTO 10
10 A$= "COMMODORE 64 " 30 ?"iGREATER THAN OR EQUAL TO 5"
20 FOR J = 1 TO 10 40END
30 PRINT See how you can tell the computer to execute more than one statement
40 FORK= 1TO1500 when (N < 5) is true. You can put any statement(s) you want after the THEN
50 NEXT K command, but none of them will be executed unless the IF condition is true.
60 PRINT A$
70 NEXT J
80 END • DIMENSIONING ARRAYS
Did you get what you expected? The loop contained in lines 40-50 tell s the Now that you know how to use a nested loop, you can have the computer
computer to count to 1500 before executing the remainder of the program . handle data in a more advanced way. What if you had a large table of num-
This is known as a delay loop and may be useful to you in your programs. bers on which you wanted to perform calculations? Picture a chart with 10
Because it is inside the main loop of the program , it is called a nested loop. rows and 5 numbers in each row. Suppose you wanted to find the average of
We will come back to nested loops later in this chapter. the five numbers in each row (see chart next page). You could create 10
64 65
arrays and have the computer calculate the average of the five numbers in 10 DIMX(10,5),A(10)
each one . This is not necessary. You can put all of the numbers in a two- =
20 FOR R 1 TO 10
dimensional array. This array would have the same dimensions as the chart 30T=0
of numbers you want to work with-10 rows by 5 columns. The DIM state- 40 FOR C = 1 TO 5
ment for th is array (we will call it array X) should be: 50 READX(R ,C)
60 T = T + X(R,C)
10 DIM X(10,5) 70 NEXTC
This tells the computer to reserve space in its memory for a two- 80 A(R) = T/5
dimensional array named X. The computer reserves enough space for 50 90 NEXTR
numbers. You. do not have to fill an ar ray with as many numbers as you 100 FOR R = 1 TO 10
110 PRINT "i !ROW #" ;R
DIMens1oned 1t for, but the computer stil l reserves space for all of the posi-
120 FOR C = 1 TO 5
tions in the array.
130 PRINTX(R ,C):NEXT C
Now it becomes very easy to refer to any number in the chart by its
140 PRINT"AVERAGE = ";A(R)
column and row position. Refer to the chart of numbers below. Find the third
150 FORD= 1TO1000:NEXT
element in the tenth row (1500). You would refer to this number as X(10,3) in
your program . The program on the following page reads the numbers from 160 NEXT R
170 DATA 1,3,5,7,9
the chart into a two-dimensional array (X) and calculates the average of the
180 DATA2,4,6,8, 10
numbers in each row.
190 DATA 5, 10,15,20,25
200 DATA 10,20,30,40 ,50
210 DATA 20,40,60,80, 100
220 DATA 30,60,90, 120,150
Column
230 DATA 40,80 ,120,160,200
Row 2 3 4 5 240 DATA 50, 100,150,200 ,250
1 1 3 5 7 9 250 DATA 100,200,300,400,500
2 2 4 6 8 10 260 DATA 500, 1OOO,1500,2000,2500
3 5 10 15 20 25
4 10 20 30 40 50
5 20 40 60 80 100
• GOSUB-RETURN
6 30 60 90 120 150 Until now, the only way you know to tell the computer to jump to another
7 40 80 120 160 200 part of your program is the GOTO statement. What if, at a certain point in the
8 50 100 150 200 250 program , you want the computer to jump to another part of the program,
9 100 200 300 400 500 execute the statements in it, then return to the point it left off and continue
10 500 1000 1500 2000 2500 executing the program from there? The part of the program that the com-
puter jumps to and executes is called a subroutine. Clear your computer's
memory and enter the program below.
10 A$ = " SUBROUTINE": B$ =" PROGRAM "
20 FOR J = 1 TO 5
30 INPUT''ENTER A NUMBER";X
40GOSUB 100
50 PRINT B$:PRINT
67
66
60 NEXT • RAM/ROM ACCESS-PEEK AND POKE
70END
The Commodore 64 's memory is composed of RAM (Random Access
100 PRINT A$:PRINT
Memory) and ROM (Read Only Memory). In all , there are over 64 ,000 mem-
=
110 Z Xt2:PRINT Z
ory locations in the computer. Each area of the computer's memory has a
120 RETURN
special function. For instance, there is a very large area to store your pro-
This p·rogram takes the five numbers you type in, squares them, and prints grams and the variables associated with them. This is the part of memory
the result. The other print messages tell you when the computer is executing that gets cleared when you use the NEW command.
the subroutine or the main program . Line 40 tells the computer to jump to Other areas are not as large , but they have very specialized functions. For
line 100, execute it and the statements following it until it sees a RETURN instance, there is an area of memory that controls the music features of the
statement. The RETURN statement tells the computer to go back in the pro- computer. There are some memory locations that have special functions of
gram to the line immediately followiny tile GOSUB statement and continue their own . There are two BASIC commands you can use to access and
executing . The subroutine can be anywhere in the program-including after manipulate the computer 's memory.
the END statement. Also, remember that the GOSUB and RETURN com - This can be a powerful programming device because the contents of the
mands must always be used together in a program (like FOR and NEXT & IF computer's memory locations determine exactly what the computer should
and THEN), otherwise the computer will give you an error message. be doing at the time. The PEEK command can be used to make the computer
tell you what value is being stored in a memory location (a memory location
can store any value between 0 and 255) . You can PEEK the value of any
• ON GOTO/GOSUB memory location (RAM or ROM) in direct or program mode. Type:
There is an even more powerful way to make the computer jump to
another section of your program (we call that branching). By using the ON
P =PEEK(650) llRE
?PE-II!
statement, you can have the computer decide what part of the program to
branch to based on a calculation or keyboard input. The ON statement is The computer assigns the value in memory location 650 to the variable P
used with either the GOTO or GOSUB-RETURN commands, depending on when you press RETURN after the first line. Then it prints the value when you
what you need the program to do. A variable or calculation should be after press RETURN after the PRINT command . Memory location 650 determines
the ON command. After the GOTO or GOSUB command , there should be a whether or not keys like the SPACEBAR and CRSR repeat when you hold
list of line numbers. Type in the program below to see how the ON command them down. A 0 in location 650 tells the computer to repeat these keys when
works. you hold them down. Hold down the SPACEBAR and watch the cursor move
across the screen.
10 ?"ENTER A NUMBER BETWEEN ONE AND FIVE" To change the value stored in a RAM location, use the POKE command.
20 INPUTX Type:
30 ON X GOSUB 100,200,300,400,500
40END POKE 650 ,96 !llRB
100 ?"YOUR NUMBER WAS 1 ":RETURN
The computer stores the value after the comma (96) in the memory loca-
200 ?"YOUR NUMBER WAS 2":RETURN
tion before the comma (650). A 96 in memory location 650 tells the computer
300 ?"YOUR NUMBER WAS 3":RETURN
101 to repeat keys like the SPACEBAR and CRSR keys when you hold them
400 ?"YOUR NUMBER WAS 4": RETURN
jown. Now hold down the SPACEBAR and watch the cursor-almost nothing
500 ?"YOUR NUMBER WAS 5": RETURN
iappens! The cursor moves one position to the right , but it does not repeat.
When the value of X is 1, the computer branches to the first line number in ro return to its normal state, type:
the list (100). When X is 2, the computer branches to the second number in
POKE 650,0 Bmi!B
the list (200), and so on .
69
68
You cannot alter the value of all the memory locations in the computer- F5 CHR$(135}
the locations in ROM (57344-65535) can be read, but not changed. F6 CH R$( 139)
F7 CHR$(136)
NOTE: As mentioned before, there are many memory locations
F8 CHR$(140)
(65,536) in the Commodore 64. Refer to the Commodore 64 Pro-
grammer's Reference Guide for a complete memory map of the To get the even-nu mbered function keys, hold down the SHIFT key while
computer. pressing the key. For example , to get F2 , hold down SHIFT and press F1 .
You can use the function keys in your programs in many ways . To do this,
• ASC AND CHR$ you 'll need to use the GET statement. Refer to Section 5 if you need a
refresher course on GET. The prog ram below prepares the F1 key to print a
Every character the Commodore 64 can print (including graphic charac- message on the screen .
ters) has a number assigned to it. This number is called a character string
code (CHR$) and there are 255 of them in the Commodore 64. There are two 10 ?" PRESS F1 TO CONTINUE "
20 GET A$:1 F A$= ""THEN 20
functions associated with this concept that should prove to be very usefu l.
The first is the ASC function . Type: 30 IF A$OCHR$(1 33) THEN 20
40 ?"YOU HAVE PRESSED F 1"
?ASC( " Q") 3&&
Lines 20 and 30 do most of the work in this program . Line 20 makes the
The computer responds with 81. 81 is the character stri ng code for the Q computer wait until a key 1s pressed before executing any more of the pro-
key. Substitute any key for 0 in the command above to find out the code gram. Note that when the command immediately after THEN 1s a GOTO com-
number for any key. mand, only the line number is necessary. Also note that a GOTO command
The second function is the CHR$ function . Type: an GOTO the same line it is on . Line 30 tells the computer to go back and
wait for another key to be pressed unless the F1 key has been pressed.
?CHR$(81) F5
The computer responds with 0 . of course! CHR$ is the opposite of ASC. • CONVERTING STRINGS AND NUMBERS
They both refer to the table of character string codes in the computer 's mem-
Sometimes you may have the need to perform calculations on numeric
ory. See the appendix of this guide for a full listing of ASC and CHR$ codes.
characters that are stored as string variables in your prog ram. Other times,
you may want to perform string operations on numbers. There are two BASIC
• FUNCTION KEYS functions you can use to convert your variables between numeric and string
type. The VAL function returns a numeric value for a string variable. Type in
By this time , you have probably noticed there are four large keys on the far
the short program below.
right side of your keyboard. These are your function keys. They are no differ-
ent than any other key on your keyboard except they do not have a printed 10A$= " 64 "
character assigned to them . They do, however, have CHR$ codes. In fact, 20 A = VAL (A$)
each of them has two CHR$ codes-one for when you press the key, and one 30? " THE VALUE OF "; A$ " IS";A
for when you press the key while holding down the SHIFT key. The CHR$
codes for the F1-F8 keys are 133-140. However, they are not numbered in At this point you should know the program does not have to be ended with
an END statement.
order. The list below shows the keys and their corresponding CHR$ codes.
The STR$ function converts numeric variables into string variables. Clear
F1 CHR$(133) the computer's memory and type in this program .
F2 CHR$(137)
F3 CHR$(134) 10A=64
F4 CHR$(138) 20 A$ = STR$ (A)
30 ?A" IS THE VALUE OF ";A$
70 71
• RANDOM NUMBERS
There is one final function before you learn to apply the concepts pre-
sented in Sections 4, 5 and 6 to things like graphics and music. The RND
function tel ls the compute r to generate a random number. All generated
numbers are nin e digits in decimal form between 0.00000000 1 and
0.999999999. Type:
?RN D(O)M MW
?(INT(RND(0)*6) + 1} + (INT(RND(0}*6) + 1}
This section and the preceding two sections have been designed to famil - Printing in Different Colors _____________ 75
iarize you with the BASIC computer programming language and its capabili- Color Character String Codes (CHR$) _ _ _ _ _ _ __ 76
ties. In the next two sections you will enter a world of ad 11anced program-
ming in graphics and sound. Remember that more information on every Color Registers-Changing Screen ,
command discussed in this Guide can be found in the Commodore 64 Pro- Border and Character Colors _ _ _ _ _ _ _ _ _ _ _ 77
grammer's Refe rence Guide. Screen Memory _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 80
Color Memory 82
Animation 83
Sprite Graphics 87
- Sprite Concepts 87
- Designing a Sprite Image 88
-Converting Your Spr ite Image Into Data 88
-Controlling Sprites 94
- Animating Your Sprites 97
-Tying Your Sprite Program Together 100
Graphics Modes 102
72 73
Your Commodore 64 gives you exceptional graphics capabilities. The Com-
modore 64 offers sixteen colors, five graphics modes and programmable
animated objects called sprites . This section elaborates on the several pow-
erful graphics features built into the Commodore 64 and how they are used.
75
Table 7-1 lists the colors available on the C64. The table also shows the key Col or CHR$ Code Col or CHR$ Code
used to specify a given color, and the resulting control character that White CHR$(5) Dk. Gray CHR$(151)
Red CHR$(28) Gray CHR$(152)
appears in quotes in a PRINT statement.
Green CHR$(30) Lt . Green CHR$(153)
Blue CHR$(31) Lt . Blue CHR$(154)
Orange CHR$(129) Lt. Gray CHR$(155)
Table 7-1. C64 Colors
Black CHR$(144) Purple CHR$(156)
Brown CHR$(149) Yellow CHR$(158)
KEYBOARD CO LOR DISPLAY KEYBOARD COLOR ~ SPLAY Lt . Red CHR$(150) Cyan CHR$(159)
mma
&1111
BLACK
WHITE
•
~ ~·
~·
ORANGE
BROWN
•
,......
1...i
~
To select any of the Commodore 64 colors , PRINT the above character
&1111 tall ~El string codes according to the colors you want to display on the screen. The
-·
RED LT. RED
~ following program illustrates how to select colors within a program.
~·
&1111 CYAN iii;:] GRAY 1
&1111
PURPLE
GREEN
•
D ~·
~·
GRAY 2
LT. GREEN
11'.11
II
10 PRINTCHR$(5)
15 PRINT "WHITE"
mma
ma
BLUE
=
m ~·
LT . BLUE 0
••
••
20 PRINTCHR$(28)
25 PRINT " RED "
~·
YELLOW GRAY 3
30 PRINTCHR$(30)
35 PRINT " GREEN "
40 PRINTCHR$(31)
45 PRINT " BLUE "
47 PRINTCHR$(129)
• COLOR CHARACTER STRING CODES (CHR$) 48 PRINT " ORANGE "
· Each character on the Commodore 64 keyboard has a number associated 50 PRINTCHR$(144)
with it. When you press a key, the computer scans the keyboard and under-
55 PRINT"BLACK "
60 PRINTCHR$(149)
stands exactly which character is typed. A character code value is entered
65 PRINT " BROWN"
into memory each time a key is pressed . These codes are referred to as 70 PRINTCHR$(150)
cha racter string codes. Appendix E lists al l the character string codes the 75 PRINT " LT . RED"
Com modore 64 understands. 80 PRINTCHR$(151)
Within a prog ram , you can select colors using character string codes 85 PRINT " DK . GRAY"
instead of holding down the CTRL key and pressing a numbered key. For 90 PRINTCHR$(152)
instance, enter the fo llowing sample program: 95 PRINT " GRAY "
100 PRINTCHR$(153)
10 PRINTCHR$(5)5ft f llO PRINT " LT . GREEN"
20 PRINT "WHITE" l!i§ 120 PRINTCHR$(154)
130 PRINT " LT . BLUE "
NOTE: In the remainder of this section, the W · 11M symbol is
140 PRINTCHR$(155)
shown only after DIRECT mode statements, not after program 150 PRINT " LT . GRAY "
lines. 200 PRINTCHR$(156)
When you RUN this program, the character color changes from blue to 210 PRINT " PURPLE "
white and the word " WHITE" is displayed. The other 15 colors also have a 220 PRINTCHR$(158)
charac ter string code assigned to them. The fo llowing is a list of all the colors 230 PRINT " YELLOW "
available on the Commodore 64 and the coresponding character string 240 PRINTCHR$(159)
codes: 250 PRINT " CYAN "
76 77
character string codes (CHR$). The following POKE changes the character
• COLOR REGISTERS-CHANGING SCREEN, color from light blue to white:
BORDER AND CHARACTER COLORS POKE646,1 M
Your Commodore 64 computer has 64K of memory. This means the C64 Note that the character color changes to white , but the characters already
holds 64 limes 1024 (65536) bytes of information. Think of the internal struc- on the screen remain the same color as before. All the characters you type
ture of your computer as 65536 storage compartments piled one on top of from now on are displayed in white unless you change the character color
the other. They are labeled starting from the bottom at location zero (0) and again .
continue upward to location 65535 on top. You can also refer to each byte as You 're probably wondering what the values that are POKEd into the color
a register, so your Commodore 64 has 65536 registers. registers mean . These values are the color information codes for the 16
Each byte inside your computer is used for a specific purpose. For colors available on the Commodore 64. The following list contains all the
instance, you have 38911 bytes available to program in BASIC. Your Commo- Commodore 64 colors and the corresponding color codes :
dore 64 tells you this as soon as you turn on the computer and read the
0 Black 8 Orange
opening screen. You may ask , what are all the rest of the bytes used for?
1 White 9 Brown
They control the computer 's brain , known as the operating system. The oper-
2 Red 10 Light Red
ating system registers control all the features of your Commodore 64.
3 Cyan 11 Dark Gray
A portion of the operating system controls graphics and color. You can
4 Purple 12 Gray
select different colors by changing the contents of the Commodore 64 color
5 Green 13 Light Green
registers . There are three color registers which control the colors of the bor·
6 Blue 14 Light Blue
der, ihe background and the characters When you first turn on your Commo-
7 Yellow 15 Light Gray
dore 64 , the background color is dark blue and the character and border
colors are light blue. You can change the background , border and character Try the following program. It uses FOR .. . NEXT loops, which you learned
color registers with the BASIC POKE statement. in the last chapter.
The POKE command modifies the contents of the specified location and
5 PRINT "[J" : REM Use shifted CLR/HOME key to produce heart symbol
places the newly specified value 1n that location. The format of the POKE shown in parentheses
command is: 10 FORI=OT015
POKE memory location , value 15 POKE53280 , I
16 FORJ=lT0500 : NEXT
For example , type the following POKE command : 18 NEXT
POKE 53280 ,0 &m!E 19 POKE53280 , 0
20 FORI=OT015
Did you notice what happened? The border color changed from light blue 25 POKE53281 , I
to black. Location 53280 is the border color register. Location 53281 is the 26 FORJ=lT0500:NEXT
background color register and location 646 is the character color register. 28 NEXT
Now change the background color from dark blue to black with the following 29 POKE53281 , 0
command: 30 FORI=OT015
35 POKE646 , I
POKE 53281 ,0 !;!W&E1!i 36 PRINT " COLOR"
37 FORJ=lT0500 : NEXT
Now all you need to know is how to change the character color with a 38 NEXT
POKE command . You already learned the two other methods to change the 39 POKE646 , 14
character color in the last section, first with the CTRL key and second with 50 POKE53280 , 14 : POKE646 , 14 : POKE53281 , 6
78 79
This program changes the color code value of each of the color regi sters FIGURE 7-1. SCREEN MEMORY MAP
using a FOR .. . NEXT loop. Lines 10 through 18 POKE each color va lue from
COLUMN
o (black) to 15 (light gray) into the border color register and displays each 10 20 30 39
border color on the sc reen . Lines 20 through 28 POKE each colo r value into 1063
the background color register and display each background color on the ~
1024-
screen. Lines 30 through 38 POKE each color value into the character color 1064
register and display each character color on the screen. 1104
1144
Lines 16, 26 and 37 are FOR ... NE XT loops that slow down the program. 1184
They are empty FOR . .. NEXT loops that delay program execution so you 1224
1264
can notice the color changes on the sc reen . Try the program without the 1304 I
1344
delay loops and see how fast the Commodore 64 runs. Line 40 restores the 1384 I I '
original border, screen and character color registers . 1424 " I 10 ~
1464
1504
1544
r-++• I
~I
I
I
I :
I
I
80 81
You can POKE any of the values in Appendix D into any of the screen Location 1024 in screen memory corresponds to location 55296 in color
locations between 1024 and 2023 . Experiment with different characters and mem_ o ry. Location 1063 corresponds to location 55335 . Screen memory
try displaying messages on the screen by POKEing a series of screen codes location 2023 corresponds to color memory location 56295 Remember
into consecutive screen memory locations. You can create character each screen location has a one to one correspondence to a c.olor memor;
graphic images by POKEing different screen code graphic symbols in pat- location that controls its color.
terns .that form picture images. In the screen memory example you POKEd a 1 into location 1024 as fol-
lows:
• COLOR MEMORY POKE 1024, 1 ==ett'f9RW
Now that you have grasped the concept of screen memory, you need to This places the letter "A" in the HOME position on the screen. Now
know how to control the color of each character position on the screen . The change the color of the letter "A" in the HOME position with the following
Commodore 64 has a separate section of memory called COLOR MEMORY, POKE:
that controls the color of information on the screen . The Commodore 64 uses
POKE 55296, 1 a!
A&!!llE
1OOO bytes to store the color information for the 1OOO character positions on
the screen. Each screen memory location has a corresponding color mem- Did you notice the difference? The letter "A" in the HOME position
ory location assigned to it. Compare Figure 7-1 with Figure 7-2, to under- changed from light blue to white. At this point you may wonder what the " 1"
stand the correspondence between screen memory and color memory and means in POKE 55296, 1. This time the "1 " is not a screen code that repre-
the way screen and color information are stored sequentially. sents a character. Instead it is the color code for white. Refer to the Color
Registers section for the list of Commodore 64 colors and the corresponding
FIGURE 7-2. COLOR MEMORY MAP color codes.
Remember, if you want to POKE a character to the screen, you actually
COLUMN
10 20 30 39 need two POKEs. First. POKE a screen code into screen memory to display a
55335
character. Second, POKE a color code into color memory to display the color
~
of the character.
55296 - ~.W.-l-J.-l-ll-l-l-l-++-H+·l-+-+++t-+-H-++++-+-H-T-t-r-t-t-ttti
55336
55376 •ANIMATION
55416
55456
55496 Your Commodore 64 is capable of animating objects on the screen . The
55536
55576 idea behind computer animation is to display an image on the screen and
55616 simulate its motion through computer instructions.
55656
55696 10 ~ . Remember when you POKEd a character into screen memory and it was
55736 displayed on the screen? That's what you are going to do to animate a
55776
55816 graphic character. To animate a graphic character on the screen , POKE its
55856
55896 screen code into a screen memory location. Next, POKE the screen code for
55936 a blank (32) into the same screen location. Then POKE the graphic character
55976
56016 screen _code in_ to a screen location next to the original one. Repeat the pro-
56056 cess w1th _a series of adjacent screen memory locations. Since the computer
56096 20
56136 is d1splay1ng and blanking out. the graphic character in successive screen
56176
56216 locations _so quickly, the image appears to be moving. For example, type in
56256 24 the following program and RUN it.
t
56295
82 83
• Line 35 POKES color code 7 (yellow} into the color memory location
10 PRINT"C " corresponding to the screen location that is POKED with the ball charac-
20 FOR 1=1024 TO 2023 STEP41 ter. Remember, when you POKE a screen code value in to screen mem-
30 POKEI,81 ory, you also have to POKE a color code value into the corresponding
35 POKE54272+I,7 color memory location . See Figure 7-1 and 7-2 to understand how each
40 FOR J=lT045:NEXT screen memory location corresponds to its own color memory location.
45 .POKE I, 32 • In line 35 , location 54272 + I is the beginning of color memory during
50 NEXT the first cycle of the loop (54727 + 1024 = 55296). The loop incre-
ments the color memory location the same way as screen memory. The
100 FOR I=2009T01450 STEP-39 second cycle of the loop inc rements the index variable I, so the POKE
110 POKEI,81 statement in line 35 POKEs the color code value into location 55337
120 POKE54272+I,7 (55296 + 41 ). Colar location 55337 corresponds to screen location
130 FOR J=lT045 :NEXT 1065. As you can see , the loop takes care of POKEing the screen loca-
140 POKEI,32 tion and corresponding color location so that the ball is always displayed
150 NEXT correctly in yellow.
160 GOT020 • Line 40 is an empty FOR ... NEXT loop. It acts as a lime delay to slow
down the program so the animation appears smooth. Try the program
without line 40. You 'll notice the program becomes choppy.
• Line 45 POKEs sc reen code value 32, the blank character, into the same
screen location that was POKEd with screen code 81 in line 30. Th is
turn s off the ball character. The ball character is turned on and off so
This is your first taste of animation . You have just made a yellow ball
quickly, it looks as though the ball is always on the screen .
bounce on the screen. Although the bouncing ball program is a simple exam-
• Line 50 is a NEXT sta tement. It updates the index variable I. The loop
ple of animation, you are now on your way to programming sophisticated ,
then cycles until the index variable equals 2023. At that point the pro-
animated graphics.
gram executes loop 2.
Here 's an explanation of the program:
• Loop 2 bounces the ball upward and off the right side of the screen .
Loops 1 and 2 both have the same statements , except different sc reen
memory locations are decremented in line 100 instead of incremented
• Line 10 clears the screen. Loop 1, lines 10 through 50, displays and as in line 20. The GOTO statement in line 60 tells the com puter to go
moves the ball from the top of the screen to the bottom . Line 20 begins a back to line 20 and execute everything again . The GOTO statement gives
loop at the start of screen memory. Notice the FOR ... NEXT statement you a way to RUN your programs continuously. Stop the program by
has the words STEP 41. This tells the computer to increment the index pressing the RUN /STOP key.
variable I, by 41 locations at a time, starting at location 1024 and ending
at location 2023. When STEP is not specified in a FOR . .. NEXT loop, Here 's another animation program that bounces the yellow ball off all four
your computer cycles through each index variable one at a time. " walls " of the screen . This program is based on program three , but it has five
• Line 30 POKEs screen code value 81 into the screen location according loops instead of three . Each of the five loops is just like the two loops in the
to the index variable I. The value 81 represents the screen code for the preceding program , except that the last three loops use different screen
ball character that bounces on the screen. The first cycle of the loop locat ions to control the three additional bounces of the bal l.
POKEs screen code 81 into location 1024. The second cycle POKEs
screen code 81 into screen location 1065 (1024 + 41 ). The third cycle
POKEs screen code 81 into screen location 1106 (1065 + 41) and so on.
Each cycle through the loop skips 40 screen locations and POKEs the
ball 41 locations past the previous sc reen location.
85
84
10 PRINT" rl" • SPRITE GRAPHICS
20 FOR I=l024 TO 2023 STEP41
30 POKEI,81 SPRITE CONCEPTS
35 POKE54272+I,7
40 FOR J=lT045 : NEXT You 've learned how to control color with the CTRL key, with PRINT state-
45· POKEI,32 ments, and with character string codes . You now know how to PRINT alpha-
numeric and graphic characters on the screen within quotes, as character
50 NEXT strings, and by POKEing val11es directly into screen memory. Animating exist-
100 FOR I=2009T01450 STEP-39 ing character images, as described in the last section , has certain limita-
110 POKEI,81 tion£ . For true graphic animation , you need a way to create your own images,
120 POKE54272+I , 7 color those images and control their movement on the screen . That 's where
130 FOR J=lT045 : NEXT sprites come in.
140 POKEI,32 Sprites are programmable movable objects. They are animated , high reso-
150 NEXT 1ution images you can create into any shape. You can move these images
200 FOR I=l423T01044 STEP-41 anywhere on the screen and color them 1n 16 colors The Commodore 64 has
210 POKEI,81 a set of sprite registers that control the color, movement and shape of the
220 POKE54272+I , 7 sprite. Sprites on the C64 provide you with true an1mat1on and soph1st1cated
graphics capab1lit1es li ke no other home computer. You 'll soon amaze your-
230 FOR J=lT045 : NEXT
self once you program spri tes and control their movement on the screer.
240 POKEI,32 A special chip inside the Commodore 64 . called the VIC (Video lntuface
250 NEXT Controller (6566)) ch1P. controls graphics modes and sorites. Border and
300 FOR I=l050T01554 STEP38 screen color registers as well as the sprite registers are all part of the VIC
31 0 POKEI , 81 chip The VIC chip normally can control 8 spr ites at once Through advanced
320 POKE542 7 2+I,7 programming you can control more than eight sprites. The VIC chip can even
330 FOR J=lT045 : NEXT determine if a sprite has moved in front of or behind another sprite. The size
340 POKEI , 32 of each sprite can also be expanded both vertically and horizontally. You can
350 NEXT use sprites in any mode: standard character, mult1-color, standard and multi-
4 00 FOR I= l 544T02009 STEP42 color bit map and extended color modes. See the discussion of Graphics
Modes later in this section for more information.
410 POKEI , 8 1 Let's begin by examining the properties of characters first, and then relate
420 POKE54272+I ,7 them to sprites. A character on the screen 1s an 8 by 8 dot grid. Since there
430 FOR J=lT045 : NEXT are 40 columns by 25 lines on the screen . the entire screen has 320 (40 x 8
440 POKEI , 32 dots per character width) dots across times 200 (25 lines x 8 dots per charac-
450 NEXT ter height) tall , which equals 64.000 total dots.
490 GOTOlOO Each character pattern requires 8 bytes of storage in character memory.
Each of the eight rows of dots in the 8 by 8 character grid require a byte of
memory storage. In other words. each screen dot requires a bit of memory,
so an 8 by 8 dot grid consists of 64 square dots and requires 64 bits (8 bytes)
of memory.
Now that you can animate a simple graphic character, it's time to learn a Each dot on the screen is ca lled a pixel. Pixel is a computer term for
much more sophisticated method called sprite animation. picture element. A sprite is made up of a 24 by 21 pixel grid, compared to a
86 87
character which is an 8 by 8 pixel grid. The width of a sprite is 24 pixels. FIGURE 7-3. SPRITE GRID
which is equal to the width of three screen characters (bytes). Since a sprite
is 21 rows of three bytes wide, a sprite requires 63 bytes (21 rows x 3 bytes SPRITE GRID
per row) of storage. Figure 7-3 illustrates the layout and storage require-
ments of a sprite.
24 BITS<DOTS)IU=3 BVTES PER ROW
DESIGNING A SPRITE IMAGE
The first step in programming a sprite is designing the sprite image. For a
1------------------------1
beginner, the best way to design a sprite is on a piece of graph paper. Draw a
box 24 blocks across by 21 blocks tall , just like Figure 7-3. The box you have
ROW
1 ........ . I • •••••••
I• • • • • • • •
just drawn is 504 (21 x 24) square blocks. Each block represents a bit in
memory. If you divide 504 by 8 bits per byte, you 'll see that the sprite uses up
2
3
4
........
•••••••• ••••••••• I. • • • • • • •
........ II •• •• •• •• •• ••.••• I •••••
l •••••••• I • • • • • • • •
I• • • • • • • •
63 bytes of memory.
You can now start designing your sprite image. Keep in mind that each 5 a a a a a I a e I • '
I • ••••••
block within the box you have drawn represents one bit in the Commodore
64's memory. As you probably know by now, a bit can take on one of two
6
7 ........
•••••••• I • ••
I • •••. • • •
I ••••
I• • • • • • • •
I
I • • • • • • • • '........
values , zero or one. That is why a bit is called a binary digit , since the root 8 •••••••• I I •••••••I. • • • • . • •
"bi" means two. A zero (0) means that a bit is " off " and a one (1) means that 9 I I a a a a a a
••••••••
I a a a a
image. That is, if you want to turn on a dot in the sprite image, you must turn •••••••• I ••••••• I a a a a I a a I
1:5
on a corresponding bit in memory where the sprite DATA is stored.
Refer to Figure 7-4 as an example of designing a sprite on a piece of graph
paper. Remember, the darkened blocks are " on " bits and the blank blocks
16
17
• • • • • • • • I •• I
• • • • • • • • I • •• • • • • •
•••••
........
••••••••
........
are " off " bits. The sprite image in Figure 7-4 represents a smiling face. Use
the blank spri te-making grid in Figure 7-5 to create your own sprite images.
18
19
• • • •• ••• I• • • • • • • •
• • • • • •• • I• • • • • • • . ........
CONVERTING YOUR SPRITE IMAGE INTO DATA
20
21
........
• • • • • • • • I• • • • • • • •
I. • .. • • . •
• • • • • • • • I• • • • • • • •
••••••••
••••••••
••••••••
The next step in programming a sprite is coding the sprite image into data
the computer can understand. On your sheet of graph paper. label the top of
eac h column the same as in Figure 7-6. 24 BITS<DOTS) X 21 BITS<DOTS) = 504 DOTS
Label the first eight columns as follows: 128, 64, 32, 16, 8, 4, 2, 1. Label 504 BITS/8 BITS PER BYTE = 63 BYTES
the second and third set of eight columns the same way.
You now have three sub-sets (bytes) of eight columns (bits) per row, each OR
labeled from 128 on the left to 1 on the right. Each 8 column sub-set repre-
sents 8 pixels that correspond to a byte of memory. Again , since there are 21 21 ROWS X 3 BYTES PER ROW = 63 BYTES
rows wi th three bytes each, the total amount of memory the sprite requires is
63 bytes. <DIAGRAM 6-3)
88 89
FIGURE 7·5. SPRITE-MAKING GRID
FIGURE 7·4. SPRITE-MAKING GRID
91
90
FIGURE 7-6. SPRITE-MAKING GRID. FIGURE 7·7. SPRITE-MAKING GRID
92 93
You may have noticed the POKE value for each sprite is equal to two,
In the program shown in Figure 7-7 , the DATA values in line 100 corres- raised to the sprite number. For example , the POKE value for sprite seven is
pond to the three sub-sets of the first row of the sprite grid. All three pieces two raised to the seventh power, which equals 128. Figure 7-8 illustrates this
of DATA equal zero since all three sub-sets of the first row of the sprite grid concept.
are blank (off). Line 11 O corresponds to the second row of the sprite grid.
The first DATA value in line 11 O equals zero, because again , no pixels are FIGURE 7·8. SPRITE POKE VALUES
turned on in that sub-set. The second piece of DATA in line 110 equals 126,
since the squares in the column positions labeled 64, 32, 16, 8, 4 and 2 in the
middle sub-set are all turned on .
Again the third DATA value in line 110 is zero because none of the pixels in
Decimal values of each
that 8 column sub-set is turned on. The DATA in line 120 represents the pixel $prite number
values for the third row of the sprite grid, line 130 represents the values in the
128 64 32 16 8 4 2 l ___/ Sprite level Number
fourth row of the sprite grid, and so on . Line 300 corresponds to the last row
of the sprite grid.
7- 6 5 4 3 2 0
Now that you know how to design a sprite on a sheet of graph paper and
code it into DATA that the Commodore 64 can understand, you are almost 21 a I a I a a I a I I a I a I
-----==
=4
ready to write your first sprite program . But first let's examine the sprite
registers and how they work . Pu1 o 1 For The SPRITE You Wont
CONTROLLING SPRITES
Special memory locations within the video chip . known as sprite registers ,
are set aside to control sprites. Each sprite register is assigned a specific
task . The first register you need to set is the sprite enable register at location The POKE command to turn on sprite 7 is:
53269. As the name implies, the sprite enable register turns on a sprite. You
must POKE a value into the sprite enable register, depending on which POKE 53269, 128
sprite(s) you want to turn on. Here 's a list of the POKE values that enable
each sprite: If you want to enable more than one sprite, add the POKE values of the
sprites you want to turn on, and POKE the sum into the sprite enable register.
Sprite No. POKE Value
Now you have to store the sprite DATA somewhere in the Commodore 64 's
0 1
memory. Although you already converted your sprite picture into DATA as in
1 2
lines 100 through 300 in Figure 7-7 , you still have to READ that DATA and
2 4
POKE it into memory. Before you can do that, you must tell the C64 where to
3 8
store the DATA.
4 16
You point out where the DATA is stored using a sprite pointer. Each of the
5 32
eight sprites has its own pointer. The following is a list of the sprite pointer
6 64
memory locations:
7 128
95
94
Sprite No. Memory Location
0 2040 Sprite No. Memory Location
1 2041 0 53287
2 2042 1 53288
3 2043 2 53289
4 2044 3 53290
5 2045 4 53291
6 2046 5 53292
7 2047 6 53293
7 53294
Now that you know what location to POKE for each sprite pointer, you
need to know the value to POKE into these locations. Here 's the formula: To assign a sprite color, POKE a sprite color register with a color code
between 0 and 15. For example, if you enter:
1. Choose an available memory location that is not being used. For this
example , choose location 12288. POKE 53294,7 &HIE
2. Divide the chosen location by 64: 12288/64 192 = sprite seven is colored yellow. (For a list of color codes, see the Color Regis-
3. POKE the sprite pointer of the sprite you previously enabled with the ter discussion given earlier in this section.)
quotient from step 2. To continue our previous example, the following
POKE command uses the seventh sprite pointer to point to sprite DATA ANIMATING YOUR SPRITES
starting at location 12288:
POKE2047, 192&E1IE Animation is the last step before your program can RUN. The key behind
To determine other locations to store sprite DATA, consult The Commo- animation is motion. Each of the eight sprites has two registers that control
dore 64 Programmers Reference Guide. movement on the screen . One register is the sprite X position, which controls
the horizontal sprite movement. The other is the sprite Y position, which
As mentioned before, the sprite DATA must be READ and then POKEd into controls the sprite's vertical movement. The following is a list of the sprite X
memory once the sprite pointers tell the Commodore 64 where to store the and Y position registers for each sprite:
DATA. The sprite pointer was set with the previous POKE command . Now you
can READ the sprite DATA you converted from your sprite image and POKE it Sprite No. Memory Location
into memory starting at location 12288. POKEing the DATA into memory 0-Xpos 53248
actually creates the sprite. The following program segment READs the DATA 0-Ypos 53249
and POKES it into memory starting at location 12288. 1 -X pos 53250
1 - Y pos 53251
50 FOR N =
0 to 62 2-X pos 53252
60 READ 0 2-Ypos 53253
70 POKE 12288 + N ,Q 3-X pos 53254
80 NEXT 3-Ypos 53255
So far you have enabled the sprite, set the sprite pointer to tell the Com- 4-X pos 53256
modore 64 where to store the sprite DATA and POKEd the sprite into mem- 4-Ypos 53257
ory. All you need to do now is to assign a sprite color and control the sprite 's 5-Xpos 53258
movement on the screen , and your sprite program will be finished. 5-Ypos 53259
Each sprite has its own sprite color register. The following is a list of sprite 6-X pos 53260
color register locations: 6-Ypos 53261
7-X pos 53262
7-Y pos 53263
96
97
The easiest way to control the vertical and horizontal coordinate values is POKE 53264 ,0 i"l!il!IE
within a FOR . .. NEXT loop. Set up a loop and POKE the index variable from Not all of the horizontal (X) and vertical (Y) positions are visible on the
the loop into the vertical and horizontal sprite position registers. For exa m- screen . Only vertical positions 50 through 249 and horizontal positions 24
ple, to move sprite 7 diagonally on the screen , use the following program through 342 are visible . In the example, when you moved sprite 7 "on the
segment: screen, you started the sprite moving at horizontal location zero and vertical
85 ·FOR Z =0 TO 200: REM Set up loop; index variable =
z position zero. Location 0,0 is off the screen as is any horizontal location less
90 POKE 53262 ,Z : REM Poke sprite 7 x pos . with index variable z than 24 and greater than 343. Any vertical location less than 50 and greater
95 POKE-53263,Z : REM Poke sprite 7 y pos. with index variable z than 249 is also off the screen . The Commodore 64 OFF-SCREEN locations
98 NEXT : REM Update index variable position are set aside so that an animated image can move smoothly onto and off of
the screen . Study Figure 7-9 to understand the layout of the visible horizontal
Notice that the FOR ... NEXT loop moves sprite 7 the ma ximum number and vertical sprite positions.
of vertical values (200), but only moves horizontally 200 out of the 320 possi-
ble positions. That was done to keep the example program simple. FIGURE 7·9. VISIBLE SPRITE POSITIONS
The sprite Y position register can store any of the 200 possible verti cal
position values . The sprite X position register cannot store all of the 320
horizontal position values because the sprite position register, like all other
memory locations in the Commodore 64 , can only represent a value up to
255. 0 IS~) 24 {$18)
I
2 9 6 (5128) 34 4 ($1581
I I I I
How do you position a sprite past the 255th horizontal screen position? I I
I
1
I I - - - - - - 8 (108)
The answer is, you have to borrow a bit from another register in order to 1
29 tStDJ---t--
represent a va lue greater than 255. 1
50 (532) - - -
An extra bit is already set aside in the Commodore 64 's memory in case . - 5 0 ($32)
you want to move a sprite past the 255th horizontal locat ion. Location 53264
controls sprite movement past position 255 . Each of the 8 bi ts in 53264 con- VISIBLE VIEWING AREA
trols a sprite. Bit 0 controls spri te 0, bit 1 controls sprite 1 and so on . For
example , if bit 7 is on, sprite 7 can move past the 255th horizontal position.
Each lime you want a sprite to move across the entire screen , turn on the
borrowed bit in location 53264 when the sprite reaches horizontal position NTSC"
255. Once the sprite moves off the right edge of the screen , turn off the 40 COLUMNS
2 08 ($00)- 25 ROWS
bo rrowed bit so the sprite can move back onto the left edge of the screen .
- - - 229 !SES)
The fol lowing POKE command allows sprite seven to move past the 255th 250 (SFA)-
-- - 250 (SFA)
horizontal position : 1
I
I
POKE 53264 , 128 E I
I I
I
I I
The number 128 is the resulting value from turning on bit 7. You arrive at 488 (S1E8) 2 4 ($18) 320 ($140) 3 4 4 {$1 581
this value by raising two to the seventh power. If you want to enable bit 5,
raise two to the fifth power, which of course equals 32. The general rule is to 'No rin Am erican tel ev1 s1on ua,,sm1ss1on stane1 a1o s 10 1 you1 nome TV
ra ise two to the power of the sprite number that you want to move past the
255th horizontal screen position . Now you can borrow the extra bit you need
to move a sprite all the way across the screen . To allow the sprite to reappear
on the lef t side of the screen , turn off bit seven again , as fol lows :
98 99
....
The following program combines all the concepts, statements and pro- 55 POKE 53271 ,128
gram segments covered so far in this section. Type in the program , and press 57 POKE 53277, 128
•ma~ after each line. Once you 've typed in the complete program, type Notice that the sprite now appears twice its original size. Location 53277
RUN and press . You'll see a smiling face moving diagonally controls horizontal expansion and location 53271 controls vertical expansion
across the screen. of the sprite. The value POKEd into these locations is calculated according to
10 PRINT"r;'" which sprite you want to expand. The general rule is raise two to the power of
20 POKE53269,128 the sprite number. For example, to expand sprite 7, the value 128 in lines 55
and 57 is calculated as two raised to the seventh power, or 128.
30 POKE2047,192
You have successfully written your first sprite program . Use this program
50 FORN=OT062 as a basis and try adding other sprites to it. Notice lines 100 through 300 only
60 READ Q contain three pieces of DATA each. The program is written this way to illus-
70 POKE12288+N,Q trate the correspondence between each DATA item and each eight column
80 NEXT byte in Figure 7-7. When you become more familiar with sprite concepts you
85 FOR Z=lT0200 can shorten the program by including more DATA items in each DATA state-
90 POKE53262,Z ment. Lines 100 through 300 are still stored as 80 character lines. The
95 POKE53263,Z spaces are stored in memory just as visible characters , but they use memory
98 NEXT needlessly. The process of shortening programs is called crunching. Later,
100 DATA 0,0,0 when you become a more advanced programmer, you will realize the value
of crunching your programs and using the Commodore 64 's memory more
110 DATA 0,126,0
efficiently.
120 DATA 1,129,128
130 DATA 2,0,64 Change line 20 of the program as follows:
140 DATA 12,0,48 20 POKE 53269,224 : REM Enable sprites 7, 6 and 5
150 DATA 8,0,16 Add the following lines to the program and RUN it again. The REM state-
160 DATA 19,197,200 ments are optional. You don't have to type them in. They document the pro-
170 DATA 16,0,8 gram so you can follow each program step.
180 DATA 32,195,4
101
100
15 POKE 53280, 1 : REM Change the border color to white
modes. Character display modes, as the name implies, display an entire 8 x 8
17 POKE 53281, 1 : REM Change the background color to white
dot character grid at a time. In character display modes, the smallest unit of
35 POKE 2046, 192 : REM Set sprite 6 data pointer to 12288
information you can display is an 8 x 8 pixel grid which equals one character.
37 POKE 2045, 192 : REM Set sprite 5 data pointer to 12288
Bit map modes allow you to display each pixel, one at a time . Bit map mode
43 POKE 53293,6: REM Coler sprite 6 blue (6)
gives you absolute control over the screen image. Graphics performed in bit
45 POKE 53292 ,2: REM Coler sprite 5 red (2)
map mode are referred to as high resolution graphics.
92 POKE 53260,Z : REM Set sprite 6 horizontal (X) position
Both groups of graphics modes can be divided into separate subdivisions.
94 POKE 53258,100 : REM Set sprite 5 horizontal (X) position
Character display modes are separated into these three subdivisions:
96 POKE 53261 ,100: REM Set sprite 6 vertical (Y) position
97 POKE 53259,Z: REM Set sprite 5 vertical (Y) position 1. Standard Character Mode
99 GOTO 85 : REM Put the program into a continuous loop 2. Multi-Coler Character Mode
3. Extended Background Color Mode
Two more sprites appear on the screen, one from the left side of the
screen and one from the top. Notice in the program , both sprites 5 and 6 use Bit map modes are separated into these two subdivisions:
the same sprite DATA as sprite 7. That 's why all three sprites look the same.
1. Standard Bit Map Mode
If you want to change the way a sprite looks, design another sprite image on
2. Multi-Color Bit Map Mode
a piece of graph paper just as you did before . Then add another complete set
of sprite DATA as in lines 100 through 300. In addition , READ the DATA and Each of the character display modes get character information from one
POKE it into a section of memory other than locations 12288 through 12351, of two places in the Commodore 64 's memory. Normally, character informa-
since the other sprite DATA is already there . Finally, set the sprite DATA tion is taken from character memory stored in a separate chip called a ROM
pointer to the starting location where the sprite DATA is POKEd into memory. (Read Only MemOfy). However, the Commodore 64 gives you the option of
All three sprites in the above program store their DATA starting at location designing your own characters and replacing the original Commodore 64
12288. That's why lines 30 , 35 and 37 POKE the same value into each of the characters with your own . Your own programmable characters are stored in
three respective sprite DATA pointers . If all eight sprites were enabled , each a portion of the 64K of RAM (Random Access Memory) available to you in the
one could use the same DATA and you would have eight identical sprites on C64 .
the screen. The Commodore 64 normally operates in standard character mode. When
Lines 43 and 45 color sprite 6 blue and sprite 5 red . Lines 92 through 97 you first turn on the Commodore 64, you are automatically in standard char-
control the movement of sprites 5 and 6. Line 99 puts the program into a acter mode. When you write programs , the C64 is also in standard character
continuous loop. If you want to stop it, press the RUN/STOP key. Notice the mode. Standard character mode displays characters in one of 16 colors on a
sprite remains on the screen. To clear the screen completely, hold down the background of o.ne of 16 colors . All the information contained in this chapter
RUN/STOP key and press the RESTORE key. operates in standard character mode except sprites. Sprites are classified
Up to now, you 've programmed three sprites on the screen. Try using all separarely from character display modes and bit map modes.
eight. In a relatively short time you should be able to create your own sprites Multi-color character mode gives you more control over color than the
in several colors and animate them on the screen. You can then move on to standard graphics modes. Each screen dot within an 8 x 8 character grid can
explore the very sophisticated color, graphics and animation features avail- have one of four colors , compared to the standard modes which can only
able on the C64 . Consult the Commodore 64 Programmer 's Reference Guide have one of two colors. Multi-color mode uses two additional background
for more information on color graphics, sprites and animation . color registers. The three background color registers and the character color
register together give you a choice of four colors for each dot within an 8 x 8
dot character grid.
• GRAPHICS MODES Multi-color mode has one disadvantage. Each screen dot in multi-color
The Commodore 64 can operate in five different graphics modes. They are mode is twice as wide as a dot in standard character mode and standard bit
divided into two groups known as character display modes and bit map map mode. As a result, multi-color mode has only half the horizontal resolu-
102
103
tion (160 x 200) of the standard graphics modes. However, the increased
control of color more than compensates for the loss in horizontal resolution .
Extended background color mode allows you to control the background
color and foreground color of each character. Extended background color
mode uses all four background color registers. In extended color mode, how-
ever, you can only use the first 64 characters of the screen code character
set. The second set of 64 characters is the same as the first , but they are
displayed in the color ·assigned to background color register 2. The same
holds true for the third set of 64 characters and background color register 3,
and the fourth set of 64 characters and background color register 4. The
character color is controlled by color memory. For example , in extended
color mode, you can display a purple character with a yellow background on
MUSIC AND SOUND
a black screen. This section introduces the Commodore 64's
Standard bit map mode allows you to control each screen dot in one of two versatile music and sound capabilities
colors. This gives you the ability to create detailed graphic images on the
screen . Bit mapping is a technique that stores a bit in memory for each dot
on the screen . If the bit in memory is turned off, the corresponding dot on the
screen becomes the color of the background. If the bit in memory is turned
on , the correspondi ng dot on the screen becomes the color of the foreground
image. The series of 64 ,000 dots on the screen and 64,000 corresponding
bits in memory control the image you see on the screen . Most of the finely
detailed computer graphics you see in demonstrations and video games are The SID Microprocessor _ _ _ _ _ _ _ __ _ __ _ 107
bit mapped high resolution graphics.
Multi-color bit map mode is a combination of standard bit map mode and Music 107
mul ti-color character mode. You can display each screen dot in one of four -Playing From Sheet Music 107
colors wi thin an 8 x 8 character grid . Again, as in multi-color character mode, - Obtain ing the Data 108
there is a tradeoff between the horizontal resolution and color control. -Writing the Program 110
Sound Effects 112
This section has described a variety of color and graphics techniques - Program Notes 114
based on advanced programming concepts . The full explanation of these
concepts is beyond the scope of this Guide. If you want more details on
graphics techniques and graphics programming, refer to the Commodore 64
Programmer's Reference Guide.
The next section completes your introduction to the Commodore 64 com-
puter by outlining the varied sound and music capabilities available to you
through the C64.
104 105
-
• THE SID MICROPROCESSOR
A special microprocessor in the C64 known as the SID (Sound Interface
Device) provides the C64 with extraordinary capabilities in generating musi-
cal tones and sound effects. This section introduces you to these capabili-
ties. For more details, see Appendix G of this book and consult the Program-
mer 's Reference Guide.
•MUSIC
The Commodore 64 is capable of producing musical tones over a large
range-a full nine octaves for up to three separate voices (musical instru-
ments) simultaneously. You can teach your C64 to play anything from Happy
Birthday to Beethoven 's Fifth Symphony.
By controlling a series of internal registers in the SID , you can program
your C64 to play a variety of complex musical sounds. These sounds or notes
have the qualities of a particular musical instrument and vary in pitch and
duration .
In a musical score sheet you will find notes indicated by position and
appearance. Compare these with Figure 8-1 for the note name and Figure
8-2 for note duration.
la:
I~
G A B c D E F 0 A B
...c D E F G A B c D E F
107
FIGURE 8·2. NOTE DURATION
,_CHORUS,
I JJ j) j
Hang down your head, Tom Doo - ley,
~= QUARTER Note d = DOTTED HALF Note Hang down your head and
Arn c
cry. - - -
07
1;• J1 J J1 j j I rJ ,J
Hang down your head, Tom Doo-ley,
c G
To create these notes through the speakers of your monitor or TV, you
must turn ON several registers in the SID microprocessor. There are seven
1@~ J1 J D j jl J. ~ II
registers for each of three voices. Each must be filled with a particular value. Poor boy, you're bound to die.
See Table 8-1 for the values of registers 2 through 6. Registers 0 and 1 are for
sound frequency and are adjusted later in the program .
To insert a musical score into your computer, follow each step in this Eighth note = 250
example, which incorporates the music of the song "Tom Dooley" : Quarter note =500
Half note = 1OOO
Whole note =
2000
A note with a dot =DR * 1.5
108 109
80 POKES+ 1,N1 :POKE S,N2
Tabulated Data
N2 DR 5. Activate the sound with register 4, using the value for the proper
Note Value N1
18 104 250 instrument (65 for piano):
D 1/8
D 1/4 18 104 500 90 POKES+ 4,65
D 1/8 18 104 250
1/4 20 169 500 6. Keep the sound on for the required time based on the value of DR in
E
1/4 24 146 500 your table. Since this value is a variable , it is represented by its varia-
G
1/2 30 245 1000 ble name, DR:
B
B 1/2 30 245 1000 100 FOR Z = 1 to DR: NEXT Z
etc .
7. Turn off the sound, using the proper value:
4. Write the program .
110 POKES +4,64
NOTE: Registers 2, 3, 4, 5 and 6 are set based on the musical 8. Keep the sound off for a very short time-about a tenth of a second.
instrument. Registers 0 and 1 are based upon each note and will
vary. There is a register 24 . It is the volume for all instruments and 120 FORT= 1to50: NEXTT
is always set to 15. The volume from your speaker is controlled by 9. Continue steps 4 through 8 with successive notes by using a READ
the monitor's volume control. statement and a loop.
111
110
20 POKES+ 24 ,15 Sound Effects Register Values
30 POKES+ 2,255 Registers 0 1 2 3 4-0N4-0FF 5 6 * 24
40 POKE S + 3,0 Variable
50 POKE S + 5,9 Names N2 N1 P2 P1 W1 W2 AD SR DR v
60 POKES+ 6,0
Sound effects:
70 READ N1 ,N2,DR
75 IF N1 =OTHEN END Police Siren 85 36 0 0 33 32 136 129 350 15
80 POKES+ 1,N1 :POKE S,N2 Crash 251 5 0 0 129 128 129 65 50 0
90 POKES+ 4,65 Rocket Blast-
100 FOR Z = 1 TO DR :NEXT Z off 100 25 0 0 129 128 9 129 50 0
110 POKES+ 4,64 Machine Gun 75 34 0 0 129 128 8 1 50 15
120 FORT= 1 TO 50:NEXT T Wailing N2 40 0 0 65 64 15 0 15
125 GOTO 70 Shooting 200 40 0 0 129 128 15 15 0
130 DATA 18,104,250, 18, 104,500,18,104,250,20.169,500,24 ,146,500 *Not a register. Part of the timing loop.
140 DATA 30,245, 1000,30,245,1OOO
150 DATA 18, 104,250 ,18, 104,500 ,18,104,250 ,20 .169,500 ,24 ,146,500 The following program, called "Sound Effects " , incorporates all these var-
160 DATA27,148,2000 iables and can produce each of these sounds . The technique is identical to
170 DATA 18,104,250, 18, 104 ,500.18,104,250,20,169,500,24,146,500 creating music, except generally only one note is needed; hence there are no
180 DATA 27, 148,1000,27 ,148, 1000 data statements. For details, see the Programmer's Reference Guide.
190 DATA 27 ,148,250,27 , 148,500,30,245,250 ,24 ,146,500,
20 ,169,500,24,146,1500
200 DATA 0,0,0
10 CLR: REM** SOUND EFFECTS**
Be sure to raise the volume on your monitor when you run your program . 15 PRINT"WHICH SOUND EFFECT?" :PRINT " 1. WAILING " :PRINT "2.
To double the tempo, change line 100: SHOOTING " : PRINT "3. " ;
16 PRINT " SIREN " :PRINT"4. ROCKET" :PRINT"5. CRASH ": PRINT" 6.
100 FORT= 1 TO DR/2: NEXT T MACHINE GUN"
To play a different song , change DATA statements to the appropr iate 17 INPUT x
values. 20 S = 54272:FOR SW= S TO S + 24:POKESW,O:NEXT:
Now that you have created your first song , experiment with other instru- K= -1 :T1$= "000000"
ments by varying the register values . You can also combine several voices to 21 ON x GOTO 23,24,25,26,27,28
represent chords or other instruments by adding 7 or 14 to each of the regi s- 23 V = 15:N1 = W1 = 65:W2 = 64:AD = 15:SR = O:DR = 1:P1 = 9:P2 = 255:0 = 1:
ter numbers (except register 24). Thus, registers 7 through 13 can control the GOT030:REM WAILING
second voice, and registers 14 through 20 the third voice . 24 N2 = 200:N1 = 40:W1 = 129:W2 = 128:AD = 15:SR = 15:DR = 1;GOT030:REM
SHOOTING
• SOUND EFFECTS =
25 N2 = 85:N1=36:W1=33:W2 32:AD = 136:SR = 129:DR = 350:V= 15:0 = 2:
GOT030:REM SIREN
Besides music , you can also create special sound effects by using the 26N2=100:N1=25:W1=129:W2=128:AD =9:SR = 129:DR = 50:K =
noise registers and varying the sound characteristics known as ADSR 25:GOT030:REM ROCKET
(Attack, Decay, Sustain and Release). These are combined in registers 5 and 27 N2 = 251 :N1=5:W1=129:W2=128:AD = 129:SR = 65:DR = 50:
6. A thorough explanation is provided in the Programmer 's Reference Guide. GOT030:REM CRASH
Below are register values for sample sound effects. 28 N2 =75:N1=34:W1=129:W2=128:AD =8:SR = 1:DR= 50:V= 15:REM
112 113
MACHINE GUN
30 POKES + 2, P2:POKE S + 3. P1 :REM PULSE
40 POKES + 5,AD :POKE S + 6,SR:REM ADSR
50 POKES + 1,N1 :POKE S,N2·REM NOTE
55 IF O= 2 THEN O = 3
56 WO= 2 THEN POKES+ 1,64:POKE S,188
60 POKES+ 4,W1 :REM ON SWITCH
63 IF 0< > 1 GOT070
65 FOR N2 = 200T05 STEP-1:POKE S,N2: NEXTN 2
68 FOR N2 = 150T05 STEP-1:POKE S,N2:NEXTN 2
70 FOR VL = 15 TO V STEP K:POKE S + 24 ,VL:REM VOLUME
APPENDICES
80FORT = 1 TO DR:NEXTT:REM DURATION
90 NEXT VL
100 POKES+ 4,W2: REM SOUND OFF
110 IF TI$>= " 000005 " THEN 10
115 IFQ = 3THENQ = 2:GOT056
120 GOT050
READY.
PROGRAM NOTES
A. Help 117
The Sound Effects program contains six sound effects the user can pick -Error Messages 117
from . Lines 10 through 21 clear all the variables and request a selection . The -Troubleshooting Chart 120
variable K in line 20 is necessary for the rocket sound. TI$ sets the built-in
B. Peripherals and Software 123
timer to zero. Lines 23 through 28 establish the values of the regist er varia-
bles for each sound. Lines 30 through 50 enter these values into the proper
-Commodore Connections for Peripherals 123
registers . The variable Q in lines 55, 56 and 115 restricts those lines to the
-Commodore Software 128
siren . The variable Q in line 63 restricts lines 65 and 68 for wailing only. Line C. Screen and Colar Memory Maps 136
70 allows for a variable volume; where none was required , V was set to 15. D. Screen Display Codes 138
Line 80 allows for a variable note duration; when not required , the variable
E. ASCII And CH R$ Codes 141
DR was set to 1. Lines 60 and 100 are the main registers. Line 11 O cuts off
the sound after five seconds. You can then select another effect. F. Sprite Register Map 144
G. Music Note Table 147
H. Sound Control Settings 149
Although by now you have experienced first hand the versatility and power
I. Derived Trigonometric Functions 151
of the Commodore 64 computer. you probably realize that you have only
begun to tap the potential of this extraordinary computer. The appendices to J. Abbreviations of BASIC Keywords 152
this Guide suggest many additional sources of information that you can use K. BASIC Conversions 155
to further explore the fascinating world of computing with the C64 . L. Recommended Reading List 157
114 115
APPENDIX A
•HELP
To help you with questions or problems about Commodore hardware, software or ser-
vices, this appendix provides several sources of information .
•ERROR MESSAGES
MESSAGE What the Problem Is What to Do
BAD DATA String da ta was received from Make sure data was saved with
an open file , but the program a separator between each .
was expecting numeric data.
BAD The program was t rying to ref- Verify you have dimensioned
SUBSCRIPT erence an element of an array the array properly. In direct
whose number is outside the mode, have the C64 print the
range specified in the DIM value of the subscript as a
statement. clue.
BREAK Program execution was Use the CONT command
stopped because you hit the to proceed or reRUN the
STOP key. program.
CAN 'T The CONT command will not You probably made a correc-
CONTINUE work , either because the pro- tion : reRUN the program.
gram was never RUN , there
has been an error, or a line has
been edited .
DEVICE NOT The required I/O device not Verify the peripheral you are
PRESENT available for an OPEN , CLOSE, calling for is on and proper
CMD , PRINT# , INPUT# , or OPEN statement 1s used .
GET# .
DIVISION BY Division by zero is a mathemat- Command the C64 to print the
ZERO ical oddity and not allowed. suspect variables to determine
which one became a zero.
EXTRA Too many items of data were Check your punctuation .
IGNORED typed in response to an INPUT
statement. Only the first few
items were accepted .
FILE NOT No file with that name exists. Verify you have the correct
FOUND tape or disk and you spelled
Jhe name correctly ; note espe-
cially spacing and upper-case
characters .
117
MESSAGE What the Problem Is What to Do MESSAGE What the Problem Is What to Do
FILE NOT OPEN The file specified in a CLOSE, Open file . Verify you used OUT OF DATA A READ statement was exe- Verify data was not missed;
CMD , PRINT# , INPUT#, or proper file number. cuted but there is no data left add more data if necessary
GET#, must first be OPENed. unREAD in a DATA statement.
FILE OPEN An attempt was made to open Close file first or use new file OUT OF There is no more RAM avail- Reduce the quantity of
a file using the number of an number MEMORY able for program or variables. GOSUBs and FOR NEXT loops
already open file . This may a:.:;o occur when too operating at once. Reuse loop
Use smaller strings. Reduce many FOR loops have been variables where possible to
FORMULA TOO The string expression being
the number of parentheses. nested, or when there are too prevent too many unfinished
COMPLEX evaluated should be split into
at least two parts for the sys- many GOSUBs in effect. loops. Clean up the memory
using FRE(X) function.
tern to work with, or a formula
has too many parentheses. OVERFLOW The result of a computation is Check your computation steps.
ILLEGAL DEVICE Occurs when you try to access Use correct device number. larger than the largest number
allowed, which is
NUMBER a device illegally (e.g .. LOAD-
ING from keyboard , screen or 1.70141884E + 38.
RS-232C). REDIM'D ARRAY An array may only be DI Men- If the array was identified early
sioned once. If an array varia- it was automatically dimen-
ILLEGAL The INPUT statement can only Use another command.
ble is used before that array is sioned to 10. Locate the DIM
DIRECT be used within a program, and
not in direct mode. DIM 'd, an automatic DIM oper- statement before using the
ation is performed on that variable.
ILLEGAL A number used as the argu- Use direct mode to determine array setting the number of
QUANTITY ment of a function or state- the value of the variables at the elements to ten, and any sub-
ment is out of the allowable moment. Correct negative sub- sequent DI Ms will cause this
range . scripts. Verify dimensions are error.
large enough .
REDO FROM Character data was typed in Provide the proper INPUT
LOAD There is a problem with the Reload. START during an INPUT statement response .
program on disk. when numeric data was
MISSING FILE LOADS and SAVES from the Key in the file name. expected. Just re-type the
NAME serial port (e.g .. the disk) entry so that it is correct , and
require a file name to be sup- the program wil l continue by
plied. itself.
NEXT WITHOUT This is caused by either incor- Verify the loop has a starting RETURN A return statement was Verify the program ends before
FOR rectly nesting loops or having a and ending point. Do not jump WITHOUT encountered , and no GOSUB coming to subroutines tagged
variable name 1n a NEXT state- into the middle of a loop. GOSUB command has been issued. at program 's end.
ment that doesn't correspond STRING TOO A string can contain up to 255 Keep strings to 255 characters
with one in a FOR statement. LONG characters. and any single INPUT to 80
NOT INPUT An attempt was made to Correct the OPEN statement 's characters.
FILE INPUT or GET data from a file secondary address. ?SYNTAX A statement is unrecognizable Look for spelling or grammar
which specified to be for out- ERROR by the Commodore 64 . A miss- errors or words not in the
put only ing or extra parenthesis, m1s- BASIC vocabulary.
NOT OUTPUT An at tempt was made to Correct lhe OPEN statement 's spelled keywords, etc.
FILE PRINT data to a file which was secondary address. TYPE MIS- This error occurs when a num- Verily$ signs were typed
spec1f1ed as input only. MATCH ber is used in place of a string, where they belong .
or vice-versa .
118 119
Symptom Cause Remedy
MESSAGE What the Problem Is What to Do
UNDEF'D A user defined function was Define the function with DEF No Picture TV on wrong channel Check other channel
FUNCTION referenced , but 1t has never within the program . for picture (3 or 4)
been defined using the DEFFN
statement. Incorrect hookup Computer hooks up
to VHF antenna
UNDEF'D An attempt was made to GOTO Make sure line numbers exist.
terminals
STATEMENT or GOSUB or RUN a line num-
ber that doesn 't exist.
Video cable no\ Check TV output
VERIFY The program on tape or disk Save the program again , under plugged in cable connection
does not match the program another name.
currently in memory. Computer set for Set computer for
wrong channel same channel as TV
NOTE: A common error is to type a 41-character line, not hit Ll 1 'P"'E (3or4)
and type a second line as if it were a new line . A l\IWS will then
Random pattern Cartridge not prop- Reinsert cartridge
treat bo th lines as one. To find this type of error, list your program
on TV with car- erly inserted after turning off
and continue hitting ffll + l\IW . Watch the cursor jump to the
!ridge in place power
beginning of each instruction line. A skipped line means it was
tagged onto the line above it. Retype these lines. Picture without Poorly tuned TV Retune TV
col or
121
120
Books
Many books have been published about the Commodore 64. For a sam-
APPENDIX B
pling see Appendix L.
• PERIPHERALS AND SOFTWARE
Magazines
Sub.scribe to " Commodore Microcomputers " and " Power/Play" for the
latest on Commodore hardware and software . For subscription information • COMMODORE CONNECTIONS FOR
call 800-345-8112 (In Pennsylvania call 800-662-2444). PERIPHERALS
User Groups
There are over 1,000 user groups (clubs) dedicated to helping Commodore
owners and sharing experiences. Find the address of the nearest user group
in the next issue of "Commodore Microcomputers " or " Power/Play." Or for
information on how to start a user group in your area write to: CONTROL CONTRO L
PORT 1 PORT 2
Commodore User Groups
1200 Wilson Drive
West Chester, Pa. 19380
Commodore Information Network
Use your AUTOMODEM or VICMODEM to communicate directly with Com-
GAME POWER POWER
modore or other C64 owners through CompuServe and use the Hotline or the PORTS SWITCH SOCKET
Special Interest Group Bulletin Boards. Information is provided with your
modem.
Customer Support Hotline
For assistance by telephone , call the customer support hotline:
or write to
II
Commodore Customer Support
1200 Wilson Drive CARTRIDGE CHANNEL TV AUDIO/VIDEO SERIAL CASSETTE USER
West Chester, Pa. 19380 SLOT SELECTOR CO NNECTOR CO NNECTOR PORT INTERFACE PORT
1. Power Socket-The free end of the cable from the power supply is
attached here.
122 123
2. Power Switch-Turns on power from the transformer.
3. Game Ports-There are two game ports, numbered 1 and 2. Each
game port can accept a joystick or game controller paddle. The light
pen can only be plugged into port 1. (Port 1 is the port closest to the
Cartridge Expansion Slot
front of the computer). Use the ports as instructed with the software.
Pin Type
Pin
- ~
12 BA 1 GND
Control Port 1 13 OMA 2 + 5V
Pin Type Note 14 07 3 + 5V
1 JO YAO 1 2 3 4 5 15 06 4 IRQ
2 JOYAi 0 0 0 0 0
05 5 R/ W
16
3 JOYA2 17 04 6 Do• Clock
4 JOYA3 0 0 0 0 18 03 7 I/O 1
5 POT AY 6 7 8 9 19 02 B GAME
6 BUTTON A/LP 20 Dl 9 EX ROM
7 +5V MAX . 50mA 21 DO I/ O 2
L IO
B GND 22 GND 11 ROML
9 POT AX
Pin Type Pin
Type l
N A9 A GND
Control Port 2 p AB B ROMH
Pin Type Note R A7 c RESET
1 JOY BO s A6 D NMI
2 JOYBl T A5 E s 02
3 JOYB2 u A4 A15
4 JOY B3 v A3 H A14
5 POT BY w A2 J A13
6 BUTTON B x Al K A12
7 + 5V MAX . 50mA y AO All
B GND _____.!:_ GND M AlO J
9 POT BX 22 21201918 17 16 15,. 13 12 11 10 9 8 7 8 5 • 3 2 ,
I :::::::::::::::::::::: I
l V X W v U T SR P N "4 L K J HF E DC B A
Rear Connections
125
124
6. TV Connector-This connector supplies both the picture and sound to
your televi sion set.
7. Audio/Video Connector-This DIN pin connector supplies direct audio
and composite video signals . These can be connected to the Commo-
dore monitor or used with separate components.
Serial I/O
Pin Type
l SERIAL SRQIN
2 GND
3 SERIAL ATN IN/ OUT
4 SERIAL CLK IN/OUT
5 SERIAL DATA IN/OUT
6 RE5Er
::::::
A-1 GND
B-2 +sv
C-3 CASSETTE MOTOR
D-4 CASSETTE READ
8. Serial Port-A Commodore serial printer or 1541 single disk drive can A B C 0 E F
E- 5 CASSETTE WRITE
be attached directly to the Commodore 64 through this port. F-6 CASSETTE SENSE
126
127
User 1/0
::::::::::::
A B C D E F H J K L M N
present values, future values. Bar graphs.
Easy Finance Ill Advanced Investing Calculate weighted cost of capital,
accrued interest on bonds, earnings per share , future uneven cash values,
rate of return, present value of a tax deduction. 16 functions. Bar graph .
• COMMODORE SOFTWARE Easy Finance IV Business Management 21 Business calculation func-
tions: Lease/Purchase Analysis, breakeven analysis, compensation , lease/
Commodore supports the C64 with a full range of software in cartridges, purchase , optimal order quantities, business forecasting , much more. Bar
disk and cassette including educational programs , financial software, pro- graphs.
ductivity software , programming aids , business software , arcade games, Easy Finance V Statistics and Forecasting Assess present/future
Bally Midway games, music and strategy adventure games as well as books sales, trends and other business parameters with 9 statistical and forecast-
from the Commodore Library (See Appendix L). ing functions. Calculate average growth rate/expected values. Special help
Here is a list of Commodore software: menu.
Financial Advisor Designed for the High School or College finance stu-
Productivity Sof tware dent or the Loan Officer at the local bank. Computes loans/investments/
Micro Cookbook Computer age solution to menu planning . Manage your stocks/bonds with amazing speed and accuracy.
recipes quickly and easily.
129
128
Speed/Bingo Math (Ages 4 to 10) Two math games help you build math
Business Software
skills and have fun at the same time. One or two players. A Bally/Midway
General Ledger 8 general ledger options. 1500 transactions. 150 chart conversion.
of-accounts. Posting integrated with other accounting modules. Custom Easy Match/Easy Count (Ages 4 to 6) Kinder Koncepts Series. Practice
income statement , trial balances , full reports. identifying shapes and letters and counting objects-importanl pre-reading
Accounts Receivable/billing 11 billing functions . 150 invoices. 75 cus- and pre-math skills.
tomers. 40 transactions/file. Billing , credit , receivables . Printed statements. What's Next/Letters or Numbers (Ages 4 to 6) Kinder Koncepts Series.
Accounts Payable/Checkwriting Combines tracking of vendor payables Practice in identifying correct sequences of numbers and letters.
with integrated checkwriting system . Interfaced with other accounting Letter SequencesfThe Long or Short of It (Ages 4 to 6) Kinder Koncepts
modules. Series. Practice in identifying letter sequences and in recognizing which
Payroll For Business with 50 employees or less. 24 different payroll func- shape is longest or shortest.
tions. Payroll checks include federal/state/other deductions. Integrated with A Letter Match/More or Less (Ages 4 to 6) Kinder Koncepts Series.
General Ledger. Prints W2's and 941 's. Upper and lower-case letters, more or less relationships, and matching
Inventory Management Computerized tracking of 1000 inventory items. numbers.
Stock receipts/issues/orders/adjustment with printed reports. Calculates Shapes and Patterns/Group It (Ages 4 to 6) Kinder Koncepts Series.
use/reorders/economic order quantities/cost averaging and more. For all Brightly colored shapes and sounds give practice in identifying shapes and
types of inventories including personal collections and insurance lists. patterns. grouping and regrouping . Excellent pre-reading and pre-math devel-
Magic Desk I Type & File Now you can type , file and edit personal letters opment drills.
and papers without learning any special commands! All Magic Desk com- A BEE C's (Ages 3 to 6) The Commodore Bee guides your child in learning
mands are pictures. Just move the animated hand to the feature you want to the alphabet. Playing games reinforces this skill. Excellent tool for young
use and you 're ready to go. children . It talks with Magic Voice!
Visible Solar System (Ages 7 to Adult) Authentic , astronomer-tested
Educational Programs
journey through the solar system. Tour the planets Earth, Mars. Jupiter and
Intro to Basic I 17 programs , a 150-page manual and a flowchart tem- Saturn as well as asteroids. comets and meteors. Planet fun for space buffs'
plate. Th is program is an instructional guide that teaches the fundamentals Number Nabber/Shape Grabber (Ages 6 to 12) Two learning games in
of programming in BASIC while assuming the user has no previous knowl- one . Builds arithmetic and shape identity skills. Lively music and sound
edge of programming . effects make this a favorite.
Intro to Basic II Uses the same easy-to-understand approach presented Math Facts (Ages 5 to 10) Give practice in basic math facts. Several
in BASIC I. This package includes a 180 page manual with explanations, levels.
practice drills, examples and a disk with 33 programs . Learn more advanced Numbers Galore (Ages 3 to 14) 3 different math programs. Number
techniques of BASIC programming with this terrific program! Match It for preschool. Math Facts Games for elementary, and Number
Zortec and the Microchips (Ages 6 to 12) A fun way to teach young Cruncher for middle school.
people how to program in BASIC. Help Zortek teach the Microchips to pro- Frenzy/Flip Flop (Ages 6 to 14) Milliken EduFun Series Frenzy ... subtrac-
gram the computer before the Zitrons attack. tion and division ... the hungry gator arrives ... save the fish . .. play the
Pilot (Ages 12 to Adult) A special language that helps nonprogrammers Bonus game . .. the more you save ... the more you play! Flip Flop ... trans-
design computerized quizzes and drills. For teachers, parents and students . formational geometry .. . look at the two figures ... do they need to flip, turn
LOGO (Ages 6 to Adu lt) Terrapin LOGO . The best , most powerful version of or slide? . .. stand on your head ... lie on your side ... you 'll flip over this
LOGO on any home computer. Includes sprite graphics, sound commands, game!
turtle graphics and 400 page tutorial. Golf Classic/Compubar (Ages 10 to 14) Milliken EduFun Series. Golf
Chopper Math (Ages 7 and up) Practice basic math skills. Get the right Classic (angle and length estimation). Fore! Play the angles. Choose dis-
answer and land the helicopter on its landing pad before it crashes. tances. Multiple players. Sports fun! Compubar (read graphs, construct
Type Right (Ages 12 to Adult) No more hunting and pecking! Learn how to arithmetic expressions) add this bar: subtract that one. Did you read them
type on your computer with 17 lessons and 4 games. correctly?
131
130
Gulp !/Arrow Graphics (Ages 6 to 12) Milliken Edu Fun Series. Gulp! (addi- Tooth Invaders Reviewed by American Dental Association . Arcade action
tion and multiplication drill) the race is on ... add ... multiply . . . faster, teaches good dental care. Beat Tooth Decay in 9 levels.
faster .. . don 't get caught ... watch out for those jaws! Arrow Graphics Triad One/Two players. Position yourself on tic-tac-toe grid for different
(problem solving and directionality) following the traveling arrow .. . where attack strategies. Progressive difficulty levels test both reflexes and mind.
did it go? ... left or right how many steps? Dragonsden Arcade-style excitement in this Commodore original. Battle
Alien Counter/Face Flash (Ages 4 to 9) Milliken EduFun Series. Alien giant spiders , bats and the dragon in this contest of skill and reflexes. 3
Counter (counting) Flying saucers . . . numbers in the sky ... aliens landing levels.
on Earth .. . another perfect encounter? Face Flash (counting , visual mem- Bally Midway Games
ory, and base ten) ready, set, go ... now you see them ... count fast ...
they're gone! How many? Blueprint Help J.J. build the "Ammo Machine " and save Loni . Parts are
Battling Bugs/Concentraction (Ages 9 to 12) Milliken EduFun Series. stored in a colorful maze of houses. Multi-skill and difficulty levels.
Battling Bugs (positive and negative numbers) columns of bugs, get rid of Clowns Amazing action under the Big Top. Clowns pop balloons for high-
them all! You might be the master exterminator! Concentraction (equivalent scoring , colorful acrobatic fun for all .
fractions) ... choose two ... are they equal? Two players. Gort 4 Space action games in 1. Fly your fighter, defeat the Empire. Mult i-
Easy Lesson/Easy Quiz For Teachers. Create your own lessons and quiz- skill levels. Talks with Magic Voice . " Best home version ever " -Creative
zes using the power of the computer. Computing .
Kickman Ride the unicycle and catch fall ing objects. Multi-skill levels.
Arcade Games
Excellent graphics and superb sound . Watch out! Don 't fall!
International Soccer A Gold Medallion Game. As close to real soccer as Lazarian 4 different screens. Multi-skill level space action . Rescue, evade
you can get without putting on cleats! Realistic player and ball movement obstacles and destroy the one-eyed leviathan .
highlight this stunning version of the most popular sport in the world . Omega Race Fast space race action . Many skill levels . Avoid deadly
Jack Attack A Gold Medallion Game. Combines cartoon animation with mines as you eliminate droid forces .
strategic challenge. 64 different screens . A Commodore original rated a Seawolf The classic two-player sea battle. Torpedo PT Boats and
" must-buy " -Electronic Games Magazine. Destroyers. Great graphics and sound .
Avengers Destroy attacking aliens with laser cannons, as you dodge their Wizard of Wor Fight your way through 25 mazes. Defeat the wizard and
bullets. Classic arcade action. Multi-speed attacks. his pets. Two-player, multi-skill. Talks with Magic Voice . Brilliant conversion of
Frogmaster Unique sports challenge. Train frogs to play football and the popular classic.
rugby. Over 100 variations. Play against computer, friend or yourself. Solar Fox You 're the pilot as you navigate your spacesh ip over a grid of
Jupiter Lander Space landing simulation. Horizontal and vertical thrust. colorful pulsating entities, using your laser to erase enemy life forms and
Softland scoring. Joystick control. other surprises. But be careful of the enemy fire or you 'll be erased! Fast
Le Mans Multi-obstacle road racing at its best. Arcade action and graph· paced conversion of a Bally Midway or iginal uses an unlimited number of
ics. Night. water, ice and divided highway hazards. levels and dozens of different patterns.
Pinball Spectacular Real pinball action and thrills. Sound you won 't
believe. Chutes. lights, bumpers and more. Strategy Adventures
Radar Rat Race Beat the maze. Eat all the cheese. Beware of deadly cats Deadline Find the murder and solve the mystery in 12 hours. Inspector
and rats. Cartoon action for all ages. casebook and evidence included.
Starpost Protect the Star Post from waves of invaders. 3 levels of skill. 99 Starcross Travel through the mystery ship. Meet aliens, friend and foe .
levels of action. Face the challenge of your destiny. Galaxy Map included.
Star Ranger Fight your way through hordes of space enemies. Avoid aste- Suspended Awaken in 500 years . Solve varied and orig inal puzzles to
roids and land safely. Superb graphics combined with intriguing strategy_ save your planet from total destruction .
Supersmash Racquetball arcade classic. 3 Games in 1. Many skill levels Zork I, II , or Ill Zork Series. Fantasy adventure in a dungeon. Find all the
make this game a smash hit. treasure and escape alive . Three continued fanta sies.
132 133
Software
Music [ ] Productivity
[ ] ____
Music Composer Create , play and save your tunes easily. Simulates up [ ] ____
to 9 instruments. Notes appear on screen . Play your keyboard like a piano . [ ] ____
Music Machine Play piano or organ melodies and percussion rhythm s ] Financial
together. Music staff shows notes on screen . Vibrato , tempo and pitch [ ] ____
controls. [ ] ____
] Educational
Programming Aids [ ] ____
Assembler 64 For experienced Assembly language programmers. Cre- [ ] ____
ate , assemble , load and execute 6500 series Assembly language code. [ ] ____
Macro assembler. Two machine language monitors. Editor and loaders. Sup- ] Business
port routines . User manual. [ ] _____
Simon 's Basic Expands Commodore BASIC with 114 commands such as [ ] ____
RENUMBER and TRACE . plus graphics commands . Programmers and novi- ] Games
ces love it! A must for the serious Commodore user. [ ] ____
Super .Expander 64 Easy graphics and music. Draw points , lines, arcs, [ ] ____
circles , ellipses , polygons . Create more sprites . Easy music programming . [ ] ____
Combine text and graphics. Adds 21 special commands to BASIC. [ ] ____
[ ] _____
] Music
• Personal Checklist [ ] ____
] Adventures
Use this checklist to keep track of what you purchase or plan to purchase. [ ] ____
[ ] ____
Hardware:
[ ] Printer ] Programming Aids
[ ] DPS 1101 DAISYWHEEL [ ] ____
[ ] MPS 801
[ ] MPS 802
[ ] ____
] Miscellaneous
[ ] MCS801
] Commodore Colar Monitor Books: Commodore Library
) 1541 Disk Drive [ ] Programmer 's Reference Guide
] Datassette [ ] Commodore 64 Adventures
) Magic Voice Speech Module [ ] Business Applications on the Commodore 64
] Joysticks [ ] Graphic Art: Using Turtle Graphics
] AUTOMODEM [ ] Mathematics on the C64
] Paddles [ ] Advanced Programming Techniques on the C64
] Light Pen [ ] Artificial Intelligence on the C64
[ ] Programming for Education on the C64
[ ] 1541 Disk Companion
135
134
COLOR MEMORY MAP
APPENDIX C COLUMN
20 JO 39
10
55335
l
IT I I I I I I I
55296- I I I I
I I I I I I I
55336 I l I I
l I
55376 lT
55416 I I I
• SCREEN AND COLOR MEMORY MAPS 55456 I I
I I I
55496
I
The following maps di splay the memory locations for identifying the char- 55536
I I I
55576
acters on the screen as well as their color. Each map is separately controll ed 55616 I I ' l I I I I I
55656 I I I I I I
and consists of 1OOO positions. 55696 ' I I
I l
The characters displayed on the maps can be controlled directly with the 55736 I I I 1 I I I
55776 I I I I I I I I
'
POKE command . 55816 I I l I I I I I I i I I I
i I I I
~
55856 ~I I
SCREEN MEMORY MAP 55896 I I I I I
I
I
--,I I I
I I
55936 I I I I
55976 i I I I I
COLUMN
30 39 56016 ! i I I I
10 20 I I i I I I
56056
1063 56096 I 20
T I l
lI 56136
I
I , ___ -rt : I I
I
I
I
I T I j
56176 I I I I
1024 ~
1064
I
I
I I I
I I I 'I I I I I I I I I I I I
I I
11 56216 I I I I I
I I I I I I I I I 56256 I I I I I I 24
1104 I I
1144 I
l
I
I I
t
1184 I I I I 56295
I I I I I I I I i
1224 I
I I I I I I I The color map is POKEd with a color value: this changes the character's
1264 I I
I I
I I I I I I I
1304 11
I I I color. Thus
1344 I I I I I I I I I I I I
I I I I I
1384 I I I I I ""~
r -T I I I I I I 10 POKE 55296, 1
1424 I I I I
1464 I I I I I I I I I I I
I : !
1504 I I' I I
I I I I I Ii I i 1 I I will change the letter M inserted above from light blue to white.
1544
1584
' I
I
I I I "i I I I I
I I I I I I I I Colar Codes
1624 11 I
I I I I I I I I I I I
1664 I
11 I I I I I I I
1704 I I I
! I I I O Black 8 Orange
1744 I I I I I
1784 I I I I I I I I I I I I I 1 White 9 Brown
I I I I I I I I I 20
1824 I 2 Red 10 Light Red
1864 I I I I I I I I I I I
will display the letter Min the upper left corner of the monitor.
136 137
SET 1 SET 2 POKE SET 1 SET 2 POKE SET 1 SET2 POKE
APPENDIX E
rn 93 ~ 1:1 105 [] 117
[IT] B 94 0 106 [] 118
~ ~ 95 CB 107 LJ 119
•
D
D
98
99
100
Ei]
~
ea
110
111
112
D
~
~
0 122
123
124
PRINT ASC(" x")
where X is any cha racte r you select , resulting in the fo llowing table. Typing
PRINT CHR$(n)
D 101 ~ 113 El 125
wnere n is the ASC II code number from the table will print the corresponding
1111 102 63 114 ~ 126 character. Thus:
~ 104 D 116 will display the letter A where the cursor happens to be and
Codes from 128-255 are reversed images of codes 0-127. PRINT CHR$(147)
-
II
0 17 " 34 3 51
1 18 # 35 4 52
2 !I 19 $ 36 5 53
3 II 20 O/o 37 6 54
- 4 21 & 38 7 55
5 22 39 8 56
6 23 ( 40 9 57
7 24 ) 41 58
OISABLES-(18 25 . 42 '
59
ENABLES - ( 1 9 26 + 43 c: 60
10 27 '
44 = 61
141
140
-
-
PRINTS CHA$ PRINTS CHAS PRINTS CHA$ PRINTS CHA$
-- IJ
D 68 [!] 97 ITD 126 Lt. Gray 155 +- 95 124 Lt. Green153 [] 182
E 69 rn 98 ~ 127 156 El 96 rn 125 Lt. Blue 154 LJ 183
F 70 El 99 128 ii 157
G
H
I
J
71
72
73
74
El
LJ
g
D
100
101
102
103
Orange 129
130
131
132
...•
IJ
158
159
160
161
PRINTS
~
CHA$
184
PRINTS
D
CHA$
186
PRINTS
~
CHAS
188
PRINTS
1!J
CHAS
190
K
L
M
75
76
77
[]
EJ
~
104
105
106
f1
f3
f5
133
134
135
•D
D
162
163
164
~
CODES
CODES
185 .:J
192-223
224-254
187 E!J
SAME AS
SAME AS
189 ~
96-127
160-190
191
•
117 146 175
y 89 ~ 118 147 ea 176
142
143
Register II-
Dec Hex 087 086 DBS 08<4 083 082 081 080
145
144
Reg ister #
Dec Hex Col or Reg is ter ii
Dec H ex
Col or APPENDIX G
32 20 BORDER COLOR 39 27 SPRITE 0 COLOR
BACKGROUND
33 21 40 28 SPRITE 1 COLOR
COLOR 0
BACKGROUND
34 22 41 29 SPRITE 2 COLOR
COLOR 1
BACKGROUND
• MUSIC NOTE TABLE
35 23 42 2A SPRITE 3 COLOR
COLOR 2 Note values are POKEd into two memory locations 54272 and 54273 , also
BACKGROUND
36 24 43 2B SPR ITE 4 COLOR known as registers or switches 0 and 1 respectively.
COLOR 3
POKE the value N1 into Register 1 and the value N2 into Register 0.
SPRITE
37 25 44 2C SPRITE 5 COLOR The list below covers three octaves of notes for Bass and Treble Clef. For
MULTICOLOR 0
SPRITE the full list of nine octaves. see the Programmer 's Reference Guide.
38 26 45 2D SPRITE 6 COLOR
MULTICOLOR 1
46 2E SPRITE 7 COLOR
a:
~
'""
;-
G A B c D E F 0 A B c D E F G A B c D E F
C Middle c
c
146 147
.....- -
F 10 241
F#
G
11
12
152
73
APPENDIX H
G# 13 4
A 13 201
A# 14 156
B 15 122
*C 16 101 • SOUND CONTROL SETTINGS
C# 17 96
D 18 104 Each sound parameter is POKEd into a register of the specialized sound
D# 19 128 generating chip. Each register or switch is a memory location (called byte
E 20 169 address) starting with 54272.
F 21 227 Each sound has a characteristic ADSR consisting of the following four
F# 23 49 parameters: Attack , Decay, Sustain , Release .
G 24 146 Attack is the rate sound rises to maximum volume. It can vary from a 2-
G# 26 8 millisecond cycle to an 8-second cycle. The corresponding register value is O
A 27 148 to 15.
A# 29 57 Decay is the rate sound falls from maximum volume to sustain level. This
B 30 245 varies from a 6-millisecond cycle to 24 seconds, corresponding with 0 to 15.
c 32 204 The values of Attack and Decay are POKEd together into register (swi tch)
C# 34 192 5 by a single number derived by multiplying the ATT/\CK value by 16 and
D 36 208 adding the DECAY value.
D# 39 1 Sustain is the amplitude level at which the sound is held, varying from 0 %
E 41 83 to 100 % of maximum level corresponding to register values of 0 to 15.
F 43 200 Release is the rate at which volume falls from the sustain level to zero:
F# 46 99 similar in timing to the decay rate .
Sustain and Release are POKEd into regi ster 6 together as one number
* MIDDLEC derived by multiplying SUSTAIN by 16 and adding the RELEASE value.
Waveform is the shape of the sound wave produced. The waveforms
called Triangle , Sawtooth and Pulse are related to the musical inst rument.
Noise is a randomized waveform . Only specific register values will activa te
this characteristic of sound .
Pulse is the tonal quality of the Pulse waveform. Tl1us, whenever register
(switch) 4 is activated with a 65 , a va lue other than zero must be POKEd into
either switch 2 or 3 for the Pulse Rate .
Frequency is the vibratory level of sound which distinguishes one note
from another. Concert A is 440 cycles per second. Switches 0 and 1 are
required to define the frequency. 256 times the value in Regi ster 1 plus the
value of Register 0 is the sound generator's oscillator frequency. This is
directly proportional to the sou nd frequency.
Below is a table of values which can be POKEd into these reg isters. The
actual memory location is 54272 plus the register number.
148
149
--
Register
Voice 1 Voice 2
Description Range of Values APPENDIX I
Voice 3
0 7 14 frequency 0 to 255
1 8 15 frequency Oto 255
2 9 16 pulse Oto 255
3 10 17 pulse 0 to 15
4 11 18 Waveform 16,32,64 , 128 • DERIVED TRIGONOMETRIC FUNCTIONS
17 ,33,65, 129
5 12 19 Attack/Decay Oto 255
6 13 20 Sustain/Release 0-255 FUNCTION BASIC EQUIVALENT
All voices
SECANT SEC(X)= l/COS(X)
21 Filter-low cutoff O to7 COSECANT CSC(X)= l/SIN(X)
22 Filter-high cutoff Oto 255 COT{X)= l /TAN (X)
COTANGENT
23 Resonance 16,32, 64 ,128 INVERSE SINE ARCSIN {X)=AT N(X/SQ R(- X* X + l ))
or any sum INVERSE COSINE ARCCOS(X)= - ATN (X/SQR
23 Filter switch/voice 1,2 or 4 (-x•x + l)) +rr/2
24 Volume 0 to 15 INVERSE SECANT ARCSEC(X)= ATN (X/SQ R(X * X - l ))
INVERSE COSECANT ARCCSC(X)=ATN(X/SQR(X*X- l ))
+ (SG N(X)- l *rr/2
INVERSE COTANGENT ARCOT (X)= ATN (X)+ rr/ 2 !
HYPERBOLIC SINE
HYPERBOLIC COS INE
SINH(X)= (EXP(X) - EXP(- X))/2
COSH(X)= (EXP(X)+ EXP(- X))/2
-
HYPERBOLIC TANGENT TAN H(X) = EXP(- X)/(EX P(x)+ EXP
(- X)) *2+ 1
HYPERBOLIC SECANT SECH (X)=2/( EXP(X)+ EXP(-X))
HYPERBO LI C COSECANT CSCH(X)= 2/( EX P(X) - EXP(- X))
HYPERBOLIC COTAN GENT COT H(X)= EXP(-X)/( EXP(X)
- EXP(-X))*2+ l
INVER SE HYPERBOLIC SINE ARCSINH (X)= LOG(X+SQ R(X*X+ Ji)
INVER SE HYPERBOLIC COSINE ARCCOSH (X)= LOG(X+SQ R(X*X- 1))
INVERSE HYPERBOLIC TANGENT ARCTANH(X )= LOG(( l + X)/( 1- X))/2
INVERSE HYPERBOLIC SECANT ARCSECH (X)= LOG((SQ R
c-x•x+ J) + l /X)
INVER SE HYPERBOLIC COSECANT ARCCSCH(X) = LOG((SG N(X)* SQR
(X*X+l/x)
INVERSE HYPERBOLIC COTAN- ARCCOTH (X)= LOG((X + l )/(x- l ))/2
GENT
151
150
APPENDIX J Com- Abbrevi-
Looks like
this on Com- Abbrevi-
Looks like
this on
mand at ion screen mand ation screen
As a time-saver when typing programs and commands, you can abbrevi- LIST L ma I L E\J SAVE S Emil A s~
ate most keywords. The abbreviation for PR INT is a question mark. The
abbreviations for other words are made by typing the first one or two letters LOAD L ma 0 LO SGN s Emil G s [l]
of the word , followed by the SHIFTed next letter of the word . When used 1n a
program line , the keyword will LIST in the full form .
LOG NONE LOG SIN sma I s EJ
MID$ Mmal MEJ SPC( s mD p so
[l]
AND A mD N A0 EXP E ma X E ~
ON NONE ON STOP s ma T s
NONE TAN
CLOSE CLma 0 CLD GET G B!lilE G El POKE Pmil 0 PD TAN
PRINT ? ? TIME TI TI
CMD C BllD M c ISI GO SUB GO m i l S Go[!}
152 153
--- -
NOTE: See the BASIC Encyclopedia (page 159) for detai ls on specif ic
commands. APPENDIX K
• BASIC CONVERSIONS
If you have programs wr itten in a BASIC other than Commodore BASIC,
some minor adjustments may be necessary before running them on the C64 .
Here are some hints to make the conversion easier.
String Dimensions
Modify all statements that are used to declare the dimension of strings.
Commodore BASIC does not require a string length dimension-only the
quantity of variables. A statement such as DIM A$(J ,K), which dimensions a
string array for J elements (single array), each of length K, should be con-
verted to DIM A$(J) .
String Concatenation
Replace the ampersand or comma some BASICs use to concatenate
strings with the plus sign .
Substrings
In Commodore 64 BASIC, the MID$, RIGHT$ and LEFT$ functions are
used to take substrings of strings. Forms such as A$(J) to access the
Jth character of the nondimensioned string A$ must be changed to
MI 0$(A$,J, 1).
Forms such as A$(J,K) to access the Kth character of the single dimen-
sioned array A$(J) must be changed to MID$(A$(J),K,1).
Slicers in the form A$(J TO K) which take a substring of the variable from
the Jth character to the Kth character must be changed to MID$(A$,J,K-
J + 1).
LET statements
LET statements are accepted by Commodore BASIC and need not be
changed .
154 155
PAUSE
To create a time delay in Commodore BASIC replace PAUSE statements
APPENDIX L
with a FOR ... NEXT loop.
PRINT AT
To achieve an equivalent in the C64 BASIC, replace PRINT AT X, Y with : • RECOMMENDED READING LIST
POKE 782,X:POKE 781, Y:SYS 65520 Below is a sample list of books available from the major publishing houses
as well as the Commodore Library.
Multiple Statements
Some BASICs use a backslash (/) to separate multiple statements on a Beginning BASIC
line. Commodore BASIC requires the colon(:). Taking Off with BASIC on the C64
Brady
Hayden Basic Commodore 64 BASIC
Multiple Assignments I Speak BASIC to My C64
To set more than one variable to the same constant, such as LET B = C = O Prentice Hall Programming Your Commodore 64 in BASIC
must be converted to separate statements with colons or on individual lines: Sams Learn BASIC Programming in 14 Days on Your C64
B=O:C=O. Commodore 64 Starter Book
Sybex Your First Commodore 64 Program
MAT functions T_he Easy Guide to Your C64
Programs using MAT functions available on some BASICS must be rewrit· Just for Kids
ten using FOR .. . NEXT loops to execute properly.
Creative Computers for Kids: C64
Random Numbers Datamost Kids and the Commodore 64
Sams Commodore 64 for Kids from 8 to 80
Other BASICs may apply the random function differently. Whereas QUE Tim lost
INT(RND*6)+ 1 is used to obtain the six numbers of a die, use Sybex Power Upl Kids ' Guide to the C64
INT(RND(0)*6)+ 1 in Commodore BASIC. Trillium Kids Working with Computers: C64
General Applications
Brady 101 Uses for the C64
Commodore Business Applications on the C64
Artificial Intelligence on the C64
Commodore 64 Adventures
Compute Creating Arcade Games on the C64
Creative The Working Commodore 64
Hayden Stimulating Simulations for the C64
Rest on C64 Data Files : A BASIC Tutorial
Sams Commodore 64 BASIC Programs
TAB Using and Programming the C64
156 157
Education
Computer Controllers
Birkhauser
Prentice Hall
Your Computer Butler
Easy Interfacing Projects for the C64
BASIC 2.0
Sybex
Graphics
The Commodore 64 Connection
ENCYCLOPEDIA
Arrays C64 Color Graphics: An Advanced Guide
Brady C64 Graphics: Activities Handbook
CBS Color Graphics for the C64
Commodore Graphic Art on the C64
Prentice Hall Sprite Graphics for the C64
Sams C64 Graphics and Sounds
Sybex Graphics Guide to the C64 INTROD UCTION _ _ _ _ _ _ __ __ _ _ _ 161
TAB C64 Graphics and Sound Programming
BASIC COMMANDS 162
Music BASIC STATEME NTS 168
Birkhauser The C64 Music Book BASIC FUN CTION S 181
Prentice Hall Music and Sound for the C64 VAR IAB LES AN D OPERATORS 186
References
Arrays The C64 User's Encyclopedia
Brady Introduction to Assembly Language for the C64
Commodore Advanced Programming Techniques on the C64
Programmer's Reference Guide
1541 Disk Companion
Compute Compute 's First Book of 64
Computext C64 BASIC Guide
Reston Master Memory Map: C64
Osborne/McGraw Your Commodore 64
159
158
............
• INTRODUCTION
In this manual, you 've seen an assortment of exercises using the BASIC
language that give you a feel for computer programming and some of the
vocabulary involved. This encyclopedia gives a list of the rules (syntax) and
terms of the BASIC 2.0 language, along with a concise description of each .
Experiment with these commands, and remember-you can 't damage your
Commodore 64 by typing in programs, and the best way to learn computing
is by computing.
The encyclopedia provides formats , brief explanations and examples of
the BASIC 2.0 commands and statements. It is not intended to teach BASIC.
If you are interested in learning BASIC, Appendix L lists tutorial books that
will help.
Commands and statements are listed in separate sections. Within the sec-
tions, the commands and statements are listed in alphabetical order. Com-
mands are used in direct mode, while statements are most often used in
programs . In most cases , commands can be used as statements in a pro-
gram if you prefix them with a line number. You can use many statements as
commands by using them in direct mode (i .e., without line numbers).
The BASIC Encyclopedia is organized as follows:
• COMMANDS: the commands used to work with programs, edit , store
and erase them .
• STATEMENTS: the BASIC program statements used in numbered lines of
programs .
• FUNCTIONS: the string , numeric and print functions .
• VARIABLES AND OPERATORS: the different types of variables, legal var-
iable names. and arithmetic and logical operators.
A more complete explanation of BASIC 2.0 commands is provided in the
Commodore 64 Programmer 's Reference Guide, available from your Commo-
dore dealer or your local bookstore.
161
The LIST command has five options:
• BASIC COMMANDS
CONT (Continue) 1. Type the word LIST to display the entire program in memory. Slow down
the LISTing by holding down the CTRL key. Stop the LISTing by pressing
This command is used to restart the execution of a program which has the RUN/STOP key.
been stopped by using the STOP key, a STOP statement or an END statement
Example: LIST (LISTs the entire program).
within the program . The program will restart at the exact place it left off.
CONT will not work if you have changed or added lines to the program (or 2. Type the word LIST and follow it with a line number to display that
even just moved the cursor), or if the program halted due to an error, or if you specified program line.
caused an error before trying to restart the program . In these cases you will
get a CAN'T CONTINUE ERROR. Example: LIST 10 (LISTs only line 10).
3. Type the word LIST and follow it with a line number and a dash to
COPY display the program starting at the specified line number.
On a dual disk drive (4040), COPY a disk file from one drive (the source file) Example: LIST 100- (LISTs from line 100 to the end of the program).
to the other. On a single disk drive (1541 ), COPY a file on the same disk under
a different filename . You must open the disk file before COPYing as follows: 4. Type the word LIST and follow it with a dash and a line number to
display the program from the beginning to the specified line number.
OPEN file number, device number, channel number
Example: LIST -100 (LISTs the program from the start up to line 100).
Example:
5. Type the word LIST, follow it with a line number, a dash and another line
OPEN 15,8,15: REM file 15, device 8, channel 15 number to display the program from the first specified line number to
the second specified lihe number.
The COPY command format is as follows:
Example: LIST 10-200 (LISTs lines 10 through 200).
PR I NT#15, "COPY[drive number]:new file = [drive number]:old file "
For example: LOAD
PRINT#15,"COPYO:NOON = 1:NIGHT" The LOAD command fills the computer 's memory with a program stored
on diskette or cassette tape. The format for the load command is as follows :
copies the file named "NIGHT" from drive 1 to drive O and renames it
"NOON" . LOAD "filename" ,[device number],[secondary address]
PRINT#15,"COPYO:STUFF = 1:STUFF " The filename is the name of the program you want to load . The device
number for cassette is 1, the device number for a disk drive is 8. The second-
copies the file named STUFF from drive 1 to drive 0.
ary address is number 1 and is only specified when you want to LOAD a
PRINT#15,"COPYO:DOGS = O:CATS " machine language program into a specific Commodore 64 memory location
from which it was SAVEd.
copies t he file named "CATS" onto the same disk in a single drive and
renames it "DOGS" You have four options in which to LOAD a program from CASSETTE tape .
LIST 1. Type LOAD and press RETURN . The computer responds by displaying :
163
162
NEW
Press the play button on the Datassette. The screen turns off and the
computer searches for the first program on the cassette tape . Press the c- BE CAREFUL WHEN YOU USE THIS COMMAND. This command
key to LOAD the program or the spacebar to search for the next program on erases the entire program in memory, and also clears out any variables that
the cassette. may have been used. Unless the program was SAVEd, it is lost.
The NEW command can also be used as a BASIC program statement.
Example: LOAD BiEIE When the program reaches this line, the program is erased. This is useful if
2. Type LOAD followed by a program name within quotation marks. The you want to leave everything neat when the program is done.
same sequence of events happens as above (option 1) except this
directly LOADs a specified program name from the cassette tape . RUN
3. Type LOAD followed by a program name within quotation marks, a The RUN command executes a program in the Commodore 64 's memory.
If a line number is specified follow;;1g the RUN command , the computer
comma and the number 1. This is the same as number 2 except you
specify the device number 1 as the Datassette. If a device number is starts RUNning the program at the specified line number. RUN may be used
not specified, it defaults to device number 1. When using cassette within a program .
tape , you do not have to specify the device number, it is optional. Examples:
Example: LOAD " Program Name ", 1 iBEIElli RUN Executes the program from the beginning .
4. Type LOAD followed by a program name within quotes, a comma, the RUN 100 Starts executing the program at line 100.
number 1, a second comma and the number 1 again. This LOADs a
specified program name from device 1 (Datassette) into the Commo· SAVE
dore 64 memory location from which it was SAVEd. If the secondary
address 1 is specified, the program name and device number must be SAVE ["filename" [,device number[,EOTflag]]]
specified. The SAVE command stores a program currently in the computer 's memory
Example: LOAD " Program Name ", 1,1 llmillli onto a disk or cassette tape.
You have three options in SAVEing programs on CASSETTE
You have two options in which to LOAD a program from DISKETTE:
1. Type SAVE and press RETURN . The Commodore 64 responds by dis·
1. Type LOAD followed by a program name wit~.in quotation marks, playing the message:
a comma and the number 8. This LOADs the specified program from
diskette. PRESS RECORD & PLAY ON TAPE
Example: LOAD " Prog ram Name",8 Press the PLAY and RECORD buttons on the Datassette . The Commodore
64 SAVEs the program in memory starting at the current position of the cas-
2. Type LOAD followed by a program name within quotes, a comma , the sette tape . Make sure you do not have an important program at that tape
number 8, a second comma and the number 1. This LOADs the speci· position because the C64 SAVEs the current program on top of the original
fied machine language program name into a predetermined Commo- one,andthatoneislost.
dore 64 memory location from which it was SAVEd.
Example: SAVE !i~11¥
1
Example: LOAD "Program Name ",8,1 liiQl;;.u.-1.1
In these examples, indicates that you must press the RETURN
key after the given command.
Arguments appearing within brackets are optional.
165
164
2. Type SAVE followed by a program name in quotation marks. This SAVEs VERIFY
the specified program onto the cassette tape at the current position . VERIFY " filename " ,[device#],[ secondary address]
The same conditions in option 1 apply.
The VERIFY command compares the program on tape or disk with the one
Example: SAVE " Program Name " &bk in memory. If the programs are identical, the Commodore 64 responds with
" OK ". If the two versions of the program differ, a VERIFY ERROR results.
3. Type SAVE followed by a program name in quotes. a comma and the
This command makes sure the program is SAVEd correctly to tape or disk.
number 1. This is the same as option 2 except you specify the device
You have three ways to VERIFY a program :
number for the Datassette.
1. Type VERIFY and press RETURN . This verifies the program at the cur-
Example: SAVE " Program Name ", 1 !ISiEIRIWI
rent position of the cassette tape .
To SAVE to DISK, type SAVE followed by a program name within quotes, a
Example: VERIFY
comma , and the number 8. This saves the contents of the Commodore 64
memory onto the disk. The diskette must be formatted before you can SAVE 2. Type VERIFY followed by a program name within quotation marks. This
programs on it. See the DISK NEW command . verifies the specified program name on the cassette tape.
Example: SAVE " Program Name ", 8#~~1il Example: VERIFY "Program Name " =e 44
3. Type VERIFY followed by a program name within quotation marks, a
SCRATCH
comma and a device number. The device number can be either 1 for
Deletes a file from the disk directory. Use this command to erase the Datassette or 8 for the disk drive. This command verifies the speci-
unwanted files and to create more storage space on the disk. You must first fied program name on the designated device (disk drive or tape).
open the disk command channel (sec0ndary address 15) before scratching
Examples: VERIFY " Program Name",8 (Verifies program on
any files as follows :
disk)
OPEN file number, device number, secondary address VERIFY " Program Name " ,1 (Verifies program on
cassette tape)
Example: OPEN 15,8, 15 4 1 w=
The format for the SCRATCH command is as follows :
PRINT# file number,"SCRATCH [drive number]:filename "
Example: PRINT#15,"SCRATCHO:MY BACK " i!EBIE
You can abbreviate the SCRATCH command as follows:
PRINT#15,"SO:MY BACK " B!lllE
The above examples erase the file named "MY BACK " from the disk in
driveO.
167
166
• BASIC STATEMENTS DATA
DATA constant list
Example: CLOSE 2 !iii&llE (Closes file 2) DATA 12, 14.5, " HELLO, MOM " , 3.14, PART 1
CLR DEF FN
This statement clears the value of any variables in memory, but leaves the This command allows you to define a complex calculation as a function
program itself intact. with a short name. In the case of a long formula that is used many times
within the program, this can save time and space .
Example: CLR !ial&E The function name will be FN and any legal variable name (1 or 2 charac-
ters long). First you must define the function using the statement DEF fol-
CMD lowed by the function name. Following the name is a set of parentheses
CMD file number [,string] enclosing a numeric variable. The actual formula that you want to define
then follows , with the variable in the proper spot. You can then "call " the
CMD sends output which normally goes to the screen , to the specified file formula, substituting any number for the variable.
corresponding to another device. This can be a printer file or a data file on
tape or disk. The file must be OPENed first. Example:
Example: OPEN 4,4 (Open file 4 on device 4-the printer) 10 DEF FNA(X) =
12*(34.75 - X/.3)
CMD4 20 PRINT FNA(7} f
LI ST (Lists the program in memory on printer) f J 7 1s inserted where
X 1s in !he fo rmula
PRINT#4 (Close channel to printer)
CLOSE 4 (Close file 4) For this example, the result would be 137.
You can specify an optional string in the CMD command . Any characters DIM
in the specified string are output to the device.
DIM variable (subscripts) [,variable(subscripts)] ...
Example:
Before you can use an array, you must first execute a DIM statement to
OPEN 4,4, (Open file 4 on device 4)
establish the DIMensions of the array. If the array has less than 11 elements
CMD 4,"Anybody out there? " (Send screen output to printer)
you do not need a DIM statement since the Commodore 64 automatically
PRINT#4 (Close channel to printer)
DIMensions each variable to 10 elements.
CLOSE 4 (Close file 4)
The DIM statement is followed by the name of the array, which may be any
legal variable name. The array name is followed by an integer enclosed in
parentheses. The integer specifies the number of elements in each dimen-
sion . You may use any number of dimensions, but keep in mind that eadi
169
168
array element uses memory. To figure out the total number of array elements following the FOR . . . TO statement is executed . If the loop var iable is greater
in each array, multiply the number of elements in each dimension of the than the end of loop value , the statement directly following the NEXT state·
array. ment is executed . If the loop variable value is negative, the loop is executed
until it becomes less than the end value. See the NEXT STATEMENT
NOTE: Integer arrays use only 40% of the space of floating point
Example:
arrays .
Example:
10 FOR L =
1 TO 20
20 PRINT L
10 DIM A$(40),B7(15},CC %(4,4,4} 30 NEXT L
Array A$ has 41 elements 40 PRINT "BLACKJACK! L = "L
Array B7 has 16 elements
This program prints the numbers from one to twenty on the screen , fol-
Array CC % has 125 elements
lowed by the message BLACKJACK! L =
21 .
You can dimension more than one array in a DIM statement by separat ing You can set up loops inside one another. This is known as nesting loops.
the arrays with commas. If you execute a DIM statement more than once for Nest loops so that the inner FOR .. . TO statement and the corresponding
each array within a program , a REDIM 'D ARRAY ERROR message is dis· NEXT statement are both in between the outer FOR ... TO statement and
played . It is good programming practice to place DIM statements near the corresponding NEXT statement. Remember that in nesting , the last loop to
beginning of the program . start is the first one to end.
170 171
Example: Example:
10 GET A$:1F A$ "" THEN 1O: REM Wait for a key to be pressed to 10 PRINT "REPETITION IS THE MOTHER OF LEARNING "
continue . 20GOTO 10
The GOTO in line 20 causes the program to be run continuously, until the
GET# RUN/STOP key is pressed .
GET# file number, variable list
IF . .. THEN
The GET# statement inputs data from a previously opened file on a periph-
eral device, one character at a time . The character is assigned to the speci- IF expression THEN statement(s)
fied variable name. This command can only be executed within a program .
The IF .. . THEN statement evaluates a condition and executes one of two
Example: possible program segments, depending on whether the condition is true or
false. If the expression is true , the BASIC statement directly following the
10 GET#1.A$ word THEN is executed. If the expression is false , the program continues to
the program line directly following the line containing the IF statement. The
GOSUB evaluated expression is usually a mathematical expression containing rela-
GOSUB line number tional or logical operators ( = , < , > , < = , > = , <> , AND , OR, NOT). The
IF .. . THEN statement is the computer 's way of making a decision.
The GOSUB statement calls a separate and independent program seg-
ment called a subroutine. When a GOSUB statement is encountered in a Example:
program, the computer jumps to a subroutine, and executes it. When a
RETURN statement is encountered in the subroutine, the computer jumps
50 IF X =0 THEN PRINT "OK "
60 PRINT "REST OF PROGRAM"
back to the instruction directly following the GOSUB statement in the main
program . Evaluates the value of X. If X equals 0, the computer PRINTS "OK " and
continues with line 60. If X does not equal 0, the part following the word
Example: THEN is skipped and the program continues with line 60.
1OGOSUB800: REM Jump to the subroutine at line 800 and execute it.
INPUT
800 PRINT "HI THERE " INPUT [" prompt string ";] variable list
810 RETURN The INPUT statement accepts characters from the keyboard and stores
them in the specified variable name. The program pauses, displays a ques-
GOTO tion mark (?) on the screen , and waits for you to type a response and press
the RETURN key. The ma ximum amount of characters you can INPUT is 77.
GOTO line number The word INPUT is followed by a variable name or list of variable names
separated by commas. You can include a message enclosed in quotes called
The GOTO statement jumps to and executes the instructions starting at a prompt before the list of input variables. If the prompt is present , there
the speciiied line number. When used in direct mode the GOTO statement must be a semicolon(:) after the closing quote. When more than one variable
starts execL tion of a program at the specified line number. is INPUT, separate them with commas. If you don 't, the computer asks for
the remaining input variable values by displaying two question marks(??) on
172 173
the screen. If you press the RETURN key without INPUTting a value , the the loop cycles again . If the index variable is greater than the limit of the
INPUT variable retains the value previously input for that variable . This state- loop. the program continues with the statement directly following the NEXT
ment can on ly be executed within a program . statement.
Specifying a variable is optional in a NEXT statement , though it may be
Example:
followed by a variable name or a list of variable names separated by com-
10 INPUT " Number of Ice Cream Cones" ;A$ mas. If there are no names listed, the last loop started is the one incre-
mented. If the variables are specifiep , they are incremented in order from left
INPUT# to right.
INPUT# works like INPUT except it takes data from a previously OPENed 10 FOR L = 1TO10:NEXT
file or device instead of the keyboard . No prompt string is allowed . Th is com- 20 FOR L = 1TO10:NEXT L
mand can only be used in prog ram mode. 30FORL = 1T010FORM = 1T010: NEXTM . L
Example: ON
101NPUT#2, A$ , C,D$
ON expression GOTO/GOSUB line #1 , line #2 , .
(Inputs three variable values from file 2.)
This statement makes the GOTO and GOSUB statements into conditional
LET statements like the IF ... THEN sta tement. The word ON is followed by a
mathematical expression and either a GOSU B or GOTO statement and a list
[LET] variable = expression
of line numbers. The result of the expression determines which line number
LET is rarely used in programs , since it is not necessary. Whenever a or subroutine is executed . If the result of the expression is 1, the first line in
var iable is assigned a value, LET is always implied. The variable name which the list is executed . If the result 1s 10, the tenth line number 1s executed , and
receives a value is on the left side of the equal sign , and the value itself is on so on . The result of the expression should not exceed the number of line
the right side. numbers in the list. If the result is larger than the number of line numbers 1n
the list or zero , the program continues with the line directly following the ON
Example : statement. If the number is negative. an ILLEGAL QUANTITY ERROR results .
10 LET A = 5 Example:
20 LET B = 6
LET is specified (but not necessary) in lines 1O and 20. 10 INPUTX:IF X<OTHEN 10 When X = 1, ON sends control to
LET is implied in lines 30 and 40. the first line number 1n the list
30C =A* B + 3
40 0$ = " HELLO " 20 ON X GOTO 50 , 30 , 30. 70 When X = 2, ON sends control to
the second line (30), etc.
NEXT 25 PRINT " FELL THROUGH ": GOTO 10
30 PR INT " TOO HIGH ": GOTO 10
NEXT [index variable ,.... ,variable] 50 PRINT " TOO LOW " :GOTO 10
The NEXT statement completes a FOR ... NEXT loop. When the computer 70E ND
encounters a NEXT statement, the program goes back to the corresponding
FOR .. . TO statement and checks the index variable. If the index variable is
less than or equal to the limit of the loop in the FOR ... TO statement ,
174 175
OPEN OPEN 4,4 OPENs a channel to use the printer.
OPEN file number, device number [.secondary address[. " filename[. type , OPEN 15,8, 15 OPENs the disk drive command channel.
mode " ]]] 5 OPEN 8,8,12,"TESTFILE ,SEQ,W" Opens a sequential disk file for
writing .
The OPEN statement opens a channel to a peripheral device such as a
See also: CLOSE, CMD , GET#, INPUT#, and PRINT# statements.
printer, disk drive or Datassette for input and output operations. The word
OPEN is followed by a logical file number and a device number. The OPEN
POKE
statement can also include the following optional information: secondary
address, a filename, a file type and a file mode. POKE address, value
The logical file number is the number assigned to a file between 1 and
255. The logical file number is referred to by the other input and output com- The POKE statement changes the contents of a Commodore 64 Random
mands such as PRINT#, INPUT#, CMD and CLOSE. The OPEN statement Access Memory (RAM) location . The word POKE is always followed by two
associates a file number to a device number. numbers. The first number is a memory location. This can have a value from
The device number is the number assigned to a peripheral device. For O to 65535. The second number is a value from O to 255, which is placed in
example , device 1 is the Datassette, device 4 is the printer and device 8 is the location, replacing any value that was there previously.
the disk drive. The device number is implied in other input and output state- Example:
ments with the logical file number.
The optional secondary address specifies an input or output operation on 10 POKE 28000,8 Places the value 8 in location 28000
a peripheral device. For example , secondary address 0 on the Datassette 20 POKE 28 * 1000,27 Places the value 27 in location 28000
specifies a read operation from tape. Secondary address 1 specifies a write
operation . These secondary addresses specify, different operations on dif- PRINT
ferent devices. Consult your peripheral 's user 's guide for more secondary PRINT print list
address information .
The OPEN statement may specify a filename enclosed in quotation marks, The PRINT statement outputs characters to the screen . The word PRINT
but it is not required for printer or tape files . The filename has a ma ximum can be followed by any of the following:
length of 16 characters .
Characters inside of quotes ("text lines " )
File type specifies which kind of files are being used. There are four types
Variable names (A 1, B, A$, X$)
of disk drive files: sequential (SEO), relative (REL) , program (PRG) and user
Functions (SIN(23), ABS(33))
(USR) files . The Datassette uses only program and sequential files . If the file
Punctuation marks (; ,)
type is not specified , the disk drive and Datassette assume it is a program
file unless the mode is specified. The characters inside of quotes are referred to as literals since they are
The mode specifies what type of output operation is performed. The PR INTed exactly as they appear. When a var ,abie name is PRINTed. the con-
modes are Read (R) , and Write (W) . The mode is usually specified when using tents of the variable is PRINTed, not the variable name (unless it appears
disk files . within quotation marks).
If more than one variable is PRINTed, they must be separated by commas
Example:
or semi-colons. A comma places 15 spaces between each output variable or
10 OPEN 3,3 OPENs the SCREEN as a device. string. A semi-colon PRINTs output variables and strings separated by one
100PEN 1,0 OPENs the keyboard as a device. space .
200PEN 1,1,0," UP " OPENs the Datassette for reading ; file to be
searched for is named UP
176 177
Example : Example:
Th is statement is used to get information from DATA statements into varia- STOP
bles , where the data can be used. The READ statement variable list may
STOP
contain both strings and numbers. Care must be taken to avoid reading
strings where the READ statement expects a number, which produces a The STOP statement halts execution of a program . The message, BREAK
TYPE MISMATCH ERROR message. IN LINE #, is displayed when the program encounters the line number that
Example: contains the STOP statement. The program can be re-started at the state-
ment following STOP using the CONT command . The STOP statement is com-
Read A$ , G$ monly used while debugging programs .
REM SYS
SYS address
REM message
The REMark is just a note to whoever is reading a LISTing of the program . The SYS statement is followed by a decimal number or numeric variable in
It may explain a section of the program , give information about the author, the range 0 to 65535. The program begins executing a machine language
etc . REM statements in no way effect the operation of the program , except to program starting at the specified address. This is similar to the USA function
add to its length. The word REM may be followed by any text , although but does not pass a parameter. See the Commodore 64 Programmer 's Refer'.
graphic characters mcy cause unexpected results. ence Guide for information about machine language programs .
178 179
WAIT • BASIC FUNCTIONS
WAIT address, value 1, value 2
NUMERIC FUNCTIONS
The WAIT statement is used to halt a program until the contents of a mem-
ory location change in a specific way. The address must be in the range Numeric functions return a numeric value . The functions they perform
between o to 65535. Value 1 and value 2 must be in the range between 0 and range from calculating mathematical functions to specifying the contents of
255. a memory location . Numeric functions follow the form :
The contents of the memory location is first logically ANDed with value 1. FUNCTION (argument)
If value 2 is present , the specified memory location is exclusive-~Red wi_th
value 2. If the result is zero, the program checks the memory location again . where the argument can be a numerical value , variable, or string .
When the result is not zero, the program continues with the statement ABS(X) (absolute value)
directly following WAIT
The absolute value function returns the positive value of the argument X.
ASC(X$)
This function returns the ASC II code (number) of the first character of X$.
ATN(X) (arctangent)
INT(X) (integer)
Returns the integer portion of X, with all decimal places to the right of the
decimal point removed. The result is always less than or equal to X. Thus , any
negative numbers with decimal places become the integer less than their
=-
current value (e.g . INT(- 4.5) 5).
181
180
If the INT funct ion is to be used for rounding up or down, the form is INT(X SGN(X) (sign)
+ I - .5)
This function returns the sign , as in positive , negative, or zero, of X. The
Example: result is + 1 if positive , 0 if zero , and - 1 if negative.
INT (4.75 + .5) SIN(X) (sine)
LOG (X) (logar ithm) This is the trigonometric sine function . The result is the sine of X, where x
Th is returns the natural log of X. The natural log is log to the base e (see is an angle in radians.
EXP(X)). To convert to log base 10, divide by LOG{10). SQR(X) (square root)
PEEK(X) This function returns the square root of X, where X is a positive number or
This function gives the contents of memory location X, where X is located 0. If X is negative, an ILLEGAL QUANTITY ERROR results .
in the range of 0 to 65535, returning a result from 0 to 255. Th is is often used TAN(X) (tangent)
in coniunction with the POKE statement.
This gives the tangent of X, where X is an angle in radians .
RN D(X) (random number)
USR(X)
This function returns a random number between 0 and 1. This is useful in
games, to simulate dice rolls and other elements of chance , and is also used When this function is used, the program jumps to a machine language
in some statistical applications. The first random number should be gener- program whose starting point is conta ined in memory locations 785 and 786.
ated by the formula RND(O), to start things off differently every time . After The parameter X is passed to the machine language program in the floating
this , the number X should be a 1, or any posit ive number. (X represents the point accumulator. Another number is passed back to the BASIC program
seed , or what the RaNDom number is based on .) If X is zero, RND is re- through the calling variable . In other words, this allows you to exchange a
seeded from the hardware clock every time RND is used. A negative value variable between machine code and BASIC. See the Commodore 64 Pro-
for X seeds the random number generator using X and gives a random num- grammer 's Reference Guide for more details on this, and on mach ine lan-
ber sequence . The use of the same negative number for X as a seed results guage programming.
in the same sequence of random numbers. A positive value gives random VAL(X$)
numbers based on the previous seed .
To simulate the rolling of a die, use the formula INT(RND{1)*6+ 1). First This function converts the string X$ into a number, and is essentially the
the random number from 0 to 1 is mult iplied by 6, which expands the range inverse operation from STR$. The string is examined from the left-most char-
from 0 to 6 (actually, greater than zero and less than six). acter to the right , for as many characters that are recognizable . If the Com-
Then 1 is added , making the range 1 to 7. The INT function truncates the modore 64 finds illegal characters , only the portion of the string up to that
decimal places, leaving the result as a digit from 1 to 6. point is converted .
To simulate 2 dice , add two of the numbers obtained by the above formula
together. STRING FUNCTIONS
Example: String functions differ from numeric functions in that they return charac-
ters , graphics or numbers from a string (defined by quotation marks) instead
100 X = INT(RND(1)*6) + INT(RND(1)*6) + 2 Simulates 2 dice of a number.
100X=INT(RND(1)*1OOO)+1 Number from 1-1000.
100 X + INT(RND{1)*150) + 100 Number from 100-249. CHR$(X)
182 183
LEFT$(X$,X) SPC(X)
This function returns a string containing the leftmost X characters of X$. This function is used in the PRINT statement to skip X spaces . x can have
a value from 0-255 .
LEN(X$)
TAB(X)
This function returns the numbP.r of characters (including spaces and
other symbols} in the string X$. This function is used in the PRINT statement. The next item to tie printed is
in column number X. X can hGve a value from Oto 255 .
MID$(X$,S,X)
RIGHT$(X$,X)
STR$(X)
Example:
A$=STR$(X}
OTHER FUNCTIONS
FRE(X)
This function returns the number of available bytes in memory. X is a
dummy argument.
POS(X)
This function returns the number of the column (0-79) where the next
PRINT statement begins on the screen . X is a dummy argument.
184 185
ARRAYS
• VARIABLES AND OPERATORS
Arrays are lists of variables with the same name, using an extra number
VARIABLES (or numbers) to specify an element of the array. Arrays are defined using the
The Commodore 64 uses three types of variables in BASIC. These are : DIM statemen t, and may be floating point. integer, or string variables arrays .
floating point numeric , integer numeric, and string (alphanumeric) variables . The array variable name is fol lowed by a se t of parentheses ( ) enclosing
the number of the variable in the list.
FLOATING POINT VARIABLES can be displayed up to nine digits. When a
number becomes larger than nine digits, as in 109 or 10-•, your computer Examples: A(7) ,BZ % (11),A$(87)
displays it in scientif ic notation form . For example , the number 12345678901
is displayed as 1.234356789E + 10. There is a limit to the size of float ing- Arrays may have more than one dimension . A two dimensional array may
point numbers that BASIC can handle, even in scientific notation . The largest be viewed as having rows and columns, with the first number identifying the
number is + 1.70141183E + 38. Calculat ions wh ich result in a larger numbe r row and the second number in the parentheses identifying the column (as if
will display the BASIC error message ?OVERFLOW ERROR. The smallest specifying a certain grid on a map).
float ing-point number is + 2.93873588E - 39. Calculat ions which result in a Examples: A(7,2),BZ%(2 ,3, 4),Z$(3,2)
smaller value give you zero as an answer and NO error message.
INTEGER VARIABLES can be used when the number is from + 32767: to RESERVED VARIABLE NAMES
- 32768 , and with no fractional portion. An integer variable is a number like
5, 10, or - 100. Integers take up less space than float ing point variables , There are three va riable names which are reserved for use by the Commo-
particularly when used in an array. dore 64, and may not be used for another purpose . These are the variables
STRING VAR IABLES are those used for character data, which may contain ST, TI , and TI$. You also can't use KEYWORDS such as TO and IF, or any
numbers, letters and any other character that your Commodore 64 can names that contain KEYWORDS , such as SRUN , ANEW, or XLOAD as varia-
make. An example of a string var iable is A$= " COMMODORE 64". ble names.
ST is a status variable for input and output (except normal screen/
VARIABLE NAMES keyboard operations). The value of ST depends on the results of the last
input/output operation. A more detailed explana tion of ST is in the Commo-
Variable names may consist of a single letter, a letter followed by a num-
dore 64 Programmer's Reference Guide, but in general, if the value of ST 1s o
ber, or two letters. Variable names may be longer than 2 characters, but on ly the opera tion was successful.
the first two are significant.
TI and TI$ are variables that relate to the rea l-time clock built into your
An integer variable is specif ied by using the percent (% ) sign after the
Com modore 64 . The system clock is upda ted every 1/60th of a second. It
variable name. String variables have the dollar sign($) after their names.
~tar t s at 0 when your Commodore 64 is turned on, and is reset only by chang-
Examples: ing the va lue of TI$. The variable TI gives you the current value of the clock in
Numeric Var iable Names: A, AS , BZ 1/60ths of a second.
Integer Variable Names: A %, A5 %, BZ % TI$ is a six-character string that reads the value of the real -ti me clock as a
String Var iable Names: A$, A5$ , BZ$ 24 hour clock . The first two characters of TI$ contain the hour, the next two
cha racters are the minutes, and the last two characters are the seconds.
This variable can be set to any value (so long as all characters are numbers).
and will be automatically updated as a 24 hour clock.
Example: TI$ = ·' 101530' ·sets the clock to 10:15 and 30 seconds (AM)
186 187
These are used most often to join multiple formulas in IF ... THEN state-
The value of the clock is lost when your Commodore 64 is turned off. It ments. When they are used with arithmetic operators, they are evaluated
starts at zero when your computer is turned on , and is reset to zero when the
last.
value of the clock exceeds 235959 (23 hours, 59 minutes and 59 seconds).
Examples:
BASIC OPERATORS IFA=BANDC=DTHEN 100 Requires both A= B & C = D to be
true .
The· ARITHMETIC operators include the following signs: IFA=BORC=DTHEN 100 Allows either A= B or C = D to be
true .
+ addition
A=5:B=4:PRINTA=B Displays a value of 0
- subtraction
A= 5:8 = 4:PRINT A> B Displays a value of - 1
• multiplication
PRINT 123 and 15:PRINT 5 OR 7 Displays 11 and 7
I division
i exponentiation (raising to a power)
On a line containing more than one operator, there is a set order in which
operations always occur. If several operators are used together, the com-
puter assigns priorities as follows : First , exponentiation , then multiplication
and division , and last, addition and subtraction . If two operations have the
same priority, then calculations are performed in order from left to right. If
you want these operations to occur in a different order, Commodore 64
BASIC allows you to give a calculation a higher priority by placing parenthe-
ses around it. Operations enclosed in parentheses will be calculated before
any other operation . You have to make sure that your equations have the
same number of left parentheses as right parentheses, or you will get a
SYNTAX ERROR message when your program is run .
There are also operators for equalities and inequalities, called RELA-
TIONAL operators. Arithmetic operators always take priority over relational
operators .
equal to
< less than
> greater than
< = or = < less than or equal to
> = or = > greater than or equal to
< > or > < not equal to
Finally, there are three LOGICAL operators, with lower priority than both
arithmetic and relational operators :
AND
OR
NOT
189
188
GLOSSARY
191
The following glossary contains definitions for some of the computer
terms used in this Guide. Most of the terminology in the glossary is universal.
However, there are certain terms that are unique to the Commodore 64 .
Consult the Commodore 64 Programmer's Reference Guide for more
detailed information on the Commodore 64 computer.
Attack-The rate at which the volume of a musical note rises from zero to
peak volume.
Background Color-The color of the portion of the screen that does not
contain characters. The background color is dark blue when you turn on the
Commodore 64 .
Bit-The abbreviation for binary digit. A bit is the smallest unit in a computer.
Each binary digit can have one of two values , zero or one . A bit is referred to
as enabled or "on" if it equals one . A bit is disabled or " off" if it equals zero.
193
Bit Map Mode-An advanced graphic mode in the Commodore 64 in which C dTon-Expression(s) between the words IF and THEN , evaluated as
you can control every dot on the screen . ei~:er\;ue or false in an /F ... THEN statement. The _conditional IF ... THEN
statement gives the computer the ability to make dec1s1ons.
Border Color-The color of the edges around the screen. The border co/or
is cyan (light blue) when you turn on the Commodore 64 . Coordinat e-A single point on a grid having vertical (Y) and horizontal (X)
values.
Branch-To jump to a section of a program and execute it. GOTO and
GOSUB are examples of BASIC branch instructions. Counter-A variable used to keep track of the number of times an event has
occurred in a program.
Byte-The number of bits that make up the smallest unit of addressable
storage in a computer. Each memory location in the Commodore 64 contains Crunch-To minimize the amount of computer memory used to store a
one byte of information. One byte is the unit of storage needed to represent program.
one character in memory. One byte is made up of eight bits. See Bit.
Cursor-The flashing square that marks the current location on the screen.
Character-Any symbol on the computer keyboard that is printed on the
screen . Characters include numbers, letters, punctuation and graphic Data-Numbers , letters or symbols that are input into the computer to be
.symbols. processed .
Character Memory-The area in Commodore 64 's memory which stores Datassette-A device used to store programs and data files sequentially on
the encoded character patterns that are displayed on the screen. tape .
Character Set-A group of related characters. The Commodore 64 char- Debug-To correct errors in a program.
acter sets consist of: upper-case letters, lower-case letters and graphic
characters. Decay-The rate at which the volume of a musical note decreases from its
peak value to a mid-range volume called the sustain level. See Sustain.
Character String Code-The numeric value assigned to represent a Com-
modore 64 character in the computer 's memory. Decrement-To decrease an index variable or counter by a specific value .
Chip-A miniature electronic circuit that performs a computer operation Delay Loop-An empty FOR ... NEXT loop that slows the execution of a
such as graphics, sound and input/output. program .
Color Memory-The area in the Commodore 64 's memory that controls the Dimension-The property of an array that specifies the directio_ n alon_g an
color of each location in screen memory. axis in which the array elements are stored. For example , a two-d1mens1onal
array has an X-axis for rows and a Y-axis for columns. See Array.
Command-A BASIC instruction used in direct mode to perform an action .
See Direct Mode. Direct Mode-The mode of operation that executes BASIC commands
immediately after the RETURN key is pressed. Also called Immediate Mode.
Computer-An electronic, digital device that stores and processes in- See Command.
formation .
Disable-To turn off a bit , byte or specific operation of the computer.
194 195
Disk Drive-A random access , mass-storage device that saves and loads Home-The upper-left corner of the screen.
files to and from a floppy diskette.
Increment-To increase an index variable or counter with a specified value .
Duration-The length of time a musical note is played.
Index-The variable counter within a FOR .. . NEXT loop.
Enable-To turn on a bit , byte or specific operation of the computer.
Input-Data led into the computer to be processed. Data can be input
Envelope Generator-Portion of the Commodore 64 that produces specific through the keyboard , disk drive, Datassette or modem.
waveforms (sawtooth, triangle, pulse width and noise) for musical notes. See
Waveform . Integer-A whole number containing no fractional part.
Execute-To perform the specified instructions in a command or program Interface-An attachment that connects a computer to a peripheral device.
statement.
Keyboard-Input component of a computer system .
Expression-A combination of constants, variables or array elements acted
upon by logical , mathematical or relational operators that return a numeric Kilobyte (K)-1,024 bytes.
value.
Loop-A program segment executed repetitively a specified number of
File-A program or collection of data stored on diskette or cassette. times.
Firmware-Computer instructions stored in ROM , as in a game cartridge. Machine Language-The lowest level language the computer understands.
The computer converts all high-level languages such as BASIC into machine
Frequency-The number of sound waves per second of a tone. The fre- language before executing any statements.
quency corresponds to the pitch of the audible tone.
Matrix-A two-dimensional rectangle with row and column values .
Function-A predefined operation that returns a single value.
Memory-Storage locations inside the computer. ROM and RAM are two
Function Keys-The eight keys on the far right of the Commodore 64 key- different types of memory.
board. Each key can be programmed to execute a series of instructions.
Memory Location-A specific storage address in the computer. There are
Graphics-Visual screen images representing computer data in memory 65,536 memory locations (0-65535) in the Commodore 64.
(1.e .. characters. symbols and pictures).
Mode-A state of operation.
Graphic Characters-Non-alphanumeric characters on the computer 's
keyboard . Modem-Abbreviation for modulator-demodulator. A modem is a computer
attachment that interfaces a computer to a telephone . This allows you to
Grid-A two-dimensional matrix divided into rows and columns. Grids are communicate with other computers using the same lines as your telephone.
used to design sprites and programmable characters .
Monitor-Video screen.
Hardware-Electronic components in a computer system such as key-
board. disk drive and printer. Multi-Color Character Mode-A graphic mode that allows you to display
four different colors within an 8 X 8 character grid.
196 197
Multi-Color Bit Map Mode-A graphic mode that allows you to display one Programmable-Capable of being processed with computer instructions.
of four colors for each pixel within an 8 X 8 character grid. See Pixel.
Program Line-A statement or series of statements preceded by a line
Null String-An empty character( ""). A character that is not yet assigned a number in a program . The maximum length of a program line on the Commo-
character string code. Produces an illegal quant ity error if used 1n a GET dore 64 is 80 characters.
statell!ent.
Random Access Memory (RAM)-The programmable area of the comput-
Octave-One full series of eight notes on the musical scale. er's memory that can be read from and written to (changed). All RAM loca-
tions are equal ly accessible at any time in any order. The contents of RAM
Operating System-A built-in program that controls everything your com - are erased when the computer is turned off.
puter does.
Random Number-A nine-digit decimal number from 0.000000001 to
Operator-A symbol that tells the computer to perform a mathematical , 0.999999999 generated by the RND function.
logical or relational operation on the specified variables, constants or array
elements in the expression. The mathematical operators are + , - . •. / and Read Only Memory (ROM)-The permanent portion of the computer's
i . The relational operators are < ,=, >. < =. => and < > . The logical memory. The contents of ROM locations can be read , but not changed. The
operators are AND , OR and NOT. ROM in the Commodore 64 contains the BASIC language interpreter, charac-
ter image patterns and portions of the operating system .
Order of Operations-Sequence in which computations are performed in a
mathematical expression . Also called Hierarchy of Operations . Register-Any memory location in RAM . Each register stores one byte . A
register can store any value between 0 and 255 in binary form.
Peripheral -Any accessory device attached to the computer such as a disk
drive, printer, modem or joystick. Release-The rate at which the volume of a musical note decreases from
the sustain level to zero.
Pitch-The highness or lowness of a tone that is determined by the fre-
quency of the sound wave . See Frequency. Remark-Com ments used to document a program . Remarks are not exe-
cuted by the computer, but are displayed in the program listing .
Pixel-Computer term for picture element. Each dot on the screen that
makes up an image is called a pixel. Each character on the screen is dis- Resolution-The density of pixels on the screen that determine the fineness
played within an 8 X 8 grid of pixels. The entire screen 1s composed of a 320 of detail of a displayed image.
X 200 pixel grid. In bit map mode, each pixel corresponds to one bit in the
computer's memory. Screen-Video display unit which can be either a television or video
monitor.
Pointer-A register used to indicate the address of a location in memory.
Screen Code-The number assigned to represent a character in screen
Printer-Peripheral device that outputs the contents of the computer's memory. When you type a key on the keyboard , the screen code for that
memory onto a sheet of paper. This paper is referred to as a hard copy. character is entered into screen memory automatically. You can also display
a character by storing its screen code directly into screen memory with the
Program-A series of instructions that direct the computer to perform a POKE command.
specific task . Programs can be stored on diskette or cassette , reside in the
computer 's memory, or be listed on a printer.
198 199
Screen Memory-The area of the Commodore 64 's memory that contains Video Interface Controller (VIC)-The MOS 6566 chip responsible for all
the information displayed on the video screen. The Commodore 64 screen the graphics features of the Commodore 64 . See the Commodore 64 Pro-
memory ranges from memory location 1024 through 2023. grammer's Reference Guide for chip specifications.
Software-Computer programs stored on diskette or cassette that can be Voice-A sound producing component inside the SID chip. There are three
loaded. into random access memory. voices within the SID chip so the Commodore 64 can produce three different
sounds simultaneously. Each voice consi sts of a tone oscillator/waveform
Sound Interface Dev ice (SID)- The MOS 6581 sound synthesizer chip generator, an envelope generator anu an amplitude modulator.
responsible for all of the audio features of the Commodore 64. See the Com-
modore 64 Programmer's Reference Guide for ch ip specifications. Waveform-A graphic representation of the shape of a sound wave . The
waveform determines some of the physical characteristics of the sound .
Sprite-A programmable, movable, high-resolution graphic image. Also
called a movable object block (MOB).
200 201
• INDEX
Binary, 193
A
Bit , 193
Abbreviations-BASIC, 152-154 Bit Map mode, 103, 194
ABSolute function , 41 , 181 Books , 158- 159
Accessories , 11 Byte 77 , 194
Addition, 36
ADSR, 112 c
Animation , 83 , 97 Cartridge slot , 124
Arrays , 63-64, 187 Cartridges, 27
ASC function , 70, 181 Cassette tape recorder, 11
ASCII character codes, 141-143 Channel selector, 125
Asterisk key, 31 , 37 Character Display mode, 103
At symbol, 49 Checklist , 134
Attack, 149, 193 CHR$codes , 141-143
ATN function , 181 CHR$ function , 70, 76, 183
Automodem , 14 CLR statement , 168
B CLR/HOME key, 23
Clock, 187
BASIC CLOSE statement , 50 , 168
abbreviations, 152-154 CMD , 168
commands, 39 , 47-50 , 56, Colon , 65
162-167 Col or
conversions, 155 code display, 76
language, 35 , 193 control , 75
math functions , 40-41 CHR$ codes , 76
numeric functions , 40 , 72 , keys , 76
181-182 memory map, 82 , 137
operators , 37, 45 screen and border registers , 77
control functions , 184-185 screen codes , 79
statements , 45 , 53-56 , 61-69, Comma , 36
168-180 Command , BASIC, 194
string functions, 70-71 , 183- 184 Commodore Information network,
variables , 42-44 , 186-188 122
203
Commodore key, 23 , 75 L p
F
Commodore Library, 135 LEFT$ function , 184
File , 176, 196 Paddles , 13
Compuserve, 122 LENgth function , 184
Floppy, 30 Parentheses, 38 , 50
Concatenat ion , 155 LET statement , 155, 17 4 PAUSE , 156
FN fun ction , 181
Connections , 123-128 LIST command , 49 , 162
FOR . .. NEXT statement, 53, 170 PEEK function , 69 , 182
constants , 42 LOAD command, 48- 49 , 163
Formatting disks, 47 Peripherals, 198
CONT command , 56 , 162 LOADing cassette software , 28-29 Pitch , 198
FRE funct ion , 184
ConTRoL key, 22 , 75 LOADing cartridge software, 28 Pixel , 87 , 198
Frequency, 149, 196
COPY command , 162 LOADing disk software , 30- 31
Function keys, 24 , 70 , 196 POKE statement , 69 , 177
Copying music, 109 LOGarithm funct ion , 182 Ports , 124-127
Copying programs , 35 G Loops, 64 , 171 POS function , 185
COSine function , 181
Game controls and ports , 124 PRINT statement , 36-39, 177
CuRSoR keys, 21 M
GET statement , 55 , 171 PRINT AT, 156
Cursor, 8 Printers, 12, 13
GET# statement , 172 Machine language, 179, 183, 197
Customer Support , 122 Magazine subscript ion , 122 PRINT#, 178
GOSUB statement, 67- 68, 172
D GOTO statement , 42 , 172 Memory, 69 , 77 , 197 Program , 198
Graphic keys , 24 Memory maps, 80-82 , 136-137 line numbering , 42
Datassette , 11
Graphic modes, 102 MID$ function , 184 mode, 41
DATA statement , 61 , 169
Modem, 13, 197 music, 110
Debug , 195
H Multicolors, 103, 197 Programmable keys, 24
Decay, 149, 195
Multiplication , 37 Progammer 's Reference Guide 32
DEFine statement , 169 High resolution mode, 103
Music programs, 109-111 104, 112, 147, 180 ' '
Delay loop, 80 HOME key, 23
Musical notes, 108, 147 Pulse , 149
DELete key, 21 , 22 Hyperbolic functions , 151
Musical scale , 107
Dice , 72 Q
DIMension statement , 63 , 66 , 169 N
Question mark, 37
Direct mode, 39 , 195 IF . . . THEN statement , 45, 173
NEW command , 165 Quotation marks, 38
Disk commands, 49-50 Initialize command , 50
NEXT statement , 53 , 174 Quote mode, 39
Disk Directory, 49 INPUT statement, 54, 173
Noise, 156
Disk Drive , 11 , 13, 30 INPUT#, 174 R
Null string , 198
Disk Software , 30 INSerT key, 21
Numeric variables, 71 RAM, 14, 69 , 199
Disks, 27 , 47 INTeger function , 40 , 72, 181
Division , 37 Integer variable, 186 0 RaN Dom function , 72 , 182
Dollar sign , 49 Random numbers, 72 , 156, 199
J ON statement , 68 , 175 READ statement , 61. 178
Duration , 108, 196
OPEN statement , 50, 176 Registers, 77 , 199
Joystick ports , 124
E Operating System, 198 Release, 149, 199
Joysticks, 13
Operators, 198 REMark statement, 178, 199
Editing programs, 46
K arithmetic , 37, 188 Replace a program , 49
END statement, 63 , 170
logical , 173, 189 Reserved variables, 187
Error messages, 117-120 Keyboard , 19-24
order of, 37 , 188-189, Restore key, 23, 102
EXPonent function, 181
198 RESTORE statement , 62 , 179
Extended background color, 104
relational , 45 , 173, 188 Return key, 20
204 205
RETURN statement , 67 , 179 STOP statement , 56 , 179 VERIFY command, 49, 166
STOP key, 22 , 45 VIC ch ip, 87, 20 1
RIGHT$ function , 184
Storing Programs , 47 Voice , 201
ROM , 14, 69
RUN command , 29, 31 , 165 String variables , 44 , 186 w
RUN/STOP key, 22 Strings , 44 , 71 , 200
STR$ function , 71 , 184 WAIT command, 180
s Subroutine , 67 , 200 Waveform , 149, 201
SAVE command , 47-48, 165 Subscripts , 200
Saving programs (tape), 47 Subtraction , 36
Saving programs (disk), 48 Sustain , 149, 200
SCRATCH command , 50, 166 Syntax, 163, 200
Screen codes , 138-140, 199 Syntax error, 119
Screen memory map , 81 , 136 SYS statement , 179
Semicolon , 36
T
serial port , 126
SGN function , 183 TAB funct ion , 39 , 185
Shift key, 20 TAN function , 183
Shift lock key, 21 Telecommunications, 122
SID chip, 107, 200 THEN , 45
SINe function , 183 TI variable , 187
Slash key, 37 TI$ variable , 187
Software Trackball , 13
business, 130 Troubleshoot ing chart , 9, 120-121
educational , 130-132
financial, 129
u
games , 132-133 Up arrow key, 37
music, 134 Upper case/graphic mode , 20
productivity, 128-129 Upper/Lower Case mode, 20
programming aids , 134 User groups , 122
using, 27-32 User port , 127
Song , 109 USR function , 183
Sound effects, 112-114
Sound registers , 108, 150 v
SPC function 40, 185 VALue function , 71 , 183
Sprite control , 94-99 Variables
Sprite programming , 100 array, 65
Sprite Register Map, 144-146 dimensions, 65
Sprite viewing area , 99 floating point , 186
Sprites , 87-94 , 200 integer, 186
SQuaRe function, 40, 183 numeric, 43
STEP, 84 , 170 string($) , 44 , 186
206 207
NEW!
RECREATIONAL
BLOCKBUSTERS
FOR YOUR
COMMODORE 64!
Don't Miss
Out On The Fun!
-- n
--·-
-··
JUST IMJl.GINE- NUMBER BUILDER- FISH-METIC-(Ages
(Ages 4-14) One of (Ages 8-13) You must 7-13) A whale of a
the most unique reach a designated mathematical learning
educational programs number, but how? game that teaches the
today! Children can Should you add , concepts of greater
create their own subtract, multiply or than , less than , and
animated stories and divide? By using the equal to in a game
watch as they come to correct sequence of type format. Apply
life . Different mathematical opera- these to positive and
background scenes tions , Number Builder negative whole
combine with allows you to arrive at numbers , fractions ,
animated objects and the number and in and decimals.
written stores to addition strengthen Includes 15
construct a film type your math skills . preliminary difficulty
sequence . Develops
spelling , reading and
creative writing skills .
Includes arcade type
format , several
difficulty levels , and
levels and an
additional super 16th
level for endless
c~ commodore
(Diskette) self test. (Diskette) challenge . (Diskette) COMPUTERS
COMMODORE 64 BOOKS NOTES
MATHEMATICS on the
Commodore 64---Learn the math
techniques that professional
programmers use. Covers a wide
variety of mathematical techniques
which you can incorporate in all
types of BASIC . Contains
numerous subroutines and
examples with illustrations.
ADVANCED PROGRAMMING
TECHNIQUES on the Commodore
64---Packed with advice and tips for
intermediate and advanced BASIC
programmers. Learn the shortcuts you
need to move up and become a more
" professional " programmer.
out of your
Conunodore co01puter.
. . . With Commodore magazines.
And save 20% off the regular newsstand price.
Subscribe to Commodore Power/Play and Commodore Microcomputers
magazines and you're on your way to realizing the full power and potential of your
new Commodore computer.
Each issue brings you new ways to use and enjoy your computer. The first word
on new software and hardware. Programming techniques for both beginners and
advanced users. In-depth product reviews of the best software and hardware. The
latest games or education and applications programs. Visits with other users who
have discovered new and interesting ways to use their Commodore computers.
You 'll find practical articles on linking up with user groups in your area.
Telecommunications and using on-line services such as CompuServe. Computer
music and art, and much, much more.
ln addition, every issue contains programs you can type in yourself and use right
away. There's entertainment and games or practical household and business
applications programs in each issue!
Together, they're the perfect combination of pure fun and productivity!
And if you take advantage of this pecial offer--0nly for new computer owners--
you can save as much as 20% off the regular newsstand price!
Subscribe now and get the most out of your Commodore
computer. And save as much as 20%!
·------------DETACH AND MAIL TODAv---- - - - - - - - - - - -
Please sign me up for
D year(s) of Power/Play and Microcomputers ( 12 issues total per year) at
S24/year (a savings of 20% off the regular newsstand price).
D year( s) of Power/Play only (entertainment and games----6 issues per
year) at SI 5/year.
D year(s) of Microcomputers only (more in-depth information about
practical ways to use your computer--6 issues per year) at S15/year.
All PRICES lN US CURRENCY Can:.dian add S'5 00 to c:ich subscription m cover postag~. Overseas: S25.00J6 issu~ (Includes posragc: ).
Name Phone _ _ _ _ _ _ __
Address _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __
City _ _ _ _ _ _ _ _ _ State _ _ _ _ Zip _ _ _ _ _ _ __
Signature _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __
METHOD OF PAYMENT
0 Enclosed is my check or money order for S (Make check or money
order payable to COMMODORE PUBUCATIONS)
0 Bill me IB 64
0 Charge my VlSA or MasterCard (circle one) Card number
Commodore Publications
Magazine Subscriptio n Department
Box 651
Holmes, PA 19043