339
|
1 /*
|
|
2 insn_bitbit.c
|
|
3 Copyright © 2009 William Astle
|
|
4
|
|
5 This file is part of LWASM.
|
|
6
|
|
7 LWASM is free software: you can redistribute it and/or modify it under the
|
|
8 terms of the GNU General Public License as published by the Free Software
|
|
9 Foundation, either version 3 of the License, or (at your option) any later
|
|
10 version.
|
|
11
|
|
12 This program is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
15 more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License along with
|
|
18 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 */
|
|
20
|
|
21 /*
|
|
22 for handling inherent mode instructions
|
|
23 */
|
|
24
|
|
25 #define __insn_bitbit_c_seen__
|
|
26
|
|
27 #include <config.h>
|
|
28 #include <stdlib.h>
|
|
29
|
|
30 #include "lwasm.h"
|
|
31 #include "instab.h"
|
|
32 #include "expr.h"
|
|
33
|
|
34 // these instructions cannot tolerate external references
|
|
35 OPFUNC(insn_bitbit)
|
|
36 {
|
|
37 int r;
|
|
38 lwasm_expr_stack_t *s;
|
|
39 int v1;
|
|
40 int tv;
|
|
41
|
|
42 lwasm_emitop(as, l, instab[opnum].ops[0]);
|
|
43
|
|
44 r = toupper(*(*p)++);
|
|
45 if (r == 'A')
|
|
46 r = 1;
|
|
47 else if (r == 'B')
|
|
48 r = 2;
|
|
49 else if (r == 'C' && toupper(**p) == 'C')
|
|
50 {
|
|
51 r = 0;
|
|
52 (*p)++;
|
|
53 }
|
|
54 else
|
|
55 {
|
|
56 register_error(as, l, 1, "Bad register");
|
|
57 return;
|
|
58 }
|
|
59 if (*(*p)++ != ',')
|
|
60 {
|
|
61 register_error(as, l, 1, "Bad operand");
|
|
62 return;
|
|
63 }
|
|
64 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
|
|
65 if (!s)
|
|
66 {
|
|
67 register_error(as, l, 1, "Bad operand");
|
|
68 return;
|
|
69 }
|
|
70 if (!lwasm_expr_is_constant(s))
|
|
71 {
|
|
72 register_error(as, l, 2, "Incomplete reference");
|
|
73 }
|
|
74 v1 = lwasm_expr_get_value(s);
|
|
75 lwasm_expr_stack_free(s);
|
|
76 if (v1 < 0 || v1 > 7)
|
|
77 {
|
|
78 register_error(as, l, 2, "Invalid bit number");
|
|
79 v1 = 0;
|
|
80 }
|
|
81 if (*(*p)++ != ',')
|
|
82 {
|
|
83 register_error(as, l, 1, "Bad operand");
|
|
84 return;
|
|
85 }
|
|
86 r = (r << 6) | (v1 << 3);
|
|
87
|
|
88 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
|
|
89 if (!s)
|
|
90 {
|
|
91 register_error(as, l, 1, "Bad operand");
|
|
92 return;
|
|
93 }
|
|
94 if (!lwasm_expr_is_constant(s))
|
|
95 {
|
|
96 register_error(as, l, 1, "Incomplete reference");
|
|
97 }
|
|
98 v1 = lwasm_expr_get_value(s);
|
|
99 lwasm_expr_stack_free(s);
|
|
100 if (v1 < 0 || v1 > 7)
|
|
101 {
|
|
102 register_error(as, l, 2, "Invalid bit number");
|
|
103 v1 = 0;
|
|
104 }
|
|
105 if (*(*p)++ != ',')
|
|
106 {
|
|
107 register_error(as, l, 1, "Bad operand");
|
|
108 return;
|
|
109 }
|
|
110 r |= v1;
|
|
111
|
|
112 lwasm_emit(as, l, r);
|
|
113
|
|
114 // ignore base page address modifier
|
|
115 if (**p == '<')
|
|
116 (*p)++;
|
|
117
|
|
118 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
|
|
119 if (!s)
|
|
120 {
|
|
121 register_error(as, l, 1, "Bad operand");
|
|
122 return;
|
|
123 }
|
|
124 if (!lwasm_expr_is_constant(s))
|
|
125 {
|
|
126 register_error(as, l, 1, "Incomplete reference");
|
|
127 }
|
|
128 v1 = lwasm_expr_get_value(s);
|
|
129 lwasm_expr_stack_free(s);
|
|
130 v1 &= 0xFFFF;
|
|
131
|
|
132 tv = v1 - ((as -> dpval) << 8);
|
|
133 if (tv > 0xFF || tv < 0)
|
|
134 {
|
|
135 register_error(as, l, 2, "Byte overflow");
|
|
136 }
|
|
137 lwasm_emit(as, l, tv & 0xff);
|
|
138 }
|