Example: stock market

INTRODUCTION TO SPRITES - commodore.ca

INTRODUCTIONTOSPRITESI npreviouschaptersdealingwithgraphics, ,becauseofthelimitationofusinggraphicsym bols, ;youcantellifoneobjectcollideswithanothe r;theycanbemadetogoinfrontandbehindanoth er;andtheycanbeeasilyex-pandedinsize, , 'snotasdifficultasitsounds, ' "keepingtrackofcharactersandgraphics,cre atingcolors, "ON/OFF" "on"or"off".We' 'smainmemorytostoreinfor-mation(data) , ,theprocesswillbeverystraightforward,and you' ' ,youcanuseyourspritewithanymode,high-res olution,low-resolution, ,64,32,16,8,4,2,1,threetimes(asshown) ' youthinkofallthesquaresyoufilledinas"on" thensubstitutea1 'sthataren'tfilledin,they're"off" , ,thefirst8 squaresareblank,or0, ,lookslikethis(againa1indicatesadot,0isa space):127 Thethirdseriesonthefirstrowalsocontainsb lanks,soit,too, ,thedataforthefirstlineis:DATA0,127,069~ --123456789~10""1112i31415161718192021 SERIESISERIESISERIES1!

In addition to accessing many of the picture making locations we will also be using some of the Commodore 64's main memory to store infor-mation (data) that defines the sprites.

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of INTRODUCTION TO SPRITES - commodore.ca

1 INTRODUCTIONTOSPRITESI npreviouschaptersdealingwithgraphics, ,becauseofthelimitationofusinggraphicsym bols, ;youcantellifoneobjectcollideswithanothe r;theycanbemadetogoinfrontandbehindanoth er;andtheycanbeeasilyex-pandedinsize, , 'snotasdifficultasitsounds, ' "keepingtrackofcharactersandgraphics,cre atingcolors, "ON/OFF" "on"or"off".We' 'smainmemorytostoreinfor-mation(data) , ,theprocesswillbeverystraightforward,and you' ' ,youcanuseyourspritewithanymode,high-res olution,low-resolution, ,64,32,16,8,4,2,1,threetimes(asshown) ' youthinkofallthesquaresyoufilledinas"on" thensubstitutea1 'sthataren'tfilledin,they're"off" , ,thefirst8 squaresareblank,or0, ,lookslikethis(againa1indicatesadot,0isa space):127 Thethirdseriesonthefirstrowalsocontainsb lanks,soit,too, ,thedataforthefirstlineis:DATA0,127,069~ --123456789~10""1112i31415161718192021 SERIESISERIESISERIES1!

2 2I3128328212832821283282641641i 64164116416411015 COLUMN2024 Series1 :=Series2:255 Series3:192 Forrow2,thedatawouldbe:DATA1,255,192 Inthesameway, ,howcanit beputtouse? REMUP,UP,ANDAWAY!5 PRINTn{CLR/HOME}n10 '1=53248: REMSTARTOFDISPLAYCHIP11 POKE'1+21,4: REMENABLESPRITE212 POKE2042,13: REMSPRITE2 DATAFROM13 THBLK20 FORN=0 TO 62:READQ : POKE832+N,Q:NEXT30 FORX = 0 TO 200~ "40 POKEV+4,X:REMUPDATEX COORDINATES50 POKEV+5,X:REMUPDATEY COORDINATES60 NEXTX70 GOTO~ fROMQ"200 DATA0,127,0,1,255,192,3,255,224,3,231,22 4210 DATA7,217,240,7,223,240,7,217,240,3,231, 224220 DATA3,255,224,3,255,224,2,255,160,1,127, 64230 DATA1,62,64,0,156,128,0,156,128,0,73,0,0 ,73,0240 DATA0,62,0,0,62,0,0,62,0,0,28,0'fORMORED ETAilONREAD& ,yourballoonissmoothlyflyingacrossthesky (page72).Inordertounderstandwhathappened , ,calledregisters,couldbeillustratedinthi smanner:Register(s)Descriptiono12-lS1621 292339-46 Xcoordinateofsprite0 Ycoordinateofsprite0 Pairedlike0 and1 forsprites1-7 MostSignificantBit-XCoordinateSpriteappe ar:1=appearO=disappearExpandspritein"X"D irectionExpandspritein"Y"DirectionSprite 0-7colorInadditiontothisinformationyoune edtoknowfromwhich64bytesectionspriteswil lgettheirdata(1byteisnotused).

3 Thisdataishandledby8locationsdirectlyaft erscreenmemory:Nowlet' (s)appearonthescreenbyPOKE ingintolo-cation21a1 (locations2040-7) ,updateXandY ,optionally,expandtheobject,changecolors , "X"directionandlocation23inthe"Y" ;V= ,POKEV+21,4makessprite2 appearbyplacinga 4 inwhatis (21) likethis:SPRITES1286432~Oe~imalvaluesofs pritenumbereach168421 SpritelevelNumber21= YouWontEachspritelevelisrepresentedinsec tion21ofthespritememoryand4 youwereusinglevel3 youwouldputa1 insprite3 whichhasa ,turningonsprites2and3 wouldberepresentedasV+21, ;POKE2042,13instructsthecomputertogetthe dataforsprite2 (location2042) , ,128,64,32,16,8,4,2, bytesofeachrow, to62:READci:POKE832+N, TO20040 POKEV+4~SPRITE2'sXCOORDI~ATn50 POKEV+~SPR~lsy COORD~A:!DIfyourememberfromschooltheXcoo rdinaterepresentsanobjectshorizontalmove mentacrossthescreenandtheYcoordinaterepr esentsthesprite' to200(onenumberatatime) ,insteadof1 ,it memorysectionstomakeit , ,doesn'tit?

4 Now,tryaddingthefollowingline:2 SPOKEV+23,4: POKEV+29,4 ! (againtoindicatesprite2)intomemorysectio ns23and29,sprite2 ' , ,makethefollowingchanges:11 POKEV+21,1212 POKE2042,13: POKE2043,1330 FORX=1 to1904 SPOKEV+6,XSSPOKEV+7,190-XAsecondsprite(n umber3)hasbeenturnedonbyPOKEing12intothe memorylocationthatmakesthespriteappear(V +21).The12turnssprites3 and2 on(00001100=12).Theaddedlines45and55move sprite3 aroundbyPOKE ingvaluesintosprite3'sXandYcoordinateloc ations(V+6andV+7).Wanttofilltheskywithev enmoreaction?Trymakingtheseaddi-tions:11 POKEV+21,2812 POKE2042,13:POKE2043,13:POKE2044,132 SPOKEV+23,12:POKEV+29,1248 POKEV+8,X58 POKEV+9,10028 ISREALLY((SPRITE2)+8(SPRITE3)+16(SPRITE4 )74 Inline11thistime,anothersprite(4)wasmade toappearbyPOKE-ing28intotheappropriate"o n" (00011100=28).Line12indicatesthatsprite4 willgetitsdatafromthesamememoryarea(13th 63sectionarea)astheotherspritesbyPOKEing 2044, ,sprites2 and3 areexpandedbyPOKEing12(Sprites2and3 on)intotheXandYdirectionexpandedmemorylo cations(V+23andV+29).)

5 , ,likeit didbeforewithX=Oto200,sprite3 'veexperimentedwithsprites,a ,youcanchangeasprite'scolortoanyofthesta ndard16colorcodes(0-15) ,tochangesprite1tolightgreen,type:POKEV+ 40,13(besuretosetV=53248).Youmayhaveno~ (ofthemap)controlssomethingcalledthemost significantbit(MSB)ofthesprite' ,thisallowsyoutomovethespritetoa :afterthespritehasbeenmovedtoXlocation25 5,placea ,toget2 tomovetohorizontallocations256-320,POKE thevalueforsprite2 whichis(4)intomemorylocation16:POKEV+16, (whichis inlocation4 ofthemap).Sinceyouareonlymovinganother64 spaces, versionoftheoriginalsprite1 program:leV= ,18':POKE+21,4: POKE2e42,132eFORN= ITO62: READQ: POKE832+N,Q25 POKEV+5,lee3eFORx=eTO2554ePOKEV+4,X5eNEX T6ePOKEV+ ITO638ePOKEV+ +16, , "turnsoff" , ' :POKE44,16:POKEI6*256,O:NEWNow,youcanuse blocks32through41(locations2048through40 95) ,however, ,beforeyougettooinvolvedwehavetodefineaf ewterms:BIT-Thisis thesmallestamountofinformationa BITasa switchthatis either"on"or"off".

6 Whena BITis"on"ithasa valueof1;whenaBITis"off" , BYTE ismadeupof8 BITS,youcanactuallyhavea ,youcanhaveallBITS"off" ~"on"is:1281641321161814121whichis128+64 +32+16+8+2+1= , differentfunction, ,whilemakingtheSPRITE wideris ' ",r------Usingcombinationsofalleightbits , 'sandl' ;"00000011"equals3, ,ifthisbytegroupingrepresentedpartofaspr ite(0isaspace,1 isacoloredarea):27IT::]128+2"o64+2'116+2 '12 +2"11+ :Tosaveyouthetroubleofconvertingbinarynu mbersintodecimalvalues-we' ' ENTER8-BITB I NARYNUt'lBER:";A$12 IFLEN(A$)<>8 THENPRINT"8 BITSPLEASE:GOTO1015TL=0:C=020 FORX=8~o1 STEP-1:C=C+130TL=TL+VAL(MID$(A$,C,1 *2+(X-1)40 NEXTX50 PRIt-iTA$.:"B I NARY";"=".:TL;"DECI to1AL"60"GOTO10 Thisprogramtakesyourbinarynumber,whichwa senteredasa string,andlooksateachcharacterofthestrin g,fromlefttoright(theMID$function). ,inline30, , ,if thefirstcharacterofA$is, thenthevaluewouldalsobe.))

7 ,intheexample,TLwouldfirstequal, times128or'


Related search queries