C64 User Manual 1984 2nd Edition

Embed Size (px)

Citation preview

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    1/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    2/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    3/199

    Copyright by Commodoe Business Macnes, (U Ltd.A ghts eserved

    This maal is copyrighted and cotans proprietary iformato. No part o his publica-

    tio may be eproduced stoed i a rerieval syste or transmted n ay o o by ay

    means eectonc echancal photocopyg ecordg o ohewse wtho he pror

    wte pemssion of COMMODORE USIESS MACHNES (U td

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    4/199

    TABLE OF CONENS

    CHPER 1

    SETTING UPUnpackng and Cnnectng the 6nstalatn . . .

    3

    Optnal Cnnectns . . 5Opeatn 7Truleshtng Cha 8Clr Adjuste Expandn u ystem With pna Perpheras . . 2

    CHPE 2

    GETTNG SARTED

    Cmmurc wth yu 64 he KeybadLadng Prras w t Frat a New Dsk Savng Prrams Lstng a Dtry Pas a Dsk

    CHPER 3

    BEIIG BSIC

    6 . 2

    . . 2 3 2

    . 2

    Prntng and Cacuatng 2 6Mathematca Functns . . 2 7Multpe Cacuatns n One Lne . 2 9Exutn Ode n Caculatns . 3 0Cnng PRNT's Capaltes . 3

    CER 4

    WITIG SIMPLE PROGRS I SC

    ne Numers 3The GOTO Statement 3 6Usng the ST Cmmand Edtng Tps 37w t Use Varaes 3 8Usng FOR NEXT Lps Usng FTEN Stateents t Cntr Prgras 2

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    5/199

    HER 5

    VCE BIC

    uc 46Smpe Ama 47NPUT 49Usg he GET Saeme fr Daa pu . 5

    5 2 5 3

    Usg GET Pgam Fuc Keys Ram Numers a Oher Fucs Guessg Game 55Yu R ll . 5 6R am Gaphcs 5 7

    HER 6

    CL GPHIC

    w Use Cl a Gaphcs Yur Cmpue 60Pg Cs 61C CR Ces w Use PEEKS a POKES . . 65Scree Graphcs ee Memy Map Cl Memy Map Me ucg als

    HER 7

    ITUCTI TO PITE

    66 67

    68 . . . 69

    s a yes . 73Creaga Spe 76Desgg a Spre 77

    umg Spres O 8Spre Clrs 8Psg Spes 82Expae Spes 83Creag Me ha Oe Spre 84pe Pes 85Turg Spres Of . 85

    HER 8MG U U

    The SD Chp . 8Sampe Su Pgram 6Playg a Sg Yur . 98Ceag Su Eecs . . . 99Flerg . 00Musc Cmpser 0

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    6/199

    CHER 9

    VCE T HG

    READ and DATA Statements 4Calcuating Averages 6

    Sbsciped Vaiables 8Dmensoning Arays 9Smaed Dice Rol wih Arrays Two-dimensiona Arays

    EDICES

    A Expanding You Commodore Comer SysemB Descipion of DOS Erro Messages

    7 4

    C Commodore BASIC 8DEFGIJK

    Abbeviaions o BASIC Keywords . 4Screen Dispay Codes 43ACI & CH$ CodesSceen and Colo Memoy Mas

    46 49

    Deivng Mathemaical FunctonsPnouts for NPU/OTPT Devces

    5 . 5

    Pogams to T 5 4Conveing Sandad BASIC Progams o ommodoe ASI 5 8

    L Eo Messages ....1 5 9 M Music Note Values . 6N Bibiogaphy . . . . . . . . . . . . . . . . 64o Spte Register Map 66P 6566/656 (VIC ) Chp Regster Map 69Q Commoe Sound Cono Setngs . . . 7R 658 Sond Ineace Devce (SID) hip Speciiaions 73S Dsk and Pnte Commands and Saemens 75

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    7/199

    THE INFORMATON IN TS MANUAL AS BEEN REVIEWED AND S BEIEVEDTO BE ENTRELY REIABE. NO RESPONSIBTY, OWEVER, IS ASSUMEDFOR NACCURACES THE ATERIA N THS MANUA IS FOR NFORMATIONPURPOSES ONLY AND IS SUBJECT TO CHANGE WITOUT NOTCE.

    THS MANUAL S COPYRGTED AND CONTANS PROPRETARY NFORMATION. NO PART OF TIS PUBCATION MAY BE REPRODUCED STORED IN ARETRIEVA SYSTEM, OR TRANSTTED IN ANY FORM OR BY ANY MEANSELECTRONC MECHANCAL PHOTOCOPYING RECORDING OR OTERWSE, WTHOUT THE PROR WRITTEN PERMISSION OF COMMODOREBUSNESS MACNES INC

    Copyright 98 by Commodore Business Machnes (UK) Ltd.All righs reserved

    vi

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    8/199

    INTRODUCTION

    o ew COMMOOR 64 s te best ome compe aalabe today oca se yo COMMOOR 64 o eeytg om bsess appcatos tooseod papewok to exctg games e 64 ofes yo lots o memoy (64K),ots o coo (16 dfeet coos ots o sod msc ad sod eects adots o ad pactca ses o ca se pepackaged sotwae o yo cawte yo ow pogams easytoea BAC

    s easytoead ses gde cotas al te omato yo eed to set pyo epmet popey destad ow to opeate yo ew COMMOOR 64ad ea ow to ceate yo ow smpe BAC pogams

    s ses gde s teded to todce yo to comptes bt t s beyodte scope o ts maal to tell yo eeytg yo eed to kow abot compteso abot BAC Howee ts gde does ee yo to a aety o pblcatostat expla te topcs we peset ee moe deta

    o tose o yo wo dot wat to ea ow to pogam yo wot ae to

    seac tog te woe book to ea ow to se Commodoe pepackagedpogams ad games o ote pepackaged td paty sotwae ee pt alte omato yo eed to kow gt p ot Captes 1 ad 2

    May exctg eates ae watg o yo sde yo COMMOOR 64. oew compte ges yo te mcocompte dstys most adaced gapcswc we ca R GRAHC pte gapcs et yo

    esg yo ow pctes deet colos st lke te oes yo see oacadetype deo games Amate as may as 8 deet pcte leels at a tme Moe yo ceatos aywee o te scee obe te se ass mages ot o bed eac ote se atomatc coso detecto tat tels te compte to do watee yo

    wat we sptes t eac ote

    ese eates let yo desg yo ow games

    e COMMOOR 64 aso as bt msc ad sod efects tat amay wel kow msc syteses s pat o yo compte ges yo

    3 depedet oces eac wt a ll 9 octae paotype age 4 deet waeoms sawtoot tagle aabe plse ad ose A pogammabe AR attack decay ssta ad eease eeope geeato A pogammabe g ow ad badpass lte tat yo ca se o eac oce Vaabe esoace ad ome cotols

    yo wat yo msc to pay back wt poessoa sod epodcto te

    COMMOOR 64 lets yo coect yo ado otpt to amost ay g-atyampcato system

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    9/199

    As you computng needs gow so can you system ou can expand yousysem by connecing you COMMODORE 64 o oher pieces of equipennown as pepheas hese accessories nclude tems ke hese:

    he DAASSEE' recoder o apes he C 51 ds dve (as many as fve at a te)

    The COMMODORE do maix pines, fo had copes of yo pogamsees ec

    he MODEM cadge fo access hogh yo elephone o he massvedaa bases of age compes as we as he sevices of hndeds ofspeciass and a vaey of nfomaon newoks

    The Commodoe 701 coo onio

    you aleady have a C 150 disk dive you deae can upgade t fo use ihe COMMODORE 64.

    Comodoe wants you to realy enjoy you new MDORE 64 An oh fun bea n mind hat prograing aes o lan Be patien wyourself as you go though he SERS GDE But beore you star pleastake a ew mnues to f ou and ma n the owne/regstraton cad that caewth your copute his ll ensue ha you COMMODORE 64 is poperyegseed wth Commodor eadquarers and hat you receive he os up-oae nforaon regarding fu enhancens for your achne

    NOTE: any progras ae und developen whie this anual is bengproduce Pease check h you ocal Coodoe deaer and ihComode ss Magaznes and Cubs whch l keep you up to dae on heweath o appicaons progas beng tten for he COMMODORE 64, worldwide .

    DATASSEE IS a regseed rad ar o Coodor Busness Machnes nc.

    viii

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    10/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    11/199

    CHAPTER 1S TT

    Unpcking nd onnecting the

    Instlltion Optionl onnections Opertion oubleshooting h oor djustment xpnding You System Wi io Peie

    CKI CCTI TH 64

    e olowig e-y-e ucio ow you ow o coec e 64 oyou eleviio e oud ye o oo d e ue eveyg wokg oely

    Beoe cig yg o e coue cec e coe o e 64coe Beide u you oud d e oowig e:

    oodoe 64

    Powe uy (gey ox w led d uly cod

    3 deo cle

    y ie e iig cec ck w you dele ediely o elceme

    F e oo e gee o e vou coecio o ecomue d w ec oe doe

    IE NEL CONNECIO

    1. ower ocet e ee ed o e ce o e owe uy ceee o uly owe o e 64

    ower wtch u o owe o e 64

    3 Gae ort c ge coeco c cce oyc o ge cooleddle wile e lige c oly e lugged o e ge o coe oe o o you coue

    E CONNECIO4. Cartrdge ot e ecgu o o e e cce og o ge

    cartridges.

    5 Channel eecor Ue wc o eec wc TV ce ecoue icue w e dilyed o

    V Connector. coeco ue o e cue d oud o youeleviio e

    2

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    12/199

    7 udo & Vdeo Outut. his connector suppled direct audo, whch ca beconnected to a hgh quaity soud system, ad a composte video signalwhch ca be fed ito a teevison or a moitor such as the Commodoe70 coor montor.

    8 Sea t a aah a C M ME e a V C 54 se

    ds dve dely he Cmmde 64 hh hs e Caette nteface. A DATASETIE '" recorder ca be attached to the

    computer so you can save inormatio on tape for use at a late time

    10 e t Vas efae ades a be aahed he se sh as he MEM 232 mma ade

    G H K

    G H

    I S TLL TI

    CONNECON O YO V

    Conect the computer to your TV as show o page 4

    Attach one ed of the TV cabe to the phoo tye V sgnal jack o e ear of

    the 64 Just push it i Either ed of the cable ca be used Conect the other ed of the cable to the atena switchbox ust ush

    3

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    13/199

    3 Pg te poe sppy cae nto te poe socet on te sde o teCoodoe 64 Jst psh t n t s eyed to allo nseton n only onedecton so y cant connect the poe cod te ong ay he poesppy conets osehold cent nto te o the copte ses

    e 64 s no coecty connected. No addtonal connectons ae eed to

    se the copte t yo V.

    4

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    14/199

    1701

    Commodor 64pm](White)Vdeo OutLumnance nput Yeow

    Montor Cable

    OPTIONAL CONNECTIONS

    L

    Audio Input (Whe)

    A In

    -... 0

    Red

    Sga See

    F OI

    Sice te 64 ue a cae o det oud ou a wi to pa ittrou a qualit apiier to realze te bet oud poible. addito te 64alo provide a tadard copoite vdeo ia tat ca be ed ito a teeviootor

    ee optio are ade poible b te audo/video output ac o te eapael o te 64 e eaiet wa to a acce to tee ial b u atadard 5-Pi DN audio cable (ot upped. Ti cabe coect diect to

    te audiovdeo coecto o te coputer wo o te ou pi o te oppoiteed o te cable cotai te audio ad vdeo ia ou ca ao cotuct ourow cable u te piout ow i Appedi a a uide

    5

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    15/199

    may e BLACK connect o th DIN cb ppi t UDIO iis g may be cnnectd to the UXIAR inpt o pi tA cnnct a monto o oth vido t ch vido cttecde VCR)

    he WH R connecto a ppi t dict IDO i g is conneced to t DO I conecto o th onit o vd ipt ctio ome ote vde sytem ch a a CR

    ending n te manacte o o DIN cb t co cd ts ay be diffent h pinot hown i Appdix I t tc p tope p i y dont et an dio o vido n t tdconnectin

    UO

    :._ -

    X O .

    .TO N*- '-:. ;=

    TV ONT

    pcd pp pt ch I 54 dk d MPS

    8,82 83 pt 52 pott o oto, o m wsh to coct tt t t t t sppd wth ddto pt t pp pocd o coct t to th copt.

    6

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    16/199

    A copeed e oo e

    OERATIO

    o e copue e oce c o e -de pae e

    oure looi a e cope o e o

    2 Ae a e oe e oo e dpaed o e TV cee:

    7

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    17/199

    3 yo V a a maua ie tu kob adjut te TV ut ou et a ceacte

    Yo may ao at to adut te coo ad tt coto o te TV o te betday Yo ca e te coo adtmet ocedue decbed ate to eteeyg et oey. We you it et a ictue te cee oud

    aea moty dak t a lght bue bode ad ette yo dot get te eected et ececk te cabe ad coectio Te

    accomayg ca e yo ioate a obem

    TBEHTNG CHAT

    ymptm Cae eed

    dcato Ligt omute ot Make ue oweot " " witc i O

    oitio

    oe cabe eck owe ocketot ued o ooe o d- coected owe

    cabe

    oe y eck coectoot ged wit wa outet

    Bad e Take tem tocomte autoized deae

    o eacemet oe

    No ctue TV o o eck otecae cae o

    ictue 3 o 4)

    coect omute ook u toooku VHF atea temia

    Vdeo cabe eck TV oututot ued cabe coectoi

    omute et et comute oo wo ame cae a TV

    cae (3 4

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    18/199

    yp aus

    Rdom p d o Ro T wih pop d

    ctid d o powp

    Pic wio oo d coo T

    Pic wih d oo d oo/poo oo djm /

    oT oo o

    Sod wi vo p dj vo oxc ih Tckodoi

    Pic O vo oo d vo o o od ow

    x op o odo pop jk o x pod o p d

    x p

    I: Th 64 w did o d vo

    w omodo oiz h op oo

    io diici To p w o o d v o o pommi id ommodo d v po o po o h o d ood id o o oodo U o hp o m om o 6 ow wo p o kowd d xpi

    9

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    19/199

    CURSOR

    he flash square uder EAD s called the cursr t's a marker thatshs here hat yu tye the keybard ll be dslayed the scree Asyu tye the cursr mves ahead e sace as the ral cursr st srelaced th the character yu tyed. ry ty the keybard ad atch

    the cursr mve hle characers yu tye are dslayed the scree

    COO ADJUSTMENT

    here s a smle ay t et a atter f clrs the mtr s yu caeasly adust the set Eve thuh yu may t be famlar th the erat fthe cmuter rht ust fll al ad yu'll see h easy t s t useyur cmuter

    Frst lk the left sde f the keybard ad lcate the key marked

    . hs stads fr C ad s used cuct th therkeys t struct the cmuter t d a secfc task use a ctrl fuct yu hld d the key hle ress a

    secd keyry ths hld the key hle als ress the a key he

    release bth keys Nth bvus shuld have haeed but f yu tuch aykey the scree ll sh the character dslayed reverse tye rathertha rmal tye lke the e messae f ayth yu tyed earler

    Hld d the '; What haes? f yu dd the abve rcedure crrectly yu shuld see a ht blue bar mve acrss the scree ad the mved t the et le as l as the 4 s ressed

    READY

    -

    10

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    20/199

    Now hold whl pssng an of th oth nmb ks Eah ofthm has a olo makd on th font Anthng dspad fom ths pnt wl bn that olo Fo amp, hold ad th k and las bothNow hold th.i .

    Wath th dspla Th ba s now n ow! In a lk mann o an hang

    th ba to an of th oth oos ndatd on th nmb ks b holdng and th appopat kChang th ba to a fw mo dffnt olos and thn adst th oo and

    tnt ontols on o monto so th dspla maths th oo o sltdTh dspa shod appa somthng lk ths

    At ths pont vthng s pop adstd and wokng ot Thfollowng hapts w ntod o to th BAIC angag Howv, o anmmdatl stat sng som of th man pwttn applatons and gamsavaabl wthot nowng anthng abot ompt pogammng

    Eah of ths pakags ontans dtad nfomaton abot how to s thpogam It s sggstd, thogh, that o ad thogh th fst fw hapts ofths mana to bom mo fama wth th opaton of o nw sstm

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    21/199

    XPG YOR S YS TM WITH OPTOA PRIPHRAL S

    mmdre ers a variey periphera devices ha expand hecpiiies f yur cmpuer hese peripheras incude

    srage devices

    riners and ers mnirs mdems r eecmmunicains game aachmens seec and graphics mdues desp cnrers

    TOAGE DEVICE

    Disk Drves

    mmdre's dis drives e yu se arge amuns nrmain n 5ppy disees Disees er as srage and rerieva and heyumaicay eep rac a yur ies in a direcy abe cnens hayu can dispay n yur screen r prin n a priner

    In addiin yu can add exra ds drives by daisychaining he rcmpuer. Daisychaining means cnnecing ne drve he cpuer anden cnnecing addiina drives each her.

    By acquiring he Cmmre 64 I Inerace xpansin Card yu can asaach any dis drive such as Cmmdres CBM 8050 4040 Dua Fpy Dis Drives he 64

    Chaper 2 cnains deaied inrmain n using ds dives

    PINTING AND PLOTTING DEVICES

    Prnters

    Yu c ach mmdre prers e 64. hese are epese dmar prers By cqurg he mmdre 64 EEE erace EpansCard yu cn as aac y EEE rer such as mmdres 6400 eerquaiy priner r he high speed 8023 d mri rer e 64

    Prnte/Plotter

    mmdre's 1520 PrinerPer prns and draws graphics in u csac ue red and green). ih he 1520 yu can daw ba chas pies and avariey cmpex graphics.

    THE 17117 MONITO

    mmdres 14 cr mnir ers a superi c picue wih highresuin ha enhances yur cmpung experienc his mnir can be cnneced he 64 he mnir is cnneced he cmpuer by an 8pin DINcae. he 17011702 Cr Mn Users Guide ha cmes wh he mni

    ceary expains cnnecins. Yu can as cnsu Appendx I inmainau he pinus in he 8-pn cnnec

    12

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    22/199

    AACHMENS FO AMES AND OE USES

    Cmmde e jc ad padde ha ehace aepa cmue hee aachme a have he appca A avaabe heCmmde hpe whch wh apppae wae aw cmuca

    wh he cmue he cee

    COMMODOE AC ADS

    Cmmde vde a vae aphc pa ad cdSMNS ASC whch add 114 pwe ew cad AC cdpamm hep ad aphc cad; ad OGO a eaeaa aae wh U aphc

    13

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    23/199

    MUSC CHMENS

    Cmmd as sn ff a Musca Kybad and a 3pad pcussnaachmn cad h gdum Bh pducs ncud sca sfapacags hs aachmns ncas h musc mang capabs fh 6 cmpus

    CONNECNG O SEREO SYSEM

    h sund and muscmang capabs f h COMMOOR 64 can bnhancd by cnncng yu cmpu a hgh quay amp and sspas. h 8pn IN cab dscussd n h 17011702 C Mnscn can as b usd cnnc yu cmpu an amp

    ESGNNG COMUER SYSEM FOR YOUR NEES

    Cmmd ffs a vay f pphas ha yu ca yu ncusmd cmpu sysm ff dn yps f sag, pnng, andcmmuncans dvcs s yu can chs has bs f yu F mnfman abu Cmmd pphas ad h Cmmd phasGud and h Cmmd magans dscussd n Appndx and cnsuyu Cmmd da

    1

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    24/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    25/199

    CHAPTER 2

    Communcatng wth you64: he Keyboa

    oang Pogams

    How to Fomat a New Dsk

    Sang Progams

    stng a Decto o pogams on a Dsk

    64: B

    he compute keyboa lets you communcate wth you 64. You use thekeys to tell the ompute what you want t to o an to answe the questonsthe compute splays on the sceen.

    he keyboa looks lke a egula typewte but the compute has specalkeys that let the 64 o moe than a typewte. Whe you ea the next ewpages take a look at these specal keys.

    RTUR he RURN key tes the compute to look at

    H

    what you type an put ths nomaton nmemoy he RURN key also moes the cusoto the next ne.

    NO Memoy s all the nomaton the com

    pute cuenty knows wthout neeng you to telt whee to look

    he SHIF key woks lke the sht key on aegula typewte t lets you pnt captal etteso the top chaactes on oube chaacte keys.

    m-\ L-'16

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    26/199

    When you are using the gaphcs on the font othe keys, the SHIFT key dsplays the gapcchaacte on the RGHT sde of te ke

    When you ae usng the ou specal uncton

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    27/199

    Y THAT LT YOU MA CHAG

    CRR

    TL

    he cuso s the lttle cooed ectagle thatmaks you place o the scee hee ae twoCuRSoR keys:

    CRSR

    moves the cuso up ad dow+CRSR moves the cuso et ad ght

    You must use the SHF key wth thet CRSR key to move the cuso up ad wth

    the + CRSR key to move the cuso to the letYou do't have to keep tappg a CRSR key to

    get t to move moe tha oe space Just hold tdow utl the cuso s whee you wat t

    DEL stads o DEete Whe you pess theDE key the cuso oves back a space adeases the chaacte thats thee

    PRN "ERROR#PRN "ERROR

    Whe you DEete the mdde o a e movethe cuso just to the let o the chaacte youwat to DELete

    FIX I AGANS SAMFIX I AGANS SA

    he pess the DE key he chaactes to theght automatcally ove ove to cose up thespace

    FX I AGAN, SAM

    NS stads o NSe You have to use theSHF key wth the NS/DE key whe you watto set chaactes a e

    I youve let some chaactes out o a le usethe CRS keys to move the cuso back to the eo

    WHE U WERE OUWHE WEE OU

    he whe you hold dow the SHF key,pess the NS/DE key utl you have eoughspace to add the mssg chaactes NSdoest move the cuso; t adds space betweethe cuso ad the chaacte to ts ght

    WHE U WERE OUWHE YOU WERE OU

    8

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    28/199

    CLRlHOM

    ROR

    Use the E and NS kes togethe to xwong haates

    WERE NUMBER O!WERE NUMBERWERE NUMBER

    WERE NUMBER ONE

    HOME moves the uso bak to the uppe letone o the seen hs s alled the HOMEposton

    CR stands o CeaR When ou use teSHIF ke wth the CRHOME ke the seen

    CeaRs and the uso etuns to the homeposton

    he REORE ke etuns the ompute to tsnomal state b RESOREng the deault ondtons eg the deault seen olo s blue, tedeault o /0 hps s OFF et) RESORE doessuh thngs as lea the seen etunng t to theognal olo and tun o the ptue- and soundmakng hps

    NOE Fo RESORE to wok ou must holddown the SOP ke whle ou pess theRESORE ke

    Fo example suppose ouve just paed amus pogam that also tuned ou seen edand ellow whle t Sed the pogam When oupess SOP and RESORE at the end o the pogam the ast note om the pogam wl ease,

    ou seen wll tun bue and the onl thngdspaed wl be the REAY pompt

    9

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    29/199

    FCTO Y

    he kes on the ght se o the keoa ae ncton kes that ocan oga to eo a vaet o tasks he exanaton o the GE stateent n Chate5 tes o how to oga ncton kes n BSC

    CTR

    RU/TOP

    COMMOOR Y

    he ConRo ke ets o set coos an oothe seca tasks cae conto nctos

    o set coos ho own the CR ke wheo ess the ke wth the coo o want Yocan get eght oe coos wth the keChate 6 aso has oe abot coos

    o get a conto ncton ho the CR ke

    own whe o ess the othe ke Conto nctons ae coon se n eackage sotwae sch as a wo ocessng sste

    Yo can hat a BASC oga whe t s stRUNnng b essng the SOP ke Yo can asose the SOP ke to hat a ntot whe t s stntng

    RUN ets o oa a oga atoatcao cassette

    When o want to se the RUN ke 9 staso se the SHF ke

    he Coooe ke can o two thngs ets o swtch back an oth between

    the e an owe case sa oe (the ettes an chaactes on the tos o the kes)an the e case/gahc sa oe (cata ettes an the gahcs on the onts o the

    kes)o swtch oes ess the an SHF

    kes at the sae teWhen o st tn on o64, t s n the

    e case/gahc oe whch eans thatevethng o te n s n cata ettesWhen o ae n ths oe, o can aso nta the gahcs on the onts o the kes o nt the gahc on the ght se o a

    ke ho own the SHF ke whe oess the ke wth the gahc o want tont Yo can on nt the ght segahcs when o ae n the ecase/gahc oe

    o nt the gahc on the et se o a keho own the ke whe o ess thegahc ke Yo can nt the et segahc n ethe oe

    0

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    30/199

    2 Theey aso lets you use the seond set ofeight aternate oors not shown on the oloreys To get these other oors hod down the

    ey whie you press the number for theolor you want ORANGE 2 BROWNJ 3 LT. RE 4 GREY

    5 GREY2 6 T GREEN 7 LT. BLUE 8 GREY3

    The COMMOORE 64 aepts programs from dis artridge or assettetapes This means you an use prewriten software simply by loadin it But moeimporant the64 ets you save your own programs for reuse. To reuse a proramyou wrote and saved on ds or tape al you do s load and run it

    When you use tapes or dss with your COMMOORE 64 be sue tat ourdis drive or assette unit s orretly onneted

    Loading Cardges

    You an use a speial line of prorams and ames n arde it our 64The programs inlude a wide ariet of busness and pesonal applatins egames are just lie rea aade ames not imitations

    Folow these steps to oad ames and te ades

    . Tun OFF your COMMOORE 64YOU MUST TURN OFF YOUR COMMOORE 64 BEFORE YOU INSERTOR REMOVE CARTRIGES IF YOU ON'T YOU MY MGE TECARTRIGE AN THE COMPUTER

    2 Insert the atide label uppemst n te sot n te ba o ou mpute.3. Turn on you 644 Bein the ame b typin te STRT e tats listed n te ames instru

    tion sheet

    21

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    31/199

    ag Prepackage Cassette Tes

    ou ca aso buy pepackaged sofware on cassette tape hese cassetesae us ke e ones w rcorded musc that you can pay on a stereo.

    nse e cassete nto your 530 DAASSEE recorder. ake sue te ape s competey rewound to the begnnng of the frst sde

    ype OAD o your keyboad he computer answers by dspayg PRESSA O AE.

    4. Pess PLAY on you DATASSETE he screen goes blank unil thecomputerfnds eprogram Then the sceen displays he message FOUND(PROGRAAE)

    5. Press e key Tis actuay loads the programintothe computer If youwat o sop e oadg pess the RUN/STO ey

    ag Yur O Prrams Frm Cssette Te

    e COODOE ets you wte and sae programs o ay brad ofcassete ape A you eed s a 530 DAASSEE recorder ad e same dof bank ape youd use o ecod musc for a stereo ape payer.

    oow ese smpe seps to oad a program you wroe ad saed o ape

    . Rewd he ape o e begng2 ype OAD OGA AE f you do't remember the program ame

    just type LOAD hs oads the frst program on the tape nto memo3 Press RE he compue responds wth

    RESS PAY ON APE

    ress e E e scee goes bak whe te computer searches forthe progam e e pogram s found the sceen dspays ths message

    OD OGRA NAME

    5. Press he [c:l key o actuay oad the pogram he screen agan goes badurg LOADg he the pogram s LOADed the scree returs to ormaand e READY promp appeas f you want to abort e oadng press eRUN/SOP KE

    NOTE en you oad a new program nto the compuers memory asructos ad unsaed pograms n the computer are erased ad ospermanety Before you LOAD a new progam be sure eeryhng you wa okeep s saed

    Afer your program s LOADed you can RN t LIS t or mae cages

    Remember ha you hae to reSAE a changed program f you wat o eep eew erso

    Lading Diss

    sks wc are ofen caed foppy dsks are reay easy to use headanage of dsks oer tapes s that you can fnd data stored o dss muchfaser You can aso sae much more data on a dsk tha o tape

    The steps are the same for oadng preprogrammed dss and dss a youprogram yoursef

    22

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    32/199

    a k y k v ak a acg pt t k ha a g la k r a l tc k ( g cv a pc ap c m h l a y p k ag a y acg y c-p B k a ay

    . h pcv ga k v at y r sk J

    p v3 yp OD OG " 8 8 t c r k t

    yp cp k y lag a k

    O ca OD h pga y g t g pac hprgra a OD "., 8

    4 r ky k sp a y c l ay:

    SG O OG

    ODGD

    5 yp c ay D a h c appa s-ar ay

    NEW DISK

    Whn y're ing a ew prgramme is for th frt tm you ned tormat it. rmattig whih is als alle heaering prepares your dik by dOngthig lie vig the is int bs. ormatting ao crat adrctory thaty s as a tale f ntes fr the files you saveon th dik hadr aprprgramme s

    ly have t frmat new iss not dik that alrady av programs onthem ess y want t erase the ntr dk and u t

    T frmat a w s se this pca vrion of th E and E com-mans

    PN 1,5

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    33/199

    V

    e yo wat to rese a proga yove wtte be sre to SAV t befoeyo D aoter proga f yo dot yol ose the progra

    e yo age a SAVd poga yo ave to SAV aga f yo at toeep te ew veso

    We yo reSA a proga yo ae repag the old veso h the eoe f yo wat to eep both te old ad the aged vesos yo have to gvehe ew oe a dfeet ae whe yo SAV t

    Savg o Ds

    he yo wat to SAV a proga yove wrtte o ds follo hese spe steps:

    . Key SA RGRM NM"8 he 8 s te ode for dss t tells theopte that yoe sg a ds

    2 Pess RRN he ds aes a se ad the opte dspays thsessage whe te proa s saved:

    SAVNG RGRAM NAM"OKAY

    Savg o Cassee Tape

    e yo a o SAV a poga yove ritte o assete ape foohese steps

    Key SV PROGRAM NAM The poa ae yo se a e p o1 6 aaes o

    2. Pess e RURN ey The opte displays he essae PRSSROR PLAY ON A

    3 Pess e eo a play eys o yor ATASST eoe e seeoes a a s he olo of the bode The RAY popt eappease e poa s SAVd

    Whe yo SAV progras o a ds te opte atoatally aes atable of otets or a DRCRY o te aes o te pogras o te ds

    Yo a dsplay ths detory to see wat pogras ae o yor ds olothese steps:

    Key A $8 ad press RRN he opter dsplays thsessage:

    SARCHNG R $ADNGRADY

    2. Key : S ad press RRN

    Yor pogras aes ae dsplayed o yor sree

    24

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    34/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    35/199

    CHAPER 3

    Printing and Calculating

    Mathematical unctions

    Multiple Calculations On One Line

    Execution Order in Calculations

    Comining PRINTs Capailities

    I you dont know BASIC this section teaches you how to do some simpe

    things ike print words and caculate prolemsThe PRINT statement tels the 64 computer to print something on the screen

    PRINT is one o the most useul and powerul commands in the BASICanguage ou can use it to dispay just aout anything including graphics andthe results o computations To use the PRINT command oow these steps

    Key in the word PRINT This tels the computer what kind o o you want itto do

    Key in a uotation mark This tels the computer where the message yowant to print egins

    3 Key in whateer you want to print on the screen4 Key in a closing uotation mark This tels the computer where the message

    you want to print ends5. Press the RETURN key This tells the computer to ollow your instructions

    which in this case is to print your message exactly as you typed it

    When you ollow these steps the computer prints your message anddisplays the READ prompt It looks like this

    PRINT "I LOVE M COMMODORE ou key in this and press RETURN

    I LOVE M COMMODORE The computer prints thisREAD

    The 64 prints whateer you encose in uotes Rememer o key n ohuotation marks

    I you make a mistake in your PRINT statement use the INSTDE key to correct your error ou can change as many characters as you like eore you pressthe RETURN key

    I you made a mistake that you didnt catch eore you pressed the RETURNkey, the computer cant ollow your instructions Instead it dispays an errormessage to help you igure out what you did wrong or example

    SNT AX ERROR

    I you get this message check oer what you typed in to see where you madea mistake The computer is e precise, and it cant ollow instructions thatcontain speling errors or other mistakes To aoid mistakes e sure you typethings in the correct orm

    Rememer that the est way to get to know BASIC and your 64 is to try dierent things and see what happens

    6

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    36/199

    USING PRINT TO CALCULATE

    ou can use PRINT to do more than ust display what you put in quotationmarks ou can also use it to perorm calculatons and automacally dspaythe results ollow these steps

    Key in PRNT Key n the calculation you want to sole DON'T enclose it in quotation

    marks3 Press the RETURN key The computer displays the answer olowed y the

    READ prompt

    eres an example

    PRNT 4

    READ

    Type this line and press RETURN

    The computer displaysthe answer

    Be sure you eae o the quotaton marks when you want the computer tosole a prolem you type the prolem inside quotation marks the computerassumes you ust want to dsplay the prolem, not sole t or example

    PRINT Key in this ne and press RETURN

    READ

    The computer dispays

    whats in quotes

    So all you hae to do to use PRINT as a caculator is omit the quotationmarks ou can use PRINT to add, sutract, multiply and diide ou can asoue exponents and perorm adanced mathematical unctions such as iguringsquare roots

    H F

    ADDITON

    Use the pus sign ) to tel the computer to add numers Rememer topress RETURN ater you type PRINT and the calculation Ths tells the computer to ollow your instructions

    SUBTRACTION

    Use the minus sign ( ) to sutract Press the RETURN key at the end o the

    caculation or exampePRNT 3

    MUTIPLICATON

    Key in ths and RETURNThe computer displays this

    Use the astersk ( * to multply ou cant use the conentona x ecausethe computer would think ts the letter x not the multipication sgn PressRETURN at the end o the calculation or example

    PRINT * Key in this and RETURN44 The computer dsplays this

    7

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    37/199

    DVISON

    se the slash mark ( or division Press the RTRN key ater you type thecaculation or example

    PRIN 44

    EXPONENTIATON

    Key in this and RRNhe computer displays this

    se the up arrow t ) to raise a numer to a powe Press the RTRN keyater you type the calculation. or example to ind to the ith power, typethis

    PRN t 543

    his is the same as

    PNT 43

    TIP

    Key in this and RTRNThe computer displays this

    BASIC has shortcuts that make programming even aster One shotcut isareviating BASIC keywords or example you can use a ? in place oPRN hroughout this ook well show you other areviations oBASIC keywords Appendix 0 lists these areviations and shows what sdisplayed on the screen when you type the areviated orm

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    38/199

    The las example shows ha you can perform more han one calcuaion on aline ou can also perform differen kinds of calculaions on he same line orexample

    3 57+2 Key in his and RETURNThe compuer displays his

    So far our examples have used small numers and simple prolems Bu he64 can do much more complex calculaions The nex example adds largenumers

    Noice ha 797 doesn' have a comma eween he and he 9 oucan' use commas his way in BASC BASC hinks commas indicae newnumers, so i would hink 797 is wo numers 7 and 97 Rememero press RETURN afer you ype he prolem

    234.5 3457. 7956736497

    The nex exampe uses a en digi numer The 6 can work wih numersha have up o en digis u can only display nine digis in he answer So he64 rounds numers ha are more han nine digis Numers five and over arerounded up and numers four and under are rounded down This means ha2232345 is rounded o 223235 Because of rounding, he compuerdoesn' give he same answer you'd ge if you added hese numers y hand In

    his case, he answer is 233647 ou can see he difference roundingmakes

    2232345 3457 79567233649

    The 64 prins numers eween . and 9,9,9 using sandard noaion, excep for leaving ou commas in large numers Numers ouside hisrange are prined using scienific noaion Scienific noaion les you expressa very large or ve small numer as a power of or example

    223 7

    Anoher way of expressing his numer is .23 T 7 The 64 uses scienific noaion for numers wih los of digis o make hem easier o read

    There is a limi o he numers he compuer can handle even using scienific noaion These limis are

    arges numers .743 3Smalles numers 2.93735 39

    29

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    39/199

    If yu trid t prfrm sm mixd calculatins f yr wn y might nthav gttn th rsults yu xpctd This s bcaus th cmputr prfrmscalculatins n a crtain rdr.

    n ths calculatin

    22

    th answr is 4 f yu add 2 t first, and thn divid 2 by 4 But th answrs 24 if yu first divd by 2 and thn add 2 and 4

    On th 64 yu always gt 24 bcaus th cmput always pfrms caclatins in th sam rdr Prblms ar slvd frm lft t right but wthin thatgnral mvmnt, sm typs f calculatins ta prcdnc vr ths.r is th rdr f prcdnc

    irstScnd Third rth

    mnus sign fr ngativ numbs, nt fr subtractinxpnntiatin, lft t ightmultiplicatin and divisin ft t rightaddtin and subtractin ft t right

    This mans that th cmputr chcs th whl calculatin fr ngativnumbrs bfr ding anythng ls Thn it s f xpnnts thn it prfrms all multplicatin and divisin thn it adds and subtracts

    Ths xpains why 2 2 is 24 is dividd by 2 bfr 2 is adddbcaus divisin has prcdnc vr additin

    Thr is an asy way t vrrid th rdr f prcdnc ncs any

    calculatin y want slvd first in parnthss If y add parnthss t thquatin shwn abv, hs what happns

    (2 ) 24

    Yu gt 4 bcaus th parnthss allw 2 and t b addd bfr thdivisin ccurs

    rs anthr xampl that shws hw yu can chang th rd and thansw with parnthss

    ? 3 + 2 - 357

    ? (3 1) 2 37

    3 1 (23)1

    ? (3 1) (2 3)

    -45

    Th last xampl has tw calculatins in panthss As usua thyvaluatd frm ft t right and thn th rst f th prblm s slvd Whnyu hav m than n calclatin in panthss, y can furth cntr thrd by using parnthss wthin panthss Th prbm in th nnrstparnthss is svd fist xamp

    ? 3 + ( (2 3))1

    In this cas 3 is sbtactd fm 2 thn 1 s mtplid by and1 saddd t 3 As yu xpimnt with svng calclatins y gt failiawith th rd in which mixd calcatns ar slvd

    3

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    40/199

    '

    The 64 computers let you combine the two types of print statements thatyou've read about in this book. Remember that anything you enclose in quotation marks is displayed exactly as you type it

    The next example shows how you can combne the types of PRINT

    statements The equaton encosed in quotes is displayed without beng soveThe equation not in quotes s solved The semicolon separates the two pas ofthe PRN statement (semicolon means no space)

    "5 * 9 = " ; 5 *9 You key in this and RETURN5 9 = 45 The computer displays this

    Remember, only the second part of the statement actually solves the caculation. The two parts are separated by a semicolon You always have to separatethe parts of a mixe PRINT statement with some punctuation for it to work the

    way you want it to. If you use a comma instead of a semicolon, there is morespace between the two parts when theyre displayed A semicolon leaves outsace

    The 6s screen is organized into zones of 10 oumns each When you use aomma to separate pats of a PRINT statement the omma works as a tabsending each result into the next zone For example:

    total;95shortage;15total95 shortage15

    If you have more than four results they ae automatically displayed on thenext line or example

    2 * 3 - 62 i 36/00 -86 - 2 8 52

    Heres the difference when you use semicoons

    2 * 3 6;2 t 3;64;00 (48)6 -2 8 5 52

    You can use the difference between the comma and the semioon in formatting PRNT staements to create complex displays

    31

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    41/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    42/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    43/199

    CHAPTER 4

    WTNG MPLE POGM N C

    Line Nmbers

    The GOTO Saemen

    Using he LST Command

    diing Ts

    How o Use aiables

    Using FO NXT oos

    Usng F/THN Saemens o Cono aiables

    So a s book as sown o ow o d sme hings wi o oe

    eemened wih ing snge ines o nsrons no o ome andgeing insan ess b essng e TUN ke his eas wa o dongings on or omer is aled e D o CLCULO mode

    B oll obabl wan o se or omer o do moe ome obs ase moe an one saemen en o ombne a nmbe o saemens inoa OG o an se e l owe o or

    To see ow eas s o wrie o irs ogram on e oow ese ses

    1 Cear e seen b odng down he S F ke we o ess e

    CL HO ke e n and ess TU s eas o nomaon a mg sibe in e omers memo ae or eermenng

    3 e n e ollowng wo nes eal as e aea ee

    COODO 2 GOTO

    emember o ess e U ke ae ea line e o ke n e sne and ess U o noie a e ome doesn esond o

    e T ommand rg awa ke did beoe wen o ed n e samekind o ommands hs is bease o ae now begnnng e ommandw a ne nmbe hen o se ne nmbes e ome knowsa oe wrng a ogram so was o o o ns keng n e wolerogam beoe ollowng an o o nsons

    5 e n U and ress TUN Te U ommand els e ome aoe nised keing n ogram saemens and oe ead o ae onsons oowed ees wa haens wen o U s rogam

    COODO

    COODO COODO COODO COODO COODO

    3

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    44/199

    6 Sto the rograms exeution b essing he RU/STOP ke The omueontinues to follow our orders b rinting COODORE 64 over and oveuntil ou interrut with the RU/STOP ke Heres how ou sreen lookswhen ou ress STOP

    COMODORE 64

    COODORE 64COODORE 64COMMODORE 64COODORE 64COODORE 64BREAK 10READY

    This simle rogram intodues severa moan ones ha ae tebasis for all rogamming

    LINE NUMBERS

    We mentioned before in ste 4 that ine numbes tel e omuer aoure witing a rogram The also tell the omuer in what order ou want testatements in our rogram to exeue Wiout ine numbes o tel e omuewhen to follow wih instrution te omue doesn know wha o do is

    Te onger and more omlex ou ogam is the moe imorant i is oemember hat he omue ees on ou to ell WH to do tngs as weas WHAT o do One good ting abou is is a ou an ke in ine 0 befoeline 10 beause he omuer ust eks he ne numbes o find ou the odefo exeuting he ogram Te omue doesnt hek fo te ode ou nesaea on te seen

    Anoher advantage of line numbes is tha ou an use the numbe to refer tohe saemen on he line Wen ou wan to go bak and eea e exeuionof a statemen al ou do is refe o b ine numbe n a GTO statemen asou did in te exame above

    35

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    45/199

    THE GOTO STATEMENT

    When ou told the comuter to RUN the samle rogram above COMMODORE64 was PRNTed reeated instead of ust once because of the GOTO statemnt in lne 0

    The GOTO statement tels the comuter to go directl to a secified line

    Then the comuter follows the instructions in the secified line and goes on tothe next line

    You can use a GOTO statement to tell the comuter to go back to a linethat'salread been executed Or GOTO can tell the comuter to ski forwardeven if this means that some lines in the rogram dont get executed

    n our examle the rogram PRNTS the message in line 10 and moves toline0 There the GOTO statement tells the comuter to go back to line 10 anddo what line 10 sas to do So the rogram rints the message in line 10 againand then moves to line 0 which sends the comuter back to ine 10 and so on

    This reetition is caled a LOOP Because the examle doesn't give the com-uter a wa out of the loo the circle reeats endlessl You have to halt the c-cle b interruting the rogram with the RUNSTOP ke

    ts best to include a statement in our rogram that ends the loo so oudon't have to use the RUNSTOP ke We'l exlain more above ending loosater in this chater

    USNG TE S COAND

    Now that ou've interruted execution of the samle rogram te in LSTand ress RETURN Your rogram is now dislaed intact because it's still in thecomuter's memor even though ou interruted the rogram's execution Theonl difference is that the comuter changed our? into the word PRNT Thisdoesnt affect our rogram it's ust the wa the comuter does things Whenou use the LST command the comuter also dislas the lines of the rogramin crrect numerica order even if ou entered the lines out of order

    One of the imortant differences between writing rograms and enterng

    single lines in the immediate/calculator mode is that ou ermanent lose animmediate statement once ou execute it and clear the screen But unti oustart a new rogram ou can alwas get a rogram back ust b keing in LST

    From here ou can change the rogram SE itor RUN it again

    36

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    46/199

    EITIG TIPS

    Whn yo a a sa n a n yo y n, o n yo js an ohang a n, h os yo a n o ng opons.

    . Yo an yp a n any , an op aoaa y sssh n n o h o on. yo ha o o o pa a n s s hsa n n. o ap:

    10 "My na s Saa0 " as on n Caona0 ? n nnsyanaRNMy na s Saah n nnsyana

    s yo an s, h s n 2 n s as s pa yh son n 0 yo no y n a S oan, yo s ha ony son n 2 s s pa o poga

    Yo an asy as a n yo on an s y yng n h n nan pssng RER y. yo no y n S, yo s a ns gon, an so s h n n

    3. Yo an asy an sng n. s CRSoR ys o o -so a o n yo an o hang, an hn js h n any ayyo an o. s soon as yo pss RER y, h n p a h o n. R o s SE y o nst o .

    Whn yo nsh ng, yo an yo poga agan o y hangsy yng n S oan R a S aso ps ns nna o yo y n o o o.

    y ng o sap poga y ang a soon o h n o th ian ong yo ns angs s o mo so pasn 0 o yo R poga. s o poga os no

    S10 PR COMOORE ;0 OO 0

    COMMOORE COMMOORE COMMOORE COMMOORECOMMOORE COMOORE COMMOORE COMMOOREBREK N 0REY

    37

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    47/199

    HOW TO USE VARIABLES aa s a sy hat stas or a a. Sotis th val of a

    aa s o or yo RN a pogra. On of h prpos of a pro-ga ay o o o or als or a aial. Loo at thi lin fro aproga

    20 E X 2 + V

    Th = ign a co or a valu o T tut opional and ay oitt.

    n hs ao, X a V a aials. Sppos X stans for th nur ofdays a oh O o h s hgs ao a aial s that you can ru in a proga, so X a sa o h ays i a h onhs not ust on onhThis is h V os onhs ha 2 ays, so V sands for th day

    or 2. a hs hap hs a poga hat gis alus o h tovarials.

    Th os poa hg o s stang ho arials or cauvarials ao yo o o op ass h yo optr. arials ao lyou rit progras ha a y sa.

    agin tha yo op oans a nh o littl slots li a an ofail os h yo a pogra, yo a s so o hs slots to oldals. l yo o s g a a o h slos yo n, an dring th prograyo can p as o ah so y sg th slots na. For apl n th

    quaton ao, s o sos y ang o X a on V. t th ginningof a progra hs sos ha as thy pty. rs at happnsn yo pt a a i Vs so

    X I INo t varia V has h a Yo a g V hs al st y riting tisip statnt

    V

    Sinc X quals 2 plus V, h yo RN h poga Xs s o gs a val, too

    X

    rs o th progra loos

    V = 2X 8 V

    ? T E NMBER OF DVS N MV S XRNTE NMBER OF DVS IN MV S

    rs anotr progra tat ss varias:

    X% 2 X 2. X = TOTL4 V X% X ? XV

    8

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    48/199

    Whn yo RN t poga t agay s ots loo ts atr ln 3 s -ct:

    On copton o th proga Y as t a 38Th ao apl ss t t typs o aals:

    EXAMPLE

    YE SYMBOL DESCRIPTION EXAMES VALUES

    Intg 0/0 o s X% % ,02,3Tt strng $ caacts n X$ AB$ "O:

    qots "DY

    Floatng al ca) X B 23. pont o o nrs .3E+2

    B s yo s t gt aa typs yo pogas yo t to osothng assgn a tt stg to an tg aa yo poga otor.

    Th a a othr thngs to p n hn yo assg nas toarals

    ara na can a on o to caractrs not contng th spcasyo s t tg an tt stng aals

    Yo can s o than to apatc characts n a aral na ut thcopt oly cogns t st to. So th coptr ol thn RNO a ENO a t sa aral rrrng to th sa slot

    pogra s as o popl to a hn yo us longr aral nast h yo s o than to chaactrs n a na sur th rst toa nq

    Yo can s X X% a X$ on progra caus th spca syos %an $ a ac aal na nq Th sa s tru A % an$

    Th st caact st alphatc (A to Z Th scon an any latrcharactrs can thr alphatc or nurc ( t 9 r that thcoptr gors charactr atr th scond nlss ts a % r $ n ththr poston

    aral nas cant contan BSIC rds hch ar as cad rs ords. hs ar th ords RIT and R that ar part thBSIC langag Appn D lsts a th BASIC rsd rs

    9

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    49/199

    ee e e ape pra that h yu ho to ue variable Thieae a e of the ther thn youve learned far

    E0 X .2Y

    30=X*Y "EA AAABEY5 "KE AAABEZYY0 "EBKNG NT:YEA AAABE KE AABE EBKG 30

    e 0 an vaabe nae.e a 5 a eae and the current value of varable Y and Z

    tce that at e , the value for Y .e ve Y a ne value and thi ne value PNed in line ine

    h that a vaae can have re than ne value n a prorane a h anthe of the perful feature f variable you can

    ae a vaae ea t itelf and another value Thi int aoed in reularaea t th d f tateet i coony ued n proran tea: tae the cuet vaue f a varable cobne it th another value and

    repace the ft vaue f the varale ith thi ne value You can alo uetateet e thee

    Y Y YYXY Y 2Y = Y * X 2)

    4

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    50/199

    SNG FONEXT LOOPS

    We entione loops earlier i this chapter urin the explaatio of theGOO tateent As youll reca loops are repeate executios of oe or morelne in a prora

    he ONEX statement lets you create very usefu oops that cotrol the

    nuber o tes a semet of a prora s execute The F statemet setsa lit on the uber of times the loop wl execute by assi a rae ofvale to a varable For exampe

    O ON TO 4

    The NEXT stateet arks the e of a FEXT loop Whe the proramreaches a NEXT statemet the coputer checks the F stateent to see ifthe liit of the loop has been reache f the mit hasnt bee reache the oopcontinues an the variabe i the F stateent is icremente by oe For ex

    aple you a a FONEXT oop to the prora at the beinni of thschapter heres what happens

    0 FOR = TO 420 ? OMMODORE 4 "

    30 NEXRN

    OMMOOREOMMOORE 4OMMOORE 4OMMOORE

    No that you've ae the FONEXT loop you ont have to break i withthe O key to halt the prorams executio

    hi ONEXT oop works like ths

    Line 0 ives the variabeT a rae of vaues fro 1 to an tels the compter to execute the ext lies uti CT euas 4

    Lne 20 tels the coputer to prntOMMODOE 4Line 30 tels the coputer to a to the current value of CT As o as the

    ale o reain ithn the rae of to 4 the proram repeats anOMMOORE is NTe aain When C equals 4 line 20 executes oeore tie When line 30 aain as to CT the coputer kos that C s noot o rae o the coputer stops executin the loop an the prora ens bytel

    o ae sre you unerstan how the F/NEXT loop works we a morePRNtateents to line 20 that let you keep track of the value of CT

    4

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    51/199

    20 PRN COMMODOR 6 COUT =; CT0 NX CRNCOMMOOR 6 COUNT=1COMODOR 6 COUNT=2

    COMMODOR 6 COUNT=

    COMMODOR 6 COUNT=

    Asyou can see the proram ends automaticaly when CT is out o the raneset up in the FOR statement

    You can increment the value of the variable in a FOR/XT statement byvaluesother than 1 All you do is add both the word STP and the value you wantto use to the end of the FOR statement For exampe

    NW

    10 FOR B = 1 TO 10 STP 520 PRINT B0 NXT B

    RU1

    579

    NW

    1.5

    555759.5

    10 FOR A = 2 TO 8 STP 220 PRNT A0 NXT A

    RUN2

    This comma tels the computer to print eachvalue beinnin at the first position of thenext 10 space zone

    6810

    6

    556585

    8

    You can also use a FOR/XT loop to count backwards When you do thismake sure your SP is neative For exampe if you chane ine 10 to this

    10 FOR A = 8 TO 2 SP

    Heres how the output looks

    RU8 6

    2

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    52/199

    I IF/TH TTNT TO ONTROL PROR

    An FHEN saemen s anoher way to control proram eecution Thissaement tells e compuer to check IF a condon s true IF that condiion srue he insrucons afer he word THEN eecute IF that condition is false theproram oes on to he net line without folowin te nstructions in the THEN

    staemen For eample0 X = 6020 X = X + 10 IF X = 6 THEN PRINT GOT IT ED0 GOT20

    You can use an IF statement to start a oop or to decde wheter certain parts ofproram wll eecute For eample

    10 A=

    020 F A< = 8 THEN 00 END0 FRODO LIE S A50 A= A + 260 GOT20RNFRODO LIES 0FRODO LIES 2

    FRODO LES 4FRODO LES 6FRODO LIE S 8

    In ths eampe the IF/THE statement in line 20 tells the computer to ceckhe current v alue of A IF A is equal to or less than 8 THE the proram skips line0 and coninues RUNnn at line 40 IF A s more than 8 n other words IF thecondon in ne 20 s false the computer inores te instructions after te THEsaement

    F line 20 s false THEN lne 30 is eecuted

    Line 0 PRNTs the messae and the current value o ALine 50 adds 2 to the value of A each time the loop RUs As soon as Aecomes 1 line 20 becomes false line 30 becomes true and the proram endsimmedaely

    You can use any of tese reational operators in IF/T HE statements

    SYMBOL

    >< =

    MEANIG

    Less thanGreater than

    Equal toNot equal toGreater tha or equal toLess than or equal to

    43

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    53/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    54/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    55/199

    CHAPTER 5DVD BSI

    Introducton

    Smple Anmaton

    INPUT

    Usng the GT Statement for Data Input

    Usng GT to Program Functon Keys

    andom Numers and Other Functons

    Guessng Game

    our oll

    andom Graphcs

    IODIO

    The next few chapters are for people who are famar wth BASC programng anguage and the concepts necessary to wrte advanced programs

    Those of you who are just startng to earn how to progra ay fd soe ofthe nformaton too technca to understand copletey. But you' fnd soesmpe exaples that are wrtten for new users n two chapters, SPITGAPHCS and CATING SOUND. These exaples wl gve you a good deaof how to use the sophstcated graphcs and sound capaltes avaae onyour 64.

    If you want to earn more aout wrtng programs n BASIC, chec thelography n the ac of ths manual Appendx N).

    If you are already falar wth BASIC programng, the foowng chapterswll help you get started wth advanced BASIC prograng technques. oufnd extensve nforaton aout advanced programmng n the COMMODO

    64 PGAMMS FNC GUID, whch s avalae through youroca Commodore dealer.

    46

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    56/199

    SI IIO

    ou ca use some o he 6s graphc capaes y pug ogeher whayouve leared so ar hs maual alog wh a ew ew coceps

    Try eerg he olowg pogram o see wha you ca do wh graphcsNoce ha you ca clude cuso cools ad scee commads WITHIN a

    PINT saeme Whe you see somehg e CS e) a pogamlsg hold dow he SHIT ey ad press he < CS ey The sreeshows he graphc represeao o a cursor e whch s wo vecal reversedars The graphc repeseao o he SHITed CHOM ey s a eversed

    :;. INDICATE NEW0 M BO NCNG B D0 PINT CHOM

    5 O X TO 0 PINT CRSRDWN)NXT "'30 O B TO 00 PINT CS T)M sa SHIT-Q"

    50 O TM TO 560 NXT TM0 NXT B5 M MO B IGHT TO T80 B 0 TO STP

    90 PINT CS T) CS TCS T00 O TM TO 50 NXT TM0 NXT B30 GOT0

    ' words hs ex w e compleed o oe e Howeve as og as you

    do h -iyou 6 w auomacaly move o he ex le eve mddle o a word

    Whe hs proram Ns dsplays a oucg al movg acoss hescree om e o gh ad ac aga Tae a close loo a he pogram o seehow hs s doe

    47

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    57/199

    NEW0 REM BOUNCING BAL,--- 20 PRINT "(CR/HOME)25 FOR X 1 TO 10: PRINT (CRSROWN);NEXT 30 FB= T 4040 IN .( FT) . is a F-0"

    ,.50 F M= 1 T5L60 NX T70 NXT B7 MV BA IT F 80 FB40 T90 INT ( F) ( F).( FT)-100 F TM 1 T 110 NX T0 NXB130 T 0

    ine 10 s a ark tha tels you what he program does A Mak statemen has no effec on the pogam itself

    ine 0 cleas he screenine 5 INTs en cursodown commands hs just postions he bal in

    the mdde of he sceen Wthout ths lne, the bal would move across the top lineof the sceen

    ine 30 sets up a loop to move the ball 40 columns from lef to righ

    ine 40 dos three things1 INs a space to erase the prevous ball positions INs the bal3 erforms a cursorleft t get ready to ease the current bal positon agan

    ine 50 and 60 set up a loop that slows down the balls movement Wthouths oop he bal woud move too fast for you to see cealy

    - ine 70 complees the loop set up in line 30 to INT balls on he screenach me he oop executes, he bal moves anothe space to the right As youcan see from the usration, the pogam contains a oop wthn a oop You

    can include up to en loops within a loop he only time you get in touble iswhn the loops cross over each other he loops have to be ND insideeach oher n ohe words if you sart loop A and then sart loopB nside oop Ayou mus fnsh loop B (the insde loop) first A maxmum of nine loops may benested in this way

    When you're writng a progam wth oops, is a good dea to daw arrowsfrom the beginnng to the end of the loops your loops cross, the compuercant figure out wht you want, so it cant execute your pogram

    nes 80 hrough 0 just revese te steps n he fst pa of the program

    and move the bal from right to left ine 90 is slightly different from line 0because the ball s movng n the opposite diecion and you have to erase theba to the igh and move o he lef

    ne 30 sends he pogram back to line 0 to start the whole process overagan

    o a varaon on the pogram, change line 40 o read

    0 N (FT) (0)

    un the progam and see wha happens now Because you eft out the curso

    contol each ba remans on the screen until it is eased by the ball moving ightto ef n the second part of the program

    48

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    58/199

    INPUT

    Up to now, everything n a program has been set up before the programRUNs Once you executed the program you couldnt change or add anything

    The INPUT stateent ets you send informaton to a program WHILE it is RUNning Not only does the program act on this inforation you suppy but the pro

    gra wont contnue untl you suppy it.To get an idea of how INPUT works type NEW press RETURN and enter this

    short program

    0 INPUT A20 PRINT YOU TYPED A30 PRINT40 IF A STOP" THEN END50 GOTO 0

    RUN? GO-YOU TYPED GO

    ? CONTNUEYOU TYPED CONTINUE

    ? STOP-YOU TYPED STOP

    Here's what happens in this program

    Lne 0 tes the coputer to dspay a question mark to propt you to INPUTa value for A, and to wat untl you suppy the vaue before contnuing the program executon.

    Line 20 PRINTs a message and the INPUT value and ine 0 PRINTs a bankne.

    ine 0 tes the computer to end the program mmedatey IF the vaue youNPUT for A s STOP

    Lne 50 returns the program to line 0 so you can INPUT another value IF line

    0 is true because the ast value you INPUT for A was STOP, then line 50 sn'texecutedYou can INPUT nuerc or strng variables and you can have the INPUT

    stateent print a essage aong with a question mark to descrbe the kind ofNPUT the computer s waitng for For exape heres what happens when you

    add a propt essage to ne 0 of the prevous exampe

    0 NPUT KEEP GONG"ARUNKEEP GONG? GO

    YOU TYPED GO

    KEEP GOING? STOPYOU TYPED STOP

    49

    Propt message cantbe ore than 38

    characters

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    59/199

    Hrs a mor complx xampl that dmostrats a lot of whats bprstd so far icudig th NT statmt.

    NE1 E TEEATE CONVESON OGA INT (SHIFTCLHOE)10 INT CONVET FO FAHENHEIT O CELSIS (F/C)":INPT A20 IF A THEN 100 IF A F" THEN 140 F A C" THEN END50 NT ENTE DEGEES CESS: ";C60 F: (C*9)15+ 320 INT C; DEG CELSIS "; F; DEG FAHENHEIT"80 INT9 GOTO 101 INT ENTE DEGEES FAHENHEIT: "F110 C 2)*9120 NT F; DEGFAHENHEIT ";C; DEG. CELSIS"10 INT140 GOTO 10

    Li 10 uss th INT statmt to prit a prompt ssag ad to wait foryou to typ i a valu for A

    is 20 0 ad 40 chck what you typd i ad tll th computr whr to

    go xt Li 20 tlls th computr to go back to i 10 ad ask for INPT agaF othig was typd i (F just ETN was prssd) Li 0 tlls th computr to go straight to li 100 ad prform th FahrhittoClsius covr

    sio IF th valu you typd for A is Fi 40 chcks to b sur that you havt typd i aythig bsid F or C. IF

    you hav li 40 ds th program F you typd i a C th computrautomatically movs to li 0 to prform th ClsiustoFahrhit covrsio.

    t may sm ik too much dtail to iclud al ths F statmts to chck

    what you NT But this is a good programmig practic that ca spar you alot of frustrato. You should aways try to b sur that your program taks carof al possibilitis

    Back to th xampl: oc th program kows what typ of covrsio tomak th calculatios ar mad Th th program INTs th tpratur

    you trd ad th covrtd tmpraturTh caculatio this program prforms is just straight math usg th sta-

    dard formua for tmpratur covrsio Aftr th caculato fishs ad thaswr is PINTd th program loops back ad starts ovr.

    Hrs a sampl xcutio of this program:CONVET FO FAHRENHEIT O CELIS (F/C) ?FENTE DEGEES FAHENHEIT 22 DEG FAHENHET 0 DEG. CELSIS

    CONVET FO FAHENHET O CELSIS (F/C) ?

    Aftr you N this program you might wat to sav it o dsk. This prograas wll as othrs ths maua ca form part of your progra bray

    50

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    60/199

    SI H S O D I

    ET lts yo pt o charactr at a tim fom th kyboard withot prssg th RETURN ky This raly spds p trig data may cass.

    Wh yo RUN a progam that has a ET statmt whatv ky yo prssis assigd to th vaiab yo icd i th ET statmt Hrs a xampl

    1 RIT (SHFTCLRHOE)10 ET A$ IF A$ " THEN 10

    20 PRINT A$0 OTO 10

    Li 1 clas th sc

    No spac btwqots

    Li 10 ts yo typ i ay ky o th kyboad I ffct th loop i li 0tls th compt to wait til yo typ i a ky bfor movig to li 20

    Li 20 displays th kys yo typ o th scL 0 sds th program back to ET aoth chaactr. Its importat to

    rmmbr that th chaactr yo typ i wo't b displayd ss yo PRINT itto th sc as wv do i li 20

    Th IF statmt i li 10 is v importat ET cotialy works v ifyo dot prss a ky (lik INPUT which waits for yo rspos) so th scod part of li 10 cotially chcks th kyboard ti yo hit a ky

    Try lavig ot th scod part of i 10 ad s what happsTo stop this progam pss th RUN/STOP ad RESTORE kys.Yo ca asiy wit th bgiig of th tmpatr covsio pogram

    to s ET istad of INPUT. If yo'v SAVEd this pogam LOAD it adchag lis 10 ad 20 ik this

    10 PRINT CONVERT FRO FAHRENHEIT OR CELSIUS (F/C)20 ET A$ IF A$ " THEN 20

    This chag maks th pogam opat mo smoothly bcs othghapps lss yo typ i o of th two sposs ( o C tht scts thtyp of covrsio If yo wat to kp th pogam b s to SAV t ga

    5

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    61/199

    USNG GET TO PROGRAM FUNCTON KEYS

    As youll recall from an earlier chapter we told you that the keys on the rightside of the keyboard (f through f8) are function keys that you can program toperform a variety of tasks.

    Heres how to program a functon key

    Use a GT Statement to read the keyboard.2 Use IF statements to compare the key you press to the CHR$ code for the

    function key you want to use. very character on the keyboard has a uniqueCHR$ number For exape the CHR$ code of f s 33 Appendx F sts theCHR$ code fo all keys

    3 Use THN stateents to tel the computer what you want the functon keyto do

    When you RUN the program al you do is press a function key you program

    ed and the key will follow the instructions you gave it in the THN statementFor exampe

    0 $ I $ ''' HN 00 I $ HR$( 37) HN RI NT HR$( )30 $ HR$( 3) HN RINT YURS TRUY

    ine 0 tes the progra to assgn the key you press to the variabe A$ Asyou'l reca from the previous example the loop in ne 0 contnuay checksthe keyboard for input.

    ine 20 programs function key 2 CHR$( 37) ne 20 tells the coputer tomake A$ equa to CHR$( ) f you press functon key 2. CHR$( ) s the switchfrom upper to lower case letters on the keyboard When you RUN this programyoull see that the characters on the screen immediately make this switch if youpress f2

    ine 30 programs function key 3 CHR$( 3). ine 30 tels the coputer toake A$ equal to the character string YURS TRUY and CHR$(3) f you pressf3 durng program execution. CHR$(3) is the code for the RTURN key.

    TH CHR$ codes for the functon keys are

    f CHR$( 33) f2 CHR$( 37)f3 CHR$(3) f CHR$( 38)f5 CHR$(35) f6 CHR$( 39)f7 CHR$(36) f8 CHR$(0)

    he CMMDR 6 RGRAMMRS RFRNC GUD has more information about programming function keys. You can purchase this extensive

    guide fro your local Comodore dealer.

    52

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    62/199

    ADOM UMBES AD OHE FUCIOS

    The 64 also has built-in functions that you can use to pefom specia tasksFunctions are ike built-in prrams included in BASC The reat advantae ofthese butn functions is that you don't have to type n a numbe of statementseve time you want to perform a specialized caculation nstead, al you do is

    tpe the command for the function you want and the computer does al the est.These built-in functions include fiurin square rts SR), findn out the

    contents of a memo lation EE), eneratin random numbes RND) etcAppendx C ists all the functions available on you compute

    One functon you can have a lot of fun with is the random numbe functon,RND. f you want to desin a ame or an educational prram, you' often needto be able to prram your computer to make up random numbes Fo exampe ou'd need to do this to simulate the tossin of dice Of couse you couldwte a poam that woud enerate these random numbes, but ts much

    easier to be able to do this just by callin upon the prewritten RaNDom numrfuncton.

    To see how RND works, t this short poram

    NEW10 FOR X 1 TO 10 F YU LEVE U HE C, YU20 RNT RND 1), F UBE E 1 CU

    30 NEXT

    When you RN this proram the screen displays

    7892897 6739256373663 012422876829521 37279E - 0.402342724 8758203 2455701

    our numbers dont match t would be ncedbe f te d ecause epoam enerates a completely random st of ten numbes

    f you the proram a few more tmes ou'll see that the esuts ae

    aways different. Thouh the numbers dont have a patten ou notce a econsstences about the ist the poam dspasFo one thn, the esuts ae aas beeen an 0 bu nee eua to o

    . Fo another the numbes ae ea numbes (th ecma ponts).No we stated out to smulate dce tosses and te esuts fom ts po

    am aen't exacty what wee ookn fo o e add a fe moe feauesto ths poam to et hat we an

    First add this ne to the proam to epace ne 20 and RN the proamaain

    20 PRNT 6RND()RN

    360566645.48602353.0045083913025842205644

    45268751309650243905268532540781302

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    63/199

    ow weve o resuls larer ha bu si have rea ubes. To sove hswell use anoher ucio

    The uncio convers real nubers o ieer (woe ubes. So yreplacin line 2 aai

    0 (6*D())

    3 1 0 4 5 5o 1

    ow were even close o our oal bu you oice ha e ubes aeo 0 o 5 no 1 o 6. So as a inal sep wel replace lie aai

    0 T(6*D(1)) 1

    ow wen you he poa youll e he resuls you waWe you wan o enerae a rae o eal ubes isea o woe

    bes e orua is slihly dieren because you us subac e owe o e rae rom he upper limi. For exaple you ca eeae aoubes bewee 1 and 5 by ypin

    P D(1)*(51) 1

    e geera orula or enerain radom bers a cerai ae s

    E

    D(1) * ( MT O OE

    54

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    64/199

    GUESSIG GAE

    Here's a gae ha uses rao ubers. Ths gae o o uses he RNDuco bu also ruces soe aoal prograg heor.

    Whe ou RUN hs progra he copuer geeraes a rao uber NMhose alue ou' r o guess as e urs as possbe

    NEW REM NUMBER GUESSING GAME PRNT "(CLRHOME _5 INPUT "ENTER UPPER LIMIT FOR GUESS ;LI NM = INT(LRND( + 5 CN = PRIN "IVE GOT THE NUMBER.:PRINT NPUT "WHATS YOUR GUESS; GU

    5 CN CN + 4 IF GU>NM THEN PRINT "MY NUMBER IS LOWER PRINTGOTO 35 F GU< NM THEN PRINT "MY NUMBER S HIGHER: PRINT:GOTO 36 IF GU = NM THEN PRNT GRE YOU GO MY UMBER65 PRINT "IN ONLY ; CN ;" GUESSES:PRINT PRT "DO YOU WAT TO TRY ANOTHER (YN8 GET N$ IF AN$= " THEN 89 F AN$ = "Y THEN F AN$< > " HEN

    ENDYou ca spec ho arge he uber be a he sa o e ogra.

    The s up o ou o guess ha he uber sA sape ru ollows alog h a explaao

    ENTER UPPER LIMIT FOR GUESS? 5IVE GOT THE NUMBER

    WHT'S YOUR GUESS? 5MY NUMBER IS HGHER

    WHATS YOUR GUESS? MY NUMBER S OWER.

    WHTS YOUR GUESS? 9GRET! YOU GO Y UBERN ONY GUESSES

    O YOU W O RY OHER Y?

    55

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    65/199

    he FHE saeen (lines 4) coe o ges o e onur (M) generae by line 0 If yo ges s og e og e owheher your guess is higher or ower a .

    Each e you ake guess lie as o C. C s coe eesrack of how any guesses you ake o ge e g ube e oe ohis gae of course is o guess he be a e e oe

    hen you ge he rig anse he rog e ege !YO GO MY MBER n ells you o a geses o oo

    Reeber ha he rogra ceaes a e ao e e e oa he gae

    You igh an o a a few lines o he ogr so e e oeage of urs generae b s gae.r-. .-.

    PROGAMMING TS: e 0 a 50 coo ee e ee o ge

    e o only e yng e o oee eo eo oce h e I/TH ee ee o e P

    oeg beore rcng o oe e

    YOU OLL

    e oog oga siulaes he ro o o ce Yo

    e ge b sel or use i as pa of a arger gae5 P RY YR K0 P CE = I(R( )6) + 0 PI W ICE IT(D( )6) 0 P P SS SPC BAR OR AOTHE O P0 '' E 4050 C$ HE 0

    o oe ee bou BASC n rao ue ee o

    oo gog o roga. As yo a ec o e eo oogg e co e CHR$() s e hace g coe o ece

    5

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    66/199

    D GHICS

    As a ina ote on andom numbes and as an ntoduction to desgninggahics, ty enteing and RUNning ths pogam

    10 PRIN "

    20 PRIN CHR(2055 + RND (130 OO 20

    he unction CHR$ (CHaacte Stng gies you a caacte based on a stan-dad code numbe om 0 to 255 ey caacte the 6 can pnt s encodedthis way Aendix ists te CHR$ codes o all keys

    A quic way o inding out te code o any caacte is to use te unctonASC (o the standad ASCII code ype

    PRIN ASC(X"

    X is te chaacte you'e checking X can be any pintabe caacte, ncudnggahics chaactes You must encose te caacte n quotation maksHees an exame

    PRIN ASC("1

    he CHR$ uncto is te opposte o ASC

    PRIN CHR$(1

    I you tye

    PRIN CHR$(205CHR$(206

    the compute displays the two gt side gaphcs on te M and N keys, wichae the chaactes used n the tte maze ogam you just ted

    he omua 2055 + RND(1 tes the compute to pick a andom numbe bet-ween 2055 and 2065 ee s ityity chance tat te andom numbe wil beaboe o below 2 CHR$ gnoes actiona aues, so a te time e

    chaacte wth code 205 is pinted, and te est o te tme code 206 isdislayed

    You can expeiment wit ts pogam by addng o subtactng a coup ftenths om 2055 is ges ete caacte a geate cance o beingdisayed

    5

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    67/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    68/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    69/199

    CHE 6COLOR AN GRAPHCS

    o to se olo ad Gahics o Yor ote

    Pritig olos

    olo $ odes

    o to se PEEKs ad POKEs

    cee Grahics

    cee Meo Ma

    olor Meo Ma

    More Bocig Balls

    HOW TO USE COLO AN GRAPHCS ON YOUR COMPUTER

    o a this book has eseted soe o the sohstcated cotigcaabtes o or 6 Bt oe o the ost ectg eatres o o e coter is ts otsadg abilit to odce 6 deet coors ad a ot o dieet grahics

    Yove aread see a ve sile deostatio o the gahcs the bo

    cg ba oga ad the aze roga at the ed o the last chate hischate itrodces o to e cocets that eai grahic ad coorograig ad that sggest deas or ceatg o o gaes ad advaced aiato

    60

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    70/199

    PRNTNG COLORS

    When yu tried te clr aligent test in hapter yu discvered that yucan cange tet crs by siply ding dn the key and pressing nef the cl keys

    he 6 ffers a fu range f 6 clrs ug ny eght crs are printed n

    te c keys yu can get eght re by dng dn te key and press-ing a clr key eres a ist f the clrs:

    a K : [a RA n4

    a H [a R .

    &1 R [i . R l YA [ RAY 1 [ R RAY I R D [ L R IIa [a L. 0l m [

    Y RAY

    When e shed yu the bucing ball prgra n te last chapter yu sathat keybard cands suc as cursr veent can be ritten int Pstateents n the sae ay yu can as add tet cr changes t yur pr-gras

    6

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    71/199

    Type NEW nd t expeimenting with chnging coos. Hold down the CTRkey nd t the sme time pess the 1 key. Now eese both keys n pess theR key. Now ho down the CTR key gin nd press the 2 key. Relese theCTR key nd type the A key. Moe through the numbers lternting wth theletters, nd type out the wo RAINOW ike this

    PRINT"j RjAj I jNj B jO jW"1BBEB

    Youl ecll ht cusor contros ppe s gphic chrcters in the RNTsttement. Coo contros re lso epresented s gphic chrcters. The coorchrt printe boe shows the gphic chcters tht ppe with ech color.ecuse o the gphic chrcters tht re displyed when you seect coorkeys you RINT sttement wil look stnge but when you RUN the progrmyoull see tht only the text o the messge is isplye. The letters in temessge utomticy chnge coors ccording to the color controls you plced in the RINT sttement

    Now try mking up some exmpes o you own mixing ny numbe o cooswithin single RINT sttement. Dont orget the secon set o colors tt youcn get by hoding down the key while you press coor keyP

    Ate you RUN pogrm with colo or mode (reerse) chnges youll notice

    tht the READY prompt n ny ditionl text you key in is the sme s thest color o moe chnge you mde To get bck to the noml isply pessthese keys together

    RUN/STO n RESTORE

    6

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    72/199

    COLOR CHR$ COES

    Befre yu start readig this secti take a lk at ppedi F hich iststhe H$ cdes fr a keys the keybard

    s yu ked ver the list f H$ cdes, yu prbably ticed that eachclr has a uique cde just ike al the ther keys ad he keybard ctrls If

    yu prt the cdes themselves by usig the H$ fucti metied thelast chapter yu ca get the same results yu gt by typig r adthe clr key i a P statemet

    Fr eampe try this

    EW P H$: EM /HME > P H$"H$ HGES ME ?

    H$ HGES ME ?Whe yu this prgram the scree clears befre the message i lie

    is Ped he tet shuld be red may cases, yul fid that its much easier t use the H$ fucti t

    chage clrs, especially if yu at t eperiet he et page shsather ay t get a raib f clrs here are a umber f simiar lies ithe prgram thrug s use the editig keys t spare yursef a t ftypig See the tes at te ed f the prgram istig t refresh yur memry

    editig prceduresEW EM M BS5 P H$ EM H$7= HME PI H$ ; ;:EM EVESE BS D + 3 G 569 P H$5: G 5 P H$ G 6 P H$3: G P H$3: G P H$ G 9 P H$56 G P H$ 5 G P H$59 G

    ype ies 5 trug ray Yur ispay su k ke tis

    EM M BS5 P H$ : EM H$ HME P H$ EM EVESE BS20CL= INT(8*RND(1))+ 1

    3 G 5679 P H$5 G

    6 3

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    73/199

    EDITIG E

    Use the key to position the curso on line 40. Then type 5 ovethe 4 of 40. Now use the < CRSR-rght key to move over to the 5 in the CHR$paentheses. Pess SHIFT and INST/DE to open up a space, and key in 28.Now just press RETURN wth the cusor anywhere on the ne.

    The dsplay should ook ke ths now:

    NEW

    1 REM AUTOMATIC COLOR BARS5 PRINT CHR(1 47 : REM CHR(1 47)= CR/HOME0 PRNT CHR(1 8;" ;:REM REVERSE BAR20 C INT8*RND)+

    30 ON C GOTO 40506070,80901 00,1 1 050 PRINT CHR(28; GOTO 1 0

    Don't wor about line 40 t's stl there, as you can see by STn the progam. Folow the same steps to modfy line 40 wth a new ne number andCR code unt youve entered a the remanng lines As a fnal check the ente proram to make sure al the nes are rght befoe you RUN t

    You pobably undestand the colo ba progam except for line 30 ere's a

    bef explanation of how this program works.Lne 5 prints the CHR code for CRHOE.Lne 10 tuns on evese type and pints 5 spaces, whch turn out to be a bar

    snce theyre reversed The frst time though the proram the bar is light bluethe norma screen dispay colo.

    ine 20 uses the random functon to select at random a coo between and8.

    ine 30 uses a varaton of the FHEN statement caed ONT hchlets the proram choose fom as list of line numbers where the pogram will o

    next. If the ON varable (n this case C has a value of the program oes tothe frst line number listed (here ts line 40. f the variable has a value of 2 theprogam goes to the second line listed, and so on

    ines 40 through 0 ust convert the random key colors to the appropriateCHR code for that colo and return the proram to ne 0 to NT a sectoof the bar in that colo. Then the whoe process starts aain

    See if ou can figure out how to produce random coos xpandONG to handle the additional colos and add the remainin CH codes

    4

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    74/199

    HOW TO USE PEEKS AN POKES

    PEEKS nd POKES le yo ech ond nde yo compe memoynd ick hing n excly whee yo wn hem

    oll ecll h in Chpe 4 we explined vible being like lle lon he compe memoy wih he vible nme he lo dde Well

    imgine ome moe peclly dened lo in he compe h nd opecific memoy locion nd h hve nmbe fo ddee

    o 64 look hee memoy locion o ee wh he ceenbckgond nd bode colo hold be wh chce o diply on heceen nd whee o diply hem ec

    o cn chnge he ceen colo define nd move obec nd even ceemc by POKEng dffeen vle ino he pecifc memoy lo

    Imgine ome memoy lo lookng omehing like h

    380 38 I 3282 :ORERCOOR

    CKGRONCOOR

    he f wo o e he memoy locio fo he bode nd bckgondcolo on yo ceen Weve p 2 he vle fo RE in he bode colo boxnd he vle fo WE in he bckgond colo box Now y yping h

    E 28 RERN>

    he bckgond colo of yo ceen will chnge o yellow bece we phe vle fo yellow in he locion h conol bckgond colo

    y POKEing diffeen vle in he bckgond coo locion nd eewh el yo ge ee li of he vle o POKE fo ech colo vilbleon yo 64

    0 CK 8 ORNGE E 9 RON2 RE 0 ligh RE

    3 C GR 4 PRPE 2 GR 2 GREEN 3 ligh GREEN6 E 4 ligh E EOW GR 3

    ee le pogm yo cn e o diply vio bode ndbckgond colo combinion

    NEW

    0 OR O O 20 OR 0 O 30 POKE 328040 POKE 328O0 OR X = O 00 NEX 60 NEX B NEX ORN

    65

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    75/199

    This program uses two smple loops to POKE various vaues to change thebackground and border colors. Lne 50 contains a DELAY loop whch justsows the program dow a lttle bt.

    If you're curious about what vaue is currently in the memory locaton forbackgroud color try ths:

    ?PEEK (53280) AND 15PEEK looks at a whoe byte, but colors only use hal a byte called a nybble.

    To PEEK just ths nybble you have to add the AND 15 to your PEEK statement.f you used ths PEEK ater RUNnng the prevous program youd get 15 as theaswer because the last border color POKEd was GRAY 3 whch s 15

    In general PEEK ets you see what value s currently n a specc memoslot. Try addng this lne to your program to display the values o BORDR andBACKGROUND as the program RNs

    25 PRINT CHR$(147); "BORDER = "; PEEK(53280) AND 15BACKGROUND = ; PEEK (53281) AND 15

    SCEEN GAHCS

    S ar when youve PRINTed normaton the computer has handed he n-ormaton sequentally one character PRNTed ater the next starng rom thecurrent cursor poston except when you asked or a new line or used a comma

    n PRINT ormattng.You can PRINT data n a paricular place by startng rom a known pace on

    the screen and PRNTing the correct number o cursor controls to ormat thedsplay. But this takes time and program steps.

    But just as there are certain locations n the 64s memoy to control colorthere are also memory locatons that you can use o conro screen locatons.

    66

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    76/199

    SCREEN MEMORY MAP

    The 64' ceen can hold 1chaacte (4 column by 5 line) o theeae 1memoy location et aide to epeent what i o the ceen. Imagie the ceen a a gd 4 by 5 with each quae tanding o one memolocaton.

    Each memory locaton can contan one o the 5 dieent chaacte the 64can diplay (ee Appendi E) Each o thee chaacte i epeented by anumbe om to 55 you POKE the value o a chaacte into a peccceen memory locaton that chaacte wll be dplayed n that pecic ceenlocaton

    Hee a gid that epeent you ceen complete with the numbe o eachceen memory locaton.

    CLUMN10 20 30 39

    106310241064110411441184

    1224264304344384 '1424 10 0464

    1504544584162416641704

    74417841824 201864190419441984 24t

    2023

    6

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    77/199

    Te 64s scee memoy omay begs a memoy ocato 1 024 a esa ocato 202 Locao 1 024 s e uppe eft coe of te scee. Locao1 02 s e posto of e e caace o te g a so o Locato 1 s e g-most poso of te fs ow Foowg e as caace a owe e ocao s e lef-mos caace o te e ow ow

    Suppose you wa o coo a ba boucg o te scee. Te ba s eme of e scee coum 29 ow 1 2 Te fomua fo cacuag ememoy locao o e scee s

    POINT 1024 X 40 * Yow+ coumwee X s e colum a Y s e ow

    Teefoe te memoy ocao of e bal s

    POINT 1024 20 480ow (4012)

    POINT 124 coumCea e scee w SHFT a CLRH_ ME a type:

    POKE 1 5,81+ caace coeocao

    Ts POKE stateme makes a bal pea te mle of te scee. Youave pace a caacte ecy to scee memoy wou usg e PRINTstaeme. Howeve you ca see te bal ye because s e same colo aste scee backgou.

    COLOR MEMORY MAP

    You ca cage e coo of e ba at appeae by ateg aote ageof memoy. Type

    POKE 7962 cooocao

    Ts cages e bals coo o e.Evey spot o e 64s scee as TWO memoy locatos oe fo tecaace coe a oe fo e coo coe Te coo memoy map begs atlocato 2 (uppe left coe) a coues o fo 1 000 locaos. You usete same coo coes 0 oug 1 a you use to cage boe abackgou coos o ecly cage caace coo

    We ca mofy e fomula fo cacuatg scee memoy ocatos o gveus e locaos to POKE colos Hees te ew fomula

    COLOR PRNT 296 40 * YowL-column

    8

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    78/199

    MORE BOUNCNG BALLS

    Here's a revised bouncing ball program that drectly prnts on the screen us-ing POKEs rather than cursor contros wthn RINT statements. When youRUN this version, youll see that it's much more flexible than the earler pro-gra and it leads up to programmng more sophsticated aniation

    EW10 POKE 53281,1: PIN "20 POKE 532807POKE 5328130 XY= 140 X Y = 150 POKE 1024 X 40*Y8160 FO = 1 O 10 : NEX70 POKE 1024 X 40*Y3280 X = X X90 IF X = 39 HEN X = - X100 Y = Y Y110 IF Y < = 0 O Y> = 24 HEN Y = - Y120 GOO 50

    Line 10 sets the cursor coor to hte and then clears the screenNTE learing the scren on (N) 64s sets the color AM to whte but on(PAL) 64s the color AM is set to the curent background color here hite)

    Line 20 sets the background coor to blue and the border color to yello

    he X and Yvariabes n line keep track of the ball's current ro and colun osition he X and Y variables n line 40 are the horizontal and verticaldirection o the balls oveent When a 1 is added to the value of X the baloves to the right; when 1 is added the ball oves to the let A added toYoves the ball down a row and a 1 added to Yoves the bal u a row

    Line 50 uts the bal on the screen at the curent XY position ne 60 is adelay loo hich is included to keep the bal on the screen long enough for yoto be abe t see it

    Line 70 erases the bal by putting a space (code 32) where the ball was on the

    screenLine 80 adds the direction actor to XLine 90 tests to see i the ba has reached one of the side walls, and reverses

    the bals direction i theres a bounce. Lines 00 and 0 do the same thng forthe top and botto alls

    Line 20 sends the ba back to display and moves the bal againYou can change the bal to any other character by changing the code in ine

    50 ro 8 to another character code. you change X or OYto 0 the ball bounces straight instead of dagonaly.

    We can aso add a litte intellgece to the boucing bal pogra. So a teonly thng yo checked for is whether the ball is goig out o bods on tescreen adding the olloing lines to the progam:

    21 FR T 1025 POKE 1024 + N(RO)*100060 +(REVERSE SPACE)27 EX L15 F PEEK 024 X 40* 1 HN OX -OX: G 80

    Lines 2 to 27 put te blocks o he sceen n rado postos Lie 5

    PEKs to see if the ball is about to bounce into a block ad if so it changesthe bal's direction.

    69

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    79/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    80/199

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    81/199

    CHAPTER 7

    Bt and Byte Creating a Sprite

    Deigning a Sprite ning Spite On Sprte Color otonng Sprite xpanded Sprite _ Creating More than One Sprite Sprite Piorte Trnng Sprite Off

    n peo apte ee hon yo how to e grap ybol in PRNTtateent to eate anaton and other al efet

    n apte , e alo hoed yo ow to POKE harater code in pecificceen eoy aton h pt haater dietly on the creen in thepae yo eleted

    n bot o tee ae yo hae to reate obet fro exiting graphic bol o tee etod take a ot of ork When yo want to ove the obect

    yo t e a nbe o poga tateent to keep track of the obect anoe t to a ne pae nd oetie the hape and eoltion of the obectint a good a yod lke t to be beae of the litation of ing graphicbol

    o an elinate a lot o thee proble by ing prite in aniate eqence prte a hgeoltion pograable obet that yo can akeinto t abot any hape by ng BSC oand All yo have to o toove the obet py tel the opter the poition where yo ke theprite to go he opte take ae of the ret

    t thi int all yo an do t prte or exaple yo can change theicoo o an tel if one obect olde th another yo an ake the go nont and beind eah ote and yo an eay expand their ie

    Yo have to learn a fe oe detail abot yor 64 and the way it hanenbe before yo can e prte t not diffilt thogh o t ollow theeape and yoll be akng yor on prite do aaing thing in no te

    2

  • 7/29/2019 C64 User Manual 1984 2nd Edition

    82/199

    B D BY

    Beoe you can ue pite it' ipotant tat you undetand a few genealtng aut ow copute wok

    n te decia yte we count in ten uing value o 0- Wen apaicula poitio oveflow it axiu value of t ecyce to zeo ad

    caieone to te next (letand poition Fo exaple te ube 64 ean6 x (0 4 x ( Te poition of eac digit ipotat e value o 64 icalculated a ollow

    6 x 0 4 x0

    NOT Any ube aied to te powe of zeo equa

    Copute toe infoatio a a eie o electical cage epeeting and ac cell wtin eoy od a patte of eigt one ad zeo caled

    binary digit o BITS Tee cell ae called BYTS A bit wic i te aletaount of infoation a copute ca toe ca be tuned ON givig it a valueof o OFF wic a a value of

    We