1000 REM "Cli" 1010[OPT Pass 1020\ 1030\ Command Line Interpreter 1040\ 1050\ 1060\ Enters here with X pointing to the first command 1070\ allowable in this context, as an offset from the start of 1080\ the command table. (zp0),Y points to the command to be examined 1090\ Table format is command text followed by a byte with the top 1100\ bit set (this may have syntax encoded in it later) 1110\ this is followed by the two byte address of the routine in question. 1120\ Returns with carry set if unable to decode the command. 1130\ The table is terminated by &FF 1140\ Note that the command terminator byte may not be &FF 1150\ 1160\ 1170.cli 1180 STY scratch0\Save start of command for future use 1190\ 1200.cli1 LDA (swzp0),Y\character 1210 AND #&5F\Force to upper case (weird if non alpha, but still not alpha) 1220 INX\to point to next table char 1230 INY\ready to go round loop 1240 EOR cmdtab-1,X\Devious, this bit ! (-1 because X already inc'd) 1250\EOR because this leaves the top bit of table in N (top of A cleared 1260\earlier) but simultaneously leaves Z as the comparison result. 1270 BEQ cli1\Exactly the same - keep going 1280 BMI cli3\ Top bit set (in table version) - we have reached the end 1290\ 1300\ At this point, we are in disagreement - 1310\ could be dot abbreviation, or a genuine mis-match. 1320\ 1330 DEY\go back to the char in question 1340 LDA (swzp0),Y 1350 CMP #ASC"." 1360 BNE cli2\Definitely not OK now 1370 INY \ SKIP OVER "." WHEN PASSING REST OF COMMAND LINE TO CLI 1380\ 1390\ Now OK so skip to end of command 1400.cli5 INX 1410 LDA cmdtab-1,X\This is the same offset as above, so exit condition 1420\ has same X. Can't miss the end despite having inc'd X as we 1430\ would have found it straight away if the last match was with 1440\ the terminator. 1450 BPL cli5 1460 BMI cli4\Unconditional 1470\ 1480\ Total failure if not dot abbreviation 1490\ so skip to next table entry 1500\ 1510.cli2 INX 1520 LDA cmdtab-2,X\X has been incremented - on entry lowest value 1530\possible would be 2nd byte of dud cmd, highest would be 1540\pointing at lo byte of address, so at this point we either 1550\test one of the command bytes or the byte with top bit set. 1560 BPL cli2\Find byte with top bit set 1570 INX\X Now pointing at 1st byte of next cmd 1580 LDY scratch0\Get back pointer to command 1590 CMP cmdtab,X 1600 BCS cli1\Another devious one ... A is always >127 (we have just 1610\tested it), and ,X is either &FF = end of table, or is 1620\a character. If X=&FF, X is always >=A hence carry clear, if 1630\X=(character) then X<128 hence X