Issuu on Google+




by StevenVickers andRobinBradbeer

FirstEdition1982 @il 982,by SinclairResearchLimited


by John Harrisof YoungArtists Frontcoverillustration


andsettingitup. Page5 CHAPTER 1 Thecomputer CHAPTER 2 rhe keyboad.Pase8 asa calculator. Page11 lettersandthecomputer CHAPTER 3 Numbers, Page14 CHAPTER 4 somesimplecommands. Pase17 CHAPTER 5 simpleprosramming. recorder. Page21 CHAPTER 6 usingthecassette CHAPTER 7 colours.Pase2b 27 CHAPTER 8 sound.Page CHAPTER 9 Insidethecase.Page29

1. The Computerand setting it up Thisshort booklethas beenwrittenfor two types of people.First,those who know nothing,or next to nothing,about computers,and, secondly,for those who are familiarwith computer based systems but who like to read instructionbooklets beforeplugginganythingin. There is a second,thickerbook which is the BASICprogrammingmanual.This shouldnot be readby the novicecomputeruseruntilthis booklethas been readand understood. Unpackingthe ZX Spectrum,you will havefound: 1 This introductorybookletand the BASICprogramming manual. 2 The computer.This hasthreejack sockets(marked9V DC lN, EARand MIC),one W socket, and an edge connectoron the back where you can plug in extra hasno switches- to turn it on youjust connnectit to the power supply. 3 A powersupply.Thisconvertsmainselectricityintothe forrnthatthe ZX Spectrum uses.lf you want to use your own power supply,it shouldgive 9 volts DC at 1.4 A unregulated. 4 An aerialleadabout2 metreslong,which connectsthe computerto a television. 5 A pair of leadsabout 75 cms long with 3.5 mm jack plugs at each end. These connectthe computerto a cassetterecorder. You will also needa television- the ZX Spectrumcanwork withoutone, but you won't be ableto see what it is doing! lt must be a UHFtelevision(in the UK); if it is not built to receiveBBC2then it is no good.As its nameimplies,the ZX Spectrum gives a colour signalwhich, if you have a colourtelevision,will producea colour picture.lf you only havea blackand white television, then the colourwill appearas black,white and six differentshadesof grey; but apartfrom that,a blackand white televisionwill work just as well as a colourtelevision. The comoonentsof the svstemshouldnow be interconnected thus:







ffigffiE6EETE TTE[XI @Eil|

F i g u r e1 lf your televisionhastwo aerialsockets,markedUHFand VHF,then use the UHF one (UK). Turn the oower on and switch on the television.You now need to tune the televisionin. The ZX Spectrumoperatesoh channel36 UHF(UK),andwhen it is first pluggedin and properlytuned it givesa picturelikethis:

@)1932 SinclairResearchLtd Figure2 When using the computer,you will turn the volume on the televisionrightdown. variabletuningcontrol,then you just haveto lf vour televisionhas a continuously 6

Chaoter1 adjustit until you get the pictureshown in figure2. Many televisionsnow havean push buttonfor eachstation.Choosean unusedone and tune it in. individual Foruse in countriesthat havea differentTV svstemto that in the UK a versionof The UK usesa UHF designedfor that systemis necessary. the ZXSpectrumspecially systemwith 625 lines and 50 frames per also uses a colourencoding systemcalledPAL. Most countriesin WesternEurope(exceptFrance)usea similar system, and the computer should operate in these countries without any The USA, Canada,and Japan,for example,use a totallydifferentTV modification. systemand a differentversionof the computeris required. storedin it is lost.Oneway Whenyou turn the ZX Spectrumoff, allthe information of keepingit for lateris by recordingit on a cassettetape.Youcan alsobuytapesthat The leadwith two jack plugs otherpeoplehavepreparedand so run their programs. at each end is used to connect a standardcassetterecorderto the ZX Spectrum' Chapter8 of this bookletexplainsthis further. Now that you have set up the computer,you will want to use it. The rest of this you will probablyalreadyhave booklettellsyou how to do that; but in yourimpatience started pressing the keys on the keyboard,and discoveredthat this removesthe copyrightmessage.Thisis good;you cannot harm the computer in this way. Be bold. Experiment.lf you get stuck, remember that you can always reset the computerto the originalpicturewith the copyrightmessageby takingout the'9V DC lN' plugand puttingit backagain.Thisshouldbe the lastresortbecauseyou loseall the informatlonin the computer. WARNING. Do not try to use the ZX 16K RAM with the ZX will not WOTK.

2. The Keyboard The keyboardof the Spectrumis veiy similarto a standardtypewriter.The letterand numberkeys are in the same place;howevereachkey can performmore than one function.On a normaltypewriterthe lettersappearin lowercase,and when usedin conjunctionwith the shift key, appear as upper case (capitals).The Spectrum keyboardis just the same. To help you know what modethe keyboardis in, a reversedout (whiteon black) thatappears the positionof the nextcharacter letterappearson the screen,indicating character it from any to distinguish pressed. is flashing letter The when a key is cursor. the lt is called on the screen. alreadv When first switchedon the Spectrumshows a copyrightmessageon the Screen. Pressingany key bringsup the word printedbelowthe letteron the key,(thisis called the keyword).This is becausethe computeris expectinga commandfrom youto tell it what to do and all commandsmust begin with a keyword.Unlikemost other computers the Spectrum allows you to enter keywords with only one key depression. For example,if the P key is pressedimmediatelyafter turningon, the keyword PRINTappearson the screen.The " symbolis markedon the P key as well.To get it, Vou must press two keys at once; hold down the SYMBOL SHIFT key, which is cornerof the keyboard,and while still doingthat,press nearthe bottom right-hand kev. the P

F i g u r e3 The cursornow changesto anfl, as a letteris now expectedby the computer.Type in the letters"Hello". lf thereis alreadysome othertext,for example,on the screen turnthe computeroff (removethe 9V plug)and startagain.Use the CAPSSHIFTkey to get the uppercaseH. In general,anythingcolouredwhite abovethe key requires QAPSSHIFT to access,and anythingcolouredred on the key requiresSYMBOLS SHIFT. with PRINTtellsthe computerto write the lettersenclosed A commandbeginning

2 Chaoter in the doublequotationmarksontothe screen.Forthis commandto be executedbv the computer,the ENTERkey must be used.When this has been done the screen shoulddisplaythe word Hello and some other characters.(A flashing question mark indicates a mistake somewhere.lf this happensstartagainand repeatthe exercise). The messageat ihe bottom is reallythe computerreportingback that everythinghas gone 'OK'. The messageis importantwhen runningprogramsbut can be ignoredat the moment. Noticesomethingelse:TheletterO andthe numeral0 are represented by different characters. lt is importantto rememberthis.The numeral,0 alwayshasa linethrough it. The computer will always interpretthe letter O as a letter, so don't press the wrong key. Similarly,the numeral1 and the lower case letter L are different,and unlikesome typewriters,thesecannotbe interchanged. As the keyboardmodeis so importantto understand it is usefulto summarisewhat happensonce again. Theflashingcharacter[l is calledthe showswhereaboutson the screen the computerwill put the nextthingthat you type. lt is not alwaysan ll if you turn the computeroff and on andthen pressENTER,the copyrightmessagewill change intoa IK cursor.The letterthat it usestells you how the computerwill interpretthe nextthingthat you type.At the beginningof a line,it will be a flashingI3 standingfor 'keyword'.(The copyrightmessageand reportsalso count as a flashingIK). A keywordis one of the computer'sspecialwords, occurringat the beginningof a commandto givethe computera generalideaof whatthe commandis goingto tellit to do.Sincethe computeris expectinga keywordat the beginningof a line,when you press- say - the P key, the computerdecidesnot to interpretthis as a P, but as PRINT;and it warnsyou that it is goingto do this by makingthe cursora Il. When it hasthe first keyword,it doesn'texpectanotherone,so what you type now will be interpreted as letters.To show this,the computerchangesthe cursorto an Il - for 'letter'. Thesedifferent states are often calledmodes- we shalltalk about kevword (or K) mode,and letter (or L) mode. lf you want to type a lot of capitalletterswithout holdingCAPS SHIFTdown, you can makeall letterscome out as capitalsby first pressingCAPS LOCK(CAPSSHIFT with 2).To show this is happening, the Il cursorwill be replacedby a flashing!l (for 'capitals'). get To lower case lettersand the I cursorback, press GApS LOCKa secondtime. (lf you pressCAPS LOCKduringkeywordmode,you will not immediatelynotice any difference,but you will see the effect after enteringthe keywordwhen the computerwill be in C mode insteadof L mode). As well as keywords,letters,numbersand variousprogrammingand scientific expressions, the keyboardalso has eight graphicscharacters. Theseappearon the numberkeys1 to 8, andcanbe printedonto the screenin a similarwav to lettersand numbers.To do this the keyboardmust be changedto graphicsmode.This is done by

2 Chapter pressingthe CAPSSHIFTkeywith the 9. Noticethe cursorchangeto a Gl, Pressing the 9 key will changebackto L mode. There is one last mode that the keyboardcan be changedto. The extendedmode, indicatedby an fl cursor,is obtainedby pressingCAPSSHIFTand SYMBOLSHIFT functionsto be at the sametime. Thisallowsmostof the scientificandprogramming used.Pressingthe two SHIFTkeysagainwill revertthe keyboardbackto letter,L, mode. wrong keysget pressed. typist,or programmer, Evenif you arethe most proficient Sofar the onlyway to overcomethis hasbeento pullthe plugout! Althoughthis may be convenientif only one commandhas been givento the computer,it is certainly very inconvenientif a lot of informationhas alreadybeenentered. Luckilywe can use the DELETEkeyto changeerrors.Forexample,not much can go wrong with the simplecommand: PRINT"Hello" ...orcanit? Let's assume that you didn't use the SYMBOL SHIFTkey to get the opening quotes.The screenwould show PRINT PHello" The computerwould not haverecognisedwhat came after PRINTas no quotes indicatesto the ZX Spectrumthat a number is expected- and it found a letter shows its confusionby flashinga I at the end of the line. you don't haveto type it all out again.on the top row of the keyboard Fortunately are four arrows pointingin differentdirectionsand the word DELETE.To operate these keys, you have to use the CAPS SHIFT key when you press them' The sidewaysarrows move the cursorto the left or the right,and the DELETEkey rubs out the characterimmediatelybeforethe cursor. To correctyour nonsenseline,pressf (CAPSSHIFTand5 at the sametime)until the cursoris just afterthe P thatyou put in by mistake- if you holdthem down for a emittinga quiet clicking secondor two, then they will startworkingcontinuously, aboutthreesecondsit you your for more than any key finger on keep fact, if In sound. automaticallyrepeatsitself.Keyin DELETE(CAPSSHIFTand 0) to deletethe wrong p, andthen type " (SYMBOLSHIFTand P) to insertwhat shouldhavebeentherenotethat it is insertedwithoutoverwritinganythingelse.Try the cursorrightkey as well,just to get the hangof it. lf you madeanygenuinetypingmistakes,correctthem mistakes;you haveto delete thatyou can'toveruurite in the Sameway, remembering them and then insertthe corrections. Now,when you pressENTER,the computerwill write yourmessageat the top of the one it did the first time, if that is stillthere. the screen- or underneath A full descriptionof the keyboardcan be found in chapter 1 of the BASIC programmingmanual. 10

3. Numbers,letters and the computer as a calculator We havealreadyseen how to tell the computerto printlettersand graphicson the screenusing PRINT.We have also seen that ENTERhas to be used to tell the computerto executethe commandjust typed in. From now on, we will not use ENTERin the manualeachtime a commandis used,but assumethat you will key it at the end of the lineautomatically. Numberscanbe handledby the computermoreeasilythan letters.In the previous chapterwe hintedat this by explaining that the computerexpectsa numberafter PRINTif quotationsmarksare not used. So if we key PRINT 2 the number2 will appearon the screen. It is possibleto mix lettersand numbers: PRINT2,"ABC" Noticethat there is a gap on the screen between the 2 and ABG. Now key PRTNT2f'ABC" and then PRINT2 "ABC" Usinga comma betweenthe items after PRINTspacesthem out by 76 columns, usinga semi-colonleavesno spacesand usingnothinggives an error. PRINTcan alsobe usedwith the mathematical functionson the keyboard.In fact the ZX Spectrumcan be usedas an electroniccalculator. Forexample: PRINT 2+2 The answerappearsat the top of the screen.Comparethis with:


3 Chapter It is possibleto combinethese to give somethingmore useful.Try PRINT "21'2:";212 Trv some other kindsof arithmeticas well: PRINT3-2 PRINT 'U5 PRINT12*2 signinsteadof X to avoidgettingit confusedwith the The * is usedas a multiplication letterx; and / is usedfor the divisionsign +. lf you like you can use negative Exoerimentwith lots of differentcalculations. numbersor numberswith decimalpointsin. lf you do enoughto use up the 22 linesof the top partof the screen,thenyou will it will allmoveup one lineandthe top happening; noticesomethingratherinteresting line will be lost. This is calledscrolling. Calculationsare not always performedin the order you might expect.As an example,try PRINT2+3*5 You might expectthis to take 2, add 3, giving5, and then multiplyby 5, giving25; - anddivisionsas well - are performed howeverthis is not the case.Multiplications b e f o r ea d d i t i o n sa n d s u b t r a c t i o n s ,o t h e e x p r e s s i o n ' 2 + 3 * 5 ' m e a n s ' t a k 3e a n d 'l multiplyit by 5, giving 5; andthenaddthat to 2, giving17'. 17 shouldbe the answer displayedon the screen. and divisionsare donefirst,we say that they havehigher Becausemulitplications and prioritythan additionand subtraction.Relativeto each other, multiplication and divisions divisionhave the same priority,which meansthat the multiplications are done in orderfrom left to right.When they are dealtwith, we are left with the - theseagainhavethe samepriorityas eachother,so we additionsand subtractions do them in orderfrom left to right. Let us see how the computerwould work out.

PR|NT20-2*9+412*3 i 2A-2*9+412*3 i i 2A18+412*3 iii 2A-18+2*3

and Firstwe do the multiplications divisionsin orderfrom left to right

2A18+6 2+6 vi I

and then the additionsand subtractions


3 Chaoter Althoughall you reallyneedto know is whetherone operationhas a higheror lower prioritythan another,the computerdoesthis by havinga numberbetween1 and 16 to representthe priorityof eachoperation:* and/ havepriority8, and * and - have priority6. This order of calculationis absolutelyrigid,but you can circumventit by using brackets;anythingin bracketsis evaluatedfirstandthen treatedas a singlenumber, so that PRINT3*2+2 givesthe answer6+2=8 but PRTNT3*(2+21 g i v e st h e a n s w e r3 * 4 : 1 2 It is sometimes useful to give the computerexpressionssuch as this because whenever the computer is expectinga number from you, you can give it an expressioninsteadand it will work out the answer.Theexceptionsto this ruleare so few that they will be statedexplicitlyin everycase. Youcan write numberswith decimalpoints(usethe fullstop),andyou canalsouse scientificnotation- as is quite common on pocket calculators.In this, after an ordinarynumber (with or without a decimalpoint),you write an exponentpart consistingof the lettere, then maybe -, and,then a nurnber.The exponentpart shifts the decimalpoint alongto the right (or left, for a negativeexponent),thus m u l t i p l y i n(go r d i v i d i n gt )h e o r i g i n anl u m b e rb y 1 0 a f e w t i m e s . F o ri n s t a n c e , 2.34e4:2.34 2.34e3=2344 234e-2=4.4234 and so on (Tryprintingtheseout on the computer.) Thisis oneof the few caseswhereyou can't replacea numberby an expression:for instance,you cannotwrite ( 1. 3 4 +1 ) e ( 6 / 2 ) . You can alsohaveexpressions whose valuesare not numbers,but stringsof letters. You have seen the simplestform of this many times,the string of letterswritten down with doublequotesaroundit. This is ratheranalogousto the simplestform of numericexpression, whichis just a numberwrittendown on its own.What you have not yet seen is the useof * with strings(butnot -, * or l, so there is no problemwith prioritieshere).Addingstringstogetherjust joinsthem togetherone afterthe other: so trv PR|NT "jers"*"ey cow" You can add togetheras manystringsas you likein a singleexpression, and if you want, Vou can even use brackets. 13

4. Some simplecommands The computer memorycan be usedto storeall sortsof things.We haveseen,so far, that the PRINT commandallows us to show letters,numbersand the resultsof usingboth lettersand numbers,on the screen. calculations lf we want to tell the computerto remembera number,or a stringof letters,then we have to allocatesome of the memoryfor that use. 'memory' which is used for Most pocket calculators have a key called rememberingnumbersfor later.Yourcomputercando much betterthanthat: it can boxesin it as you like,andyou write a nameon each haveas manyof theseimaginary one. As an example,supposeyou want to rememberyour agel The LET commandis used (LET is the keywordon the L key): let's say it is 34 LET age=34 What happenswhen the LET commandis used,is that a certainsectionof memoryis 'age' out andthe number34 is storedin it. To get this storedinformation designated type PRINTage and back comes the number34. lt is very easyto changethe contentsof the 'age'. Type: called


LET age:56 then type: PRINT age 'age' is an exampleof a variableso called and 56 should appearon the screen. becauseits is possibleto combineprintinga messagedirectto the screen,and the value of a variable.Type PRINT "Your age is

" i age

Howeverthe computeris a lot more usefulthan just rememberingnumberswith names attached to them. lt can also rememberstrings of letters. To differentiate between number variablesand string variables- as they are called- the dollar symbol- $ - is usedat the end of the variablename. For example: if we wanted to save the string of letters

"Your age is" 14


we couldcall it

a$ (stringvariablenamescanonlyhavea singleletter,otherthanthe$, in them).Sotype LETa$:"Your age is " lf younow key PRINTa$ backcomes the stringof letterson the screen. lf the computer hasn't been turned off sincethe start of this chaptertype PRINTag;age and see what happens. Thereare other ways of getting informationinto the computer's memory without usingthe LET command. For examplethe INPUT command,in its simplestform, tells the computerthat some information is expected from the keyboard.Instead of typing LET etc. everytime,you can key INPUT age Once the ENTER key has been presseda flashingE cursor will appearon the screen.This meansthat the computerwants some informationfrom you. So type your age and then pressthe ENTERkey. Althoughnothingseems to have happened the variablehas now beengiventhe valueyou typed in. Typing PRINT age shouldorove this. Let'scombineall this togetherinto a seriesof commands. Type LET b$:"What is your age?" o LET a$:"Your age is INPUT (b$);age: PRINT a$;age Note that the last line consistsof two commandsseparatedby a colon. t5


tNpUT(b$);age is anotherway of entering INPUT"Whatis your age?";age





q $

5. Simpleprogramming Up to now we havebeentellingthe computerwhat to do,directlyfrom the keyboard. are Althoughit is possibleto combinecommandstogether,only limitedapplications f e a s i b l eu s i n gt h i s m e t h o d . The greatthing aboutcomputersis that they are programmable. Thismeansthat to make them do things in a sequence. we can give them a seriesof instructions Everycomputerhas its own languagewhich allows us to communicatewith it. them easily. areverysimple- so thatthe computercanunderstand Somelanguages that are simplefor the computerto understandare difficult languages Unfortunately simpleenoughfor us for humans.In some ways the reverseis alsotrue- languages to understandare relativelvdifficultfor the comouter- and even have to be translatedor interpreted. The ZX Spectrumusesa high levellanguagecalledBASIC. BASIC stands for BeginnersAll-purposeSymbolic InstructionCode and the languagewas designedat Dartmouthcollegein New Hampshire,USA,in is very widely used on personalcomputers,but althoughit is broadlysimilaron all of for Thatis why this manualis written specifically them, there are subtledifferences. the ZX Spectrum.But ZX SpectrumBASICis not too far from a (non-existent) consensusBASICand so you shouldnot havetoo muchtroubleadaptingany BASIC programto work on the ZX Spectrum.UnlikeotherBASICsZX SpectrumBASICdoes not allow the command LET to be omitted when valuesare being assignedto variables. can be storedin the computer.The ZX Thereis a limit to how many instructions Spectrumindicatesthis limit by emittinga buzz. in BASICit is necessary to let the computerknowthe orderin When programming which the instructionsare to be executed.Hence each line of the sequenceof i n s t r u c t i o nhsa sa n u m b e ra t i t s b e g i n n i n gl t. i s n o r m atl o s t a r ta t 1 0 a n dt o i n c r e a s e this by 10 for eachnew line.Thisallowsother linesto be insertedif they havebeen omitted,or the programto be modified. Let'slookat a simpleprogram.Considerthe seriesof commandsat the end of the to lf we wantedto repeatthe seriesof commandsit wouldbe necessary lastcha'pter. enterthem eachtime. A programovercomesthat necessity Type in the followingwith ENTERaftereachline. 10 LET b$:"What is your age? " 20 LET a$:"Your age is " 30 INPUT (b$);age 40 PRINTa$;age Note that it is not necessaryto enterany spaces,exceptinsidequotes. Nothingwill actuallyhappenuntil we tell the computerto start working on the program.That is done by usingRUN (the keywordon R). E n t e rt h i s c o m m a n da n d s e e w h a t h a p p e n s . 11

Chapter 5

What is your age?ll Figure4 You may also have noticeda right facingarrow when each line has been entered. This indicatesthe last line entered.lf you want to see the programagainkey ENTER again,(or LIST).You can use RUN to executethe programas manytimes as you like. When you no longer need this program,you can remove it by using the NEW 'clean command.This wipes out the programstoredin memory,and givesyou a slate' ready to put in a new one. Key NEW, then LIST and see what happens.

@)1982 Sinclair ResearchLtd Figure5 To recap: When you type in a commandprecededby a number,then this tellsthe computer that it is not simplya command,but a programline.The computerdoes not execute it, but stores it away for later. 18

Chapter5 The ZX Spectrumhelpfullywrites on the screen(or lists)all the programlinesthat you have enteredwith a Iagainst the lastlinethat you entered. but just storesthem The computerwill not executeany of theselinesimmediately, away insideitself. To get the computerto executethese lines,you must use the commandRUN. lf you press ENTERon its own you will get the listingback. Let's consideranothersimpleprogram.Thisone will be a bit more mathematical and print out the squaresof all the numbersbetween 1 and 10 (the squareof a numberis just that numbermultipliedby itself). anotherconceptin programmingin To generatenumbersfrom 1 to 10 introduces BASIC.This is the methodby which we get the computerto count.Earlierwe have 'name' to seenthat numberscan be storedin the computer'smemoryby attachinga with the a value to variable. Let variable x start them or technically, assigning a the value1 and increasein stepsof 1 to 10.Thisis doneby usingthe commandFOR. . . TO. . . STEP. So to enter this program key NEW to get rid of the previousone and type the following: 10 FORx=l TO 10 STEP1 (Normallythe STEP1 part can be omittedif countingis going up in steps of one). The next linemust now tell the computerwhat to do with x at whatevervalueit is, so kev: 20 PRINTx, x*x Finallywe needa lineto tell the computerto go to the next valueof x, therefore Key 30 NEXT x On reachingthis instructionthe computergoes back to line 10 and repeatsthe sequence.Whenx exceeds10 the computergoesto the next linein the programi.e. l i n e4 0 . The programshouldnow appearon the screenas follows: 10 FORx=l TO 10 STEP1 20 PRINTx, x*x 30 NEXT x For completenesswe shouldreallyhaveanotherline tellingthe computerthat the programhas endedwhen x:10 so key

40sroP 10

Chapter 5 lf the programis now RUN two columnsshouldappear,the firstwith valuesof x, the secondwith valuesof x*x, or x is possibleto labelthese columnsby a d d i n ga n o t h e rl i n e ,l i k et h i s 5 PRINT"x","xxx" Noticethat althoughthis has beenenteredafterallthe otherlines,becauseit hasa puts it in the correctplace. lower line numberthe computerautomatically programs functions.lf you have any doubt using other mathematical Try writing pagesin the BASICprogramming about how to use them refer to the appropriate manual.


6. Using the cassetterecorder It is rathertedioushavingto type programsin to the computereachtime you want to use it. The ZX Spectrumhas the facilityfor recordingprogramsonto magnetictapes with a normal,domesticcassetterecorder.lf you havea programin the memorytry to save it usingthe followingprocedure. lf you can saveprogramson cassettetapeyou can loadthem backagainlater. the cheap will work: as far as the computeris concerned, Most cassetterecorders portablemonocassetterecordersareat leastas goodas expensivestereoones,and give less troubleas well. You will find a tape countervery useful. andan The cassetterecordermust havean inputsocketfor use with microphones (if loudspeaker the external not try there is one, use with earphones for socket output socket).They shouldbe 3.5 mm jack sockets( fit the jack plugson the leads provided),becauseother sorts often do not give a signalpowerfulenoughfor the computer. Any cassettetape shouldwork althoughlow noisetapes may be better. Having acquireda suitablecassetterecorder,connectit to the cornputerusingthe leads suppliedwith the ZX Spectrum:one lead shouldconnect the microphoneinput 'MlC' on the back of the computerand socketon the recorderto the socketmarked 'EAR' on the recorderto the socket the earphone connect Output should other the socket.(Youcannotharmthe ZX Spectrumby connectingthe cablesincorrectly). When you are usingthe SAVE commandto storea programonto tape,you must 'EAR' socketson the make sure that one of the plugs of the leadconnectingthe computerandcassetterecorderis pulledout - eitherof them will do. lf you forgetto do this you will get nothingmorethana steadynoterecordedonto the tape,which is recordingit useless.The reasonfor this is th-atwhen the cassette recorderis'EAR' 'MlC' puts socket. the it out on and its socket, in on amplifiesthe signalcoming smothering lf this gets backintothe computerit will form a loop,whichwill oscillate, the signalyou were tryingto record. Type some programinto the computer,saythe squaresprogramin the previous chapter,and then tYPe. SAVE "Squares" Squaresis just a namethat you useto labelthe programwhile it is on tape.You are allowed up to ten charactersin the name which must consist of iust lettersand numbers. The computerwill havecome up with a messageStart tape then press any key. We shallfirstgo througha dry runso thatyou canseewhat happens:do not startthe cassette recorder,but press a key on the ZX Spectrumand watch the borderof the stripes. TV screen.You will see patternsof colouredhorizontal 5 secondsof red and pale blue stripes,about 1 cm wide and moving slowly upwaros. A very shortburstof blue and yellowstripes. 1 secondwith everythingas normal. 21

6 Chaoter 2 secondsof the red and paleblue patternagain, about 1 secondof the blue and yellowpatternagain. Try it againuntilyou can recognise allthese.The information is savedaway in two to the redand palebluepattern, blocksand bothblockshavea lead-incorresponding to the blue and yellow pattern.The first and the informationitself, corresponding the nameand variousotherbits of information blockis a preliminary one containing aboutthe program,and the secondis the programitselftogetherwith any variables present.The white sectionbetweenthem is just a gap. Now let's actuallycapturethat signalon cassettetape. 1. Positionthe tapein a parteilherthatis blank,or thatyouareprepared to overuurite. 2. Type SAVE "Squares" (andENTER) 3. Start the cassetterecorderrecording. 4. Pressany key on the ZX Spectrum. 5. Watch the televisionas before.When the computerhas finished(with the report 0 OK) stop the cassetterecorder. To make surethat this hasworked,you can checkthe signalon the tape againstthe programin the computerusingthe VERIFYcommand. 1. Turn the volumecontrolon the cassetterecorderto approximately half way and 'EAR' lead. reconnectthe 2. Rewindthe cassetteto somewherebeforewhere you startedto recordpreviously. 3. Type VERIFY"Squares" (VERIFYis extendedmode, then shiftedR). 4. Startthe cassetterecorderplaying. The televisionborderwill alternatebetween red and paleblue untilthe tape reaches the recordingyou made; then you will see the same patternas you did when you savedthe program.In the one secondgap in the middle,ProgramSquares will be for somethingon tape, it written on the screen- when the computeris Searching printsup the nameof everythingit comesacross.lf you see allthis patternand then the computerstopswith report0 OK yourprogramis safelyrecordedon tape and you 22

6 Chapter Otheru'rise, somethinghas gone wrong Go can skip the next few paragraphs. throughthese questionsto find out what.

Making sure your program is saved H a st h e n a m ec o m e u p 7 lf not then eitherthe programwas not savedproperlyin the first place,or it was, but was not readbackproperly.You needto find out which.To see if it was saved properly, rewind the tape to iust before where you started (you recording,and playit backthroughthe tape recorder'sown loudspeaker will probablyhaveto unplugthe leadfrom the earphonesocket on the tape The red and paleblue lead-ingivesa very clear,steadyhighpitched recorder). note, and the blue and yellow informationpart gives a much less pleasant Bothof thesearequiteloudsound,likea morsecodemessagein a hurricane. at full volumethev can easilydrown conversation. lf you do not hearthese noisesthenthe programprobablydid not get saved. Checkthat the rightleadsare pluggedin the rightsockets.Make surethat the 'EAR' 'MlC' socketsare not. lt happens socketsare connected,and that the with some tape recordersthat the jack plug does not make contactif it is pushedrightin. Try pullingit out abouta tenthof an inch-you can sometimes feel it settlingdown into a morenaturalposition.Alsocheckthat you were not tryingto recordon the plasticleaderat the beginningof the cassette.When you havecheckedthese,try savingagain. then SAVEwas probablyall right lf vou can hearthese soundsas described and your problemis with readingback. Checkthe leadsagain,and alsocheckthe volumelevel.lf it is too quietthe computerwill not hear the signalproperly,and you will not see the right patternson the screen;if it is too loudthe signalwill get distorted- you may be There is a able'to hear it comingthroughthe computer'sown loudspeaker. valuesin between,but you couldtry experimenting. wide rangeof acceptable The next caseis when the computerfindsthe programand writes its name are: up but stillgoes wrong. Some possibilities You mistypedthe name,eitherin SAVE (whenthe computerwill write the mistyped name on the screen)or VERIFY:the computerwill ignore the programand carryon flashingred and paleblue as it goes. Thereis a genuinemistakeon the tape: the computerwill come backwith R Tape loading error, which meansin this case that it failedto verify the program.Saveit again. It is just possiblethat the volumesettingon the tape recorderis not quite right; but it cannotbe far wrong becausethe computerrnanagedto readthe first block. na

Chaoter 6 Now let us supposethat you havesavedthe programand successfully verifiedit. Loadingit backis just likeverifyingit exceptthat you type LOAD "Squares" insteadof VERIFY"Squares" you shouldhaveno problemloading. LOAD is on the J key.Sinceit verifiedproperly, LOAD deletesthe old program(andvariables) in the computerbeforeloadingin the new one from taoe. Once a programhas been loaded,the commandRUN will run it. programson cassette.They must be specially It is possibleto buy pre-recorded written for the ZX Spectrum:differenttypes of computerhavedifferentways of recordingprograms,so they cannotuse eachother'stapes. lf your tape has morethanone programrecordedon the sameside,then eachwill have a name. You can choosewhich programto loadin the LOAD command:for instance,if the one you want is called'helicopter'you couldtype LOAD "helicopter" (LOAD"" meansLOADthe first programyou comeacrosswhichcan be very useful if you cannotrememberthe nameof your program.)


7. Colours One of the reasonsfor buyingthe ZX Spectrumin the first placewas the abilityto use colouron the TV screen.The screenis dividedinto two areas.The outer part is referredto as BORDER,the centralarea as is possibleto changethe colours of these two sectionsat will, both directlyfrom the keyboardand in a program. The zx Spectrumhas eight coloursto play with, and these are given numbers between A and 7 . Althoughthe colourslook in randomorder,they do in fact give decreasingshadesof greyon a monochromeTV. Here is a list of them for reference,they are also written over the appropriate n u m b e rk e y s : 0 1 2 3 4 5 6 7

black blue red purple,or magenta green paleblue,or cYan vellow white

When the computeris firstswitchedon the systemworks in blackandwhite. So the normalvaluefor BORDERand PAPERis 7 i.e.,white. The colourof any character o n t h e s c r e e ni s d e f i n e db y t h e I N K c o m m a n dT. h i s i s n o r m a l l y0 , i . e . , appearing b l a c k .I n i t i a l l yt h e t h r e e c o m m a n d sc o n t r o l l i ntgh e s c r e e nc o l o u r sa r e s e t b y t h e computer. However,you can changethese values.For examplekey BORDER2 lf you rememberedto pressthe ENTERkey, the bordershouldnow changefrom white to red.Thisincludesthe areaat the bottomwherecommandsand instructlons a r e t y p e di n . T r y t y p i n gi n o t h e rn u m b e r sa n d s e e h o w t h e c o l o u r sc h a n g e . Now try changingthe centreof the screenareaby keying PAPER5 The PAPERcommandis one of the extendedmodecommandsas mentionedearlier. It is obtainedby typingboth GAPSSHIFTand SYMBOLSSHIFTat the same time. PAPERis then a shiftedG. When the ENTERkey is pressedtwice the centreof the screenshouldchangeto pale blue.The first ENTERcancelsthe PAPERcommand alreadystoredin the computer,but onlywhen the secondENTERis pressed(causing does the computerto LISTanyprogramandthereforerebuildthe screeninformation) it hasn't and you television, get using a colour are used. lf the new PAPERcolour 25

7 Chapter changedcolour,try adjustingthe colourcontrolson the television,and maybethe tuning control. The INK commandis similarto the PAPERcommandandcontrolsthe colourof the charactersappearingon the PAPERsectionof the screen.Obviouslyif the INK and PAPERcoloursare the same nothingwill appearon the screenl The BORDER,PAPERand INK commandscan be used in programs.Here is a simpleone to show the ranoeof coloursavailable:

10 FOR r"O, ":r x 20 BORDER 30 PAPER7-x: GLS 40 PAUSE50 50 NEXTx Thisprogram,whenRUN,goesthroughthe eightcolours, contrasting the PAPER The CLS commandafterPAPERforcesthe computerto and BORDERcolours. rebuildthe screenimageandusethe new PAPERcolour.ThePAUSEcommand (Tryrunning for 1 second sothatwe canseewhat'shappening the stopsthe program program withthePAUSEleftout.)ToshowhowtheINKcommand workstypeinthe followingprogram, aftera NEWcommand. 10 BORDER 7 20 PAPER1 30 INK4 40 PRINT"Greencharacterson blue background" with the colourcapabilities Thereare other commandsassociated of the ZX in the BASICprogramming manual. Spectrum, andthesearedetailed


8. Sound The ZX Spectrumcan makesoundsof an infinitevariety.The frequencyof the note and its durationare underthe controlof the user.The commandBEEPis usedto tell the computerto makea sound.BEEPis an extendedmodecommandand is obtained usingthe Z key. 'centre' frequencyfor the BEEPcommandis middle C. This can be varled The within the BEEPcommand,and any note can be obtainedif it is expressedas semitonesor parts of semitonesabove or below this centre frequency.lf the command BEEP 2,0 is enteredthe computershouldemit a soundat middleC pitch for two seconds. The two numbersbetween them controlthe sort of note that is emitted, the first givingthe lengthof the note in seconds,and the secondthe pitch of the note in iemiiones abovemiddleC. Thusthe pitchcodefor middleC is 0, that for C# is 1, for D it is 2, and so on up to the next C abovewhich is 12,because12 semitonesmake one octave.You can carryon to 13 and beyond,if you want, so that the higherthe number,the higherthe Pitch. Trv this: BEEP1,4: BEEP1,2: BEEP2,0 Youshouldhearno lessthanthe first barof ThreeBlindMice. Sinceyou canjoinquite a few BEEPstogetherwith colons like this, you could,if you had the patience, producea whole tune.You might liketo try usingmore notes than iust three. (Colonsdon't just join BEEPstogether;you can use lhem to build composite commandsout of any of the elementarycommands.) example,you canmakea singingchameleoncommandby As a more complicated mixingBEEPand BORDERtogether: BORDER'1:BEEP1,14: BORDER3: BEEP1,16: BORDER4: BEEP 1,12: BORDER6: BEEP1,0: BORDER5: BEEP4,7: BORDER1 (Don'tworry aboutthe fact that this stretchesover from one line to the next: the computerdoesn'ttake any noticeof this.) A short programto play a whole seriesof notes could be as follows: 1 0 F O Rx = O T O 2 4 20 BEEP 2, X 30 NEXT x Thereare a lot more thingsthat can be donewith this command- see the BASIC zt

Chapter 8 programmingmanualfor other ideas. For notes lowerthan middleC the numberof semitonesis indicatedby a negative numoer.


9. What's lnsidethe Gase? The picturehere showswhat the insideof the ZX Spectrumlookslike. UHF or VHF modulator (Transmits picture)

ULA (Grandexecutive)

PALencoder (Colourmixer)

Backof computer


RAM (Notepad)


10 Figure LoudsPeaker As you can see everythingis named by a three letter abbreviation.The black rectangularpiecesof plasticwith lots of metallegs are the integratedcircuitsthat actuallydo allthe work. Insideeachone is a ]"x|" squareof siliconloinedby wires to the metal legs.On that siliconchip are thousandsof transistorsthat make up the electroniccircuitsthat are the computer. chip,often calledthe CPU(Central The brainsbehindthe operationis the processor one is calledaZBAA,which is a fasterversionof the ProcessorUnit).Thisparticular popular280. The processorcontrolsthe computer,doesthe arithmetic,looksat what keyshave been pressed,decideswhat to do as a result,and in generaldecideswhat the it couldnot do allthis on its own. computershoulddo. However,for all its cleverness, It knows nothingaboutBASICor decimalpointarithmetic,for example,and it hasto 29

Chaoter 9 get all its instructionsfrom anotherchip,the ROM (ReadOnly Memory).The ROM contains a long list of instructionsthat make a computer program,telling the processorwhat to do underall foreseeable This programis written circumstances. not in BASIC,but in what is calledZSAmachinecode,and takesthe form of a long sequenceof numbers.Thereare altogether16384(16*142q of these,which is why ZX SoectrumBASICis sometimescalleda 16K BASIC- lKis 1A24. Althoughthere are similarchips in other computers,this particularsequenceof instructionsis uniqueto the ZX Spectrumand was written speciallyfor it. The eight chips next to it are for the memory.This is RAM (RandomAccess Memory)and therearetwo other chipsthat work closelywith them. RAM is where the processorstores informationthat it wants to keep, any BASICprograms,the variables, the picturefor the televisionscreenandvariousotheritemsthat keeptrack of the state of the comouter. The big chip is the ULA (UncommittedLogicArray)chip. lt reallyacts as the 'communications the processorrequiresactually centre',makingsurethateverything gets done; it also readsthe memoryto see what the televisionpictureconsistsof signalsto the TV interface. and sends the appropriate The PAL encoderis a whole groupof componentsthat convertsthe logicchip's televisionoutput into a form suitablefor colourtelevisions. The regulatorconvertsthe slightlyerraticvoltageof the power supply to an absolutelyconstantfive volts. This concludesthe Introductory Booklet.lf you feel that you haveunderstoodit well we suggestthat you now try readingthe BASICprogrammingmanual.


Printudby Tlu LeagraacPress Ltd LutonandLondon



Sinclair ZX Spectrum - Introduction