Commodore 64 User Manual
Commodore 64 User Manual
COfuIPIJTERS
uSEf '5 r{AfflJAt $Tntaun*''r
CUITS
INFOR}TATION TO USER
"WARNINGT THIS EQUIPMENT HAS BEEN CERTIFIED TO COM)-' r --
THELIMITSFoRACLASSBCoMPUTINGDEVICE,PURSUANT-Cj.
PART J OF PART.15 OF FCC RULES' ONLY PERIPHEMLS ICCI,)--.:;
INPUT/OUTPUTDEVICES,TERMINALS,PRINTERS,ETC')CERT;:l-:
COMPLYWITHTHECLASSBLIMITSMAYBEATTACHEDTOTHS::""
PUTER.OPERATION\(ITHNON-CERTIFIEDPERIPHEMLSISL(:-'''
RESULT IN INTERFERENCE TO RADIO AND TV
RECEPTION.
pfir
*l*["ul j
'[;
fq iifl,* r: :#;,
S rr* -.'.- -:i ",
'0r. '- **- i:::.:-*
.l$-::l; . "--,_.-
;AE,-r:
-r- -r', ut
{,tE ::r i'\€:: -:
_c_ ".-:?i::"T[,nu.;
F (..- -- ri-n,,,
r lr.[*'--r,l th$
-
i\-;r:X:\:: :
3E :{ :i., \*ri"l i
F 5 I"r- I -I." ;fr
35 u'l{,! :; *-{
r *-
,,r:i r
.*,*
''{l;i
H
fr
ffs
fit
frt TABTE OF CONTENTS
*tt
h
h INTRODUCTION
h I. SETUP
o Unpocking ond Connect:rg --"e
a lnstollotion
Ccn
#,
*t
.
.
.
Optionol Connections
Operotion
Color Adlustmenr
h
*,s
2. GETTING STARTED
. Keyboord
h
h
. Bock to Normol
o Looding ond Soving Prog's-.
. PRINT ond Colculorions
t Precedence
{,t . Combining Things . .
h
k 3. BEGINNING BASIC PROGRAMT
o The Next Step..
.
GOTO.
* a Editing Tips . .
* a Voriobles
+
a IF. . . THEN.
* a FOR.. . NEXT Loops ...
H 4. ADVANCED BASIC
. lntroduction
Flrst Edition * o Simple Animotion
Ninth Printing Nested Loops
- 1984
* O
Copyright @) 1982 by Commodore Business Mochines, lnc.
All rights reserued. Pt O
.
INPUT
GET
Rondom Numbers ond Othe' F--,r*
This monuol is copyrighted ond conloins proprietory informotion. No pori of rhis publico- a/a, o Guessing Gome .
lion moy be reproduced, stored in o retrievol syslem, or tronsmitfed in ony form or by onv
meons, elecironic, mechonicol, photocopying, recording or otherwise, without the pric' *,' o Your Roll
wriiten permission of COMMODORE BUSINESS MACHINES, Inc'
*,t
#./-
t,J
#
tEl v
*g
*r"
*nn
h TABTE OF CONTENTS
*o
h
h INTRODUCTION . .... vii
I. SETUP I
. Unpocking ond Connecting the Commodore 64 . . . . 2
* . lnstolloiion 3
. Optionol Connections
*.t a Operotion
6
8
*.t . Color Adiustment ll
*" STARTED
h
*
2. GETTING
o Keyboord
o Bock to Normol
o Looding ond Soving Progroms
13
14
17
+
Editing Tips . 34
* o Voriobles 34
.IF. .THEN 37
.FOR,..NEXTLoops. 39
*
4. ADVANCED BASIC 41
* o lntroduction.....
a4 o Simple Animotion
42
e Nested Loops .
. INPUT
43
44
;h-
H .GET.
45
47
hotion, lt{o pqrl o{ thb pubSce
trkttriired h or47 fom or by cry
H a Rondom Numbers
o Guessing Gome .
ond Other Functions 48
50
Iry c *e:wi*, *+trctr tre Prior * . Your Roll 52
EL hc-
*r
*
c?
:
fr
. Rondom Grophics 53
fr
er APPENDICES
CHR$ ond ASC Functions 53
ar
fr
lntrod u ction
fr
58
o PEEKs ond POKEs E: SCREEN DtSpLAv :::::
60
o Screen Grophics F: ASCII ond CHRS :3::S
o Screen Memory Mop . .
62
62 # G: SCREEN AND CO-ai r{r;rri-
o Color Memory Mop .
o More Bouncing Bolls
64
65
fr H: DERIVING MATFE,,,:- ::- :
l: PINOUTS FOR INe_- : _*=,_
fi
.
J: PROGRAMS TO TQ'
K: CONVERTTNG STA\l:;: 3r
6. SPRITE GRAPHICS 67 fl COMMODORE 6: 3:J :
. lntroduction to Sprites
. Sprite Creotion
68
69
fr L: ERROR MESSAGES
M: MUSTC NOTE VATLiS
o Additionol Noies on Sprites 75 fJ N: BlBLlOGRApHy ,
fr
.
{i
K: CONVERTING STANDARD BASIC PROGRAMS
TO
67 CoMMODORE 64 BASIC .... 148
68 L: ERRORMESSAGES ...
h
r5O
69 M: MUSIC NOTE VALUES
N: BIBLIOGRAPHY.
....... 152
h
75
O: SPRTTE REGTSTER MAp ..
..... 156
76
....
h
159
P: COMMODORE 64 SOUND CONTROL SETTTNGS . . . 162
7l)
&
h
*
INDEX
r65
&
0
8I
h
h
88
8t
c0
h
*
90
*
9I
tn *
9l *
%
1r5
el4
AT
t
cl4
1n
r'@
*a
><
fr
c1t
a_r
fi
{t INTRODUCTION
fi congrotulotions, on your purchose of one of the best computers in the
{t world. You ore now the proud owner of the COMMODORE 64. Com-
modore is known os The Friendly Compuler compqny, ond port of
{t being friendly is giving you eosy to reod, eosy to use ond eosy ro
fs understond instruciion monuols. The coMMoDoRE 64 usER,s GUIDE is
designed to give you oll the informoiion you need to properly set up your
{: equipment, get ocquoinred with operoring the COMMODORE 64, ond
{s give you o simple, fun stort ot leorning to moke your own progroms.
For those of you who don,t wont to bother leorning how to progrom,
{t we've put oll the informotion you need to use commodore progroms or
fs other prepockoged progroms ond/or gome cortridges (third porty
softwore) right up front. This meons you don't hove to hunt through
{s entire book to get stoned.
the
type video gomes. Nor only thot, the spRrrE EDrroR rer's you onimore os
fr mony os I different picture levels or one time. The spRlrE EDlroR will
L,J
fG
production, the COMMODORE 64 ollows you ro connecr your oudio our-
put to olmost ony high-quolity omplificotion system.
While we're on the subiect of connecring the COMMODORE 64 tc
other pieces of equipment . . your system con be exponded by odding
occessories, known os peripherols. os your compuling needs gro,,v.
some of your options include items like o DATASSETTE* recorder or os
,l541
mony os 5, VIC disk drive storoge units for the progroms you moke
ond/or ploy. lf you olreody hove o vrc r54o disk drive your deorer con
updote it for use with the COMMODORE 64. you con odd o VIC dot
motrix printer to give you printed copies of your progroms, letters, in_
voices, etc. lf you wont to connect up with lorger computers ond their
mossive doto boses then iust plug in o VICMODEM cortridge, ond get
the services of hundreds of speciolists ond o voriety of informotion net-
works through your home or business telephone. Finolly if you,re one of
those people interested in the wide voriety of opplicotions softwore
ovoiloble in CP/M*x, the COMMODORE 64 con be firted wirh o plug-in
Z-80 microprocessor.
Just os importont os oll the ovoiloble hordwore is the foci thot this
USER'S GUIDE will help you develop your understonding of computers.
It won't tell you everything there is to know obout computers, but it will
refer you to o wide voriety of publicotions for more detoiled informotion
obout the topics presented. Commodore wonfs you to reolly enioy your
new COMMODORE 64. And to hove fun, remember: progromming is
not the kind of thing you con leorn in o doy. Be potient with yourself os
you go through the USER'S GUIDE. But before you siort, roke o few
minutes to fill out ond moil in fhe owner/registrotion cord thot come with
your computer. lt will ensure thot your COMMODORE 64 is properly
registered with Cornmodore Heodquorters ond thot you receive the most
up-to-dote informqtion regording fulure enhoncemenls for your mo-
chine. Welcome fo o whole new world of fun!!
NOIE,
Mony progroms ore under development while this monuol is being
produced. Pleose check with your locol Commodore deoler ond witl
Commodore User's Mogozines ond Clubs, which will keep you up *c
dote on the weolth of opplicotions progroms being written for thE
Commodore 64, worldwide.
*DATASSETTE
is o registered trodemork of Commodore Business Mochines, lnc.
** CP/M is o registered trodemork of Digitol Reseorch
lnc. Specificotions sub e:. .:
chonge.
vill
l.
,l:
* liL::'",:
i,.*--- -.. - "
*.
fl
UNPACKING AND CONNECTING THE
fr
(--"
COMMODORE 64
Lt
The following step-by-step instructions show you how to connect the
Commodore 64 lo your ielevision set, sound system, or monitor ond
{a
moke sure everything is working properly. {?
Before ottoching onything to the computer, check the contents of the
Commodore 64 contoiner. Besides this monuol, you should find the fol-
{?
lowing items: {1
l. Commodore 64 -?
2. Power supply (block box with on AC plug ond supply cord)
3. Video coble
{?
4. TV Switchbox (smoll silver box with short ontenno lecrds). {t
lf ony items ore missing check bock with your deoler immediotely for {t
o replocement.
o look ot the orrongement of the vorious
{? _.'_
First, let's toke
on the compuler ond how eoch functions.
connections
fl
SIDE PANEL CONNECTIONS
fl4 -
!,
I. Power Socket. The free end of the coble from the power supply is #
ottoched here lo supply power to the Commodore 64.
# C,els*qr r-tu.rlrr:r
2.
3.
?ower Swifch. Turns on power fo the Commodore 64-
Gome Ports. Eoch gome conneclor con occept o ioystick or gome
controller poddle, while the lightpen con only be plugged into the
4 . -:
gome port closest to the front of your computer.
* . v:.gr BC,,'- ,/':- : ".
REAR CONNECTIONS *
*
4. Cortridge Slot. The rectongulor slot io the left occepts progrom or
gome cortridges.
ta f',1 5TA r.A:
3 rr,
5. Chonnel Selecior. Use this switch to select which TV chonnel the l-'1' CO\\Bfil3,rrs -3 virJtfi
computer's picture will be disployed on.
6. TV Connector. This connector supplies both the picture ond sound to
your television set.
e
€-
7. Audio & Video Output. This connector supplies direct oudio, which
con be connected to o high quolity sound system, ond o "compos-
t4
ite" video signol, which con be fed into o television "monilor'" *
B. Seriol Porl. You con ottoch o printer or single disk drive direcily to
the Commodore 64 through this connector. #
,9.
!t
w-a
!,
??
*i,
3;
ilu',
'l ;
;--1'
zYl
rL-r
f_!
r.-_,
fs
g,*_r
f-t
;-l
a-t GAME
PORTS
POWER POWER
SWITCH SOCI(ET
t'1
{t
;*t
a*t <-ch. 3 Ch.4->
f1
t*_t
?*i CARTRIDGE CHANNEL
c-*3 slor TV
SELEcToR coNNEcToR
.. AUDIO/VIDEO SERIAL CASSEIIE
conlrcroR- porii rffirncr
USER
PORT
--',
--t
-12..-'l
-J
fi
i.;
>l-- I
-
-;-?
5---?
{,-l
itr:[] E
TV
SWITCH BOX |Ll
f7
T0 A T0 300 oHM
fl
rv stclnL
JACK
/\
V
ANTENNA
INPUT 77
77
i*'!
€'-'i
{r
t*l
ra
{?
7?
3. lf you hove o VHF onienno. disconnect it from your TV set. ri
4. Connect your VHF ontenno coble to the screw ierminols lobeled ,,on_ *
*
I
#
-h
fr
5'-3
fi
ft
gi-O
h
h
C-O
h
fr
fs
75 OHM TO
300 oHM
ADAPTER
fr
f3
YOUR 75 OHM
COAX VHF ANTENNA
fi
13
r3
lurrr your TV set.
sr brminols lobeled "on- fr
Irro coble is the round qre @-@@
r odopter (nor supplied)
fr {:h'ffij*,,.r,
tc-
denno swilchbox to the
r =* b ooe of the newer
pl ulill need o 3OGohm
m
c4
x rhe switchbox to the fr
:r irdkoted on the corrr- H
re the switch to the left, * The commodore 64 is now correctry connected. No odditionor
con-
I lio.rg locol TV signol is nections ore required to use the compuier with your TV.
: dher chonnel to ovokl G4 switchbox will connect the computer to the TV when the
The ontenno
rrclen
a4 sride switch is in
the "computer" position. When the switch is in the,,TV,, position
your set
on the side of
ttdow insertinn in only
:r cord rfre wrong uroy-
*e
e4 will operote normolly.
BACK OF YOUR TV
-a
e*i
C,-.)
c*)
i*l
i*l --1
{j
{?
-?
q-?
ANTENNA !,
SWITCH
80x YOUR VHF
\fa
ANTENNA
(IF USED)
,>St
e4
sPTroh{Ar coN su EeTtoN $
e4
Since the Commodore 64 furnishes o chonnel of high fidelity sound,
e4
you moy wish to ploy it through o quolity omplifier to reolize the best
sound possible. ln oddition, the Commodore 64 olso provides o ston- fr
dord "composite" video signol, which con be fed into o television
monitor.
>4
These options ore mode possible by the oudio/video output iock on ?4
the reor ponel of the Commodore 64. The eosiesi woy to goin occess to
these signols is by using o siondord 5-Pin DIN oudio coble (not
P
supplied). This coble connects directly to the oudio/video connecror on e*4
the computer. Two of the four pins on the opposite end of the coble
contoin the oudio ond video signols. Optionolly, you con construct your
V.
own coble, using the pinouts shown in Appendix I os o guide. *
FI
'-2J
-a
;ut
tr;
*t
ch
6+3
ft Normolly, the BLACK connecror
i
fr
ft
signol. This plug
-or.!.
plifier, or the AUDIO lN
of the DIN coble supplies
.onn..t.d ,"'ln]'orr,,ARy inpur the AUDIO
connector .r-. _-." itor
such os o video cossette recorder
(VcR).
of on qm_
or other video system,
The WHITE or RED c
:l I
fi Y,".
fr
T h i s p u s,.
r
*
" "..,1
inpuf section of some iiff
o: :: lii:? : :1 il,.JT J"l:.:. i ;q
other video .rri",i,"r*f,
^l
os o VCR.
I l
{t"fi -,
fr Depending on fhe monufociure,
of the plugs moy be differenr. of ,,ou, Ji, .o0,., rhe color
,r. ;j;;rs coding
fr shown in Appendix I to
Iil;^,ff .'I'':,,'J:JJ::,, j,ll " 0""'i ""' o n o ud io o,.,ra.o-, is or
fi
n
J
; ft
IS,.-:i
fc
I
II
I
fe
I ff l
$a
I
fr
i:
l
fi
f.u
-s--
ri;
lrlft
r?
l-3til't
- TO AUXILIARY
:1i"5il
fr INPUT OR
fi
'rrEn j :e -"
s.: _ -:
fr
1: -3: :3 --€ :€:- *
€ Af:.',:€S : S-:-- H TV I\4ONITOR
, t-: : -ee.5.:-
H
E€ :.--: -- :: ( : - lP' AUDIO SYSTEM
u E ;: - tr::e5: -:
8tr,C::::e -:.
ta
!6c€::--*:-:-:- Qt' I lf youpurchosed peripheror equipment,
!r^a :j -€ ::: e such os o vrc I54 I disk
or o VIC l515 prinfer, you drive
/t moy wish to connect if
<f ---<- the user,s monuols supplied ot this time. Refer fo
?s with ony
proper procedure for connecting
it to the"JOi,.r",
computer.
equipmenr for rhe
f-t
7t
L'
--1_
b '{:
I
>-+
1l
l*-?
A completed system might look like rhis.
5*a -1,--
tf
nt
€a
5-'
;-i
3-l
'a"*)
3-a
5-. TROUBLESHOOT]\ G
5-, Sy t otcr
5*a
{i
{"
7a
*PERATIGru -<
t,
l.
>-2
l,
Turn on the computer using the rocker switch on rhe right-side ponel
when you're looking o, the computer from the front. ;-t
2. After o few moments ihe following will be disployed on the TV
reen:
f,
sc
t4
t4
e*4
CURSOR SIGNALS
COMMODORE 64 IS
*
WAITING FOR YOUR c-1
INPUT.
tr4
"4
r<
=-t
rf!
r ':,
2-i
2-r
E*t lf your TV hos o monuol fine tuning knob, odiust the
t-, o cleor picture.
TV until you get
5-r 4. You moy olso wont to odiust the color ond tint controls on the
the best disploy. you con use the color odjustment procedure
TV fcr
Q-{ scribed loter to get everything setup properly. When you
de_
first get o
a-! picture, the screen should oppeor mostly dork
blue border ond letters.
blue, with o ilgt,
i-l
7-l lf you don't get the expected results, recheck the cobles
ond connec_
i-) tions. The occomponying chort will help you isolote
ony problem.
-n-)
TROUBI.ESHOOTING CHART
a,
a-- )
t 6,- -l
i-l
I Symptom
lndicotor Light
not "On"
Couse
Compuler no.t
Remedy
Power cqble
i-? not plugged
Check power socket
for loose or dis-
t-) chonnel
Check other
chonnel for
picture (3 or 4)
* -'; I nco rrect Computer hooks up to
t1 hooku p VHF ontenno terminols
v.
not plugged coble connection
in
H Computer set
for wrong
Set computer for
sqme chqnnel qs TV
G*r chonnel (3 or 4)
s
rtJ -^,
l>-- 'l
r-J
i, -,
'-.-
{.
. --7
-
ir
Symptom Remedy t-l
Rondom pottern Cortridge noi Rei n se rt i-l
cortridge ofter
on TV with
cortridge in
ProPerlY
in serted turning off power 7-t
ploce a*t
Picture without Poorly tuned Relune TV
7*l
color
Adiusr color/ l
i-l
Picture with
poor color
Bod color
odlusimenl h ue/brig htness i-'l
on TV controls on TV
3*a
Sound with
excess
TV volume up
high
{.
bockg ro u nd
noise
i-l
TV volume too Adiust volume of
3- _l -
Picture OK,
but no sound low i-g
Aux. output
not properly
Conneci sound
iock to oux. input
{t
con nected on omplifier ond r-_?
selecl oux. input
rt
,s/'a
-
TIP: The COMMODORE 64 wos designed to be used
But we ot Commodore recognize thot computer
difficulties. To help onswer your questions ond give
by everyone'
users mqy' occosionolly' run into
you some fun progromming
a4
ideos, Commodore hos creoted severol publicotions to
help you You might olso flnd {-'
thot it's o good ideo to ioin o Commodore Users Club to
CoTAMODORE 64 owners who con help you goin
help you meet some other
knowledge ond experience e4t
t4
CURSOR
t4
The floshing squore under READY is colled the
ond indicotes
t4
cursor
t4
where whot you type on the keyboord
As you type, the cursor will move
cursor position is reploced with the
will
oheod
be
one
chorocter
disployed
spoce'
you typed'
on the screen'
os the originol
Try typing on
vc"4
you type ore disployed on the TV
the keyboord ond wotch os chorocters
screen. #
#
r*3
2", )
-)--.,
!'J
!t
t'-- i
'-- ?
E -t
t{ {., i=; t\{* $A A$}.i UST,tugS ru tf
tJ
set o pottern of colors on the TV so
f, -l 'o vou con
".]ff'ilr:r';ff':|"
i -t
tl, f
::
how:li':
eosy 3r,r' " ..use", n;]"jl"fi
" it is to
the Commodore
First, look on the left side
:!i,fiJd;'
64. "i;, I ; ;]Jl *
of the tuyUoo.a ond locote
!@. fnis sronds for ConTRoL the key morked
)FL
raa keys, to instruct the compufer "^O-,,
,r"0, in coniunction with other
)Fr
to do o specific fosk.
ra,
O-,
!ao
Ct
oF,
ia,
Dts.
!t,
i-t
'z-- t
Z*,
ln_r
2-,
2-i
2*i
z*?
+'9
>*)
)*] To use o control function, you hold
down the@[key while depress-
ing o second key.
?4 Trvrhis; hord [email protected] whire orso depressing the@key.
p---'i leose both keys. Nothing
obvious should iore hoppened,
Then re-
touch ony key now' the screen bur if you
l}-*j" wifi show fhe chorocfer disproyed
in re-
tvpe--like the openins messose
?*) I^iIi }.,1";r1|';J:il.""-ol
Hold down tt'"
or ony-
|r*i
2
{
t
long os the $!![@ is de-
ond then move down to the next line os
pressed.
E RED BAR
tr GREEN BAR
E BLUE BAR
tr YELLOW BAR
i,
t=
rr
t,
lrSE : i:
:lt,: --''
--:: -
e
ft * "
!,
;,e1:""5 :" t,
t,
ta
t,
a,
1,
h[ft -
i:r:"
i4r+_
I '1.*-:.
'rl
,l-l
fi E:
l9 7 \\g^
KffiY&SARM L-a '"' -': : ':
Now thot you've gol everything set up ond odiusted, pleose toke o ft
few moments to fomiliorize yourself with the keyboord which is your
most importont meons of communicotion with ihe Commodore 64.
fi
You will find the keyboord similor to o stondord typewriter keyboorcl {t
f,
.E
found in most oreos. There ore, however, o number of new keys which
IISI
control speciolized functions. Whot follows is o brief description of the
i-, -:: :',:
vorious keys ond how they function. The detoiled operotion of eoch key
will be covered in loter sections. c*i .'" ,n=rl I -:
E
c-n Ef
E
{, E-it :
x {t
{t l=ffiil
f,
ffi {v - l-Fr
ra-lrig
f"
i"v
r7 EEE :
r7 ._ -t. -
@ r?
tst
U
Th. ]@[ key signols the computer to look ot the informotion thot
you typed ond enters thot informotion inio memory.
tst
t--,
trtr >-__*)
The @ key works like thot on o stondord iypewriter. Mony keys P
ore copoble of disploying two letters or symbols ond two grophic chor- P
octers. ln the "upper/lower cose" mode the @ key gives you ston-
dord upper cose chorocters. ln the "upper cose/grophic" mode the P
E@ luy will disploy the grophic chorocter on the right hond side of >--)
the front port of the key.
ln the cose of speciol YELLow function keys, the @ t.v will give >*i
-
yotr the function morked on the front of the key.
tt
l4
t.7
ra
--r
r-
ft
f.
"-*a
EDITING
ft
r'irur:+: ;,e.:r.* -:i{.t : f. No one is perfect, ond the Commodore
64 tokes thot into occount. A
(6l8:,:-: *":-
llir 1: - -,:,,: :,-r :u
: tt,Z." fi number of editing keys let you correcf
motion oround on the screen.
typing mistokes ond move infor-
fr A @[ed
@!
close up the spoce.
ollows you to lNSerT informorion
exomple, if you noticed o typing mistoke on o iine. For
ffi perhops you left our porr of o nome_you
in the beginning of o line_
Err * EllrldtE
f. tllElfifif posirions rhe cursor ot the ,,HOME,,position
eL/. which is rhe upper left_hond corner. of the screen,
A shifred ,ilt ttlif will cleor the
trt€lE'-*' {,1,:-n r:.': Qe- screen ond ploce the cursor in the
home position.
=rE
I
--: :'::-,: :-:--
,:- r-:--
;,:: e-4 @
*.*.
Ea !r-::,- : -,:,:: -€ (P
"E -;-- -:-: ::: :- €- EEEEEII operotes os the nome impries. rt restores the computer fo the
r@,:.* ;,,i ffi normol stote it wos in before you chonged
some commond. A lot more will be
things with o progrom or
soid on this in loter chopters.
ffi
f,t I5
ffi
F.:
I
r-l
r-'7
{.
FUNCTION KEYS
t-a
The four function keys on the right side of the keyboord con be "pro- {,
grommed" io hondle o voriety of
mony woys to hondle repetitive tosks.
functions. They con be defined in
f, @ com*oDoRE (E'
{,
{,
,
{i
{7
i-t
{,
7,
i-,
i*b
{.
77
Zlt
rt
t4
Y7 BACK TO I-IORMA.
l@ *4
The@!key, which stonds for ConTRoL, ollows you to set colors, ond "4
ry?t
perform other speciolized functions. You hold the @!key down while
depressing onother designoted key to get o control function. You hod on
>-4
opportunity to try the @k.v when you chonged text colors to creote v2-
different color bors during lhe setup procedure.
Y-4
€-
Normolly, depressing tf," ffiftftB key will stop the execution o{ o
?4
BASIC progrom. lt signols the computer io STOP doing something' Using
t't
*--:"
t6
--
l-E?-a
--
>:-'.
rfJ
T.'j
>::- 7
)-- )
6t
t-, tt," @@[ key in the shifred mode will ollow you ro ouromoricolly
lood o progrom from tope.
5*t
5*r @ comnoDoRE KEy
Qt- r The Commodore key
Ef
a-r
ni-
@ performs o number of functions. First, ir
ollows you to move betwEn the text ond grophic
disploy modes.
t When the computer is first turned on, it is
in the Upper Cose/Grophic
a-, mode, thot is, everything you type is in
upper cose letters. As wos men_
tlo:udl using the fflil k.y in rhis mode'will disploy
righr side of the keys.
tt. g.ophi. on tl,.
!-t If you hold down the
e Now, old
U", @ key, rhe disploy will chonge
11t to upper ond lower cose. if you hold down the
j-l other key with o grophic symbor, rhe grophic E t", onJ on,
shown on the left side of
the key will be disployed.
j-t To get bock into the upper cose/grophic
mode hold down the
j-t ond @@ key ogoin. @ key
"a-' j The second function of the @ key is to ollow you occess to o second
set of eight rexr colors. By h-olding down
G 0.,
rhe
Ti wi, be in the orternote ""0
number keys, ony text now typed
from the key you depressed. Chopter
"*-"iln.
coror ovoirobre
z'-7
Y3
C'^t BACK TO NORffiAg"
e-') Now thot you've hod o chonce to look over the
keyboord, let,s explore
e--'j some of the Commodore 64,s mony copobilities.
lf you still hove the color bors on the screen from
)n) se.1, hold f@
odiusting your TV
ond EEEtr . The screen shourd creor ond the
@ )2, will be positioned in the ,,home,, cursor
spot (upper left_hond corner of the
sc reen).
v---, Now' simulroneously hord
@ ond the E k.v. This sers the texr coror
1*-4 bock to light blue. There is one more step ,Ieeded
v to n,ormol. Hold!@ond
to get everylhing bock
@(zero nor oh!). This sers the displolimode
bock to normol. lf you remember. we turned
REVERSE type on wirh the
C-/:i @tr to creote the color bors (the color bors were
octuolly reversed
t>P'l
spoces)' rf we were in the normor text mode
b during the coror test, the
cursor would hove moved, bur left blonk
t-F
iust spoces.
l
f; t7
E-
E
,t'1
)--l
5*?
t,
Now thqt you've done things the hord woy, there is o simple wcy to reset the 1,
mochine to tha normol disploy. Firsf press the IEEEEE key ond then press
the f$ft!fl key. f!f[l!ll musl olwoys be held down in order to use the f,
f$fi[!| key functiorr.
5*i
This will cleor the screen ond return everything io normol. lf there is o progrom in
the computer, it wili be left untouched. This is q good sequence to remember, espe- c*i -t :
ciolly i{ you do o lot of progromming.
lf you wish to resel the mochine os if it were turned off ond then switched on e-i {..-ltrilJ
-t-
ogo!n, iype, SYS64759 ond press Efufl| Be core{ul using this commond! ll wiil
wipe out ony progrom or informotion thot is currently in fhe computer. i-, DISK, -, -
i-i
{t
t#A#ENS AruM SAW!B\J# PRffi&RAETS a*l
c*t
One of the most importont feotures of the Commodore 54 is the obili,y-
to sove ond lood progroms fo crnd {rom cossette tope or disk. q*,
This copobility oiiows you lo sove the progroms you wriie for use ot o
loler time, or purchose prewritten progroms to use with the Commodore {i
64.
Moke sure thot eilher the disk drive or dolosette unit is ottoched
7"
properly. {,
LOADING PREPACKAGED PROGRAMS
t7
>lt
-
For those of you interested in using only prepockoged progroms *
ovoiloble on cortridges, cossette, or disk here's oll you hove tc Co:
e",, LOADING PROGil-riri ;; - \,, . -:
I. CARTRIDGEST The Commodore 64 computer hos o line of progroms
*
ond gomes on cortridge. The progroms offer o wide voriety of business
ond personol opplicotions ond the gomes ore iust like reql orcode >4 :
l----,
ir'
I
r,
,-- 7
ft
1-, settes thot come ol
th e to e i.
o,, e
p ':"I
. ffi
J,.",J :J.,?:. L::.* ,:;
rffi
a*t Then, iusr type LoAD. The
compure, *itt Jr.*", wirh pREss
T::",;;
" pLAy "
oN
5-, TAPE, so you respond by pressing
this point the computer screen
ploy on yow dotosefte mochine.
will go blonk until
Ai
6,- t found. The computer will soy the progrom is
FoUi; fr*oo*o, NAME),".rr.,,,
on the
e-r screen. Now you press down
on rhe
lood the progrom into the computer. fit rrv. in,. *,i,
n ,I, *on, to stop the looding
i-t simply press rhe
@E k.v
?-i 3' DlSK: using your disk.drive,
so thot the lobel on,the,.djsk
corefuily insert ihe preprogrommed
disk
i-t for
is focing ,O
o iittre notch on the disk (if mighr ""0
[u-LJ.rua
is closest to you. Look
r'
;- -'
,:' I
,* --7
{.u
t-?
t,
ft
Afteryoudepresstheploykey,thescreenwillblonk,turningthe 7-7
border color of the screen os the computer seorches for the progrom.
When the progrom is found, the screen will disploy:
7:l SAV \G I?:3;}.,tr,:
7'* 7
a-7
i'*i
a*,
t--
octuolly LOAD the progrom, depress the @ key' To obondon
the
To
LOADing procedure, t'.rit f$ftfiE lf you hit the
the
Commodore
progrom is
key' the
LOADed'
i*l '
:: -:-;-
screen will ogoin turn the border color while
After the LOAD|ng procedure is completed, the screen will return to
the i*i l-tlrJ
normol stote ond the READY prompt will reoppeor' a-7 -
n-*7
LOADING PROGRAMS FROM DISK
z-7
Looding o progrom from disk follows the some formot' Type:
1-7
>-t
ra
>-l
?"r
The I is the code for the disk, so you're iust ietting the computer know
e--?
thot you wont the progrom looded from the disk' t u't
After you t.|it @t the disk will srort whirring ond the disploy 24
shows'
t-i
t*4
c-1
) :-tt
c*'J
c*j -l
20 )-
I
Li
fr
t-"I
)-7
5,
"i
NOIE:
t*t When you lood o new progrom into
the computer,s memory, ony in-
7*, structions thot were in the computer
sure you sove o progrom you,re
previously will be erosed.
Moke
6t Once o progrom hos been looded,
working on before looding o n"*
on".
a-t
a*t
FI
\I ant
e"t ,,PROGRAM
NAME" CON be up to 16 chorocfers
a*7 F.filfill the computer will respond with:
long. After you hit
a*7
z*?
eu?
e-7
a"? Press both the record ond ploy
keys on the dotosetfe. The screen
c*) blonk, turning rhe color of the border.
After the progrom is soved on tope,
will
LE.I
?
,:- J
,-- !
5, -.,
The computer is precise ond expects
f*-r form.
ri nstructions fo be given ri n o speciflc
Yi
Y3
>-^r whot you've discovered is thot the commodore
64 is o corcurotor in its
bosic form. The result of ,,24,,wos
?-'J colculoted ond printed outomoticolly.
ln foct, you con olso perform subtroction,
c-.t ponentiotion' ond odvonced moih
multiplicotion, division, ex_
funcfions such os corcuroting squore
roots, etc. And you're not limited to
2--s more on thot loter.
o single colculotion on o li,-r., or,
)-t Note thot in the obove form, pRINT
behoved differently from the first
O'3 exomple. ln this cose, o volue or result
the exoct messoge you entered becouse
of o colculotion is prinied,
rother thon
the quote morks were omitted.
?'*i
>*4 ADDITION
?*: 23
-L
17'!
{7
r4
5- EXPO\ \' A: :\
tt
E
SUBTRACIION
3-l
ft
5-7
i*7
;*j
TIP:
----l
*"-,*? BASIC hos o number of sh
tA,
*
*-1 THIS
-REPLACES THE
?
Pu WORD PRINT
c*3
{j
fr 25
ll*
f:
,]: -l
?-a
6tA
Up to this point we've iust used smoll numbers ond simple exomples.
However, the Commodore 64 is copoble of more complex colculotions. ft
You could, for exomple, odd o number of lorge figures together. Try 7-?
this, but don't use ony commos, or you'll get on error:
5a
aa
f" da>
i-
i:?
Thot looks fine, but now try this: {t
{t
7-l
{T
{r
a-3
lf you took the time to odd this up by hond, you would get o different
resu lt.
-i
Whot's going on here? Even though the compuier hos o lot of power, -
there's o limit to the numbers it con hondle. The Commodore 64 con a-a
work with numbers contoining I0 digits. However when o number is
printed, oniy nine digits ore disployed. e<
So in our exomple, the result wos "rounded" to fit in the proper
ronge. The Commodore 64 rounds up when the next digit is five or more;
c4
it rounds down when the nexi digir is four or less. e-4
Numbers between 0.0.l ond 999,999,999 ore printed using stondord
nctotion. Numbers outside this ronge ore printed using scientific noto-
e-4
tion. e-4
Scientific nototion is iust o process of expressing o very lorge or smoll
number os o power of 10.
t?,
lf you type: t?'
t-4
t-4
Clt
c-,Sn
b
!
26
^-i
t,
,L-:J^'
t,
e'
I
;*l
7--7
{,
j.23 * jOtlT ond is used
r-*i This is the some os
There is o limit to the numbers the computer
iust to keep things tidy.
con hondle, even in
.-i scientiflc nototion. These limits ore:
at Lorgest: -r 1.70141l83E+3g
6-7 Smollest (different from zero): -f 2.93g235gg_39
i-t PRECEDENEH
3-7
a-7 lf you tried fo perform some mixed corcurotions
exomples we showed eorrier, you might not
different from the
i-7 you expected. The reoson is thot fhe
hove gotten the resurts thof
computer performs corcurorions in o
e-! cerioin order.
t-4
p*1
*4.
c*-1
DF,I
2--' 27
,at
^-^.'
!7
U--*'l
Yr
"<
ct
you will get 35 divided bY 5 with 2 odded 1o the onswer, which is nol
whot you intended ot oll. To get whot you reollY wonted, try this:
r-i
ft
5t
a"'i
a"-7
Whot hoppens now is thot the computer evoluotes whot is contoined
in the porentheses first. lf there ore porentheses within porentheses' the
'-*3
innermost porentheses ore evoluoted first' 3"-3
Where there ore o number of porentheses on o line' such os: '-*i
t
a,-
a-t
3-.t
the computer evoluotes them left to righr. Here 2l would be multiplied 7*a
by 7 |or the resuh of tr47. '-*a
>Fl
!at
a-t
q-l
3*J
z*7
z-a t.he numbers wi'be printed ocross the screen ond down
on to the next
"*3
Z-"7
llne.
The Commodore 64's disploy is orgonized into 4 oreos of I0
columns
>L't'a eoch' The commo tobs eoch resurt into the
ar next ovoirobre oreo. Since
we osked for more informotion to be printed
?<
>Pt
(we tried to fitfive r'-corumn oreos
down to the next line.
thon wourd fit on one rine,
on one rine) the rost item wos moved
e4
?4
?G'
V4
?4
e4
c'*J
*,8't
29
"*J
.t
_ iL_-.
J -r'
lr
t
tl
t
I
t
rl
t
t
t,
!t
ra
!,
'
3
l' t
fl
14
;-
TH* ruEXT STEP tJ
Up to now we've performed some simple operotions by entering o lJ
single line of instructions into the computer. On.e @l wos de_
pressed, the operotion thot we specified wos performed immediotely.
This is colled the IMMED|ATE or CALCULATOR mode.
But to occomplish onything significont, we must be oble to hove the
ffrr
-
computer operote with more thon o single line stotement. A number of
stotements combined together is colled o pRoGRAM ond ollows you to a7
use the full power of the Commodore 64.
To see how eosy it is to write your first Commodcre 64 progrom, try
{"
th is:
Cleor the screen by holding rhe @@ key, ond then depressing the {a
-7
G@EB k"v.
Type NEW ond press (This iust cleors out ony numbers thot
f@[
{t
might hove been left in the computer from your experimenting.)
Now type the following exocrly os shown (Rernember ro hit
{7
@f {"
ofter eoch line)
a7
a4
*
fl
4
a
d
Now, type RUN ond hit @-wotch whot hoppens. your screen
will come olive wirh COMMODORE 64. After you,ve finished wotching
d
the disploy, hit @[ to srop the progrom. t4
A number of importont concepts were introduced in this short pro-
grom thot ore the bosis for oll progromming.
e-4
Notice thot here we preceded eoch stotemenf with o number. This a-4
LINE number tells ihe computer in whot order to work with eoch stote-
ment. These numbers ore olso o reference point, in cose the progrom
t2
needs to get bock to o porficulor line. Line numbers con be ony whoie e-1
number (integer) volue between 0-63,999. e-4
rl PRINT "COMMODORE 64" *J"
1
I
--
t-
'TATEI^EN'
tlNE NUHBER #
!
--:/-a
{
IJ
fl
{a
14
{r
r-
t,
f7
e-i
int
int
z-*7
i-*7
i*,
e-i
f7
@! f-, It is good progromming proctice lo number lines
10-in cose you need to insert some stotemenfs loter in increments of
f^t Besides PRINT, our progrom olso used
on.
onother BASIC commond,
GOTO. This instructs the computer to go
;-" directly fo o porticulor line ond
pei'form it, then continue from thot point.
C4 IO PRINT "COMMODORE 64"
14
t4 2A GOTO rc
fi",
':'a
.{ --1
i --7
ffiffiBTEru& TBPS 1t
lf you moke o misioke on o line, you hove o number of editing
r --?
options.
l. You con retypeo iine onytime, ond the computer will outomoticolly
r'
substitute the new line for the old one. 7-7
2. An unwonted line con be erosed by simply typing the line number a--")
ond $@.
3. You con olso eosily edit on existing line, using the cursor keys ond 7'Fr
editing keys" r4
Suppose you mode o typing mistoke in q line of the exomple' To
{----,
eorrect it withoui retyping the entire line, try fhis:
Type LIST, then using the @ ond liE[f,ll keys together move the {7
-:7
cursor up until it is positioned on the line thot needs to be chonEed' ll
to the cursor to the chorocfer you
Now, use the cursor-right key move
wont to chonge. typing the chonge over the old chorocter. Now hit 7-v
fl@[ ond the corrected line will repioce the old one' {"
need more spoce on the line, position the cursor where the
lf you
spoce is needed ond hit f@ ond [l[@ ot the sorne time ond o f7
spoce will open up. Now iust type in the odditionol informotion ond hit {-)
fi@! . Likewise, you con delete unwonted chcrrocters by plocing the
ond hitting the ffitfif -Fl
!
*il. the right of the unwonted chorocter
key' --4
tl
thot chonges were entered, type LIST ogoin, ond the cor-
To verify
rected progrom will be disployedlAnd lines don't hove to be entered in
-.4
ra
numericol order. The cornputer will outomoticolly ploce them in the t-/,
proper sequence.
Try editing our somple progrom on poge 33 by chonging line l0 ond
14
odding o commo to ihe end of the line. Then RUN the progrom ogoin' )-4
DON'T FORGET TO MOVE THE
>-t -,
IO PRINT "COMMODORE", CURSOR PAST LINE 20
YOU RUN THE PROGRAM,
BEFORE
t -t
?*'-}
weffiBeffitffis
t-l
Voriobles ore some of ihe most used feotures of ony progromming
longuoge, becouse voriobles con represent much more informotion in v2 D
the computer. Understonding how voriobles operote will moke comput- ) -st
ing eosier ond ollow us to occomplish feots thot would nct be possible )-/t
11
otherwise.
i,-? -a
s=t
I
jS -'
!
t(-v,
a'a
,a--?
[,
1-i
i,
i,
a,
a-,
i*?
Z-,
7-t
a-,
a-t
a-i
3-7 lmogine o number of boxes within the computer
thot con eoch hord o
':'
e-? number or o string of text chorocters. Eoch
lobeled with o nome thot we choose. Thot
of these boxes is to be
-ae) nome is cored o voriobre
ond represents the informotion in the respective
box.
riili.ir r-"-'7 For exomple, if we soy:
2*? 2A X
30 X$ :
23.5
"THE SUM OF xyo*X : ,,
en?
cn7 x 23.5
c*j 35
i-lt
3-?
_J:j
J
,:- ?
7-7
(t
Ao/"
Xt/" r-,
A1 yo
NM%
r-- i
The'$'following the vorioble nome indicotes the vorioble will repre-
i- ,
sent o text string. The following ore exomples of string voriobles: {-,
A$ e-7
X$
Mt$ i-7
Flooting point voriobles follow the some formot, with the type indi- i;l
coto r:
AI
i'n,
X 7*,
'a* |
MI
ln ossigning o nome to o vorioble there ore o few things to keep in a*,
mind. First, o vorioble nome con hove one or two chorocters. The first i-7
chorocter must be on olphobetic chorocter from A to Z; the second
chorocter con be either olphobetic or numeric (in the ronge 0 to 9). A i-7
third chorocter con be included to indicote the type of vorioble (integer i-a
or text string), o/o or $.
You cqn use vorioble nomes hoving more ihqn two olphobetic
a:7
chorocfers, but only the first two ore recognized by rhe compuler. So
ta-7
PA ond PARTNO ore the some ond would refer to fhe some vorioble
z*?
box.
The lost rule for vorioble nomes is simple: they con't contoin ony ?-a
BASIC keywords (reserved words) such os GOTO, RUN, etc. Refer bock
to Appendix D for o complete list of BASIC reserved words.
;-2
To see how voriobles con be put to work, type in the complete pro- ?--n?
grom thot we introduced eorlier ond RUN it. Remember to hit f!s[!
e"--n?
ofter eoch line in the progrom.
t-t
t/,
t-4
t--4 -- i n,
j -/t
i*z
?=-7
36
> -,--7
-
t7
*+D
'--4
(, a-.-
lf you did everything os shown, you should get
f*l printed on the screen_
the following result
6,
5*7
5-'--
6*l
i-,
a--,
--*1 We've puf fogether oll the tricks leorned
f, os you see it ond print the sum of fhe two
ln lines I0 ond 20 we ossigned on integer
so for to formoi the disploy
voriobles.
C-, flooting point voiue to X. This puts the
volue to X%a ond ossigned o
*.b.. ossocioted with the vori_
€*, oble in ifs box. ln line 30, we ossigned
o text srring to Xg. Line 40
f, combines fhe two types of pRrNT stotements
octuol volue of Xo/o ond X. Line 50 prints
to print o messoge ond the
e--" X:X+l
e-4 This would never be occepted in
most used concepts in progromming.
normol olgebro, but is one of the
t=-? lt meons: toke the current volue of
X, odd one to it ond ploce the new sum into
the box representing X.
2-?t
>4
e-?
l*4
V*4, IF TF{ffiru
Y7 Armed with the obility to eosily updote the volue
e--'l now try o progrom such os,
of voriobles, we con
E,-lt 37
;*!
a-?
i-n
(t
r--
It
it
a-t
7'-?
7'*?
a<
3--'l
{r
7nl
Whot we've done is introduce two new BASIC commonds, ond pro-
vided some control over our runowoy little print progrom introduced ot
l-l
the stort of this chopter. c*" "iI-
lF. . . THEN odds some logic to the progrom. it soys lF o condition
holds true THEN do something. lF the condition no longer holds true,
i*" : -: *'
THEN do lhe next line in the progrom. 74 i::-:4
q4
Equol To
Nor Equol To q-?
Greoter Thon or Equol
Less Thon or Equol To
To
e-t-
The use of ony one of these conditions is simple, yet surprisingly e-t
powerful.
:6 ;4
tA CI
2g ?"coMMoDoRE 64"
q-4
3ACt:CT+l
< 5 THEN 20
4A tF Cr
*-1,
I
I
c-4 a
50 END e-!
e-?
<-.1
38 i-'l
)-s><
!
i--,
{a
'---
(, -
r- ln the somple progrom, we,ve set up o ,,loop,, thot hos
stroints ploced on it by soying: lF o volue is less thon
some con_
some number
i,
6
THEN do something.
Line I0 sets cr (counT) equor to 0. Line 20 prinrs
our messoge. Line 30
€*, odds one to t'ire vorioble cT. This rine counts how mony times
we do the
q*l loop. Eoch time the loop is executed, CT goes up by
one.
Line 40 is our conirol line. lf CT is less thon 5, meoning
e"o cuted the loop less thon 5 times, the progrom goes bock
we,ve exe-
to line
20 ond
6- prints ogoin. when cT becomes equol to S-indicoring
5 coMMoDoRE
;a 64's were printed-fhe progrom goes to line 50, which
the progrom.
signols to END
{t
fl FOR...NEXTTOGPS
{" There is o simpler, ond preferred woy to occomplish
whot we did i
the previous exomple by using o FOR
-" NEXT loop. Consider the
q< following:
e"-""
e<
e-4
e4
e-4
e-4
*4
*2'
+4
v4
e-4 As you con see, the progrom hos become much smoiler ond more
direct.
e=*? CT storts ot I in line I0. Then, line 20 does some printing. ln Line 30
q"t
?="?
c t-.?,
l':
;-+'!
f
>'
a
5'
CT is incremented by l. The
NEXT stotement in line 30 outomoticolly
sends the progrom bock to line l0 where the FOR port of the FOR . t
NEXT stotement is locoted. This process will continue until CT reoches the
limit you entered.
t'
The vorioble used in o FOR . NEXT loop con be incremented by
smoller omounts thon 'l
, if needed. a
Try this:
l}
t
!
ll
I
t
a
e
a
a
lf you enter ond run this progrom, you'll see the numbers from I to
I0, by .5, printed ocross the disploy.
Ail we're doing here is printing the volues thot NB ossumes os it goes
through the loop.
You con even specify w-hether the vorioble is increosing or decreos-
ing. Substitute the following for line l0:
l0 FOR NB : I0 ro I STEP -.5
ond wolch the opposite occur, os NB goes from lO to I in descending
order.
40
-
t,
a,
-
!,
#
#
#
#
.-14
f
4
!
3
fl--? ":*
a :3
f-? at
-?
lf ia"
-a
t]
"1
:3
a
-? )
t,
:'3
-e
INTRODUCTION 2€t)
t,
-:rA
The next few chopters hove been written for people who hove be-
?-4
t
-aE
'" 4e
come relolively fomilior with the BASIC progromming longuoge ond the ^-4 't:
4
\t
concepis necessory to write more odvonced progroms'
: i3
For those of you who ore iust storting to leorn how to Progrom' you
moy find some of the informotion o bit too technicol to understond
*
completely. But toke heort. becouse for these two fun chopters'
SPRITE GRAPHICS ond CREATING sOUND, we',ve set up some simple P - ::-
exomples thot ore written for the new user. The exomples will give
o good ideo of how to use the sophisticoted sound ond
you
grophics eA 'E@
copobilities ovoiloble on your COMMODORE 64' eA .::
lfyoudecidethotyouwontioleornmoreoboutwritingprogromsin
o bibliogrophy (Appendix N) in the bock of this mon-
BASIC, we've put
eA
uol. tJ
lf you ore olreody fomilior with BASIC progromming' these chopters
will help you gei storted with odvonced BASIC progromming techniqu-
YJ
es. More detoiled informotion con be found in the coMIAoDORE 54 >-4
PROGRAMMER'S REFEREIIC6 MANUAI, ovoiloble through your locol
Commodore deoler.
qs)
7YJ
42
;4
--gt
!,
-*1
r 5'-
{a
rt
fr SIMPTE ANIMATION
f,
fr
fr
Let's exercise some of the Commodore 64's grophic copobilities by
putting together whot we've seen so for, together wiih o few new con-
fr
#
cepts. lf you're ombitious, type in the following progrom ond see whot
hoppens. You will notice thot within the print stotements we con olso
include cursor controls ond screen commonds. When you see something
like {CRSR LEFT} in o progrom lisiing, hold the @ t.v ond hit the
# CRSR LEFT/ RIGHT key. The screen will show the grophic representotion
# of o cursor left (two verticol reversed bors). ln the some woy, pressing
fr
5-t
f@ ond EEE[@ shows os o reversed heort.
NEH
73
fr
#
LA
?g
REM BOUNCING EFLL
PRINT " {CUR,',gOme}
25 FORX=1TOlB:
3A FORBL=lT04O
:
PRINT " {CRSR/EIOI.IN} ": NEXT
r,
fl
5A FOR TH
6A NEXT TI'I
7g
75
NEXT BL
TO5
#
3!'[rs HEXT BL
lErr :: : '-,- - l3s GoTo 2s
lir"lc: -: - -
G n*": -.- : #
ra{ -: i":-
€r?nErE"l -
# IIP:
All words in this text will be completed on one line. However, os long os you don't
Lxjr ---
* t,it f@@ your 64 will outomoticolly move to the nexl line even in ihe middle of o
* word.
'r-r-l
+it :,:,: r -i -.* -
--- ee
Q,,U- The progrom will disploy o bouncing boll moving from left to right,
l5!r:,-* -: '*:--:-- e'r-, ond bock ogoin, ocross the screen.
c COiI{HODORE &{ c* lf we look ot the progrom closely, (shown on poge 44) yov con see
{t
,-h 43
;h
*?
a-u
--A
,a
i, -t'
3--? INPUT
A", Up to now, everything within o progrom hos been set before it is run.
7-l Once the progrom wos storted, nothing could be chonged. INPUT
ollows us to poss new informotion to o progrom os it is running ond
3"i hove thoi new informotion octed upon.
3-l To get on ideo of how INPUT works, type NEW ]fu[!ond
short progrom:
enter this
3-?
3-?
a-a YOU TYPED
D--*'r
J
COMPUTER
-4
a, RESPONDED
.=,*?
?--?
g4 Whot hoppens when you run this progrom is simple. A question mork
>Y, will oppeor, indicoting thot the computer is woiting for you to type
something. Enter ony chorocter, or group of chorocters, from the
?*. keyboord ond hit Es[! The computer will then respond with "YoU
?NJ
- TYPED :" followed by the inforrnotion you entered.
tnt -
This moy seem very elementory, but imogine whot you con hove the
computer do with ony informotion you enter.
a You con INPUT either numeric or string voriobles, ond even hove the
*u'
INPUT stotement prompt the user with o messoge. The formot of INPUT is:
72 , I N PUT "PROMPT MESSAGE,,;VARIABLE
).-l*-,
\
\
*)t'n aao*", A{usr aE 3g cHARAcrErs or r.Ess.
e-"'t 45
?-r?
a
-.=Y
t,
--_!- i
a'a
i-4
(1,
Or, iust:
r--?
INPUT VARIABTE
4l:t IF
H$ .:> "r-:" THEi.{ 16 ( HtRt . /
5B It.lF'l-lT "Et.lTEFj frEr:iF:EE!; r::EL!; Il-lE: ":r:: \--z
F.:El f = ri tl:f ! :./g+Jl a
;:rl F E: I t'lT r:: .! " ftEr:i. l:EL!; I l-l::; = " .; F.:
FIiHFjEIIHEI T,,
" E|EG.
(
/-\^i^
DoN'T I ---7
t
:lli PE: I I.]T
Il',dfiTl ;:a
-tqru
'f Ll rfr:rTr:r 113
tl
It..lF'l-lT "El.l]-EF: [rEr:iF:EE::; FffHHEIIHEIT: " ;F
1t::]tl
I lEl t:: = ': F-:il:r +:i.J3
l;rd F'FTII.IT F:,. EIEI];. FI-THI;:EI.IHEIT = " ., [: : rr
-4
ra
r.ELE: I t_tE: ,,
BEr:i.
?-4
-
1:lr:t PF: I l.lT
>---?
1,+rjl [ir:rT[r 1l:r \1
>4
-
lf you enter ond run this progrom, you'll see INPUT in oction'
Line l0 uses the input slotemenl to not only gother informotion, bui c4
olso print our prompt. Also notice thot we con osk for either o number or
siring (by using o numeric or string vorioble).
e-4 _:-
..:
- -
Lines 20, 30, ond 40 do some checks on whot is typed in' ln line 20, if
e
noihing is eniered (irr, ]fu[l is hit), then the progrom goes bock to y4
line l0 ond requests the input ogoin. ln line 30, if F is typed, you know
the user wonts to convert o temperoture in degrees Fohrenheit to Cel- t4 '.:.,
sius, so the progrom bronches to the port thot does thot conversion v2
Line 40 does one more check. We know there ore only two volid
choices the user con enter. To get to line 40, the user must hove typed
v2
some chorocter olher thon F. Now, o check is mode to see if thot chor- >*4
octer is o C; if not, the progrom requesls input'ogoin. >-r'J
!
This moy seem like o lot of deioil, but it is good progromming proc-
t-s
!
J
!a
----1
!
:'7
?
a'a
"-4
i, -- tice A user not fomirior with the progrom con become
l --t it does something stronge becouse o mistoke
very frustroted if
wos mode entering infor_
1,
.1,
motion.
[r-3li,lJ :-r Once we determine whot type of conversion to perform,
-- 5--? does the colculotion ond prints out the temperotu!.e
the progrom
entered ond the
5-' converted temperoture.
r'-?
"--?
2"4 GET
?'-€,
;-'J
-
-
alS <
,J
ff -'
r-a
,-4
a
('
lf you RUN the progrom, the screen will cleor ond eoch time you hit o
key, line 20 will print it on the disploy, ond then GET onother chorocter.
t,
It is importont to note thot the chorocler enlered will not be disployed t1,
unless you specificolly PRINT it to the screen. os we've done here'
The second slotemenf on line l0 is olso importont. GET continuolly
a*,
works, even if no key is pressed (unlike INPUT thot woits for o response), {-a
so ihe second porf of this line continuolly checks the keyboord until o key
C<
See whot hoppens if the second port of line |0 is eliminoted.
To stop this progrom you con hit the @@[ ond f$@! kevs.
t<
--4
ta
The first port of the temperoture conversion progrom could eosiiy be
rewritten to use GET. LOAD the temperolure conversion progrom, ond c<
modify lines 'l0, 20 ond 40 os shown:
i*a
-:'7
t3
IE PRII.IT "COHVERT FRDI{ FffHREHHEIT OE CEL=-IUE
{.F /Ci "
IFR*="' {t
t--2
?E L.iET FI:$:
4A IF H$ {i ..f,.,
THEH
e---'?
This modificotion will moke the progrom operote smoother, os nothing
will hoppen unless the user types in one of the desired responses to --4,
seleci the type of conversion. -sl
e
Once this chonge is mode, moke sure you sove the new version of the
progrom.
--4
-
14
q-)
ffiAhID&trI F{I.!MtsERS Aru& ffiThf;ffiR FEJNfiYASruS
c_/,
The Commodore 64 contoins o number of functions thot ore used to
e-4
perform speciol operotions. Functions could be thought of os built-in t4
progroms included in BASIC.. But rother thon typing in o number of
stotemenis eoch time you need io perform o speciolized colculotion, you
2.4
lust type the commond for the desired function ond the cornputer does
t"A
lhe rest.
Mony times when designing o gome or educotionol progrom, you
U.2
need to generote c rondom number, to simulote the throw o{ dice, for t)
exomple. You could certoinly write o progrom thot would generote these )-)J
numbers, but on eosier woy to coll upon the RoNDom number function. t-/J
To see whot RND octuolly does, try this short progrom: t
t,---3
48
l'-z
;-4
_--*t
?
r-a
2--
-
6a
r-= HEt,I
5r
fr 1A
2A
FDRX=lTO
PRINT RNB(1),
3A NEXT
{,
q*l After running the progrom, you will
,." o airlffffi
c-
C-
c-7
{r
7-a Your numbers don,t motch? Well, if they
{r trouble, os they should be completely rondoml
Try running the progrom o few more
did we would oll be
e;,
?4
t4
Q-1
>2
2,2t
s-sl
v
"-'3
-
It
?*i
,---a
,4
-
€r
Thot cured the problem of not hoving results lorger fhon l,
but we still
hove the decimol port of the result to deol with. Now, onother function t.
con be colled upon. ft,
The lNTeger function converts reol numbers into integer volues.
Once more, reploce line 20 with the following ond run the progrom to 1Dt
see the effeci of the chonge: 5-.
c<
c<
3<
fl
1*?
7--e
{7
Thot took core of o lot, getting us closer to our originol gool of 54
generoting rondom numbers between I ond 6. lf you exomine closely {" -t
whot we generoted this lost time, you'll find thot the results ronge from
0 to 5, only.
--a
ra ::
As o lost siep, odd o one to the stotement, os follows: .A"-?
-
20 PRrNT rNT(6*RND(r))+ r, F-2
t'
Now, we hove ochieved the desired results. >-a
!
ln generol, you con ploce o number, vorioble, or ony BASIC expres-
sion within the porentheses of the INT function. Depending on the ronge
>-7
\ta
desired, you iust multiply the upper limit by the RND function. For >4
\-
exomple, to generote rondom numbers between I ond 25, you could
type, e-)
20 PR|NT rNT(25*RND(r))+ r
e-4
The generol formulo for generoting o set of rondom numbers in o t4
certoin ronge is: t4
N UMBER=lNT(LOWER LIMIT+(U PPER- LOWER+ I )* RN D( I )) v2
&UESSING GAMH
v2
to some lengths to understond rondom numbers,
a_4
Since we've gone
why not put this informotion to use? The following gome not only illus- 3-4
?-4
i=-?
----n
ta
i*l
P-a
.-4
-
5' trotes o good use of rondom numbers, but olso
r--? tionol progromming theory.
introduces some oddi_
r*a 9B
1trJB IF tlH$ THEI.{ 7A
?-*)
e4
Z-4
>4
?4
t4
'lI' l, e,*1
aez
er4
c4
g=*,
G=*?
U
Ft,
a:4
i.
{,4
71
--4 RA\13r" 3;/e
lF/THEN stolements compore your guess to the number generoted. ta,,-.,
Depending on your guess, the progrom tells you whether your guess wos
higher or lower thon the rondom number generoted' a'
From the formulo given for determining rondom number ronge, see if
you con odd o few lines to the progrom thot ollow the user to olso
i'
specify the lower ronge of numbers generoted' i1
Eoch time you moke o guess, cN is incremented by I to keep trock of t-4
I-1
the number of guesses' ln using the progrom, see if you con use good
reosoning to guess o number in the leost number of tries'
When you get the right onswer, the progrom prints out the "GREATI !l-4
you GoT MY NUMBER" messoge, olong with the number of tries it took.
-?2
You con then storl lhe process over ogoin Remember, the progrom
f,
11
ln lines 40 ond 50, o colon is used to seporote multiple stotements on o single line. t---2
I--4
This not only soves 1'yping, bul in long progroms will conserve memory spoce'
Also notice in rhe lF/THEN siotements on the some two lines, we instructed the
compuier io pRINT something, rother thon immediolely bronching to some other poinl
!-e,
in ihe progrom.
The losl point illustrotes the reoson behind using line numbers in incremenls of ] 0: a 4
After the progrqm wos written, we decided 1o odd the count port By iusr odding
those new lines ot the end of rhe progrom, numbered to foll between the proper e
existing lines, the progrom wos eosily modified ' ?-a
t,
a4
YOt.lR ROIL
C4
The following progrom simulotes the throw of two dice. You con enioy
os it stonds, or use it os pori of o lorger gome"
C4
it
CA
5 PRINT " llarE tcl tri' :,;or-tt* L-lck? "
2./,
lE PRItIT "REEI ErICE = ";Il'lT(5{tEt'l0(1ii+1 e-2
28 PRIt'{T "l,lHITE OIr-E = ";It'lT(6ttE}"lfi(1i''+1
36 PRI}{T "HIT SPHCE BHR FOE FINDTHER RULL":PPIi'{T *)
4o GET Fl$: IF F+ = "" THEN 4E Q)
58 IF H$ = f,HR${32i THEt'l lll
Core to trY Your luck?
,"-t4
FromwhotyoU,veleornedoboutrondomnUmbersondBASlC,seei{ >-4
!
you con follow whot is going on.
52 "-4
3-4
"-'t1
--<)
rE l--
a,-*A
.-4
!a
5t RANDOM GRAP!.I;C5
{-
t, As o finol note on rondom numbers, ond os on introduction to desigrr-
a, ing grophics, loke o moment to enter ond run this neot little progrom:
at
€*"
{7
e*" As you moy hove expected, line 20 is the key here. Anofher function,
CHR$ (Chorocter String), gives you o chorocter, bosed on o stondord
i", code number from 0 to 255. Every chorocter the Commodore 64 con
{t print is encoded this woy (see Appendix F).
To quickly find out the code for ony chorocter, iust type:
7*i PRTNT ASC('X")
5-7 where X is the chorocter you're checking (this con be ony printobie
{7 chorocter, including grophics). The response is the code for the chor-
octer you typed. As you probobly figured out, "ASC" is onother function,
{"
{a which returns the stondord "ASCll" code for the chorocter you typed.
You con now print thoi chorocter by typing:
{t PRINT CHR$(X)
-4
tt lf you iry typing:
a4 you will see the two right side grophic chorocters on the M ond N keys.
>-/,
-
These ore the two chorocters fhot the progrom is using for the moze.
By using the formulo 205.5 + RND(l) the cornpufer will pick o rondom
* number between 205.5 ond 206.5. There is o fifty-fifty chonce of the
number being obove or below 206. CHR$ ignores ony froctionol vcrlues,
*
) so holf ihe time the chorocter with code 205 is printed ond the remoin-
t-r ing time code 206 is disployed.
tt - lf you'd like to experiment with this progrom, try chonging 205.5 by
odding or subtrociing o couple tenths from it. This will give either chor-
a-4 octer o greoter chonce of being selected.
*) ,
>-/J
Z-nt
?=--'t
i='7
3-/t
f,t
f#
::'riit
, ;iiF,.
':i .
,:,,
I ';i
:
,
i ", - ri !it.
l
a-a
i-4
f?
trffiB.&R &Nffi Gmep*.{$frS
t.
t.
Up to now we've explored some of the sophisticoted computing
copobilities of the Commodore 64. But one of its most foscinoting feo-
tures is on outstonding obility to produce color ond grophics.
You've seen o quick exomple of grophics in the "bouncing boll" ond
fr
{7 @UEEBtrrI
"moze" progroms. But these only touched on the power you commond.
A nuniber of new concepts will be introduced in this section to exploin {?
grophic ond color progromming ond show how you con creote your own {"
gomes ond odvonced onimotion. A {* !,1 *
Becouse we've concentroted on the computing copobilities of the mo- {"
chine, oll the disploys we've generoted so for were o single color (light {"
blue text on o dork blue bockground. with o light blue border).
ln this chopter we'll see how to odd color to progroms ond control oll {t
those stronge grophic symbols on the keyboord. {7 " :-:
@t
i
{t
Pffi$ruYl$dffi C#TffiRS {a
As you discovered if you tried the color olignment test in Chopter I , {7 r5.'!{:,r,lI
@o :".
Ilr...t,,t :i,,Iyr"
l
you con chonge text colors by simply holding the!@key ond one of {" @8tr
the color keys. This works fine in the immediote mode, but whot hop-
pens if you wont to incorporote color chonges in your progroms? --l
a @!E: I
When we showed the "bouncing boll" progrom, you sow how a @E': r
keyboord commonds, like cursor movement, could be incorporoted ?--?
rl l@@;E
within PRINT stotements. ln o like woy, you con olso odd text color
>--? @E'EI
chonges to your progroms.
You hove o full ronge of l6 text colors to work with. Using the@!
lr @EM
key ond o number key, the following colors ore ovoiloble:
>--2
r.!
12345678
Block White Red Cyon Purple Green Blue Yellow
tr-r
e--/,.)
lf you hold down the G t"V olong with the oppropriote
key, these odditionol eight colors con be used:
number e-.,
Q*--t-t
12 3456
Lr. Groy 1 Groy 2
78
Lt. Groy
t-1
Oronge Brown
Red
Lt.
Green Blue
3
t-)
TYPE NEW, ond experiment with the following. Hold down theE[!
?;,
key ond ot the some time hit the[key. Next, hit theEk.V without
>-sl
It L-Iflfr
?---'J
ra
tI
{,
Z*T
fl
# j^
#ffi: tl T;,Jffi,.il
c
51, i# i
#
#
word RAINBOW os follows:
I 0 PRtNT"l Rtol,
t*l, lot*,,
# @EEEEEEE
#
fr?
RUN
RAINBOW
64 @E wHrTE E|
GIE
BA
oRANGE n
r*'l @E
@o
RED E EE
BROWN
Lr. RED X
;
fl
4
@E
CYAN N
PURptE il BE
EE
GRAy r
GRAY 2
e
t @tr GREEN tr G'E
TJ
tr. cREEN Il
>44
\- @E B.UE E GE r-T. BLUE O
@E YEu-ow E
# Even though the pRl.NT stotemeni
GIE GRAy 3 !:
,DA1?t
tt @ ond @E
C
57
:"t
'rli-'.a
U
,gf t
a-f
'{4
(r
#ffiL#R #ft4ffi$ i-1ffiffiHf;
tr
Toke o brief look ot Appendix F, then turn bock to this seciion. lr
You moy hove noticed in looking over the list of CHR$ codes in
Appendix F thot eoch color (os well os most other keyboord conirols, f.
such os cursor movement) hos o unique code. These codes con be {-
printed directly to obtoin the some results os typins @ ond the
c4
oppropriote key within the PRINT sfotement.
For exomple, try this: #
*
c<
{7
{'t
c-1
fl @:I
E
The text should now be green. ln mony coses, using the CHR$ func- {7
tion will be much eosier, especiolly if you wont to experiment with
chonging colors. The following progrom is o different woy to get o roin-
:-a
!
bow of colors. Since there ore o number of lines thot ore similor (40- -:A
e
I I0) use the editing keys to sove o lot of typing. See the notes ofter the
*
listing to refresh your memory on the editing procedures.
f
--- 2
HEI,I
t4
1 E:Ef'l Hl-lTt-rl'lFlT I r:: L-:l:rLr:lF: EfiF:!;
FFiIl.{T
=1B F'F: I I.ITE:HF:5( 14I:r : E:Et'l r::HFi$i 147.:= C;LF"./Ht-rl'1E "4
e-4
I::HE:f i: 18 ] .;
ll:1 r::L = Il.iTtE:*E:f.lEr{ I :!)+1
.; : E:EI'1 F.EI\.'EB::;E EHF:
y-4
:;rjr fil.,I L-:L !:ir:rTr:r 4R,5rJ.E|:_1,fi.l,rlLf .,3r:.r. 1r:lB. 1 1U
4rJ F E: I l.{T r::HFjs r.5 ) .; : r:ir:rTt:r 1 B V-1,
5r:r F'E: I t']T r-:HF:f !r:r.) : : r:ir:rTr:r 1El
6Er FE:
1:
58
"-4
a--7
---n-a
!
ell
Z4
,J<
a- Type lines 5 through 40 normolly.
Your disploy should look like rhis:
5'
fr
f,
C-
fr
f,
{t
{t EDITING NOTES
fl
fi
fl
#
#
G4
e4 Don'r worry. Line 40 is still there. LIST the progrom
tPn some procedure, continue to modify the lost line
ond see. Using the
tP' ond cHR$ code untir oil the remoining rines hove
with o new line number
been entered. see, we
told you the editing keys would come in
Q4 entire progrom to moke sure o, the rines were
hondy. As o finol check, list the
i
a-l
,-4
tl
f4
whot the whole progrom octuolly does. Line 5 prints the CHR$ code for
11,
CLR/HOME.
Line I0 turns reverse type on ond prints 5 spoces, which turn out to be a*. -I
@
o bor, since they're reversed. The first time through the progrom the bor
i,
will be light blue, the normol text color.
Line 20 uses our workhorse, the rondom function to select o rondom {a
color between I ond 8.
Line 30 contoins o voriotion of the lF ' . THEN stotement which is
{<
colled ON . . . GOTO. ON . ' . GOTO ollows the progrom to choose
from o list of line numbers to go to. lf the vorioble (in this cose CL) hos o
fl
volue of l, the first line number is the one chosen (here 40). lf the volue
{"
is 2, the second number in the list is used, eic.
Lines 40-110 lust convert our rondom key colors to the oppropriote
{a
CHR$ code for thoi color ond return lhe progrom to line l0 ro PRINT o
{"
section of the bor in fhot color. Then the whole process siorts over {"
ogoin.
See if you con figure out how to produce l6 rondom numbers, ex-
{7
pond ON . . GOTO to hondle them, ond odd the remoining CHR$ fl
codes to disploy the remoining 8 colors.
fl
P&EKs ANil P&KEs {,
{,
No, we're not tolking obout iobbing the computer, but we will be oble
to "look oround" inside the mochine ond "stick" things in there. i4
Just os voriobles could be thought of os o representotion of "boxes" >--a
tl
within the mochine where you ploced your informotion. you con olso
think of some speciolly defined "boxes" within the computer thot repre- 14
sent specific memory locotions.
The Commodore 64 looks ot these memory locotions to see whol the
a4
screen's bockground ond border color should be, whot chorocters ore to
be disployed on the screen-ond where-ond o host of other tosks. y4
"4
By plocing, "POKEing," o different volue into the proper memory lo-
cotion, we con chonge colors, define ond move obiects, ond even e-4
creote music. tln
These memory locotions could be represented like lhis:
t'2-
*2
?;t
BORDER
COLOR
BACKGROUND
COLOR ;-4
?-4
--4
a
---4
a
ea)
>, _-4
j --t
ra
l-. :,e-- on poge 60 we showed iust four rocotions, two of which control the
t. screen ond bockground colors. Try typing this:
1.,-- POKE 5328r,7 @l
6t The bockground color of the screen wiil chonge to yeilow becouse
we
i, ploced the volue '7'-for yellow-in the locotion thot controls the
bockground color of the screen.
i- t Try PoKEing different volues into the bockground coror rocotion,
ond
a*? see whot results you get. You con pOKE ony volue between 0 ond
but only 0 through l5 will work.
255,
i*? CYAN
3 GRAY I
4 PU RPLE tl GRAY 2
i*7 6
5 GREEN 'I 'l
Lisht GREEN
3*?
BLU E 14 Light BLUE
7 YELLOW l5 GRAY 3
---?
t,
con you think of o woy to disproy the vorious bockground ond border
D
t,
-'1'7 combinotions? The following moy be of some help:
--?
t,
D -*'?
-
> -*-?
-
>4
> -r-2
)Fl
'--
>*.
?"-,-
t*-
?*4
C elt Two simple loops were set up to POKE vorious volues to chonge the
bockground ond border colors. The DELAY loop in line 50
iusr slows
e,*? rhings down o bit.
-Li
> )-? 6I
))v<
U
-* i
t!
.-a
,-4
a
5-4
For the curious, try:
t, -E4
"4
?4
SEREEN ffiEffiORV MAP
*-4
Since the computer's screen is copoble of holding 1000 chorocters (40
columns by 25 lines) there ore 1000 memory locotions set oside to hon- e4
dle whot is ploced on the screen. The loyout of the screen could be u2
thought of os o grid, with eoch squore representing o memory locotion.
And since eoch locotion in memory con contoin o number from 0 to *2
255, there ore 256 possible volues for eoch memory locotion. These ?4
volues represent the different chorocters the Commodore 64 con disploy
(see Appendix E). By POKEing the volue for o chorocter in the oppro- ?-4
--4
n
r-4
---/l
tt
€,"-?
il
4
{,
fr
-1
t,.- o.oie screen memory locotion, thot chorocter will be disployed in
the
proper position.
5'
,? -,e 33;::i /,3s g /e.
f,
c :-:
'€-€r er:e:.'-'5
::-:e. ::3-S
Ce_
O'e
fr
fr
COLUMN
20
{t
--il
3AC(- :0.1
{c
- -i1l
. r8l
fr
-62.1
t56l
.i0J
'.1 t1
fl .78,1
1.E21
186 4
19 01
-' 194 4
fl
19 8J
ng "lr-rl :-:-:-e-: rl
"4
t4 for colculotion of the memory locotion on the screen is:
r!
f,
i lli
iii
.-
.4
L
{-+
--*
Cleor the screen with @ ond g@ ond type:
t'
POKE I524,8I
t'
POKE 55796,1 ^
the other for the color code. The color memory mop begins ot locotion
a
55296 (top left-hond corner), ond continues on for 1000 locotions. The tl , -;a
COTUMN
=d4
a
2A >-t,
e
+ --A
e
a4
55296
5 5336
55376
C4
55416
55456
55496
55536
5 5576
5616
t4
t4
5
55656
55696 '--
It o
tA
55736
55776
55E16
s5856
55896
t2
e.2
55936
55976
56016
56056
s6096
56r36
eJ
56176
56216
56256
CA
I ?*LJ*)
It
--4
56295
t,
--Y?
!t
-JJ'.
tl]
sl
13 LF-
I
a-a
c-
"--
some color codes, from 0-15, ihof we used to chonge border ond
f, bockg'ound colors con be used here to directly chonge chorocter coror.s.
a- The formulo we used for colculoting screen memory locotions con be
modified to give the locotions to POKE color codes. The new formulo is:
g*t
COTOR PRINT = 55296 +X+ 4A*y
5-
a-
{? MORE BSUNE$NG EAIffi
c-7
a-, Here's o revised bouncing boll progrom thot prints directly on the
screen with PQKEs, rother thon using cursor controls within pRINT stote-
3-t menTs. As you will see ofter running the progrom, it is much more flexi-
a-t ble thon the eorlier progrom, ond will leod up to progromming much
more sophisticoted onimotion.
{t HEI,I
"-4
2-4
The X ond Y voriobles in line 30 keep trock of the current row r:nd
column position of the boll. The DX ond Dy voriobles in iine 40 ore the
>4 horizontol ond verficol direction of the boll's movement. When o *I is
odded to the X volue, ihe boll is moved to the right; when -l is odded,
t?. the boll moves to the left. A *I odded to y moves the boll down o row,.
t4 o - I odded to Y moves the boll up o row.
Line 50 puts the boll on ihe screen ot the current cursor position. Line
V*/r 60 is the fomilior deloy loop, leoving the boll otr the screen lust long
>-4 enough to see it.
Line 70 eroses the boll by putting o spoce (code 32) where rhe boll
elt wos on the screen.
z-s 65
2-'!
2-,
a-i
Line 80 0dds the direction foctor to X. Line 90 tests to see if the boll
hos reoched one of the side wolls, reversing lhe direction if there's o
,l00
bounce. Lines ond II0 do the some thing for the top ond bottom
wolls.
,l20
Line sends the progrom bock to disploy ond moves the boll
ogoin.
By chonging the code in line 50 from 8l to onother chorocter code,
you con chonge the boll to ony other chorocter. lf you chonge DX or DY
to 0 the boll will bounce stroight insteod of diogonolly'
We con olso odd o little more intelligence. So for the only thing you
checked for is the X ond Y volues getting out of bounds for the screen.
Add the following lines to the progrom.
n7 FI]RL=1TOlE
POKE 1E:4 + IHT (Et'lD( 1 ]+lEgE] ' lbh
l.lEl{T L
B5 IF PEEK( 1AA4 + ;t + 413*'l:' = 16t, THEI'I tlH = -Bl-i:
GOTfr -qA
1 r:r5 IF PEEK(19124 + i.i + 4B*?-, = 168 THEI{ ErV = -frY :
GOTO 1gg
66
fi
i
a 4
fl
INTRODUCTION TO sPRlTEs 1',
I
fr
memory locotions. This would then ploce the oppropriote chorocters di-
#
rectly on the screen in the right spot'
Creoting onimotion in both these coses requires o lot of work becouse f
obiects must be creoted from existing grophic symbols. Moving the ob-
fl
iect requires o number of progrom stotemenis to keep trock of the ob-
iect ond move it to o new spot. And, becouse of the limiiotion of using fl
grophic symbols, the shope ond resolution of the obiect might not be os
fl
good os required.
Using sprites in onimoted sequences eliminotes o lot of these prob- fl
lems. A sprite is o high-resoluiion progrommoble oblect thot con be
fl
mode into iust obout ony shope-through BASIC commonds. The obiect
con be eosily moved oround the screen by simply telling the computer f,
the position the sprite should be moved to. The computer tokes core of
lhe rest.
And sprites hove much more power thon iust thot. Their color con be
f,
a
chonged; you con tell if one obiect collides with onother; they con be -'',
?-4
mode to go in front ond behind onother; ond they con be eosily ex- a
ponded in size, iust for storters. 2-,
!
The penolty for oll this is minimol. However, using sprites requires ,.-l,
!
knowing some more detoils obout how the Commodore 64 operotes ond
how numbers ore hondled within the computer' lt's not os difficult os it
sounds, though. Just follow the exomples ond you'll be moking your own
4
>-*)
\a
sprites do omozing lhings in no time.
4
SPRITE CREATION
Sprites ore controlled by o seporote picture-moker in the Commodore 4
64. This picrure moker hondles the video disploy. lt does oll the hord 4
work of creoting ond keeping trock of chorocters ond grophics, creoting
colors, ond moving oround. 4
t2
This disploy circuit hos 46 different "ON/OFF" locotions which oct like
internol memory locotions. Eoch of these locotions breoks down into o
series of 8 blocks. And eoch block con either be "on" or "off". We'll get
into more detoil obout this loter. By POKEing the oppropriofe decimol
e
4
volue in the proper memory locotion you con control the formotion ond ?.**7
movement of your sprite creotions. 1
a
=,>Jt)
68 G*"?
rj
€a
3
l>-
-?
-a
r<
fr
t,
ln oddition to occessing mony of the picture moking rocotions we will
olso be using some of the commodore 64's moin memory fo store infor-
t, motion (doto) thot defines the sprites. Finolly, eight memory locotions
tr
fr
directly ofter the screen memory will be used to tell the computer exoctly
which memory oreo eoch sprite will get its doto from.
As we go ihrough some exomples, rhe process will be very
: ,:-:'
(.*:
.:
#
#
So let's get on with creoting some sprife grophics. A spriie obiect is 24
dots wide by 2l dots long. up to erght sprites con be controiled ot o
time. Sprites ore disployed in o specior independent 320 dot wide by
#
-": : ( 200 dot high oreo. However, you con use your sprite with ony mode,
-:- high-resolution, low-resolution, text etc.
#
fl* -
Soy you wont to creote o bolloon ond hove it floot oround the sky.
#
The bolloon could be designed os in rhe 24 by 21 grid on poge 70.
The next step is to convert the grophic design into doio the computer
#
#
con use. Get o piece of notebook or groph poper ond set up o somple
grid thot is 2l spoces down ond 24 spoces ocross. Across the top write
128,64,32,16,8,4,2,.l , three times (os shown) for eoch of the 24
#
#
squores. Number down the left side of the grid l-2.l for eoch row. Write
the word DATA ot the end of eoch row. Now fill in the grid with ony
design or use the bolloon rhot we hove. lt's eosiest to outline the shope
rrt
>1n
first ond then go bock ond fill in the grid.
Now if you think of oll rhe squores you filled in os,,on,, then substitute
o I for eoch filled squore. For the one's thot oren,t filled in, they,re,,olf,,
2n so put o zero.
)n
storting on the first row, you need to convert the dots into three sepo-
rote pieces of doto the computer con reod. Eoch set of g squores is
?n equol to one piece of doto colled o byte in our bolloon. working from
the left, the first 8 squores ore blonk, or 0, so the vorue for thot series of
;14 numbers is 0.
;h
cP
The middle series looks like this (ogoin
spoce):
128 64 32 l6
oI indicores o dot, 0 is o
eP 1t
a):'. 64+ 32 + 16+ 127
e)t The third series on the first row olso contoins blonks, so it, too, equols
,{t zero. Thus, the doto for the first line is:
,-l-'a
'--h
!, I
DATA O, 127, O
69
a-)'-'l
14
vl
/t
f,P
SER I ES
1
,tr2 SERIES
I
l'
SERTES
rt
tr -4
8 iza tz 8 212832 8
12832
6416
2
1r 64 16
2
t'
#
4 4
c4
6 #
1
I
c4
4
,:
o
=
l^
ru f
-ll
3
fl--?
1,2
13
fl
1.4
15
lb
17
fl
fl
18
19
20
2t
a
COLUMN --a
4
e
The series thot moke up row two ore colculoted like this: ,ga
ll
Series 'l
: 0 0 0 0 0 0 0
),--a
!a
?-a
!1
>--2
11 1 1 11 1
1
ra
;4
t2B+64+ +t6+ I +4 +2 + t- 255
-
4
32
Series 3: 0 0 0 0 0 0
?4
128 + 64 : 192
e4
For row 2, the doto would be,
eA
DATA r ,255,192
ln lhe some woy, the three series thot moke up eoch remoining row
e)
would be converted inio their decimol volue. Toke the time to do the tJ
remoinder of the conversion in this exomple. t4
Now thot you hove the doto for your obiect, how con it be put to use?
Type in lhe following progrom ond see whot hoppens. r-4
r-4
-=r-?
e
--t-a
{3
l
4
a
f, I
1 REI'I UP, UP,
s PRIrir "Icr-RzuomE]"
FINO HI,IFV!
tr 19 V= 53244 : REI'1 STffRT OF trISPLH'/ CHIP
f- 11 POKE V+2L.4 : REl"l ENfiBLE SPRITE 2
rt
5<
12 P0KE 2A42,13 : REf'l SPRITE 2 trHTH FROI''I 13TH BLK
2A FOR N = B TO 52: REHD I : PBKE 832+N,8: NEXT
36 FOR X = B TA 2Ag
46 POKE V+4,X: REI'I IIPOHTE X
cETs rrs rNFo. FRor'{ DATA*
COORBII'IHTES
2gg DaT afq .. L27, A, 1, 255 " t92, 3, :l33, 224, 3, ?3 l, 224
fl 218 OffTF 7,2t?,24A,7,223,24A,7,217,?49,3,23L,224
226 BRTB 3,255,224,3,2=3,224,2,?53,16,A, l, L?7,64
239 DHTF 1,62,64,A, 156,128,A, L=6,123,A,73,@,9,73,9
{? 249 OATR 8,52,A,A,62,4,4,62,,4,9,?8,4
8. j
'FOR MORE OETAIL oN READ & DATA SEE CHAPTER
.{ i ', '.,
{" lf you typed everything correctly, yiur bolloon is smoofhly''flying
,l
A4 0 X coordinole of sprite
Y coordinote of sprite 0
0
i,,* -
?84 I
t, 2 - 15 Poired like 0 ond l for sprites 1-7
!, l6 Most Significont Bir-X Coordinote
-a
>--a
rt
2t
29
Sprite oppeor: 1 :oppeor 0:disoppeor
Expond sprite in "X" Direction
\, a'1 Expond sprite in "Y" Direction
>-4 39-46 Sprite0-Tcolor
-2
\-
*
?4 ln oddition to this informotion you need to know from which 64 byte
section sprites will get their doto (l byte is not used).
e4 This doto is hondled by S locotions directly ofter screen memory:
e4
v-'- 2040
itttllt
P SPRITE O 1234567
;4 Now let's outline the exoct procedure to get things moving ond finolly
C4 write o progrom.
;-e-3
t, 7l
a-"4
C4
#
2*:,
,-1
a
(, -,^
_.^
t'-. --,,.
f,
5',
{-t
c4
3-4
1-4
c*-"
i--?
7-)
i*-?
ACTUAL SCREEN PHOTO 7-..?
{a
__-7t
f
There ore only o few things necessory to octuolly creote ond move on ,-1'7
a
obiect.
l. Moke the proper sprite(s) oppeor on the screen by POKEing into lo-
-4
t
cotion 2l o I for the bit which turns on the sprite. -'4-?
a
2. Set sprite pointer (locotions 2O4O-7) to where sprite doto should be ) --'-7
reod from.
3. POKE octuol doto into memory. ?--a
4. Through o loop, updote X ond Y coordinotes to move sprite
5.
oround.
You con, optionolly, expond the obiect, chonge colors, or perform o
,-4
voriety of speciol functions. Using locotion 29 to expond your sprite in e-4
the "X" direction ond locotion 23 in ihe "Y" direction.
t-4
There ore only o few ilems in the progrom thot might not be fomilior t4
f rom the discussion so for.
c2
ln line l0;
V=53248 c2
sets V to lhe storting memory locolion of the video chip. ln this woy we ?-4
iust increose V by the memory number to gei the octuol memory loco- a-r4
tion. The register numbers ore the ones given on the sprite register mop
i-4
72 ,-4
a
t---"7
i-',
,,-2
,r4
ta ln line 1,],
t,
-J
POKE V+2J,4
7,- mokes sprite 2 oppeor by plocing o 4 in whot is colied the sprite enoble
register (2.l)to turn on sprite 2. Think of it like this:
€<
fr
c< Sprire Level Number
-7
5-"
{7 Put c I For Tile You Wonr
{t
SPRITE
i*-) 4 hoppens to be sprite level 2. lf you were using level 3 you would put o
I in sprite 3 which hos o volue of 8. ln foct if you used both sprites 2
5-? onC 3 you would put o I in both 4 ond 8. you would then odd the
5-1 numbers togeiher iust like you did with the DATA on your groph poper.
So, turning on sprites 2 ond 3 would be represented os V*21,12.
{" ln line l2;
3-? POKE 2442,13
i*? instructs the computer to get the doto for sprite 2 (locotion 2042) from
the 13th oreo of memory. You know from moking your sprife fhot it
rt tokes up 63 sections of memory. You moy not hove reolized it, but those
FI
!t
numbers you put ocross the top of your grid equol whot is known os 3
byies of the computer. ln other words eoch collection of the following
- numbers, 128,64,32,16,8,4,2,1 equols 1 byte of compurer memory.
>---? Therefore with the 2l rows of your gr.id times the 3 bytes of eoch row,
eoch sprite tokes up 63 bytes of memory.
e-4 2a FoR N = 0 ro 52: READ Cf poir 832+N,e1
I WHOLE SPRITE
C4 NEXT
This line hondles the octuol sprite creotion. The 63 bytes of doto thot
e-4 represent the sprite you creoted ore READ in through rhe loop ond
tP- POKEd into the l3th block of memory. This storts ot locotion g32.
vz 30 FORX:AIO20A
40PoKEV*4''J@
v2 s o PoKE vr5.x,-"---m.iimf66.0'FD]I'AiF)
rememffi..ho;filA;;;
es' tf you represenrs on obiecrs
horizontol movement ocross the screen ond the y coordinote represents
?-4
U the sprite's verticol movement ocross the screen. Therefore os the volues
t
73
{i
--4
t,
3"t
lr
I
rt
F4
!
a-4
'-a i:": f, In line ll this iime, onother sprite (4) wos mode to oppeor by P9KE-
:- : -: ,-
--5
:::.:-=:_- 1-, ing 28 into the oppropriote "on" locotion of the sprite memory section.
. --,'_: *"*;::'",;';:r:;,.',^,1'.1'lllll;;i]
::--4
5- n., irs doto rrom the some
:::-: , , t , memory oreo (l3th 63 section oreo) os the oiher sprites by POKEing
-. fr^ 'o'oill;^"
: a--:-'' -='a' -:.. \
25. sprires 2 ond 3 ore exponded by poKEins 12 (sprires 2
i - -:.::- tf4 ond 3 on) into the X ond Y direction exponded merrrory locotions (V+23
F? ond V+29).
t3 Line 48 moves sprite 3 olong the X oxis. Line 58 positions spriie 3
::- -'
,!:;::-- t4 holfwoy down the screen, ot locotion I00. Becouse this volue does not
:-? chonge, like it did before with X:0 ro 2OQ, sprite 3 iust moves horizon-
tl Totry.
I--t
I--?
ADDtTtONAt r*OTE5 ON SPRITES
:::'i:.'
,4 r;: :
a':: n:::-:+:
': - -:
: :-. {r
--:
- --:
t\l^,^, +h^+ ;*^^+^..1 .^,;.L ^--:.^-
.,}l*,i?;llY:"":'ffi'[:":":Ji'J,'ll"'ji;"',iilm:HH:,':
- !-... -^--
color codes (0-15) ihotwere used to chonge chorocler coior. These con
--i- -
fl
o''?'#Jl.T;:',"".r
. -.i :.: ,.,---: i-? lj[jr,:"i: ?,o ,,nn, sreen, rype: poKE
- i -:" :'n:':- ". v+40,13 (be sure ro set V:5324g).
{,
:.: ::, {? ,n"
"lll.IiJ,iff"J:J?';: il:Ji:0"]lH'"";il',:.:.:'""i;:
becouse the screen is 320 dofs wide ond the X direcfion register con
*l
{"
only hold o volue up to 255. How then con you get on obiect to move
a-?
b ocross the entire screen?
There is o locotion on the memory mop thot hos not been men-
*
tioned yet. Locotion l6 (of the mop) conirols something colled the most
)"/)
(, signiflcont bit (MSB) of the sprite's X direction locotion. ln effect, this
:.. ; - , : -; - --: --=
- -= , .,.-: oliows you to move the sprite to o horizoniol spot between 256 ond 320.
--- e.-"
The MSB of X register works like this: ofter the sprite hos been
.-: : : l,: -: .r _=s e4
v moved to X locotion 255, ploce o volue into memory locotion 16 repre-
_r^
: :-: - ?4 senting the sprite you wont lo move. For exomple, to get 2 to move to
;- - -, .r0, POKE the volue for spriie 2 which is (4) into
e2-
s 1"1:::-'^!"^.:],:i'.rru
r- t2 rnemory locotion 16:
P.KE v+ 16,4.
. i2,
t4
24
L
-):; :l:',1"",t""ru"':5 ::::";": :1'J':: JT:*;'::iL::.i
spoces, X locotions would only ronge between 0 ond 63 this time.
>--'ta
!,
7s
)-/a
!,
--4
-
!r
d,
f,
This whole concept is best illustroted with o version of the originol
fr
fr -.rrms afl c ClT o: or
fr
''
frr' f trlp6 o m*c I
sprite I progrom:
A.nrr' ts* 'ltp .ru'bt
# IYIE-'hc r oaftrnd I
lE V= 534,1S: FOKE V+Zl ,4 : PtltKE ?942,L3
2B Fr-rR l'{ = E TO 62 : REBtr 8 : PDKE 832+N,8 :
?5 POHE ',./+s, rBB
NEXT
fr
#
i 9--\ rorr c:trii du
:r sTi lrn uilinr ru
r,illll ,m iG lffc
3e FOF: l{ = I TL-l 855
4A POKE V+4,i1 #
5E HEHT
69 POKE V+I6.4 #
7A FOft. ir = B TD 63
# 3r?S lrlr rduG {fl b@
BA PIIKE V+4, ;{
9S NEXT
f, !d.!
IBB POI(E V+16,4
1 1A GOTO 3A
f,
54 r 12&-01-tlta
llrmrctr
Line 60 sets the most signiffcont bit for sprite 2. Line 70 storts moving
f, 1qm rar nm J@ ra o
GEIF-iDrffidr
the stondord X direction locotion, moving sprite 2 the rest of the woy *
ocross the screen.
Line I00 is importont becouse it "turns off" the MSB so thot the
4 :il r@r f,@m
rflS mre d@ c l
{tiE lnG ruru dr
sprite con stort moving from the left edge of ihe screen ogoin. E-r=fr
To define multiple spriles, you moy need odditionol blocks for the * .{fhir' ilm' 151n65g t
sprite doto. You con use some of BASIC's RAM by moving BASIC. Before r *@{SiiIIB.,r
f,til{D
typing or looding your progrom type: {, m$ffilffi. fimLrn
* raccffc !cr-
POKE14,I 6: POKE I 6* 256,0:N EW
* nftril glf,ii@ 0n b
Now, you con use blocks 32 through 41 (locolions 2048 through 4095) to
store sprite doto.
r,
*
ela
nfilEEnO
':I o. E
BINARY ARITHMETIC
c-a r[0
It is beyond the scope of this introductory monuol to go into detoils of
how the computer hondles numbers. We will, however, provide you with 2A
o good bose for understonding the process ond get you siorted on
sophisticoted onimotion.
2A
But, before you get too involved we hove to define o few terms: {,
{,
BIT-This is the smollest omounl of informotion o computer con store.
#
r<
g
-*,4
4
{a
fr
e
a-
Think of o BIT os o switch thot is either "on" or "off ". When o BIT is
"on" il hos o volue of 1; when o BIT is "off" it hos o volue of 0.
fr
#
After BlT, the nexl level is BYTE.
#
---i
:-J€dx. : r€xT of BITS. ln other words, you con hove oll B|TS "off" sc your ByTE
=
will look like this:
# 1286432t68421
6< ond its volue will be 0. All BITS "on" is:
{"
{?
{a
128 64 32 t6
m 8
?4 )2Bl u I sz I ro I a I t I z I
Decimol Vqlue
r
e4 0
0
0
0
0
0
0
0
0
0
0
0
0
I
l
0
2IO
211
22 0 0 0
0
0 0 0
0
0
0
212
22
0 0 0 0
0 0 0 0 0 0 0 2I^
0 0 0 0 0 0 0 2T5
0 0 0 0 0 0 0 216
*--
"4 ? 0 0 0 0 0 0 0 217
>-<
t,
rt
#
--t'4
rdil
Using combinotions of oll eight bits, you con obtoin ony decimol volue
from 0 io 255. Do you stort to see why when we PoKEd chorocter or
color volues into memory locotions ihe volues hod ro be in the 0-255
ronge? Eoch memory locotion con hold o byte of informotion'
Any possible combinotion of eight 0's ond l's will convert to o
unique decimol volue between 0-255. lf oll ploces conloin o I then the
volue of the byte equols 255' All zeros equol o byte volue of zero;
"OOOOOOI l" equols 3, ond so on. This will be the bosis for creoting doto
thot represents spriies ond monipuloting them. As iust one exomple, if
this byte grouping represented port of o sprite (0 is o spoce, I is o
colored oreo):
27f2s21 23 22 2' ^O
To.or" you the irouble of converting binory numbers into decimol volues-we'll
I
i
i need to do thol o lot-the following Progrom will do the work for you' lt's o good
i ideo to enler ond sove the progrom for future use.
I
6B 60TO 1S
This progrom fokes your binory number, which wos entered os o string, ond looks
ot eoch chorocter of the string, from left to right (the MID$ funclion). The vorioble C
indicotes whot chorocter to work on os the progrom goes through the loop'
The vAL function, in line 30, returns the octuol volue of the chorocter. Since we
ore deoling with numeric chorocters, the volue is the some os the chorocter. For
exomple, if the first chorocter of A$ is I then the volue would olso be l '
The finol port of line 30 multiPlies the volue of the current chorocter by the
proper
power of 2. Since the first volue is in the 217 ploce, in the exomple' TL would first
equol I times 128 or 128. l{ the bir is 0 then fhe volue for thot ploce would olso be
zero.
This process is rePeoted for oll eight chorocters os TL keeps trock of the runnlng
lotol decimol volue of the binory number.
78
3rf\ :*: -3 rtr -3
Olt(!: :' :': -:. : -
:,il ::-,5- -r l
-=
i{iit *c -q :' :*":
c tr :-*:--: ::':
,iS,-:ne t!:*: t -
t : il,::* : :
t,
E llll&l ,4 -fl y,!
-
rlu m- r: i ill{: tt
,
'!f, -
i Fj{lE . ':
-
a
-fi_,
ElEt f tt'r,TP,r.;
)
-
a,
)
-
)
a,
Wl
ritS
rr
v
4
\-
{"
r A COMPUTER f, 5 Storr WAVEFORM wirh one of
ar .t
.: stondord settings (12, 33, b5
5q POKE54276,17
ar 129).
: --::ses: moking
-':'-a .trrcocies,, f. 6 nter o time loop to set the
E
60 FORT:lTO250:NEXT
: -, Dicol sOUnd
c< DURATION of the nore ro be
:'oyed (o quorter note is opprox.
:': f,-c:r you con
# '250" btJ moy vory since o longer
e"4 k"y.
RUN ond hii ,f-l"
1ffi;
?4
e4 5 REM MUSICAL SC,ALE €_____T;rrc of prosrom
e-4 7
r0
FORL = 5427 2t O 54296:pO KE t,O: N EXT
PoKE 54296,
*2 2A POKE 51277,9
Sch volum. or highclr rofring 05)
Sets Anock/Oecoy
c4 3s poKE s4276,r7<
40 FQRT : I TO300: N EXI
_;:;::;f...ffi"*l8;.j;.:i..,
Durot;on (how rons) ooch nor€ proy.
tt
"-4/"a 5O READ A lcodr 6rr numbcr in lina ilO
>)-'<
t
DATA
?"-
!
a 8l
)--/a
!..
{t
.--- a
rl
-1
rt
r:'-,-rtmd
r l- *
-f,
FREQUENCY locotions. The number 54273=HIGH :,- , : :*::,t
FREQUENCY lor VOICEI ond 54272=LOW FRE-
fl ' l: -* ,*'
82 ,4
{
-,e4
f,
{*)
,_: t
€*a
€4
4" As you've iust seen, you con moke your
iu4 c f{erent musicor insfruments. Let's toke
COMMODORE 64 sound like
o croser rook oi how eoch sound
TJ se.tltng works
5-
fi IMPORTANT SOUND SffiYYSru&S
{7 POKE 51296,9
.-"
Ycu only hove to set the volume ONCE ot
a-*1 the beginning of your pro_
{a 3rom, since the some setting octivotes oil three
volcES (chonging the vorume during o musicor
of the commodore
64,s
note or sound effect
*t :cn produce interesting results but is beyond the scope
of this introduc-
#
rrt
'on.)
2. ADSR ond WA\fEfORM CONTROI SETTING_you,ve
hcw chonging the woveform con chonge the
sound
olreody seen
effect from
# 'xylophone" ro ,,horpsichord.,,
Eoch VOICE hos its own WAVEFORM
aONTROt SETTING which lets you define four
+"
-44
woveforms: Triongle, Sowtooth, pulse (Squore)
TROL olso octivotes the COMMODORE
different types of
ond Noise. The CON_
64,s ADSR feoture, but we,ll
come bock fo this in o moment. A somple woveforrn
:+" like this:
stort setting looks
;h
EP
ADSR AND WAVEFORM CONTROT SETTINGS
coNrtoI Notc Srorr/Sbp Numbcn
+P VOICE I
REGISTER
51276
TRIANGI.E SAWTOO?H rutsE
t7lt6 33t32 65161 t29lt28
a1). vorcE
51283 tilt6 33132 6s161 t29ll28
2Pt 3 51290 til16 331s2 6sl6t t29lt28
,-)'''a
V Although the control registers ore different for eoch voice the
>-Yl woveform settings ore the some for eoch
type of woveform. To see how
i-u-,
!
-)-"
5-0
.H
a
-4
rl'
a4
this works, look ot Lines 85 ond 90 in the musicol scole progrom. ln this IJ
progrom, immediotely ofter setting the frequency in Line 80, we set the --4
CoNTROL SETTING for VOIGE I in Line 85 by POKEing 54276,17. This tr
turned ori the CoNTROL for VolcE I ond set it to o TRIANGLE
14 @
WAVEFORM (17). ln Line 70 we POKE 54276,1 6, stopping the note' Lo-
ter, we chongecl ihe woveform stort setting from l7 to 33 to creote o 14
SAWTOOTH WAVEFORM ond this gove the scole o "horpsichord" effect' I-4
t-:2
see how the GoNTROL SETTING ond WAVEFORM interoct? setting the
woveform is similor to setting the volume, except eoch voice hos its own
\-4
i_
setting ond insteod of PoKEing volume levels we're defining woveforms.
Next, we'l! look ot onother ospect of sound ' the ADSR feoture'
3' ATTACI(DECAY SEIIING-As we mentioned before, the ADSR t-4
coNTROL sETTING not only defines the woveform but it olso octivotes
thE ADSR, Or ATTACI(DECAY/SUSIAIN/REIEASE fEOtUTC Of thE COM-
\-e
MODORE 64. We,ll begin by looking ot ihe ATTAC(0eeny setting. The \--l
following chorf shows the vorious ATTACK ond DECAY levels for eoch i-l
t-4
voice. lf you,re noi fomilior with the concepts of sound ottock ond de-
,'ottock" os the rote ot which o note/sound orises
coy, you might think of
io iis MAXIMUM VOLUME. The DECAY is the rofe oi which the nole/ t--a
a--1
sound folls from its highest volume level bock to the SUSTAIN level. The
following chort shows the ATTAC(DECAY setting for eoch voice, ond the
numbers for eoch ottock ond decoy setting' Note thot YOU MUST ---,
a
CoMBINEATTACKANDDECAYSETTINGSBYADDINGTHEMUPAND *--1'
ENTERING THE TOTAL. For exomple, you con set o HIGH ATTACK
rote a
ond o LOW DECAY rote by odding the high ottock number (64) to the ---1'
low decoy number (l). The totol (65) will tell the computer to set the high
---,
a
ottock rote ond low decoy rote. You csn olso increose the ottock rotes
by odding ihem together (128 + 64 + 32 * I6
: MAX' ATTACK RATE -,'-, -q,l r 1l
a
of 240).
---, -;' i n
a
AITACI(DECAY RATE SETTINGS
ArIACI( DECAY HIGH MEDIUM LOW IOWESI HIGH MED.
tOW TOWESI .A
VOICE
SETIINGANACKATTACKATTACKATTACKDECAY,DECAY,DECAY,DECAY
I 54277 128 64 JZ l6 8 A
4 2
\-4
t6
.A
t28 64 5l 8
VOICE 2 4284
JI 16 8 4 2
VOICE 3 54291 128 64
you set on ottock rote with i-ro decoy, the decoy is outomoticolly
lf ti
zero, ond vice-verso. For exomple, if you P9KE 54277,64
you set o
t_2
medium qttock rote with zero decoy for VOICE I ' lf you POKE 54277
you set o medium ottock rote ond o low decoy rote
(becouse
'66
66:64+2 '.4
ond sets BOTH settings). You con olso odd up severoi ottock
volues' or ---a
(32) ond o
severol decoy volues. For exomple, you con odd o low ottock
,4
.--'?
a.
*/7
'>,
')
I
aa7
*,a
# -L.
t va -EC;- ofiock (64) for o combined ottock rote of 96, then
odcl o
)- -ec jrr decoy of 4 ond presto . . . POKE 54277,10A.
t )1 1t At this point, o somple progrom
'he .";ord NEW, hir
will better illustrote the effecf. Type
t 1t trEEE[l ond type in rhis progrom ond RUN it:
ft.
# *'"
5 FOR L=54272TO542g6:poKEL,0:NEXT(_._
0 PRINT"HIT ANY KEY" (-----
'I
20 PoKE54296.t s
Durotion ih€ nor6 proys.
screen me!sos..
#
#
30 t,QKE54277,64
rD POKE54277.
40 POKE54273.17l7:POKE54272,37 <--pote
60 GETK$:tFK$ :",,THEN60
S€r AnocldOecoy.
Check
on6 noie inro vorcE l
the keyboord
i"
#,)
70 POKE54276, I7:FORT: I TO20O:NEXT <=.==-
8A POKE54276, I6:FORT: I TO50:NEXT
90 coro2a
<__
s€i utoErom cofror (hionsro).
#
#
Here, we're using VOICE
MEDIUM ATTACK RATE ond ZERO
I to creote
one note ot o time . with o
DECAY. The key is Line 40. pOKEing
the
#
ATTACUDECA' sefring with fhe number
64 o MEDTUM o*ock
rote' The resurt sounds rike someone 'crivores
bouncing o bo, in on oir drum.
#4
!f
4q POKE 54277,19A
rc
?4 - HIGH DEcAy (8) + MEDTUM DEcAy(4) + row DECAY(2) : trel
iso.
Eil:
-- fr
l*--r';E"giv
=5
e-4 This effect sounds like o sound on oboe
or ofher ,,reedy,,instrument
might moke. lf you,d like to experiment, try
chonging the woveform ond
?4 otiock/decoy numbers in the musicol scole
"oboe" sounds. Thus
exomple to see how on
e-/, you con see thot chonging the ottock/decoy
rotes con be used fo creote different types
of sound effects.
2-4 4' susrAlN/REtEASE SETTTNG-Like Attock/Decov, the susTArN/
t2, RELEASE SEItiNg iS OCtiVOtEd bY thc
RELEASE lets you "extend" (susrArN)
ADSR/WAVEFORM CONITOI. SUSTAIN/
o porrion of o porricuror sound, rike
?4 the "sustoin pedol" on o piono or orgon which
lets you proiong o note.
r'4 Any nore or sound con be sustoined or ony
SUSTATN/RELEASE Setting moy be
one of fO f.r.i. ih.
used with o FOR. . NEXT loop to
?-41
14 85
{
r:r
i-'
-4
a
determine how long the note will be held ot SUSTAIN volume before
a4 A
being releosed. The following chort shows the numbers you hove to ta
POKE to reoch different SUSTAIN/RELEASE, rotes. ta
ta-4
SUSIAIN/ REIEASE HIGH
SUSTAINIRETEASE RATE SETTINGS
TiIEDIUM I.OW [OWEST HIGH MED. I.OW a4
a4
I.OWES!
coNTROt SETTING SUSTA|N SUSrA|N SUSTATN SUSTA|N REtEASE IELEASE tEtEASE XEIEASE
VQICE
VOICE 2
542/
5428s
A tza
128
64
64 JI 't6 8
I 4
4
2
I fl :,::
,il1!
u"_flrut:fil
_tiir h:
':n::
i -il*ilUi:ir
f,
i
VOICE 3 54292 128 64 aa I6 8 4 2
2A POKE54277,64
3A POKE54278,128-
Sel AflocUDecoy.
--a
a
--A
Ser Susroin/Releose
7A POKE54276,l7:FORT= I (---
TO200:NEXT s.i viowrom conror (hionsre).
SAAAPTE
the NOTE
fi
fNEQUENCY NUAABER c c# D D# E F F# G G# A A# B c c#
54273 34 JO 38 40 43 45 48 5t 54 61 64
CiCEI'LOW 7\ 68 72
85 126 200 q,
t98 127 97 tll t72 126 188 149
{. 54 280 34 36 38 40 43 45 48
69
fl CICE2,,LOW
51 54 57 6I 64 68
54279 75 85 126 r00 r98 127 97 lH 172 't26 r88 149 169
jILEJ/ H IGH 54287 34 36 38 40 E t u
fl
43
3]CE3i LOW 54286 85 t26 100
48
52 r98 127
54 =t 6t 68 n
97 lti t72 126 r88 149 t69
t't
& &a r-1 j: :rL: r
rt
*
Used in o progrom,
5 FORL
it looks like this:
Type the word NEW to erose your previous progrom ond type in the
following progrom, then type RUN to heor the song. fl 6-nfndrft,---1
tuC_ d
Lq:rrfr*rl
*D.t!
* I
MICHAEL ROW THE BOAT ASHORE.I MEASURE rle fu*-
* Z- tugi;;*cfrl
2 FORL=54272T Q54296:POKEL,0: N EXT * h ar mErtrmI
5 Y= 5129 6tW = 5127 6: A= 54277 :Ht = 5427 3:LF = 5427225 = 5427 8 :
?H=512752PL=51274
e-, t- tb ltr I+n "- JL
ftrrfr"
IO POKEV, I 5:POKEA,88:POKEPH, I 5:POKEPL, I 5:POKES,89 c-a ,- lhrhLbLfr
mldrftctt
20 READH:lFH= - I THENEND
e)2 rlinnridfrl
30 READT
e/, llfthrbct
40 READD
60 POKEHF, F:POKELF,L:POKEW,65
80 FORT= I TOD:NEXT:POKEW,64
#
#
lC.--..r.t-!dtff
ftrrtu
ll-ftr--_f,'"{Effl
85 FORT=lTO50:NEXT
#
fl
*
f,
f,
{,
roDoRE 64
f,_-- 9A GOTC^Ia
ta 1 g g D AT A34,7 5,250,13, 52,2 5g, 51,97,37 5, 13, 52, 1 25,5 1,97
o=o 'I
05 DATA25 5,57
,172,25g
fr
ft
r
)29
1
g DATA5r,97,59s,a,s,125,13,52,25g,51,g7,25g,57,172
l r5 DATAIOAA,st,97,50g
DATA_1,-1,_1
fr
a
mistoke.
You hove o wide ronge of options ovoiloble if you
differenf sound effects. Here ore l0 progromming
helpyougetstortedexperimentingwith*,na.rrl.t.
wont to creote
ideos which might
DOI.I CRYING
5A POKEW,A
= 54272
trr
trr
SE L{AV6P9R]\I, FADING
=14777
DOKE,A
.--a
Y
-4 -r
a
ao
MEAD AND $AYA ta--4
z.-)
fr
There ore mony times, though, when neither one of
quite you're trying to do, especiolly
fit the iob if it involves o lot of
f,
informotion.
Try this short Progrom:
f,
a-=-?
fl
{"
{a
{a
fl---?
I
---l
t
--l
a
*'a
a
-4
l1
?-l
a
.-4
-
READs one volue from the DATA stotement
ln line I0, the computer
fhe next vcilue in
?-2
ond ossigns thot volue to X' Eoch time through the loop
the DATA stotement is reod ond thot volue ossigned to
X,
A pointer in the computer itself keeps trock of which volue
ond PRlNTed'
is to be used
e4
next:
e-4
Pointer
j
,?'
4g DATA 1, 31, 16, 234.56 t)
t;.
When oll the volues hove been used' ond
the computer executed the t4
loop ogoin, looking for onother volue' the OUT
OF DATA error wos dis- ?-4
tl
ployed becouse there were no more volues to
READ'
.-4
--4
ta
--n?
?
?-l )
a
€-1
?,1
a
# 1t is importont to follow the formot of the DATA stotement precisely:
fr 4a DATA 1,34, [email protected], ta,234.56
- t1
'::' . ,., lthin the pro-
r. - : 'ie progrom is
#
#
voriobles, or hove orithmetic operofions in DATA lines. This would be
incorrect:
#
fr
{"
You con, however, use o string vorioble in o READ storement ond then
ploce string informotion in the DATA line. The following is occeptoble:
fl#
f
f
*
-4
tr
*
4
4
*
4 .
Notice thot this time, the READ stotement wos ploced inside o FOR
NEXT loop. This loop wos then executed to motch the number of
-n
Y
-)<
a
93
>4
r'a
E
!F
{ -<
-*1
a
-t
f
SToREingthedotopointertothebeginningofthedotolist.Addline50 t'-4
to the previous Progrom: -4
a'-
sfr GOTO
t-2
1o
a--?
ewffiffi&ffiffi$ a
-,--7
o procticol use of READ ond
The following progrom illustrotes
DATA'
rt --'7
by reoding in o set of numbers ond colculoting their overoge'
a --a
--,
a
-4
tl
.Fl
a
.n?
a
.-l
t
,u4
a
>-,
i-*e
EA
eA
e-4
tt
Line 5 sets CT, the CounTer, ond T, Toiol' equol to
zero' Line l0 READs
if the volue is
v--2
o volue ond ossigns the volue to X' Line 20 checks to see
ourflog(hereo-l).lfthevolueREADisportofthevolidDATA'CTis 2',-f'
incremented by I ond X is odded to the totol' i-4
When the flog is READ, the progrom bronches to line 50
which PRINTs
.-4
J-
-C, -'-?
--Fl
z
---- )
a
--,
!
{,
f,
_--J, the number of volues reod. Line 60 pRrNTs
tr, the totor, ond rine 70 divides
the totol by the number of volues to gei the overoge.
7< By using o flog ot the end of the DATA, you con ploce
ony number
:s'-9 Srsgrom f. volues in DATA stotements-which moy stretch
over severor rines-
of
."
7-7
{)
DATA,
{)
fl
fl
fl
{.
{"
{e
{"
* ln running the progrom, the DATA storemenrs were set
t4 up in the some
order thot the READ stotemeni expected the informotion: o nome (o
e4 string), then three volues. ln other words Ng the first time
the DATA "MIKE", A in rhe READ corresponds to r90 in the
through gets
r< 95
f7
r-)
Il'i:
ll
--,
{
---e
a.
letter or single digit. ln ony of the progroms thot you would write, it is
a4 ,t
doubt{ul thot we would hove o need for more vorioble nomes thon \J
z1)'
possible with oll the combinotions of letters or numbers ovoiloble. Buf L.
you ore limited in the woy voriobles ore used with progroms. 4
Now let's introduce the concept of subscripted voriobles. i''
A(t ) \4
L-:::: a4
This would be soid: A sub l. A subscripted vorioble consists of o letter
a4
-
followed by o subscript enclosed within porentheses. Pleose note the --e
tL
difference between A, Al, ond A(l). Eoch is unique. Only A(1) is o 7--?
subscripted vorioble.
Subscripted voriobles, like simple voriobles, nqme o memory locotion 3
within the computer. Think of subscripted voriobles os boxes to store
informotion, iust like simple voriobles:
7-?
7--7
A(0)
A(t) ra
-,-2
A(2) a
A(3)
A(4)
--e
ll
.rt
lf you wrote:
1' -
INPUT or READ stotements.
Let's use subscripted voriobles to do the overoges o different woy.
fr
f,
5J
14
f
6<
fl
fl
fl
fl
f,
-44
tl
--"4
a
--r-?
rl
---)
a
2-4
t,
z-4 this progrom, buf it illustrotes how subscripted voriobles work. Line r0
osks for how mony numbers will be entered. This vorioble, X, octs os
e-4 the counter for the loop within which volues ore enrered ond ossigned to
the subscripted vorioble, B.
e_4 Eoch time through the INPUT loop, A is increosed by I ond so the next
e_4 volue entered ls ossigned to the next element in ihe orroy A. For exom_
t'2 ple, the first time through the loop A : I, so the first volue entered
is ossigned to B(l). The next iime through, A : 2; fhe next volue is
c*2 ossigned to B(2), ond so on until oll the volues hove been entered.
eY' But now o big difference comes into ploy. Once oll the volues hove
been entered, they ore stored in the orroy, reody to be put to work in o
--4
It voriety of woys. Before, you kept o running totol eoch time through the
--4
z
--4
11
?-4
q
---l
I
I
a -a
-4
a
t--1,
INPUT or loop, but never could get bock the individuol pieces of
READ ---
doto wilhout re-reoding the informotion.
ta --
ln lines 50 through 80, onother loop hos been designed to odd up the tJ'
vorious elemenls of ihe orroy ond then disploy lhe overoge. This sepo-
rote port of the progrom shows thot oll of the volues ore stored ond con
a4
a4,
be occessed os needed.
To prove thot oll of the individuol volues ore octuolly stored seporotely
3
in on orroy, type the following immediotely ofter running the previous
progrom: f,
-4
t
* l*_ i
A : I TO 5 : ?B(A),:
fl
FOR NEXT
:;" Nt;'
12s 167 189
fl
167
158 :* i
The disploy will show your octuol volues os the contents of the orroy
a4
ore PRlNTed.
a-t
ffi$MffiFd$fi#ed f,
lf you tried to enter more thon I0 numbers in the previous exomple, 74
*-a
you got o DIMENSION ERROR. Arroys of up to eleven elements (sub- a
scripts 0 to l0 for o one-dimensionol orroy) moy be used where needed, *-a
rt
iust os simple voriobles con be used onywhere within o Progrom. Arroys
of more thon eleven elements need to be "declored" in o dimension I--/,
stolement.
Add this line to the progrom:
5 DrM B(r00)
.n
-t
This lets the computer know thot you will hove o moximum of 100 14
elements in the orroy. ,--2
1
The dimension stotement moy olso be used with o vorioble, so the
following line could reploce line 5 (don't forget to eliminote line
,A
15 DrM B(X)
5):
i-a
This would dimension the orroy with the exoct number of volues ihot t4
will be entered.
Be coreful, though. Once dimensioned, on orroy connot be redimen-
t,2
sioned in onother port of the progrom. You con, however, hove multiple t)
orroys within the progrom ond dimension them oll on the some line, like ,-4
th is: ),-e
a
l0 DIM c(20), o$q, Eual
-4
t
--,-a
a
*4
(.
_--
t )
i-,
{/t
(<
\a-.4 SIMULATED DICE ROII" WITH ARRAYS
ta As progroms become more complex, using subscripted voriobles will
:rtdown on the number of stotements needed, ond moke the progrom
{-n
fr
{7
s,.npler to write.
A single subscripted vorioble con be used, for exomple, to keep trock
c{ the number of times o porticulor foce turns up:
I REI'I DICE SIHULRTION : PRII{T tlHR$( r47)
fl 3A R = IHT(6#RH0(1)i+1
4B FtJR.:=F(R)+1
NEXT L
i-3 =a
6g PRINT , "NU1.1BER OF TIf,lES',
C = I TO 6 : PEIHT C, F(C):
{t 7A FOR NEXT
aa The orroy F, for FACE, will be used to keep trock of how mony times o
porticulor foce turns up. For exomple, every time o 2 is thrown, F(2) is
{t ncreosed by one. By using the some element of the orroy to hold the
fl octuol number on the foce thot is thrown, we've eliminoted the need for
fl -ive other voriobles (one for eoch foce) ond numerous stotements to
check ond see whot number is thrown.
{t Line 'l O osks for how mony rolls you wont to simulote.
fl Line 20 estoblishes the loop to perform the rondom roll ond increment
the proper element of the orroy by one eoch for eoch toss.
14 After oll of the required tosses ore completed, line 60 pRlNTs rhe
r-" heoding ond line 70 PRINTs the number of times eoch foce shows up.
A somple run might look like rhis:
r-a
r'-a
z--"
t4
*?'
*/.
v4 Well, ot leost it wosn't looded!
t-' Just os o comporison, the following is one woy of re-writing the some
progrom, but without using subscripted voriobles. Don't bother to type it
>_/, in, but do notice the odditionol stotements necessory.
!
-/t
t
<<
r/t
i-t
ffi
:lr
a-
-4
a
fl A
1IA IHPUT "HOT,I I'IFNY EtrLLs:";H tr I
?BFDRL=1TOH
36 R = IHT{S*RHO(1Ji+l 1r'
:
4gIFE=1THEt'lFl=Fl + HEHT
a4
41 IFR=2THEHF2=F2+
42 IFR=3THEl'lF?=F3+
43IFR=4THEHF4=F4+
44IFR=5THEI{F5=F5+
:
:
:
:
i.lE.'{T
t'lEliT
HEXT
i-{EHT
3
f,
45 IFR=6THEl.lF6=F6+
6S PRIHT , "HUT,IBER
:
AF T I I4ES ''
l'iEHT
fl
7E PRIT.IT L, FI
71 PEIttr 2, F2 f,
7E FRIT.IT ;1. F3
73 PRINT 4, F4 3
;?4 PRIHT 5, F5
75 PRIHT 6, F6 fl3
The progrom hos doubled in size from I to l6 lines. ln lorger pro-
groms the spoce sovings from using subscripted voriobles will be even
flfl
3
more dromotic.
fr
11', ROW
1< q
14
I
#
2
3 25s
f 4
r-"
,'*--?
Try this: con you think of o woy using o two-dimensionol orroy tr:
tobulote the results of o questionnoire for your club thot involved four
questions ond hod up to three responses for eoch question? The prob-
tt
r.e -- l lem could be represented like this:
*
4 CLUB QUESTIONNAIRE
QUESTION I
QUESTION 2 -4
3
QUESTION 3
QUESTION 4
-4
I
-4
I
I-:-a
for the questionnoire might
The progrom to do the octuol tobulotion
look like thot shown on Poge 103'
This progrom mokes use o{ mony
hove been presented so for' Even
of the progromming techniques thot
if you don't hove ony need for the
3---a
a
octuol progrom right now' see i{ you con follow how ihe progrom .-?
I
works.
The heort of this progrom is o 4 by
3 two-dimensionol orroy' A(4'3)'
onswer to eoch question ore held a --a
The totol responses {o'-eoch possible
in the oppropriote element of the orroy'
For the soke of simplicity' we
(A(O'O) to A(0'4))' Remember'
I---,
don't use the first rows ond column I--,
present ony orroy you design'
in
though, thot ihose elements ore olwoys is in- *--,
YES' then A(l
ln proctice, if question one is onswered column I for o'1)YES re- a
cremented by one-row 1 for question
I ond --,
some pottern'
onsY:rs follow the a
,Oon.u. The rest of the questions ond
A NO respon." to'q"'ion th"u would
odd one to element A(3'2)' ond tl-*,
so on. -,
{
,-*,
t
.?2
ia
*a
^r-
"_4
t-
t)
,,-4
l--t
t
--4
I
{
.-4
(.-4
t-_- )
--5
!t
-4
a
a4
I
<= "lS:
5-
ir
". l:: IDED
74
54
#
-{"
fl
fl
fl
fl
-f,
4
!t
-Fl
a
.F?
a
--,
t,
14
r-,
14
e-4
Y4
??'
2y'-
v2
14
.-4
i-< t03
--4
{
r_--?
--/a
rll
t
T
t
I
t
ll
t
I
t
t
I
a
t
I
a
a
a
a
a
t
t
|l
I
t
a
t
t
t
t
!
a
a
a
,>
t,
?t,
?
a
-
!f
a
a
a
f
d
ff rffiA
#e co[mDo!
f4 AND 3()Fil
f
*
INTRODUCTION
Now thot you've become more intimotely involved with your Commo-
4
{,
rcCETreS
Ifl=Gffifld
dore 64, we wont you to know thot our customer support does not stop
here. You moy not know it, but commodore hos been in business for
over 23 yeors. ln ihe 1970's we introduced the first self-contoined per-
?
ff
{nd@h--{q
3 Frr qfiri rn-lr
sonol computer (the PET). We hove since become the leoding computer .ffiffi
compony in mony countries of the world. Our obility to design ond hbbd
monufocture our own computer chips ollows us to bring you new ond 4 fiiD"kffi
better per:onol computers ot prices woy below whot you'd expect for \|a o m-mrabd
this level of technicol excellence. tutlhftJl
ry&r'ffi
Commodore is committed to supporting not only you, the end user,
but olso the deoler you boughi your computer from, mogozines which
publish how-io orticles showing you new opplicotions or techniques,
>.
>
-{ ,cffr ef, iffi
turhril*I
ond imporiontly sofiwore developers who produce progroms
on cortridge, disk ond tope for use with your computer. We encouroge
you to estoblish or ioin o Commodore "user club" where you con leorn
new techniques, exchonge ideos ond shore discoveries. We publish two
>
?
iE[Eftmt
rnrtrrEt'
r ffin-,lb-
Gutfi'
seporote mogozines which contoin progromming tips, informotion on
new products ond ideos for computer opplicoiions' (See Appendix N)'
ln North Americo, Commodore provides o "Commodore lnformotion
ft treont
ture.6mfu
fmun:r dtifll.
Network" on the CompuServe lnformotion Service
network, oll
vlcMoDEM
you need
telephone
is your commodore
interfoce cortridge
64
(or
compuler
other
to occess this
ond our low cost
compotible modem).
*
i* o firhr-hG
&cs#..
rrdhE(
The following
rion which
efficiently.
help
They
APPENDICES
you
olso
progrom
include
contoin
your
chorts,
Commodore
importont
tobles,
informotion
64
ond
on
other
foster
the wide
informo-
ond more
voriety
*
4 F*.offiit
ErIrilrE
otrG.-rt
of commodore products you moy be interested in, ond o bibliogrophy rrH:bhG
listing of over 20 books ond mogozines which con help you develop your
progromming skills ond keep you current on the lotest informotion con-
d. t ldrffii
D!kif
>4
cerning your computer ond peripherols.
>
>,
a
a--'
{,
64 APPENDIX A
t' -lJ
l}' -
f" COMMCIDSRE &4 ACCffiSS#RIH5
{"
{" AN D SGFTWARffi
{7
r-7
-,: .:: ,.,,.i. your Commo-
i-" ACCESS0Rt€5
:-.' :-:cc.1 does not stop {? The Commodore 64 will support commodore vrc 20 sroroge
devices
'i -:: tr-3^ in business for
'-: j-.' s: f-contoined per-
{7 o.d occessories-DATASSETTE recorder, disk drive, modem, printer _
so your system con expond to keep poce wirh chonging needs.
::-:'-- eoding computer {? Dotosette Recorder-This row cost tope unit enobres progroms ond
I - - :: -; to design ond {" '
doto to be stored on cossette tope. ond ployed bock ot o loter
: -: .: ^..g you new Ond
: : ,", ,". - =' 1oa'd expect for {" time. The dotosette con olso be used to ploy pre_written progroms.
€*t
--,
a
--,
a
the full ronge of CBM peripherols including disk units ond printers. tt a--
Additionolly, o 280 cortridge will ollow you to run CPIM* on the
Commodore 64, giving you occess to the lorgest bose of
t'
microcomputer opplicotions ovoiloble'
f-4
a
t-4
SOFTWARE
a---2
Severol cotegories of softwore will be offered for the Commodore 64,
providing you with o wide voriety of personol, entertoinment, ond edu-
cotionol opplicotions to choose from. t---)
BUSINESS AIDS fl
fl
. An Electronic Spreodsheet pockoge will ollow you to plon budgets,
ond perform "whot if?" onolysis. And with the optionol grophic 3
progrom, meoningful grophs moy be creoted f rom the spreodsheet a4
a-4
doto.
a Finonciol plonning, such os loon omortizotion. will be eosily hon-
dled with the Finonciol Plonning Pockoge. -4
tl
a A number of Professionol Time Monogement progroms will help d/4
monoge oppointments ond work lood. a
. Eosy-to-use Doto Bose progroms will ollow you io keep trock of :44
a
informotion moiling lists phone lists inventories
ond orgonize informoiion in o useful form. a -,
a Professionol Word Processing progroms will turn the Commodore 64 >A
into o full-feotured word processor. Typing ond revising memos,
letiers, ond other text moteriol become o breeze. 4
t
4
ENTERTAINMENT
*
The highest quolity gomes will be ovoiloble on plug-in cortridges
for the Commodore 64, providing hours of enioyment' These pro-
4
4
groms moke use of the high resolution grophics ond full sound
ronge possible with the Commodore 64.
Your Commodore 64 ollows you oll the fun ond excitement ovoil-
tA
t)
oble on MAX gomes becouse these two mochines hove completely
compotible cortridges. 4
'*4"t1
a
lnc'
"CP/M is o regisiered trodemork of Digitol Reseorch
.4/)
rL
F4'?
1
P€tl
rL
-/,
CF
5-,
61
_1:-E :i r, S_CpOn
fl
4 EDUCATION
-- -: :-: 3'-'ers. 5o o The Commodore 64 is o tutor thot never tires ond olwoys gives
I --- ::r,'' ^' 'he
5,'
:-:::':trse 3;
fr
fr
personol ottention. Besides occess to much of the vost PET educo-
tionol progroms, odditionol educotionol longuoges thot will be
ovoiloble for the Commodore 64 include PILOT, LOGO ond other
key odvonced pockoges.
14
e4
c4
{"
(<
5<
64
c4
{ -: --: {"
:r::":-: .^.
i
{,
,-*?
!f
FF,,
a
*
4
4
q4
e4
e4D
r*!. , J_
= =:=
- lrti-- i
--- J :--'U
- -
.
YJ
t/.
L UiJ
=I. = =
C4
j
fl
--zt
a
-tt?
j
cat
.-
\
APPENDIX B
C
7;
;- ,.!ry {a\"r* l,nqr r-mtmf
>
a,
:€ I q- ";Etr--
IFE* -"1..t'.'5
3G-*- F I
>
"'=-
Stotements used with doto files ore OPEN, CLOSE, PRINT#, INPUT#,
ond GET#. The sysrem vorioble ST (stotus) is used to check for tope
morkers.
t-'1 'mrrm
A MIr,',@llrtutrf
Y@ ftaoxm
ff ff'
i
In writing doto to tope, the some concepts ore used os when disploy- t-,.4
ing informotion on the computer's screen. But insteod of PRlNTing in-
ar, ffi-*: - .f,ii'i'
formotion on the screen, the informotion is PRlNTed on tope using o \ ?* :tt;t - tu
voriotion of the PRINT commond-PRINT#. -E 3IF,:*'- ;{f . ffi
\
The following progrom illustroies how this works:
t-.'4 :m Iiil-: 5Er
rE PRIHT,,T,.IRITE_TO_TIIPE_PF:DEEBI.1.,
2A OPEH l,r'1."tr8TFr FILE"
36 PEII.IT "T!'PE NBTII TI] BE :{TOREB UR TYFE
58 PRINT
STOP" >
)
b
6s INPUT "offTB";ff$
7A PRINT *1, Hf
BB IF FI:S .{}.,ST[IP., THEN 58
9g PRIHT
7
>
lEA PRINT "L]LL"ISI}.IG FILE"
118 CLOSE T
The first thing thoi you must do is OPEN o file (in this cose DATA FILE). ?
Line I0 hondles thot.
The progrom prompts for the doto you woni to sove on tope in line
60. Line 70 writes whot you typed-held in A$-onto the tope. And the
process continues.
>
lf you type STOP, line I l0 CLOSES the file.
*
2
h
llo >
h
>.
e4
a--1
# -: .etrieve the informotion, rewind the tope, ond iry this:
7<
f- 1.
:8
F,E:i I.lT,.EEIiR-TFIFE-F'ROL:F.:FIf,I,,
r:rFEi.] 1 . I .tal, "E|FITF| FILE"
-i'J PPIl.,lT "FILE
-f,
OPEI'I"
.19 PFt I t.iT
PERATION :6 Ii.iPLtT#1. ES
c< :'tl PFt I l{T B:S
<<
fl Agoin, the file "DATA FILE" first must be OPENed. ln line 50 the pro-
crom INPUTs A$ from fope ond olso PRINTs A$ on the screen. Then the
.'.'hole process is repeoted until "STOP" is found, which ENDs the pro-
{"
fl grom.
A voriotion of GET-GET#-con olso be used to reod the doto bock
fl irom tope. Reploce lines 50-80 in the progrom obove with:
f4 5t:i GET#I, HS
{" Stjr IF Fl$ - "" THEN Et'tn
it-] PEIl.lT ri$. FlsrlriFl$i
! EB [iL-rTL-l srlr
14
--,
,4?
j
,.,-a
a
a-)
4
't- "
e4
e4
v/,;)
Y_-,
v-z
b4
P-4
\f
r/-l
t5
-*t-l
j
>-'-?
3
?---,
\!
a-4
a--,
I
I
APPENDIX C 4
t'1
t
I 2
coMnnoDoRE 64 BASre I -*4
I 4
This monuol hos given you on introduction to the BASIC longuogs- t -*t
enough for you to get o feel for computer progromming ond some of
D
a
the vocobulory involved. This oppendix gives o complete list of the rules
I
4
(SYNTAX) of Commodore 64 BASIC, olong with concise descriptions.
Pleose experiment with these commonds. Remember, you con't do ony
permonent domoge to the computer by iust typing in progroms, ond the
3
4
a
t4
best woy to leorn compuling is by doing.
This oppendix is divided into sections occording to the different types
of operotions in BASIC. These include:
l}
4
a-4
l. Voriobles ond Operolors: describes the different type of voriobles,
legol vorioble nomes, ond orithmetic ond logicol operotors.
2. Commonds: describes the commonds used to work with progroms, I-4
edit, store, ond erose them. ---l
1
3. Slolemenls: describes the BASIC progrom stotements used in num-
bered lines of progroms. 1
4
a -4
4. Functions: describes the string, numeric. ond print functions.
--,
j
VARIABTES 4
^ t,E F_AI: ; !
The Commodore 64 uses three types of voriobles in BASIC. These ore
reol numeric, integer numeric, ond string (olphonumeric) voriobles.
Vorioble nomes moy consist of o single letter, o letter followed by o ;*
number, or two letters. CA
An integer vorioble is specified by using the percent (7o) sign ofter the
vorioble ncme. String voriobles hove the dollor sign ($) ofter their .A
nome.
-4
EXAMPTES
,)
*-"2
Reol Vorioble Nomes: A, A5, BZ
lnteger Vorioble Nomes: Ao/", Asyo, BZ"/o
:4
t
!-r?""4
l I2 -.4
t
-?Jl
tL
)-/lrFF-
tl
a*,
14,
fl S'ring Vorioble Nomes: A$, A5$, BZ$
l, A.roys ore lists of voriobles with the some nome, using extro numbers
': specify the element of the orroy. Arroys ore defined using the DIM
s'c:emeni, ond moy contoin flooting point, integer, or string voriobles.
f" 'Te orroy vorioble nome is followed by o set of porentheses ( ) enclos-
fr
a
NOTE: There ore three vorioble nomes which
're
ore reserved for use by
Commodore 64, ond moy not be defined by you. These voriobles
fl c.e, S'[, Tl, ond Tl$. ST is o stotus vorioble which relotes to input/output
:perotions. The volue of ST will chonge if there is o problem looding o
i-? crogrom f rom disk or tope.
Tl ond Tl$ ore voriobles which relote to the reol-time clock built into
C-? rhe Commodore 64. The vorioble Tl is updoted every r/aoth of o second.
11 I storts ot 0 when the computer is turned on, ond is reset only by chong-
* + Addirlon
t-t -
- -- ^:^-.L^
- Subtroction
i -:^. .!^i- * Multiplicotion
tfi / utvtston
2
E/t I Roising to o power (exponentioiion)
2-/t On o line contoining more thon one operotor, there is o set order in
{? which operotions olwoys occur. lf severol operotions ore used together
{t I I3
{t
r-7
{,
l*
ffi
ffi
ffi
tl
['t
i
i
f,
d
f, E
on the some line, the computer ossigns priorities os follows: First, ex-
ponentiotion. Next, multiplicotion ond division, ond lost, oddition ond
ffr husdl
sublroction.
You con chonge the order of operotions by enclosing within po-
rentheses the colculotion to be performed first. Operotions enclosed in
fr
f,
im;p
ilr![E-
ush
tla-4,ft
!ffD ts
lF A: B OR C : D THEN 100 (Allows either port to be true)
f, !oo'Nmr(t' h
f, efl@fr
rEtDlre,'
rd
h*
I
COMMANDS *
un@ *-, ld
CONI (Conrinue) *
* E
lo restort lhe execution of o progrom which hos
This commond is used
been stopped by eirher using the STOP key, o STOP slotement, or on 7- faorrnud-
END stotemenr within the progrom. The progrom will restort ot the exoct {, rqrqii*tl
ploce from where it left off. srH"lbb-EC
CONT will nol work if you hove chonged or odded lines to ihe pro-
* ff:Bomdr
grom (or even iust moved the cursor), or if the progrom holted due to on * hilcgmd
error, or if you coused on error before trying to restort the progrom' ln ,4
t,
tltprurob
ihese coses you will get o CAN'T CONTINUE ERROR'
tt4
f,
f, o
3
f,
9l '
-1,
:rrS tr.,Sr, eX_
c:3'':- ond
H
,fr, LIST
-:e
5tr commond ollows you to look ot lines of o BASIC progrom in
LIST
-en-rcry. You con osk for the entire progrorn to be disployed, or onl;,
!F.: :: - j ry.n F po-
Sbt.
3l:c':.:-!
{:na 5
e-c:sed in
#
#
:etoin line
.IS T
numbers.
# -iST
.isT t0
l0- Shows only from line l0 until end
Shows only line lO
#
fi"
-rsT -t0
_rsT t 0-20
Shows lines from beginning until I0
Shows line from lO to 20, inclusive
#
f)
LOAD
-; E\
fl within quotes. The nome moy then be followed by o commo ond
number or numeric vorioble, which octs os o device number
enclosed
o
to indicote
where the progrom is coming from.
<4
-, lf no device number is given, the commodore 64 ossumes device #r.
fl which is the cossette unit. The other device commonry used with the
LOAD commond is the disk drive, whlch is device #8.
42 LOAD A$
HELLO, ond loods progrom. if found
Looks for progrom whose nome is in the vorioble A$
''-
t4
LOAD "HELLO",8
LOAD "X",8
Looks for progrom colled HELLO on the disk drive
Looks for first progrom on disk
e4 NEW
e/, This commond eroses the entire progrom in memory, ond
Y-2r olso cleors
out ony voriobles thot moy hove been used. Unless the progrom wos
v2 SAVEd, it is |ost. BE CAREFUL WHEN YoU UsE THIS COMMAND.
fl I I5
{,
it
{!
f
d
ff,
RUN
E
This commond couses execution of o progrom, once the progrom
looded into memory. lf there is no line number following RUN, the com-
is F
ff
EdcIt
ryqfrftmlr
*tE"hrcfr
puter will stort with the lowest line number. lf o line number is desig-
noted, the progrom will slort executing from the specified line.
firtftgf-tGrr
f,
f,
ffrH
urrrre
mffi"lh
5
SAVE
v#
the computer will give the progrom thot nome, so it con be more eosily ta
locoted ond retrieved in the future' The nome moy olso be followed by
o device number.
't (rcr -"i
ql
*:
After the device number, there con be o commo ond o second
number, either 0 or I . lf the second number is l, the Commodore 64 will
put on END-OF-TAPE morker ofter your progrom' This signols the
C
compuler not to look ony further on the tope if you were fo give on * 'Erdtflr
odditionol LOAD commond. lf you try to LOAD o progrom ond the com-
puter finds one of these morkers, you will get o FILE NOT FOUND ER- * rtnr .h!htr
IdLa-.
ROR. *
SAVE Slores progrom to tope without nome * GT
SAVE "HELLO" Stores on tope with nome HELLO * OD*h{r
SAVE A$ Stores on tope with nome in A$
fm,E
SAVE "HELLO",8
SAVE "HELLO",I ,I
Stores on disk wirh nome HELLO
Stores on tope with nome HELLO
ond follows progrom with
morker
END-OF-
#
*
*
ftid-BdL
&rftr3f
brJlr*t'r
TAPE
zQ
3
il6
>
?e
t
v
€1
54
t'4
VERIFY
r'rri: ; - r. '-: :: - -
fr
f,
This commond couses the computer to check the progrom on disk or
tope ogoinst the one in memory. This is proof thot the progrom is octu-
olly SAVEd, in cose the tope or disk is bod, or something went wrong
i8:1'n: -:
5< during the SAVE. VERIFY without onything ofter the commond couses the
fr
1<
VERIFY "HELLO" Seorches for HELLO, checks ogoinst memory
VERIFY "HELLO",8 Seorches for HELLO on disk, then checks
-
Te-:
."
.h|e.: f-14 STATEMENTS
crosE
e
fl , This commond completes ond closes ony files used by OPEN stote-
ments. The number following CLOSE is the file number io be closed.
tl
e.) CLOSE 2 Only file #2 is closed
?4
4
t}
ctR
4
4 This commond will erose ony voriobles in memory, but leoves the
progrom itself intoct. This commond is outomoticolly executed when o
RUN commond is given.
*
V4 CMD
e?' CMD sends the output which normolly would go to fhe screen (i.e.,
v/, PRINT stotements, LlSTs. but not POKEs onto the screen) to onother de-
c/, vice insteod. This could be o printer, or o doto file on tope or disk. This
device or file must be OPENed first. The CMD commond must be fol-
-/l
j lowed by o number or numeric vorioble referring to the file.
--1o
3 Il7
-4
j
.-4
tb
tl?/) F.
fl
f,
f,
OPEN
CMD I
I,4 OPENs device #4, which is the printer
All normol output now goes to prinier fr
fr
mnmurq;rfft
bt!8fr*Jr
il*dhbl
LIST
DEF FN fl tfrrmlt.r
fl ftgmrrird
This commond ollows you io define o complex colculotion os o func-
tion with o short nome. ln the cose of o long formulo thot is used mony
times within ihe progrom, this con sove time ond spoce.
#
#
Irf (h- he=E
hhmuffid
The function nome will be FN ond ony legol vorioble nome (l or 2
chorocters long). First you must define the funclion using the stotement
DEF followed by the function nome. Following the nome is cr set of po-
#
€+t
Ftml"lturqrfl
@trdtdCr
rentheses enclosing o numeric vorioble. Then follows the octuol formulo
thot you wont to define, with the vorioble in the proper spot. You con * mt(fU.-fDII
then "coll" the formulo, substituting ony number for the vorioble.
: 12*Q4.75 - X/.3)
f, TFrL
trmr.
tA DEF FNA(x) * k ud d th Lqrr
2l PR|NT FNA(7) t
t I 7 is inseded where
* crdrilrrtrcd
.*Jdi{:ELfl
X is in the formulo
* E,
For this exomple, the result would be 137. * -ErL
CE
cr*a
e-*, LGgffirI
(hr-rh-t
DIM
q-' bhrfl
When you use more thon I I elements of on orroy, you must execute o
DIM stotement for the orroy. Keep in mind thot the whole orroy tokes up 4
f,
dffi L-.trf
r r8
4
4
fl
g"ir
#
#_-b '::- n memory, so don't creole on orroy much
5' :: tgure the number of voriobles lorger fhon you,ll need.
creoted with DlM, multiply the totol
t,,,b :',l- ber of elements in eoch dimension of the
orroy.
fi 111
fr
fr
tr] ELEMENTS 16 EIEMENTS
fl END
fl FOR,..TO,..STEP
use CONT to restort the progrom.
{)
f) This stotement works wifh the NEXT stotement
the progrom o set number of times. The formot
to repeot o section of
{) is:
{7 l0 FOR L : r TO tO STEP .t
{a 2O PRINT L
3O NEXT L
*
t" The end of the loop volue moy be followed
onother number or vorioble. ln this cose, the
by the word STEp ond
volue following STEp is
* odded eoch time insteod of I . This ollows you
to count bockwords, or
e4 by froctions.
tlt GET
{t t19
{t
ta
{3
I--
-4
a
fr
grom would holt with on error messoge. The GET stotement moy be \ 3t--
fJ
ploced into o loop, checking for ony empty result. This loop will continue
until o key is hit.
a-4
o RETURN stotement is encountered, the progrom iumps bock to the
stotement immediotely following the GOSUB. This is useful if there is o
routine in your progrom thol occurs in severol ports of the progrom. a ,
a-4
lnsteod of typing the rouline over ond over, execute GOSUBs eoch time
the routine is needed.
a
*-,
20 GOSUB 804
GOTO OR GO TO
-4
!}
>A
a
When o stotement with the GOTO commond is reoched, the next line
to be executed will be the one with the line number following the word -4
a
GOTO.
--,
f
IF. . .THEN --,
lF. . .THEN lets the computer onolyze o situotion ond toke two possi- ;"
lf the expression is
ble courses of oction, depending on the outcome.
true, the stotement following THEN is executed. This moy be ony BASIC <A 'r:.
stote me nt.
lI the expression is folse, the progrom goes directly to the next line.
tfr
The expression being evoluoted moy be o vorioble or formulo, in ,/'
which cose it is considered true if nonzero, ond folse if zero. ln most L
coses, there is on expression involving relotionol operotors (:, <, >, P4
(:, ):, <>, AND, OR, NOT). t
*41
b
I20
-41
tL
-r4
tb
f-/)
-.**-
a-?
# ---a
tJ .} , , > 'i-i-HEN
r: END
lr IN PUT
fr
tJ
{"
-^e
rNPUT stotement o,ows the progrom
to get doto from the user,
:ss cning thot doto to o vorioble. The progrom
-:" moTk (?) on the screen, ond woit will stop, print o ques_
for the user to fype in the onswer
:"c hit RETURN.
fl NPUT is foliowed by o vorioble nome,
or o list of vorioble nomes,
5< seooroted by commos. A messoge moy be ploced
:e{ore the list of voriobre nomes to be tNpUT.
's to be rf
within guote morks,
more thon one voriobre
lNpUT, they must be seporoted by commos
when typed.
-"
{" '3 INPUT "PLEASE ENTER YOUR FTRST
NAtvlE ,,;Ag
{t 2; PRINT "ENTER YOUR CODE NUMBER";
: INPUT B
{?
fl INPUT#
# 'le or device.
.Z
.l INPUT#I, A
34 LET
c4" ZLETA:5
:
c4 27 tET D$ "HELLO"
c;" NEXT
ON
S"dfrnrltf
r
This commond turns the GOTO ond GOSUB commonds into speciol
versions of the lF stotement. ON is followed by o formulo, which is
evoluoted. lf the result of the colculoiion is one, the first line on the list is
?ff, ffirdl+ft
executed; if the result is 2, the second line is executed, ond so on. lf the
tu4.nryffi
b lln utHh rfl b*
result is 0, negotive, or lorger thon the list of numbers, the next line
executed will be the stotement following the ON stotement.
ff? ri!*d*#-
mriffi!iln"o
IO INPUT X
2A ON X GOTO \A,2A,3A,4g,5g
OPEN
ft ! SrttrIt
tnffi3*8,
0
The device numbers ore:
Screen
? -u-rrydr
lhfu* rilDirra
ql6I
?
/t, hndbr
I Cossette
kmfrr*
4 Printer
8 Disk
Muftm ilrtll
* ffin omln eibft
Following the device number moy be o third number. seporoted dl rfrilr
* rmrt
ogoin by o commo, which is the secondory oddress. ln the cose of the
cossetle, this is 0 for reod, I for write, ond 2 for write with end-of-tope
morker.
i?
4
I{h- ,rlrlr h' ttb ildrl
dilfitunn mtn
ln ihe cose of the disk, the number refers to the buffer, or chonnel, nlm-l're
number. ln the printer, the secondory oddress controls feotures like ex- * ,lrm.1etr"t
ponded printing. See the Commodore 64 Progrommer's Reference Mon-
uol for more detoils.
122
>
F4
>t
j
f Fillf n*f,
>.
s{
#
fr
ta
., OPEN 1,0 OPENs the SCREEN os o device
2E OPEN 2,1,A,"D" OPENs the cossetfe for reoding,
f, file to be seorched for is
fr
fr
30 0PEN 3,4
49 oPEN 4,8,15
OPENs the printer
D
#
fl POKE
c4
4 Text String with quotes
Vorioble nomes
c4 Functions
e4 Punctuotion morks ore used to help formot the doto on the screen.
e4 The commo divides the screen into four corumns, while the semicoron
suppresses oll spocing. Either mork con be the losf symbol
on o line.
v-4 This results in the next thing pRlNTed octing os if it were o
of the some PRINT stotement.
continuotion
v-4
e4 IO PRINT "HELLO"
20 PRINT "HELLO",A$
{t 30 PRINT A+B
*-'-')
-
-)
-l
{)
f/-,
? r
40 PRINT J;
6O PRINT A,B,C,D
PRINT#
ff mdr rd irHi
st
There ore o few differences between this siotement ond PRINT'
PRINT#isfollowedbyonumber,whichreferstothedeviceordotoflle StlB;Ltrrdfrr
previously OPENed. This number is followed by o
commo ond o list to be
* O{&"hgn
printed. The commq ond semicolon hove the
PRINT. Pleose note thot some devices moy
some
not work
effect os they do in
with TAB ond SPC' f? p;lrDffida
ffi,bbfl
lO0 PRINT#l,"DATA VALUES"; A%,
READ
Bl' C$
?
ffl
il
mlLdrHt
"! Gftrlr,ho1:
is used to ossign informotion from DATA stotements to
vori-
READ
must be token to :) SAd;brnt-
obles, so the informotion moy be pur to use' Core
ovoid READing strings where READ is expecting
give o TYPE MISMATCH ERROR'
o number' which will
h
>.
ffiar.I
REM (Remork)
?4
offect the operotion of the progrom' except
REM stotements in no woy
to its length. REM moy be followed by ony text'
to odd
RESIORE
fr
line. SnnrrthJ
REIURN
-D.hrld
This stotement is olwoys used in coniunction
with GOSUB' When the rml-d
*
>
stotement immediotely
progrom encounters o RETURN, it will go to the
following the GosuB commond. lf no GosUB
wos previously issued' o 4 hrh.dh,
will occur'
RETURN WITHOUT GOSUB ERROR
124
>.
>.
h
llt
5-{
a-4
{4 .t SIOP
TJ
This stotement will holt progrom execution. The rnessoge, BREAK lN
xxx will be disployed, where xxx is the line number contoining STOP. The
a4
- orogrom moy be restorted by using the CONT commond. STOP is nor-
f sYs
fl
f, SYS is followed by o decimol number or numeric volue in the ronge
0-65535. The progrom will then begin executing the mochine longuoge
3 WAIT
fl WAIT is used to holt the progrom until the contents of o memory loco-
WAIT X,Y,Z
e
-4
a The contents of the memory locotion ore first exclusive-ORed with the
?/, third number, if present, ond then logicoily ANDed with the second
a number. lf the result is zero, the progrom goes bock to thot memory
2'/, locotion ond checks ogoin. When ihe result is nonzero, the progrom
rt
,,-,
ra
continues with the next stotement.
?4
4
!
--4
f I25
--4
a
--/?
j
?/a
fl
>a
COS(X) (cosine)
? A ilng*rG {*Gbl
lqEffiE mnfufuI
fr
nrilih-
t>>
Returns the volue of the cosine of X, where X is on ongle meosured in mb fumrbrbgn
rodions.
ExP(X)
drc"
Returns the volue of the mothemoticol constont e(2.71827183) roised ? Lft prdl
to the power of X. I brrh brnq:
FNxx(X) mEn
Returnsthevolueoftheuser-definedfunctionxxcreotedinoDEF iltfrrtrr iln
FNxx(X) stotement. * d'dr b.r'Fil ffilir
rNr(x)
to
Returns the truncoted volue
the right of the decimol
of X, thot is, with oll the decimol ploces
point removed. The result will olwoys be less
>
\,
\
rmF{
mLhrLr
f,rtlrrLnqf
\
thon, or equol to, X. Thus, ony negotive numbers with decimol ploces
will become the integer less thon their current volue'
>.
i.
SlF.{
taffi ral:r
LOG(X) (logorithm)
Will return the noturol log of X. The noturol log to the bose e (see i.b ilrrb,crO
rFlH{
ffi XLr
b
'l
ftdrdlh*
>
PEEK(X)
UED
Used to find out contenls of memory locotion X, in the ronge 0-65535,
givingoresultfrom0-255.PEEKisoftenusedincon|unctionwiththe
POKE stotement. 7b
krffirffiL
pfrnrladt
ilrtr,lbnd:t
RND(X) (rondom number)
RND(X) returns o rondom number in the ronge 0-1. The first rondom
number should be generoted by the formulo RND(-Tl) to stort things off
3
rl
tlridrlrr&H
g nrqurnt
dmdhrEr;l
t
;:Y
h
51
#
# A negotive volue for X will reseed the generotor. The use of the some
l- -
fr
fr
"egotive number for X will result in the some sequence of ,,rondom,,
^umbers.
The formulo for generoting o number between X crnd y is:
fr
# a., he re,
N = RND(I)*fi-X)+X
fl SGN(X) (sign)
fl 5lN(X) (sine)
f,
f, SIN(X) is the trigonometric sine function. The result
X, where X is on ongle in rodions.
will be the sine of
34
fl2.*2
ra
SOR(X) (squore root)
4
--r'l
3
-/)
t
-4
t
-47
IL
{:
STRING FUNCTIONS
1
2
=
It I: WflOO.C
tl I = WUlf
It r = ry(ilFl
>
Asc(x$)
ll r = fril--!&
This function will return the ASCII code of the firsi chorocler of X$.
>
> qrEm
>
cHR$(x)
LEFr$(X$,X)
o slring chorocler whose
>
\
rltl
Ib- --ql
rresfrdbl{}
:
\ ilhfrhrilts
Returns o string contoining fhe leftmost X chorocters of $X.
>
:1!l
\ m
rEN(x$)
RrGHT$(X$,X)
>.
b
rlll
1r--
E
;-ut-
-T
Returns the rightmost X chorocters in X$. b
b
bLtuL fl
il
srR$(x)
3
^fl
vAr(x$)
?
,d!*"
128 >.
h
t--.L
AE
51
f
51 x: VAL("]23.456") X: 123.456
lr
f. X: VAL("I2Al3B") X:12
x:fr
::ifi-':,,:-a- :- I S
fr
fr
X:
X:
VAL("RIU0l7")
VAL (" - 1 .23 .4s .67") X : -1.23
f
f OTHER FUNCTIONS
fl FRE(x)
5< This function returns the number of unused bytes ovoirobre in memory,
fl regordless of the volue of X. Note thot FRE(X) will reod oui n negotive
t -r (:
a< numbers if the number of unused bytes is over 32K.
fl POS(x)
fl This function returns the number of the column (0-39) ot which the
fl next PRINT stotement will begin on the screen. X moy hove ony volue
ond is not used.
fl-.4,
!
sPc(x)
a ,
TAB(X)
*
TAB is olso used in o PRINT stotemenr; the next item to be pRlNTed will
* be in column X.
-4
ta
*
r: i c4
c4
r'l*-: :- :-
va
vr''
4
nc:['*.--: -,e-se
f'f*r::-:-:'::-=-
Eu€ ---:e'tl'-
.4
l}
.-i)
rb
-4
rlr
?*4
tL
-/)
] r'-:
fl
APPENDIX D
F
=^J
?
C,-
d
uffiil!
lb
,rGrr
-
ABBREVIATIONS FOR
BASIC KEYWORDS
??
Iffir
UGilT
]Uf,
rulf,
r
?
?
u]6llr
u@i@
rIr
dil@ I
ril[!f,
mfi
"-i
I
words ore mode by typing the first one or two letters of the word, fol- m, ml
lowed by the SHlFTed next letter of the word. lf the obbreviotions ore
used in o progrom line, the keyword will LIST in the full form'
?f,
rffirfil
mn
ilIf,
mlo
r
Com- Abbrovi-
Lookr lihc
thir on Com- Abbrovi-
lookr like
this on
flA mi
m
ffi(
Cp {
rxm
ft
12
mond otaon tcllaon mond olion 3Cnlcn m (
pfr
ABS n@e Am END E@N Z
> B
E I
F EEo
FN
FE ht
t_
rc6
*mm!r
mf,l
,!
cHR$ c@H cfn FRE F@R FE l,
t Fmr+ pI0 r
cLosE cL@ o CLE GET G@E GLI
-I
\t NH'B oIG r
cLR c @L cE GEl# NONE GET# * qET mf,t
cMD c @tt cN GOSUB GO@S GO tr * nEsltr mI$ r
coNT c EEo cE GoTo o@o G tr * Efir'.]um mlr r
COS NONE cos tF NONE IF *
*
DATA o@n
DEF o @r
DE
DE
tNpUT
TNPUT#
NONE
|@ N
INPUT
tz 4t
e
DtM o @r Dil INT NONE INT
/4
a
r30
>
h
lD-
t
.{
f,
f, ^l Looks like
fr
ta Com- Looks like
Abbrevi- this on Com-
mond oiion screen
Abbrevi- this on
mond olion screen
L@r
LEN
LE
RND
RUN
R@N
R@U
R
R
Z
a
Lil
fl-. . JST L@r SAVE sE@ a s
tr
fl -OAD
-oG
L@o
NONE
LE
LOG
SGN
SIN s@l
SEE G S
a
u
E
{. rn tD$ M@ Mil SEO
{.
sPC( P S
n
fl NEW
NEXT
NONE
N@
NEW
NE
SQR
STATUS
s@a
ST
a
e
{) ST
.a NOT
ON NONE
N@! NE
ON
STEP sT@
SE@
E SIE
sf
ll STOP T
Lookr like
trh it on
a'
OPEN o@B p o[l STR$ sr@n STE
l<ne€ n
B. :1 l'
OR NONE OR SYS s@ilY sf[
PEE K pEE r PE TAB( T@A rf
T. =T a' POKE pEE o PE TAN NONE TAN
{,
fl: .L -'
POS NONE POS THEN TEEH rf
fl; .= fr ? PRINT
PRINT#
?
P@ R
?
P
tr
TIME
TIME$
TI TI
fl. ^: tt
Tt$ Tt$
3:-=
>-2
v
READ RE@E R
tr USR u@s up
::v e4 REM NONE RE VAL v@e v@
@. nr@s
fl: :f e?. R ESTORE RE
tr VERIFY vEE r vI
nr@r E
a 24 RETU RN RE WAIT wE@ n w@
\ PUT v4
f.. Z {t
\t
./l
ID
.s1
tD
-4
a
?/?
{J
tI
APPENDIX E
fr
#
#
SCREEN DISPTAY CODES #
*
The following chort lists oll of rhe chorocters
64 chorocter sets. lt shows which numbers
memory (locotions lO24-2O23) to gel o desired
shotrld
into the Commodore
built
be POKEd into screen
chorcrcter' Also shown is
PEEKed from the screen'
?
which chorocter corresponds to o number
one set ot o iime' This
Two chorocter sels ore ovoiloble, but only *
meons thoi you connot hove chorociers
from one set on the screen ot
the some time you hove chorocters from ihe
ore switched by holding down the @
other set disployed' The
ond @ keys simul-
?
4
>
sers
toneouslY. .,4
>
From BASIC, POKE 53272,21 will switch to upper cose mode ond
POKE 53272,23 swiiches to lower cose'
Any number on the chort moy olso be disployed
reversechoroctercodemoybeobtoinedbyoddingl2Slothevolues
-
shown.
in REVERSE' The
132
'a
h
llt
f
f,
fl 1 SETl SET2
tr -l
POKE SET' SET2 POKE SET.| SET2 POKE
fr
l1'
fi
Jj
KK
ri 9
10
Yo
&
37
38
E
m
465
866
c67
11 39
E
f, LI 12 40 tr D68
fl Mm
Nn
13 41
E E69
5< Oo
14 42 tr F70
64 Pp
15 43 E G71
fl Oq
16 44 U
t
H72
fl Rr
17 45 t73
fl Ss
18 46
N
Z
J74
K75
fl Tt
19
20 0
47
48
tr 176
fl Uu 21 1 49
N M77
34 Vv 22 2 50 Z N78
fl4
tl
Ww
Xx
23
24 4
3 51
52
tr
fI
o79
P80
-4
e
Yy
Zz
25 5 53
n o81
--,
3
26 6 54
E R82
;4 t 27 7
I
55
M s83
tl
?4
e 28 56
tr T84
r-
e
4 u85
l 29 9 57
1 30 58 x v86
c4 31 ; 59 o w87
e4 32 60 E x88
TF 2 POKE c4 33 61
m Y89
290
Cr'. 34 62 tT
e4
2{l
35
36
?
E
ll
63
64
ffi
f,
91
92
a
-<
rb
-Fl
a
*
{:
fr MD c*ij
Z E
>
105 117
m 93
@ 96 tr 108 E
tr
120
>. r*hm
fl E
>. mogft
109 121
97
E ffryry5f
tr 123
tr
>.
111
= 99 'hLdhd
tr tr 112 E 124
(ffiumrfrr
>.
100
tr E E 125 rerffibqtJ
tE
101 113
ffi
fI
102
103
E
m
114
115
126
127 >.
>.
E 104 tr 116
h ri
ri.
h
b
fi
*
#
3
d
il
2)
#
u -'
llll
C
# e.
*;
il
ll
::
*
2a
2.
h
3E
--,
a
--1
a
a4 I APPENDIX F
l' E
lfJ
74 ASCII AND ChiR$ EOE}85
74
f
\ I "-.^
a-/- #
-4
I
This oppendix shows you whot chorocters will oppeor if you pRINT
cHR$(x), for oll possible volues of X. lt will olso show the vorues ob-
");
fl roined by typing PRINT ASC("x"), where x is ony chorocter you con type.
This is useful in evoluoting the chorocter received in o GET stotemenr,
converting upper/lower cose, ond printing chorocter bosed commonds
{" iike switch to upper/lower cose) thot could not be enclosed in quotes.
{"
fl--2
I
b -1-";- -4
I E 17 34 51
-4
a
*4
A 18 3s 52
t.}
2
m 19 36 5 53
*--?
rl
3
4
B 20 37 6 54
21 38 7 55
*--)
a 5 22 39 8 56
*-',
tl 6 23 40 9 57
.4 7 24 41 : 58
14 orsreLes@@8 25 42 59
z4 eruaies@@9 26 43 60
v4 10
E
27 44 61
vae 11
12
28 45 62
ffi
r[
29 46
t,ur @ ?
@ 13 30 47 @ 64
Y-4
?-4
ffimr 14
E 31 € A 65
2--v'l
15
@ 32 49 B 66
16 ! 33 50 c 67
2 --'-7
,,*')
e
".a"
-t)
-1
a
--q
a
a1 lnilh-T }*ru t
IJ .
D 68 tlt s7 ltr 126 ffi 155
t'
E
t_.1
I::
E 69 m e8 I t! 122 156
a4
F
t,
70
71
E
tr ioo I tr 12e
@
B
157
158
3
t-2
_,b
L
M
75
76
77
m
t
tr
105 I tg
106 I f5
133
134
135
.
tr
T
162
163
164
3
3
N
o
78
79
n
tr
107 I t7
108 I t2
136
137
tr
ffi
165
166
3
-4
t
P 80 N 109 I f4 138 D 167
tt---2
o 81 Z 110 I f6 139 E 168
tr 120 E 178 *
I 91
,2 149
c U x gl
l
92
93 tT
121
122 o
150
151 tr
179
180 "2
v2
t 94 ffi 123 tr 152 tr 181 ,2
e 95 f, 124 n 153 tt 182
r4
E 96 m 125 n 154 . 183 --'?
I
-/Zl
Q
-t?
I
--?
t
---|kFrB-=
lL
'1
14
--q
rl
fl ,-A PfiII'TS CHRS PRIXTS CHRS PRII{TS CHBI PRIXTS CHBI
nrl t'
fr
3*q3 I
184 tr 186 tr 't88
il 190
E
In fl# CODES
CODES
CODE
192-223
224-254
255
SAME AS
SAME AS
SAME AS
96-127
160-190
126
@ f,
fI f,
fl
{)
t fl
I fl
--__.
fl
E *
7 --'4
C
- 4
rll
.
--,
rt
--,
e
{ >-',
tl
-_- *
I
. *
=
?4
e4
e4
f= e-?.
f 2A
I
l 4
{t
-4?
!
-4
It
;4
!
-/l
trr
,T
e
t-l
I
t
APPENDIX G ^
IJ
2
t
2
t
SCREEN AND COLOR MEMORY $IRAPS I4
t4
The following chorts list which memory locotions control plocing chor- a
-1'
octers on the screen, ond the locotions used to chonge individuol chor- 4
a
t--a
octer colors, os well os showing chorocter color codes'
1063
-a
t
t024
1064
1
t--4
-2
t---a
I 104
I 144
I 184
t2?4
1264
1304
a
t
t---A
r344
*4
r384
t424 '"=
1464
t
1504
1544
l5E4
*4
rt
r
1664
1704
624
_A
t
a --',
11 44
r7E4
t824
1864
r904
,4
a
1944
1984 *-J,
i*a
CA
c''4
a-!n
.'4
ta
-la
-/a
rb
L
./7
I
-la
It-_z)FF"
l
i{
f
{-t1 ae ociuol volues to pOKE into o color memory locotion to chonge o
TJ a-o.octer's color ore:
--_)
IORY MAPS
fr
la'
fr
3 BLACK
I WHITE
2 RED
B
9
1a
ORANGE
BROWN
Light RED
f, 3 CYAN
.1 PURPLE
'I
1 GRAY I
f,
--4
a
---a
tl
,4
a
---,
e lll
{
o
.--,
14
14
AA
e4
CA
v?.
V-/.
Z4
{.
.F?
rt
-;)
-
*
-/) F.-
lr
!-
I
L---,
APPENDIX H
f, --_.- AP.trE\] X
LJ
A
L.
ARCSINH(X)= LOG(X+SQR(XxX+ I )) _4
t
,
L-4
. --)
LF=
af
ff APPENDIX I
ff
[R,NCTIONS f PINOUTS FOR INPUT/OUTPUT DEVICES
ff This oppendix is designed
ff,
moy be colcu- show you whol conneclions moy be
tUSrc mode to the Commodore 64.
l) Gome l/O
tqMI.B{T f, 2) Cortridge Slot
4) Seriol l/O (DisldPrinter)
5) Modulotor Output
? 3) Audio/Video 6) Cossette
f, 7) User Port
n
hEoq-x'x+r)
hsron fl Control Port
Pin Type
s
hlEooo<'x-r))
hGoco<'x-r))
f,
f,
,l
2
JOYAO
JOYAI
JOYA2
12345
ooooo
im oooo
ffl 4 JOYA3
F*orr-*lr
f* 8
9
GND
POT AX
Fo-er.x-xl
Freorxl * Control Pori 2
tr+r
B+so*(x'x+r)
ftsr+se*(x'x-r))
t,
t Pin
2
I
Type
JOYBO
JOYB I
lllElt+xy(t -x)y2 * 3 JOYB2
frro*
rt f 4 JOYB3
P
5 POI BY
pGGGr.(x)'soR 6 BUTION B
7 +5V MAX. 50mA
reEIX+t1/(x-r))/2 8 GND
* 9 POT BX
*
4
f,
*
f,
4
*
f,
t'fl
Cortridge Exponsion Slot
Type
f3 C-h
?
iilllll{!
12 BA GND ${ - t'i,iu
+5V
3
l3 DMA _; -.{{Ed!E
rt
14 D7 +5V jll4
-r*ii$G l!
?
15 D6 rRa ?:
't6 -*tff 'E
D5 R/W- {'+ lE
-ffi
17
I6
l9
D4
D3
D2
DI
Dot Clock
rio
GAfrE
EXROil
r
I
f ,
f,
20
2l DO lo2 b'fG}
IoML
fl
22 GND
f,
Pin
anm
N A9
f,
--fl
P A8
I M
t'f
R A7
r llllll-
S
T
A6
A5
:m
r lfllllllE
U A4 -w:
., NE
E rffiil. *m
X A1 t d :m.:
Y AO --, r flm:
I GND a ::
*, mMl
I E76 5a3 2 e
t
2221?o19Ja 171615la13121110 t
hli
a *mm
ZY XWVU TSF PNML K J H F €OC BA ?A rm
Audio/Video
!
\r
t :fl
I rl[
r
fPt^ rvpe Note
, rrr
lr LUMINANCE ta
rye
l2 GND
* qE
l3
l4
ls
AUDIO OUT
VIDEO OUT
4
P
{ rh
ryi
e
AUDIO IN
$ ro
!h !!r}}T
4
4
! !.!l
,r4
!
atrtrE.
e 4
C
1a
,a4
a
-/4
14
{}
i{ Cossette
--zlt
fr
le
1<
GND
-5V
123456
fl CASSETTE MOTOR
CASSETTE READ
fl CASSETTE WRITE
CASSEIIE SENSE
ABCDEF
{.
.a
-, User I O
fFa
fl
--
-- '
fl 1
2
3
GND
+5V
RESET
MAX. 100 mA
--: {) CNTI
5 SP]
{.
fl 8
9
6
7
CNT2
SP2
PO
SER, ATN IN
9
{D
-, r0
ll
12
9
GND
VAC
VAC
{,
Pin Type Nole
{, GND
{, B
C
FLAG2
PBO
{, D PBI
P82
?-"
E
F PB3
a\
.:' : -;- c4 H
J
PB4
PB5
c4 K
t
PB6
P87
t4 N
PA2
GND
c-F'
t4 123456789101112
I rIIIITIITT!
c4 tt
?4
ta ABCDEFHJKLMN
fl
?4?
I43
ta
>/?
!
r-J
s'fr
#
#
APPENDIX J c,
#
D ruCltsflb
lDqts'Ei
s:tr p5lrrft
lra Fi:tt ir
PROGRAMS TO TRY
#
#
O ft*tm'ti
!I rmIfirP d],4t
f"ilD lrrnril:ifr
ar rnrrnrtr
nm fffiF fi'f
f? If rrffi
il f.-'
II st*
tI rflrl
fi?
,ilrtI
*t
\Ab've included o number of useful progroms for you to try with Your
Commodore 64. These progroms will prove both entertoining
useful.
ond f? tr -!. Iflrf
Atrrryil rdhl
iI If-
ilfl.flrirl
f,
ff,
I 5r. *tlrl
tr.tLdil
tDlIr
, -r. r*ff
Il fl. ^-^*-
rJfrf
fl{bff;n
-fl
flf e ibdFm
flH,rllr
lXaril{ -
a
.,ra ffffit
il;rfrf t I
ifE
e fif
a ! I[rr5.;(}.{t
t! frt '-rr+
F.?
a
O rr*"tE:
rm ffl'lLrl#'
tD lt Urrrff
?
*
I
il
T
l
ffiilr
d
tryfla
;mglEfl
, at rffid
?
*
{1I
am
-..*
ii*Flm
1gl,il{illJF
0 nm:rcfg
5 ;#tfftil
rr{hf
P
P
rn bJilCI
5 nDr }tt[E
5 dt
m d1
,n
4
*
fr*''II
,:!D rfffDlt!
,D 6nrx3*r'{f
fio nrlra16-
,!n trNr-n'tI
--a D fr0t'lIl !
*a
rt- f[o u{Ea,{El
f,s! ,i*!3N,tff
h"1
1
a
/4
lL L-
i-{
d
i4 jrm buttprf ield,,
t'-'l +
-:.." IranL I nstructions,';z$: i ftssc(:$)=TggotolSO
:. -._ ii1'_.U to guess the r,lUsterU
lla :'- -'" '|3'tou rnusl gupss onIU 1+gatS_1*tter :_t*tte.,,
word,,
:- -.- !on,Js. Loo,..,,
74 r- -.- ,_lou u i l1 he told th* number
fr
f,
.- -.'2 t lDr 'jots, ) of Uour qupss-,, of roatches,,
i. nr,"0hrnt: the tnick i. Io u".g sl ightlU,,
..:"1.. f rom u,,<
.''ntii
nfll
if' r !uu
quess to
one quE5b
rJupss .'t,atch'
uou ouess
miglrt
the naxt;
Lo I,ne
crElch, and
trg,hotctr,
ne:it; Eo.i thtst,,
ir,Jt,,
ana,let-i;ots,,
,get 2 ; o
icl,art,,,
i."" r nt I' f or the next guess . . . ,, or
Uou
1< oata t,xt,sf , j t,cc:rdbd i f ,esfber6,qgl,xg
deia hpshf , i bu,J i,d,jurjli,kE,m,nz, it,it t
14 dats sbkt' i, r*fr.lfrrrrn..;nj,Jrt,oofUrqiqii
,lEta rvf tu,s.ir,if sr,1sf ttrpuuf i,f*io,
a< .JBtts xf t,Hf .fr3u6,nr,nvti:raf cst,,g;r.i
dtsta u i idl.esvol r,-l,npperujhfsr;;,lfg
{" data cp,g,r_,t i , rrrz j oh, trvt,u, hhvaf , i,*; of,
,lata uisf f ,t;hiu.brJref trhsvnq,bslob
,Jata nvbsu,dsffqrcfodi
{" dala st,ebs. svsbrn, tnf rnrn,rqsfti,tqtsi
fl n=f,0
grF,r,o, *r.; g,
{a d I nt nl n ) ,: ( S ) , g ( S )
(
for j=lton:r+tsdnS( j ) :n,rxtj
t4 t)
: : 0 I or =1t o5 : if =2 (k )t henh h+1:: (
:rrl n")it. L
1,. r..;
= k )=0: ot o700 1r
t-e l,
:r0 npxt j
-i.,i c,r i nt,,0EOBIIUEUBB0[I]ilUU0lltl!I,,
--,1 I fg.i30gotog6O ;H;,,J0TS,,
z'ta -l,l E'r ,J -h*ttpr tel l gou. . wo"cl was ,,,;
fo..,=1to5:printchri(U(.;) ) ; :ner,t
attl -li c,r
-:) :qotoglO
i'
./'?l
I :'.,'l o.int"gou got it in ontg,,;r;;,,guess*s.,,
:i,) i nc,ut"FsnoU-rer word,';:g
:-) ^=1 : I {asc (:S)<,.i/g,IotoE0O
ill
-4
a
r45
-/?
I
-/t
tL
irl:i
--1
:4
,4
a,
1 r*m **} 9P'lu*nc*
t-q
I
:{
r*trt
r*trt *;} frolt t,*l; {,ls*r grouF'
a4
4
5
reii
rFtrt
+r+
**+
softwar* Bxcfranr:l*
E,o tio:l 371
c'a 1S936
a4
(rlont'JofierUvilt*'
6
7
rErtl
r*ltl
**+
1120 c=0
830 nPxt i i-q
S40 i f c=0 goto
ii6 t," int "oqou 'J 'J
900 retn checl'. for tsnotheF gam*
600
it in "; t; " tr ies" i i-r;
Pi6 ino,t "Fuant to s'larl again ";g$ )*
C20 if'1*ft$(!$.1)="u" lp r1$="oP"' 6p r1$="l" goto 300 -4
?30 *nd
950 r,r int
960 r,rint left$(zli.s)
z-,
970 for i=1 to e; g,rint a$( i );:nExt I
146
i-a
t*--l
l-l
t FF*
{-{
c{
-I---
lar
: =-. ; -;r j -r I E,r'E;L-tFE,fl
:'- ; ii !I t, i l!_t lril irlt I l!fl lril I illl ilil ,,
lf'
--/r-
: .:, .-- ;j !t !I I rlt itlt trfl i lrp trj i i!_[ [[ ,,
f, =
.- s=
i =iL:r4* : Fr:rF:I
=
i=',.-',.r:!,1:riEFciTri,r,;:t-l
:l,t:riEFET,i,r,
1f r:riri ; F, :;:_ L) =F 1+:. r:r.i::rq
l.:rr:[]iF,trl__ d C I,,
;F 1=F 1,
f, --*-=I'r-LE|'I
: f T ! JT', a
f , :r it.:,-., rnrnh,
3
ii=-'l:frE=rl:::it-l=18:FtE=_i:::i,.,r=rJt-i*1rt+FtE:filr=FtT+1r:+[rE:
tl'.'=|1i ;il=rl ;l.1=i :i:l:=,+ IHg=rIr, :I=ir
:':rRI,=r:rTr:rl:F,r:tl:.Er:i+i+Ir+I.rlT*l1t:_rfrE:Ffrf,,E!;+trt+Ji+;:.:::t-ril1r,J-F,E
3 ='-ri,.E
:' +!
r:, 1,.
+i., .+r:rr:1[iHt.lfriri : Fr-rt,: rr_:;*= 1 - iliorar].,;5"
i+t+ I
1 I : FtEl,l.r 1 ri +,::4 : F, D
E ::; +.
:'e in r : J cFf -,, ,,THEl.t:::rl,l
E t:i +: ::: . i
, ,a,,,,
f,:.
-
{, -F=F,lk,.tl:itrl,:.ti:E:i.i.r,..'l.j:I=r,r*i;rlFt=:f+T+rl:IFFFT__fTFlEl.]Frli
fl :,: i,:E::+F:+T . i
:r-;1,:Er:,+:,+T.JiF:E1,1
: F:E1.1 F
f,
4
-'_ r
a
: F = 11
c:,+:,+ t
5 ar E.:tr .,lr,r+1
g 1',,.'
*
- Hr,J : FEI,1 ,::ET HTT,.F.EL
rFrlrE. I=1Tr:r5r:1+trT : t.ttr..r
; r:rlrEr::l;: .|.J1,/ I FtEI.1 F,l-tLt:,E
tr + 1 I I F = :l T H E i..t,,,,' _ r:1
1-1 1.
-4
!l,
I FBi= " fr" THEl tt,1= 1 : rlrrl:=4 : Er:rT!:r::rl' r]
I FF$= " E" THE|{ft,=: ; i:r,::=::r : r:ir:rT,-r.:r!:i!:t
i Fri+= " 1il" TlJEl..{t,1=Jl ; r:n:t=: : r:ir:rTr:t:rlr:i
{, ] f
g
= " It" rH f I iI'1 = i:r : r:rr:: = i : rl r:rTr:r :-:r L:i r:r
: F i'f + = r' !i, THEf.tt.] rir ; p1r,r 1 .; ! r;, r:l i:r r:1r:r
r--, = = T :r
: F E .' =,, N,' THEi..]t,]= 1 I 1..11,,,= :r: : t:it:t Tr:r.lr*B
:jr
!:-r
irfi
t4 : =Fl-t=
'i
:. ;_r i:t :i
,,I"
Li
THEt.t:[tril
L::1
-p It:ir:iTr:r::ll1rl
t4 :E iltT"HIT E l:E',",
-'iTl: E ; l.FF].F=,,,!Tl"ll=ljr:r1Er !i,il-:1IT Fr:rF, t:j I E,,
: = ! rlTF$ ;f-tETt_tFri.l
t4
2r'. \ OTES:
-r,ae 100 uses (SHtFT CLR/HOME),
srBL g).(CTRL l),(sHlFT B).
Line 530 uses (f7)
./a
a
- re 510 uses (f3)
- re 520 uses (f5)
Line 570 uses (18)
Line 590 uses (SHtFT CLR/HOME)
.a
--? 147
t
.zl
t
./l
l>-
-<
:1
I
t t
APPENDIX K
t1 t
:4
I
2
CONVERTING STANDARD :4 Ih-r*[F]p furola;mc,t
": -,. :,* - -:-
BASIC PROGRAMS TO a
, :i 'd ''' -rrr
'!'"-"'"
! : -
i:
Multiple Assignmenls
To set B ond c equol lo zero, some BASICs ollow stotements of the
form: :/,
:/,
lfr B:C:A
"-'4
>
LET
148
t--l
t--a
-t
a
-*q
a.
c
Some BASICs use o bockslosh (\ ) to seporote multiple stotements on
ine. With Commodore 64 BASIC, seporote oll stotements by o colon
14
14
)
MAT Funciions
r
t
.l
1
t
*4
APPENDIX t --.
t'I illl -r-l
t
1
1
HKM&R ffiffiS$A&ffiS 1
4
I
4
I
4
This oppendix contoins o complele list of the error messoges gener- --2
11 :..*:'; m;mii'
oted by the Commodore-64, with o description of couses.
1--a
BAD DATA String doto wos received from on open file, but the pro- t4 ' :]:: - nr
4-a
on orroy whose number is outside of the ronge specified in ,he DIM I
stotement.
1
CANT CONTINUE The CONT commond will not work, either becouse
the progrom wos never RUN, there hos been on error, or o line hos
been edited. -a
*4
1
I
NOT PRESENT The required l/O device wos not ovoiloble for
DEVTCE
on OPEN, CLOSE, CMD, PRINT#, INPUT#, or GET#. --l
a i::"_i. *'--"] -
DIVISION BY ZERO Division by zero is o mothemoticol oddity ond not ,-.*,
1
ollowed.
EXIRA TGNORED Too mony items of doto were typed in response to
.-4
1
on INPUT stotement. Only the first few items were occepted.
\--*,
FltE NOT FOUND lf you were looking for o file on tope, ond END-OF-
TAPE morker wos found. lf you were looking on disk, no file wirh thot
.4
nome exists.
'-lst
FltE NOT OPEN The file specified in o CLOSE, CMD, PRINT#, INPUT#,
or GEf #, must first be OPENed. ./-a ti : "i ;: : -,- -'i m,5 u
FttE OPEN An ottempt wos mode to open o file using the number of .-* .r ii i:
on olreody open file.
FORMUTA TOO COMPTEX The string expression being evoluoted -o*
should be split into ot leost two ports for the system to work with, or o
fornrulo hos too mony porentheses.
i-*
ILLEGAI DIRECT The INPUT siotement con only oe used within o pro- \'4
grom. ond not in direct mode. ,-a
ItLEGAt QUANTIIY A number used os the orgument of o function or
stoterneni is oul of the oilowoble ronge.
,4
!
\
_/l
,j4
t
"/4
\
. r,"1
.-{
a-'tr
14 IOAD -.ere is o problem with the progrom on tope.
-Z
tJ NEXT WITHOUT FOR This is coused by either incorrecrly nesring loops
.., -' -='- j c voriobre nome in o NEXT stotement thot doesn,t.orrl.pond
1J ," '- :^e in o FOR stotement.
3
NoT INPUT FltE An offempr wos mode to rNpuT
--: ...rrch wos specified to be for output or GET doro from o
-
3
only.
Nor oUTPUT FltE An ofrempr wos mode to pRINT
doto ro o file which
3
...:s specifled os input only.
ouT oF DATA A READ stotement wos executed but
3
*r3r.5:::-i there is no doro
Sener_ :: unREAD in o DATA srotement.
3
FOR loops hove been
:i,re :-- -re pro- 'esred, or when there ore too mony GOSUBs in
effect.
+--€- 3e:ouse f, 'c'roble is used before thot orroy is DrM'd, on outomotic DrM operotion
s performed on thot orroy setting the number
of elements to ten, ond
3 :- r subsequent DlMs will couse this error.
n
r a'= rehos
REDO FROM START Chorocfer doto wos
typed in during on INpUT
ll:r:t,1 :ole for s'ctement when numeric dofo wos expected.
Just re_type the entry so
i
etc.
',: ; e ,. .- thot TYPE MISMAT.H This error occurs when
o number is used in proce of o
s-. ng, or vice-verso.
Vpr
: *-'- - ^.^ t4
-:' cn or 4
tl-4
{)
fl
--l
t5r
tf
*
<
-1
t
APPENDIX M -1 *t{L ). *4!
I rdi- i
4
4
MUSIC NOTE VAI.UES \
4
4
\-4
\4
This oppendix contoins o complete list of Note#, octuol note, ond the
volues to be POKEd into the Hl FREQ ond LOW FREQ registers of the
sound chip to produce the indicoted note.
\
4
\4
MUSICAT NOIE I OSCITTATOR FREQ --.2
t
_--2
c-0 \
\-/1,
0 268 12
I c#-a 284 28
2
3
D-0
D#-0
30r
3r8
45
62
-4'
f
4 E-0 337 8I \ ,
5 F-0 358 r02 *-l
\
6 F# -0 379 123
7 G-0 401
'I
45
*-*,
1
I G#-O 425 r69
a
4
9
r0
A-0
A#-0
451
477
r95
221 *A
ll B-0 506 250 .4
a
c-l
I6
17 c#-l
536
568
24
56 :A
r8 D-l 602 90
t9 D#-1 637 125
20 E-l 675 I63
2l F_I 716 204 ,
22 t#-l 758 246
23 G-I 803 35 i-r-
24
25
G#-1
A-l
85i
902 r34
83
t2
26 A#-1 955 187 ,.r'z
27 B-l r0t2 244 __-a
a
32 c-2 t072 48
"-l
a
r52 --'l
11
--tl
a
-_za
a :Fp,*
I
-i
c4
.a
\- MUSICAT NOTE OSCITTATOR FREQ
3 ir c#-2 I r36
3
4 112
D-2 1204 4 t80
:_
D#-2 127 5 4 251
tra
fl -2
38 | 517 5
I 'e: :.e-s of the 237
39 G-2 607 6
3
1
71
40 G#-2 1703 6 167
3 +l
Aa
A-2
A#-2
1804
t9tI
7 12
t9
3
r
qJ B-2 2025 7 233
c-3
28
12 3 48
49
50
c#-3
D-3
2t 45
2273
2408
8
I
9
97
225
104
51 D#-3 2551
-, 52 E-3 2703
9 247
62 t0 t43
81 -. 53 F-3 2864 ll 4B
'x2
<A
F#-3 3034 II
123
-,
{, 55 G-3 3215
218
12 143
145 56 G#-3 3406 t3 7B
57 A-3
i59
t95
-ta
{, 58 A#-3
3608
3823
t4
14
24
239
221
250
.4 59
64
B-3
c-4
4050
4291
I5
l6
210
r95
24 {, 65 c#-4 4547 17 r95
56 66 D-4 4817 18 209
90
{, 67 D#-4 5r03 t9 239
{, 68 E-4 5407 21 3t
F-4
204
t4 69
70 F# -4
5728
6069
22 96
l8r
246 e4 71 G-4 6430
23
25 30
35
v4 72
/3
G#-4
A*4
6812 26 t56
83
r34 v/' 74 A#-4
7217
7647
28
29
49
2ZJ
t87
4 75 B-4
c-5
8r0l 3t 165
fl
244 80 8583 22 r35
48 8l c#-5 9094 35 134
{)
fl
i-l
-
:3
G-fr
#
f,
MUSICAT NOIE OSCITTAIOR FREQ
HI tow
f
ff tt6
NOTE OCTAVE DECIMAT
tg
t't'
37 162
82 c-0 9634
83 c#-0 10207 39 223
r08r4 42 62
84 D-0
F-5 44 193 'rE
?
85 11457
86 F#-5 12139 47 t07
G-5 1 2860 50 60
;4
?
87
88 G#-5 13625 53 57 lrll
89 A-5 14435 56 99
90
9l
96
A#-5
B-5
c-6
1 5294
r 6203
17167
59
63
67
r90
75
l5
3
?
97
98
99
c#-6
D-6
D#-6
r8188
19269
2041 5
71
75
79
12
69
l9l
f,
f"t
100 E-6 21629 84 125
l0l F-6 22915 89 l3r
102 F#-6 24278 94 214
\!,
r03 G-6 25721 r00 121
4
r04
r05
G#-6
A-6
27251
28871
r06
112
I 15
199
h
r06 A#-6 30588 119 124
h
107
112
r 13
B-6
c-7
c#-7
32407
34334
36376
126
134
142
l5l
30
24
h
b
114 D-7
D#-7
38539
40830
r50
r59
r39
126
b
h
I 15
I 16 E-7 43258 r68 250
2)
117 F-7 45830 179 6
ll8 r#-7 48556 r89 172
ll9 G-7 51 443 200 243
?,,
w
r20 G#-7 s4502 212 230
121 A-7 57743 225 I43
122 A#-7 61176 238 248
253 46
123 B-7 6481 4 *
-rq
h
!L
z4
>,
a
-14
h
ILE
{-.-.?
f, FITIER SET'TINGS
a r{ Contents
3
-ln
High frequency (0-255)
3
3 Resononce (bits 4-7)
Filter voice 3 (bit 2)
3
3-4
a
--'l
a
a--_.
-4
rt
*4
a
14
<4
{"
.4
<4
t4
,y't
,y't
.4
-/)
a
tl
_/c
_r')
rl
-/?
t
.t)
rL
<
4
4
APPENDIX N 4
4
4
4
BXBTIOGRAPHY
-At
"4
Addison-Wesley "BASIC ond the Personql Computer", Dwyer
4
ond Critchfield
-2
4
"Compute's First Book of PET/CBM"
Compute
Cowboy Computing "Feed Me, l'm Your PET Computer", Corol Al-
4
exonder
l
C{
-r
f, ':1,.'c W. Soms "The Howord W. Soms Crosh Course in
\- crocomputers", Louis E. Frenzel, Jr.
3 ven M. Rogers
.3.:-c.rer",
3
3
"VlC 20 Progrommer's Reference Guide,,, A.
Finkel, P. Higginbottom, N. Horris, ond M.
Tomczyk
Dwyer
3
Corol Al_
Homes ond Schools" , Gory W. Orwig, Univer_
cr.3.! ;c
20,,,
r the PET",
3 Csborne/McGrow-Hill "PET/CBM Personol Compurer Guide,,, Corroll
S. Donohue
"PET Fun ond Gornes", R. Jeffries ond G.
-,
;-, Fishe r
-"3 Pr i Feidmon (, "PET ond the IEEE" A. Osborne ond C.
-"3
'' t/,OS Technol-
:4 Donohue
fl
fl--? 157
{!
f,
d
Prentice-Holl "The PET Personol Computer for Beginners",
#
# mt
Reston Publishing Co.
S. Dunn ond V. Morgon
"PET ond the IEEE 488 Bus (GPIB)", Eusene
Fisher ond C. W. Jensen
#
#
"PET BASIC-Troining Your PET Computer",
Romon Zomoro, Wm. F. Corrie, ond B.
#
# ftlrf rc
Allbrecht
"PET Gomes ond Recreotion", M. Ogelsby,
Lindsey, ond D. Kunkin
L. #
f,
"PET BAS|C", Richord Huskell
am
rl-
lFrw
l!_-
vices
r Eiitr
7, mSrr x
h
I
u
P
*
rr
fla
lllt
"!=
rllaE m
mur
{+
l,
, m lrrr
*
??
-={
a
<4
t-'+ APPENDIX
L4 O
I -o^o iE-
14
. r-c B.
i4 SPRITE REGISTER MAP
i4
I
i4
i4
.4
T, A.
7<
1
3
2 stxT
r<
? S]Y7
3ASIC
4 s2x7
,Z r, 5
'nfor- 14 o
:Jt ONS *4
t
7
r'"
8
z'--2
B
5 )0 per
"4
,;--2
D
"4
t4
Y4
v -'J
t -'J
,;4
i-'l
"-<
{4 159
{"
i=i)
L-{
L
t
L
t
Regisier #
L
4
Dec
21
Hex DB7
t5 SE7
D86 DB5 DB4 DB3 DB2 DB1 DBO
23 )7 SEXYT
MODE
\4
\-4
24 r8 VSI3 VS12 VSI I VSIO CBI 3 CBI 2 CBI I N.C-. SCREEN
Chqrocter
I nte ru pt \_
--2
26 ]A N.C. N.C. N.C. N.C MLPI MISSC MISBC MRIR( lnterupt
Req uest's
-a
\-
--a
l"
\--2
Request
MASKS
IC SCMO MULTICOLOR
\ 1T
2A SCMT
SPR ITE
SELECT sa
\
\**,
?9 ID SEXX/ SEXX( SPR ITE
30 IE SSC SSCO
EXPAND
Sprite-Sprite
X
*a
t
COLLISION
rt
3',| ]F SBCT SBCO Sprite-
Boc kg round
"*_q
!
COLLISION
-1,
A
,n
,-E
'-A
'*-A
L
\--a
t--a
r60
\--tA
. '/l
\ 5;rr*-
&:..:
,i$.i
t-{
rL -,
C-,I coroR coDES
3 O
DEC HEX cotoR
3
BLACK EXTERIOR COL
l I WHITE
3 2
fr
2 RED
3 3 CYAN
.3 4 4 PURPLE
3
3 26
5
6
5
6
GREEN
BLUE
27 7 7 YELLOW
,- i;
3 28 8
9
ORANGE
3
29 9 BROWN
2A t0 A LT RED
2B ll B GRAY
,- I
3 2C 12 C GRAY 2
3 2D
2E
t3
14
D
E
LT GREEN
LT BLUE
F
3
I t5 GRAY 3
-,
-:3:\ D:
generoie
a4
.4
Remember thot you must set the VOLUME before you con a
sound. POKE54296 followed by o number from 0 fo I5 sets the volume
"4
t
for oll 3 voices.
li tokes 2 seporote POKEs to generote eoch musicol note for ,-4
a
exomplePOKE54273,34:POKE542T2,T5designoteslowCinthesomple --a
a
scole below.
Also.youoren,tlimitedtothenumbersshowninthetobles.lf34 *;a
I
doesn'tsound"right"foralowC,try35'ToprovideohigherSUSTAIN
numbers
,*,
t
or ATTACK rote thon those shown, odd two or more SUSTAIN
together. (Exomples: POKE54277,96 combines two ottock rotes (32 ond .*,
Oi to, o combined higher ottock rote but '
provides o low ottock rote (16) ond o medium decoy rote
POKE54277
(4)'
'2O i.*s
1
,-q
*,
Al
N,A
)-*
Vrt
t-2
,4
,la
',-a
\
t
,/l
,.4
-<
--{
rL
{4
\.-I
#
.4
.< SETTING VOLUME-SO
IT
) coNTROr 3 J}3llllt]Iflillllll12ed s6ninss rone. from o (off) ro 15 (toudcsr)
3 'lAY A NOTE c c# E
'lrl -^#l.,].. Irl 'lan t
3
]. IREQUENCY
51273 31 36 (3
57)
l"l;k h;fi;
- - eed io use in your aal
, :
*;IEQUENCy 51272 75
-
.:--:c:re 64's 3 voices i2
3
TRIANGIE
: :: --^ followed by o .r^Y1l fYY NOISE
:*-
51275 | A volue of O ro ll5 (for pulse wov€form only)
, I
' -': '5 E
5427,a A voluc of O ro 255 (for pulte woveform only)
sets the volume
,4
L
: ( DECAY POKE ATK4 AIK3 ATK2 ATK I DEC DEC3 oEC2 DEC I
- --s:cl note for
l-e: :/, C in the somple
--,
a
51277 128 6/ 32 16 I 4 2 I
\,'-a
.: , .<-^ \ RELEASE PoKE sus4 sus3 sus2 sus I RET,{ REI.3 REL2 REI.I
i 51278 128 61 32 l6 I
-: s, - - rhe tobles. lf
-4
8 1
34
-: r ce . higher SUSTAIN I
I lorr ,
-_
-:'e SUSTAIN numbers * "rv 1 c#
I
F#l
D
!l:1
E
"3
,4 , _,:: t^-:
-_
E4 -_ l-.
51282
|
A volue of
of
O
O
ro i5 (for pulrc woveform only)
to 255 (for pul$ woveform only)
v-4 I SUiljE5
POKE suszlsusrlneu REr.3 REI.I
32 l,o l,
.4 54285 ) 128 161 lRE12
I 12 I
.--a
,3
I
-volue
{4 r63
--l
1
'.1)
-{
1
1
.,
4 \li,
TO PTAY A NOTE c c* D ol E f r# G G# A,# B c c#
4
HIGH FREQUENCY
IOW TREQUENCY
s1287 3t
51286 75
36
85
38
126 200 52
{0 43
198
15 {8
27 97
5l 51
ll 172
61
26
61
r88
18
19 t69
72
4'4
wAvEtolA POKE TRIANGI.E SAWIOOTH PU LSE NOISE
PUTSE RATE
51290 t7 33 65 129
-2
-4
,, tr"t
to PUtsE
ATTACVDECAY
I srzgc I
Lar88 I
POKE
A
Lolr.
ATK,t
"olre
ATK3
of o lo 15 (for Pulre wovoform only)
of o to 255 (for Pulre wovc{orm oniy)
-a
SUSTAIN/NEIEASE POKE
54292 r28 61 32 t6 8 A 2 1
-4
-),
*J)
-4
TRY THESE SETTINGS TO SIMU LATE DIFFERENT INSTRUMENTS
Prlr.
*4
llnsr*.nr
leiono
Wqveform
Pulse
u?:""
9
"l
IlHi-o
Rot.
Lo-2.5.5
*4
i Flute Trionge 96
I
| ruot opplicoble
Not opplicoble
*-,,
IHorp.i.hord
xvlophon"
Sqwtooth
Triongle l 9
I
lNot opplicoble *4
*4
I
lCJroon Triongle 0 ruot opplicoble
|
lcoliiop. Trio n g le 0 lNor opplicqble
IA.."rdion
lT,u.put
Triongle
Sowtooth
r02
96
Not opplicoble
I
Itl:lcrticoute
*A
I
J
t'
,!
IN DEX Commonds, BASIC, I I4- l I7
;1 Commodore key, (see grophics keys)
3 A
Acbreviotions, BASIC commonds. 130,
Conneciions
optionol,6-7
3 t3l
A:cessories, viii, 106-.l08
reor, 2-3
side ponel, 2
3
;-
Aidition, 23, 26-27,
A\D operotor, ll4
113
3
t?
A.;tnmeiic, Formulos, 23, 26-27, ll3,
'20, 140
A..oys,95-103
ASC function, 128, ,l35-l37
Cursor, l0
D
DATASSETTE recorder, (see cossette
f,
ccbreviotions, 130-l3I DATA stofement, 92-94, 1 18
:cmmonds, I 14-l l7 DEFine stotement, I l8
f
- rneric f unctions, '1,25-127 Deloy loop, 61, 65
ocerotors, I l3-1 14 DELete key. l5
:'ner functions, I 29 DlMension stotement, 118-l I9
s'o?ements,117-125 Division, 23, 26, 27, 113
{
-frrr!\TS ? s'. rg functions, 128
,c:iobles, I 12-l l3
Durotion, (see For . Next)
? i: ogrophy,156-158 E
?
reg Rote END stotement, I I9
3-s .ess oids, 108 Equol, not-equol-to, signs. 23, 26-27,
- - - -c-255
'.:':cplicoble
trcplicoble f );e
C
76 lt4
Equotions, I I4
":-
',:' :opllcoble
: cplicoble
:pplicoble
f l= :. otians, 22-29
::sie-e tope recorder (oudio), viii,
' ;_)i )1
3,
Error messoges, 22-23, t50-l5l
Exponsion pon, 111-112
EXPonent function, 126
Exponentiotion, 25-27, 113
:oplicoble --1,
') l:sse*e tope recorder (video),
l: ss,e-e. porl 3
7
F
'.:' :pp icoble
-*1,
,-) l-iS,unctioa, 36-37, 16-17, 53, Files. (DATASSETTE), 21, II0-lll
) t ::-50 il3, t28, 135-r37, I48
l -i r'c'emeni, I I7
Files, (disk), 21, ll0-lll
FOR stotement, l l9
) 4 ::,s.rent, II-l2
l-R5 :cdes, 58
Gome conlrols ond ports, 2-3, l4l
?
GET stotement, 17-18, I l9-t 20
te,i 5e 57 GET# stotement, 120
nop, 64, 139 Getting storted, l3-29
:ii(S crd POKES, 60-6I
a ''3(ic in your progrom
-a
4
_) !:-eE' cid border, 60-63. 138
GOSUB stotement. I20
GOTO (GO TO) stotement, 32-31, 120
J
4 J
I65
ar
fl
- ---!
I
I
t
't
t
2
3
3
Grophic keys, 17, 56-57, 61, 132-137 NOT operotor, 114
Grophic symbols, (see grophic keys) Numeric voriobles, 36-37
Greoter thon, I l4
t-2
o
H ON stotement, 122
Hyperbolic funciions, 140 OPEN stotemenl, 122
Operotors .4
t-4
I orithmetic, I l3
IEEE-488 lnterfoce, 2-3, t4l logicol, 114
a-4
IF THEN 37-39,120- relotionol, I l4
a-4
INPUT stotemenr, 45-47 P
'
INPUT#, I2I Porentheses,28
lNSert key, l5 function,60-62
lNTeger function, 126
PEEK
Peripherols, viii, 2-8, 107-'l09 --4'
I
lnteger vorioble, I l2 POKE stotement, 60-61
l/O pinouts, l4'l -143 Ports, l/O, 2-3, 141-143
a€
l/O ports, 2-7, 141-143
J
Joysticks, 2-3, 141
POS function, 129
PRf NT stotement, 23-29, 123-124
PRINT#, I24
Prog ro ms
3-1
t
editing, 15, 34
K line numbering , 32-33 _-L,a
a
Keyboord, l4-17
t
loodi ng/soving (DATASSETTE),
looding/soving (disk), I 8-2,I
Prompt, 45
I 8-2 I
a
)-2
LEFT$ funciion, 128
a AL ^),1
LENgih funciion, 128
.),a
Less thon, I l4
LET siotemenf,
LIST commqnd
LOAD commond, I
,
l2l
33-34,
toPe'
LOADing progroms on.l26
l5
r 8-20
Quototion morks, 22
R
,n
LOGorithm function, READ stotement, 124
REMqrk stoiemeni, 124
;i,a
,#
Loops,39-40, 43-45
Lower cose chorqcfers, l4-17 Reserued words. (see Commond siote-
ments)
'l
M Resiore key, 15, 8
Mothemof ics
formulos, 23-27 .l40
function toble,
RESTORE
Return
sfoiement, 124
key, 15,
RETURN stotement, 124
18 rF'
,+,
symbols, 24-27, 38, 114 RIGHT$ frinction, 128
Memory exPonsion, 2-4, 142 RUN commond, ll6
*+,
-l
21, 116
Soving progroms (D,ATASSETTE), 2l
;h
:p
Music, 79-90
N
Nomes
Soving progroms (disk), 21
Screen memory moPs, 62-63, I38
SGN, function, 127
iF-
,A
Shift key, 14-15, 17
progrom, 18-21
vorioble, 34-37
NEW commond, l'l 5
SlNe f unciion, 127
Sound effects, 89-90
'l29
l-Z
rL
NEXT stoiemenf , 121-122 5PC function, ---a
r66 .-a
rL
rL
,--.4
L
Lts*
/'l
I
;{
t
#
I
fJ
-t ::t -: :lliOR, vii, 69-76
!'; -E -::cphics, vii,69-76
USR function, I27
User defined funciion, (see DEF)
!G-cQe.rnction, 127
S-3: :c-nond, 125 V
S-3t <ey, I6-I7 VALue function, I28
- S'- -g ,oriobles, 36-37, I l2-l l3
Voriobles
3 S-i5 :rnction, I 28
orroy, 95-103, Il3
- S-:sc.ipted voriobles, 95-98, I I2-l l3 dimensions, 98-'l03, I I3
f, S.:'roction,24,113
S,^'ax error,
SYS
22
stotemeni, 125
flooting point, 95-.l03, Il3
integer, 95-.l03,
numeric, 95-103,
ll2
ll2
string (g), 95-103, lt2
3
T
:AB f unction, .]29 VERIFY commond, I l7
- --A\ :unction, 127 Voice, 80-90, 162-164
3 Ti rorioble, ll3
iiS vorioble, Il3 W
I - a-
3
3
r'-e clock, I l3
-/:cnnections,3-7
U
WAIT commqnd, 125
Writing to tope, ) 10
to al 3
-4
I
*=-,
a
-a
t
.-a
a
*-=a
a
:-: l:--:rC siote- 4,4
4
I
.4
.4
;4
: : t\\- !Fl /l
aP'
^_ al 110
t4
<4
--l
I
--a
L
*-?
t
167
-/A
,/a
L
L h*"
j{
\_
L
t
l-4
\
4
\
1
4
t
4 t.
-4
\
4
\-4
\4
\ -2
\--?
\
"-2
Commodore hopes you've enioyed the COMMODORE
64
some pro- --4rt
USER'S GUIDE. Although this monuol contoins
I
a-'2
:4
-/a
ln oddition updotes ond corrections os well os
progromming hinis ond tips ore ovoiloble in
mogozines' on the COtu\MODORE dotobose of the --a
the COMMODORE ond POWER
COMPUSERVE INFORMATION NETWORK'
PIAY
occessed through o ViCMODEM' :-Z
\-
_4
4
\- r;F*
c{I
t* aCil*r*iOOORE 6rt eUtCK REFERENCE CARD
3
Rerurn3 curenr cursor position
_-i ra\.:
Posirions cursor ro tefi coher of
3
po5ilion
\S' l€. De erer chorocter or curre.r cu.sor
Potiion
3
,-
::li
:RSR (eys
When used wirh
PRtNI srdrem.ni
.lm€ric color key,
setecr texr cotor. Moy be used in
3
ac-Tcoo,e Key when used wnh SHTFT selecG
beMeen uppe./tower cose ond
srophic disptoy mode.
3
Whe. u5ed whh nume.ic cotor key
selecrs optionol text color
! :il.r :ffE
3
ARUYS ANO sTRINGS
0lM aix.Y.z) seB moxim!m subscriprs for A;
,e3erues 3poce for (x+ t)'(y+ l).lZ+ t)
3 LEN lxtl
elemenrs nod ns or A(o,O,O)
Returns number of chorocieB in X$
3
STR!(X) Rerurns n!meric voiu€ of X,
conveded to o string
vAkxS) Rerurns numeric volle of Ag,. up io
Ulk d irt^:tru_aas
3
f 6r nonnumeric choroder
cHR$(X) Reruhs ASCII chorocter whose code
:3 n: 64
3
ASC(xt) Returnr ASCII code for ff6t
INPUT
At OR
"ABC";A
A pRtNTs ,?, on s.,een ond woib for
user to enler o il.inq or votue
pRtNTs messoge qnd woit for
user
ro enter volue. Con otso tNpUT At
--a
\_ OATA A,"B",C
.horocr€r votu€,.o RETURN needed
tnitiotizes o ser of votues rhbt
con be used by REAO sroiement
--2
r_ 46 or A
REAO
RTSTORE
Assigns nexr DATA votue ro A$ or A
Resets doro poinier ro sron
---,
r_ { pRrNT ,,A= ,,,A
READ,ng rhe DATA
pRtNTs $ring ,A_
til ogo,n
, ond votue o{ A
,-|'
t_
:r---.- :,:g-:- .recJio^ f,om
.* --*ir :':s.:- *oi horred
; suPpresses spocee
ro next ffeld
_','robs doio
moctall Ftow
4
| . :r:r,a ::-,."3:: xoron x lF A=3 THEN lO
':r: tF ossedion is rue THEN execue
fottowing poa of ,roremenr. tF
; : ,:- . -o.nine dnguoge folse, exe.ure nexr tine nlmber
*4
t_
:r:E--_- r:--!.'rg
,-4 ,'ir
!s:+_-,
*..r-€::x.:.-o.hi.e
.-i,if+ i...:,--.
!l.-:e,o
NEXT
GOSUB
A
2m0
is ) unte.s 3pecified
Deffnes end of loop. A is opiionot
Bronche3 ,o subrourane iloding or
ffi tine 20m
d ffircaruOs
* -:i
":i!+
,i
-m-F
r-r. :-:9-.-
r.A.. -.8
RETURN Mo.ks e6d oI slbrourine. Reiuhs io
sotemeni following mosr recent
GOSUB
* b 6ry ]fff,
i rr+e
-..5r
:--..;
.c- * i.rd
y€,o-.rxdior
bur ON X GOTO A,B
Bronches ro Xih tine number o.
lisr. tf X = I bronches ro A. erc.
-4
r_
N I -c r 4 \- r.*,Y! Src.i X ON X GOSUB A,B Bronch.3 io sub.ourin. or Xih tine
number in tisr
-4
r*
3
3
/?
\-
_/a
L r-"-
sir
c#
#
#
#
#
Z
o 1=>
r :a
A = ;3
, < :G
E =r
=-<
^i
n
F
F
9 :iFI3ai:9
f:f-!-!!
elr=;;+
6!F==:;
=F
Tn
oi oo
oo
: EEsBlPE
#
#
l.=.
-
sJ:3
=
1a=
* E-
=
I
r
i
e
=;
g;
j d
ti5:is-.1
Elgig:=:
ig
=
Bio
x il o 6o
Q-=
# ===
=1=
'a
?
I
!rj-6;ic>
;?i?5ir I
o_9
-o
4 {
T. F
6
!:-ll.-f
i?&T:;i I
i= O- Cc
O^
f, V
e- ::3: {is
=.!c=^'=- a
3x
# -,, -!
E-<xSi=
- 16=X 6
b
J
I
D9
oac
f, f ^'' J
=
- = L
^ - =a
l) O)-
a;.ih -' - O.
N ?a l= = =.
# a
7 i f o
o - f 6-3
=.P
3ialei\f _s; =
r ir
rf
=
oX
oa
#
O C o Ot
a '!= = j-EE
u +l J ! - 3
, -'Uf- :-
o
4 a o-?-c>
-o
=;iin
o ^I *a)
:-< o-
4 o
f,
(,)
nI
E=;.iel I g q :ri1+3E
x
4
= E.
3
:
=
E
o
J
o
c XIo
rg+
i !
3
4
4
=g=
iE
T\ J=
e
B
3 o
o 3
e[ i i: i iaiilc+ r o
:
;i E +iiEiii
zi? 'a
4 rca
lrEd ? E
4
0')
4
i!-c
^=,
x{
D
o
ii *El I tsiii+i €;
sg= 2 la::;13
a
o
(t)
o
4 =-?
d
=i isa e s:E!:li
a
&
>=P
-=
x-=-
a
a
ii q-
5 ;;lgiii
=i -=.--d
E=.
o
=r.
)
a
*
{a
J
;
--i
'l
zl
1
? ;
e
-
P:3:=i:
*i^i=t6
ii:EriE
o
f,
f,
a
S
rL
r,
tL
tL
t"
!- cornrnodore
f=
COMPUTERS
Business Machines. lnc -Comouter.Systems Division'
"" ' ""'
Commodore"rzoo
wiison orive wesl Chester. PA 193q0 ^
2K4 Canada
3:zO PharmZJy'Avenue, Agincourt, Ontario, M1W
$1 2.95/2201 0
Printed in u.s.A