-
Notifications
You must be signed in to change notification settings - Fork 84
/
ifendif.src
275 lines (273 loc) · 6.53 KB
/
ifendif.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
;
;
;***************************************************************************
; directive_ife
;***************************************************************************
directive_ife
jsr numeric_conditional_eval eval
bcs false_conditional false iff error
lda value if value <> 0
ora value+1
bne false_conditional false
beq true_conditional go true
;
;***************************************************************************
; directive_ifn
;***************************************************************************
directive_ifn
jsr numeric_conditional_eval eval
bcs false_conditional flase iff error
lda value if == 0
ora value+1
beq false_conditional false
bne true_conditional true
;
;***************************************************************************
; directive_ifge
;***************************************************************************
directive_ifge
jsr numeric_conditional_eval eval
bcs false_conditional false iff error
lda value+1 if < 0
bmi false_conditional false
bpl true_conditional true
;
;***************************************************************************
; directive_ifgt
;***************************************************************************
directive_ifgt
jsr numeric_conditional_eval eval
bcs false_conditional false iff error
lda value+1 if < 0
bmi false_conditional false
ora value if == 0
beq false_conditional false
bne true_conditional true
;
;***************************************************************************
; directive_ifle
;***************************************************************************
directive_ifle
jsr numeric_conditional_eval eval
bcs false_conditional false iff error
lda value+1 if < 0
bmi true_conditional true
ora value if <> 0
bne false_conditional false
beq true_conditional true
;
;***************************************************************************
; directive_iflt
;***************************************************************************
directive_iflt
jsr numeric_conditional_eval eval
bcs false_conditional false iff error
lda value+1 if >= 0
bpl false_conditional false
; bmi true_conditional true
;
true_conditional
jmp true_1
;
false_conditional
jmp false_1
;
;
;***************************************************************************
; directive_ifb
;***************************************************************************
;
directive_ifb
jsr macro_conditional_eval
lda nargs
beq true_conditional
ldy #0
lda (args),y
beq true_conditional
bne false_conditional
;
;***************************************************************************
; directive_ifnb
;***************************************************************************
;
directive_ifnb
jsr macro_conditional_eval
lda nargs
beq false_conditional
ldy #0
lda (args),y
beq false_conditional
bne true_conditional
;
;***************************************************************************
; directive_ifdef
;***************************************************************************
;
directive_ifdef
jsr macro_conditional_eval
lda nargs
beq false_conditional
ldd args
jsr is_symbol_defined
bcs false_conditional
bcc true_conditional
;
;***************************************************************************
; directive_ifndef
;***************************************************************************
directive_ifndef
jsr macro_conditional_eval
lda nargs
beq false_conditional
ldd args
jsr is_symbol_defined
bcc false_conditional
bcs true_conditional
;
;***************************************************************************
; directive_ifnidn
;***************************************************************************
directive_ifnidn
jsr macro_conditional_eval
ldx nargs
beq false_conditional
dex
beq true_conditional
jsr idn_check
bne true_conditional
beq false_conditional
;
;***************************************************************************
; directive_ifidn
;***************************************************************************
directive_ifidn
jsr macro_conditional_eval
ldx nargs
beq true_conditional
dex
beq false_conditional
jsr idn_check
beq true_conditional
bne false_conditional
;
idn_check
ldd args
phd
ldx #args
jsr string_advance
pld
ldy #args
jmp strcmp
;
;
;
macro_conditional_eval
inc conditional_depth
jsr macro_parse_args_for_expansion ; copies args to macro_args
ldi macro_args ; set argsto point to macro args
std args
rts
;
numeric_conditional_eval
inc conditional_depth
jsr comma_delimit_args
ldd args
jsr eval
php
ldd value
jsr list_equate
plp
rts
;
;
;;
;
;******************************************************************************
; .endif directive
;******************************************************************************
;
directive_endif
lda conditional_depth
bne 10$
jmp outerr_n
;
10$ dec conditional_depth
;
;****************************************************************************
; true conditional
;****************************************************************************
;
directive_if_list_check
true_1
;
lda list_enable_conditional
beq 20$
jsr un_set_list
20$ sec
rts
;
;******************************************************************************
; .else directive
;******************************************************************************
;
directive_else
lda conditional_depth
bne false_1
jmp outerr_n
;
;
;****************************************************************************
; false conditional
;****************************************************************************
;
ram embedded_conditional_count
;
false_1 jsr directive_if_list_check unlist if not to do that
lda #1
sta embedded_conditional_count
;
10$ jsr read_line do read a line
bcc 20$ if EOF
rts return sec ( no bytes used )
;
20$ ldi line send to lister
jsr set_list
;
jsr directive_if_list_check unlist if not to do that
;
30$ jsr delimit_label_oper delimit the operator
jsr oper_toupper force it to upper case
;
ldi text_endif if oper == ".ENDIF"
ldy #oper
jsr strcmp
bne 40$
; dec nest count
dec embedded_conditional_count
bne 10$ if <> 0
; loop
dec conditional_depth dec global endif count
sec return no bytes used
rts
;
40$ ldi text_else if oper == ".ELSE"
ldy #oper
jsr strcmp
bne 50$
lda embedded_conditional_count if nest count <> 1
cmp #1
bne 10$ loop
;
sec return no bytes used
rts
;
50$ ldi 200$ if oper doesn;t start with ".IF"
ldy #oper
jsr strstrt
bcs 10$ loop
;
inc embedded_conditional_count nest count++
jmp 10$
;
200$ .byte ".IF",0
;