-
Notifications
You must be signed in to change notification settings - Fork 84
/
exten1.src
298 lines (264 loc) · 4.22 KB
/
exten1.src
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
.page
.subttl 'extensions 1'
;
; instring : position of str1 in str2 at or after position n
; usage : instr(a$, b$ {,n})
instr
lda facmo ;save pointer to temporary descriptors
sta tmpdes
lda facmo+1
sta tmpdes+1
jsr frmevl ;get next arg.
jsr chkstr ;must be string
lda facmo ;save it, as well
sta tmpdes+2
lda facmo+1
sta tmpdes+3
ldx #1 ;default starting position
stx faclo
jsr chrgot
cmp #')' ;any length argument?
beq inst1 ;branch if not
jsr combyt ;else go get a one byte argument
inst1
jsr chkcls ;look for )
ldx faclo
bne *+5
jmp fcerr ;starting position can't be 0
dex
stx positn
ldx #3 ;copy 'pointers to temp descriptors' to zero page
inst2
lda tmpdes,x
sta ptarg1,x
dex
bpl inst2
ldy #2 ;now get the descriptors
inst3
jsr indpt1
sta str1,y
jsr indpt2
sta str2,y
dey
bpl inst3
lda str2 ;check if string 2 is null
beq instnf ;if so, return 0
inst5
lda #0
sta match
clc
lda str2 ;length of string 2
adc positn
bcs instnf ;too long, not found
cmp str1 ;see if > length of string 1
bcc inst6 ;< len string 1
bne instnf ;must be >, not found
inst6
ldy match
cpy str2 ;if match len = str len, then found
beq instfd
tya
clc
adc positn ;compare str1(s+p+m) with str2(m)
tay
jsr inds1p
sta syntmp
ldy match
jsr inds2p ;(str2+1),y
cmp syntmp
beq inst7
inc positn ;not the same, start over from next positn
bne inst5 ;always
inst7
inc match ;count characters that match
bne inst6 ;always
instfd
inc positn
lda positn
.byte $2c
instnf
lda #0
pha
lda tmpdes+2 ;free temp descriptors
ldy tmpdes+3
jsr fretmp
lda tmpdes
ldy tmpdes+1
jsr fretmp
pla
tay
jmp sngflt
.page
trap
jsr errdir
jsr chrgot ;if no #, means 'turn off trap'
beq trap1
jsr getwrd
sty trapno
.byte $2c
trap1
lda #$ff ;flag no trap
sta trapno+1
rts
resume
jsr errdir ;no direct mode
ldx errlin+1 ;is there an error to resume from?
inx
beq rescnt ;can't resume!
jsr chrgot ;look for arguments
beq resswp ;no arg's...restart err'd line
bcc resnum ;numeric argument
cmp #nexttk ;only other choice is 'next'
bne ressnr ;if not, syntax error
jsr resswp ;resume execution with next stm't
ldy #0
jsr indtxt
bne resum2 ;must be a ':'
iny ;must be a null,get next line
jsr indtxt ;make sure its not end-of-text
bne resum1
iny
jsr indtxt
bne resum1
jmp ready ;2 nulls, eot. bye!
resum1
ldy #3 ;new line, update pointers
jsr indtxt
sta curlin
iny
jsr indtxt
sta curlin+1
tya
clc
adc txtptr
sta txtptr
bcc resum2
inc txtptr+1
resum2
jsr chrget ;skip over this character, into body of statement
jmp data ;advance until null or ':', then rts
resnum
jsr getwrd
sta linnum+1
jsr resend
jmp luk4it
resswp
ldx #1
resum0
lda errlin,x
sta curlin,x
lda errtxt,x
sta txtptr,x
dex
bpl resum0
resend
ldx #$ff
stx errnum ;reset error status- he's saying he's fixed it
stx errlin
stx errlin+1 ;flag 'no further resumes until next error'
ldx tmptrp ;restore trap line to allow traps again
stx trapno+1
rts
ressnr jmp snerr
rescnt
ldx #errcr
jmp error
errd
jsr conint ;get integer arg in x
dex
txa
cmp #errlst ;check range
bcs errerr ;what would you call it?
jsr erstup
ldy #$ff
ldx #0
erflp1 ;count printing characters
inx
erflp3
iny
lda (index2),y ;ind.ok
bmi errd1 ;msb set means last
cmp #$20
bcc erflp3 ;don't count non-printers
bcs erflp1 ;count all others
errd1
txa
jsr strspa ;get space
ldx #0
ldy #$ff
erflp2 ;this time, move chars
iny
lda (index2),y ;ind.ok
cmp #$20
bcc erflp2
jsr swapxy
pha
and #$7f
sta (dsctmp+1),y
jsr swapxy
inx
pla ;test if msb was set
bpl erflp2
jmp chrd1 ;pla,pla,jmp putnew
errerr
jmp fcerr ;bad value
swapxy
pha
txa
pha
tya
tax
pla
tay
pla
rts
hexd
jsr chknum
lda poker
pha
lda poker+1
pha
jsr getadr ;2 byte val in (poker)
lda #4
jsr strspa
ldy #0
lda poker+1
jsr hexit
lda poker
jsr hexit
pla
sta poker+1
pla
sta poker
jmp chrd1 ;pla,pla,jmp putnew
hexit
pha
lsr a
lsr a
lsr a
lsr a
jsr dohex
pla
dohex
and #$0f
cmp #$0a
bcc dohex1
adc #6
dohex1
adc #'0'
sta (dsctmp+1),y
iny
rts
puctrl
jsr frmstr ;do frmevl,frestr. return with a=len, index=~string
tay
dey
cpy #4
bcs errerr ;len > 4 is error
puc60
jsr indin1 ;lda (index),y
sta puchrs,y
dey
bpl puc60
rts
;.end