>LIST REM "Cli" [OPT Pass \ \ Command Line Interpreter \ \ \ Enters here with X pointing to the first command \ allowable in this context, as an offset from the start of \ the command table. (zp0),Y points to the command to be examined \ Table format is command text followed by a byte with the top \ bit set (this may have syntax encoded in it later) \ this is followed by the two byte address of the routine in question. \ Returns with carry set if unable to decode the command. \ The table is terminated by &FF \ Note that the command terminator byte may not be &FF \ \ .cli STY scratch0\Save start of command for future use \ .cli1 LDA (swzp0),Y\character AND #&5F\Force to upper case (weird if non alpha, but still not alpha) INX\to point to next table char INY\ready to go round loop EOR cmdtab-1,X\Devious, this bit ! (-1 because X already inc'd) \EOR because this leaves the top bit of table in N (top of A cleared \earlier) but simultaneously leaves Z as the comparison result. BEQ cli1\Exactly the same - keep going BMI cli3\ Top bit set (in table version) - we have reached the end \ \ At this point, we are in disagreement - \ could be dot abbreviation, or a genuine mis-match. \ DEY\go back to the char in question LDA (swzp0),Y CMP #ASC"." BNE cli2\Definitely not OK now INY \ SKIP OVER "." WHEN PASSING REST OF COMMAND LINE TO CLI \ \ Now OK so skip to end of command .cli5 INX LDA cmdtab-1,X\This is the same offset as above, so exit condition \ has same X. Can't miss the end despite having inc'd X as we \ would have found it straight away if the last match was with \ the terminator. BPL cli5 BMI cli4\Unconditional \ \ Total failure if not dot abbreviation \ so skip to next table entry \ .cli2 INX LDA cmdtab-2,X\X has been incremented - on entry lowest value \possible would be 2nd byte of dud cmd, highest would be \pointing at lo byte of address, so at this point we either \test one of the command bytes or the byte with top bit set. BPL cli2\Find byte with top bit set INX\X Now pointing at 1st byte of next cmd LDY scratch0\Get back pointer to command CMP cmdtab,X BCS cli1\Another devious one ... A is always >127 (we have just \tested it), and ,X is either &FF = end of table, or is \a character. If X=&FF, X is always >=A hence carry clear, if \X=(character) then X<128 hence X