Mercurial > hg-old > index.cgi
comparison lwasm/insn_tfm.c @ 357:0cf4948d53b4
Checkpoint - adding actual cpu instructions
author | lost@starbug |
---|---|
date | Wed, 31 Mar 2010 20:12:20 -0600 |
parents | old-trunk/lwasm/old/insn_tfm.c@eb230fa7d28e |
children |
comparison
equal
deleted
inserted
replaced
356:7166254491ed | 357:0cf4948d53b4 |
---|---|
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 | |
28 PARSEFUNC(insn_parse_tfm) | |
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 { | |
38 lwasm_register_error(as, l, "Unknown operation"); | |
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 { | |
54 lwasm_register_error(as, l, "Unknown operation"); | |
55 return; | |
56 } | |
57 c = strchr(reglist, toupper(*(*p)++)); | |
58 if (!c) | |
59 { | |
60 lwasm_register_error(as, l, "Unknown operation"); | |
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 { | |
78 lwasm_register_error(as, l, "Bad operand"); | |
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+ | |
90 l -> lint = instab[l -> insn].ops[0]; | |
91 break; | |
92 | |
93 case 10: //r0-,r1- | |
94 l -> lint = instab[l -> insn].ops[1]; | |
95 break; | |
96 | |
97 case 1: // r0+,r1 | |
98 l -> lint = instab[l -> insn].ops[2]; | |
99 break; | |
100 | |
101 case 4: // r0,r1+ | |
102 l -> lint = instab[l -> insn].ops[3]; | |
103 break; | |
104 | |
105 default: | |
106 lwasm_register_error(as, l, "Unknown operation"); | |
107 return; | |
108 } | |
109 l -> pb = (r0 << 4) | r1; | |
110 l -> len = OPLEN(l -> lint); | |
111 } | |
112 | |
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) | |
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 { | |
131 lwasm_register_error(as, l, "Bad operand"); | |
132 r0 = r1 = 0; | |
133 } | |
134 else | |
135 { | |
136 r1 = lwasm_lookupreg2(regs, p); | |
137 if (r1 < 0) | |
138 { | |
139 lwasm_register_error(as, l, "Bad operand"); | |
140 r0 = r1 = 0; | |
141 } | |
142 } | |
143 l -> len = instab[l -> insn].ops[0] + 1; | |
144 l -> pb = (r0 << 4) | r1; | |
145 } | |
146 | |
147 EMITFUNC(insn_emit_tfmrtor) | |
148 { | |
149 lwasm_emitop(l, instab[l -> insn].ops[0]); | |
150 lwasm_emit(l, l -> pb); | |
151 } |