339
|
1 /*
|
|
2 insn_tfm.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 #include <config.h>
|
|
22 #include <ctype.h>
|
|
23 #include <string.h>
|
|
24
|
|
25 #include "lwasm.h"
|
|
26 #include "instab.h"
|
|
27
|
357
|
28 PARSEFUNC(insn_parse_tfm)
|
339
|
29 {
|
|
30 static const char *reglist = "DXYUS AB 00EF";
|
|
31 int r0, r1;
|
|
32 char *c;
|
|
33 int tfm = 0;
|
|
34
|
|
35 c = strchr(reglist, toupper(*(*p)++));
|
|
36 if (!c)
|
|
37 {
|
357
|
38 lwasm_register_error(as, l, "Unknown operation");
|
339
|
39 return;
|
|
40 }
|
|
41 r0 = c - reglist;
|
|
42 if (**p == '+')
|
|
43 {
|
|
44 (*p)++;
|
|
45 tfm = 1;
|
|
46 }
|
|
47 else if (**p == '-')
|
|
48 {
|
|
49 (*p)++;
|
|
50 tfm = 2;
|
|
51 }
|
|
52 if (*(*p)++ != ',')
|
|
53 {
|
357
|
54 lwasm_register_error(as, l, "Unknown operation");
|
339
|
55 return;
|
|
56 }
|
|
57 c = strchr(reglist, toupper(*(*p)++));
|
|
58 if (!c)
|
|
59 {
|
357
|
60 lwasm_register_error(as, l, "Unknown operation");
|
339
|
61 return;
|
|
62 }
|
|
63 r1 = c - reglist;
|
|
64
|
|
65 if (**p == '+')
|
|
66 {
|
|
67 (*p)++;
|
|
68 tfm |= 4;
|
|
69 }
|
|
70 else if (**p == '-')
|
|
71 {
|
|
72 (*p)++;
|
|
73 tfm |= 8;
|
|
74 }
|
|
75
|
|
76 if (**p && !isspace(**p))
|
|
77 {
|
357
|
78 lwasm_register_error(as, l, "Bad operand");
|
339
|
79 return;
|
|
80 }
|
|
81
|
|
82 // valid values of tfm here are:
|
|
83 // 1: r0+,r1 (2)
|
|
84 // 4: r0,r1+ (3)
|
|
85 // 5: r0+,r1+ (0)
|
|
86 // 10: r0-,r1- (1)
|
|
87 switch (tfm)
|
|
88 {
|
|
89 case 5: //r0+,r1+
|
357
|
90 l -> lint = instab[l -> insn].ops[0];
|
339
|
91 break;
|
357
|
92
|
339
|
93 case 10: //r0-,r1-
|
357
|
94 l -> lint = instab[l -> insn].ops[1];
|
339
|
95 break;
|
357
|
96
|
339
|
97 case 1: // r0+,r1
|
357
|
98 l -> lint = instab[l -> insn].ops[2];
|
339
|
99 break;
|
357
|
100
|
339
|
101 case 4: // r0,r1+
|
357
|
102 l -> lint = instab[l -> insn].ops[3];
|
339
|
103 break;
|
357
|
104
|
339
|
105 default:
|
357
|
106 lwasm_register_error(as, l, "Unknown operation");
|
339
|
107 return;
|
|
108 }
|
357
|
109 l -> pb = (r0 << 4) | r1;
|
|
110 l -> len = OPLEN(l -> lint);
|
339
|
111 }
|
|
112
|
357
|
113 EMITFUNC(insn_emit_tfm)
|
|
114 {
|
|
115 lwasm_emitop(l, l -> lint);
|
|
116 lwasm_emit(l, l -> pb);
|
|
117 }
|
|
118
|
|
119 PARSEFUNC(insn_parse_tfmrtor)
|
339
|
120 {
|
|
121 int r0, r1;
|
|
122 static const char *regs = "D X Y U S A B 0 0 E F ";
|
|
123
|
|
124 // register to register (r0,r1)
|
|
125 // registers are in order:
|
|
126 // D,X,Y,U,S,PC,W,V
|
|
127 // A,B,CC,DP,0,0,E,F
|
|
128 r0 = lwasm_lookupreg2(regs, p);
|
|
129 if (r0 < 0 || *(*p)++ != ',')
|
|
130 {
|
357
|
131 lwasm_register_error(as, l, "Bad operand");
|
339
|
132 r0 = r1 = 0;
|
|
133 }
|
|
134 else
|
|
135 {
|
|
136 r1 = lwasm_lookupreg2(regs, p);
|
|
137 if (r1 < 0)
|
|
138 {
|
357
|
139 lwasm_register_error(as, l, "Bad operand");
|
339
|
140 r0 = r1 = 0;
|
|
141 }
|
|
142 }
|
357
|
143 l -> len = instab[l -> insn].ops[0] + 1;
|
|
144 l -> pb = (r0 << 4) | r1;
|
339
|
145 }
|
357
|
146
|
|
147 EMITFUNC(insn_emit_tfmrtor)
|
|
148 {
|
|
149 lwasm_emitop(l, instab[l -> insn].ops[0]);
|
|
150 lwasm_emit(l, l -> pb);
|
|
151 }
|