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