.PAGE 'PARSE & EXECUTE'
;PARSE & EXECUTE STRING IN CMDBUF
.SKIP
PARSXQ
	LDA #0
	STA WBAM
	LDA LSTDRV
	STA DRVNUM
	JSR OKERR
	LDA ORGSA
	BPL PS05
	AND #$F
	CMP #$F
	BEQ PS05
	JMP OPEN
PS05	JSR CMDSET      ;SET VARIABLES,REGS
	LDA (CB),Y
	STA CHAR
	LDX #NCMDS-1    ;SEARCH CMD TABLE
PS10	LDA CMDTBL,X
	CMP CHAR
	BEQ PS20
	DEX
	BPL PS10
	LDA #BADCMD     ;NO SUCH CMD
	JMP CMDERR
PS20	STX CMDNUM      ;X= CMD #
.SKIP
	CPX #PCMD       ;CMDS NOT PARSED
	BCC PS30
	JSR TAGCMD      ;SET TABLES, POINTERS &PATTERNS
PS30	LDX CMDNUM
	LDA CJUMPL,X
	STA TEMP
	LDA CJUMPH,X
	STA TEMP+1
	JMP (TEMP)      ;COMMAND TABLE JUMP
.SKIP
; SUCCESSFUL COMMAND TERMINATION
ENDCMD
	LDA #0
	STA WBAM
ENDSAV
	LDA ERWORD
	BNE CMDERR
;
	LDY #0
	TYA
	STY TRACK
.SKIP
SCREND	STY SECTOR      ;SCRATCH ENTRY
	STY CB
	JSR ERRMSG
	JSR ERROFF
SCREN1
	LDA DRVNUM
	STA LSTDRV
	TAX
;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;
	JMP PTCH43      ; *** ROM DS 05/01/85 ***
	NOP             ; FILL
;	LDA #0
;	STA NODRV,X
RTCH43
;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;
	JSR CLRCB
	JMP FREICH      ;FREE INTERNAL CHANNEL
;
CLRCB
	LDY #CMDLEN-1
	LDA #0
CLRB2
	STA CMDBUF,Y
	DEY
	BPL CLRB2
	RTS
;
; COMMAND LEVEL ERROR PROCESSING
CMDERR	LDY #0
	STY TRACK
	STY SECTOR
	JMP CMDER2
.SKIP
SIMPRS	LDX #0          ;SIMPLE PARSER
	STX FILTBL
	LDA #':
	JSR PARSE
	BEQ SP10
	DEY
	DEY
	STY FILTBL
SP10	JMP SETANY      ;SET DRIVE #
.PAGE 'PARSE-TAGCMD'
PRSCLN
	LDY #0
	LDX #0
	LDA #':
	JMP PARSE       ;FIND POS'N OF ":"
;
;TAG COMMAND STRING
;  SET UP CMD STRUCTURE
;  IMAGE & FILE STREAM PTRS
;
.SKIP
TAGCMD
	JSR PRSCLN
	BNE TC30
TC25	LDA #NOFILE     ;NONE, NO FILES
	JMP CMDERR
TC30	DEY
	DEY
	STY FILTBL      ;":"-1 STARTS FS1
	TXA
	BNE TC25        ;ERR: "," BEFORE ":"
TC35	LDA #'=         ;SEARCH: "="
	JSR PARSE
	TXA             ;?FILE COUNT= 1-1?
	BEQ TC40
	LDA #%01000000  ;G1-BIT
TC40	ORA #%00100001  ;E1,^E2-BITS
	STA IMAGE       ;FS STRUCTURE
	INX
	STX F1CNT
	STX F2CNT       ;INIT FOR NO FS2
	LDA PATFLG
	BEQ TC50
	LDA #%10000000  ;P1-BIT
	ORA IMAGE
	STA IMAGE
	LDA #0
	STA PATFLG      ;CLEAR PATTERN FLAG
TC50	TYA             ;PTR TO FS2
	BEQ TC75        ; FS2 NOT HERE
	STA FILTBL,X
	LDA F1CNT       ;FS2 IS HERE NOW,...
	STA F2PTR       ;...NOW SET F2 PTR
	LDA #$8D        ;FIND CR-SHIFTED
	JSR PARSE       ;PARSE REST OF CMD STRING
	INX             ;ADVANCE FILTBL PTR TO END
	STX F2CNT       ;SAVE IT
	DEX             ;RESTORE FOR TEST
	LDA PATFLG      ;SAVE LAST PATTERN
	BEQ TC60        ;?ANY PATTERNS?
	LDA #%1000      ;YES, P2-BIT
TC60	CPX F1CNT       ;?F2CNT=F1CNT+1?
	BEQ TC70
	ORA #%0100      ;G2-BIT
TC70	ORA #%0011      ;E2-BIT,^E2-BIT
	EOR IMAGE       ;EOR CLEARS ^E2-BIT
	STA IMAGE
TC75
	LDA IMAGE
	LDX CMDNUM
	AND STRUCT,X    ;MATCH CMD TEMPLATE
	BNE TC80
	RTS
TC80	STA ERWORD      ;**COULD BE WARNING
	LDA #BADSYN     ;ERR: BAD SYNTAX
	JMP CMDERR
.SKIP
.PAGE 'PARSE'
;PARSE STRING
;  LOOKS FOR SPECIAL CHARS,
;  RETURNING WHEN VAR'BL CHAR
;  IS FOUND
;   A: VAR'BL CHAR
;   X: IN,OUT: INDEX, FILTBL+1
;   Y: IN: INDEX, CMDBUF
;     OUT: NEW PTR, =0 IF NONE
;         (Z=1) IF Y=0
.SKIP
PARSE	STA CHAR        ;SAVE VAR'BL CHAR
PR10	CPY CMDSIZ      ;STAY IN STRING
	BCS PR30
	LDA (CB),Y      ;MATCH CHAR
	INY
	CMP CHAR
	BEQ PR35        ;FOUND CHAR
	CMP #'*         ;MATCH PATTERN CHARS
	BEQ PR20
	CMP #'? 
	BNE PR25
PR20	INC PATFLG      ;SET PATTERN FLAG
PR25	CMP #',         ;MATCH FILE SEPARATOR
	BNE PR10
	TYA
	STA FILTBL+1,X  ;PUT PTRS IN TABLE
	LDA PATFLG      ;SAVE PATTERN FOR EA FILE
	AND #$7F
	BEQ PR28
	LDA #$80        ;RETAIN PATTERN PRESENCE...
	STA PATTYP,X
	STA PATFLG      ;...BUT CLEAR COUNT
PR28	INX
	CPX #MXFILS-1
	BCC PR10        ;NO MORE THAN MXFILS
PR30	LDY #0          ;Y=0 (Z=1)
PR35	LDA CMDSIZ
	STA FILTBL+1,X
	LDA PATFLG
	AND #$7F
	BEQ PR40
	LDA #$80
	STA PATTYP,X
PR40	TYA             ;Z IS SET
	RTS
.SKIP
;INITIALIZE COMMAND TABLES, PTRS, ETC.
.SKIP
CMDSET	LDY BUFTAB+CBPTR
	BEQ CS08
	DEY
	BEQ CS07
	LDA CMDBUF,Y
	CMP #CR
	BEQ CS08
	DEY
	LDA CMDBUF,Y
	CMP #CR
	BEQ CS08
	INY
CS07	INY
CS08	STY CMDSIZ      ;SET CMD STRING SIZE
.SKIP
	CPY #CMDLEN+1
	LDY #$FF
	BCC CMDRST
	STY CMDNUM
	LDA #LONGLN     ;LONG LINE ERROR
	JMP CMDERR
;  CLEAR VARIABLES,TABLES
CMDRST
	LDY #0
	TYA
	STA BUFTAB+CBPTR
	STA REC
	STA TYPE
	STA TYPFLG
	STA F1PTR
	STA F2PTR
	STA F1CNT
	STA F2CNT
	STA PATFLG
	STA ERWORD
	LDX #MXFILS
CS10	STA FILTBL-1,X
	STA ENTSEC-1,X
	STA ENTIND-1,X
	STA FILDRV-1,X
	STA PATTYP-1,X
	STA FILTRK-1,X
	STA FILSEC-1,X
	DEX
	BNE CS10
	RTS
.SKIP
.END
