-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathcrunch.src
208 lines (200 loc) · 4.06 KB
/
crunch.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
.page
.subttl 'crunch 30dec83'
; crunch
;
; entry: txtptr points to start of text to crunch
; exit: txtptr points to start of crunched text
; calls: chrget
; chrgot
; reser
; kloop
; rem
; data
; collapses all reserved words to tokens. does
; not alter data or rem. removes all graphic
; characters not in quoted strings
;
;
; an escape token is implemented as follows:
;
; as each character on a line of text to be crunched is scanned, an
; indirect jump is performed. anyone wishing to scan for their own
; commands should grab off this vector, saving the return vector.
; on entry, if the carry flag is set, it is still up for grabs.
; the current text pointer is at txtptr. if the escape
; routine recognizes the command, it should:
;
; ) put the length of the reserved word in y
; ) put the desired 'second' token in a
; ) clear the carry flag
;
; if it is not your command, leave the acc. and the carry
; flag intact. note: the reserved word *must* be >= 2 charcters
; long. exit through the old vector (for daisy chaining). if
; the carry flag is clear on entry, it means someone else
; before you recognizes this command. in this case, just pass
; control through the old vector
crunch
jmp (icrnch)
ncrnch
lda txtptr ;save old text loc
pha
lda txtptr+1
pha
crun05
jsr chrgot
jmp crun20
crun10
jsr chrget
crun20
bcc crun10 ;don't crunch numbers
jmp (iesclk) ;give others a chance at this. carry is set.
nesclk
bcc crun95 ;carry clear if someone wanted it
cmp #0 ;end of line?
beq crun90 ;yes...
cmp #':' ;multi-stmt char?
beq crun10
cmp #'?' ;print abreviation?
bne crun30 ;no...
lda #printk ;substitute print token
bne crun75 ;branch always
crun30
cmp #$80 ;graphics?
bcc crun40 ;no...
cmp #pi ;yes...pi?
beq crun10 ;o.k....leave alone
ldy #1
jsr kloop ;crunch out graphics
beq crun05 ;branch always
crun40
cmp #'"' ;quote string?
bne crun60 ;no...
crun50
jsr chrget
cmp #0 ;end of line?
beq crun90 ;yes...
cmp #'"' ;close quote?
beq crun10 ;yes...
bne crun50 ;no...
crun60
jsr reser ;reserved word?
bcc crun10
cpy #0 ;anything to move?
beq crun70 ;no...
jsr kloop ;crunch it out
crun70
lda count ;put token...
crun75
ldy #0
sta (txtptr),y ;in text
cmp #remtk
beq crun80
cmp #datatk
bne crun10
jsr chrget
jsr data
jmp crun05
crun80
jsr chrget
jsr rem
;
; no other statements can follow a rem
;
crun90 ldx txtptr
pla
sta txtptr+1
pla
sta txtptr
sec ;compute length of line
txa
sbc txtptr
tay
iny
rts
crun95 ;crunch out old text, install an escape token
pha ;save second token
dey
dey ;waste (# of chars) - 2
jsr kloop
ldy #0
lda #esctk
sta (txtptr),y ;install escape token...
iny
pla
sta (txtptr),y ;..and second token
jsr chrget ;skip over token
jmp crun10 ;and continue with line
.page
; kloop
;
; crunch loop. moves offset .y characters
; from txtptr to end of line
kloop
clc ;compute source address
tya
adc txtptr
sta index1
lda txtptr+1
adc #0
sta index1+1
ldy #0
kloop2
jsr indin1 ;move source
sta (txtptr),y ;to destination offset
iny
cmp #0 ;end of line?
bne kloop2 ;no...
rts
.page
; reser
;
; search reserved word list for a match
; entry: (txtptr) is first char of word to match
; exit: .y=length of word matched
; .c=success/fail (set/clear) flag
; count=token value
reser
lda #>reslst ;start search here
ldy #<reslst
sta index1+1
sty index1
ldy #0
sty count
dey
rese10
iny
rese20
jsr indtxt
sec
sbc (index1),y ;does letter match? (ind.ok)
beq rese10 ;yes...continue
cmp #$80 ;no....end of word?
beq rese60 ;yes...c set...done
;
; find next word
;
rese30
lda (index1),y ;ind.ok
bmi rese40 ;found end of current
iny
bne rese30
rese40 iny ;start of next
inc count ;value of token
clc
tya
adc index1
sta index1
bcc rese50
inc index1+1
rese50 clc
ldy #0
lda (index1),y ; end of list? ind.ok
bne rese20 ;no...
;
; yes...carry clear...fail
;
rese60 ora count ;.a=$80 if match
sta count ;token is formed
rts
;.end