-
Notifications
You must be signed in to change notification settings - Fork 82
/
code9.src
271 lines (253 loc) · 3.24 KB
/
code9.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
.page
.subttl 'code9'
bmi docstr
bcs chkerr
chkok
rts
docstr
bcs chkok
chkerr
ldx #errtm
.byte $2c
sterr
ldx #errst
jmp error
frmevl
ldx txtptr ;txtptr points to 1st char. in formula
bne frmev1
dec txtptr+1
frmev1
dec txtptr
ldx #0 ;dummy precedence = 0
.byte $24
lpoper
pha ;save precedence
txa
pha
tsx ;confirm enough system stack available (recursive calls)
cpx #<sysstk+5 ;bottom of stack + 3*addprc + 2
bcc sterr ;formula too complex
jsr eval
lda #0
sta opmask
tstop
jsr chrgot ;last char
loprel
sec
sbc #greatk
bcc endrel
cmp #lesstk-greatk+1
bcs endrel
cmp #1
rol a
eor #1
eor opmask
cmp opmask
bcc snerr5
sta opmask
jsr chrget
jmp loprel
endrel
ldx opmask
bne finrel
bcs qop
adc #greatk-plustk
bcc qop
adc valtyp
bne *+5
jmp cat
adc #$ff
sta index1
asl a
adc index1
tay
qprec
pla
cmp optab,y
bcs qchnum
jsr chknum
doprec
pha
negprc
jsr dopre1
pla
ldy opptr
bpl qprec1
tax
beq qopgo
bne pulstk
finrel
lsr valtyp
txa
rol a
ldx txtptr
bne finre2
dec txtptr+1
finre2
dec txtptr
ldy #ptdorl-optab
sta opmask
bne qprec ;bra
qprec1
cmp optab,y ;check precedence
bcs pulstk
bcc doprec
dopre1
lda optab+2,y
pha
lda optab+1,y
pha
jsr pushf1
lda opmask
jmp lpoper
snerr5
jmp snerr
pushf1
lda facsgn ;save fac on stack unpacked
ldx optab,y ;precedence
tay
clc
pla ;pointer into stack
adc #1
sta index1
pla
adc #0
sta index1+1
tya
pha
jsr round ;put rounded fac on stack
lda faclo
pha
lda facmo
pha
lda facmoh
pha
lda facho
pha
lda facexp
pha
jmp (index1)
qop
ldy #255
pla
qopgo
beq qoprts
qchnum
cmp #100 ;relational operator?
beq unpstk
jsr chknum ;must be number
unpstk
sty opptr
pulstk
pla ;get mask for rel. op. if it is one
lsr a ;setup c for dorel's chkval
sta domask
pla ;unpack stack into arg
sta argexp
pla
sta argho
pla
sta argmoh
pla
sta argmo
pla
sta arglo
pla
sta argsgn
eor facsgn
sta arisgn ;sign used by add, sub, mul, div
qoprts
lda facexp
rts
.page
eval
jmp (ieval)
neval
lda #0
sta valtyp ;assume numeric
eval0
jsr chrget ;get a character
bcs eval2
eval1
jmp fin ;it is a number
eval2
jsr isletc ;variable name?
bcc *+5
jmp isvar
cmp #pi ;pi?
bne qdot
lda #<pival
ldy #>pival
jsr movfm
jmp chrget
pival
.byte @202,@111,@017,@332,@241
qdot
cmp #'.' ;constant?
beq eval1
cmp #minutk ;negation?
beq domin
cmp #plustk
beq eval0
cmp #'"' ;string?
bne eval3
strtxt
lda txtptr
ldy txtptr+1
adc #0 ;c=1
bcc strtx2
iny
strtx2
jsr strlit ;process string
jmp st2txt
eval3
cmp #nottk ;not?
bne eval4
ldy #24
bne gonprc ;bra
notop
jsr ayint ;integerize
lda faclo ;get argument
eor #$ff
tay
lda facmo
eor #$ff
givayf
jsr stoint ;integer to float routine
jmp floats
eval4
cmp #fntk ;user defined function?
bne *+5
jmp fndoer
cmp #onefun ;function name?
bcc parchk
jmp isfun
parchk
jsr chkopn ;only thing left is formula in parens
jsr frmevl
chkcls
lda #')' ;close paren?
.byte $2c
chkopn
lda #'(' ;open paren?
.byte $2c
chkcom
lda #',' ;comma?
synchr
ldy #0
sta syntmp
jsr indtxt
cmp syntmp
bne snerr
jmp chrget ;ok
snerr
ldx #errsn ;'syntax error'
jmp error
negoff =negtab-optab
domin
ldy #negoff ;precedence below '-'
gonprc
pla
pla
jmp negprc ;do negation
;end