annotate src/pseudo.c @ 52:b9856da2674a

Added file inclusion
author lost
date Sun, 04 Jan 2009 20:16:38 +0000
parents e672232caffe
children 493cb8ea50a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
1 /*
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
2 pseudo.c
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
3 Copyright © 2009 William Astle
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
5 This file is part of LWASM.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
6
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
8 terms of the GNU General Public License as published by the Free Software
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
10 version.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
11
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
15 more details.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
16
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
17 You should have received a copy of the GNU General Public License along with
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
19
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
20
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
21 This file implements the various pseudo operations.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
22 */
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 #include <stdlib.h>
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
25 #include <string.h>
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26 #include "lwasm.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
27 #include "instab.h"
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
28 #include "expr.h"
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
29 #include "util.h"
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
31 extern int lwasm_read_file(asmstate_t *as, const char *filename);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
33 OPFUNC(pseudo_org)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
34 {
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
35 int rval;
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
36 lwasm_expr_stack_t *s;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
37
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
38 if (as -> passnum != 1)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
39 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
40 // org is not needed to be processed on pass 2
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
41 // this will prevent phasing errors for forward references that
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
42 // resolve on the second pass
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
43 // we saved the org address in l -> codeaddr on pass 1
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
44 as -> addr = l -> codeaddr;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
45 return;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
46 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
47
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
48 if (l -> sym)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
49 {
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
50 register_error(as, l, 1, "No symbol allowed with ORG");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
51 }
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
52 s = lwasm_evaluate_expr(as, l, *p, NULL);
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
53 if (!s)
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
54 {
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
55 register_error(as, l, 1, "Bad expression");
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
56 return;
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
57 }
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
58 if (!lwasm_expr_is_constant(s))
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
59 {
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
60 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
61 lwasm_expr_stack_free(s);
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
62 return;
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
63 }
49
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
64 rval = lwasm_expr_get_value(s) & 0xffff;
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
65 lwasm_expr_stack_free(s);
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
66 l -> codeaddr = rval;
49
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
67 l -> addrset = 1;
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
68 as -> addr = rval;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
69 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
70
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
71 /*
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
72 The operand for include is a string optionally enclosed in "
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
73 */
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
74 OPFUNC(pseudo_include)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
75 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
76 int v1;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
77 char *fn;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
78
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
79 // only include files on pass 1
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
80 // but make sure local include context is right
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
81 // for the next line...
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
82 if (as -> passnum != 1)
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
83 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
84 as -> context += 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
85 return;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
86 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
87
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
88 while (**p && isspace(**p))
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
89 (*p)++;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
90
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
91 if (!**p)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
92 {
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
93 register_error(as, l, 1, "Bad file name");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
94 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
95 }
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
96
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
97 if (**p == '"')
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
98 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
99 // search for ending "
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
100 (*p)++;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
101 for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
102 /* do nothing */ ;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
103 if (*((*p)+v1) != '"')
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
104 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
105 register_error(as, l, 1, "Bad file name");
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
106 return;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
107 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
108 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
109 else
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
110 {
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
111 // search for a space type character
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
112 for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
113 ;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
114 }
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
115
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
116 fn = lwasm_alloc(v1 + 1);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
117 memcpy(fn, *p, v1);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
118 fn[v1] = '\0';
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
119
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
120 // end local label context on include
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
121 as -> context += 1;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
122 if (lwasm_read_file(as, fn) < 0)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
123 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
124 register_error(as, l, 1, "File include error (%s)", fn);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
125 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
126 lwasm_free(fn);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
127 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
128
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
129 OPFUNC(pseudo_rmb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
130 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
131 int rval;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
132 lwasm_expr_stack_t *s;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
133
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
134 s = lwasm_evaluate_expr(as, l, *p, NULL);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
135 if (!s)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
136 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
137 register_error(as, l, 1, "Bad expression");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
138 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
139 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
140 if (!lwasm_expr_is_constant(s))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
141 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
142 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
143 lwasm_expr_stack_free(s);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
144 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
145 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
146 rval = lwasm_expr_get_value(s);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
147 lwasm_expr_stack_free(s);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
148 l -> nocodelen = rval;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
149 as -> addr += rval;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
150 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
151 /*
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
152 void pseudo_rmd(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
153 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
154 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
155
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
156 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
157 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
158 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
159 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
160 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
161 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
162 if (v1 < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
163 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
164 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
165 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
166 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
167 cl -> len = v1 * 2;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
168 cl -> nocode = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
169 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
170
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
171 void pseudo_rmq(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
172 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
173 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
174
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
175 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
176 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
177 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
178 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
179 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
180 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
181 if (v1 < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
182 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
183 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
184 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
185 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
186 cl -> len = v1 * 4;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
187 cl -> nocode = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
188 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
189
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
190 void pseudo_zmb(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
191 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
192 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
193
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
194 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
195 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
196 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
197 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
198 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
199 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
200 if (v1 < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
201 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
202 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
203 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
204 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
205 while (v1--)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
206 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
207 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
208
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
209 void pseudo_zmd(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
210 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
211 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
212
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
213 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
214 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
215 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
216 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
217 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
218 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
219 if (v1 < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
220 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
221 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
222 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
223 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
224 while (v1--)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
225 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
226 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
227 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
228 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
229 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
230
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
231 void pseudo_zmq(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
232 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
233 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
234
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
235 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
236 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
237 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
238 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
239 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
240 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
241 if (v1 < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
242 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
243 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
244 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
245 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
246 while (v1--)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
247 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
248 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
249 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
250 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
251 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
252 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
253 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
254
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
255 void pseudo_end(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
256 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
257 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
258
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
259 while (**optr && isspace(**optr))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
260 ;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
261 if (**optr && **optr != '*' && **optr != ';')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
262 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
263 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
264 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
265 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
266 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
267 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
268 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
269 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
270 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
271 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
272 v1 = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
273 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
274 if (as -> passnum == 2)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
275 as -> execaddr = v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
276 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
277
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
278 void pseudo_align(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
279 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
280 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
281 int cn;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
282
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
283 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
284 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
285 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
286 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
287 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
288 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
289 cn = cl -> addr % v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
290 if (cn)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
291 cn = v1 - cn;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
292
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
293 while (cn)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
294 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
295 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
296 cn--;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
297 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
298 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
299 */
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
300 OPFUNC(pseudo_equ)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
301 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
302 lwasm_expr_stack_t *s;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
303 int rval;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
304
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
305 // equ is not needed to be processed on pass 2
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
306 if (as -> passnum != 1)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
307 return;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
308
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
309 if (l -> sym == NULL)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
310 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
311 register_error(as, l, 1, "No symbol specified");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
312 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
313 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
314
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
315 s = lwasm_evaluate_expr(as, l, *p, NULL);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
316
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
317 if (!s)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
318 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
319 register_error(as, l, 1, "Bad expression");
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
320 rval = 0;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
321 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
322 else
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
323 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
324 if (!lwasm_expr_is_constant(s))
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
325 register_error(as, l, 1, "Invalid incomplete reference (pass 1)");
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
326 rval = lwasm_expr_get_value(s);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
327 lwasm_expr_stack_free(s);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
328 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
329 l -> symaddr = rval & 0xFFFF;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
330 l -> addrset = 2;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
331 if (strchr(l -> sym, '@') || strchr(l -> sym, '?'))
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
332 lwasm_set_symbol(as, l -> sym, as -> context, l -> symaddr);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
333 else
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
334 lwasm_set_symbol(as, l -> sym, -1, l -> symaddr);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
335 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
336 /*
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
337 void pseudo_set(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
338 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
339 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
340
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
341 if (cl -> hassym == 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
342 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
343 errorp1(ERR_NOSYM);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
344 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
345 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
346 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
347 // eval_expr returns -1 if there was a forward ref
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
348 // or -2 if the expr was invalid
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
349 if (rval == -2)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
350 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
351 // carp
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
352 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
353 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
354 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
355 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
356 // remove symbol ref
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
357 cl -> hassym = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
358 // mark as a "comment" so it isn't processed next time
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
359 cl -> opcode = -1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
360 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
361 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
362 cl -> code_symloc = v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
363 cl -> isset = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
364 cl -> isequ = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
365 cl -> symaddr = v1 & 0xFFFF;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
366 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
367
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
368 void pseudo_setdp(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
369 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
370 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
371
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
372 if (cl -> hassym)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
373 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
374 register_error(as, cl, ERR_SYM);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
375 cl -> hassym = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
376 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
377 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
378 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
379 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
380 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
381 if (rval == -1)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
382 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
383 errorp1(ERR_FORWARD);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
384 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
385 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
386 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
387 cl -> opcode = -1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
388 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
389 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
390 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
391 // setdp needs to resolve properly on pass 2
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
392 if (v1 > 0xff || v1 < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
393 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
394 errorp1(ERR_OVERFLOW);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
395 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
396 as -> dpval = v1 & 0xff;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
397 cl -> dpval = v1 & 0xff;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
398 cl -> issetdp = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
399 cl -> numcodebytes = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
400 //printf("%s\n", "SETDP2");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
401 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
402
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
403 void pseudo_fcc(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
404 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
405 int cn = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
406 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
407
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
408 delim = *(*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
409 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
410 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
411 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
412 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
413 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
414 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
415 while (**optr && **optr != delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
416 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
417 emit(**optr);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
418 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
419 cn += 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
420 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
421 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
422 cl -> len = cn;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
423 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
424
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
425 void pseudo_fcs(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
426 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
427 int cn = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
428 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
429
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
430 delim = *(*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
431 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
432 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
433 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
434 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
435 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
436 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
437 while (**optr && **optr != delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
438 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
439 if (!*((*optr) + 1) || *((*optr) + 1) == delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
440 emit((**optr) | 0x80);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
441 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
442 emit(**optr);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
443 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
444 cn += 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
445 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
446 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
447 cl -> len = cn;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
448 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
449
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
450 void pseudo_fcn(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
451 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
452 int cn = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
453 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
454
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
455 delim = *(*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
456 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
457 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
458 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
459 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
460 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
461 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
462 while (**optr && **optr != delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
463 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
464 emit(**optr);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
465 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
466 cn += 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
467 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
468 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
469 emit(0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
470 cl -> len = cn + 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
471 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
472
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
473 void pseudo_fcb(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
474 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
475 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
476
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
477 fcb_again:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
478 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
479 if (v1 < -127 || v1 > 0xff)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
480 errorp2(ERR_OVERFLOW);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
481 emit(v1 & 0xff);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
482 if (**optr == ',')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
483 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
484 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
485 goto fcb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
486 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
487 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
488
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
489 void pseudo_fdb(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
490 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
491 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
492
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
493 fdb_again:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
494 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
495 emit((v1 >> 8) & 0xff);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
496 emit(v1 & 0xff);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
497 if (**optr == ',')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
498 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
499 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
500 goto fdb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
501 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
502 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
503
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
504 void pseudo_fqb(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
505 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
506 int rval, v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
507
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
508 fqb_again:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
509 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
510 emit((v1 >> 24) & 0xff);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
511 emit((v1 >> 16) & 0xff);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
512 emit((v1 >> 8) & 0xff);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
513 emit(v1 & 0xff);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
514 if (**optr == ',')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
515 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
516 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
517 goto fqb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
518 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
519 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
520
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
521 // don't need to do anything if we are executing one of these
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
522 void pseudo_endc(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
523 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
524 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
525 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
526
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
527 // if "else" executes, we must be going into an "ignore" state
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
528 void pseudo_else(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
529 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
530 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
531 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
532 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
533
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
534 void pseudo_ifne(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
535 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
536 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
537 int rval;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
538 // printf("ifne %s\n", *optr);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
539 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
540 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
541 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
542 errorp1(ERR_BADCOND);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
543 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
544 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
545 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
546 // printf("Condition value: %d\n", v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
547 if (!v1)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
548 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
549 // printf("condition no match\n");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
550 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
551 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
552 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
553 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
554 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
555 void pseudo_ifeq(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
556 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
557 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
558 int rval;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
559
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
560 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
561 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
562 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
563 errorp1(ERR_BADCOND);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
564 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
565 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
566 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
567 if (v1)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
568 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
569 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
570 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
571 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
572 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
573 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
574 void pseudo_iflt(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
575 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
576 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
577 int rval;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
578
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
579 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
580 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
581 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
582 errorp1(ERR_BADCOND);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
583 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
584 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
585 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
586 if (v1 >= 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
587 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
588 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
589 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
590 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
591 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
592 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
593 void pseudo_ifle(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
594 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
595 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
596 int rval;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
597
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
598 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
599 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
600 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
601 errorp1(ERR_BADCOND);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
602 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
603 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
604 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
605 if (v1 > 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
606 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
607 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
608 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
609 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
610 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
611 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
612 void pseudo_ifgt(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
613 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
614 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
615 int rval;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
616
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
617 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
618 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
619 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
620 errorp1(ERR_BADCOND);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
621 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
622 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
623 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
624 if (v1 <= 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
625 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
626 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
627 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
628 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
629 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
630 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
631 void pseudo_ifge(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
632 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
633 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
634 int rval;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
635
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
636 rval = eval_expr(as, cl, optr, &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
637 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
638 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
639 errorp1(ERR_BADCOND);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
640 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
641 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
642 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
643 if (v1 < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
644 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
645 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
646 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
647 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
648 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
649 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
650
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
651 void pseudo_error(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
652 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
653 cl -> user_error = strdup(*optr);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
654 errorp1(ERR_USER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
655 }
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
656 */