-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathrenumber
379 lines (379 loc) · 7.62 KB
/
renumber
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
.PAG 'RENUMBER'
;********************************************
;* *
;* RENUMBER *
;* *
;* SYNTAX: *
;* RENUMBER [N1[,N2[,N3]]] *
;* N1 =NEW START LINE NUMBER, DEFAULT 10 *
;* N2 =LINE INCREMENT, DEFAULT 10 *
;* N3 =START LINE, DEFAULT FIRST *
;* *
;* SYNTAX ERROR MAY OCCUR FOR MISSING COMMAS*
;* OR BAD LINE NUMBERS *
;* ILLEGAL QUANTITY ERROR FOR LINE INCREMENT*
;* ZERO AND BAD RENUMBER RANGE *
;* OVERFLOW ERROR IF INCREMENT WRAPS LINE *
;* NUMBER DURING RENUMBER *
;* *
;* RETURNS TO READY MODE ON COMPLETION OF *
;* RENUMBER *
;* *
;********************************************
.SKI 3
; THE RENUMBER ALGORITHMN EXAMINES THE ENTIRE STATEMENT
; TABLE FIRST FOR EMBEDDED LINE NUMBERS (BRANCHES) TO
; FIX. THIS IS DONE BY LOOKING FOR KEYWORDS (GOTO, GOSUB,
; THEN, RUN) WHICH ARE USUALLY FOLLOWED BY LINE NUMBERS.
;
; THE OLD LINE NUMBER IS MAPPED TO A NEW VALUE AND THE
; STRING REPRESENTING THE NEW BRANCH LABEL REPLACES THE
; ORIGINAL TEXT. AFTER COMPLETING THIS FIRST PASS OVER THE
; TABLE, A SECOND PASS IS MADE TO REPLACE THE STATEMENT
; NUMBER BYTES BY THEIR FINAL VALUES. LASTLY, THE TABLE
; IS RELINKED.
;
.SKI 4
TESTWD .BYT 0,TKGOTO,TKRUN,TKGOSU,TKTHEN,TKREST,TKRESU,TKTRAP
RENUM LDA #0 ;LINE #10...
LDX #10
STX FRESPC ;DEFAULT RENUM ORIGIN...
STA FRESPC+1
STX FRETOP ;DEFAULT INCREMENT...
STA FRETOP+1
STA HIGHTR ;DEFAULT START LINE#
STA HIGHTR+1
JSR CHRGOT ;ANY PARMS?
BEQ REN010 ;NO...
JSR LINGET ;YES...GET NEW ORIGIN
LDA LINNUM
LDX LINNUM+1
STA FRESPC
STX FRESPC+1
JSR CHRGOT ;ANY MORE PARMS?
BEQ REN010 ;NO...DEFAULT REST...
JSR CHKCOM ;MUST BE COMMA
JSR LINGET ;GET NEW INCREMENT
LDA LINNUM
LDX LINNUM+1
STA FRETOP
STX FRETOP+1
BNE REN005 ;INCREMENT IS O.K.
TAX ;TEST LO BYTE
BNE REN005 ;INCREMENT IS NON-ZERO...
REN004 JMP FCERR ;ILLEGAL QUANTITY ERROR...
REN005 JSR CHRGOT ;MORE PARMS?
BEQ REN010 ;NO...
JSR CHKCOM ;YES...MUST BE COMMA
JSR LINGET ;GET START LINE
LDA LINNUM
LDX LINNUM+1
STA HIGHTR
STX HIGHTR+1
JSR FNDLIN ; TEST FOR ILLEGAL RENUM RANGE
LDA LOWTR ;^1ST STMT TO RENUMBER
LDX LOWTR+1
STA HIGHDS
STX HIGHDS+1
LDA FRESPC
LDX FRESPC+1
STA LINNUM
STX LINNUM+1
JSR FNDLIN ;LOWTR := ^1ST STMT TO BE OVERLAPPED
LDA LOWTR+1 ;CAN'T BE SMALLER
SEC
SBC HIGHDS+1
BCC REN004 ;BAD...
BNE REN010 ;OK, DO RENUMBER
LDA LOWTR
SBC HIGHDS
BCC REN004 ;BAD...
REN010 JSR STXTPT ;START AT FIRST LINE
;
AD7640 JSR CHARGT ;SKIP LINKS
BNE AD7668
JSR CHARGT
BNE AD7669 ;NOT LAST (NULL) LINK
JSR AD7730 ;PUT CURRENT LIN # IN FAC
AD764B JSR CHARGT ;SKIP LINK
BNE AD7655
JSR CHARGT
BNE AD7656 ;NOT NULL LINK
JMP SUBCLR ;LAST ONE...DONE
;
AD7655 JSR CHARGT
AD7656 JSR CHARGT
STA LINNUM ;IF LINE# >= START#, REPLACE WITH FACHO
INY
LDA (TXTPTR)Y
SEC
SBC HIGHTR+1
BCC AD7658 ;NO, LET ALONE
BNE AD7657 ;YES, REPLACE
LDA LINNUM
SBC HIGHTR
BCC AD7658 ;NO, LET ALONE
AD7657 LDA FACHO
STA (TXTPTR)Y ;HI
DEY
LDA FACHO+1
STA (TXTPTR)Y ;LO
JSR CHARGT ;SKIP PAST 2ND BYTE OF LINE#
JSR AD773B ;INCR LINE# AND SCAN TO EOL
BEQ AD764B ;ALWAYS...
AD7658 JSR CHARGT ;SKIP PAST LINE#
JSR AD774A ;SCAN TO EOL
BEQ AD764B ;ALWAYS...
;
AD7668 JSR CHARGT
AD7669 JSR CHARGT ;MOVE ON
JSR CHARGT
AD766F JSR CHARGT ;ONE MORE
AD7672 CMP #$22 ;OPENING DOUBLE QUOTE?
BNE AD7681 ;NO...
AD7676 JSR CHARGT ;SCAN LINE
BEQ AD7640 ;END...
CMP #$22 ;CLOSE DOUBLE QUOTE
BNE AD7676 ;NO... CONTINUE
BEQ AD766F ;YES... RESUME RENUMBER
AD7681 TAX ;END OF LINE?
BEQ AD7640 ;YES...
BPL AD766F ;NOT A TOKEN...
LDX #$07 ;CHECK SPECIAL TOKEN LIST
AD7688 CMP TESTWD,X
BEQ AD7692 ;A MATCH...
DEX
BNE AD7688 ;CONTINUE UNTIL ZERO
BEQ AD766F ;NOT SPECIAL...CONTINUE
AD7692 LDA TXTPTR ;SAVE CURRENT TXTPTR
STA OLDLIN
LDA TXTPTR+1
STA OLDLIN+1
JSR CHRGET
AD769D BCS AD7672 ;NOT A #...
JSR LINGET ;GET LINE # FROM TEXT
JSR AD76DA ;TEST FOR 'ON'
LDA OLDLIN ;RESTORE OLD TXTPTR
STA TXTPTR
LDA OLDLIN+1
STA TXTPTR+1
LDY #0
LDX #0
AD76B1 LDA FBUFFR+1,X ;GET CHARACTER FROM NUMBER
BEQ AD76C7 ;END OF NUMBER
PHA ;SAVE DIGIT FROM NEW NUMBER
JSR CHRGET ;GET DIGIT FROM OLD NUMBER
AD76BA BCC AD76BF ;DIGIT...MOVE ON
JSR AD7706 ;OTHER CHAR...MOVE UP
AD76BF PLA
LDY #0
STA (TXTPTR)Y ;PUT NEW DIGIT IN NEW NUMBER
INX
BNE AD76B1 ;BRANCH ALWAYS
;
AD76C7 JSR CHRGET
AD76CA BCS AD76D4 ;OLD STUFF AFTER # IS OTHER CHAR
AD76CC JSR AD7715 ;DIGIT...MOVE DOWN
JSR CHRGOT
BCC AD76CC ;STILL DIGITS...
AD76D4 CMP #$2C ;COMMA FROM 'ON'?
BEQ AD7692 ;IT IS...
BNE AD7672 ;NO...
;
AD76DA JSR AD7730
AD76DD JSR CHARGT ;NEW LINE, SKIP OVER LINK
BNE AD76EC
JSR CHARGT
BNE AD76ED
LDA #$FF ;END-OF-TABLE, USE FFFF FOR LINE#
STA FACHO
STA FACHO+1
BMI AD76FB ;ALWAYS
;
AD76EC JSR CHARGT
AD76ED JSR CHARGT
STA HIGHDS ;HIGHDS := CURRENT LINE# IN LOOP
CMP LINNUM
BNE AD76FE
JSR CHARGT
STA HIGHDS+1
CMP LINNUM+1
BNE AD7701
SEC ;IF LINNUM < START#, NO REMAPPING
SBC HIGHTR+1
BCC AD76F0
BNE AD76FB
LDA LINNUM
SBC HIGHTR
BCS AD76FB
AD76F0 LDA LINNUM ;USE SAME LINE#
STA FACHO+1
LDA LINNUM+1
STA FACHO
AD76FB LDX #$90 ;MAKE REPLACEMENT STRING
SEC
JSR FLOATC
JMP FOUT
AD76FE JSR CHARGT
AD7701 JSR AD773A ;SCAN TO END OF LINE
BEQ AD76DD ;ALWAYS
AD7702 RTS
;
AD7706 JSR AD7726
INC ARGMO
JSR AD755D
.IFN CC1 <
INC VARTAB
>
.IFE CC1 <
INC TXTEND
>
BNE AD7714
.IFN CC1 <
INC VARTAB+1
>
.IFE CC1 <
INC TXTEND+1
>
AD7714 RTS
.SKI 4
AD7715 JSR AD7726
DEC ARGMO
JSR AD7545
.IFN CC1 <
LDA VARTAB
>
.IFE CC1 <
LDA TXTEND
>
BNE AD7723
.IFN CC1 <
DEC VARTAB+1
>
.IFE CC1 <
DEC TXTEND+1
>
AD7723
.IFN CC1 <
DEC VARTAB
>
.IFE CC1 <
DEC TXTEND
>
RTS
.SKI 4
AD7726 JSR AD7529
LDY #0
STY COUNT
STY ARGMO
RTS
.SKI 4
AD7730 LDA FRESPC
STA FACHO+1
LDA FRESPC+1
STA FACHO
JMP STXTPT
.SKI 4
AD773A LDA HIGHDS+1 ;IF LINE# >= START#, INCR NEW#
SEC
SBC HIGHTR+1
BCC AD774A ;NOPE, JUST SCAN TO EOL
BNE AD773B
LDA HIGHDS
SBC HIGHTR
BCC AD774A
AD773B LDA FACHO+1 ;INCREMENT NEW LINE#
CLC
ADC FRETOP
STA FACHO+1
LDA FACHO
ADC FRETOP+1
STA FACHO
AD774A JSR CHARGT ;SCAN TO END OF LINE
BNE AD774A
RTS
.SKI 4
CHARGT LDY #0
INC TXTPTR
BNE AD7758
INC TXTPTR+1
AD7758 LDA (TXTPTR)Y
RTS
.SKI 4
AD7529 LDA TXTPTR
STA INDEX1
LDA TXTPTR+1
STA INDEX1+1
.IFN CC1 <
LDA VARTAB
>
.IFE CC1 <
LDA TXTEND
>
STA INDEX2
.IFN CC1 <
LDA VARTAB+1
>
.IFE CC1 <
LDA TXTEND+1
>
STA INDEX2+1
RTS
.SKI 4
AD753A LDA INDEX1
CMP INDEX2
BNE AD7544
LDA INDEX1+1
CMP INDEX2+1
AD7544 RTS
.SKI 4
AD7545 LDY COUNT
INY
LDA (INDEX1)Y
LDY ARGMO
INY
STA (INDEX1)Y
JSR AD753A
BNE AD7555
RTS
AD7555 INC INDEX1
BNE AD7545
INC INDEX1+1
BNE AD7545
.SKI 4
AD755D LDY COUNT
LDA (INDEX2)Y
LDY ARGMO
STA (INDEX2)Y
JSR AD753A
BNE AD756B
RTS
AD756B LDA INDEX2
BNE AD7571
DEC INDEX2+1
AD7571 DEC INDEX2
JMP AD755D
.SKI 4
SUBCLR JSR LNKPRG
LDA INDEX1
LDX INDEX1+1
CLC
ADC #$02
.IFN CC1 <
STA VARTAB
>
.IFE CC1 <
STA TXTEND
>
BCC AD72B6
INX
AD72B6
.IFN CC1 <
STX VARTAB+1
>
.IFE CC1 <
STX TXTEND+1
>
JSR RUNC
JMP READY
.END