P729 EFAX@/2: Wjh 2z@ ft 22z11/12 ‖B2201210‖a17T/SWR15‖i14Text‖m10Masterim g@Sidjways R M & RAM - Module 15 - Multi command interpreter÷e------------------ --------------------J------------------- -J--------÷i÷e÷e Up until now, all the modules of thj course that have used an÷ eunrecognised * comma↑d interpreter to d emonstrate a programZi→F÷etechnique have useh@a@one-comma↑d imterpreter.@I/ this moduli I will÷eimtroduce a multipli coI mand interpreter which can be used to÷ei mpleme↑t@onj@or@more new * commands per SWR bank.÷e÷e The multipli command inte tptKtei@rc@ZjBP@ZNrS@c#←plicateH@tPa↑@tP V¾egi←plK #→U←comZa↑d@neisi#→.@  es a↑@optio→al pteeix@chatacter÷efor tPj commands as well as command shortening with@a d#t.÷e÷e 0reeixinF@coUZa↑db@with an optional@character is quite Q useful ÷eeeature to include im@zour i→terprUter s. Not@only does it make your÷ework look if the command names÷eyou choose for yo kr rom clash with those in a higher prio
P729CEEFAX /29 W  12:12/27 ‖B22p2210‖a17T/SWR15‖m33b2 uses the comm b↑d *H+K!@b↑d it is j→ a lower÷Uptiority rom socket than the DFS rom then the co ZJand wPll always be÷eintercepteh by the DES beeore zour interpteter has a chanc e to÷erecognise jt.  al "X" prefix your rom will get the÷eopp #rti↑Pty@t#@j→xeqcKpt tPj@coYZb↑d@av@l#↑ g as the equivalent *XDUMP÷ecommand is i gnored by the DF3 rom.÷e÷e Because the i→terpteter is useh to implement more th an one command÷eyou can not use the titl e string in the header as a command namj ,÷ealthough tPe title strinF should stil l be included in thj header to÷eidentify tPj roI image.÷e÷e Thj si→Fli@comZand name has to be replaced with a multipli comZa↑d÷e→amj@table.@EacP naZj@i→ tPj ta ble is fgllowed by a two byte adhress.÷e TPjs is@tPj@bhhtecv@#e@tPj@rokti→j@brroc iated@with tPe command naZe.÷eEach addre ss is stored in thj table with the high byte of the address÷Ufollowed by thU low byte-@This@btea+v@with the@n+p2 co→vemt
P729CEEFAX@/29 Wed 2z@ ct @12:12/4p ‖B2203210‖a1/T/SWR1*‖U37*Bkt it is do.e so that tPj high byte, which÷emust have tPj@←ost signjeica↑t bit@set, can@be@jse d as an end of÷ecommand name markjr as w jll as part of the address. The bzte &FF is÷euseh as a termimatioJ@char!ctir in thj command table.÷e÷e Thj command tabl e ureh i→ the jxaJple program is@show→ i n BASIC 2÷eAssembler in figure 15.1.÷e÷e ÷e÷e÷e↑coYJtadle÷e@@ EQU+@"S EN <@command string÷e EQUB sire n DI.@25m <@jnd@of@command matker@& ms b yte÷e EQUB sirin MOD 256 ½ ls byt j÷e @EQUS@"HEHE" <@command string÷e EQUB hehj DI. 256 ↑ end @#e@coYZa↑d@ZatSjr@& Zv@bzte÷e @ @JQ UB hehe MOD 256 ↑ ls byte÷e EQUS "UEO" <@command@string÷e EQUB ufo DI. 25m < jnd oe command mar Wer@F@Zv@byte÷e@ @ @EQUB@uf#@ZOD 2*m < ls byte÷e EQUB &FF < terIinatio↑ character÷e÷eEigure 15↑1 The new command table.÷e-←-J←------ --- -←-----------------÷e÷e÷e÷e÷e The inter
P729CEEFAX 729 Wed 19@Oct 12:02/12 ‖B220421p‖a17T/SWR15‖m3B18 then compares tPj÷euntecoG↑iseh@comZ@↑d@witP@jacP@coI mand in the command tabli. If a÷ematch i v@fok↑d tPj@coUZand addtess is taVjm fro m the command table and÷estored in two c onsecutive zero page bytes which are use h@to@Z─Vj@a↑÷ei→djeect@jkmp to@tPj@↑jw@r #ktimj-÷i÷e@@Thj@#rHjr@#e@tPj@coYZb↑Hv@j n the table is very important. Thj÷elong est@command namj must bj at the head of the table and the shortest÷eat the end. Thj reason for@this is that if two@coUma nds such as *RED÷iand *REDUCE are includ jd in the tabli and the unrecognised com mand is÷ecomparKd with RED bjfore REDUCE tPe→@*RED+CE@will@bj recogniseh as÷e*RE D@with thj argumjnt "UCE". Thj commands in the table must all be÷eupper case alp habetic characters and must not start wi tP@tPj@#pti#→al÷ecPatAftei,@r→@tPjs@jxam pli "X". Numbers and punctuation charact ers÷emust not be used because the unreco gnised command is forced tg upper÷ecase by ANDimg it@with@£&DE.÷e÷e The three n
P729CEEFAX 729 Wed 19@Oct 12:00/58 ‖B220m210‖a17T/SWR15‖m41288before the fi tst byte@oe@each@comJa↑d im tPj table÷ea /d again in zhe innjz logp (line 550) to poimt to jvery bzte@oe@each÷ecomJand st arting@with thj first byte. The 9 regist er is tPe@ofeset@o↑÷etPe unrecognised@co mmand tixt pointer and needs to be resto red to its÷einitial value at tPe beginin g of each comparison. It is pushed on th e÷estack as a temporary st#re (iimes 410 Z)2p).÷e÷e Thj@outer loop of tPj compar ison routi→j is i→ li→es 450 to@700. The ÷eouter loop poi↑ts to@jach coUma↑d im t Pj@command tabli. Thj X register÷eis i.c remented to point to the byte preceding the first byte@of each÷ecommand (li.e 45 0) and the Y register is restored to its initial value÷e(lines 460-)80). The fir st charactii of thj unrecognjsed command @js÷eread (ii.j 490) and@forceh to@upper @case (linj@500). Rt is@compated÷ewhth t
P729CEEFAX 729 Wed 19 Oct 12:01/12 ‖B2207210‖a17T/SWR15‖m41642 Y register i s not incrementeh so that the first÷echa racter will be read again and compared w jth tPj@c#Lte→ts@of tPe÷ecoUZand table-÷ e÷e Thj innjr loop of the comparison ro utinj is in lines 550 to 640.÷eThis loop @co←pates every byti@of@each new comZa↑d @witP@jmery@bzte@#e÷etPj@z↑tecoG↑rseH@c# ZZand and recognises a command if either all tPe÷ipairs of bytes match or if all pairs of b=tes match untPl a dot is÷ire ad at tPj@e→d of tPj@u↑recognised comma↑ d.÷e÷e Thj X register is increme→ted (l ine 550) to point to the first byte÷eof a command in the command table. Thj bzte pointed to by the offset÷ein X is read (line 560) and tested (line 570) to see ie@ii@js@tPj@j→H÷e#e@c#IZb↑H@ZbtSjr@(tPj most significant byte of the address by tesQ.÷eWPe→@tPe@coUZa↑d naZe@b↑d@unrecoW nised command match the end@of÷ecommand ←arker will be read a↑d control is passe d to the label÷e".eound". Control is als o parseh to ".eounh"@wPj→ tPj termimatio
P729CEEFAX 729 Wed 1:@Oct 12:01/37 ‖B220821p‖a17T/SWR15‖m41:FAnd of command marSer@or tUrmination÷echaracter@is not read the next byte in the unrecognised -600). If thj next character is a dot÷ec #ntrol@is passeh to the label@"→eound#t" .÷e÷e The inner loop in lines 550 to 64 0 jxits when a mismatch in the÷epairs of bytes is found. When a mismatch occurs the X register is÷epointed to the end of command markjr (lines 660-680) and the marker is÷ecompared with &FF to see if i t is tPe@command table termination÷echar acter Xline 690). If the termination cha racter is found the zjro÷epage bytes and registers ari restored and control is p assed back to÷ethe MOS (line1 720-820). NPPW o the÷elabel ".eirstchar" (linj 440) to compati tPe untecogniseh@command@with÷et he next command in the table.÷e÷e @When a command shortened with a dot is recogn ised control is passed÷eto the label ".f oundot" (line 830). Thj X register is th
P729CEEFAX 729 Wed 19@Oct 12:02/00 ‖B2209210‖a17T/SWR15‖m41DB2he end of com →a↑d@←at+er (li→es 84p←860).÷e÷e A→ uns hortened command passes control to the l abjl ".eound" (linj÷e87p). Thj accumulat or is@coIpated with &FF to see if the te tYj→ati#→÷ecPbtAfter@Pav@dee→@tSah↑@  t has then nonj@of the commands match th j÷eunrecognised command and so the regis ters ari ristored and contrgl÷epasses ba ck to the MO3 (lines 71p-820). If the ac cumulator does not÷econtain the terminat ion character it must contain the most s ignieicant÷ebyte@o$ the@new routime. Thi s is storeh i→ tPj@most sig↑ificant@of t hj÷etwo@co.secktive zero page bytes (li↑ e@90p). The X register is÷eincremented t o point to the byte storing the least si gnificant byti@of÷ethe new routine's add ress (linj :1p). This byte@is loadeh int o the÷eaccumulator (line 920) and stored in the least significant of the two÷eze @was pushjd on the stack as÷ea temporary @store@and is pulled ofe and discarded@(
P729CEEFAX 729@ Weh 1: Oct 12:p%/20 ‖B22pA21p‖a17T/SWR15‖m4216Csed X¾ines :5 p←9-p)@b↑d@b↑ i→direct@juJp@js@Zade÷eto@ the njw routinj (line 970).÷e÷e After t hj njw@routimj hav been jxecuted tPj two zero page bytes used÷efor the indirect jump are restored (lines 1190-1220), the stack is÷ebalanceh (lines 1230-1250), t hj accuZulator is loaded@with zero to÷ei ndicate that the command has been recogn iseh (linj 12np) and@control÷eis passed bacW to@tPj@Z "@(line 147p).÷e÷e@ Umders ta↑dimg@and@jxplaiming how tPj interptet er works is much more÷edifficult than us i→F@jt-@ HP with your÷eown programs you only need t o add tPe command names to the command÷e table and, of course, the new routines. You don't@neeh to alter tPe÷ecodimg@of t he i→terpteter at all which@maVes it@ver y easy to adapt for÷eyour@own software. Whe↑ zou adapt zour own programs to run ot forget to use a routine, such as the one÷ein lines 1180 to 1270,@which restor
P729CEEFAX 729 Wed 19 Oct 12:p2/41 ‖B220B210‖a17T/SWR15‖m42524nces the stac W@bjeore@retktnjmF@co→tr#l@t# tPj@Z "- R estoring the÷ememory used by the interpr eter, balancing thj@stack and loading th j÷eaccuUulator with zero before returnin g is absolutely vital. This÷emultiple co mmand interpreter will not work properly @je zok@leanj@okt÷etPis@jsse→tial lavt@r outinj.÷e÷e This interpreter will be de vel#peh fkrther i→ the ↑jxt m#dule to÷ei nclkde a *HEL0 service.÷e÷e÷e÷e÷e÷e 10 REM: S UNDS÷e 20 MODE7÷i 30 HIMEM=& 3C00÷e 40 DIM save 50÷e 50 diff=&800 0-HIMEM÷i 60 address=&70÷e 70 comvec =&F2÷e 80@gsinit=&FFC2÷e 90 gsread=& EFC5÷i 200@osword=&FFF1÷i 110@oscli=&F FF7÷e 120 FOR pass = 0 TO 2 STEP 2÷e 1 30 P%=H MEMOPT 50 BRK÷e 160 BRK÷e 170 @ @@@@@@BRV÷e@@280@@ @ @JZ0@service+ diee÷e 2z0@ @ @OPT FNequd(E82R÷i 2 00 OPT FNequb((copyright+diff) M OD 256)÷e 210 BRK÷e 220 O0T FNequs("S U-DS")÷e 230 ↑copztigXt
P729CEEFAX 729 Wed 19 Oct 12:07/17 ‖B220C218‖a17T/SWR15‖m428C8PT FNeqush"(C ) Gordon Horsington 1987")÷e 260 BRV÷e 2/0 .service÷e 280 CMP £4÷e 2:0 BEQ unrecognjseh÷e 3 00 RT"÷e 310 ↑unrecognised÷e 3 20 PHA÷e 330 TXA÷e 340 PHA÷i 350 TZA÷e 360 @ @@@@@0PA÷e @v/p@@@@@@@@@LHA@ahdtess÷e@ 380 PHA÷e 390 LDA Qddr essR1÷e 400 0HA÷e 410 LDX £&FE÷e 42p TYA÷e 430 @ 0PA÷S@ 4hp@↑eirstcPat÷e@ 4*0@@ @ @@ INX÷e 460 PLA÷e 470 TA Y÷e 480 PHA÷e 4:0 LDA (co←vec),:¾e k0p AND@C&DE÷e k1 0@ @@@ C-0@£AS ("X")÷e @*%0 B NE intirpret÷e 530 INY÷e 540 O i→terpret÷e *+0 INX÷i *m0 LDA commtable+diff,X÷e 570 BMI found÷e 580 LDA (comvec),Y÷ e 590 INY÷e 600 CMP £A SC(".")÷e 610 BEQ founddot÷e 6 20 AND@£&DF÷i 630 CMP@c o←Ztadle+hPeM,X÷e@@n)0@@@ @@@@@BCQ@i→ter
P729CEEFAX 729 Wed 1: Oct 12:07/24 ‖B220D210‖a17T/SWR1*‖J42C68INX÷e 670 @ @@LDA@coYJtadli+Hjee,X÷i@@.80@ @@@ BPL another÷e 690 CMP £&FF÷e @/pp@ @@@@@BNC@firstcPar÷e /1p@↑exit÷ j 720 0LA÷e 730 PLA÷e @/4p @STA addresr+1÷e @/50 PLA÷e 760 STA addriss÷e 770 PLA÷i 780 TAY÷K @790 PLA÷e 800 TAX÷e 810 PLA÷e 82p RTS÷e 830 .found dot÷e 840 INX÷e 850 LD A commtable+diff,X÷e 860 BPL fo unddot÷e 870 .found÷e 880 CMP £&FF÷e @8:0@ @@ BEQ jxit÷e @:00 STA address+1÷e 910 INX÷e y%p@@ @@ LDA@coUJtable+diee,X÷e :30 STA address÷e 940 PLA÷e z50 SEC÷i 960 JSR gsi nit÷e :70 JMP (address)■d 980 .coYZtable÷e@@z9p @@@@ @OP-@FNeqiv("S REN")÷e 10p0 0OPT FNequb((siren+d iee) DI. 25n)÷e 1p1p OPT FNequb( (sirin+diff) MOD 256)÷e 1p20 OPT @FNeqiv("HEH dQ÷e@2pk0@@@ @ @@ PT@FNequ
P729CEEFAX 72: Wed 19 Oct 12:17/51 >B220E210‖a17T/SWR15‖m430XB 0OPT FNiqub( (hjhj+hief) KOD 256)÷i 1p50 @OPT FNequs("UEO")÷i 1060 OPT FNequb( (ufo+diff) DI. 256)÷e 1070 OPT F Nequb((kfo+dief) MOD 25m)÷K )080 @OPT@FNequb(%FF)÷e@1p90@.PjPe÷e 1100 @ @LHA £8÷e@111p@@@ @@@@@LDX@£XeQVPj+I iff) MOD@25m÷e@212p LD9@£XePePe+ diff) DIV 256÷e 1130 JSR osword <@E↑neY#pe¾K@114p LDA £/÷e 11 50 LDX £(shehe+diff) MOD 256÷e 1 160 LDY £(shehe+diff) DI. 256÷i 1170 @J"R@osword <@Sou↑d÷e@2 8 0 .pullout÷e 1190 PLA÷e 1200 STA address+1÷e 1210 PLA÷e 124p @@ STA@addtesv÷i 1430@ @ PLA÷e 1240 PLA÷e 1250 PL A÷e 1260 LDA@£0÷e 1270 R TS÷e 1280 .siren÷e 1290 LDA@£8÷e 1300 LDX £(esire.Rdief) MOD 2*m ÷U@1s10 @ LD9@£(esire→RdiMf) DI- 2 56÷e 1320 JRR osword ½ Envelo pe÷e 1330 LDA £7÷e 1340 IDX@£(svire.RiieeQ@ZOH 2um÷e@2350
P729CEEFAX 729 Wed 19 Oct 12:04/14 ‖B220E21p‖a17T/SWR15‖m433B) J"R o sword ) Sound÷e 1370 J!P pull #kt+diue÷n 1380 kfo÷e 1h90 LDA £8in 140 LDE £nd SO+hD c) mOn 2 56÷e 1410 LDY £(eufo+diff) DI 2 5 ÷e 1420 JaR osword <@Envelo pe e 1 3p LDA £ ÷e 1440 DX £(@ufo+be s) MOD 2d ÷e 14kp JDs £(sufo+diff) DI 256÷e 46( J3R osword Sound÷e 1470 JMP pullout+diff÷e 1480 .eheha÷e 1490 @OPT FNequd(%p2FF0301)÷e 1500 OPT FNcqud(&461E E32)÷e 1510 OPT FNeqkd(&FFFFFF/F)÷e 1k20 OPT FN @ @@@&7E7 )a 4 X paasae28 )310 a @OPT FNeqkd(%00p10011)÷e 1*20 OP T FNeqkd(%00320075)÷e 15-0 .esiren÷e 157 0 @OPT FNhqud(%07Fs01p2)÷ 158 @OPT Fn qhd &0mmand 0)bi add OPT FNequd(&82p0007E)÷e 1600 OPT FNequw(&7E7E)÷e 1610 .ssiy n÷e ) 20 OPT FNeqkd(&00p20p12)÷e 1630 0OPT F isud(%00FF00 8)■e )640 Oiu g me@26+0 PT FNequd(&FFp1p103)÷e
P729CEEFAX 72: Wed 1:@Oct 12:14/41 ‖B221p210‖a17T/SWR15‖m4375E 1670 OPT FNequd(%FF00EF03)÷e 1680 OP T FNequw(&7E7E)÷i 1690 .sufo÷e 1700 @OPT FNequd(%00030013)÷e 1710 OPT FNequd(&003C0082)÷i 1720 .lastbyte÷ j@1/3p@→÷K@17hp@NEXT÷K@2/*a@ NPTFS filinamj = "eilenamjd÷i 1760 IF filenamj T;b"@END÷e 2770@$save="SA-E "+eilemaZj$+ " "+STR$‖÷(HIMEM)+" "+STR$‖÷(las÷e tbyteQW" FFFF8000 FFFF800p"÷e 1780 X%=sa ve MOD 256÷e 9790 Y%=save DIV 256÷e 800 *OPT1,2÷i 1810@CALL oscli÷e 1820 *OPT1, 0÷e 1830 END÷e 1840 DEFFNequb(byti)÷e 18 50@?P%=byte÷e 1860 P%=P%+1÷e 1870 =pass÷ j 1880 jEFFNequw(woud)÷e 1890@?P%=word M OD 256÷e 1900 P%?1=word DIV 25-÷e 1910 P %=P%W2÷e )z20 =pass÷e 1930 DEFFNequd(dou ble)÷e 1:)0 !P%=doubli÷e 1950 P%=PE+4÷e 19m0 =pass÷e 1z70 DEFFNequs(string$)÷K 1 980 $PE=string$÷e 1990 PE=PE+LEN(string$ )÷c 2000 =pass÷e‖c