JOYTemplate for Letters group  d2oIty pXh{I L"ɾz k Z-KiZ-K: N"զI` {x R< N"զI` {x R<L$ЦIz yx UL$ЦIz xx UL$ЦIz x UL$ЦIz ~x UL$ЦIz }x UL$ЦIz |x UL$ЦIz sx UL$ЦIz rx U xScript 1: 0x R< @ ZBASIC.TIP(S)File $AuthorS.W.Keen1988, ^TheElms,KimblewickRd,Gt.Kimble,Aylesbury,Bucks,HP178TDAsausertoZedcorZBasic,IhavewrittenthistipsandhintsfiletoaidPCWusersoftheP.D.versionZBDEMO.COM. Mh0 #`DISCCONTENTSZBDEMO.COMandZBASIC.HLPareZBasicfiles.ZBASIC.HLPisaccessedfrom<ZBDEMOsimplybytypinghelp.Thehelpfilethendisplaysalistofthevarioustopicscovered.ZBASIC.TIPisaLocoScriptdocumentdcontainingvarioustipsandtricksforusingZBDEMO.AccessthisbystartingLocoScript,select"changedisc",insertthisdiscandpressPtoprintitFIND$.ZASisaroutinewhichchecksthediscdirectorytofindaPspecificfile,anddemonstratestheprinciplesofZBasicdiscerrortrapping.ZMODE2.ZASisaprogramwhichdoesanumberofstatisticaltestsondatastoredinanarrayandprintsthetimetakentodothesetestsVALL.ZASisaroutinetocheckfornumbersinstringinputsDATABASE.ZASisarandomaccessfiledemostrationprogram,DATABASE.DATisthedatathattheaboveprogramreadsSEQUENCE.ZASisaroutinetofiletheendoffilemarkerinsequentialaccessfiles,SEQUENCE.DATisthedatafilethattheaboveprogramreads<BRIKBAT.ZASisagame.Usetheleft&rightcursorkeystocatchthexfallingbricks,BRIKBAT.COMistheaboveprogramaftercompilationGRAFIX.ZASisademoofsometherudimentarygraphicsavailableonthedPCWSLIKMENU.ZAShowtodoLocoScriptstylepulldownmenusinZBasicTORUNANYOFTHE.ZASFILESFROMTHEZBASICEDITOR,SELECTEFROMTHEPMENU,ANDTHENENTERLOADFILENAME.ZAS(MUSTBEINCAPITALS)DThelastprogramsarehandyP.D.utilities:D.COMdoesaDIR[SIZE]andSHOWsimultaneouslyUNERA.COMwillunerasefilesiftheyarestillhiddeninthedirectory.SimplysayUNERAprogname.typtorecoverafile xScript 1: 0x R< FIP.COMislikePIP.COMbuthasmenusandcangiveadirectoryoferased<files0CLS.COM&CLS.ASMclearthescreenfromCP/M<PAUSE.COM&PAUSE.ASMwritesReadyonthescreenandwaitsforakeyDpress,handyforpromtingdiscchangesetc. TEXTNOTES meansakeyonthekeyboardPWhendiscussingZBasiccommands,optionalcommandsareshowninsideL[squarebrackets]0X,variable$andvariablearevariablenamesZBasiccommandsareshowninUPPERCASEP xScript 1: 0x R<  0GETTINGSTARTEDdZBDEMO.COMistheP.D.versionofthefullblowninteractiveBASIC<compiler,whileZBASIC.HLPisahelpfilewhichcanbeaccessedfrom<withinZBasic,howeverZBDEMO.COMistheonlyfilerequiredtowriteyourownBASICprograms.ThemajordrawbackoftheP.D.versionisthatitdoesNOTallowyoutoXsavecompiledcodetodiscasa.COMfile.  0TEXTISCOMPILEDINTHEMEMORYONLY.dAsZBasicexistsinvariousformsformanydifferentcomputersandoperatingsystemsyoumustfirstconfiguretheZBdemofiletosuitthePCW(seeCONFIGUREFORPCW).ThisisdonebyrunningZBDEMO,whenthisdhasloadeditprintsamessagestatingthelimitationsoftheP.D.version,andoffersamenu. Mh ZBasicMENUYouentertheprogrammingareabyselectingtheEoption,andthenkeyinyourprogramtextasusual,butnotethattheZBasiceditordoesn't(usethespecialPCWkeyssuchasetc(seeEditorCommands).TORUNANYOFTHE.ZASFILESFROMTHEZBASICEDITOR,SELECTEFROMTHEMENU,ANDTHENENTERLOADFILENAME.ZAS(THECOMMANDANDFILENAMEMUSTBEINCAPITALS)PisthePatchoptionwhichallowscleverpeopletomodifythecontentsofmemoryaddresses.Don'tworryaboutthisbitunlessyouareheavily intoJumpTablesandMemoryMaps.WistheZwarm"warmstart"filecreator.Ihavefoundthisveryuseful,asoverenthusiasticuseofthekeycancrashZBasicanddropyoudthru'toCP/M,meaningthatyourprogramcodeisstranded,andyou<destroyitwhenyourestartZBasic,howeverZwarmstartsZBasicinaslightlydifferentwaysoyoucanrecoveryourprogramtext.CreateZwarmasfollows:AfterConfigure,Savethechangesasdescibedabove,typequittoreturntoCP/MandthenrestartZBasicbytypingzbdemoand8 xScript 1: 0x R< thenselectWfromthemenuandthenSaveitasZWARM.COM.(Then,ifyoucrashoutofZBasic,justtypezwarmtorestart<ZBasic,pressEtoentertheeditorandpressLtoLISTyourprogram<text.TheSoptionallowsyoutosavethechangesmadetoZBDEMOafterusingtheC,PorWoptionsdescribedabove.@ xScript 1: 0x R<  (CONFIGURINGZBasicFORPCWAtthispoint,selectCtoConfigurewhichmeansansweringaseriesofquestionsconcerningyourparticularchoiceformathsaccuracyetc,andthehardwarecodesforcontrollingthescreen.Configureasksthefollowingquestions:<Doubleprecisionmathsthemaximumlengthofdoubleprecisionmaths  h   Xis54butforspeedsetthisto6DSingleprecisionmathsforspeedsetto4HScientificmathsditto(MaxBufferssetto1,becauseZBDEMOwon'tallowyouopen  h   Xmorethan1fileatatime(ArrayBase   XforcompatabilitywithMallardBASICsetto0RoundingNumber  XsetstheroundingfactorforPRINTUSINGDefaultVariableTypeSingle,DoubleorIntegerforspeedchooseIntegerandmarkreal  h   Xnumberswithinyourprogramsusing!(Single)(  h   Xor#(Double)oruseDEFSNGorDEFDBLatthe   h   XstartdTestArrayBounds Xthischecksforarrayoverflow,chooseY<ConverttoUppercaseifyouchooseNthenyouMUSTtypeinBASIC  h  keywordsincapital.TheYoptionwill  h   X"capitalise"alltextthatyoutypeBUTyouared  h   Xnotallowedtoembedkeywordsinvariable<  h   Xnamesi.e.totalisnotallowedbecauseitx  h   XcontainsthekeywordTO.TheYoptionis<  h   Xprobablyeasiertousebutbecarefulwith  h   XvariablenamesDefaultCLEARsizeThisisusedbyaspecialZBasicarray(  h   XcalledINDEX$.ZBDEMOonlyallowsyou2kfor  h   XINDEX$.Suggestyoujustpress x xScript 1: 0x R< ClearScreenStringenter&451B.ThisisthePCWcodeCHR$(27)"E"ClearEndofLineenter&4B1B."""""CHR$(27)"K"ClearEndofPageenter&4A1B."""""CHR$(27)"J"CursorOffenter&661B."""""CHR$(27)"f"CursorOnenter&651B."""""CHR$(27)"e"ListPreviousLineChooseakey,sayuparrowListNextLine""""downarrowList1stLine""""leftarrowListlastLine""""rightarrowFindnextoccurence""""semicolon(Print@stringenter&591B.ThisisthePCWcodeCHR$(27)"Y"OverlayOffsetbecausethisversiondoesn'tsupportl  h   Xusers.OVLfilesThenpressStosavebutenterthefilenameinUPPERCASE. 0EDITORCOMMANDS<UseltoLISTyourprograms,l100liststoline100,l100200listsPlines100to200,l"subroutine"liststhelabelledsubroutine,l+ P xScript 1: 0x R< xlistswithoutusinglinenumbers(usethistoimpressyourPascalfriends!).<Usee10toeditline10.Presstodisplayeachcharacter,numberformultiplemoves.lCtoChangetocharacterunderthecursorPress< DEL>tobackspaceorusenumberformultiplemoves,thethedeletekeyfunctionisswitchedoffunlessyouuseeXtend.\SXtosearchforcharacterX.DdeletethecharacterunderthecursorD5deletethecharacterunderthecursorandthenext4too.HKXkillallcharactersuptoXIinserttextXjumptoendoflineandgointoisertmode.DlinenumberdeletesthatlinenumberlDELorDELETE500deletesthatlinenumberDDELorDELETE100deletesline100onwards\orAtoabortchanges. MhP pRANDOMPROGRAMMINGTIPSZBasicdoesn'taddFILETYPEStoyourprograms,sospecifyyourownwhenPyouSAVE.i.e.use.ZAStodifferentiatebetweenZBasicandMallardprograms.ZBasicdisablesthekey,sowhendevelopingprogramsalwaysstart(yourprogramswithTRONBtoenable,otherwiseyougetwellandDtrulystuckifyougetintoanendlessloop<ToclearthescreenuseCLS,howeverthisdoesn'thomethecursor.Ibelievethatitispossibletohavea4byteclear&homestringbutthisistheonlypartoftheZBasicmanualwhichissomewhatopaque.PToclear&homedoeitherCLS:PRINT@(0,0)orPRINT@(0,0):CLSPAGEor\CLS32ifyoucanwaitalldaydCLSPAGEclearsthescreenfromthecurrentposition,whileCLSLINEPclearsthecurrentlinefromthecurrentposition.CLSASCIInumberfillsthescreenwithcharactersofthatASCIIcode.P xScript 1: 0x R< (ZBasicregardsALLmonitorscreensasbeingthesamesize,andPRINT@and[LINE]INPUT@regard0,0asthetopleftcorner.ThecoordinatesaregivenasHorizontal,Verticaltherefore80,24isthebottomrightcorner.Syntaxerrorsaredisplayedwitha0besidetheoffendingcharacterandthemissingcharacterisprintednexttotheerrormessage.(WhenyoutypeRUNthewholeoftheprogramcodeiscompiledinmemoryandallsyntaxischeckedthen,notaseachlineisexecuted.dZBasichasitsownprogrameditorwhichisnotspecifictothePCW<keyboardsoMallardtrickslinetogettoendofalinewon'twork,useXtoeXtendtheline.ZBasicsupportstheusualFOR..NEXTandWHILE..WENDloopsandalsohaspDO..UNTILloops,forexample(200DOt210a$=INKEY$L220UNTILLEN(a$)isanelegantwayofwaitingforakeytobepressed.However,I(preferredtouseINPUT$inMallardandthisdoesnotexistinZBasic,butyoucandoitwith[LINE]INPUT!&n,a$the!meansdon'twaitforand&nmeansacceptaninputtoamaximumofncharacterslongZBasicusestheusual*,+,,/mathssymbols,MODfindstheremainderofPintegerdivision,[ordoexponentiationandyoucanalsodosomemathsinBinarywhichalittlequicker.Binarymathsuses<<(2lessthansigns)todomultiplicationand>>(2<greaterthansignstododivision).UsingthismethodyoucanfindPIwiththeexpressionpi!=ATN(1)<<2inBinarymathsthe2infactmeans2tothepowerof2.Otherexamples4>>1(4/2indecimal),4<<1(4*2indecimal),904.>>6=14.15625theexpressionindecimalis904/64,notethat904isfollowed(bya"."toforcetheresulttoarealnumber,alsobeawarethatthe(numberfollowingthe<<or>>signsisforcedtointeger.InmyopionBinarymathsisn'tmuchhelpbecauseofthebrainbendingthatyoumustH xScript 1: 0x R< doinordertouseit.However,areallyusefulfeatureallowsyoutohavecomplexIFs,insteadofhavingalinewhichsays01000IFa=54thenz=12:count=1:message$="OK"tYoucandothisL1000LONGIFa=541010z=121020count=1$1030message$="OK"1040ENDIFP xScript 1: 0x R< OryoucanuseIF...THEN...ELSEtypelogicwiththeXELSEclauseL5000LONGIFa=545010z=125020count=1$5030message$="OK"5040XELSE5050message$="NotOK"5060ENDIFpwhichismuchmorereadable.<BecauseZBasicisacompileryoudon'thavetogoformultistatementlinestoincreasespeed,gobacktoyourearlyprogrammingdaysandputastatementperline.ZBasicindentsloopsandLONGIFsforyoutomakethemeasiertoread.dIfyoudohavealoopthatiscompletedon1linethenitputsa*againstthelinenumbersothatyoucanidentifyiteasier.PThelineeditorgenerateslinenumberstomakeiteasierforyoutoalteryourcode,butyoucanuselinelabelsforsubroutinesandifyou<mustuseGOTOthensayGOTO"start"ratherthanGOTO1500,forexample`1000GOSUB"test"1010PRINT"testcompleted". .  h  programcontinues.2000"test":REMstartoftestsubroutine2010a=VAL(a$)2020RETURN\Linelabelsaidreadability!!<Anotherlittlepeculiarityisthatitdoesn'tconvertfilenamesintoxuppercaseorautomaticallyadd.ZASfiletypes,sowhenyouSAVEaprogramtypesavePROGNAME.ZASN.B.speechmarksarenotneeded.<Onthesamethought,makesurethatyourprogramsconverttheirdatafilenamesintouppercasetoofilename$=UCASE$(filename$)SequentialfilesinZBasicareverysimilartoMallardinthatyousayOPEN"O",1,filename$PRINT#1,variable$","variableoruseWRITE#1,variable$;n,variableCLOSE[#1]whichwillwriteafile$OPEN"I",1,filename$INPUT#1,variable$,variableoruseREAD#1,variable$;n,variableCLOSE[#1]P xScript 1: 0x R< whichwillreadafile.PRINT#andINPUT#arewillreadandwriteASCIIfiles,READ#andWRITE#areforfileswherethedatahasbeentokenised.Pnisthelengthofastring,andmustbeusedwhenstringsareused.@RandomaccessfilesarelittledifferentthaninMallard(Forexampleyoudon'thavetoLSETorRSETdataorconvertnumberstostrings/stringstonumbers.ThisconversionisintrinsicinREAD#andWRITE#.OPEN"R",1,filename$[,recordlength]\WRITE#1,variable$;n,variableCLOSE[#1]whichwillwriteafileOPEN"R",1,filename$[,recordlength]pREAD#1,variable$;n,variableCLOSE[#1]whichwillreadafilePYoucanpositionthedatapointertoaparticularplaceinthefile(usingthekeywordRECORD#filenumber,recordnumber[,locationinrecord]i.e.setrecordnumberto1atthestartoftheprogram,searchthru'thefilewithxDO4 recordnumber=recordnumber+1 RECORD#1,recordnumber READ#1,variable$;1UNTILsearch$=variable$pthenoverwriteexistingdataRECORD#1,recordnumberWRITE#1,newvariable$;1xZbasicDIRis"passive"andonlyworksineditmodenotduringrund(anyway,thedisplayis'orrible).ThereisnotaFILESfunction.ZBasicdoesnotsupportJetsamfilingnordoesithaveaFIND$function,PhoweverfeelfreetousemyFIND$.ZASroutineincludedonthisdisc.Ifyouwanttoalterthisroutine,makesurethatyouresetERRORto0PbeforeRETURNingtothemainprogramorthesameerrormessagewillcropupoverandover.<Otherdiscerrorsareasfollows,butnotethatONERRORGOSUB65535(enablesyourownerrortrappingroutinesandONERRORRETURNdisableslthisandreturnserrortrappingtoZBasicP xScript 1: 0x R<  (fERROR < = >MEANING ,z256 < = > ?Noerrorinfile#1d ,z257 < = > ?EndofFile#1 ,p258 < = >DiscFullinfile#1 ,z259 < = > ?File#1notfoundP ,p260 < = >File#1notopen ,z261 < = > ?File#1badfilename ,z262 < = > ?File#1badfileNo( ,z263 < = > ?File#1iswritePonly< ,z264 < = > ?File#1isreadPonly )>265512 < =DiscerrorinFile#1Errors513768arethesameerrorsinFile#2"7691024""""""#3<INDEX$isaspecialarraywhichallowsyoutoinsertanddeletedataelements.INDEX$doesn'tworkwithSWAP.SadlyIhaven'thadmuchreasontouseINDEX$socannotofferanytipsonusingit.PRENUMrenumbersprogramlinesandusesthesameoptionalcomandsasMallardYoucanuse?asshorthandforPRINTand'forREMMaximumlinelengthis250charactersMallardsONINSTR....GOSUBdoesn'twork.InZBasic,useINSTRtofindlthepositionononestringwithinanotherTX=INSTR(startposition,stringtosearch,stringtofind)UseONXGOSUBlineinmenuselections.ZBasicdoesn'tlikecomplexstringwork,forexampleFORi=1toLEN(variable$) variable=ASC(MID$(variable$,i,1)PNEXTproducesaStringTooComplexerrorInsteaddoFORi=1toLEN(variable$)\ temp$=MID$(variable$,i,1) variable=ASC(temp$)PNEXTXLeaveZBasicwiththecommandquitThere'snosequentialaccessfileEOF,usetheroutineinSEQUENCE.ZASinstead  xScript 1: 0x R< XIfyouwantadelayloopdon'tbotherwithtFORi=1to5000PNEXTPjustsayDELAY5000instead.DELAYcountsin1/1000thsofasecond,therefore5000is5secondsDon'tbotherwithbel$=CHR$(7):PRINTbel$insteadjustuseBEEPtosound0thespeaker,justlikeonyouroldSpectrum!ZBasichasalotofgraphicscommands,unfortunatelyonlyafewworkon<thePCW,andthosethatdoaren'tveryinmpressive.Theprogramfile@GRAFIX.ZASshouldgiveyousomeideaofwhatyoucando.TheprogramfileBRIKBAT.ZASandBRIKBAT.COMshowwhatyoucandowithZBasicifyouwanttowritefastisharcadegamesdYoucansetupyourPROFILE.SUBfiletoautomaticallytoentertheeditor.Makethefirstcommandzbdemoandthesecondcommand