annotate src/insn_tfm.c @ 97:2e8dda44027c

Bumped package version to 2.0
author lost
date Sat, 17 Jan 2009 07:09:15 +0000
parents 74a3fef7c8d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
1 /*
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
2 insn_tfm.c
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 32
diff changeset
3 Copyright © 2009 William Astle
31
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
4
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
5 This file is part of LWASM.
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
6
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
10 version.
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
11
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
15 more details.
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
16
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
19 */
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
20
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
21 /*
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
22 for handling inherent mode instructions
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
23 */
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
24
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 31
diff changeset
25 #define __insn_tfm_c_seen__
31
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
26
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
27 #include <ctype.h>
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
28 #include <string.h>
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
29
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
30 #include "lwasm.h"
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
31 #include "instab.h"
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
32
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
33 OPFUNC(insn_tfm)
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
34 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
35 static const char *reglist = "DXYUS AB 00EF";
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
36 int r0, r1;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
37 char *c;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
38 int tfm = 0;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
39
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
40 c = strchr(reglist, toupper(*(*p)++));
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
41 if (!c)
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
42 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
43 register_error(as, l, 1, "Unknown operation");
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
44 return;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
45 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
46 r0 = c - reglist;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
47 if (**p == '+')
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
48 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
49 (*p)++;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
50 tfm = 1;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
51 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
52 else if (**p == '-')
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
53 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
54 (*p)++;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
55 tfm = 2;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
56 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
57 if (*(*p)++ != ',')
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
58 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
59 register_error(as, l, 1, "Unknown operation");
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
60 return;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
61 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
62 c = strchr(reglist, toupper(*(*p)++));
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
63 if (!c)
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
64 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
65 register_error(as, l, 1, "Unknown operation");
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
66 return;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
67 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
68 r1 = c - reglist;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
69
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
70 if (**p == '+')
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
71 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
72 (*p)++;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
73 tfm |= 4;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
74 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
75 else if (**p == '-')
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
76 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
77 (*p)++;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
78 tfm |= 8;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
79 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
80
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
81 if (**p && !isspace(**p))
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
82 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
83 register_error(as, l, 1, "Bad operand");
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
84 return;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
85 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
86
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
87 // valid values of tfm here are:
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
88 // 1: r0+,r1 (2)
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
89 // 4: r0,r1+ (3)
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
90 // 5: r0+,r1+ (0)
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
91 // 10: r0-,r1- (1)
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
92 switch (tfm)
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
93 {
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
94 case 5: //r0+,r1+
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
95 lwasm_emitop(as, l, instab[opnum].ops[0]);
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
96 break;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
97 case 10: //r0-,r1-
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
98 lwasm_emitop(as, l, instab[opnum].ops[1]);
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
99 break;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
100 case 1: // r0+,r1
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
101 lwasm_emitop(as, l, instab[opnum].ops[2]);
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
102 break;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
103 case 4: // r0,r1+
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
104 lwasm_emitop(as, l, instab[opnum].ops[3]);
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
105 break;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
106 default:
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
107 register_error(as, l, 1, "Unknown operation");
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
108 return;
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
109 }
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
110 lwasm_emit(as, l, (r0 << 4) | r1);
674ee393426c Added handler for TFM instructions
lost
parents:
diff changeset
111 }