>LIST
 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 ! (<cmdtab>-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 <cmdtab>,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<A hence carry set.
 1640 RTS\Return with carry clear if command no good.
 1650\
 1660\
 1670\ Gets here with command all matched, but must check for
 1680\ next char non-alpha. X points to lo of execute address
 1690\ Y was pointing to char of command which failed to match - terminator
 1700\ or other - but has been inc'd.
 1710\
 1720.cli3
 1730 DEY
 1740 LDA (swzp0),Y
 1750 CMP #ASC"A"
 1760 BCC cli4\less
 1770 CMP #ASC("z")+1\Cheating here - not checking for [\]^`
 1780 BCC cli2\Definitely "alpha" or [\]^`
 1790\
 1800\ Enters here with comand fully checked, X points to lo of addr
 1810\
 1820.cli4
 1830.spcs
 1840 Lda (swzp0),Y
 1850 Cmp #32
 1860 Bne cli10
 1870 Iny
 1880 Jmp spcs
 1890.cli10
 1900 Tya
 1910 Clc: Adc swzp0
 1920 Sta zp0:sta cline \******* New store for command addr
 1930 Lda swzp1
 1931 Adc #0
 1940 Sta zp1:sta cline+1
 1950.ncy1
 1960 LDA cmdtab,X
 1970 STA swzp0
 1980 LDA cmdtab+1,X
 1990 STA swzp1
 2000 JMP (swzp0) \Execute the command!
 2010\
 2020\
 2030\
 2040\
 2050\
 2060\
 2070\
 2080\
 2090\
 2100\
 2110.cmdtab
 2120 EQUS "DIR"
 2130 EQUB &80+dirbit
 2140 EQUW setdef
 2150\
 2160 EQUS "INFO"
 2170 EQUB &80+filebit
 2180 EQUW info
 2190\
 2200 EQUS "LIB"
 2210 EQUB &80+dirbit
 2220 EQUW lib
 2230\
 2240 EQUS "SHELL"
 2250 EQUB &80+textbit
 2260 EQUW shell
 2270\
 2280 EQUS "DELETE"
 2290 EQUB &80+filebit
 2300 EQUW delete
 2310\
 2320 EQUS "RENAME"
 2330 EQUB &80+fromtobit
 2340 EQUW rename
 2350\
 2360 EQUS "COPY"
 2370 EQUB &80+fromtobit
 2380 EQUW copy
 2390\
 2400.swcmds\These commands allowed at the sideways entry point.
 2410\
 2420 EQUS "TERMINAL"
 2430 EQUB &80
 2440 EQUW StartTerm
 2450\
 2460 EQUS "HOSTFS"
 2470 EQUB &80
 2480 EQUW select_fs
 2490\
 2491 EQUS "TYPE"
 2492 EQUB &80+filebit
 2493 EQUW Type
 2501\
 2502 EQUS "PRINT"
 2503 EQUB &80+filebit
 2504 EQUW Print
 2510\
 2511 EQUS "MOUSE"
 2512 EQUB &80
 2513 EQUW Init_mouse
 2514\
 2515 EQUS "JOYSTICK"
 2516 EQUB &80
 2517 EQUW Remove_mouse
 2518\
 2520 EQUB &FF \ End of table
 2530\
 2540\
 2550\
 2560\
 2570]
 2580RETURN
>*spool
