-
Notifications
You must be signed in to change notification settings - Fork 84
/
parsex
239 lines (239 loc) · 4.06 KB
/
parsex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
.PAGE 'PARSE & EXECUTE'
;PARSE & EXECUTE STRING IN CMDBUF
.SKIP
PARSXQ
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 ERWORD
BNE CMDERR
;
LDY #0
TYA
STY TRACK
.SKIP
SCREND STY SECTOR ;SCRATCH ENTRY
STY CB
JSR ERRMSG
JSR ERROFF
LDA DRVNUM
STA LSTDRV
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 FILTRK,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 FILTRK,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 FILENT-1,X
STA FILDAT-1,X
STA FILTRK-1,X
STA FILSEC-1,X
DEX
BNE CS10
RTS
.SKIP
.END