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