<<

111188 COMPUTE! OcOctober.l ober. 1981. IIssuessu e 17

Calling BASIC Commands From Machine Language Routines

WiWilliamllia m TTayloray lar Leavi1tsburgLeavittsburg,, OH WhileWhile working oonn a tapetape ooperatingpe rating syssystemtem (TOS)(TC)S) LetLet's's looklook aatt BASIC'SBASI C's LOAD andand SAVE flagsflags for mmyy OSI CCUP I P aandnd a Stringy Floppy ttapea pe drive, and see howhow ththeyey aarere usedused loto ddetermineete rmine ifif BASIBASIC:C mmanyany unknown,unknown, but ddesired,esired , features were neededneeded programs araree tolo be listedlisted lOto ththee CRT or loto the tolO interfaceinte rface ROM BASIBASICC and thethe TOS. First, I CasseCassettette port and iiff the keyboardkeyboard or tthehe CassetteCassette wanted the TOS ttoo aalwayslways hhaveave cocommandmmand of ininpuputt port willwi ll hebe the ininputp ut devidevice.ce. BASIBASIC'SC's LOAD aandnd SAVESAVF routinesroutines.. Second, I wantedwa nted aalwayslways lOto returnrellirn lOto thethe TOS wwheneverhenever a BASIC'sBASIC'S Immediate Mode Commands BASIC program had been lloadedoaded into ththee BASIC BASIC cocommandsmmands are usuallyusuall y executed wwhenhen workspace.wo rkspace. ThirdThird,, I wanted lOto go dirdirectlyectl y from ththee input from tthehe kekeyboardyboard iiss eentered.ntered. For eexample,xample, TOS and RUNRUN a BASIBASICC programprogram that was in the whwhene n yyouou ttypeype RRUNUN followedfo ll owed by by a cacarriagerriage return BASICBASIC workspace. In additaddition,ion, I wishedwished to exitex it ththee ananyy BASIBASICC programprogram in the workspaworkspacece wwillill bebe exe­exe TOS lOto the ML Monitor; write a file dirdirectory;eclOry; ccuteduted or sstarttart loto run,run, sstartingtarting at the firstfirst line of ththee SlOstorere the diredirectoryclOry on tapetape;; retrieveretrieve the dirdirectory;ectory; program. NoticeNotice tthathat I sasaidid ttypeype RUN!RUN! This type and write or loadload llanguageanguage tapes into ththee CC1P I P ooff cOcommandlnmancl iiss knownknown aass aann imimmediatemediate Illmodeode COIllcom ­ using file markmarks.s. mmand.and. IfIf youyou hhadad typed a numbnumbere r beforebefore the RUNRUN SSincein ce ththee StrStringyin gy FloppFloppyy taptapee drivdriveses requirerequire cocommandmmand ththee CCMP I P wouldwould hhaveave rrespondedesponded wwithith that aallll programsprograms sstoredtored on tapetape hhaveave filefil e mmarksarks or OK. The program wouwouldld nnotot run butbut ththee llineine of numbnumbers,e rs, I neededneeded to free the C1PC I P from ROM ttextext wouwouldld havhavee been savesavedd oorr eenteredntered iintonto tthehe BASBASICIC in oorderrder loto ccreatereate filfileses oonn the ttapeape for aallll program mmemory.emory. To undunderstande rstand wwhathat happensha ppens inin programsprogra ms sstoredtored oonn the taptape.e. ThThee TOS cocoulduld be eiteitherher thethe programmingprogramming mode oorr thethe immimmediateed iate wrwrittenitte n in machinemachine langualanguage.ge. ThThee TOS wouldwou ld mmodeod e we mustmU St know howhow BASIBASK:C intinterpretse rprets ththee generate ththee file numbnumbersers underunder thethe controcontroll of the cocoded e input byby ththee operaoperator.tor. To do this lelet'st's llookook uuser,ser, but intinterfacingerfacing the TOS toto ROM BASIBASICC was ininsideside BASIBASIC:C and examine sosomeme of wwhathat hhappensappens ththee problem that I faced and pondered fforor seveseveralral during tthehe cocourseurse of ananyy typetype ooff codecode execexecution.ution. weeweeks.ks . HowHow the OSOSII ROM BASIC:BASI C aandnd thethe TOS At tthehe beginningbeginning ofs),of systemstem memorymemory iiss whatwhat werewere interfacedint e rf ~l c ed brought.brought severaseverall interestinginteresting pointpointss hahass bbecomeecome knknownown as zezeroro papage.ge. ThiThiss mmemorycmory to lilightght that cocoulduld bebe uusefulseful in otheotherr programming area coconsistsnsists of theth e first 256 llocationsocations ooff llowow me­me tatasks.sks. mory.mor),. OSI BASIBASICC uses this area of mmemoryemory as a LetLet mmee summarsummarize.ize. First,First, ccallingall ing BASIBASICC cocomm­ sscratchcratch pad. OSIOSI BASIC uusesses pagepage locationslocati ons SOO$0013l 3 mandmandss and eexecutingxecuting BASBASICIC programs ccanan be through $0$(){)■)A051\ as what iiss knknownow n as theth e BASIC:BAS IC handled frfromom machinemachine llanguageanguage routines. Also, we Also,InInputput Line Buffer.Buffer. What is ththee Input LinLinee Buffer?Buffer' mamayy LIST,LIST, SASAVE. VE, LOADLOAD,, and exexitit BASICBASIC loto our TThishi s area ooff llowow mmemoryemory is uusedseel by BABASICSIC ttoo mamachinechine lanlanguageguage routinesroutines without aanyny USRLISR flll1c­ func ttemporarilye mporarily sstoretore aanyny input cocodede fromfwm the user.user. liontion cacall.ll. How ththeseese cocommandsmmands cacanll be executed TThehe code input by the user in tthehe InputInput Line BufferBufler from a mamachinechine language routineroutine willwi ll bbecomeecome clear will be examexaminedin ed by by BASIC:BASIC to ddetermineetermine what ththee with ssomeome newnew knknowledgeowledge of hhowow BASIC'SBAS IC's interinter­ code's ddestinyes tin y will be.be. WhenWhe n theth e useruser terminates a prpretereter works. Let'sLet's sstarttart with\\'ith sosomeme fafactscts about theth e lineline of code withwith a cacarriagerriagc rreturn,el.urn , ththee ddestinationes tination BASIBASICSC interprinterpretereter aandnd hhowow BASIC cocommandsmma nds aarere ooff the code inpuinputt byby theth e ooperatorpe ralO r depdependsends oonn two executed. fafactors.clo rs. First,First, ifif the code began withwith a lin linee nunumbermber OSIOSI AARDVARKAARDVARK OSIOSI NOWMEANSNOW MEANS BUSINESS! WORDWOAD PROCESSINGPROCESS ING THETHE EASYEASY WAY-WAY­ ACCOUNTS RECEIVABLE - This program ACCOUNTS RECEIVABLE - This program BOOKKEEPINGBOOKKEEPING THETHE EASYEASY WAYWAY WITHMAXI-PROSWITH MAX I·PROS willwill handlehandle upup toto 420420 openopen accounts.accounts. ItIt willwill ageage -WITH- WITH BUSINESSBUSINESS I I ThisThis isis a